summaryrefslogtreecommitdiff
path: root/wizards/source/tools/ModuleControls.xba
blob: 59c1363e55c97fb9b3ce7e9901c76471cbd91e6d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
<?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="ModuleControls" script:language="StarBasic">Option Explicit


&apos; Accepts the name of a control and returns the respective control model as object
&apos; The Container can either be a whole document or a specific sheet of a Calc-Document
&apos; &apos;CName&apos; is the name of the Control
Function getControlModel(oContainer as Object, CName as String)
Dim aForm, oForms as Object
Dim i as Integer
	oForms = oContainer.Drawpage.GetForms
	For i = 0 To oForms.Count-1
		aForm = oForms.GetbyIndex(i)
		If aForm.HasByName(CName) Then
			GetControlModel = aForm.GetbyName(CName)
			Exit Function
		End If
	Next i
	Msgbox(&quot;No Control with the name &apos;&quot; &amp; CName &amp; &quot;&apos; found&quot; , 16, GetProductName())
End Function



&apos; Gets the Shape of a Control( e. g. to reset the size or Position of the control
&apos; Parameters:
&apos; The &apos;oContainer&apos; is the Document or a specific sheet of a Calc - Document
&apos; &apos;CName&apos; is the Name of the Control
Function GetControlShape(oContainer as Object,CName as String)
Dim i as integer
Dim aShape as Object
	For i = 0 to oContainer.DrawPage.Count-1
		aShape = oContainer.DrawPage(i)
		If HasUnoInterfaces(aShape, &quot;com.sun.star.drawing.XControlShape&quot;) then
			If ashape.Control.Name = CName then
				GetControlShape = aShape
				exit Function
			End If
		End If
	Next
End Function


&apos; Returns the View of a Control
&apos; Parameters:
&apos; The &apos;oContainer&apos; is the Document or a specific sheet of a Calc - Document
&apos; The &apos;oController&apos; is always directly attached to the Document
&apos; &apos;CName&apos; is the Name of the Control
Function getControlView(oContainer , oController as Object, CName as String) as Object
Dim aForm, oForms, oControlModel as Object
Dim i as Integer
	oForms = oContainer.DrawPage.Forms
	For i = 0 To oForms.Count-1
		aForm = oforms.GetbyIndex(i)
		If aForm.HasByName(CName) Then
			oControlModel = aForm.GetbyName(CName)
			GetControlView = oController.GetControl(oControlModel)
			Exit Function
		End If
	Next i
	Msgbox(&quot;No Control with the name &apos;&quot; &amp; CName &amp; &quot;&apos; found&quot; , 16, GetProductName())
End Function



&apos; Parameters:
&apos; The &apos;oContainer&apos; is the Document or a specific sheet of a Calc - Document
&apos; &apos;CName&apos; is the Name of the Control
Function DisposeControl(oContainer as Object, CName as String) as Boolean
Dim aControl as Object

	aControl = GetControlModel(oContainer,CName)
	If not IsNull(aControl) Then
		aControl.Dispose()
		DisposeControl = True
	Else
		DisposeControl = False
	End If
End Function


&apos; Returns a sequence of a group of controls like option buttons or checkboxes
&apos; The &apos;oContainer&apos; is the Document or a specific sheet of a Calc - Document
&apos; &apos;sGroupName&apos; is the Name of the Controlgroup
Function GetControlGroupModel(oContainer as Object, sGroupName as String )
Dim aForm, oForms As Object
Dim aControlModel() As Object
Dim i as integer

	oForms = oContainer.DrawPage.Forms
	For i = 0 To oForms.Count-1
		aForm = oForms(i)
		If aForm.HasbyName(sGroupName) Then
			aForm.GetGroupbyName(sGroupName,aControlModel)
			GetControlGroupModel = aControlModel
			Exit Function
		End If
	Next i
	Msgbox(&quot;No Controlgroup with the name &apos;&quot; &amp; sGroupName &amp; &quot;&apos; found&quot; , 16, GetProductName())
End Function


&apos; Returns the Referencevalue of a group of e.g. option buttons or check boxes
&apos; &apos;oControlGroup&apos; is a sequence of the Control objects
Function GetRefValue(oControlGroup() as Object)
Dim i as Integer
	For i = 0 To Ubound(oControlGroup())
&apos;		oControlGroup(i).DefaultState = oControlGroup(i).State
		If oControlGroup(i).State Then
			GetRefValue = oControlGroup(i).RefValue
			exit Function
		End If
	Next
	Msgbox(&quot;No Control selected!&quot;,16, GetProductName())
End Function


Function GetRefValueOfControlGroup(oContainer as Object, GroupName as String)
Dim oOptGroup() as Object
Dim iRef as Integer
	oOptGroup() = GetControlGroupModel(oContainer, GroupName)
	iRef = GetRefValue(oOptGroup())
	GetRefValueofControlGroup = iRef
End Function


Function GetOptionGroupValue(oContainer as Object, OptGroupName as String) as Boolean
Dim oRulesOptions() as Object
	oRulesOptions() = GetControlGroupModel(oContainer, OptGroupName)
	GetOptionGroupValue = oRulesOptions(0).State
End Function



Function WriteOptValueToCell(oSheet as Object, OptGroupName as String, iCol as Integer, iRow as Integer) as Boolean
Dim bOptValue as Boolean
Dim oCell as Object
	bOptValue = GetOptionGroupValue(oSheet, OptGroupName)
	oCell = oSheet.GetCellByPosition(iCol, iRow)
	oCell.SetValue(ABS(CInt(bOptValue)))
	WriteOptValueToCell() = bOptValue
End Function


Function LoadDialog(Libname as String, DialogName as String, Optional oLibContainer)
Dim oLib as Object
Dim oLibDialog as Object
Dim oRuntimeDialog as Object
	If IsMissing(oLibContainer ) then
		oLibContainer = DialogLibraries
	End If
	oLibContainer.LoadLibrary(LibName)
	oLib = oLibContainer.GetByName(Libname)
	oLibDialog = oLib.GetByName(DialogName)
	oRuntimeDialog = CreateUnoDialog(oLibDialog)
	LoadDialog() = oRuntimeDialog
End Function


Sub SwitchWizardDialogHeight(oDialog as Object, sReduceDialog as String, sHeightenDialog as String)
Dim oDialogModel  as Object
Dim iDlgHeight as Integer
Dim iYPos as Integer
	oDialogModel = oDialog.Model
	If oDialogModel.Height &gt; 100 Then
		iDlgHeight = 26
		oDialog.GetControl(&quot;imgTheme&quot;).visible = false
		oDialog.GetControl(&quot;cmdSwitchHeight&quot;).Model.Label = CHR(9663)
		oDialog.GetControl(&quot;cmdSwitchHeight&quot;).Model.HelpText = sHeightenDialog
	Else
		iDlgHeight = 210
		oDialog.GetControl(&quot;imgTheme&quot;).visible = true
		oDialog.GetControl(&quot;cmdSwitchHeight&quot;).Model.Label = CHR(9653)
		oDialog.GetControl(&quot;cmdSwitchHeight&quot;).Model.HelpText = sReduceDialog
	End If
	iYPos = iDlgHeight - 20
	oDialogModel.cmdCancel.PositionY = iYPos
	oDialogModel.cmdHelp.PositionY = iYPos
&apos; Todo: Abfragen, ob in der Sequenze oDialogModel.GetControls()  auch ein cmdBack 
&apos; vorhanden ist
	oDialogModel.cmdBack.PositionY = iYPos
	oDialogModel.cmdGoOn.PositionY = iYPos
	oDialogModel.cmdSwitchHeight.PositionY = iYPos
	oDialogModel.Height = iDlgHeight
End Sub


Sub GetFolderName(oRefModel as Object)
Dim oFolderDialog
Dim iAccept as Integer
Dim sPath as String
Dim InitPath as String
Dim RefControlName as String
Dim oUcb as object
	oUcb = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
	oFolderDialog = CreateUnoService(&quot;com.sun.star.ui.dialogs.FolderPicker&quot;)
	InitPath = ConvertToUrl(oRefModel.Text)
	If oUcb.Exists(InitPath) Then
		oFolderDialog.SetDisplayDirectory(InitPath)
	End If
	iAccept = oFolderDialog.Execute()
	If iAccept = 1 Then
		sPath = oFolderDialog.GetDisplayDirectory()
		If oUcb.Exists(sPath) Then
			oRefModel.Text = ConvertFromUrl(sPath)
		End If
	End If
End Sub


Sub GetFileName(oRefModel as Object, Filternames())
Dim oFileDialog as Object
Dim iAccept as Integer
Dim sPath as String
Dim InitPath as String
Dim RefControlName as String
Dim oUcb as object
Dim i as Integer
Dim MaxIndex as Integer
	oUcb = createUnoService(&quot;com.sun.star.ucb.SimpleFileAccess&quot;)
	oFileDialog = CreateUnoService(&quot;com.sun.star.ui.dialogs.FilePicker&quot;)
	MaxIndex = Ubound(FilterNames())
	For i = 0 To MaxIndex
		oFileDialog.AppendFilter(FilterNames(i,0), FilterNames(i,1))
	Next i
	oFileDialog.SetCurrentFilter(FilterNames(0,0)
	InitPath = ConvertToUrl(oRefModel.Text)
	If oUcb.Exists(InitPath) Then
		oFileDialog.SetDisplayDirectory(InitPath)
	End If
	iAccept = oFileDialog.Execute()
	If iAccept = 1 Then
		sPath = oFileDialog.Files(0)
		If oUcb.Exists(sPath) Then
			oRefModel.Text = ConvertFromUrl(sPath)
		End If
	End If
End Sub
</script:module>