1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _CONTROLHELPER_HXX_
29 #define _CONTROLHELPER_HXX_
30 
31 #include <rtl/ustring.hxx>
32 #include <com/sun/star/uno/Any.hxx>
33 
34 #include <list>
35 #include <map>
36 
37 #include <premac.h>
38 #include <Cocoa/Cocoa.h>
39 #include <postmac.h>
40 #include "SalAquaConstants.h"
41 #include "FilterHelper.hxx"
42 #include "AquaFilePickerDelegate.hxx"
43 
44 using namespace com::sun::star;
45 using namespace rtl;
46 
47 class ControlHelper {
48 
49 public:
50 
51     //------------------------------------------------------------------------------------
52     // Constructor / Destructor
53     //------------------------------------------------------------------------------------
54     ControlHelper();
55     virtual ~ControlHelper();
56 
57     //------------------------------------------------
58     // XInitialization delegate
59     //------------------------------------------------
60     void       initialize( sal_Int16 templateId );
61 
62     //------------------------------------------------------------------------------------
63     // XFilePickerControlAccess function delegates
64     //------------------------------------------------------------------------------------
65     void       setValue( sal_Int16 nControlId, sal_Int16 nControlAction, const uno::Any& rValue );
66     uno::Any   getValue( sal_Int16 nControlId, sal_Int16 nControlAction ) const;
67     void       enableControl( sal_Int16 nControlId, sal_Bool bEnable ) const;
68     OUString   getLabel( sal_Int16 nControlId );
69     void       setLabel( sal_Int16 nControlId, const NSString* aLabel );
70 
71     //------------------------------------------------------------------------------------
72     // other stuff
73     //------------------------------------------------------------------------------------
74     void       updateFilterUI();
75 
76     //------------------------------------------------------------------------------------
77     // Type definitions
78     //------------------------------------------------------------------------------------
79     enum ToggleType {
80         AUTOEXTENSION, //but autoextension is handled differently on MacOSX
81         PASSWORD,
82         FILTEROPTIONS,
83         READONLY,
84         LINK,
85         PREVIEW,
86         SELECTION,
87         TOGGLE_LAST
88     };
89 
90     enum ListType {
91         VERSION,
92         TEMPLATE,
93         IMAGE_TEMPLATE,
94         LIST_LAST
95     };
96 
97     //------------------------------------------------------------------------------------
98     // inline functions
99     //------------------------------------------------------------------------------------
100     inline NSView* getUserPane() {
101         if (m_bIsUserPaneLaidOut == false) {
102             createUserPane();
103         }
104         return m_pUserPane;
105     }
106 
107     inline bool    getVisibility(ToggleType tToggle) {
108         return m_bToggleVisibility[tToggle];
109     }
110 
111     inline void    setFilterControlNeeded(bool bNeeded) {
112         m_bIsFilterControlNeeded = bNeeded;
113         if (bNeeded == true) {
114             m_bUserPaneNeeded = true;
115         }
116     }
117 
118     inline void    setFilterHelper(FilterHelper* pFilterHelper) {
119         m_pFilterHelper = pFilterHelper;
120     }
121 
122     inline void    setFilePickerDelegate(AquaFilePickerDelegate* pDelegate) {
123         m_pDelegate = pDelegate;
124     }
125 
126     inline bool    isAutoExtensionEnabled() {
127         return ([((NSButton*) m_pToggles[AUTOEXTENSION]) state] == NSOnState);
128     }
129 
130 private:
131     //------------------------------------------------------------------------------------
132     // private member variables
133     //------------------------------------------------------------------------------------
134 
135     /** the native view object */
136     NSView*    m_pUserPane;
137 
138     /** the checkbox controls */
139     NSControl* m_pToggles[ TOGGLE_LAST ];
140 
141     /** the visibility flags for the checkboxes */
142     bool m_bToggleVisibility[TOGGLE_LAST];
143 
144     /** the special filter control */
145     NSPopUpButton *m_pFilterControl;
146 
147     /** the popup menu controls (except for the filter control) */
148     NSControl* m_pListControls[ LIST_LAST ];
149 
150     /** a map to store a control's label text */
151     ::std::map<NSControl *, NSString *> m_aMapListLabels;
152 
153     /** a map to store a popup menu's label text field */
154     ::std::map<NSPopUpButton *, NSTextField *> m_aMapListLabelFields;
155 
156     /** the visibility flags for the popup menus */
157     bool m_bListVisibility[ LIST_LAST ];
158 
159     /** indicates if a user pane is needed */
160     bool m_bUserPaneNeeded;
161 
162     /** indicates if the user pane was laid out already */
163     bool m_bIsUserPaneLaidOut;
164 
165     /** indicates if a filter control is needed */
166     bool m_bIsFilterControlNeeded;
167 
168     /** a list with all actively used controls */
169     ::std::list<NSControl*> m_aActiveControls;
170 
171     /** the filter helper */
172     FilterHelper *m_pFilterHelper;
173 
174     /** the save or open panel's delegate */
175     AquaFilePickerDelegate *m_pDelegate;
176 
177     //------------------------------------------------------------------------------------
178     // private methods
179     //------------------------------------------------------------------------------------
180     void HandleSetListValue(const NSControl* pControl, const sal_Int16 nControlAction, const uno::Any& rValue);
181     uno::Any HandleGetListValue(const NSControl* pControl, const sal_Int16 nControlAction) const;
182 
183     void         createControls();
184     void         createFilterControl();
185     void         createUserPane();
186     NSTextField* createLabelWithString(const NSString* label);
187 
188     int          getControlElementName(const Class clazz, const int nControlId) const;
189     NSControl*   getControl( const sal_Int16 nControlId ) const;
190     static int   getVerticalDistance(const NSControl* first, const NSControl* second);
191 
192     void         layoutControls();
193 };
194 
195 #endif //_CONTROLHELPER_HXX_
196