Version 4.0.0.1, tag libreoffice-4.0.0.1
[LibreOffice.git] / cui / source / inc / iconcdlg.hxx
blob73e01e5ad2c1a118a33b92d7077f9d2fb8522ed7
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef _ICCDLG_HXX
20 #define _ICCDLG_HXX
22 #include <vcl/tabpage.hxx>
23 #include <vcl/msgbox.hxx>
24 #include <vcl/dialog.hxx>
25 #include <vcl/button.hxx>
26 #include <vcl/image.hxx>
27 #include <svtools/ivctrl.hxx>
28 #include <svl/itempool.hxx>
29 #include <svl/itemset.hxx>
30 #include <tools/string.hxx>
31 #include <vector>
33 #define CTRLS_OFFSET 3
34 #define RET_USER 100
35 #define RET_USER_CANCEL 101
37 // forward-declarations
38 struct IconChoicePageData;
39 class IconChoiceDialog;
40 class IconChoicePage;
42 // Create-Function
43 typedef IconChoicePage* (*CreatePage)(Window *pParent, const SfxItemSet &rAttrSet);
44 typedef sal_uInt16* (*GetPageRanges)(); // gives international Which-value
46 // position of iconchoicectrl
47 enum EIconChoicePos { PosLeft, PosRight, PosTop, PosBottom };
49 /// Data-structure for pages in dialog
50 struct IconChoicePageData
52 sal_uInt16 nId;
53 CreatePage fnCreatePage; ///< pointer to the factory
54 GetPageRanges fnGetRanges; ///< pointer to the ranges-function
55 IconChoicePage* pPage; ///< the TabPage itself
56 sal_Bool bOnDemand; ///< Flag: ItemSet onDemand
57 sal_Bool bRefresh; ///< Flag: page has to be newly initialized
59 // constructor
60 IconChoicePageData( sal_uInt16 Id, CreatePage fnPage, GetPageRanges fnRanges, sal_Bool bDemand )
61 : nId ( Id ),
62 fnCreatePage ( fnPage ),
63 fnGetRanges ( fnRanges ),
64 pPage ( NULL ),
65 bOnDemand ( bDemand ),
66 bRefresh ( sal_False )
70 class IconChoicePage : public TabPage
72 using TabPage::ActivatePage;
73 using TabPage::DeactivatePage;
75 private :
76 const SfxItemSet* pSet;
77 String aUserString;
78 sal_Bool bHasExchangeSupport;
79 IconChoiceDialog* pDialog;
81 void SetDialog( IconChoiceDialog* pNew ) { pDialog = pNew; }
82 IconChoiceDialog* GetDialog() const { return pDialog; }
84 void SetInputSet( const SfxItemSet* pNew ) { pSet = pNew; }
86 void ImplInitSettings();
88 protected :
89 IconChoicePage( Window *pParent, const ResId &, const SfxItemSet &rAttrSet );
91 sal_uInt16 GetSlot( sal_uInt16 nWhich ) const { return pSet->GetPool()->GetSlotId( nWhich ); }
92 sal_uInt16 GetWhich( sal_uInt16 nSlot ) const { return pSet->GetPool()->GetWhich( nSlot ); }
94 public :
95 virtual ~IconChoicePage();
97 const SfxItemSet& GetItemSet() const { return *pSet; }
99 virtual sal_Bool FillItemSet( SfxItemSet& ) = 0;
100 virtual void Reset( const SfxItemSet& ) = 0;
102 sal_Bool HasExchangeSupport() const { return bHasExchangeSupport; }
103 void SetExchangeSupport( sal_Bool bNew = sal_True ) { bHasExchangeSupport = bNew; }
105 enum {
106 KEEP_PAGE = 0x0000, ///< error handling
107 /** 2nd filling of an ItemSet for updating superior examples;
108 this pointer can always be NULL!! */
109 LEAVE_PAGE = 0x0001,
110 /// refresh set and update other pages
111 REFRESH_SET = 0x0002
114 virtual void ActivatePage( const SfxItemSet& );
115 virtual int DeactivatePage( SfxItemSet* pSet = 0 );
116 void SetUserData(const String& rString) { aUserString = rString; }
117 String GetUserData() { return aUserString; }
118 virtual void FillUserData();
119 virtual sal_Bool IsReadOnly() const;
120 virtual sal_Bool QueryClose();
122 void StateChanged( StateChangedType nType );
123 void DataChanged( const DataChangedEvent& rDCEvt );
126 class IconChoiceDialog : public ModalDialog
128 private :
129 friend class IconChoicePage;
131 EIconChoicePos meChoicePos;
132 ::std::vector< IconChoicePageData* > maPageList;
134 SvtIconChoiceCtrl maIconCtrl;
136 sal_uInt16 mnCurrentPageId;
138 // Buttons
139 OKButton aOKBtn;
140 CancelButton aCancelBtn;
141 HelpButton aHelpBtn;
142 PushButton aResetBtn;
144 const SfxItemSet* pSet;
145 SfxItemSet* pOutSet;
146 SfxItemSet* pExampleSet;
147 sal_uInt16* pRanges;
149 sal_uInt32 nResId;
151 sal_Bool bHideResetBtn;
152 sal_Bool bModal;
153 sal_Bool bInOK;
154 sal_Bool bModified;
155 sal_Bool bItemsReset;
157 DECL_LINK ( ChosePageHdl_Impl, void * );
158 DECL_LINK(OkHdl, void *);
159 DECL_LINK(ResetHdl, void *);
160 DECL_LINK(CancelHdl, void *);
162 IconChoicePageData* GetPageData ( sal_uInt16 nId );
163 void Start_Impl();
164 sal_Bool OK_Impl();
166 void SetPosSizeCtrls ( sal_Bool bInit = sal_False );
167 void SetPosSizePages ( sal_uInt16 nId );
169 void FocusOnIcon ( sal_uInt16 nId );
171 protected :
172 void ShowPageImpl ( IconChoicePageData* pData );
173 void HidePageImpl ( IconChoicePageData* pData );
175 virtual void PageCreated( sal_uInt16 nId, IconChoicePage& rPage );
176 virtual SfxItemSet* CreateInputItemSet( sal_uInt16 nId );
177 inline SfxItemSet* GetInputSetImpl() { return (SfxItemSet*)pSet; }
178 inline IconChoicePage* GetTabPage( sal_uInt16 nPageId )
179 { return ( GetPageData (nPageId)->pPage?GetPageData (nPageId)->pPage:NULL); }
180 const SfxItemSet* GetRefreshedSet();
182 void ActivatePageImpl ();
183 sal_Bool DeActivatePageImpl ();
184 void ResetPageImpl ();
186 short Ok();
188 public :
190 // the IconChoiceCtrl's could also be set in the Ctor
191 IconChoiceDialog ( Window* pParent, const ResId &rResId,
192 const EIconChoicePos ePos = PosLeft, const SfxItemSet * pItemSet = 0 );
193 ~IconChoiceDialog ();
195 virtual void Paint( const Rectangle& rRect );
196 virtual void Resize();
198 // interface
199 SvxIconChoiceCtrlEntry* AddTabPage(
200 sal_uInt16 nId, const String& rIconText, const Image& rChoiceIcon,
201 CreatePage pCreateFunc /* != NULL */, GetPageRanges pRangesFunc = NULL /* NULL allowed*/,
202 sal_Bool bItemsOnDemand = sal_False, sal_uLong nPos = LIST_APPEND );
204 void SetCurPageId( sal_uInt16 nId ) { mnCurrentPageId = nId; FocusOnIcon( nId ); }
205 sal_uInt16 GetCurPageId() const { return mnCurrentPageId; }
206 void ShowPage( sal_uInt16 nId );
208 /// gives via map converted local slots if applicable
209 const sal_uInt16* GetInputRanges( const SfxItemPool& );
210 void SetInputSet( const SfxItemSet* pInSet );
211 const SfxItemSet* GetOutputItemSet() const { return pOutSet; }
213 const OKButton& GetOKButton() const { return aOKBtn; }
214 OKButton& GetOKButton() { return aOKBtn; }
215 const CancelButton& GetCancelButton() const { return aCancelBtn; }
216 CancelButton& GetCancelButton() { return aCancelBtn; }
217 const HelpButton& GetHelpButton() const { return aHelpBtn; }
218 HelpButton& GetHelpButton() { return aHelpBtn; }
220 short Execute();
221 void Start( sal_Bool bShow = sal_True );
222 sal_Bool QueryClose();
224 const SfxItemSet* GetExampleSet() const { return pExampleSet; }
226 EIconChoicePos SetCtrlPos ( const EIconChoicePos& rPos );
229 #endif //_ICCDLG_HXX
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */