1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
22 #include <svl/stritem.hxx>
23 #include <sfx2/tbxctrl.hxx>
24 #include <vcl/InterimItemWindow.hxx>
26 #include "doceventnotifier.hxx"
27 #include "scriptdocument.hxx"
32 * @brief Manage states of macro and dialog Library ComboBox
36 class LibBoxControl
: public SfxToolBoxControl
40 * Macro for registering two methods
43 * static SfxToolBoxControl* CreateImpl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx)
44 * static void RegisterControl(sal_uInt16 nSlotId = 0, SfxModule* pMod=nullptr)
46 * @see Macro SFX_IMPL_TOOLBOX_CONTROL
48 SFX_DECL_TOOLBOX_CONTROL();
51 * @param nSlotId -- the slot as internal operation number
52 * @param nId -- this item's unique id in ToolBox
53 * @param rTbx -- the ToolBox which contains this ComboBox
55 LibBoxControl(sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
);
58 * Triggered if state was changed
60 * @param nSlotID -- the slot as internal operation number (not used in this place)
61 * @param eState -- enum value which contains ComboBox state
64 virtual void StateChangedAtToolBoxControl(sal_uInt16 nSlotID
, SfxItemState eState
,
65 const SfxPoolItem
* pState
) override
;
67 * Create combobox of Macro and Dialog Library
69 * @param pParent -- parent window
70 * @return ComboBox of macro and dialog Library
72 virtual VclPtr
<InterimItemWindow
> CreateItemWindow(vcl::Window
* pParent
) override
;
76 * @brief Base class for all ComboBox elements.
78 * Base class for ComboBoxes which need to update their content according
79 * to the list of open documents.
81 class DocListenerBox
: public InterimItemWindow
, public DocumentEventListener
84 DECL_LINK(SelectHdl
, weld::ComboBox
&, void);
85 DECL_LINK(KeyInputHdl
, const KeyEvent
&, bool);
88 std::unique_ptr
<weld::ComboBox
> m_xWidget
;
90 /// @param pParent -- parent window
91 DocListenerBox(vcl::Window
* pParent
);
92 virtual ~DocListenerBox() override
;
93 virtual void dispose() override
;
95 virtual void Select() = 0;
96 virtual void FillBox() = 0;
98 /// key strokes the ComboBox receives
99 virtual bool HandleKeyInput(const KeyEvent
& rKEvt
);
102 // DocumentEventListener
103 virtual void onDocumentCreated(const ScriptDocument
& _rDoc
) override
;
104 virtual void onDocumentOpened(const ScriptDocument
& _rDoc
) override
;
105 virtual void onDocumentSave(const ScriptDocument
& _rDoc
) override
;
106 virtual void onDocumentSaveDone(const ScriptDocument
& _rDoc
) override
;
107 virtual void onDocumentSaveAs(const ScriptDocument
& _rDoc
) override
;
108 virtual void onDocumentSaveAsDone(const ScriptDocument
& _rDoc
) override
;
109 virtual void onDocumentClosed(const ScriptDocument
& _rDoc
) override
;
110 virtual void onDocumentTitleChanged(const ScriptDocument
& _rDoc
) override
;
111 virtual void onDocumentModeChanged(const ScriptDocument
& _rDoc
) override
;
113 DocumentEventNotifier maNotifier
;
116 void set_sensitive(bool bSensitive
);
120 * @brief Macros and Dialogs Library ComboBox
122 * @see LibBoxControl Class
124 class LibBox
: public DocListenerBox
128 LibBox(vcl::Window
* pParent
);
129 virtual ~LibBox() override
;
130 virtual void dispose() override
;
133 * Update selection in ComboBox of macro and dialog Library
135 * @param pItem -- string that was selected
137 void Update(const SfxStringItem
* pItem
);
140 /// Called for setting language when user selects a language in ComboBox
141 virtual void Select() override
;
144 static void ReleaseFocus();
147 * Insert name library in specified position
149 * @param rDocument -- macro or dialog
150 * @param eLocation -- enum value of Locations
152 void InsertEntries(const ScriptDocument
& rDocument
, LibraryLocation eLocation
);
157 /// Fill up the combobox
158 virtual void FillBox() override
;
163 * @param rKEvt represents key event
164 * @return a bool value: true if was handled, and false if there was nothing handled
166 virtual bool HandleKeyInput(const KeyEvent
& rKEvt
) override
;
168 DECL_LINK(FocusInHdl
, weld::Widget
&, void);
169 DECL_LINK(FocusOutHdl
, weld::Widget
&, void);
171 OUString maCurrentText
;
173 bool mbFillBox
; ///< If true, when FillBox() is called
177 * @brief Manage stats of Language ComboBox
179 * @see LanguageBox Class
181 class LanguageBoxControl
: public SfxToolBoxControl
184 /*! Macro for registering two methods
187 * static SfxToolBoxControl* CreateImpl(sal_uInt16 nSlotId, sal_uInt16 nId, ToolBox& rTbx)
188 * static void RegisterControl(sal_uInt16 nSlotId = 0, SfxModule* pMod=nullptr)
190 * @see Macro SFX_IMPL_TOOLBOX_CONTROL
192 SFX_DECL_TOOLBOX_CONTROL();
195 * @param nSlotId -- the slot as internal operation number
196 * @param nId -- this item's unique id in ToolBox
197 * @param rTbx -- the ToolBox which contains this ComboBox
199 LanguageBoxControl(sal_uInt16 nSlotId
, ToolBoxItemId nId
, ToolBox
& rTbx
);
202 * Triggered if state was changed
204 * @param nSlotID -- the slot as internal operation number (not used in this place)
205 * @param eState -- enum value which contains ComboBox state
208 virtual void StateChangedAtToolBoxControl(sal_uInt16 nSID
, SfxItemState eState
,
209 const SfxPoolItem
* pState
) override
;
211 * Create ComboBox of Language
214 * @return LanguageBox ComboBox
216 virtual VclPtr
<InterimItemWindow
> CreateItemWindow(vcl::Window
* pParent
) override
;
220 * @brief Class language ComboBox
222 * @see LanguageBoxControl Class
224 class LanguageBox
: public DocListenerBox
230 LanguageBox(vcl::Window
* pParent
);
231 virtual ~LanguageBox() override
;
232 virtual void dispose() override
;
235 * Update selection in ComboBox of macro and dialog Library
237 * @param pItem -- string that was selected
239 void Update(const SfxStringItem
* pItem
);
242 /// Called for setting language when user selects a language in ComboBox
243 virtual void Select() override
;
248 * @param rKEvt represents key event
249 * @return a bool value: true if was handled, and false if there was nothing handled
251 virtual bool HandleKeyInput(const KeyEvent
& rKEvt
) override
;
254 /// Delete all languages from ComboBox
256 /// Switch interface of dialog to selected language
259 /// Fill up the language combobox
260 virtual void FillBox() override
;
262 OUString msNotLocalizedStr
;
263 OUString msDefaultLanguageStr
;
264 OUString msCurrentText
;
266 bool mbIgnoreSelect
; ///< do not use in this class
269 } // namespace basctl
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */