Description
This script in Page.vb and Article.vb runs on the following events:
•Placing library objects on a page. Code: FromLib. Value: 1
•Resizing objects on a page. Code: Size. Value: 2
•On starting text editing. Code: StartEdit. Value: 3
•On ending text editing. Code: EndEdit. Value: 4
•After replacing an object with an image. Code: ImgReplace. Value: 5
•When moving an object on a page. Code: Move. Value: 6
•When closing text source editing. Code: CloseTxtSrc. Value: 7
•On update of a layer. Code: LayerUpdate. Value: 8
•On activating a page. Code: Activate. Value: 9
•On moving a rotation hinge. Code: SetHinge. Value: 10
•When text editing fails. Code: EndEditFail. Value: 11
•After the paste. Code: EndPaste. Value: 12
•When rotating. Code: Rotate. Value: 13
•On shape update. Code: ShapeUpdate. Value: 14
•When format of frame changes. Code: FormatChange. Value: 15
Actually, it is used only in Page.vb.
Syntax
OnAction |
Code in PageDesigner.vb (handles page events)
Public Overridable Sub OnAction(ByVal action As IEditorialEvent.Actions) Implements IEditorialEvent.OnAction
'v12 on 26/Oct/15 (BS): implement FormatChange
'v11 on 23/Oct/15 (BS): preference F_SyncNavWithPage to control syncing of navigator with the current page
'v10 on 01/Oct/15 (BS): passing "keypress" from other function through UtilsBase.varKeyP
'v9 on 30/Sep/15 (BS): added fit on resize if turned on in pers. prefs
'v8 on 16/Mar/15 (BS): works also for top images (that do non overlap body)
'v7 on 04/Feb/15 (BS): make Shift and Ctrl extended action as personal preferences
'v6 on 15/Jan/15 (BS): handle EndPaste
'v5 on 17/dec/14 (BS): handle also pictures and captions when unlinked
'v4 on 15/Dec/14 (BS): handle scaling/moving of picture with caption that follows (OnImgDragChgAlignCapt)
'v3 on 10/Nov/14 (BS): handle keep total height when resizing article head holding Shift pressed
Dim keyP As Integer = Fred.GetQualifier
If keyP = 0 Then
If UtilsBase.varKeyP = 1 Then
keyP = 1
UtilsBase.varKeyP = 0
End If
End If
Dim r As Drawing.Rectangle = CType(Page.GetOldSelArea(), Drawing.Rectangle)
If (action = IEditorialEvent.Actions.Rotate) Then
If Fred.TestSel(IFredApp.eDispatcherType.Rotate) Then
If keyP = 2 Then
TxtSlant()
End If
End If
End If
If (action = IEditorialEvent.Actions.Size) Then
If keyP = 2 And SystemUserOptions.F_CtrlEx Then 'v7
If r.Width <> Page.GetSelectionWidth Then
If Page.GetSelectionCount = 1 Then Return
OnBodyDragResplit(r)
Return
End If
End If
If keyP = 1 And SystemUserOptions.F_ShiftEx Then 'v7 pressed Shift and the extended action is enabled
DisableDraw()
Dim photoCaptionTypeId As Integer = Fred.GetTypeIdFromName(photoname)
If Page.ObjGetTypeId = photoCaptionTypeId AndAlso Page.GetSelectedKind = POK.oBitmap AndAlso Page.GetSelectionCount = 1 Then
OnImgDragChgAlignCapt(r)
Else
If SystemUserOptions.AFCS_PromptNS Then 'v3
AlignArticleParts(r, 1) ' align article below parts keeping total height (if any article)
Else
AlignArticleParts(r, 0) ' align article below parts NOT keeping total height (if any article)
End If
End If
Return
End If
If keyP = 0 And SystemUserOptions.F_FitOnResize Then ' no key pressed
If Fred.HasActiveArticle Then
If Page.GetSelectedTxtId > 0 Or Page.GetSelectedImgId > 0 Then
If Page.GetSelectionCount > 0 Then
Dim oA(,) As Object = PushSelectionEx()
For t As Integer = 1 To CInt(oA(0, 0))
If CInt(oA(t, 6)) = POK.oFrame Then
If CInt(oA(t, 30)) > 0 Then ' if linked
Page.ObjSelectId(CInt(oA(t, 0)), False)
Fred.TxtSelect(CInt(oA(t, 30)))
If Fred.GetActiveTxt.OverN <> 0 Then
FitTxt("", True)
End If
End If
End If
Next
PopSelection(oA)
End If
End If
End If
End If
ElseIf (action = IEditorialEvent.Actions.Move) Then
If keyP = 1 And SystemUserOptions.F_ShiftEx Then 'v7
Dim photoCaptionTypeId As Integer = Fred.GetTypeIdFromName(photoname)
If Page.ObjGetTypeId = photoCaptionTypeId AndAlso Page.GetSelectedKind = POK.oBitmap AndAlso Page.GetSelectionCount = 1 Then
OnImgDragChgAlignCapt(r)
Else
If SystemUserOptions.AFCS_PromptNS Then 'v3
AlignArticleParts(r, 1) ' align article below parts keeping total height (if any article)
Else
AlignArticleParts(r, 0) ' align article below parts NOT keeping total height (if any article)
End If
End If
End If
ElseIf (action = IEditorialEvent.Actions.FromLib) Then
Page.Focus()
Page.ObjSetFromLib()
If Page.ObjTestGrouped = 2 Then
Fred.SelNormal()
Dim e = Page.ObjUnselect()
End If
ElseIf (action = IEditorialEvent.Actions.ImgReplace) Then
'MsgBox("Action: Image replace")
ElseIf action = IEditorialEvent.Actions.CloseTxtSrc Then
'Page.ViewZoomFit(False,False)
ElseIf action = IEditorialEvent.Actions.Activate Then
' synchronize title and edition with the current page
Dim window As IShellWindow = DirectCast(Main.Window, IShellWindow)
If Not window Is Nothing AndAlso Fred.GetWindowType = 1 Then ' do this only for pages - not for masters or libraries
If Not Page.GetPageEdition Is Nothing Then
If SystemUserOptions.F_SyncNavWithPage Then 'v11
window.SetElementOnSearch("title", Page.GetPageEdition.titleRefAttr)
window.SetElementOnSearch("edition", Page.GetPageEdition.idAttr)
End If
End If
End If
ElseIf action = IEditorialEvent.Actions.SetHinge Then
' Rotation hinge moved
ElseIf (action = IEditorialEvent.Actions.EndPaste) Then
' End paste
OnEndPaste()
ElseIf (action = IEditorialEvent.Actions.ShapeUpdate) Then
' Page.SelElement().ExcludeAutoVerts()
ElseIf (action = IEditorialEvent.Actions.FormatChange) Then
If Page.TestReadOnly Then Return
' get current format data
Dim curH As Integer = 0
Dim iFormatId As Integer = 0
If Fred.HasActiveTxt Then
iFormatId = Ted.GetActiveTxt.FormatId
Else
iFormatId = Ted.GetCurrentLocalTxt.FormatId
End If
Dim oFormat As Format = Fred.GetFormat(iFormatId)
Dim sFormatname As String = oFormat.Name
Dim oTS = oFormat.DefaultTextStatus
Dim oPS = oFormat.DefaultParaStatus
Dim iTSize = oTS.CharH
Dim iTLead = oPS.Leading
'check selection count
If Page.GetSelectionCount = 1 Then
Dim iId As Integer = Page.GetSelectedId
curH = Page.GetSelectionHeight
If Fred.GetTypeNameFromId(Page.ObjGetTypeId) <> bodyname Then
If SystemUserOptions.AFCS_SizeWFormat Then
Dim rr As Drawing.Rectangle
rr.X = Page.GetSelectionX
rr.Y = Page.GetSelectionY
rr.Width = Page.GetSelectionWidth
rr.Height = Page.GetSelectionHeight
Page.ObjSetHW(iTLead, -1)
Dim overH As Integer = 0
If Fred.HasActiveTxt Then
If Fred.GetActiveTxt.Depth > 0 Then
overH = Ted.GetActiveTxt.OverH
End If
Else
If Ted.GetCurrentLocalTxt.Depth > 0 Then
overH = Ted.GetCurrentLocalTxt.OverH
End If
End If
If overH <> 0 Then
Page.ObjInflateSgm(0, 0, 0, overH, "F+")
End If
If SystemUserOptions.AFCS_PromptNS Then 'v3
AlignArticleParts(rr, 1) ' align article below parts keeping total height (if any article)
Else
AlignArticleParts(rr, 0) ' align article below parts NOT keeping total height (if any article)
End If
End If
End If
End If
'v2 - store formats in tool
Dim elem As ElementProp = Page.SelElement()
If elem IsNot Nothing Then
Dim newFormat = elem.TextFormatId
Do
Page.ObjSetToolFormatId(newFormat)
If keyP = 2 Then
StoreDefFormatToFrame(newFormat)
End If
Loop While CBool(elem.NextSel)
End If
End If
End Sub
Code in PageTxtDesigner.vb (handles text editing events)
Public Overridable Sub OnAction(ByVal action As IEditorialEvent.Actions) Implements IEditorialEvent.OnAction
If action = IEditorialEvent.Actions.EndEditFail Then
If Ted.GetActiveTxt().IsChanged Then
Dim objArt = Ted.GetActiveArticle
Dim i As Integer = objArt.GetCurTxtIdx
If MsgBox(My.Resources.IDS_CloseAbandon4, vbYesNo, MainAddIn.Label) = vbYes Then
objArt.CloseTxt(i, True)
End If
End If
End If
End Sub