xref: /aoo42x/main/cui/source/inc/iconcdlg.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 #ifndef _ICCDLG_HXX
28 #define _ICCDLG_HXX
29 
30 #include <vcl/tabpage.hxx>
31 #include <vcl/msgbox.hxx>
32 #include <vcl/dialog.hxx>
33 #ifndef _SV_BUTTON_HXX
34 #include <vcl/button.hxx>
35 #endif
36 #include <vcl/image.hxx>
37 #include <svtools/ivctrl.hxx>
38 #include <svl/itempool.hxx>
39 #include <svl/itemset.hxx>
40 #include <tools/list.hxx>
41 #include <tools/string.hxx>
42 
43 #define CTRLS_OFFSET		3
44 #define BUTTON_DISTANCE		8
45 #define RET_USER 		100
46 #define RET_USER_CANCEL	101
47 
48 // forward-declarations
49 struct IconChoicePageData;
50 class IconChoiceDialog;
51 class IconChoicePage;
52 
53 // Create-Function
54 typedef IconChoicePage* (*CreatePage)(Window *pParent, const SfxItemSet &rAttrSet);
55 typedef sal_uInt16*		    (*GetPageRanges)(); // liefert internationale Which-Wert
56 
57 // page-list
58 DECLARE_LIST( IconChoicePageList, IconChoicePageData * )
59 
60 // position of iconchoicectrl
61 enum EIconChoicePos { PosLeft, PosRight, PosTop, PosBottom };
62 
63 /**********************************************************************
64 |
65 | Data-structure for pages in dialog
66 |
67 \**********************************************************************/
68 
69 struct IconChoicePageData
70 {
71 	sal_uInt16 nId;					 // Die ID
72 	CreatePage fnCreatePage;	 // Pointer auf die Factory
73 	GetPageRanges fnGetRanges;// Pointer auf die Ranges-Funktion
74 	IconChoicePage* pPage;		 // die TabPage selber
75 	sal_Bool bOnDemand;				 // Flag: ItemSet onDemand
76 	sal_Bool bRefresh; 				 // Flag: Seite mu\s neu initialisiert werden
77 
78 	// Konstruktor
79 	IconChoicePageData( sal_uInt16 Id, CreatePage fnPage, GetPageRanges fnRanges, sal_Bool bDemand )
80 		: nId			( Id ),
81 		  fnCreatePage	( fnPage ),
82 		  fnGetRanges	( fnRanges ),
83 		  pPage			( NULL ),
84 		  bOnDemand		( bDemand ),
85 		  bRefresh		( sal_False )
86 	{}
87 };
88 
89 /**********************************************************************
90 |
91 | IconChoicePage
92 |
93 \**********************************************************************/
94 
95 class IconChoicePage : public TabPage
96 {
97 	using TabPage::ActivatePage;
98 	using TabPage::DeactivatePage;
99 
100 private :
101 	const SfxItemSet*	pSet;
102 	String				aUserString;
103 	sal_Bool				bHasExchangeSupport;
104 	IconChoiceDialog*	pDialog;
105 	sal_Bool				bStandard;
106 
107 	void				SetDialog( IconChoiceDialog* pNew ) { pDialog = pNew; }
108 	IconChoiceDialog*	GetDialog() const { return pDialog; }
109 
110 	void				SetInputSet( const SfxItemSet* pNew ) { pSet = pNew; }
111 
112 	void				ImplInitSettings();
113 
114 protected :
115 	IconChoicePage( Window *pParent, const ResId &, const SfxItemSet &rAttrSet );
116 
117 	sal_uInt16				GetSlot( sal_uInt16 nWhich ) const	{ return pSet->GetPool()->GetSlotId( nWhich ); }
118 	sal_uInt16				GetWhich( sal_uInt16 nSlot ) const	{ return pSet->GetPool()->GetWhich( nSlot ); }
119 
120 public :
121 	virtual             ~IconChoicePage();
122 
123 	const SfxItemSet&	GetItemSet() const { return *pSet; }
124 
125 	virtual sal_Bool		FillItemSet( SfxItemSet& ) = 0;
126 	virtual void		Reset( const SfxItemSet& ) = 0;
127 
128 	sal_Bool				HasExchangeSupport() const				{ return bHasExchangeSupport; }
129 	void				SetExchangeSupport( sal_Bool bNew = sal_True )	{ bHasExchangeSupport = bNew; }
130 
131 	enum {
132 		KEEP_PAGE = 0x0000,		// Fehlerbehandlung; Seite nicht wechseln
133 			// 2. F"ullen eines ItemSets f"ur die Aktualilsierung
134 			// "ubergeordneter Beispiele; dieser Pointer kann immer
135 			// NULL sein!!
136 		LEAVE_PAGE = 0x0001,
137 			// Set aktualisieren und andere Page aktualisieren
138 		REFRESH_SET = 0x0002
139 	};
140 
141 	virtual void		ActivatePage( const SfxItemSet& );
142 	virtual int			DeactivatePage( SfxItemSet* pSet = 0 );
143 	void				SetUserData(const String& rString)	{ aUserString = rString; }
144 	String				GetUserData() { return aUserString; }
145 	virtual void		FillUserData();
146 	virtual sal_Bool		IsReadOnly() const;
147     virtual sal_Bool    QueryClose();
148 
149 	void				StateChanged( StateChangedType nType );
150 	void				DataChanged( const DataChangedEvent& rDCEvt );
151 };
152 
153 /**********************************************************************
154 |
155 | IconChoiceDialog
156 |
157 \**********************************************************************/
158 
159 class IconChoiceDialog : public ModalDialog
160 {
161 private :
162 	friend class IconChoicePage;
163 
164 	EIconChoicePos			meChoicePos;    // Position des IconChoiceCtrl's
165 	IconChoicePageList		maPageList;		// Liste von PageData-Pointer
166 
167 	SvtIconChoiceCtrl		maIconCtrl;		// DAS IconChoice-Control
168 
169 	sal_uInt16					mnCurrentPageId;	// Id der aktuell sichtbaren Page
170 
171 	// Buttons
172 	OKButton				aOKBtn;
173 	CancelButton			aCancelBtn;
174 	HelpButton				aHelpBtn;
175 	PushButton				aResetBtn;
176 
177 	const SfxItemSet*		pSet;
178 	SfxItemSet*				pOutSet;
179 	SfxItemSet*				pExampleSet;
180 	sal_uInt16*					pRanges;
181 
182 	sal_uInt32				nResId;
183 
184 	sal_Bool					bHideResetBtn;
185 	sal_Bool					bModal;
186 	sal_Bool					bInOK;
187 	sal_Bool					bModified;
188 	sal_Bool					bItemsReset;
189 
190 	DECL_LINK ( ChosePageHdl_Impl, void * );
191 	DECL_LINK ( OkHdl,			   Button * );
192 	DECL_LINK ( ResetHdl,          Button * );
193 	DECL_LINK ( CancelHdl,		   Button * );
194 
195 	IconChoicePageData*		GetPageData ( sal_uInt16 nId );
196 	void					Start_Impl();
197 	sal_Bool					OK_Impl();
198 
199 	void					SetPosSizeCtrls ( sal_Bool bInit = sal_False );
200 	void					SetPosSizePages ( sal_uInt16 nId );
201 
202 	void					FocusOnIcon ( sal_uInt16 nId );
203 
204 protected :
205 	void					ShowPageImpl ( IconChoicePageData* pData );
206 	void					HidePageImpl ( IconChoicePageData* pData );
207 
208     virtual void            PageCreated( sal_uInt16 nId, IconChoicePage& rPage );
209 	virtual SfxItemSet*		CreateInputItemSet( sal_uInt16 nId );
210 	inline SfxItemSet*		GetInputSetImpl() { return (SfxItemSet*)pSet; }
211 	inline IconChoicePage*	GetTabPage( sal_uInt16 nPageId )
212 								{ return ( GetPageData (nPageId)->pPage?GetPageData (nPageId)->pPage:NULL); }
213 	const SfxItemSet*		GetRefreshedSet();
214 
215 	void					ActivatePageImpl ();
216 	sal_Bool					DeActivatePageImpl ();
217 	void					ResetPageImpl ();
218 
219 	short					Ok();
220 
221 public :
222 
223 	// im Ctor k�nnte auch die Position des IconChoiceCtrl's gesetzt werden.
224 
225 	IconChoiceDialog ( Window* pParent, const ResId &rResId,
226 					   const EIconChoicePos ePos = PosLeft, const SfxItemSet * pItemSet = 0 );
227 	~IconChoiceDialog ();
228 
229 	///////////////////////////////////////////////////////////////////////////////////
230 	// virtuelle Methoden
231 	//
232 	virtual void		Paint( const Rectangle& rRect );
233 	virtual void		Resize();
234 
235 	///////////////////////////////////////////////////////////////////////////////////
236 	// Schnittstelle
237 	//
238 
239 	SvxIconChoiceCtrlEntry*	AddTabPage(
240 		sal_uInt16 nId, const String& rIconText, const Image& rChoiceIcon, const Image& rChoiceIconHC,
241 		CreatePage pCreateFunc /* != NULL */, GetPageRanges pRangesFunc = NULL /* NULL allowed*/,
242 		sal_Bool bItemsOnDemand = sal_False, sal_uLong nPos = LIST_APPEND );
243 
244 	void				SetCurPageId( sal_uInt16 nId ) { mnCurrentPageId = nId; FocusOnIcon( nId ); }
245 	sal_uInt16				GetCurPageId() const       { return mnCurrentPageId; }
246 	void				ShowPage( sal_uInt16 nId );
247 
248 						// liefert ggf. per Map konvertierte lokale Slots
249 	const sal_uInt16*		GetInputRanges( const SfxItemPool& );
250 	void				SetInputSet( const SfxItemSet* pInSet );
251 	const SfxItemSet*	GetOutputItemSet() const { return pOutSet; }
252 
253 	const OKButton& 	GetOKButton() const { return aOKBtn; }
254 	OKButton&			GetOKButton() { return aOKBtn; }
255 	const CancelButton& GetCancelButton() const { return aCancelBtn; }
256 	CancelButton&		GetCancelButton() { return aCancelBtn; }
257 	const HelpButton&	GetHelpButton() const { return aHelpBtn; }
258 	HelpButton&			GetHelpButton() { return aHelpBtn; }
259 
260 	short				Execute();
261 	void				Start( sal_Bool bShow = sal_True );
262     sal_Bool            QueryClose();
263 
264 	const SfxItemSet*	GetExampleSet() const { return pExampleSet; }
265 
266 	EIconChoicePos		SetCtrlPos   ( const EIconChoicePos& rPos );
267 };
268 
269 #endif //_ICCDLG_HXX
270 
271