1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: iconcdlg.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #include <vcl/tabpage.hxx>
34 #include <vcl/msgbox.hxx>
35 #include <vcl/dialog.hxx>
36 #ifndef _SV_BUTTON_HXX
37 #include <vcl/button.hxx>
39 #include <vcl/image.hxx>
40 #include <svtools/ivctrl.hxx>
41 #include <svtools/itempool.hxx>
42 #include <svtools/itemset.hxx>
43 #include <tools/list.hxx>
44 #include <tools/string.hxx>
46 #define CTRLS_OFFSET 3
47 #define BUTTON_DISTANCE 8
49 #define RET_USER_CANCEL 101
51 // forward-declarations
52 struct IconChoicePageData
;
53 class IconChoiceDialog
;
57 typedef IconChoicePage
* (*CreatePage
)(Window
*pParent
, const SfxItemSet
&rAttrSet
);
58 typedef USHORT
* (*GetPageRanges
)(); // liefert internationale Which-Wert
61 DECLARE_LIST( IconChoicePageList
, IconChoicePageData
* )
63 // position of iconchoicectrl
64 enum EIconChoicePos
{ PosLeft
, PosRight
, PosTop
, PosBottom
};
66 /**********************************************************************
68 | Data-structure for pages in dialog
70 \**********************************************************************/
72 struct IconChoicePageData
75 CreatePage fnCreatePage
; // Pointer auf die Factory
76 GetPageRanges fnGetRanges
;// Pointer auf die Ranges-Funktion
77 IconChoicePage
* pPage
; // die TabPage selber
78 BOOL bOnDemand
; // Flag: ItemSet onDemand
79 BOOL bRefresh
; // Flag: Seite mu\s neu initialisiert werden
82 IconChoicePageData( USHORT Id
, CreatePage fnPage
, GetPageRanges fnRanges
, BOOL bDemand
)
84 fnCreatePage ( fnPage
),
85 fnGetRanges ( fnRanges
),
87 bOnDemand ( bDemand
),
92 /**********************************************************************
96 \**********************************************************************/
98 class IconChoicePage
: public TabPage
100 using TabPage::ActivatePage
;
101 using TabPage::DeactivatePage
;
104 const SfxItemSet
* pSet
;
106 BOOL bHasExchangeSupport
;
107 IconChoiceDialog
* pDialog
;
110 void SetDialog( IconChoiceDialog
* pNew
) { pDialog
= pNew
; }
111 IconChoiceDialog
* GetDialog() const { return pDialog
; }
113 void SetInputSet( const SfxItemSet
* pNew
) { pSet
= pNew
; }
115 void ImplInitSettings();
118 IconChoicePage( Window
*pParent
, const ResId
&, const SfxItemSet
&rAttrSet
);
120 USHORT
GetSlot( USHORT nWhich
) const { return pSet
->GetPool()->GetSlotId( nWhich
); }
121 USHORT
GetWhich( USHORT nSlot
) const { return pSet
->GetPool()->GetWhich( nSlot
); }
122 const SfxPoolItem
* GetOldItem( const SfxItemSet
& rSet
, USHORT nSlot
);
123 const SfxPoolItem
* GetExchangeItem( const SfxItemSet
& rSet
, USHORT nSlot
);
126 virtual ~IconChoicePage();
128 const SfxItemSet
& GetItemSet() const { return *pSet
; }
130 virtual BOOL
FillItemSet( SfxItemSet
& ) = 0;
131 virtual void Reset( const SfxItemSet
& ) = 0;
133 BOOL
HasExchangeSupport() const { return bHasExchangeSupport
; }
134 void SetExchangeSupport( BOOL bNew
= TRUE
) { bHasExchangeSupport
= bNew
; }
137 KEEP_PAGE
= 0x0000, // Fehlerbehandlung; Seite nicht wechseln
138 // 2. F"ullen eines ItemSets f"ur die Aktualilsierung
139 // "ubergeordneter Beispiele; dieser Pointer kann immer
142 // Set aktualisieren und andere Page aktualisieren
146 virtual void ActivatePage( const SfxItemSet
& );
147 virtual int DeactivatePage( SfxItemSet
* pSet
= 0 );
148 void SetUserData(const String
& rString
) { aUserString
= rString
; }
149 String
GetUserData() { return aUserString
; }
150 virtual void FillUserData();
151 virtual BOOL
IsReadOnly() const;
152 virtual sal_Bool
QueryClose();
154 static const SfxPoolItem
* GetItem( const SfxItemSet
& rSet
, USHORT nSlot
);
156 void StateChanged( StateChangedType nType
);
157 void DataChanged( const DataChangedEvent
& rDCEvt
);
160 /**********************************************************************
164 \**********************************************************************/
166 class IconChoiceDialog
: public ModalDialog
169 friend class IconChoicePage
;
171 EIconChoicePos meChoicePos
; // Position des IconChoiceCtrl's
172 IconChoicePageList maPageList
; // Liste von PageData-Pointer
174 SvtIconChoiceCtrl maIconCtrl
; // DAS IconChoice-Control
176 USHORT mnCurrentPageId
; // Id der aktuell sichtbaren Page
180 CancelButton aCancelBtn
;
182 PushButton aResetBtn
;
184 const SfxItemSet
* pSet
;
186 SfxItemSet
* pExampleSet
;
197 DECL_LINK ( ChosePageHdl_Impl
, void * );
198 DECL_LINK ( OkHdl
, Button
* );
199 DECL_LINK ( ResetHdl
, Button
* );
200 DECL_LINK ( CancelHdl
, Button
* );
202 IconChoicePageData
* GetPageData ( USHORT nId
);
206 void SetPosSizeCtrls ( BOOL bInit
= FALSE
);
207 void SetPosSizePages ( USHORT nId
);
209 void FocusOnIcon ( USHORT nId
);
212 void ShowPageImpl ( IconChoicePageData
* pData
);
213 void HidePageImpl ( IconChoicePageData
* pData
);
215 virtual void PageCreated( USHORT nId
, IconChoicePage
& rPage
);
216 virtual SfxItemSet
* CreateInputItemSet( USHORT nId
);
217 inline SfxItemSet
* GetInputSetImpl() { return (SfxItemSet
*)pSet
; }
218 inline IconChoicePage
* GetTabPage( USHORT nPageId
)
219 { return ( GetPageData (nPageId
)->pPage
?GetPageData (nPageId
)->pPage
:NULL
); }
220 const SfxItemSet
* GetRefreshedSet();
222 void ActivatePageImpl ();
223 BOOL
DeActivatePageImpl ();
224 void ResetPageImpl ();
231 // im Ctor könnte auch die Position des IconChoiceCtrl's gesetzt werden.
233 IconChoiceDialog ( Window
* pParent
, const ResId
&rResId
,
234 const EIconChoicePos ePos
= PosLeft
, const SfxItemSet
* pItemSet
= 0 );
235 ~IconChoiceDialog ();
237 ///////////////////////////////////////////////////////////////////////////////////
238 // virtuelle Methoden
240 virtual void Paint( const Rectangle
& rRect
);
241 virtual void Resize();
243 ///////////////////////////////////////////////////////////////////////////////////
247 SvxIconChoiceCtrlEntry
* AddTabPage(
248 USHORT nId
, const String
& rIconText
, const Image
& rChoiceIcon
,
249 CreatePage pCreateFunc
/* != NULL */, GetPageRanges pRangesFunc
= NULL
/* NULL allowed*/,
250 BOOL bItemsOnDemand
= FALSE
, ULONG nPos
= LIST_APPEND
);
252 SvxIconChoiceCtrlEntry
* AddTabPage(
253 USHORT nId
, const String
& rIconText
, const Image
& rChoiceIcon
, const Image
& rChoiceIconHC
,
254 CreatePage pCreateFunc
/* != NULL */, GetPageRanges pRangesFunc
= NULL
/* NULL allowed*/,
255 BOOL bItemsOnDemand
= FALSE
, ULONG nPos
= LIST_APPEND
);
257 void RemoveTabPage( USHORT nId
);
259 void SetCurPageId( USHORT nId
) { mnCurrentPageId
= nId
; FocusOnIcon( nId
); }
260 USHORT
GetCurPageId() const { return mnCurrentPageId
; }
261 void ShowPage( USHORT nId
);
263 // liefert ggf. per Map konvertierte lokale Slots
264 const USHORT
* GetInputRanges( const SfxItemPool
& );
265 void SetInputSet( const SfxItemSet
* pInSet
);
266 const SfxItemSet
* GetOutputItemSet() const { return pOutSet
; }
267 const SfxItemSet
* GetOutputItemSet( USHORT nId
);
268 int FillOutputItemSet();
270 const OKButton
& GetOKButton() const { return aOKBtn
; }
271 OKButton
& GetOKButton() { return aOKBtn
; }
272 const CancelButton
& GetCancelButton() const { return aCancelBtn
; }
273 CancelButton
& GetCancelButton() { return aCancelBtn
; }
274 const HelpButton
& GetHelpButton() const { return aHelpBtn
; }
275 HelpButton
& GetHelpButton() { return aHelpBtn
; }
277 void RemoveResetButton();
280 void Start( BOOL bShow
= TRUE
);
281 sal_Bool
QueryClose();
283 const SfxItemSet
* GetExampleSet() const { return pExampleSet
; }
285 void SetCtrlColor ( const Color
& rColor
);
286 EIconChoicePos
SetCtrlPos ( const EIconChoicePos
& rPos
);
288 void CreateIconTextAutoMnemonics( void );