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