xref: /aoo42x/main/cui/source/inc/treeopt.hxx (revision c7be74b1)
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 #include <com/sun/star/uno/Reference.h>
25 #include <sfx2/basedlgs.hxx>
26 #include <sfx2/tabdlg.hxx>
27 #include <svtools/svtreebx.hxx>
28 #include <tools/resary.hxx>
29 #include <vcl/image.hxx>
30 #include <vcl/fixbrd.hxx>
31 #include <vcl/fixed.hxx>
32 
33 #include <vector>
34 
35 // static ----------------------------------------------------------------
36 
37 sal_Bool            EnableSSO();
38 CreateTabPage   GetSSOCreator( void );
39 
40 // class OfaOptionsTreeListBox -------------------------------------------
41 
42 //!#define NUMBER_OF_OPTION_PAGES  12
43 class SfxModule;
44 class SfxShell;
45 class SfxItemSet;
46 class XColorList;
47 typedef ::boost::shared_ptr< XColorList > XColorListSharedPtr;
48 
49 class OfaOptionsTreeListBox : public SvTreeListBox
50 {
51 	using  SvListView::Collapse;
52 
53 private:
54 	sal_Bool 			bInCollapse;
55 
56 public:
OfaOptionsTreeListBox(Window * pParent,const ResId & rResId)57 	OfaOptionsTreeListBox(Window* pParent, const ResId& rResId) :
58 		SvTreeListBox( pParent, rResId ), bInCollapse(sal_False) {}
59 
60 	virtual sal_Bool    Collapse( SvLBoxEntry* pParent );
IsInCollapse() const61 	sal_Bool			IsInCollapse()const {return bInCollapse;}
62 };
63 
64 // struct OrderedEntry ---------------------------------------------------
65 
66 struct OrderedEntry
67 {
68     sal_Int32       m_nIndex;
69     rtl::OUString   m_sId;
70 
OrderedEntryOrderedEntry71     OrderedEntry( sal_Int32 nIndex, const rtl::OUString& rId ) :
72         m_nIndex( nIndex ), m_sId( rId ) {}
73 };
74 
75 typedef std::vector< OrderedEntry* > VectorOfOrderedEntries;
76 
77 // struct Module ---------------------------------------------------------
78 
79 struct Module
80 {
81     rtl::OUString           m_sName;
82     bool                    m_bActive;
83     VectorOfOrderedEntries  m_aNodeList;
84 
ModuleModule85     Module( const rtl::OUString& rName ) : m_sName( rName ), m_bActive( false ) {}
86 };
87 
88 // struct OptionsLeaf ----------------------------------------------------
89 
90 struct OptionsLeaf
91 {
92     rtl::OUString   m_sId;
93     rtl::OUString   m_sLabel;
94     rtl::OUString   m_sPageURL;
95     rtl::OUString   m_sEventHdl;
96     rtl::OUString   m_sGroupId;
97     sal_Int32       m_nGroupIndex;
98 
OptionsLeafOptionsLeaf99     OptionsLeaf(    const rtl::OUString& rId,
100                     const rtl::OUString& rLabel,
101                     const rtl::OUString& rPageURL,
102                     const rtl::OUString& rEventHdl,
103                     const rtl::OUString& rGroupId,
104                     sal_Int32 nGroupIndex ) :
105         m_sId( rId ),
106         m_sLabel( rLabel ),
107         m_sPageURL( rPageURL ),
108         m_sEventHdl( rEventHdl ),
109         m_sGroupId( rGroupId ),
110         m_nGroupIndex( nGroupIndex ) {}
111 };
112 
113 typedef ::std::vector< OptionsLeaf* > VectorOfLeaves;
114 typedef ::std::vector< VectorOfLeaves > VectorOfGroupedLeaves;
115 
116 // struct OptionsNode ----------------------------------------------------
117 
118 struct OptionsNode
119 {
120     rtl::OUString           m_sId;
121     rtl::OUString           m_sLabel;
122     rtl::OUString           m_sPageURL;
123     bool                    m_bAllModules;
124     rtl::OUString           m_sGroupId;
125     sal_Int32               m_nGroupIndex;
126     VectorOfLeaves          m_aLeaves;
127     VectorOfGroupedLeaves   m_aGroupedLeaves;
128 
OptionsNodeOptionsNode129     OptionsNode(    const rtl::OUString& rId,
130                     const rtl::OUString& rLabel,
131                     const rtl::OUString& rPageURL,
132                     bool bAllModules,
133                     const rtl::OUString& rGroupId,
134                     sal_Int32 nGroupIndex ) :
135         m_sId( rId ),
136         m_sLabel( rLabel ),
137         m_sPageURL( rPageURL ),
138         m_bAllModules( bAllModules ),
139         m_sGroupId( rGroupId ),
140         m_nGroupIndex( nGroupIndex ) {}
141 
~OptionsNodeOptionsNode142     ~OptionsNode()
143     {
144         for ( sal_uInt32 i = 0; i < m_aLeaves.size(); ++i )
145             delete m_aLeaves[i];
146         m_aLeaves.clear();
147         m_aGroupedLeaves.clear();
148     }
149 };
150 
151 typedef ::std::vector< OptionsNode* > VectorOfNodes;
152 
153 struct LastPageSaver
154 {
155     sal_uInt16          m_nLastPageId;
156     rtl::OUString   m_sLastPageURL_Tools;
157     rtl::OUString   m_sLastPageURL_ExtMgr;
158 
LastPageSaverLastPageSaver159     LastPageSaver() : m_nLastPageId( USHRT_MAX ) {}
160 };
161 
162 // class OfaTreeOptionsDialog --------------------------------------------
163 
164 namespace com { namespace sun { namespace star { namespace frame { class XFrame; } } } }
165 namespace com { namespace sun { namespace star { namespace container { class XNameAccess; } } } }
166 namespace com { namespace sun { namespace star { namespace lang { class XMultiServiceFactory; } } } }
167 namespace com { namespace sun { namespace star { namespace awt { class XContainerWindowProvider; } } } }
168 
169 struct OptionsPageInfo;
170 struct Module;
171 class ExtensionsTabPage;
172 typedef std::vector< ExtensionsTabPage* > VectorOfPages;
173 
174 class OfaTreeOptionsDialog : public SfxModalDialog
175 {
176 private:
177 	OKButton		aOkPB;
178 	CancelButton    aCancelPB;
179 	HelpButton 		aHelpPB;
180 	PushButton 		aBackPB;
181 
182 	FixedBorder		aHiddenGB;
183 	FixedText 		aPageTitleFT;
184 	FixedLine		aLine1FL;
185 	FixedText		aHelpFT;
186 	FixedImage 		aHelpImg;
187 
188     ImageList       aPageImages;
189     ImageList       aPageImagesHC;
190 
191 	ResStringArray	aHelpTextsArr;
192 
193 	OfaOptionsTreeListBox	aTreeLB;
194 
195 	String 			sTitle;
196 	String			sNotLoadedError;
197 
198     SvLBoxEntry*    pCurrentPageEntry;
199 
200 	// for the ColorTabPage
201 	SfxItemSet*		    pColorPageItemSet;
202 	XColorListSharedPtr maColorTab;
203 	sal_uInt16			nChangeType;
204 	sal_uInt16 			nUnknownType;
205 	sal_uInt16			nUnknownPos;
206 	sal_Bool			bIsAreaTP;
207 
208 	sal_Bool			bForgetSelection;
209 	sal_Bool			bExternBrowserActive;
210 	sal_Bool			bImageResized;
211 	bool            bInSelectHdl_Impl;
212     bool            bIsFromExtensionManager;
213 
214     // check "for the current document only" and set focus to "Western" languages box
215     bool            bIsForSetDocumentLanguage;
216 
217     Timer           aSelectTimer;
218 
219     com::sun::star::uno::Reference < com::sun::star::awt::XContainerWindowProvider >
220                     m_xContainerWinProvider;
221 
222     static LastPageSaver*   pLastPageSaver;
223 
224 	SfxItemSet*		CreateItemSet( sal_uInt16 nId );
225 	void			ApplyItemSet( sal_uInt16 nId, const SfxItemSet& rSet );
226     void            InitTreeAndHandler();
227     void            Initialize( const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& _xFrame );
228 	void			ResizeTreeLB( void );	// resizes dialog so that treelistbox has no horizontal scroll bar
229 
230     void            LoadExtensionOptions( const rtl::OUString& rExtensionId );
231     rtl::OUString   GetModuleIdentifier( const com::sun::star::uno::Reference<
232                                             com::sun::star::lang::XMultiServiceFactory >& xMFac,
233                                          const com::sun::star::uno::Reference<
234                                             com::sun::star::frame::XFrame >& xFrame );
235     Module*         LoadModule( const rtl::OUString& rModuleIdentifier,
236                                 const com::sun::star::uno::Reference<
237                                     com::sun::star::container::XNameAccess >& xRoot );
238     void            LoadNodes( const com::sun::star::uno::Reference<
239                                     com::sun::star::container::XNameAccess >& xRoot,
240                                Module* pModule,
241                                const rtl::OUString& rExtensionId,
242                                VectorOfNodes& rOutNodeList );
243     void            InsertNodes( const VectorOfNodes& rNodeList );
244 
245 protected:
246     DECL_LINK(ExpandedHdl_Impl, SvTreeListBox* );
247     DECL_LINK(ShowPageHdl_Impl, SvTreeListBox* );
248     DECL_LINK(BackHdl_Impl, PushButton* );
249     DECL_LINK( OKHdl_Impl, Button * );
250     DECL_LINK( HintHdl_Impl, Timer * );
251     DECL_LINK( SelectHdl_Impl, Timer * );
252 
253     virtual long    Notify( NotifyEvent& rNEvt );
254     virtual void    DataChanged( const DataChangedEvent& rDCEvt );
255     virtual short   Execute();
256 
257 public:
258     OfaTreeOptionsDialog( Window* pParent,
259         const com::sun::star::uno::Reference< com::sun::star::frame::XFrame >& _xFrame,
260         bool bActivateLastSelection = true );
261     OfaTreeOptionsDialog( Window* pParent, const rtl::OUString& rExtensionId );
262     ~OfaTreeOptionsDialog();
263 
264     OptionsPageInfo*    AddTabPage( sal_uInt16 nId, const String& rPageName, sal_uInt16 nGroup );
265     sal_uInt16              AddGroup(   const String& rGroupName,  SfxShell* pCreateShell,
266                                     SfxModule* pCreateModule, sal_uInt16 nDialogId );
267 
268     void                ActivateLastSelection();
269     void                ActivatePage( sal_uInt16 nResId );
270     void                ActivatePage( const String& rPageURL );
271     void                ApplyItemSets();
272 
GetColorChanged() const273     sal_uInt16              GetColorChanged() const { return nChangeType; }
GetColorTable()274     XColorListSharedPtr GetColorTable() { return maColorTab; }
275 
276 	// helper functions to call the language settings TabPage from the SpellDialog
277     static void         ApplyLanguageOptions(const SfxItemSet& rSet);
278 };
279 
280 // class OfaPageResource -------------------------------------------------
281 
282 class OfaPageResource : public Resource
283 {
284 	ResStringArray		aGeneralDlgAry;
285 	ResStringArray	 	aInetDlgAry;
286     ResStringArray      aLangDlgAry;
287     ResStringArray      aTextDlgAry;
288 	ResStringArray		aHTMLDlgAry;
289 	ResStringArray		aCalcDlgAry;
290 	ResStringArray		aStarMathDlgAry;
291 	ResStringArray		aImpressDlgAry;
292 	ResStringArray		aDrawDlgAry;
293 	ResStringArray		aChartDlgAry;
294 	ResStringArray		aFilterDlgAry;
295 	ResStringArray		aDatasourcesDlgAry;
296 
297 public:
298 	OfaPageResource();
299 
GetGeneralArray()300 	ResStringArray& GetGeneralArray() 		{return aGeneralDlgAry;}
GetInetArray()301 	ResStringArray& GetInetArray() 			{return aInetDlgAry;}
GetLangArray()302     ResStringArray& GetLangArray()			{return aLangDlgAry;}
GetTextArray()303 	ResStringArray& GetTextArray() 			{return aTextDlgAry;}
GetHTMLArray()304 	ResStringArray& GetHTMLArray() 			{return aHTMLDlgAry;}
GetCalcArray()305 	ResStringArray& GetCalcArray() 			{return aCalcDlgAry;}
GetStarMathArray()306 	ResStringArray& GetStarMathArray()		{return aStarMathDlgAry;}
GetImpressArray()307 	ResStringArray& GetImpressArray() 		{return aImpressDlgAry;}
GetDrawArray()308 	ResStringArray& GetDrawArray() 			{return aDrawDlgAry;}
GetChartArray()309 	ResStringArray& GetChartArray()			{return aChartDlgAry;}
GetFilterArray()310 	ResStringArray& GetFilterArray() 		{return aFilterDlgAry;}
GetDatasourcesArray()311 	ResStringArray& GetDatasourcesArray()	{return aDatasourcesDlgAry;}
312 };
313 
314 // class ExtensionsTabPage -----------------------------------------------
315 
316 namespace com { namespace sun { namespace star { namespace awt { class XWindow; } } } }
317 namespace com { namespace sun { namespace star { namespace awt { class XContainerWindowEventHandler; } } } }
318 
319 class ExtensionsTabPage : public TabPage
320 {
321 private:
322     rtl::OUString       m_sPageURL;
323     com::sun::star::uno::Reference< com::sun::star::awt::XWindow >
324                         m_xPage;
325     rtl::OUString       m_sEventHdl;
326     com::sun::star::uno::Reference< com::sun::star::awt::XContainerWindowEventHandler >
327                         m_xEventHdl;
328     com::sun::star::uno::Reference< com::sun::star::awt::XContainerWindowProvider >
329                         m_xWinProvider;
330     bool                m_bIsWindowHidden;
331 
332     void                CreateDialogWithHandler();
333     sal_Bool            DispatchAction( const rtl::OUString& rAction );
334 
335 public:
336     ExtensionsTabPage(
337         Window* pParent, WinBits nStyle,
338         const rtl::OUString& rPageURL, const rtl::OUString& rEvtHdl,
339         const com::sun::star::uno::Reference<
340             com::sun::star::awt::XContainerWindowProvider >& rProvider );
341 
342     virtual ~ExtensionsTabPage();
343 
344     virtual void    ActivatePage();
345     virtual void    DeactivatePage();
346 
347     void            ResetPage();
348     void            SavePage();
349 };
350 
351