381 lines
16 KiB
XML
381 lines
16 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
|
|
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="PageStyles" script:language="StarBasic" script:moduleType="normal">
|
|
Dim pDialog As Object
|
|
Sub pageStylesDialog
|
|
|
|
Dim listBox As Object
|
|
Dim oStyles As Object
|
|
Dim pageStyles As Object
|
|
Dim pageStyleNames() As String
|
|
Dim imageURL As String
|
|
Dim pageStyle As Object
|
|
Dim i As Integer
|
|
oStyles = ThisComponent.StyleFamilies
|
|
pageStyles = oStyles.getByName(oStyles.elementNames(2))
|
|
pageStyleNames = pageStyles.getElementNames
|
|
Dim displayPageStyleNames(Ubound(pageStyleNames))
|
|
For i = LBound(displayPageStyleNames) To Ubound(displayPageStyleNames)
|
|
pageStyle = pageStyles.getByName(pageStyleNames(i))
|
|
displayPageStyleNames(i) = pageStyle.displayName
|
|
Next i
|
|
subShellSort(displayPageStyleNames)
|
|
DialogLibraries.LoadLibrary("ePublishing")
|
|
pDialog = CreateUnoDialog( DialogLibraries.ePublishing.PageConfig )
|
|
imageURL = convertToURL(getExtensionPath() + "/images/panel.svg")
|
|
pDialog.getControl("ImageControl1").model.imageURL = imageURL
|
|
pDialog.getControl("ImageControl1").model.ScaleMode = 2
|
|
pDialog.getControl("description").setText(getTranslation("PageConfigDialogTranslations"))
|
|
cleanPageSettings()
|
|
setHelpText()
|
|
pDialog.getControl("Cancel").Label = getTranslation("PageConfigDialogCancelButton")
|
|
pDialog.getControl("Ok").Label = getTranslation("PageConfigDialogOkButton")
|
|
listBox = pDialog.getControl("pageStyles")
|
|
listBox.addItems(displayPageStyleNames, 0)
|
|
pDialog.Title = getTranslation("PageConfigDialogTitle")
|
|
pDialog.Execute()
|
|
pDialog.dispose()
|
|
End Sub
|
|
|
|
Function getExtensionPath As String
|
|
Dim extensionIdentifier As String
|
|
Dim pip As Object
|
|
extensionIdentifier = "pro.litvinovg.epublishing"
|
|
pip = GetDefaultContext.getByName("/singletons/com.sun.star.deployment.PackageInformationProvider")
|
|
getExtensionPath = pip.getPackageLocation(extensionIdentifier)
|
|
End Function
|
|
|
|
|
|
Sub applyPageStyleConfiguration()
|
|
|
|
Dim styles As Object
|
|
Dim selectedItems() As String
|
|
Dim oStyles As Object
|
|
Dim pageStyles As Object
|
|
Dim pageStyleNames() As String
|
|
Dim pageStyleName As String
|
|
Dim pageStyleDisplayName As String
|
|
Dim pageStyle As Object
|
|
Dim style As Object
|
|
Dim i As Integer
|
|
Dim foundIndex As Integer
|
|
pDialog.getControl("Ok").Model.State = 0
|
|
styles = pDialog.getControl("pageStyles")
|
|
'Mri styles
|
|
selectedItems = styles.getSelectedItems
|
|
If Ubound(selectedItems) < 0 Then
|
|
MsgBox getTranslation("pageStylesNoStyleSelected")
|
|
Exit sub
|
|
EndIf
|
|
If noPageSettings() Then
|
|
MsgBox getTranslation("pageStylesNoSettingsSet")
|
|
Exit sub
|
|
EndIf
|
|
oStyles = ThisComponent.StyleFamilies
|
|
pageStyles = oStyles.getByName(oStyles.elementNames(2))
|
|
pageStyleNames = pageStyles.getElementNames
|
|
Dim displayPageStyleNames(Ubound(pageStyleNames))
|
|
For i = LBound(displayPageStyleNames) To Ubound(displayPageStyleNames)
|
|
pageStyle = pageStyles.getByName(pageStyleNames(i))
|
|
displayPageStyleNames(i) = pageStyle.displayName
|
|
Next i
|
|
|
|
For i = LBound(selectedItems) To Ubound(selectedItems)
|
|
pageStyleDisplayName = selectedItems(i)
|
|
foundIndex = getIndex(displayPageStyleNames, pageStyleDisplayName)
|
|
pageStyleName = pageStyleNames(foundIndex)
|
|
pageStyle = pageStyles.getByName(pageStyleName)
|
|
applyPageSettings(pageStyle)
|
|
Next i
|
|
MsgBox getTranslation("PageConfigSettingsApplied")
|
|
cleanPageSettings()
|
|
End Sub
|
|
|
|
|
|
|
|
Sub cleanPageSettings()
|
|
pDialog.getControl("pageHeight").setText("")
|
|
pDialog.getControl("pageWidth").setText("")
|
|
pDialog.getControl("leftPageMargin").setText("")
|
|
pDialog.getControl("topPageMargin").setText("")
|
|
pDialog.getControl("rightPageMargin").setText("")
|
|
pDialog.getControl("bottomPageMargin").setText("")
|
|
pDialog.getControl("headerHeight").setText("")
|
|
pDialog.getControl("headerOffset").setText("")
|
|
pDialog.getControl("footerHeight").setText("")
|
|
pDialog.getControl("footerOffset").setText("")
|
|
pDialog.getControl("footnoteAreaHeight").setText("")
|
|
pDialog.getControl("footnoteAreaOffset").setText("")
|
|
pDialog.getControl("textToLine").setText("")
|
|
End Sub
|
|
|
|
Sub setHelpText
|
|
pDialog.getControl("pageHeight").Model.HelpText = getTranslation("PageConfigPageHeight")
|
|
pDialog.getControl("pageWidth").Model.HelpText = getTranslation("PageConfigPageWidth")
|
|
pDialog.getControl("leftPageMargin").Model.HelpText = getTranslation("PageConfigLeftPageMargin")
|
|
pDialog.getControl("topPageMargin").Model.HelpText = getTranslation("PageConfigTopPageMargin")
|
|
pDialog.getControl("rightPageMargin").Model.HelpText = getTranslation("PageConfigRightPageMargin")
|
|
pDialog.getControl("bottomPageMargin").Model.HelpText = getTranslation("PageConfigBottomPageMargin")
|
|
pDialog.getControl("headerHeight").Model.HelpText = getTranslation("PageConfigHeaderHeight")
|
|
pDialog.getControl("headerOffset").Model.HelpText = getTranslation("PageConfigHeaderOffset")
|
|
pDialog.getControl("footerHeight").Model.HelpText = getTranslation("PageConfigFooterHeight")
|
|
pDialog.getControl("footerOffset").Model.HelpText = getTranslation("PageConfigFooterOffset")
|
|
pDialog.getControl("footnoteAreaHeight").Model.HelpText = getTranslation("PageConfigFootnoteAreaHeight")
|
|
pDialog.getControl("footnoteAreaOffset").Model.HelpText = getTranslation("PageConfigFootnoteAreaOffset")
|
|
pDialog.getControl("textToLine").Model.HelpText = getTranslation("PageConfigTextToLine")
|
|
pDialog.getControl("mm1").setText(getTranslation("PageConfigMM"))
|
|
pDialog.getControl("mm2").setText(getTranslation("PageConfigMM"))
|
|
pDialog.getControl("mm3").setText(getTranslation("PageConfigMM"))
|
|
pDialog.getControl("mm4").setText(getTranslation("PageConfigMM"))
|
|
pDialog.getControl("mm5").setText(getTranslation("PageConfigMM"))
|
|
pDialog.getControl("mm6").setText(getTranslation("PageConfigMM"))
|
|
pDialog.getControl("mm7").setText(getTranslation("PageConfigMM"))
|
|
pDialog.getControl("mm8").setText(getTranslation("PageConfigMM"))
|
|
pDialog.getControl("mm9").setText(getTranslation("PageConfigMM"))
|
|
pDialog.getControl("mm10").setText(getTranslation("PageConfigMM"))
|
|
pDialog.getControl("mm11").setText(getTranslation("PageConfigMM"))
|
|
pDialog.getControl("mm12").setText(getTranslation("PageConfigMM"))
|
|
pDialog.getControl("mm13").setText(getTranslation("PageConfigMM"))
|
|
End Sub
|
|
|
|
|
|
Function noPageSettings() As Boolean
|
|
Dim setting As String
|
|
noPageSettings = true
|
|
setting = pDialog.getControl("pageHeight").getText()
|
|
If Len(setting) > 0 Then
|
|
noPageSettings = false
|
|
EndIf
|
|
setting = pDialog.getControl("pageWidth").getText()
|
|
If Len(setting) > 0 Then
|
|
noPageSettings = false
|
|
EndIf
|
|
setting = pDialog.getControl("leftPageMargin").getText()
|
|
If Len(setting) > 0 Then
|
|
noPageSettings = false
|
|
EndIf
|
|
setting = pDialog.getControl("topPageMargin").getText()
|
|
If Len(setting) > 0 Then
|
|
noPageSettings = false
|
|
EndIf
|
|
setting = pDialog.getControl("rightPageMargin").getText()
|
|
If Len(setting) > 0 Then
|
|
noPageSettings = false
|
|
EndIf
|
|
setting = pDialog.getControl("bottomPageMargin").getText()
|
|
If Len(setting) > 0 Then
|
|
noPageSettings = false
|
|
EndIf
|
|
setting = pDialog.getControl("headerHeight").getText()
|
|
If Len(setting) > 0 Then
|
|
noPageSettings = false
|
|
EndIf
|
|
setting = pDialog.getControl("headerOffset").getText()
|
|
If Len(setting) > 0 Then
|
|
noPageSettings = false
|
|
EndIf
|
|
setting = pDialog.getControl("footerHeight").getText()
|
|
If Len(setting) > 0 Then
|
|
noPageSettings = false
|
|
EndIf
|
|
setting = pDialog.getControl("footerOffset").getText()
|
|
If Len(setting) > 0 Then
|
|
noPageSettings = false
|
|
EndIf
|
|
setting = pDialog.getControl("footnoteAreaHeight").getText()
|
|
If Len(setting) > 0 Then
|
|
noPageSettings = false
|
|
EndIf
|
|
setting = pDialog.getControl("footnoteAreaOffset").getText()
|
|
If Len(setting) > 0 Then
|
|
noPageSettings = false
|
|
EndIf
|
|
setting = pDialog.getControl("textToLine").getText()
|
|
If Len(setting) > 0 Then
|
|
noPageSettings = false
|
|
EndIf
|
|
End Function
|
|
|
|
Sub applyPageSettings(targetStyle As Object)
|
|
Dim oStyles As Object
|
|
Dim curStyle As Object
|
|
Dim inputHeight As String
|
|
Dim inputTopMargin As String
|
|
Dim inputBottomMargin As String
|
|
Dim inputLeftMargin As String
|
|
Dim inputRightMargin As String
|
|
Dim inputHeaderBodyDistance As String
|
|
Dim inputFooterBodyDistance As String
|
|
Dim inputFootnoteLineDistance As String
|
|
Dim inputFootnoteLineTextDistance As String
|
|
Dim inputFooterHeight As String
|
|
Dim inputHeaderHeight As String
|
|
Dim inputFootnoteArea As String
|
|
|
|
Dim newWidth As Long
|
|
Dim newHeight As Long
|
|
Dim newTopMargin As Long
|
|
Dim newBottomMargin As Long
|
|
Dim newLeftMargin As Long
|
|
Dim newRightMargin As Long
|
|
Dim textFieldHeight As Long
|
|
Dim textFieldWidth As Long
|
|
Dim headerBodyDistance As Long
|
|
Dim footerBodyDistance As Long
|
|
Dim footnoteLineDistance As Long
|
|
Dim footnoteLineTextDistance As Long
|
|
|
|
oStyles = ThisComponent.StyleFamilies.getByName("PageStyles")
|
|
inputWidth = pDialog.getControl("pageWidth").getText()
|
|
inputHeight = pDialog.getControl("pageHeight").getText()
|
|
inputTopMargin = pDialog.getControl("topPageMargin").getText()
|
|
inputBottomMargin = pDialog.getControl("bottomPageMargin").getText()
|
|
inputLeftMargin = pDialog.getControl("leftPageMargin").getText()
|
|
inputRightMargin = pDialog.getControl("rightPageMargin").getText()
|
|
inputHeaderBodyDistance = pDialog.getControl("headerOffset").getText()
|
|
inputFooterBodyDistance = pDialog.getControl("footerOffset").getText()
|
|
|
|
inputFooterHeight = pDialog.getControl("footerHeight").getText()
|
|
inputHeaderHeight = pDialog.getControl("headerHeight").getText()
|
|
inputFootnoteArea = pDialog.getControl("footnoteAreaHeight").getText()
|
|
|
|
inputFootnoteLineTextDistance = pDialog.getControl("textToLine").getText()
|
|
'InputBox("Введите расстояние от текста страницы до линии сноски (в сотых долях мм):", "Установка расстояния от текста страницы до линии сноски ", "")
|
|
inputFootnoteLineDistance = pDialog.getControl("footnoteAreaOffset").getText()
|
|
'InputBox("Введите расстояние от линии сноски до текста сноски (в сотых долях мм):", "Установка расстояния от линии сноски до текста сноски ", "")
|
|
|
|
|
|
curStyle = targetStyle
|
|
'Mri curStyle
|
|
newWidth = curStyle.Width
|
|
newHeight = curStyle.height
|
|
newTopMargin = curStyle.TopMargin
|
|
newBottomMargin = curStyle.BottomMargin
|
|
newLeftMargin = curStyle.LeftMargin
|
|
newRightMargin = curStyle.RightMargin
|
|
If covertMMtoLong(inputFootnoteArea) > 0 Then
|
|
Dim footnoteArea As Long
|
|
footnoteArea = covertMMtoLong(inputFootnoteArea)
|
|
curStyle.FootnoteHeight = footnoteArea
|
|
EndIf
|
|
|
|
If covertMMtoLong(inputHeaderBodyDistance) > 0 Then
|
|
headerBodyDistance = covertMMtoLong(inputHeaderBodyDistance)
|
|
curStyle.HeaderBodyDistance = headerBodyDistance
|
|
EndIf
|
|
If covertMMtoLong(inputFooterBodyDistance) > 0 Then
|
|
footerBodyDistance = covertMMtoLong(inputFooterBodyDistance)
|
|
curStyle.FooterBodyDistance = footerBodyDistance
|
|
EndIf
|
|
If covertMMtoLong(inputFootnoteLineDistance) > 0 Then
|
|
footnoteLineDistance = covertMMtoLong(inputFootnoteLineDistance)
|
|
curStyle.FootnoteLineDistance = footnoteLineDistance
|
|
EndIf
|
|
If covertMMtoLong(inputFootnoteLineTextDistance) > 0 Then
|
|
footnoteLineTextDistance = covertMMtoLong(inputFootnoteLineTextDistance)
|
|
curStyle.FootnoteLineTextDistance = footnoteLineTextDistance
|
|
EndIf
|
|
|
|
If covertMMtoLong(inputFooterHeight) > 0 Then
|
|
Dim footerHeight As Long
|
|
footerHeight = covertMMtoLong(inputFooterHeight)
|
|
curStyle.FooterIsOn = true
|
|
curStyle.FooterIsDynamicHeight = false
|
|
curStyle.FooterHeight = footerHeight + curStyle.FooterBodyDistance
|
|
EndIf
|
|
|
|
If covertMMtoLong(inputHeaderHeight) > 0 Then
|
|
Dim headerHeight As Long
|
|
headerHeight = covertMMtoLong(inputHeaderHeight)
|
|
curStyle.HeaderIsOn = true
|
|
curStyle.HeaderIsDynamicHeight = false
|
|
curStyle.HeaderHeight = headerHeight + curStyle.HeaderBodyDistance
|
|
EndIf
|
|
|
|
|
|
If curstyle.IsLandscape Then
|
|
If covertMMtoLong(inputHeight) > 0 Then
|
|
newWidth = covertMMtoLong(inputHeight)
|
|
EndIf
|
|
If covertMMtoLong(inputWidth) > 0 Then
|
|
newHeight = covertMMtoLong(inputWidth)
|
|
EndIf
|
|
|
|
If covertMMtoLong(inputLeftMargin) > 0 Then
|
|
newTopMargin = covertMMtoLong(inputLeftMargin)
|
|
EndIf
|
|
If covertMMtoLong(inputRightMargin) > 0 Then
|
|
newBottomMargin = covertMMtoLong(inputRightMargin)
|
|
EndIf
|
|
If covertMMtoLong(inputTopMargin) > 0 Then
|
|
newLeftMargin = covertMMtoLong(inputTopMargin)
|
|
EndIf
|
|
If covertMMtoLong(inputBottomMargin) > 0 Then
|
|
newRightMargin = covertMMtoLong(inputBottomMargin)
|
|
EndIf
|
|
|
|
Else
|
|
If covertMMtoLong(inputWidth) > 0 Then
|
|
newWidth = covertMMtoLong(inputWidth)
|
|
EndIf
|
|
If covertMMtoLong(inputHeight) > 0 Then
|
|
newHeight = covertMMtoLong(inputHeight)
|
|
EndIf
|
|
If covertMMtoLong(inputTopMargin) > 0 Then
|
|
newTopMargin = covertMMtoLong(inputTopMargin)
|
|
EndIf
|
|
If covertMMtoLong(inputBottomMargin) > 0 Then
|
|
newBottomMargin = covertMMtoLong(inputBottomMargin)
|
|
EndIf
|
|
If covertMMtoLong(inputLeftMargin) > 0 Then
|
|
newLeftMargin = covertMMtoLong(inputLeftMargin)
|
|
EndIf
|
|
If covertMMtoLong(inputRightMargin) > 0 Then
|
|
newRightMargin = covertMMtoLong(inputRightMargin)
|
|
EndIf
|
|
End If
|
|
textFieldWidth = newWidth - newLeftMargin - newRightMargin
|
|
textFieldHeight = newHeight - newTopMargin - newBottomMargin
|
|
If textFieldWidth > 5000 Then
|
|
curStyle.Width = newWidth
|
|
curStyle.LeftMargin = newLeftMargin
|
|
curStyle.RightMargin = newRightMargin
|
|
EndIf
|
|
|
|
If textFieldHeight > 5000 Then
|
|
curStyle.Height = newHeight
|
|
curStyle.TopMargin = newTopMargin
|
|
curStyle.BottomMargin = newBottomMargin
|
|
EndIf
|
|
|
|
Exit Sub
|
|
End Sub
|
|
|
|
|
|
Function covertMMtoLong(dimension As String) As Long
|
|
If Len(dimension) < 1 Then
|
|
convertMMtoLong = -1
|
|
Exit Function
|
|
EndIf
|
|
dimension = customReplace(dimension, ".", ",")
|
|
If Not IsNumeric( dimension ) Then
|
|
convertMMtoLong = -1
|
|
Exit Function
|
|
EndIf
|
|
Dim value As Double
|
|
value = CDbl(dimension)
|
|
If value < 0 Then
|
|
convertMMtoLong = -1
|
|
Exit Function
|
|
EndIf
|
|
value = value * 100
|
|
covertMMtoLong = CLng(value)
|
|
End Function
|
|
|
|
Function customReplace(Source As String, Search As String, NewPart As String) As String
|
|
Dim Result As String
|
|
Result = join(split(Source, Search), NewPart)
|
|
customReplace = Result
|
|
End Function
|
|
|
|
</script:module>
|