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