1#
2# This file is part of the LibreOffice project.
3#
4# This Source Code Form is subject to the terms of the Mozilla Public
5# License, v. 2.0. If a copy of the MPL was not distributed with this
6# file, You can obtain one at http://mozilla.org/MPL/2.0/.
7#
8# This file incorporates work covered by the following license notice:
9#
10#   Licensed to the Apache Software Foundation (ASF) under one or more
11#   contributor license agreements. See the NOTICE file distributed
12#   with this work for additional information regarding copyright
13#   ownership. The ASF licenses this file to you under the Apache
14#   License, Version 2.0 (the "License"); you may not use this file
15#   except in compliance with the License. You may obtain a copy of
16#   the License at http://www.apache.org/licenses/LICENSE-2.0 .
17#
18from .UnoDialog import UnoDialog, UIConsts
19from ..common.Desktop import Desktop
20from ..common.PropertyNames import PropertyNames
21from .event.CommonListener import ItemListenerProcAdapter, \
22    ActionListenerProcAdapter, TextListenerProcAdapter, \
23    AdjustmentListenerProcAdapter
24
25'''
26This class contains convenience methods for inserting components to a dialog.
27It was created for use with the automatic conversion of Basic XML Dialog
28description files to a Java class which builds
29the same dialog through the UNO API.<br/>
30It uses an Event-Listener method, which calls a method through reflection
31when an event on a component is triggered.
32see the classes CommonListener for details
33'''
34
35class UnoDialog2(UnoDialog):
36
37    '''
38    Override this method to return another listener.
39    @return
40    '''
41
42    def __init__(self, xmsf):
43        super(UnoDialog2,self).__init__(xmsf,(), ())
44        ControlList = {}
45
46    def insertButton(
47        self, sName, actionPerformed, sPropNames, oPropValues, listener):
48        xButton = self.insertControlModel(
49            "com.sun.star.awt.UnoControlButtonModel",
50            sName, sPropNames, oPropValues)
51        if actionPerformed is not None:
52            actionPerformed = getattr(listener, actionPerformed)
53            xButton.addActionListener(
54                ActionListenerProcAdapter(actionPerformed))
55
56        return xButton
57
58    def insertCheckBox(
59        self, sName, itemChanged, sPropNames, oPropValues, listener):
60        xCheckBox = self.insertControlModel(
61            "com.sun.star.awt.UnoControlCheckBoxModel",
62            sName, sPropNames, oPropValues)
63        if itemChanged is not None:
64            itemChanged = getattr(listener, itemChanged)
65            xCheckBox.addItemListener(ItemListenerProcAdapter(itemChanged))
66
67        return xCheckBox
68
69    def insertComboBox(
70        self, sName, actionPerformed, itemChanged,
71        textChanged, sPropNames, oPropValues, listener):
72        xComboBox = self.insertControlModel(
73        "com.sun.star.awt.UnoControlComboBoxModel",
74        sName, sPropNames, oPropValues)
75        if actionPerformed is not None:
76            actionPerformed = getattr(listener, actionPerformed)
77            xComboBox.addActionListener(
78                ActionListenerProcAdapter(actionPerformed))
79
80        if itemChanged is not None:
81            itemChanged = getattr(listener, itemChanged)
82            xComboBox.addItemListener(ItemListenerProcAdapter(itemChanged))
83
84        if textChanged is not None:
85            textChanged = getattr(listener, textChanged)
86            xComboBox.addTextListener(TextListenerProcAdapter(textChanged))
87
88        return xComboBox
89
90    def insertListBox(
91        self, sName, actionPerformed, itemChanged,
92        sPropNames, oPropValues, listener):
93        xListBox = self.insertControlModel(
94            "com.sun.star.awt.UnoControlListBoxModel",
95            sName, sPropNames, oPropValues)
96
97        if itemChanged is not None:
98            itemChanged = getattr(listener, itemChanged)
99            xListBox.addItemListener(ItemListenerProcAdapter(itemChanged))
100
101        return xListBox
102
103    def insertRadioButton(
104        self, sName, itemChanged, sPropNames, oPropValues, listener):
105        xRadioButton = self.insertControlModel(
106            "com.sun.star.awt.UnoControlRadioButtonModel",
107            sName, sPropNames, oPropValues)
108        if itemChanged is not None:
109            itemChanged = getattr(listener, itemChanged)
110            xRadioButton.addItemListener(
111                ItemListenerProcAdapter(itemChanged))
112
113        return xRadioButton
114
115    def insertTextField(
116        self, sName, sTextChanged, sPropNames, oPropValues, listener):
117        return self.insertEditField(
118            sName, sTextChanged, "com.sun.star.awt.UnoControlEditModel",
119            sPropNames, oPropValues, listener)
120
121    def insertImage(self, sName, sPropNames, oPropValues):
122        return self.insertControlModel(
123            "com.sun.star.awt.UnoControlImageControlModel",
124            sName, sPropNames, oPropValues)
125
126    def insertInfoImage(self, _posx, _posy, _iStep):
127        xImgControl = self.insertImage(
128            Desktop.getUniqueName(self.xDialogModel, "imgHint"),
129            ("Border",
130                PropertyNames.PROPERTY_HEIGHT,
131                PropertyNames.PROPERTY_IMAGEURL,
132                PropertyNames.PROPERTY_POSITION_X,
133                PropertyNames.PROPERTY_POSITION_Y, "ScaleImage",
134                PropertyNames.PROPERTY_STEP,
135                PropertyNames.PROPERTY_WIDTH),
136            (0, 10, UIConsts.INFOIMAGEURL, _posx, _posy, False, _iStep, 10))
137        return xImgControl
138
139    '''
140    This method is used for creating Edit, Currency, Date, Formatted,
141    Pattern, File and Time edit components.
142    '''
143
144    def insertEditField(
145        self, sName, sTextChanged, sModelClass,
146        sPropNames, oPropValues, listener):
147        xField = self.insertControlModel(sModelClass,
148            sName, sPropNames, oPropValues)
149        if sTextChanged is not None:
150            sTextChanged = getattr(listener, sTextChanged)
151            xField.addTextListener(TextListenerProcAdapter(sTextChanged))
152        return xField
153
154    def insertDateField(
155        self, sName, sTextChanged, sPropNames, oPropValues, listener):
156        return self.insertEditField(
157            sName, sTextChanged,
158            "com.sun.star.awt.UnoControlDateFieldModel",
159            sPropNames, oPropValues, listener)
160
161    def insertNumericField(
162        self, sName, sTextChanged, sPropNames, oPropValues, listener):
163        return self.insertEditField(
164            sName, sTextChanged,
165            "com.sun.star.awt.UnoControlNumericFieldModel",
166            sPropNames, oPropValues, listener)
167
168    def insertTimeField(
169        self, sName, sTextChanged, sPropNames, oPropValues, listener):
170        return self.insertEditField(
171            sName, sTextChanged,
172            "com.sun.star.awt.UnoControlTimeFieldModel",
173            sPropNames, oPropValues, listener)
174
175    def insertFixedLine(self, sName, sPropNames, oPropValues):
176        oLine = self.insertControlModel(
177            "com.sun.star.awt.UnoControlFixedLineModel",
178            sName, sPropNames, oPropValues)
179        return oLine
180
181    def insertLabel(self, sName, sPropNames, oPropValues):
182        oFixedText = self.insertControlModel(
183            "com.sun.star.awt.UnoControlFixedTextModel",
184            sName, sPropNames, oPropValues)
185        return oFixedText
186
187    def insertScrollBar(self, sName, sPropNames, oPropValues,
188            iControlKey, listener):
189        oScrollBar = self.insertControlModel(
190            "com.sun.star.awt.UnoControlScrollBarModel",
191            sName, sPropNames, oPropValues)
192        if listener is not None:
193            method = getattr(listener, "scrollControls")
194            oScrollBar.addAdjustmentListener(
195                AdjustmentListenerProcAdapter(method))
196        if self.ControlList is not None:
197            self.ControlList[sName] = iControlKey
198        return oScrollBar
199
200    def showMessageBox(self, windowServiceName, windowAttribute, MessageText):
201        return SystemDialog.showMessageBox(
202            xMSF, self.xControl.Peer,
203            windowServiceName, windowAttribute, MessageText)
204