xref: /aoo41x/main/sfx2/source/inc/templdgi.hxx (revision bd7afb38)
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 _SFX_TEMPDLGI_HXX
24 #define _SFX_TEMPDLGI_HXX
25 
26 class SfxTemplateControllerItem;
27 
28 #ifndef _BUTTON_HXX //autogen
29 #include <vcl/button.hxx>
30 #endif
31 #ifndef _TOOLBOX_HXX //autogen
32 #include <vcl/toolbox.hxx>
33 #endif
34 #ifndef _LSTBOX_HXX //autogen
35 #include <vcl/lstbox.hxx>
36 #endif
37 #include <svl/lstner.hxx>
38 #include <svtools/svtreebx.hxx>
39 #include <svl/eitem.hxx>
40 
41 #define _SVSTDARR_USHORTS
42 #include <svl/svstdarr.hxx>		// SvUShorts
43 
44 #include <rsc/rscsfx.hxx>
45 #include <tools/rtti.hxx>
46 
47 #include <sfx2/childwin.hxx>
48 #include <sfx2/templdlg.hxx>
49 
50 class SfxStyleFamilies;
51 class SfxStyleFamilyItem;
52 class SfxTemplateItem;
53 class SfxBindings;
54 class SfxStyleSheetBasePool;
55 class SvTreeListBox ;
56 class StyleTreeListBox_Impl;
57 class SfxTemplateDialog_Impl;
58 class SfxCommonTemplateDialog_Impl;
59 class SfxTemplateDialogWrapper;
60 class SfxDockingWindow;
61 
62 namespace com { namespace sun { namespace star { namespace frame { class XModuleManager; } } } }
63 
64 // class DropListBox_Impl ------------------------------------------------
65 
66 class DropListBox_Impl : public SvTreeListBox
67 {
68 private:
69     DECL_LINK( OnAsyncExecuteDrop, SvLBoxEntry* );
70     DECL_LINK( OnAsyncExecuteError, void* );
71 
72 protected:
73     SfxCommonTemplateDialog_Impl* pDialog;
74     sal_uInt16                        nModifier;
75 
76 public:
77     DropListBox_Impl( Window* pParent, const ResId& rId, SfxCommonTemplateDialog_Impl* pD ) :
78         SvTreeListBox( pParent, rId ), pDialog( pD ) {}
79     DropListBox_Impl( Window* pParent, WinBits nWinBits, SfxCommonTemplateDialog_Impl* pD ) :
80         SvTreeListBox( pParent, nWinBits ), pDialog( pD ) {}
81 
82     virtual void     MouseButtonDown( const MouseEvent& rMEvt );
83     virtual sal_Int8 AcceptDrop( const AcceptDropEvent& rEvt );
84     using SvLBox::ExecuteDrop;
85     virtual sal_Int8 ExecuteDrop( const ExecuteDropEvent& rEvt );
86 
87     sal_uInt16           GetModifier() const { return nModifier; }
88 
89     virtual long     Notify( NotifyEvent& rNEvt );
90 };
91 
92 // class SfxActionListBox ------------------------------------------------
93 
94 class SfxActionListBox : public DropListBox_Impl
95 {
96 protected:
97 public:
98 	SfxActionListBox( SfxCommonTemplateDialog_Impl* pParent, WinBits nWinBits );
99 	SfxActionListBox( SfxCommonTemplateDialog_Impl* pParent, const ResId &rResId );
100 
101 	virtual PopupMenu*	CreateContextMenu( void );
102 };
103 
104 // class SfxCommonTemplateDialog_Impl ------------------------------------
105 
106 struct Deleted
107 {
108     bool bDead;
109 
110     Deleted() : bDead(false) {}
111 
112     inline bool operator()() { return bDead; }
113 };
114 
115 class SfxCommonTemplateDialog_Impl : public SfxListener
116 {
117 private:
118 	class ISfxTemplateCommon_Impl : public ISfxTemplateCommon
119 	{
120 	private:
121 		SfxCommonTemplateDialog_Impl* pDialog;
122 	public:
123 		ISfxTemplateCommon_Impl( SfxCommonTemplateDialog_Impl* pDialogP ) : pDialog( pDialogP ) {}
124 		virtual SfxStyleFamily GetActualFamily() const { return pDialog->GetActualFamily(); }
125 		virtual String GetSelectedEntry() const { return pDialog->GetSelectedEntry(); }
126 	};
127 
128 	ISfxTemplateCommon_Impl		aISfxTemplateCommon;
129 
130 	void	ReadResource();
131 	void	ClearResource();
132 
133 protected:
134 #define MAX_FAMILIES			5
135 #define COUNT_BOUND_FUNC		13
136 
137 #define UPDATE_FAMILY_LIST		0x0001
138 #define UPDATE_FAMILY			0x0002
139 
140 	friend class DropListBox_Impl;
141 	friend class SfxTemplateControllerItem;
142 	friend class SfxTemplateDialogWrapper;
143 
144 	SfxBindings*				pBindings;
145 	SfxTemplateControllerItem*	pBoundItems[COUNT_BOUND_FUNC];
146 
147 	Window*						pWindow;
148 	SfxModule*					pModule;
149 	Timer*						pTimer;
150 
151 	ResId*						m_pStyleFamiliesId;
152 	SfxStyleFamilies*			pStyleFamilies;
153 	SfxTemplateItem*			pFamilyState[MAX_FAMILIES];
154 	SfxStyleSheetBasePool*		pStyleSheetPool;
155 	SvTreeListBox*				pTreeBox;
156 	SfxObjectShell*				pCurObjShell;
157     ::com::sun::star::uno::Reference< ::com::sun::star::frame::XModuleManager >
158                                 xModuleManager;
159     Deleted*                    pbDeleted;
160 
161 	SfxActionListBox			aFmtLb;
162 	ListBox						aFilterLb;
163 	Size						aSize;
164 
165 	sal_uInt16						nActFamily;	// Id in der ToolBox = Position - 1
166 	sal_uInt16						nActFilter;	// FilterIdx
167 	sal_uInt16						nAppFilter;	// Filter, den die Applikation gesetzt hat (fuer automatisch)
168 
169 	sal_Bool						bDontUpdate				:1,
170 								bIsWater				:1,
171 								bEnabled				:1,
172 								bUpdate					:1,
173 								bUpdateFamily			:1,
174 								bCanEdit				:1,
175 								bCanDel					:1,
176 								bCanNew					:1,
177 								bWaterDisabled			:1,
178 								bNewByExampleDisabled	:1,
179 								bUpdateByExampleDisabled:1,
180 								bTreeDrag				:1,
181 								bHierarchical			:1,
182 								bBindingUpdate			:1;
183 
184 	DECL_LINK( FilterSelectHdl, ListBox * );
185 	DECL_LINK( FmtSelectHdl, SvTreeListBox * );
186 	DECL_LINK( ApplyHdl, Control * );
187 	DECL_LINK( DropHdl, StyleTreeListBox_Impl * );
188 	DECL_LINK( TimeOut, Timer * );
189 
190 
191 	virtual void		EnableItem( sal_uInt16 /*nMesId*/, sal_Bool /*bCheck*/ = sal_True ) {}
192 	virtual void		CheckItem( sal_uInt16 /*nMesId*/, sal_Bool /*bCheck*/ = sal_True ) {}
193 	virtual sal_Bool		IsCheckedItem( sal_uInt16 /*nMesId*/ ) { return sal_True; }
194 	virtual void		LoadedFamilies() {}
195 	virtual void		Update() { UpdateStyles_Impl(UPDATE_FAMILY_LIST); }
196 	virtual void		InvalidateBindings();
197 	virtual void		InsertFamilyItem( sal_uInt16 nId, const SfxStyleFamilyItem* pIten ) = 0;
198 	virtual void		EnableFamilyItem( sal_uInt16 nId, sal_Bool bEnabled = sal_True ) = 0;
199 	virtual void		ClearFamilyList() = 0;
200     virtual void        ReplaceUpdateButtonByMenu();
201 
202         void				NewHdl( void* );
203 	void				EditHdl( void* );
204 	void				DeleteHdl( void* );
205 
206 	sal_Bool				Execute_Impl( sal_uInt16 nId, const String& rStr, const String& rRefStr,
207 									  sal_uInt16 nFamily, sal_uInt16 nMask = 0,
208 									  sal_uInt16* pIdx = NULL, const sal_uInt16* pModifier = NULL );
209 
210 	void						UpdateStyles_Impl(sal_uInt16 nFlags);
211 	const SfxStyleFamilyItem*	GetFamilyItem_Impl() const;
212 	sal_Bool						IsInitialized() { return nActFamily != 0xffff; }
213 	void						ResetFocus();
214 	void						EnableDelete();
215 	void						Initialize();
216 
217 	void				FilterSelect( sal_uInt16 nFilterIdx, sal_Bool bForce = sal_False );
218 	void				SetFamilyState( sal_uInt16 nSlotId, const SfxTemplateItem* );
219 	void				SetWaterCanState( const SfxBoolItem* pItem );
220 
221 	void				SelectStyle( const String& rStyle );
222 	sal_Bool				HasSelectedStyle() const;
223 	void				FillTreeBox();
224 	void				Update_Impl();
225 	void				UpdateFamily_Impl();
226 
227 	// In welchem FamilyState muss ich nachsehen, um die Info der i-ten
228 	// Family in der pStyleFamilies zu bekommen.
229 	sal_uInt16				StyleNrToInfoOffset( sal_uInt16 i );
230 	sal_uInt16				InfoOffsetToStyleNr( sal_uInt16 i );
231 
232 	void				Notify( SfxBroadcaster& rBC, const SfxHint& rHint );
233 
234 	void				FamilySelect( sal_uInt16 nId );
235 	void				SetFamily( sal_uInt16 nId );
236 	void				ActionSelect( sal_uInt16 nId );
237 
238     sal_Int32           LoadFactoryStyleFilter( SfxObjectShell* i_pObjSh );
239     void                SaveFactoryStyleFilter( SfxObjectShell* i_pObjSh, sal_Int32 i_nFilter );
240 
241 public:
242 	TYPEINFO();
243 
244 	SfxCommonTemplateDialog_Impl( SfxBindings* pB, Window*, bool );
245 	SfxCommonTemplateDialog_Impl( SfxBindings* pB, Window* );
246 	~SfxCommonTemplateDialog_Impl();
247 
248 	DECL_LINK( MenuSelectHdl, Menu * );
249 
250 	virtual void		EnableEdit( sal_Bool b = sal_True )	{ bCanEdit = b; }
251 	virtual void		EnableDel( sal_Bool b = sal_True )	{ bCanDel = b; }
252 	virtual void		EnableNew( sal_Bool b = sal_True )	{ bCanNew = b; }
253 
254 	ISfxTemplateCommon*	GetISfxTemplateCommon() { return &aISfxTemplateCommon; }
255 	Window*				GetWindow() { return pWindow; }
256 
257 	void				EnableTreeDrag( sal_Bool b = sal_True );
258 	void				ExecuteContextMenu_Impl( const Point& rPos, Window* pWin );
259 	void				EnableExample_Impl( sal_uInt16 nId, sal_Bool bEnable );
260 	SfxStyleFamily		GetActualFamily() const;
261 	String				GetSelectedEntry() const;
262 	SfxObjectShell*		GetObjectShell() const { return pCurObjShell; }
263 
264 	virtual void		PrepareDeleteAction();	// disable buttons, change button text, etc. when del is going to happen
265 
266 	inline sal_Bool			CanEdit( void ) const	{ return bCanEdit; }
267 	inline sal_Bool			CanDel( void ) const	{ return bCanDel; }
268 	inline sal_Bool			CanNew( void ) const	{ return bCanNew; }
269 
270 	// normaly for derivates from SvTreeListBoxes, but in this case the dialog handles context menus
271 	virtual PopupMenu*	CreateContextMenu( void );
272 
273     // Rechnet von den SFX_STYLE_FAMILY Ids auf 1-5 um
274     static sal_uInt16       SfxFamilyIdToNId( SfxStyleFamily nFamily );
275 
276     void                SetAutomaticFilter();
277 };
278 /* -----------------10.12.2003 11:42-----------------
279 
280  --------------------------------------------------*/
281 
282 class DropToolBox_Impl : public ToolBox, public DropTargetHelper
283 {
284     SfxTemplateDialog_Impl&     rParent;
285 protected:
286     virtual sal_Int8    AcceptDrop( const AcceptDropEvent& rEvt );
287     virtual sal_Int8    ExecuteDrop( const ExecuteDropEvent& rEvt );
288 public:
289     DropToolBox_Impl(Window* pParent, SfxTemplateDialog_Impl* pTemplateDialog);
290     ~DropToolBox_Impl();
291 };
292 // class SfxTemplateDialog_Impl ------------------------------------------
293 
294 class SfxTemplateDialog_Impl :  public SfxCommonTemplateDialog_Impl
295 {
296 private:
297 	friend class SfxTemplateControllerItem;
298 	friend class SfxTemplateDialogWrapper;
299     friend class DropToolBox_Impl;
300     friend class SfxTemplatePanelControl;
301 
302 	Window*	m_pFloat;
303 	sal_Bool			m_bZoomIn;
304     DropToolBox_Impl    m_aActionTbL;
305 	ToolBox				m_aActionTbR;
306 
307 	DECL_LINK( ToolBoxLSelect, ToolBox * );
308 	DECL_LINK( ToolBoxRSelect, ToolBox * );
309     DECL_LINK( ToolBoxRClick, ToolBox * );
310     DECL_LINK( MenuSelectHdl, Menu* );
311 
312 protected:
313 	virtual void	Command( const CommandEvent& rMEvt );
314 	virtual void	EnableEdit( sal_Bool = sal_True );
315 	virtual void	EnableItem( sal_uInt16 nMesId, sal_Bool bCheck = sal_True );
316 	virtual void	CheckItem( sal_uInt16 nMesId, sal_Bool bCheck = sal_True );
317 	virtual sal_Bool	IsCheckedItem( sal_uInt16 nMesId );
318 	virtual void	LoadedFamilies();
319 	virtual void	InsertFamilyItem( sal_uInt16 nId, const SfxStyleFamilyItem* pIten );
320 	virtual void	EnableFamilyItem( sal_uInt16 nId, sal_Bool bEnabled = sal_True );
321 	virtual void	ClearFamilyList();
322     virtual void    ReplaceUpdateButtonByMenu();
323 
324 	void 			Resize();
325 	Size			GetMinOutputSizePixel();
326 
327 	void			updateFamilyImages();
328 	void			updateNonFamilyImages();
329 
330 public:
331 	friend class SfxTemplateDialog;
332 	TYPEINFO();
333 
334 	SfxTemplateDialog_Impl( SfxBindings*, SfxTemplateDialog* pDlgWindow );
335 	SfxTemplateDialog_Impl( SfxBindings*, SfxTemplatePanelControl* pDlgWindow );
336 	~SfxTemplateDialog_Impl();
337 
338     void Initialize (void);
339 };
340 
341 // class SfxTemplateCatalog_Impl -----------------------------------------
342 
343 class SfxTemplateCatalog_Impl : public SfxCommonTemplateDialog_Impl
344 {
345 private:
346 	friend class SfxTemplateControllerItem;
347 	friend class SfxCommonTemplateDialog_Impl;
348 
349 	ListBox					aFamList;
350 	OKButton				aOkBtn;
351 	CancelButton			aCancelBtn;
352 	PushButton				aNewBtn;
353 	PushButton				aChangeBtn;
354 	PushButton	   	 		aDelBtn;
355 	PushButton				aOrgBtn;
356 	HelpButton				aHelpBtn;
357 
358 	SfxTemplateCatalog*		pReal;
359 	SvUShorts				aFamIds;
360 	SfxModalDefParentHelper	aHelper;
361 
362 protected:
363 	virtual void	EnableItem( sal_uInt16 nMesId, sal_Bool bCheck = sal_True );
364 	virtual void	CheckItem( sal_uInt16 nMesId, sal_Bool bCheck = sal_True );
365 	virtual sal_Bool	IsCheckedItem( sal_uInt16 nMesId );
366 	virtual void	InsertFamilyItem( sal_uInt16 nId, const SfxStyleFamilyItem* pIten );
367 	virtual void	EnableFamilyItem( sal_uInt16 nId, sal_Bool bEnabled = sal_True );
368 	virtual void	ClearFamilyList();
369 	virtual void	EnableEdit( sal_Bool = sal_True );
370 	virtual void	EnableDel( sal_Bool = sal_True );
371 	virtual void	EnableNew( sal_Bool = sal_True );
372 
373         using SfxCommonTemplateDialog_Impl::NewHdl;
374 	DECL_LINK( FamListSelect, ListBox * );
375 	DECL_LINK( OkHdl, Button * );
376 	DECL_LINK( CancelHdl, Button * );
377 	DECL_LINK( NewHdl, Button * );
378 	DECL_LINK( ChangeHdl, Button * );
379 	DECL_LINK( DelHdl, Button * );
380 	DECL_LINK( OrgHdl, Button * );
381 
382 public:
383 	TYPEINFO();
384 	SfxTemplateCatalog_Impl( Window* pParent, SfxBindings*, SfxTemplateCatalog* pWindow );
385 	~SfxTemplateCatalog_Impl();
386 
387 friend class SfxTemplateCatalog;
388 
389 	virtual void	PrepareDeleteAction();
390 };
391 
392 #endif // #ifndef _SFX_TEMPDLGI_HXX
393 
394 
395