110ce8018SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
310ce8018SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
410ce8018SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
510ce8018SAndrew Rist  * distributed with this work for additional information
610ce8018SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
710ce8018SAndrew Rist  * to you under the Apache License, Version 2.0 (the
810ce8018SAndrew Rist  * "License"); you may not use this file except in compliance
910ce8018SAndrew Rist  * with the License.  You may obtain a copy of the License at
1010ce8018SAndrew Rist  *
1110ce8018SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1210ce8018SAndrew Rist  *
1310ce8018SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1410ce8018SAndrew Rist  * software distributed under the License is distributed on an
1510ce8018SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1610ce8018SAndrew Rist  * KIND, either express or implied.  See the License for the
1710ce8018SAndrew Rist  * specific language governing permissions and limitations
1810ce8018SAndrew Rist  * under the License.
1910ce8018SAndrew Rist  *
2010ce8018SAndrew Rist  *************************************************************/
2110ce8018SAndrew Rist 
2210ce8018SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _CONTROLHELPER_HXX_
25cdf0e10cSrcweir #define _CONTROLHELPER_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <rtl/ustring.hxx>
28cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <list>
31cdf0e10cSrcweir #include <map>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir #include <premac.h>
34cdf0e10cSrcweir #include <Cocoa/Cocoa.h>
35cdf0e10cSrcweir #include <postmac.h>
36cdf0e10cSrcweir #include "SalAquaConstants.h"
37cdf0e10cSrcweir #include "FilterHelper.hxx"
38cdf0e10cSrcweir #include "AquaFilePickerDelegate.hxx"
39cdf0e10cSrcweir 
40cdf0e10cSrcweir using namespace com::sun::star;
41cdf0e10cSrcweir using namespace rtl;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir class ControlHelper {
44cdf0e10cSrcweir 
45cdf0e10cSrcweir public:
46cdf0e10cSrcweir 
47cdf0e10cSrcweir     //------------------------------------------------------------------------------------
48cdf0e10cSrcweir     // Constructor / Destructor
49cdf0e10cSrcweir     //------------------------------------------------------------------------------------
50cdf0e10cSrcweir     ControlHelper();
51cdf0e10cSrcweir     virtual ~ControlHelper();
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     //------------------------------------------------
54cdf0e10cSrcweir     // XInitialization delegate
55cdf0e10cSrcweir     //------------------------------------------------
56cdf0e10cSrcweir     void       initialize( sal_Int16 templateId );
57cdf0e10cSrcweir 
58cdf0e10cSrcweir     //------------------------------------------------------------------------------------
59cdf0e10cSrcweir     // XFilePickerControlAccess function delegates
60cdf0e10cSrcweir     //------------------------------------------------------------------------------------
61cdf0e10cSrcweir     void       setValue( sal_Int16 nControlId, sal_Int16 nControlAction, const uno::Any& rValue );
62cdf0e10cSrcweir     uno::Any   getValue( sal_Int16 nControlId, sal_Int16 nControlAction ) const;
63cdf0e10cSrcweir     void       enableControl( sal_Int16 nControlId, sal_Bool bEnable ) const;
64cdf0e10cSrcweir     OUString   getLabel( sal_Int16 nControlId );
65*d7e3d99bSHerbert Dürr     void       setLabel( sal_Int16 nControlId, NSString* aLabel );
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     //------------------------------------------------------------------------------------
68cdf0e10cSrcweir     // other stuff
69cdf0e10cSrcweir     //------------------------------------------------------------------------------------
70cdf0e10cSrcweir     void       updateFilterUI();
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     //------------------------------------------------------------------------------------
73cdf0e10cSrcweir     // Type definitions
74cdf0e10cSrcweir     //------------------------------------------------------------------------------------
75cdf0e10cSrcweir     enum ToggleType {
76cdf0e10cSrcweir         AUTOEXTENSION, //but autoextension is handled differently on MacOSX
77cdf0e10cSrcweir         PASSWORD,
78cdf0e10cSrcweir         FILTEROPTIONS,
79cdf0e10cSrcweir         READONLY,
80cdf0e10cSrcweir         LINK,
81cdf0e10cSrcweir         PREVIEW,
82cdf0e10cSrcweir         SELECTION,
83cdf0e10cSrcweir         TOGGLE_LAST
84cdf0e10cSrcweir     };
85cdf0e10cSrcweir 
86cdf0e10cSrcweir     enum ListType {
87cdf0e10cSrcweir         VERSION,
88cdf0e10cSrcweir         TEMPLATE,
89cdf0e10cSrcweir         IMAGE_TEMPLATE,
90cdf0e10cSrcweir         LIST_LAST
91cdf0e10cSrcweir     };
92cdf0e10cSrcweir 
93cdf0e10cSrcweir     //------------------------------------------------------------------------------------
94cdf0e10cSrcweir     // inline functions
95cdf0e10cSrcweir     //------------------------------------------------------------------------------------
getUserPane()96cdf0e10cSrcweir     inline NSView* getUserPane() {
97cdf0e10cSrcweir         if (m_bIsUserPaneLaidOut == false) {
98cdf0e10cSrcweir             createUserPane();
99cdf0e10cSrcweir         }
100cdf0e10cSrcweir         return m_pUserPane;
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir 
getVisibility(ToggleType tToggle)103cdf0e10cSrcweir     inline bool    getVisibility(ToggleType tToggle) {
104cdf0e10cSrcweir         return m_bToggleVisibility[tToggle];
105cdf0e10cSrcweir     }
106cdf0e10cSrcweir 
setFilterControlNeeded(bool bNeeded)107cdf0e10cSrcweir     inline void    setFilterControlNeeded(bool bNeeded) {
108cdf0e10cSrcweir         m_bIsFilterControlNeeded = bNeeded;
109cdf0e10cSrcweir         if (bNeeded == true) {
110cdf0e10cSrcweir             m_bUserPaneNeeded = true;
111cdf0e10cSrcweir         }
112cdf0e10cSrcweir     }
113cdf0e10cSrcweir 
setFilterHelper(FilterHelper * pFilterHelper)114cdf0e10cSrcweir     inline void    setFilterHelper(FilterHelper* pFilterHelper) {
115cdf0e10cSrcweir         m_pFilterHelper = pFilterHelper;
116cdf0e10cSrcweir     }
117cdf0e10cSrcweir 
setFilePickerDelegate(AquaFilePickerDelegate * pDelegate)118cdf0e10cSrcweir     inline void    setFilePickerDelegate(AquaFilePickerDelegate* pDelegate) {
119cdf0e10cSrcweir         m_pDelegate = pDelegate;
120cdf0e10cSrcweir     }
121cdf0e10cSrcweir 
isAutoExtensionEnabled()122cdf0e10cSrcweir     inline bool    isAutoExtensionEnabled() {
123cdf0e10cSrcweir         return ([((NSButton*) m_pToggles[AUTOEXTENSION]) state] == NSOnState);
124cdf0e10cSrcweir     }
125cdf0e10cSrcweir 
126cdf0e10cSrcweir private:
127cdf0e10cSrcweir     //------------------------------------------------------------------------------------
128cdf0e10cSrcweir     // private member variables
129cdf0e10cSrcweir     //------------------------------------------------------------------------------------
130cdf0e10cSrcweir 
131cdf0e10cSrcweir     /** the native view object */
132cdf0e10cSrcweir     NSView*    m_pUserPane;
133cdf0e10cSrcweir 
134cdf0e10cSrcweir     /** the checkbox controls */
135cdf0e10cSrcweir     NSControl* m_pToggles[ TOGGLE_LAST ];
136cdf0e10cSrcweir 
137cdf0e10cSrcweir     /** the visibility flags for the checkboxes */
138cdf0e10cSrcweir     bool m_bToggleVisibility[TOGGLE_LAST];
139cdf0e10cSrcweir 
140cdf0e10cSrcweir     /** the special filter control */
141cdf0e10cSrcweir     NSPopUpButton *m_pFilterControl;
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     /** the popup menu controls (except for the filter control) */
144cdf0e10cSrcweir     NSControl* m_pListControls[ LIST_LAST ];
145cdf0e10cSrcweir 
146cdf0e10cSrcweir     /** a map to store a control's label text */
147cdf0e10cSrcweir     ::std::map<NSControl *, NSString *> m_aMapListLabels;
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     /** a map to store a popup menu's label text field */
150cdf0e10cSrcweir     ::std::map<NSPopUpButton *, NSTextField *> m_aMapListLabelFields;
151cdf0e10cSrcweir 
152cdf0e10cSrcweir     /** the visibility flags for the popup menus */
153cdf0e10cSrcweir     bool m_bListVisibility[ LIST_LAST ];
154cdf0e10cSrcweir 
155cdf0e10cSrcweir     /** indicates if a user pane is needed */
156cdf0e10cSrcweir     bool m_bUserPaneNeeded;
157cdf0e10cSrcweir 
158cdf0e10cSrcweir     /** indicates if the user pane was laid out already */
159cdf0e10cSrcweir     bool m_bIsUserPaneLaidOut;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     /** indicates if a filter control is needed */
162cdf0e10cSrcweir     bool m_bIsFilterControlNeeded;
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     /** a list with all actively used controls */
165cdf0e10cSrcweir     ::std::list<NSControl*> m_aActiveControls;
166cdf0e10cSrcweir 
167cdf0e10cSrcweir     /** the filter helper */
168cdf0e10cSrcweir     FilterHelper *m_pFilterHelper;
169cdf0e10cSrcweir 
170cdf0e10cSrcweir     /** the save or open panel's delegate */
171cdf0e10cSrcweir     AquaFilePickerDelegate *m_pDelegate;
172cdf0e10cSrcweir 
173cdf0e10cSrcweir     //------------------------------------------------------------------------------------
174cdf0e10cSrcweir     // private methods
175cdf0e10cSrcweir     //------------------------------------------------------------------------------------
176cdf0e10cSrcweir     void HandleSetListValue(const NSControl* pControl, const sal_Int16 nControlAction, const uno::Any& rValue);
177cdf0e10cSrcweir     uno::Any HandleGetListValue(const NSControl* pControl, const sal_Int16 nControlAction) const;
178cdf0e10cSrcweir 
179cdf0e10cSrcweir     void         createControls();
180cdf0e10cSrcweir     void         createFilterControl();
181cdf0e10cSrcweir     void         createUserPane();
182*d7e3d99bSHerbert Dürr     NSTextField* createLabelWithString( NSString* label);
183cdf0e10cSrcweir 
184cdf0e10cSrcweir     int          getControlElementName(const Class clazz, const int nControlId) const;
185cdf0e10cSrcweir     NSControl*   getControl( const sal_Int16 nControlId ) const;
186cdf0e10cSrcweir     static int   getVerticalDistance(const NSControl* first, const NSControl* second);
187cdf0e10cSrcweir 
188cdf0e10cSrcweir     void         layoutControls();
189cdf0e10cSrcweir };
190cdf0e10cSrcweir 
191cdf0e10cSrcweir #endif //_CONTROLHELPER_HXX_
192