Page styles config working
This commit is contained in:
parent
23f8834361
commit
c3f28049e7
6 changed files with 1665 additions and 1557 deletions
|
@ -1,14 +1,15 @@
|
|||
<?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">Sub pageStylesDialog
|
||||
DialogLibraries.LoadLibrary("ePublishing")
|
||||
Dim dialog As Object
|
||||
<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
|
||||
|
@ -18,31 +19,19 @@
|
|||
displayPageStyleNames(i) = pageStyle.displayName
|
||||
Next i
|
||||
subShellSort(displayPageStyleNames)
|
||||
|
||||
dialog = CreateUnoDialog( DialogLibraries.ePublishing.PageConfig )
|
||||
Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
|
||||
DialogLibraries.LoadLibrary("ePublishing")
|
||||
pDialog = CreateUnoDialog( DialogLibraries.ePublishing.PageConfig )
|
||||
imageURL = convertToURL(getExtensionPath() + "/images/panel.svg")
|
||||
dialog.getControl("ImageControl1").model.imageURL = imageURL
|
||||
dialog.getControl("description").setText(getTranslation("PageConfigDialogTranslations"))
|
||||
|
||||
dialog.getControl("pageHeight").setText("")
|
||||
dialog.getControl("pageWidth").setText("")
|
||||
dialog.getControl("leftPageMargin").setText("")
|
||||
dialog.getControl("topPageMargin").setText("")
|
||||
dialog.getControl("rightPageMargin").setText("")
|
||||
dialog.getControl("bottomPageMargin").setText("")
|
||||
dialog.getControl("headerHeight").setText("")
|
||||
dialog.getControl("headerOffset").setText("")
|
||||
dialog.getControl("footerHeight").setText("")
|
||||
dialog.getControl("footerOffset").setText("")
|
||||
dialog.getControl("footnoteAreaHeight").setText("")
|
||||
dialog.getControl("footnoteAreaOffset").setText("")
|
||||
dialog.getControl("Cancel").Label = getTranslation("PageConfigDialogCancelButton")
|
||||
dialog.getControl("Ok").Label = getTranslation("PageConfigDialogOkButton")
|
||||
listBox = dialog.getControl("pageStyles")
|
||||
pDialog.getControl("ImageControl1").model.imageURL = imageURL
|
||||
pDialog.getControl("description").setText(getTranslation("PageConfigDialogTranslations"))
|
||||
cleanPageSettings()
|
||||
pDialog.getControl("Cancel").Label = getTranslation("PageConfigDialogCancelButton")
|
||||
pDialog.getControl("Ok").Label = getTranslation("PageConfigDialogOkButton")
|
||||
listBox = pDialog.getControl("pageStyles")
|
||||
listBox.addItems(displayPageStyleNames, 0)
|
||||
dialog.Title = getTranslation("PageConfigDialogTitle")
|
||||
dialog.Execute()
|
||||
pDialog.Title = getTranslation("PageConfigDialogTitle")
|
||||
pDialog.Execute()
|
||||
pDialog.dispose()
|
||||
End Sub
|
||||
|
||||
Function getExtensionPath As String
|
||||
|
@ -54,7 +43,128 @@ Function getExtensionPath As String
|
|||
End Function
|
||||
|
||||
|
||||
Sub setDimensions
|
||||
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("")
|
||||
'Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
|
||||
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
|
||||
|
@ -66,6 +176,9 @@ Sub setDimensions
|
|||
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
|
||||
|
@ -81,85 +194,112 @@ Sub setDimensions
|
|||
Dim footnoteLineTextDistance As Long
|
||||
|
||||
oStyles = ThisComponent.StyleFamilies.getByName("PageStyles")
|
||||
inputWidth = InputBox("Введите ширину страниц (в мм):", "Установка ширины всех страниц документа", "")
|
||||
inputHeight = InputBox("Введите высоту страниц (в мм):", "Установка высоты всех страниц документа", "")
|
||||
inputTopMargin = InputBox("Введите размер верхнего поля (в мм):", "Установка размера верхнего поля для всех страниц", "")
|
||||
inputBottomMargin = InputBox("Введите резмер нижнего поля (в мм):", "Установка размера нижнего поля для всех страниц", "")
|
||||
inputLeftMargin = InputBox("Введите размер левого поля (в мм):", "Установка размера левого поля для всех страниц", "")
|
||||
inputRightMargin = InputBox("Введите размер правого поля (в мм):", "Установка размера правого поля для всех страниц", "")
|
||||
inputHeaderBodyDistance = InputBox("Введите расстояние от верхнего колонтитула до текста (в сотых долях мм):", "Установка расстояния от верхнего колонтитула до текста", "")
|
||||
inputFooterBodyDistance = InputBox("Введите расстояние от нижнего колонтитула до текста (в сотых долях мм):", "Установка расстояния от нижнего колонтитула до текста ", "")
|
||||
inputFootnoteLineTextDistance = InputBox("Введите расстояние от текста страницы до линии сноски (в сотых долях мм):", "Установка расстояния от текста страницы до линии сноски ", "")
|
||||
inputFootnoteLineDistance = InputBox("Введите расстояние от линии сноски до текста сноски (в сотых долях мм):", "Установка расстояния от линии сноски до текста сноски ", "")
|
||||
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()
|
||||
|
||||
For i = 0 to oStyles.Count - 1
|
||||
curStyle = oStyles.getByIndex(i)
|
||||
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 CLng(inputHeaderBodyDistance) > 0 Then
|
||||
headerBodyDistance = CLng(inputHeaderBodyDistance)
|
||||
If covertMMtoLong(inputHeaderBodyDistance) > 0 Then
|
||||
headerBodyDistance = covertMMtoLong(inputHeaderBodyDistance)
|
||||
curStyle.HeaderBodyDistance = headerBodyDistance
|
||||
EndIf
|
||||
If CLng(inputFooterBodyDistance) > 0 Then
|
||||
footerBodyDistance = CLng(inputFooterBodyDistance)
|
||||
If covertMMtoLong(inputFooterBodyDistance) > 0 Then
|
||||
footerBodyDistance = covertMMtoLong(inputFooterBodyDistance)
|
||||
curStyle.FooterBodyDistance = footerBodyDistance
|
||||
EndIf
|
||||
|
||||
If CLng(inputFootnoteLineDistance) > 0 Then
|
||||
footnoteLineDistance = CLng(inputFootnoteLineDistance)
|
||||
If covertMMtoLong(inputFootnoteLineDistance) > 0 Then
|
||||
footnoteLineDistance = covertMMtoLong(inputFootnoteLineDistance)
|
||||
curStyle.FootnoteLineDistance = footnoteLineDistance
|
||||
EndIf
|
||||
If CLng(inputFootnoteLineTextDistance) > 0 Then
|
||||
footnoteLineTextDistance = CLng(inputFootnoteLineTextDistance)
|
||||
If covertMMtoLong(inputFootnoteLineTextDistance) > 0 Then
|
||||
footnoteLineTextDistance = covertMMtoLong(inputFootnoteLineTextDistance)
|
||||
curStyle.FootnoteLineTextDistance = footnoteLineTextDistance
|
||||
EndIf
|
||||
'Globalscope.BasicLibraries.LoadLibrary( "MRILib" )
|
||||
'Mri curStyle
|
||||
|
||||
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 CLng(inputHeight) > 0 Then
|
||||
newWidth = CLng(inputHeight + "00")
|
||||
If covertMMtoLong(inputHeight) > 0 Then
|
||||
newWidth = covertMMtoLong(inputHeight)
|
||||
EndIf
|
||||
If CLng(inputWidth) > 0 Then
|
||||
newHeight = CLng(inputWidth + "00")
|
||||
If covertMMtoLong(inputWidth) > 0 Then
|
||||
newHeight = covertMMtoLong(inputWidth)
|
||||
EndIf
|
||||
|
||||
If CLng(inputLeftMargin) > 0 Then
|
||||
newTopMargin = CLng(inputLeftMargin + "00")
|
||||
If covertMMtoLong(inputLeftMargin) > 0 Then
|
||||
newTopMargin = covertMMtoLong(inputLeftMargin)
|
||||
EndIf
|
||||
If CLng(inputRightMargin) > 0 Then
|
||||
newBottomMargin = CLng(inputRightMargin + "00")
|
||||
If covertMMtoLong(inputRightMargin) > 0 Then
|
||||
newBottomMargin = covertMMtoLong(inputRightMargin)
|
||||
EndIf
|
||||
If CLng(inputTopMargin) > 0 Then
|
||||
newLeftMargin = CLng(inputTopMargin + "00")
|
||||
If covertMMtoLong(inputTopMargin) > 0 Then
|
||||
newLeftMargin = covertMMtoLong(inputTopMargin)
|
||||
EndIf
|
||||
If CLng(inputBottomMargin) > 0 Then
|
||||
newRightMargin = CLng(inputBottomMargin + "00")
|
||||
If covertMMtoLong(inputBottomMargin) > 0 Then
|
||||
newRightMargin = covertMMtoLong(inputBottomMargin)
|
||||
EndIf
|
||||
|
||||
Else
|
||||
If CLng(inputWidth) > 0 Then
|
||||
newWidth = CLng(inputWidth + "00")
|
||||
If covertMMtoLong(inputWidth) > 0 Then
|
||||
newWidth = covertMMtoLong(inputWidth)
|
||||
EndIf
|
||||
If CLng(inputHeight) > 0 Then
|
||||
newHeight = CLng(inputHeight + "00")
|
||||
If covertMMtoLong(inputHeight) > 0 Then
|
||||
newHeight = covertMMtoLong(inputHeight)
|
||||
EndIf
|
||||
If CLng(inputTopMargin) > 0 Then
|
||||
newTopMargin = CLng(inputTopMargin + "00")
|
||||
If covertMMtoLong(inputTopMargin) > 0 Then
|
||||
newTopMargin = covertMMtoLong(inputTopMargin)
|
||||
EndIf
|
||||
If CLng(inputBottomMargin) > 0 Then
|
||||
newBottomMargin = CLng(inputBottomMargin + "00")
|
||||
If covertMMtoLong(inputBottomMargin) > 0 Then
|
||||
newBottomMargin = covertMMtoLong(inputBottomMargin)
|
||||
EndIf
|
||||
If CLng(inputLeftMargin) > 0 Then
|
||||
newLeftMargin = CLng(inputLeftMargin + "00")
|
||||
If covertMMtoLong(inputLeftMargin) > 0 Then
|
||||
newLeftMargin = covertMMtoLong(inputLeftMargin)
|
||||
EndIf
|
||||
If CLng(inputRightMargin) > 0 Then
|
||||
newRightMargin = CLng(inputRightMargin + "00")
|
||||
If covertMMtoLong(inputRightMargin) > 0 Then
|
||||
newRightMargin = covertMMtoLong(inputRightMargin)
|
||||
EndIf
|
||||
End If
|
||||
textFieldWidth = newWidth - newLeftMargin - newRightMargin
|
||||
|
@ -175,8 +315,35 @@ Sub setDimensions
|
|||
curStyle.TopMargin = newTopMargin
|
||||
curStyle.BottomMargin = newBottomMargin
|
||||
EndIf
|
||||
Next
|
||||
|
||||
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>
|
Loading…
Add table
Add a link
Reference in a new issue