EgtWPFLib :

- Introdotta gestione messaggi multilingua.
- Introdotto EgtPopup con la proprietà aggiuntiva Topmost che se disattivata permette di non avere i popup sempre in primo piano.
This commit is contained in:
Emmanuele Sassi
2016-02-12 08:32:23 +00:00
parent 7b74c6c8af
commit 9fd88023e0
8 changed files with 231 additions and 12 deletions
+9
View File
@@ -0,0 +1,9 @@
Module ConstMsg
Public Const MSG_EGTWPFLIB As Integer = 20000
Public Const MSG_EGTCALCULATOR As Integer = MSG_EGTWPFLIB + 10
Public Const MSG_EGTCALCULATORWD As Integer = MSG_EGTWPFLIB + 20
Public Const MSG_EGTKEYBOARD As Integer = MSG_EGTWPFLIB + 30
Public Const MSG_EGTMSGBOX As Integer = MSG_EGTWPFLIB + 40
End Module
+1 -1
View File
@@ -167,7 +167,7 @@ Public Class EgtCalculator
End Sub
Private Sub EgtCalculator_Loaded(sender As Object, e As EventArgs) Handles Me.Loaded
m_sErrorString = EgtMsg(10200 + 1)
m_sErrorString = EgtMsg(MSG_EGTCALCULATOR + 1)
If Not IsNothing(m_SourceTxBx) Then
Dim SourceTxBx As TextBox = m_SourceTxBx
ValueTxBx.Text = SourceTxBx.Text
+6 -6
View File
@@ -346,25 +346,25 @@ Public Class EgtMsgBox
Case Buttons.YES_NO_CANCEL
Btn1.SetValue(Grid.ColumnProperty, 1 + m_iExtraColumns)
Btn1.SetValue(Grid.ColumnSpanProperty, 2)
Btn1.Content = "Yes"
Btn1.Content = EgtMsg(MSG_EGTMSGBOX + 3)
Btn2.SetValue(Grid.ColumnProperty, 4 + m_iExtraColumns)
Btn2.SetValue(Grid.ColumnSpanProperty, 2)
Btn2.Content = "No"
Btn2.Content = EgtMsg(MSG_EGTMSGBOX + 4)
Btn3.SetValue(Grid.ColumnProperty, 7 + m_iExtraColumns)
Btn3.SetValue(Grid.ColumnSpanProperty, 2)
Btn3.Content = "Canc"
Btn3.Content = EgtMsg(MSG_EGTMSGBOX + 2)
Case Buttons.OK_CANCEL
Btn1.SetValue(Grid.ColumnProperty, 2 + m_iExtraColumns)
Btn1.SetValue(Grid.ColumnSpanProperty, 2)
Btn1.Content = "Ok"
Btn1.Content = EgtMsg(MSG_EGTMSGBOX + 1)
Btn2.Visibility = Windows.Visibility.Hidden
Btn3.SetValue(Grid.ColumnProperty, 5 + m_iExtraColumns)
Btn3.SetValue(Grid.ColumnSpanProperty, 2)
Btn3.Content = "Canc"
Btn3.Content = EgtMsg(MSG_EGTMSGBOX + 2)
Case Buttons.OK
Btn1.SetValue(Grid.ColumnProperty, 4 + m_iExtraColumns)
Btn1.SetValue(Grid.ColumnSpanProperty, 2)
Btn1.Content = "Ok"
Btn1.Content = EgtMsg(MSG_EGTMSGBOX + 1)
Btn2.Visibility = Windows.Visibility.Hidden
Btn3.Visibility = Windows.Visibility.Hidden
Case Buttons.NULL
+8
View File
@@ -0,0 +1,8 @@
<Popup x:Class="EgtPopup"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
</Popup>
+149
View File
@@ -0,0 +1,149 @@
Imports System.Windows.Controls.Primitives
Imports System.Windows.Interop
Public Class EgtPopup
Inherits Popup
''' <summary>
''' Is Topmost dependency property
''' </summary>
Public Shared ReadOnly IsTopmostProperty As DependencyProperty = DependencyProperty.Register("IsTopmost", GetType(Boolean), GetType(EgtPopup), New FrameworkPropertyMetadata(False, New PropertyChangedCallback(AddressOf OnIsTopmostChanged)))
Private _appliedTopMost As System.Nullable(Of Boolean)
Private _alreadyLoaded As Boolean
Private _parentWindow As Window
''' <summary>
''' Get/Set IsTopmost
''' </summary>
Public Property IsTopmost() As Boolean
Get
Return CBool(GetValue(IsTopmostProperty))
End Get
Set(value As Boolean)
SetValue(IsTopmostProperty, value)
End Set
End Property
''' <summary>
''' ctor
''' </summary>
Public Sub New()
' Chiamata richiesta dal Wpf
InitializeComponent()
AddHandler Me.Loaded, AddressOf OnPopupLoaded
AddHandler Me.Unloaded, AddressOf OnPopupUnloaded
End Sub
Private Sub OnPopupLoaded(sender As Object, e As RoutedEventArgs)
If _alreadyLoaded Then
Return
End If
_alreadyLoaded = True
If Child IsNot Nothing Then
Child.[AddHandler](PreviewMouseLeftButtonDownEvent, New MouseButtonEventHandler(AddressOf OnChildPreviewMouseLeftButtonDown), True)
End If
_parentWindow = Window.GetWindow(Me)
If _parentWindow Is Nothing Then
Return
End If
AddHandler _parentWindow.Activated, AddressOf OnParentWindowActivated
AddHandler _parentWindow.Deactivated, AddressOf OnParentWindowDeactivated
End Sub
Private Sub OnPopupUnloaded(sender As Object, e As RoutedEventArgs)
If _parentWindow Is Nothing Then
Return
End If
RemoveHandler _parentWindow.Activated, AddressOf OnParentWindowActivated
RemoveHandler _parentWindow.Deactivated, AddressOf OnParentWindowDeactivated
End Sub
Private Sub OnParentWindowActivated(sender As Object, e As EventArgs)
Debug.WriteLine("Parent Window Activated")
SetTopmostState(True)
End Sub
Private Sub OnParentWindowDeactivated(sender As Object, e As EventArgs)
Debug.WriteLine("Parent Window Deactivated")
If IsTopmost = False Then
SetTopmostState(IsTopmost)
End If
End Sub
Private Sub OnChildPreviewMouseLeftButtonDown(sender As Object, e As MouseButtonEventArgs)
Debug.WriteLine("Child Mouse Left Button Down")
SetTopmostState(True)
If Not _parentWindow.IsActive AndAlso IsTopmost = False Then
_parentWindow.Activate()
Debug.WriteLine("Activating Parent from child Left Button Down")
End If
End Sub
Private Shared Sub OnIsTopmostChanged(obj As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim thisobj = DirectCast(obj, EgtPopup)
thisobj.SetTopmostState(thisobj.IsTopmost)
End Sub
Protected Overrides Sub OnOpened(e As EventArgs)
SetTopmostState(IsTopmost)
MyBase.OnOpened(e)
End Sub
Private Sub SetTopmostState(isTop As Boolean)
' Dont apply state if its the same as incoming state
If _appliedTopMost.HasValue AndAlso _appliedTopMost = isTop Then
Return
End If
If Child Is Nothing Then
Return
End If
Dim hwndSource = TryCast(PresentationSource.FromVisual(Child), HwndSource)
If hwndSource Is Nothing Then
Return
End If
Dim hwnd = hwndSource.Handle
Dim rect As WinApi.RECT
If Not WinApi.GetWindowRect(hwnd, rect) Then
Return
End If
Debug.WriteLine("setting z-order " & isTop)
If isTop Then
WinApi.SetWindowPos(hwnd, WinApi.HWND_TOPMOST, 0, 0, 0, 0, _
WinApi.TOPMOST_FLAGS)
Else
' Z-Order would only get refreshed/reflected if clicking the
' the titlebar (as opposed to other parts of the external
' window) unless I first set the popup to HWND_BOTTOM
' then HWND_TOP before HWND_NOTOPMOST
WinApi.SetWindowPos(hwnd, WinApi.HWND_BOTTOM, 0, 0, 0, 0, _
WinApi.TOPMOST_FLAGS)
WinApi.SetWindowPos(hwnd, WinApi.HWND_TOP, 0, 0, 0, 0, _
WinApi.TOPMOST_FLAGS)
WinApi.SetWindowPos(hwnd, WinApi.HWND_NOTOPMOST, 0, 0, 0, 0, _
WinApi.TOPMOST_FLAGS)
End If
_appliedTopMost = isTop
End Sub
End Class
+4 -4
View File
@@ -20,11 +20,11 @@ Public Class EgtTextBox
Private Const OFFSET = 3 'Offset per non mostrare la tastiera attaccata alla TextboxBase
' Riferimento al PopUp ed alla Keyboard, usati nel caso in cui la tastiera sia attiva
Private WithEvents m_KeyboardPopUp As Popup
Private WithEvents m_KeyboardPopUp As EgtPopup
Private WithEvents m_Keyboard As EgtWPFLib.EgtKeyboard
' Riferimento al PopUp ed alla calcolatrice, usati nel caso in cui la calcolatrice sia attiva
Private WithEvents m_CalculatorPopUp As Popup
Private WithEvents m_CalculatorPopUp As EgtPopup
Private WithEvents m_Calculator As EgtWPFLib.EgtCalculator
' Riferimento alla finestra in cui si trova la EgtTxBx
@@ -113,7 +113,7 @@ Public Class EgtTextBox
Owner = Owner.Parent
End While
m_Owner = Owner
m_KeyboardPopUp = New Popup
m_KeyboardPopUp = New EgtPopup
m_Keyboard = New EgtWPFLib.EgtKeyboard(TxBx, Owner, GetKeyboardDimension(Me))
m_KeyboardPopUp.Child = m_Keyboard
m_KeyboardPopUp.PlacementTarget = TxBx
@@ -132,7 +132,7 @@ Public Class EgtTextBox
Owner = Owner.Parent
End While
m_Owner = Owner
m_CalculatorPopUp = New Popup
m_CalculatorPopUp = New EgtPopup
m_Calculator = New EgtWPFLib.EgtCalculator(Owner, GetKeyboardDimension(Me), WidthType.PIXEL, TxBx)
m_CalculatorPopUp.Child = m_Calculator
m_CalculatorPopUp.PlacementTarget = TxBx
+8
View File
@@ -82,6 +82,7 @@
<Import Include="System.Windows.Navigation" />
</ItemGroup>
<ItemGroup>
<Compile Include="ConstMsg.vb" />
<Compile Include="EgtCalculator.xaml.vb">
<DependentUpon>EgtCalculator.xaml</DependentUpon>
</Compile>
@@ -94,6 +95,9 @@
<Compile Include="EgtMsgBox.xaml.vb">
<DependentUpon>EgtMsgBox.xaml</DependentUpon>
</Compile>
<Compile Include="EgtPopup.xaml.vb">
<DependentUpon>EgtPopup.xaml</DependentUpon>
</Compile>
<Compile Include="EgtTextBox.xaml.vb">
<DependentUpon>EgtTextBox.xaml</DependentUpon>
</Compile>
@@ -140,6 +144,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="EgtPopup.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="EgtTextBox.xaml">
<Generator>MSBuild:Compile</Generator>
<SubType>Designer</SubType>
+46 -1
View File
@@ -1,5 +1,5 @@
Imports System.Globalization
Imports System.Runtime.InteropServices
Public Module Utility
@@ -38,5 +38,50 @@ Public Module Utility
End If
End Function
#Region "<!--EgtPopup-->"
Public Class WinApi
<StructLayout(LayoutKind.Sequential)> _
Public Structure RECT
Public Left As Integer
Public Top As Integer
Public Right As Integer
Public Bottom As Integer
End Structure
<DllImport("user32.dll")> _
Public Shared Function GetWindowRect(hWnd As IntPtr, ByRef lpRect As RECT) As <MarshalAs(UnmanagedType.Bool)> Boolean
End Function
<DllImport("user32.dll")> _
Public Shared Function SetWindowPos(hWnd As IntPtr, hWndInsertAfter As IntPtr, X As Integer, Y As Integer, cx As Integer, cy As Integer, _
uFlags As UInteger) As Boolean
End Function
Public Shared ReadOnly HWND_TOPMOST As New IntPtr(-1)
Public Shared ReadOnly HWND_NOTOPMOST As New IntPtr(-2)
Public Shared ReadOnly HWND_TOP As New IntPtr(0)
Public Shared ReadOnly HWND_BOTTOM As New IntPtr(1)
Public Const SWP_NOSIZE As UInt32 = &H1
Public Const SWP_NOMOVE As UInt32 = &H2
Public Const SWP_NOZORDER As UInt32 = &H4
Public Const SWP_NOREDRAW As UInt32 = &H8
Public Const SWP_NOACTIVATE As UInt32 = &H10
Public Const SWP_FRAMECHANGED As UInt32 = &H20
' The frame changed: send WM_NCCALCSIZE
Public Const SWP_SHOWWINDOW As UInt32 = &H40
Public Const SWP_HIDEWINDOW As UInt32 = &H80
Public Const SWP_NOCOPYBITS As UInt32 = &H100
Public Const SWP_NOOWNERZORDER As UInt32 = &H200
' Dont do owner Z ordering
Public Const SWP_NOSENDCHANGING As UInt32 = &H400
' Dont send WM_WINDOWPOSCHANGING
Public Const TOPMOST_FLAGS As UInt32 = SWP_NOACTIVATE Or SWP_NOOWNERZORDER Or SWP_NOSIZE Or SWP_NOMOVE Or SWP_NOREDRAW Or SWP_NOSENDCHANGING
End Class
#End Region
End Module