OnUpdateGUI Event |
[Top] [Chapter] [Previous] [Next] |
This is the main event to update any custom toolbar and menu. Member of WPDLLInt Declaration C# OnUpdateGUIEvent(Object Sender, int Editor, int UpdateFlags, int StateFlags, int PageNr, int PageCount, int LineNr)
Declaration OCX OnUpdateGUI(ByVal Editor As Long, ByVal UpdateFlags As Long, ByVal StateFlags As Long, ByVal PageNr As Long, ByVal PageCount As Long, ByVal LineNr As Long)
The event can be used to show the current position in a statusbar:
Private void wpdllInt1_OnUpdateGUI(Object Sender, int Editor, int UpdateFlags, int StateFlags, int PageNr, int PageCount, int LineNr) { stPage.Text = Convert.ToString(PageNr)+'/'+ Convert.ToString(PageCount); stLine.Text = "Line " + Convert.ToString(LineNr); stIns.Text = (((StateFlags&2)!=0)?"INS":""); }
This is also the recommended event to update any custom toolbar and menu. Inside this event You can use the wpaGetFlags to retrieve the states of all implemented wpa actions in one array. C# example: private void wpdllInt1_OnUpdateGUI(object Sender, int Editor, int UpdateFlags, int StateFlags, int PageNr, int PageCount, int LineNr) { int wpa_italic = wpdllInt1.wpaGetID("Italic"); byte[] stateflags = wpdllInt1.wpaGetFlags(0); // Current editor btItalic.Pushed =(stateflags[wpa_italic] & 2)!=0; } In this example we use wpaGetID to get the ID for a certain action to make the process better to understand. In a real world application you would use wpaGetID() only once and then save the result id in an integer property added to the button or menu class. (see example "First C# Application" in the manual)
Note: You can use wpaSetFlags to modify certain internal states. This makes it possible to disable internal buttons under program control.
Also see: IWPAttrInterface TextAttr;
VB 6 Example: Here we took the automatically created MDI example and converted it to use TextDynamic. The way a the toolbar is processed here is not optimal - it uses fixed names. We would recommend to use IDs in the toolbar and use a separate array to match the button to the action. This is the code which simply uses the original logic:
Private Sub rtfText_OnUpdateGUI(ByVal Editor As Long, ByVal UpdateFlags As Long, ByVal StateFlags As Long, ByVal PageNr As Long, ByVal PageCount As Long, ByVal LineNr As Long) Dim s As String ' the returned array is a string Dim i As Integer ' we need the index of a certain action Dim Bytes() As Byte ' we need a bytes array to test the flags
' Retrieve the setting of all atcions s = rtfText.wpaGetFlags(0) ' this are the flags for the current editor Bytes = StrConv(s, vbFromUnicode) ' convert string to bytes
' Character attributes have been changed If (UpdateFlags And 8 <> 0) Then ' this is the id for the command to toggle 'bold' i = rtfText.wpaGetID("bold") ' Use the id to update the setting of 'Bold' fMainForm.tbToolBar.Buttons("Fett").Value = IIf(Bytes(i) And 2, tbrPressed, tbrUnpressed) ' Proceed with the other elements ' ... ' this is the id for the command to toggle 'italic' i = rtfText.wpaGetID("italic") ' Use the id to update the setting of 'italic' fMainForm.tbToolBar.Buttons("Kursiv").Value = IIf(Bytes(i) And 2, tbrPressed, tbrUnpressed)
' this is the id for the command to toggle 'underline' i = rtfText.wpaGetID("underline") ' Use the id to update the setting of 'underlined' fMainForm.tbToolBar.Buttons("Unterstrichen").Value = IIf(Bytes(i) And 2, tbrPressed, tbrUnpressed) End If
' Paragraph attributes have been changed If (UpdateFlags And 4 <> 0) Then ' this is the id for the command to toggle 'left' i = rtfText.wpaGetID("left") ' Use the id to update the setting of 'left aligned' fMainForm.tbToolBar.Buttons("Links ausrichten").Value = IIf(Bytes(i) And 2, tbrPressed, tbrUnpressed) ' Proceed with the other elements ' ... ' this is the id for the command to toggle 'Center' i = rtfText.wpaGetID("Center") ' Use the id to update the setting of 'Centered' fMainForm.tbToolBar.Buttons("Zentrieren").Value = IIf(Bytes(i) And 2, tbrPressed, tbrUnpressed)
' this is the id for the command to toggle 'Right' i = rtfText.wpaGetID("Right") ' Use the id to update the setting of 'Rechts ausrichten' fMainForm.tbToolBar.Buttons("Rechts ausrichten").Value = IIf(Bytes(i) And 2, tbrPressed, tbrUnpressed) End If
End Sub
Category |