2020-03-17 16:15:01 +01:00
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE script:module PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
2020-05-06 16:20:51 +02:00
<script:module xmlns:script="http://openoffice.org/2000/script" script:name="PageStyles" script:language="StarBasic" script:moduleType="normal"> Dim pDialog As Object
Sub pageStylesDialog
2020-05-05 18:47:09 +02:00
Dim listBox As Object
Dim oStyles As Object
Dim pageStyles As Object
Dim pageStyleNames() As String
2020-05-05 22:49:46 +02:00
Dim imageURL As String
2020-05-05 23:32:59 +02:00
Dim pageStyle As Object
2020-05-06 16:20:51 +02:00
Dim i As Integer
2020-05-05 18:47:09 +02:00
oStyles = ThisComponent.StyleFamilies
pageStyles = oStyles.getByName(oStyles.elementNames(2))
pageStyleNames = pageStyles.getElementNames
2020-05-05 23:32:59 +02:00
Dim displayPageStyleNames(Ubound(pageStyleNames))
For i = LBound(displayPageStyleNames) To Ubound(displayPageStyleNames)
pageStyle = pageStyles.getByName(pageStyleNames(i))
displayPageStyleNames(i) = pageStyle.displayName
Next i
subShellSort(displayPageStyleNames)
2020-05-06 16:20:51 +02:00
DialogLibraries.LoadLibrary("ePublishing")
pDialog = CreateUnoDialog( DialogLibraries.ePublishing.PageConfig )
2020-05-05 22:49:46 +02:00
imageURL = convertToURL(getExtensionPath() + "/images/panel.svg")
2020-05-06 16:20:51 +02:00
pDialog.getControl("ImageControl1").model.imageURL = imageURL
2020-05-06 23:51:12 +02:00
pDialog.getControl("ImageControl1").model.ScaleMode = 2
2020-05-06 16:20:51 +02:00
pDialog.getControl("description").setText(getTranslation("PageConfigDialogTranslations"))
cleanPageSettings()
2020-05-06 19:22:33 +02:00
setHelpText()
2020-05-06 16:20:51 +02:00
pDialog.getControl("Cancel").Label = getTranslation("PageConfigDialogCancelButton")
pDialog.getControl("Ok").Label = getTranslation("PageConfigDialogOkButton")
listBox = pDialog.getControl("pageStyles")
2020-05-05 23:32:59 +02:00
listBox.addItems(displayPageStyleNames, 0)
2020-05-06 16:20:51 +02:00
pDialog.Title = getTranslation("PageConfigDialogTitle")
pDialog.Execute()
pDialog.dispose()
2020-05-05 18:47:09 +02:00
End Sub
2020-05-05 22:49:46 +02:00
Function getExtensionPath As String
Dim extensionIdentifier As String
Dim pip As Object
2020-05-05 23:32:59 +02:00
extensionIdentifier = "pro.litvinovg.epublishing"
2020-05-05 22:49:46 +02:00
pip = GetDefaultContext.getByName("/singletons/com.sun.star.deployment.PackageInformationProvider")
getExtensionPath = pip.getPackageLocation(extensionIdentifier)
End Function
2020-05-05 18:47:09 +02:00
2020-05-06 16:20:51 +02:00
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
2020-05-06 19:22:33 +02:00
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")
2020-05-07 12:20:56 +02:00
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"))
2020-05-06 19:22:33 +02:00
End Sub
2020-05-06 16:20:51 +02:00
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)
2020-03-17 16:15:01 +01:00
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
2020-05-06 16:20:51 +02:00
Dim inputFooterHeight As String
Dim inputHeaderHeight As String
Dim inputFootnoteArea As String
2020-03-17 16:15:01 +01:00
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")
2020-05-06 16:20:51 +02:00
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
2020-03-17 16:15:01 +01:00
newWidth = curStyle.Width
newHeight = curStyle.height
newTopMargin = curStyle.TopMargin
newBottomMargin = curStyle.BottomMargin
newLeftMargin = curStyle.LeftMargin
newRightMargin = curStyle.RightMargin
2020-05-06 16:20:51 +02:00
If covertMMtoLong(inputFootnoteArea) > 0 Then
Dim footnoteArea As Long
footnoteArea = covertMMtoLong(inputFootnoteArea)
curStyle.FootnoteHeight = footnoteArea
EndIf
2020-03-17 16:15:01 +01:00
2020-05-06 16:20:51 +02:00
If covertMMtoLong(inputHeaderBodyDistance) > 0 Then
headerBodyDistance = covertMMtoLong(inputHeaderBodyDistance)
2020-03-17 16:15:01 +01:00
curStyle.HeaderBodyDistance = headerBodyDistance
EndIf
2020-05-06 16:20:51 +02:00
If covertMMtoLong(inputFooterBodyDistance) > 0 Then
footerBodyDistance = covertMMtoLong(inputFooterBodyDistance)
2020-03-17 16:15:01 +01:00
curStyle.FooterBodyDistance = footerBodyDistance
EndIf
2020-05-06 16:20:51 +02:00
If covertMMtoLong(inputFootnoteLineDistance) > 0 Then
footnoteLineDistance = covertMMtoLong(inputFootnoteLineDistance)
2020-03-17 16:15:01 +01:00
curStyle.FootnoteLineDistance = footnoteLineDistance
EndIf
2020-05-06 16:20:51 +02:00
If covertMMtoLong(inputFootnoteLineTextDistance) > 0 Then
footnoteLineTextDistance = covertMMtoLong(inputFootnoteLineTextDistance)
2020-03-17 16:15:01 +01:00
curStyle.FootnoteLineTextDistance = footnoteLineTextDistance
EndIf
2020-05-06 16:20:51 +02:00
If covertMMtoLong(inputFooterHeight) > 0 Then
Dim footerHeight As Long
footerHeight = covertMMtoLong(inputFooterHeight)
curStyle.FooterIsOn = true
curStyle.FooterIsDynamicHeight = false
curStyle.FooterHeight = footerHeight + curStyle.FooterBodyDistance
EndIf
2020-03-17 16:15:01 +01:00
2020-05-06 16:20:51 +02:00
If covertMMtoLong(inputHeaderHeight) > 0 Then
Dim headerHeight As Long
headerHeight = covertMMtoLong(inputHeaderHeight)
curStyle.HeaderIsOn = true
curStyle.HeaderIsDynamicHeight = false
curStyle.HeaderHeight = headerHeight + curStyle.HeaderBodyDistance
EndIf
2020-03-17 16:15:01 +01:00
If curstyle.IsLandscape Then
2020-05-06 16:20:51 +02:00
If covertMMtoLong(inputHeight) > 0 Then
newWidth = covertMMtoLong(inputHeight)
2020-03-17 16:15:01 +01:00
EndIf
2020-05-06 16:20:51 +02:00
If covertMMtoLong(inputWidth) > 0 Then
newHeight = covertMMtoLong(inputWidth)
2020-03-17 16:15:01 +01:00
EndIf
2020-05-06 16:20:51 +02:00
If covertMMtoLong(inputLeftMargin) > 0 Then
newTopMargin = covertMMtoLong(inputLeftMargin)
2020-03-17 16:15:01 +01:00
EndIf
2020-05-06 16:20:51 +02:00
If covertMMtoLong(inputRightMargin) > 0 Then
newBottomMargin = covertMMtoLong(inputRightMargin)
2020-03-17 16:15:01 +01:00
EndIf
2020-05-06 16:20:51 +02:00
If covertMMtoLong(inputTopMargin) > 0 Then
newLeftMargin = covertMMtoLong(inputTopMargin)
2020-03-17 16:15:01 +01:00
EndIf
2020-05-06 16:20:51 +02:00
If covertMMtoLong(inputBottomMargin) > 0 Then
newRightMargin = covertMMtoLong(inputBottomMargin)
2020-03-17 16:15:01 +01:00
EndIf
Else
2020-05-06 16:20:51 +02:00
If covertMMtoLong(inputWidth) > 0 Then
newWidth = covertMMtoLong(inputWidth)
2020-03-17 16:15:01 +01:00
EndIf
2020-05-06 16:20:51 +02:00
If covertMMtoLong(inputHeight) > 0 Then
newHeight = covertMMtoLong(inputHeight)
2020-03-17 16:15:01 +01:00
EndIf
2020-05-06 16:20:51 +02:00
If covertMMtoLong(inputTopMargin) > 0 Then
newTopMargin = covertMMtoLong(inputTopMargin)
2020-03-17 16:15:01 +01:00
EndIf
2020-05-06 16:20:51 +02:00
If covertMMtoLong(inputBottomMargin) > 0 Then
newBottomMargin = covertMMtoLong(inputBottomMargin)
2020-03-17 16:15:01 +01:00
EndIf
2020-05-06 16:20:51 +02:00
If covertMMtoLong(inputLeftMargin) > 0 Then
newLeftMargin = covertMMtoLong(inputLeftMargin)
2020-03-17 16:15:01 +01:00
EndIf
2020-05-06 16:20:51 +02:00
If covertMMtoLong(inputRightMargin) > 0 Then
newRightMargin = covertMMtoLong(inputRightMargin)
2020-03-17 16:15:01 +01:00
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
2020-05-06 16:20:51 +02:00
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
2020-03-17 16:15:01 +01:00
</script:module>