Skip to content

Commit

Permalink
minor changes to PasteAsText;
Browse files Browse the repository at this point in the history
prevent MainWindow from loosing focus when clicking on FormatBox.
  • Loading branch information
changbowen committed Dec 24, 2016
1 parent 036e68d commit 6fbdf30
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 40 deletions.
2 changes: 1 addition & 1 deletion FormatBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
xmlns:wtk="http://schemas.xceed.com/wpf/xaml/toolkit"
Width="230" Height="250" UseLayoutRounding="True" AllowsTransparency="True"
WindowStyle="None" Background="{x:Null}" FontSize="10" ShowInTaskbar="False" ShowActivated="False"
Topmost="True">
Topmost="True" PreviewGotKeyboardFocus="FB1_PreviewGotKeyboardFocus">
<Window.Resources>
<Storyboard x:Key="SB_In">
<DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="Grid_Main">
Expand Down
36 changes: 29 additions & 7 deletions FormatBox.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,33 @@ public partial class FormatBox : Window
{
RichTextBox RTB_Main;

//private const int GWL_EXSTYLE = -20;
//private const int WS_EX_NOACTIVATE = 0x08000000;
//private const int WS_EX_TOOLWINDOW = 0x00000080;
//[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
//public static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, int dwNewLong);
//[System.Runtime.InteropServices.DllImport("user32.dll", CharSet = System.Runtime.InteropServices.CharSet.Auto)]
//public static extern int GetWindowLong(IntPtr hWnd, int nIndex);

//private void FB1_SourceInitialized(object sender, EventArgs e)
//{
// //not working
// var interopHelper = new System.Windows.Interop.WindowInteropHelper(this);
// int exStyle = GetWindowLong(interopHelper.Handle, GWL_EXSTYLE);
// SetWindowLong(interopHelper.Handle, GWL_EXSTYLE, exStyle | WS_EX_NOACTIVATE);
//}

public FormatBox()
{
InitializeComponent();
}

private void FB1_PreviewGotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
e.Handled = true;
Owner.Focus();
}

public void Popup()
{
//refresh reference for when reset setting is executed
Expand Down Expand Up @@ -54,8 +76,8 @@ public void Popup()
var easefunc = new CubicEase() { EasingMode = EasingMode.EaseInOut };
var anim_move_x = new DoubleAnimation(realpos.X, new Duration(new TimeSpan(0, 0, 0, 0, 300)), FillBehavior.Stop) { EasingFunction = easefunc };
var anim_move_y = new DoubleAnimation(realpos.Y, new Duration(new TimeSpan(0, 0, 0, 0, 300)), FillBehavior.Stop) { EasingFunction = easefunc };
Topmost = false;
Topmost = true;
//Topmost = false;
//Topmost = true;
BeginAnimation(LeftProperty, anim_move_x);
BeginAnimation(TopProperty, anim_move_y);
}
Expand All @@ -64,8 +86,8 @@ public void Popup()
public async void Unpop()
{
var sb = ((Storyboard)FindResource("SB_Out"));
Topmost = false;
Topmost = true;
//Topmost = false;
//Topmost = true;
sb.Begin();
await Task.Run(() => System.Threading.Thread.Sleep(200));
Hide();
Expand Down Expand Up @@ -259,16 +281,16 @@ private void CB_AutoDock_Click(object sender, RoutedEventArgs e)

internal void PasteAsText(object sender, RoutedEventArgs e)
{
RTB_Main.CaretPosition.InsertTextInRun(Clipboard.GetText());
var txt = Clipboard.GetText();
RTB_Main.CaretPosition.InsertTextInRun(txt);
RTB_Main.CaretPosition = RTB_Main.CaretPosition.GetPositionAtOffset(txt.Length);
}

internal void Find(object sender, RoutedEventArgs e)
{
new Win_Search().Show();
}



#endregion
}
}
58 changes: 26 additions & 32 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,14 +419,9 @@ private void Win_Main_Loaded(object sender, RoutedEventArgs e)
Top = set.Win_Pos.Y;
}

bool firstload = false;
if (App.fb == null)
{
App.fb = new FormatBox();
firstload = true;
}
App.fb = new FormatBox();
App.fb.Tag = RTB_Main;
//App.fb.Owner = this; causing fb to close when mainwin closes.
App.fb.Owner = this; //causing fb to close when mainwin closes.
lastdockstatus = (DockStatus)set.DockedTo;
RTB_Main.FontFamily = new FontFamily(set.Font);
RTB_Main.Foreground = new SolidColorBrush(set.FontColor);
Expand All @@ -436,38 +431,37 @@ private void Win_Main_Loaded(object sender, RoutedEventArgs e)
Rec_BG.Fill = new SolidColorBrush(set.PaperColor);
((Xceed.Wpf.Toolkit.ColorPicker)App.fb.CP_Paper.Content).SelectedColor = set.PaperColor;

if (firstload)

//add fonts to menu
foreach (var f in Fonts.SystemFontFamilies)
{
//add fonts to menu
foreach (var f in Fonts.SystemFontFamilies)
var mi = new ComboBoxItem
{
var mi = new ComboBoxItem
{
Content = f.Source,
FontFamily = f,
FontSize = this.FontSize + 4,
ToolTip = f.Source
};
App.fb.CB_Font.Items.Add(mi);
if (f.Source == set.Font) mi.IsSelected = true;
}
App.fb.CB_Font.Items.SortDescriptions.Add(new System.ComponentModel.SortDescription("Content", System.ComponentModel.ListSortDirection.Ascending));
App.fb.CB_Font.SelectionChanged += (object s1, SelectionChangedEventArgs e1) =>
Content = f.Source,
FontFamily = f,
FontSize = this.FontSize + 4,
ToolTip = f.Source
};
App.fb.CB_Font.Items.Add(mi);
if (f.Source == set.Font) mi.IsSelected = true;
}
App.fb.CB_Font.Items.SortDescriptions.Add(new System.ComponentModel.SortDescription("Content", System.ComponentModel.ListSortDirection.Ascending));
App.fb.CB_Font.SelectionChanged += (object s1, SelectionChangedEventArgs e1) =>
{
if (App.fb.Grid_Main.Opacity == 1 && e1.AddedItems.Count == 1)
{
if (App.fb.Grid_Main.Opacity == 1 && e1.AddedItems.Count == 1)
{
var mi = (ComboBoxItem)e1.AddedItems[0];
var mi = (ComboBoxItem)e1.AddedItems[0];
if (!RTB_Main.Selection.IsEmpty) //only change selected
if (!RTB_Main.Selection.IsEmpty) //only change selected
RTB_Main.Selection.ApplyPropertyValue(TextElement.FontFamilyProperty, mi.FontFamily);
else //change default
else //change default
{
RTB_Main.FontFamily = mi.FontFamily;
set.Font = mi.FontFamily.Source;
}
RTB_Main.FontFamily = mi.FontFamily;
set.Font = mi.FontFamily.Source;
}
};
}
}
};


//loading contents
if (File.Exists(doc_loc))
Expand Down
Binary file modified bin/Release/DesktopNote.exe
Binary file not shown.

0 comments on commit 6fbdf30

Please sign in to comment.