Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef INCLUDED_CUI_SOURCE_INC_ICONCDLG_HXX
20 : #define INCLUDED_CUI_SOURCE_INC_ICONCDLG_HXX
21 :
22 : #include <rtl/ustring.hxx>
23 : #include <svl/itempool.hxx>
24 : #include <svl/itemset.hxx>
25 : #include <svtools/ivctrl.hxx>
26 : #include <vcl/tabpage.hxx>
27 : #include <vcl/msgbox.hxx>
28 : #include <vcl/dialog.hxx>
29 : #include <vcl/button.hxx>
30 : #include <vcl/image.hxx>
31 : #include <vector>
32 :
33 : #define CTRLS_OFFSET 3
34 : #define RET_USER 100
35 : #define RET_USER_CANCEL 101
36 :
37 : // forward-declarations
38 : struct IconChoicePageData;
39 : class IconChoiceDialog;
40 : class IconChoicePage;
41 :
42 : // Create-Function
43 : typedef IconChoicePage* (*CreatePage)(Window *pParent, const SfxItemSet &rAttrSet);
44 : typedef sal_uInt16* (*GetPageRanges)(); // gives international Which-value
45 :
46 : // position of iconchoicectrl
47 : enum EIconChoicePos { PosLeft, PosRight, PosTop, PosBottom };
48 :
49 : /// Data-structure for pages in dialog
50 : struct IconChoicePageData
51 : {
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
58 :
59 : // constructor
60 0 : 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 0 : bRefresh ( sal_False )
67 0 : {}
68 : };
69 :
70 : class IconChoicePage : public TabPage
71 : {
72 : using TabPage::ActivatePage;
73 : using TabPage::DeactivatePage;
74 :
75 : private :
76 : const SfxItemSet* pSet;
77 : OUString aUserString;
78 : sal_Bool bHasExchangeSupport;
79 : IconChoiceDialog* pDialog;
80 :
81 : void SetDialog( IconChoiceDialog* pNew ) { pDialog = pNew; }
82 : IconChoiceDialog* GetDialog() const { return pDialog; }
83 :
84 : void SetInputSet( const SfxItemSet* pNew ) { pSet = pNew; }
85 :
86 : void ImplInitSettings();
87 :
88 : protected :
89 : IconChoicePage( Window *pParent, const ResId &, const SfxItemSet &rAttrSet );
90 :
91 : sal_uInt16 GetSlot( sal_uInt16 nWhich ) const { return pSet->GetPool()->GetSlotId( nWhich ); }
92 0 : sal_uInt16 GetWhich( sal_uInt16 nSlot ) const { return pSet->GetPool()->GetWhich( nSlot ); }
93 :
94 : public :
95 : virtual ~IconChoicePage();
96 :
97 0 : const SfxItemSet& GetItemSet() const { return *pSet; }
98 :
99 : virtual bool FillItemSet( SfxItemSet& ) = 0;
100 : virtual void Reset( const SfxItemSet& ) = 0;
101 :
102 0 : sal_Bool HasExchangeSupport() const { return bHasExchangeSupport; }
103 0 : void SetExchangeSupport( sal_Bool bNew = sal_True ) { bHasExchangeSupport = bNew; }
104 :
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
112 : };
113 :
114 : virtual void ActivatePage( const SfxItemSet& );
115 : virtual int DeactivatePage( SfxItemSet* pSet = 0 );
116 0 : void SetUserData(const OUString& rString) { aUserString = rString; }
117 0 : OUString GetUserData() { return aUserString; }
118 : virtual void FillUserData();
119 : virtual sal_Bool IsReadOnly() const;
120 : virtual sal_Bool QueryClose();
121 :
122 : void StateChanged( StateChangedType nType ) SAL_OVERRIDE;
123 : void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
124 : };
125 :
126 : class IconChoiceDialog : public ModalDialog
127 : {
128 : private :
129 : friend class IconChoicePage;
130 :
131 : EIconChoicePos meChoicePos;
132 : ::std::vector< IconChoicePageData* > maPageList;
133 :
134 : SvtIconChoiceCtrl maIconCtrl;
135 :
136 : sal_uInt16 mnCurrentPageId;
137 :
138 : // Buttons
139 : OKButton aOKBtn;
140 : CancelButton aCancelBtn;
141 : HelpButton aHelpBtn;
142 : PushButton aResetBtn;
143 :
144 : const SfxItemSet* pSet;
145 : SfxItemSet* pOutSet;
146 : SfxItemSet* pExampleSet;
147 : sal_uInt16* pRanges;
148 :
149 : sal_uInt32 nResId;
150 :
151 : sal_Bool bHideResetBtn;
152 : sal_Bool bModal;
153 : sal_Bool bInOK;
154 : sal_Bool bModified;
155 : sal_Bool bItemsReset;
156 :
157 : DECL_LINK ( ChosePageHdl_Impl, void * );
158 : DECL_LINK(OkHdl, void *);
159 : DECL_LINK(ResetHdl, void *);
160 : DECL_LINK(CancelHdl, void *);
161 :
162 : IconChoicePageData* GetPageData ( sal_uInt16 nId );
163 : void Start_Impl();
164 : sal_Bool OK_Impl();
165 :
166 : void SetPosSizeCtrls ( sal_Bool bInit = sal_False );
167 : void SetPosSizePages ( sal_uInt16 nId );
168 :
169 : void FocusOnIcon ( sal_uInt16 nId );
170 :
171 : protected :
172 : void ShowPageImpl ( IconChoicePageData* pData );
173 : void HidePageImpl ( IconChoicePageData* pData );
174 :
175 : virtual void PageCreated( sal_uInt16 nId, IconChoicePage& rPage );
176 : virtual SfxItemSet* CreateInputItemSet( sal_uInt16 nId );
177 : inline SfxItemSet* GetInputSetImpl() { return (SfxItemSet*)pSet; }
178 0 : inline IconChoicePage* GetTabPage( sal_uInt16 nPageId )
179 0 : { return ( GetPageData (nPageId)->pPage?GetPageData (nPageId)->pPage:NULL); }
180 : const SfxItemSet* GetRefreshedSet();
181 :
182 : void ActivatePageImpl ();
183 : sal_Bool DeActivatePageImpl ();
184 : void ResetPageImpl ();
185 :
186 : short Ok();
187 :
188 : public :
189 :
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 : virtual ~IconChoiceDialog ();
194 :
195 : virtual void Paint( const Rectangle& rRect ) SAL_OVERRIDE;
196 : virtual void Resize() SAL_OVERRIDE;
197 :
198 : // interface
199 : SvxIconChoiceCtrlEntry* AddTabPage(
200 : sal_uInt16 nId, const OUString& rIconText, const Image& rChoiceIcon,
201 : CreatePage pCreateFunc /* != NULL */, GetPageRanges pRangesFunc = NULL /* NULL allowed*/,
202 : sal_Bool bItemsOnDemand = sal_False, sal_uLong nPos = TREELIST_APPEND );
203 :
204 0 : void SetCurPageId( sal_uInt16 nId ) { mnCurrentPageId = nId; FocusOnIcon( nId ); }
205 0 : sal_uInt16 GetCurPageId() const { return mnCurrentPageId; }
206 : void ShowPage( sal_uInt16 nId );
207 :
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; }
212 :
213 : const OKButton& GetOKButton() const { return aOKBtn; }
214 0 : OKButton& GetOKButton() { return aOKBtn; }
215 : const CancelButton& GetCancelButton() const { return aCancelBtn; }
216 0 : CancelButton& GetCancelButton() { return aCancelBtn; }
217 : const HelpButton& GetHelpButton() const { return aHelpBtn; }
218 : HelpButton& GetHelpButton() { return aHelpBtn; }
219 :
220 : short Execute() SAL_OVERRIDE;
221 : void Start( sal_Bool bShow = sal_True );
222 : sal_Bool QueryClose();
223 :
224 : const SfxItemSet* GetExampleSet() const { return pExampleSet; }
225 :
226 : EIconChoicePos SetCtrlPos ( const EIconChoicePos& rPos );
227 : };
228 :
229 : #endif // INCLUDED_CUI_SOURCE_INC_ICONCDLG_HXX
230 :
231 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|