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