1 <?xml version=
"1.0" encoding=
"UTF-8"?>
2 <!DOCTYPE script:module PUBLIC
"-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "module.dtd">
3 <script:module xmlns:
script=
"http://openoffice.org/2000/script" script:
name=
"SF_DialogUtils" script:
language=
"StarBasic" script:
moduleType=
"normal">REM =======================================================================================================================
4 REM === The ScriptForge library and its associated libraries are part of the LibreOffice project. ===
5 REM === The SFDialogs library is one of the associated libraries. ===
6 REM === Full documentation is available on https://help.libreoffice.org/ ===
7 REM =======================================================================================================================
12 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
13 ''' SF_DialogUtils
14 ''' ========
15 ''' FOR INTERNAL USE ONLY
16 ''' Groups private functions that are common to the SF_Dialog and SF_DialogControl class modules
18 ''' Topics where SF_DialogUtils matters:
19 ''' - resizing dialog and dialog controls
20 '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
22 REM ================================================================== EXCEPTIONS
24 REM ============================================================ MODULE CONSTANTS
26 Public Const MINPOSITION = -
99999 ' Conventionally indicates
"do not change position
"
28 REM =========================================pvA================= PRIVATE METHODS
30 REM -----------------------------------------------------------------------------
31 Public Function _ConvertPointToAppFont(ByRef poView As Object _
35 ''' Convert the X, Y position expressed in pixels to a Point expressed in
"Map APPFONT
"
36 ''' Args:
37 ''' poView: a com.sun.star.awt.XControl - stardiv.Toolkit.UnoDialogControl
38 ''' plX, plY : the horizontal and vertical coordinates of the top-left corner of the control
39 ''' Returns:
40 ''' a com.sun.star.awt.Point object
42 Dim oPoint As New com.sun.star.awt.Point
' The input Point
43 Dim oReturn As Object
' Return value
48 Set oReturn = poView.convertPointToLogic(oPoint, com.sun.star.util.MeasureUnit.APPFONT)
51 Set _ConvertPointToAppFont = oReturn
53 End Function
' SFDialogs.SF_DialogUtils._ConvertPointToAppFont
55 REM -----------------------------------------------------------------------------
56 Public Function _ConvertPointToPixel(ByRef poView As Object _
60 ''' Convert the X, Y coordinates expressed in
"Map APPFONT
" units to a point expressed in pixels
61 ''' Args:
62 ''' poView: a com.sun.star.awt.XControl - stardiv.Toolkit.UnoDialogControl
63 ''' plX, plY : the horizontal and vertical coordinates of the top-left corner of the control
64 ''' Returns:
65 ''' a com.sun.star.awt.Point object
67 Dim oPoint As New com.sun.star.awt.Point
' The input point
68 Dim oReturn As Object
' Return value
73 Set oReturn = poView.convertPointToPixel(oPoint, com.sun.star.util.MeasureUnit.APPFONT)
76 Set _ConvertPointToPixel = oReturn
78 End Function
' SFDialogs.SF_DialogUtils._ConvertPointToPixel
80 REM -----------------------------------------------------------------------------
81 Public Function _ConvertSizeToAppFont(ByRef poView As Object _
82 , ByVal plWidth As Long _
83 , ByVal plHeight As Long _
85 ''' Convert the Width, Height dimensions expressed in pixels to a Size expressed in
"Map APPFONT
"
86 ''' Args:
87 ''' poView: a com.sun.star.awt.XControl - stardiv.Toolkit.UnoDialogControl
88 ''' plWidth, plHeight : the horizontal and vertical dimensions of the control
89 ''' Returns:
90 ''' a com.sun.star.awt.Size object
92 Dim oSize As New com.sun.star.awt.Size
' The input size
93 Dim oReturn As Object
' Return value
97 oSize.Height = plHeight
98 Set oReturn = poView.convertSizeToLogic(oSize, com.sun.star.util.MeasureUnit.APPFONT)
101 Set _ConvertSizeToAppFont = oReturn
103 End Function
' SFDialogs.SF_DialogUtils._ConvertSizeToAppFont
105 REM -----------------------------------------------------------------------------
106 Public Function _ConvertSizeToPixel(ByRef poView As Object _
107 , ByVal plWidth As Long _
108 , ByVal plHeight As Long _
110 ''' Convert the Width, Height dimensions expressed in
"Map APPFONT
" units to a Size expressed in pixels
111 ''' Args:
112 ''' poView: a com.sun.star.awt.XControl - stardiv.Toolkit.UnoDialogControl
113 ''' plWidth, plHeight : the horizontal and vertical dimensions of the control
114 ''' Returns:
115 ''' a com.sun.star.awt.Size object
117 Dim oSize As New com.sun.star.awt.Size
' The input size
118 Dim oReturn As Object
' Return value
121 oSize.Width = plWidth
122 oSize.Height = plHeight
123 Set oReturn = poView.convertSizeToPixel(oSize, com.sun.star.util.MeasureUnit.APPFONT)
126 Set _ConvertSizeToPixel = oReturn
128 End Function
' SFDialogs.SF_DialogUtils._ConvertSizeToPixel
130 REM -----------------------------------------------------------------------------
131 Public Function _ConvertToAppFont(ByRef poView As Object _
132 , ByVal pbPoint As Boolean _
134 ''' Switch between the _ConvertPointToAppFont and the _ConvertSizeToAppFont routines
135 ''' Args:
136 ''' poView: a com.sun.star.awt.XControl - stardiv.Toolkit.UnoDialogControl
137 ''' pbPoint: when True return a Point, otherwise return a Size
138 ''' Returns:
139 ''' a com.sun.star.awt.Point or a com.sun.star.awt.Size object
141 Static oSession As Object
' Alias of SF_Session
142 Dim oPosSize As Object
' com.sun.star.awt.Rectangle
145 If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService(
"Session
")
146 If oSession.HasUNOMethod(poView,
"getPosSize
") Then
147 Set oPosSize =poView.getPosSize()
148 Else
' Should not happen
149 Set oPosSize = New com.sun.star.awt.Rectangle
153 _ConvertToAppFont = _ConvertPointToAppFont(poView, oPosSize.X, oPosSize.Y)
' com.sun.star.awt.Point
155 _ConvertToAppFont = _ConvertSizeToAppFont(poView, oPosSize.Width, oPosSize.Height)
' com.sun.star.awt.Size
158 End Function
' SFDialogs.SF_DialogUtils._ConvertToAppFont
160 REM -----------------------------------------------------------------------------
161 Private Function _FormatsList(psControlType) As Variant
162 ''' Return the list of the allowed formats for Date and Time control types
163 ''' Args:
164 ''' DateField or TimeField control
165 ''' Returns:
166 ''' The allowed format entries as a zero-based array
168 Dim vFormats() As Variant
' Return value
169 Const CTLDATEFIELD =
"DateField
"
170 Const CTLTIMEFIELD =
"TimeField
"
172 Select Case psControlType
175 "Standard (short)
" _
176 ,
"Standard (short YY)
" _
177 ,
"Standard (short YYYY)
" _
178 ,
"Standard (long)
" _
179 ,
"DD/MM/YY
" _
180 ,
"MM/DD/YY
" _
181 ,
"YY/MM/DD
" _
182 ,
"DD/MM/YYYY
" _
183 ,
"MM/DD/YYYY
" _
184 ,
"YYYY/MM/DD
" _
185 ,
"YY-MM-DD
" _
186 ,
"YYYY-MM-DD
" _
190 "24h short
" _
191 ,
"24h long
" _
192 ,
"12h short
" _
193 ,
"12h long
" _
199 _FormatsList = vFormats
201 End Function
' SFDialogs.SF_DialogUtils._FormatsList
203 REM -----------------------------------------------------------------------------
204 Public Function _Resize(ByRef Control As Object _
205 , Optional ByVal Left As Variant _
206 , Optional ByVal Top As Variant _
207 , Optional ByVal Width As Variant _
208 , Optional ByVal Height As Variant _
210 ''' Move the top-left corner of a dialog or a dialog control to new coordinates and/or modify its dimensions
211 ''' Without arguments, the method either:
212 ''' leaves the position unchanged and computes best fit dimensions
213 ''' resets the initial position and dimensions (Scrollbar, ProgressBar, FixedLine, GroupBox, TreeControl
", TableControl)
214 ''' Attributes denoting the position and size of a dialog are expressed in
"Map AppFont
" units.
215 ''' Map AppFont units are device and resolution independent.
216 ''' One Map AppFont unit is equal to one eighth of the average character (Systemfont) height and one quarter of the average character width.
217 ''' The dialog editor (= the Basic IDE) also uses Map AppFont units.
218 ''' Args:
219 ''' Control: a SF_Dialog or SF_DialogControl class instance
220 ''' Left : the horizontal distance from the top-left corner
221 ''' Top : the vertical distance from the top-left corner
222 ''' Width : the horizontal width of the rectangle containing the Dialog[Control]
223 ''' Height : the vertical height of the rectangle containing the Dialog[Control]
224 ''' Negative or missing arguments are left unchanged.
225 ''' Returns:
226 ''' True when successful
228 Dim bResize As Boolean
' Return value
229 Dim oModel As Object
' Model of Control object
230 Dim oView As Object
' View of Control object
231 Dim Displayed As Boolean
' When Trs, the dialog is currently active
232 Dim oSize As Object
' com.sun.star.awt.Size
233 Dim oPoint As Object
' com.sun.star.awt.Point
234 Dim oPreferredSize As Object
' com.sun.star.awt.Size
235 Dim iFlags As Integer
' com.sun.star.awt.PosSize constants
236 Static oSession As Object
' SF_Session alias
237 Dim cstThisSub As String
238 Const cstSubArgs =
"[Left], [Top], [Width], [Height]
"
240 If ScriptForge.SF_Utils._ErrorHandling() Then On Local Error GoTo Catch
244 If IsNull(Control) Then GoTo Finally
245 If IsMissing(Left) Or IsEmpty(Left) Then Left = MINPOSITION
246 If IsMissing(Top) Or IsEmpty(Top) Then Top = MINPOSITION
247 If IsMissing(Height) Or IsEmpty(Height) Then Height = -
1
248 If IsMissing(Width) Or IsEmpty(Width) Then Width = -
1
249 If ScriptForge.SF_Utils._EnterFunction(cstThisSub, cstSubArgs) Then
250 If Not ScriptForge.SF_Utils._Validate(Left,
"Left
", ScriptForge.V_NUMERIC) Then GoTo Finally
251 If Not ScriptForge.SF_Utils._Validate(Top,
"Top
", ScriptForge.V_NUMERIC) Then GoTo Finally
252 If Not ScriptForge.SF_Utils._Validate(Width,
"Width
", ScriptForge.V_NUMERIC) Then GoTo Finally
253 If Not ScriptForge.SF_Utils._Validate(Height,
"Height
", ScriptForge.V_NUMERIC) Then GoTo Finally
258 ' Initialize local variables depending on caller
259 Select Case .ObjectType
260 Case
"DIALOG
"
261 cstThisSub =
"SFDialogs.Dialog.Resize
"
262 Set oModel = ._DialogModel
263 Set oView = ._DialogControl
264 Displayed = ._Displayed
265 Case
"DIALOGCONTROL
"
266 cstThisSub =
"SFDialogs.DialogControl.Resize
"
267 Set oModel = ._ControlModel
268 Set oView = ._ControlView
269 Displayed = .[Parent]._Displayed
272 ' Manage absence of arguments: best fit or reset
273 If Left = MINPOSITION And Top = MINPOSITION And Width = -
1 And Height = -
1 Then
274 If IsNull(oSession) Then Set oSession = ScriptForge.SF_Services.CreateScriptService(
"ScriptForge.Session
")
275 If oSession.HasUnoMethod(oView,
"getPreferredSize
") Then
276 ' Compute a best fit size when relevant
277 Set oPreferredSize = oView.getPreferredSize()
278 Set oSize = SF_DialogUtils._ConvertSizeToAppFont(oView, oPreferredSize.Width, oPreferredSize.Height)
280 Height = oSize.Height
282 ' Reset factory settings otherwise
291 ' Model sizes are in APPFONTs, View sizes are in pixels. Use view.convertSizeToPixel() to convert
292 ' For dynamic dialogs: convertSizeToPixel() is available only as from the dialog is made visible
293 ' =
> When the dialog is visible, positions and sizes are updated in view
294 ' When the dialog is not visible, positions and sizes adapted on model
297 ' Trace the elements to change
299 With com.sun.star.awt.PosSize
300 If Left
> MINPOSITION Then iFlags = iFlags + .X Else Left =
0
301 If Top
> MINPOSITION Then iFlags = iFlags + .Y Else Top =
0
302 If Width
> 0 Then iFlags = iFlags + .WIDTH Else Width =
0
303 If Height
> 0 Then iFlags = iFlags + .HEIGHT Else Height =
0
305 ' Convert APPFONT units to pixels
306 Set oPoint = SF_DialogUtils._ConvertPointToPixel(oView, CLng(Left), CLng(Top))
307 Set oSize = SF_DialogUtils._ConvertSizeToPixel(oView, CLng(Width), CLng(Height))
309 If iFlags
> 0 Then .setPosSize(oPoint.X, oPoint.Y, oSize.Width, oSize.Height, iFlags)
313 ' Store position and dimensions in APPFONT units
314 If Left
> MINPOSITION Then .PositionX = CLng(Left)
315 If Top
> MINPOSITION Then .PositionY = CLng(Top)
316 If Width
> 0 Then .Width = CLng(Width)
317 If Height
> 0 Then .Height = CLng(Height)
324 ScriptForge.SF_Utils._ExitFunction(cstThisSub)
328 End Function
' SFDialogss.SF_DialogUtils._Resize
330 REM ============================================= END OF SFDIALOGS.SF_DIALOGUTILS