LibreOffice Module svtools (master) 1
tabbar.hxx
Go to the documentation of this file.
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
20#pragma once
21
22#include <svtools/svtdllapi.h>
23#include <tools/link.hxx>
24#include <vcl/window.hxx>
26#include <memory>
27
28class StyleSettings;
29
30/*
31
32Allowed StylbeBits
33------------------
34
35WB_SCROLL - The tabs can be scrolled via an extra field
36WB_MINSCROLL - The tabs can be scrolled via 2 additional buttons
37WB_RANGESELECT - Connected ranges can be selected
38WB_MULTISELECT - single tabs can be selected
39WB_BORDER - a border is drawn in the top and in the bottom
40WB_DRAG - A StartDrag handler is called by the TabBar, if drag
41 and drop should be started. In addition, drag and drop
42 is activated in the TabBar with EnableDrop().
43WB_SIZEABLE - a Split handler is called by the TabBar, if the user
44 wants to change the width of the TabBar
45WB_STDTABBAR - WB_BORDER
46
47
48Allowed PageBits
49-----------------
50
51Setting page bits modify the display attributes of the tab name
52
53TabBarPageBits::Blue
54 - Display tab name in light blue, used in draw for
55 invisible layers and in calc for scenario pages
56TabBarPageBits::Italic
57 - Display tab name italic, used in draw for
58 locked layers
59TabBarPageBits::Underline
60 - Display tab name underlined, used in draw for
61 non-printable layers
62
63
64Handlers
65-------
66
67Select - is called when a tab is selected or unselected
68DoubleClick - Is called when a DoubleClick has been fired in the
69 TabBar. Inside of the handler, GetCurPageId() returns
70 the clicked tab or 0, if no tab has been clicked.
71ActivatePage - Is called, if another page is activated.
72 GetCurPageId() returns the activated page.
73DeactivatePage - Is called, when a page is deactivated. If another page
74 may be activated, true must be returned; if another
75 page shall be excluded from the activation, false must
76 be returned. GetCurPageId() returns the page to be
77 deactivated.
78
79
80Drag and Drop
81-------------
82
83For Drag and Drop, the WinBit WB_DRAG must be set. In addition, the
84Command handler, the QueryDrop handler and the Drop handler must be overlaid.
85In doing so, the following must be implemented in the handlers:
86
87Command - If dragging should be started in this handler,
88 StartDrag() must be called. This method
89 then selects the respective entry or returns
90 false, if dragging cannot be carried out.
91
92QueryDrop - This handler is always called by StarView, when the
93 mouse is pulled over the window while dragging
94 (s.a. SV documentation). In this handler, it must be
95 determined whether a drop is possible. The drop
96 position can be shown in TabBar using ShowDropPos().
97 When calling, the position of the Event must be passed.
98 If the position is at the left or right border,
99 scrolling automatically takes place in the TabBar.
100 This method also returns the respective drop position,
101 which is also needed for a drop. If the window is left
102 while dragging, the drop position can be taken back
103 using HideDropPos(). Thus, it is also possible to handle
104 a drag which was triggered from outside the TabBar.
105
106Drop - In the Drop handler, the pages have to be moved, or
107 the new pages have to be inserted. The respective
108 drop position can be determined using ShowDropPos().
109
110The following methods are needed for Drag and Drop and must be called
111by the handlers:
112
113StartDrag - Must be called from the Command handler. As parameters,
114 the CommandEvent and a reference to a Region must be
115 passed. This vcl::Region then must be passed in
116 ExecuteDrag(), if the return value indicates that
117 ExecuteDrag shall be carried out. If the entry is not
118 selected, it is set as the current entry beforehand.
119 Because of this, attention must be paid that the Select
120 handler can be called from this method.
121
122ShowDropPos - This method must be called by the QueryDrop handler,
123 so that the TabBar shows where the Tabs are
124 inserted. This method can also be used in the Drop
125 handler, in order to determine the position at which
126 the Tabs shall be inserted. In the method, the
127 position of the Event must be passed. This method
128 returns the position, at which the Tabs shall be inserted.
129
130HideDropPos - This method takes back the DropPosition previously
131 displayed using ShowDropPos(). This method should be
132 called, when the window is left in the QueryDrop()
133 handler or the drag process has been ended.
134
135The following methods can be used if the pages should be switched
136in the Drag and Drop:
137
138SwitchPage - This method must be called by the QueryDrop handler
139 if the page, over which the mouse pointer resides,
140 should be switched. This method should be called
141 each time the QueryDrop-Handler is called.
142 Switching the page happens with a delay (500 ms) and
143 is automatically managed by this method.
144 The Position of the Event must be passed in the method.
145 This method returns true if the page has been switched.
146
147EndSwitchPage - This method resets the data for the switching of the
148 page. This method should be called when the window
149 is left in QueryDrop() or the drag process has been
150 ended.
151
152IsInSwitching - With this method, it can be queried in
153 ActivatePage()/DeactivatePage() whether this has been
154 caused by SwitchPage(). Thus, for example, switching
155 can be avoided in DeactivatePage() without an error
156 box.
157
158
159Window Resize
160--------------
161
162If the window width can be changed by the user, the WinBit WB_SIZEABLE
163must be set. In this case, the following handler must be overlaid:
164
165Split - When this handler is called, the window should be
166 adapted to the width that is returned by GetSplitSize().
167 In doing so, no minimal or maximum width is taken into
168 account. A minimal size can be queried using
169 GetMinSize() and the maximum width must be calculated
170 by the application itself. As only Online Resize is
171 supported, the window width must be changed inside
172 this handler and possibly the width of dependent windows
173 as well. For this handler, a link can also be set using
174 SetSplitHdl().
175
176The following methods deliver more information while Splitting:
177
178GetSplitSize() - Returns the width of the TabBar, to which the user
179 wants to resize the window. No minimum or maximum
180 width is taken into account. However, a width < 5
181 is never returned. This method only returns valid
182 values as long as splitting is active.
183
184GetMinSize() - With this method, a minimum window width can be
185 queried, so that at least something of a Tab is
186 visible. Still, the TabBar can be set more narrow
187 then the width that this method returns.
188 This method can also be called, when no splitting
189 is active.
190
191
192Edit Mode
193----------
194
195The TabBar also offers the user the possibility to change the names
196in the Tabs.
197
198EnableEditMode - With this, it can be configured that on Alt+LeftClick,
199 StartEditMode() is automatically called by the TabBar.
200 In the StartRenaming() handler, the renaming can still
201 be rejected.
202StartEditMode - With this method, the EditMode is started on a Tab.
203 false is returned, if the EditMode is already
204 active, the mode is rejected with StartRenaming()
205 or no space is available for editing.
206EndEditMode - With this method, the EditMode is ended.
207SetEditText - With this method, the text in the AllowRenaming()
208 handler can still be replaced by another text.
209GetEditText - With this method, the text, which the user has typed
210 in, can be queried in the AllowRenaming() handler.
211IsInEditMode - This method is used to query whether the EditMode
212 is active.
213IsEditModeCanceled - This method can be used in the EndRenaming()
214 handler to query whether the renaming has
215 been canceled.
216GetEditPageId - With this method, the tab that is being/has been
217 renamed is queried in the Renaming handlers.
218
219StartRenaming() - This handler is called when the EditMode hast been
220 started using StartEditMode(). GetEditPageId()
221 can be used to query which Tab should be renamed.
222 false should be returned if the EditMod should
223 not be started.
224AllowRenaming() - This handler is called when the EditMode is ended
225 (not in case of Cancel). Within this handler, it
226 can then be tested whether the text is OK.
227 The Tab which was renamed can be queried using
228 GetEditPageId().
229 One of the following values should be returned:
230 TAB_RENAMING_YES
231 The Tab is renamed.
232 TAB_RENAMING_NO
233 The Tab is not renamed, but the EditMode remains
234 active, so that the user can adapt the name
235 accordingly.
236 TAB_RENAMING_CANCEL
237 The EditMode was cancelled and the old text
238 is restored.
239EndRenaming() - This handler is called when the EditMode has been
240 ended. The tab that has been renamed can be
241 queried using GetEditPageId(). Using
242 IsEditModeCanceled(), it can be queried whether
243 the mode has been cancelled and the name has
244 thus not been changed.
245
246
247Maximum Page width
248-------------------
249
250The Page width of the tabs can be limited in order to make an easier
251navigation by them possible. If then, the text cannot be displayed
252completely, it is abbreviated with "..." and the whole text is
253displayed in the Tip or in the active help (if no help text is set).
254Using EnableAutoMaxPageWidth(), it can be configured whether the
255maximum page width should be based on the currently visible width
256(which is the default). Otherwise, the maximum page width can
257also be set using SetMaxPageWidth() (in pixels) (in this case, the
258AutoMaxPageWidth is ignored).
259
260ContextMenu
261-----------
262
263If a context-sensitive PopupMenu should be displayed, the Command
264handler must be overlaid. Using GetPageId() and when passing the
265mouse position, it can be determined whether the mouse click has been
266carried out over an item resp. over which item the mouse click has
267been carried out.
268*/
269
270namespace weld {
271class Button;
272}
273
274#define WB_RANGESELECT (WinBits(0x00200000))
275#define WB_MULTISELECT (WinBits(0x00400000))
276#define WB_MINSCROLL (WinBits(0x20000000))
277#define WB_INSERTTAB (WinBits(0x40000000))
278#define WB_STDTABBAR WB_BORDER
279
280// Page bits
281
282enum class TabBarPageBits {
283 NONE = 0x00,
284 Blue = 0x01,
285 Italic = 0x02,
286 Underline = 0x04,
287};
288namespace o3tl {
289 template<> struct typed_flags<TabBarPageBits> : is_typed_flags<TabBarPageBits, 0x07> {};
290};
291
292 // interface checks only, do not use in regular control flow
293
294#define TPB_DISPLAY_NAME_ALLFLAGS (TabBarPageBits::Blue | TabBarPageBits::Italic | TabBarPageBits::Underline)
295
296// - TabBar-Types - used in TabBar::AllowRenaming
297
303
304class MouseEvent;
305class DataChangedEvent;
306
307struct ImplTabBarItem;
308struct TabBar_Impl;
309
310
312{
313 friend class ImplTabSizer;
314
315private:
316 std::unique_ptr<TabBar_Impl> mpImpl;
317
318 OUString maEditText;
326 sal_uInt64 mnSwitchTime;
328 sal_uInt16 mnCurPageId;
329 sal_uInt16 mnFirstPos;
330 sal_uInt16 mnDropPos;
331 sal_uInt16 mnSwitchId;
332 sal_uInt16 mnEditId;
333
334 bool mbFormat : 1;
336 bool mbSizeFormat : 1;
339 bool mbDropPos : 1;
340 bool mbInSelect : 1;
341 bool mbMirrored : 1;
344
349
350 using Window::ImplInit;
351 SVT_DLLPRIVATE void ImplInit( WinBits nWinStyle, bool bSheets );
352 SVT_DLLPRIVATE void ImplInitSettings( bool bFont, bool bBackground );
353 SVT_DLLPRIVATE void ImplGetColors(const StyleSettings& rStyleSettings,
354 Color& rFaceColor, Color& rFaceTextColor,
355 Color& rSelectColor, Color& rSelectTextColor);
356 SVT_DLLPRIVATE void ImplShowPage( sal_uInt16 nPos );
357 SVT_DLLPRIVATE bool ImplCalcWidth();
358 SVT_DLLPRIVATE void ImplFormat();
359 SVT_DLLPRIVATE sal_uInt16 ImplGetLastFirstPos();
360 SVT_DLLPRIVATE void ImplInitControls();
361 SVT_DLLPRIVATE void ImplEnableControls();
362 SVT_DLLPRIVATE void ImplSelect();
363 SVT_DLLPRIVATE void ImplActivatePage();
364 SVT_DLLPRIVATE bool ImplDeactivatePage();
365 SVT_DLLPRIVATE void ImplPrePaint();
366 SVT_DLLPRIVATE ImplTabBarItem* ImplGetLastTabBarItem( sal_uInt16 nItemCount );
367
368 DECL_DLLPRIVATE_LINK(ImplClickHdl, weld::Button&, void);
369 DECL_DLLPRIVATE_LINK(ImplAddClickHandler, weld::Button&, void);
370 DECL_DLLPRIVATE_LINK(MousePressHdl, const MouseEvent&, bool);
371 DECL_DLLPRIVATE_LINK(ContextMenuHdl, const CommandEvent&, void);
372
373 ImplTabBarItem* seek( size_t i );
374 ImplTabBarItem* prev();
375 ImplTabBarItem* next();
376
377protected:
378 virtual void AddTabClick();
379 OUString GetAuxiliaryText(sal_uInt16 nPageId) const; // needed in derived class LayerTabBar
380 void SetAuxiliaryText(sal_uInt16 nPageId, const OUString& rText );
381
382public:
383 static const sal_uInt16 APPEND;
384 static const sal_uInt16 PAGE_NOT_FOUND;
385
386 TabBar(vcl::Window* pParent, WinBits nWinStyle, bool bSheets = false);
387 virtual ~TabBar() override;
388 virtual void dispose() override;
389
390 virtual void MouseMove( const MouseEvent& rMEvt ) override;
391 virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
392 virtual void MouseButtonUp( const MouseEvent& rMEvt ) override;
393 virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
394 virtual void Resize() override;
395 virtual void RequestHelp( const HelpEvent& rHEvt ) override;
396 virtual void StateChanged( StateChangedType nStateChange ) override;
397 virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
398 virtual bool PreNotify( NotifyEvent& rNEvt ) override;
399
400 virtual void Select();
401 virtual void DoubleClick();
402 void Split();
403 virtual void ActivatePage();
404 virtual bool DeactivatePage();
405 virtual bool StartRenaming();
406 virtual TabBarAllowRenamingReturnCode AllowRenaming();
407 virtual void EndRenaming();
408 virtual void Mirror();
409
410 virtual void InsertPage( sal_uInt16 nPageId, const OUString& rText,
412 sal_uInt16 nPos = TabBar::APPEND );
413 void RemovePage( sal_uInt16 nPageId );
414 void MovePage( sal_uInt16 nPageId, sal_uInt16 nNewPos );
415
416 Color GetTabBgColor( sal_uInt16 nPageId ) const;
417 void SetTabBgColor( sal_uInt16 nPageId, const Color& aTabBgColor );
418
419 void Clear();
420
421 bool IsPageEnabled( sal_uInt16 nPageId ) const;
422
423 void SetPageBits( sal_uInt16 nPageId, TabBarPageBits nBits );
424 TabBarPageBits GetPageBits( sal_uInt16 nPageId ) const;
425
426 sal_uInt16 GetPageCount() const;
427 sal_uInt16 GetPageId( sal_uInt16 nPos ) const;
428 sal_uInt16 GetPagePos( sal_uInt16 nPageId ) const;
429 sal_uInt16 GetCurPagePos() const { return GetPagePos(GetCurPageId()); }
430 sal_uInt16 GetPageId( const Point& rPos ) const;
431 tools::Rectangle GetPageRect( sal_uInt16 nPageId ) const;
432 // returns the rectangle in which page tabs are drawn
433 tools::Rectangle GetPageArea() const;
434
435 void SetCurPageId( sal_uInt16 nPageId );
436 sal_uInt16 GetCurPageId() const { return mnCurPageId; }
437
438 void SetFirstPageId( sal_uInt16 nPageId );
439 void MakeVisible( sal_uInt16 nPageId );
440
441 void SelectPage( sal_uInt16 nPageId, bool bSelect );
442 sal_uInt16 GetSelectPageCount() const;
443 bool IsPageSelected( sal_uInt16 nPageId ) const;
444 void SetProtectionSymbol( sal_uInt16 nPageId, bool bProtection );
445
446 void SetMaxPageWidth( tools::Long nMaxWidth );
447
448 void EnableEditMode() { mbAutoEditMode = true; }
449 bool StartEditMode( sal_uInt16 nPageId );
450 void EndEditMode( bool bCancel = false );
451 void SetEditText( const OUString& rText ) { maEditText = rText; }
452 const OUString& GetEditText() const { return maEditText; }
453 bool IsInEditMode() const;
454 bool IsEditModeCanceled() const { return mbEditCanceled; }
455 sal_uInt16 GetEditPageId() const { return mnEditId; }
456
462 void SetMirrored(bool bMirrored);
464 bool IsMirrored() const { return mbMirrored; }
465
469 void SetEffectiveRTL( bool bRTL );
471 bool IsEffectiveRTL() const;
472
473 bool StartDrag( const CommandEvent& rCEvt, vcl::Region& rRegion );
474 sal_uInt16 ShowDropPos( const Point& rPos );
475 void HideDropPos();
476 void SwitchPage( const Point& rPos );
477 void EndSwitchPage();
478
479 virtual void SetPageText( sal_uInt16 nPageId, const OUString& rText );
480 OUString GetPageText( sal_uInt16 nPageId ) const;
481 OUString GetHelpText( sal_uInt16 nPageId ) const;
482
483 tools::Long GetSplitSize() const { return mnSplitSize; }
484
487 using Window::SetHelpId;
488 using Window::GetHelpId;
489
490 void SetStyle( WinBits nStyle );
491 WinBits GetStyle() const { return mnWinStyle; }
492
493 void SetScrollAlwaysEnabled(bool bScrollAlwaysEnabled);
494
495 Size CalcWindowSizePixel() const;
496
497 void SetSelectHdl( const Link<TabBar*,void>& rLink ) { maSelectHdl = rLink; }
498 void SetSplitHdl( const Link<TabBar*,void>& rLink ) { maSplitHdl = rLink; }
499 void SetScrollAreaContextHdl( const Link<const CommandEvent&,void>& rLink ) { maScrollAreaContextHdl = rLink; }
500 void SetAddButtonEnabled(bool bAddButtonEnabled);
501
502 // accessibility
503 virtual css::uno::Reference<css::accessibility::XAccessible> CreateAccessible() override;
504};
505
506/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_uInt16 GetEditPageId() const
Definition: tabbar.hxx:455
bool mbFormat
Definition: tabbar.hxx:334
tools::Long mnLastOffX
Definition: tabbar.hxx:324
static const sal_uInt16 PAGE_NOT_FOUND
Definition: tabbar.hxx:384
bool mbMirrored
Definition: tabbar.hxx:341
bool mbDropPos
Definition: tabbar.hxx:339
tools::Long mnOffX
Definition: tabbar.hxx:322
sal_uInt16 GetCurPagePos() const
Definition: tabbar.hxx:429
OUString maEditText
Definition: tabbar.hxx:318
tools::Long mnOffY
Definition: tabbar.hxx:323
WinBits GetStyle() const
Definition: tabbar.hxx:491
std::unique_ptr< TabBar_Impl > mpImpl
Definition: tabbar.hxx:316
sal_uInt16 mnFirstPos
Definition: tabbar.hxx:329
void SetSelectHdl(const Link< TabBar *, void > &rLink)
Definition: tabbar.hxx:497
sal_uInt16 mnCurPageId
Definition: tabbar.hxx:328
tools::Long GetSplitSize() const
Definition: tabbar.hxx:483
bool IsMirrored() const
Returns true, if the control is set to mirrored mode (see SetMirrored()).
Definition: tabbar.hxx:464
Size maWinSize
Definition: tabbar.hxx:319
bool mbInSelect
Definition: tabbar.hxx:340
DECL_DLLPRIVATE_LINK(ContextMenuHdl, const CommandEvent &, void)
sal_uInt16 mnSwitchId
Definition: tabbar.hxx:331
DECL_DLLPRIVATE_LINK(MousePressHdl, const MouseEvent &, bool)
sal_uInt16 mnDropPos
Definition: tabbar.hxx:330
bool mbEditCanceled
Definition: tabbar.hxx:338
void SetEditText(const OUString &rText)
Definition: tabbar.hxx:451
sal_uInt16 mnEditId
Definition: tabbar.hxx:332
bool mbScrollAlwaysEnabled
Definition: tabbar.hxx:342
sal_uInt64 mnSwitchTime
Definition: tabbar.hxx:326
tools::Long mnSplitSize
Definition: tabbar.hxx:325
const OUString & GetEditText() const
Definition: tabbar.hxx:452
void SetScrollAreaContextHdl(const Link< const CommandEvent &, void > &rLink)
Definition: tabbar.hxx:499
void EnableEditMode()
Definition: tabbar.hxx:448
tools::Long mnCurMaxWidth
Definition: tabbar.hxx:321
DECL_DLLPRIVATE_LINK(ImplClickHdl, weld::Button &, void)
Link< TabBar *, void > maSelectHdl
Definition: tabbar.hxx:345
bool mbSheets
Definition: tabbar.hxx:343
bool IsEditModeCanceled() const
Definition: tabbar.hxx:454
Link< const CommandEvent &, void > maScrollAreaContextHdl
Definition: tabbar.hxx:347
DECL_DLLPRIVATE_LINK(ImplAddClickHandler, weld::Button &, void)
bool mbAutoEditMode
Definition: tabbar.hxx:337
bool mbFirstFormat
Definition: tabbar.hxx:335
size_t maCurrentItemList
Definition: tabbar.hxx:348
void SetSplitHdl(const Link< TabBar *, void > &rLink)
Definition: tabbar.hxx:498
WinBits mnWinStyle
Definition: tabbar.hxx:327
sal_uInt16 GetCurPageId() const
Definition: tabbar.hxx:436
static const sal_uInt16 APPEND
Definition: tabbar.hxx:383
Link< TabBar *, void > maSplitHdl
Definition: tabbar.hxx:346
tools::Long mnMaxPageWidth
Definition: tabbar.hxx:320
bool mbSizeFormat
Definition: tabbar.hxx:336
virtual void dispose() override
void SetStyle(WinBits nStyle)
virtual void RequestHelp(const HelpEvent &rHEvt)
virtual void StateChanged(StateChangedType nStateChange)
void SetHelpText(const OUString &rHelpText)
virtual void Resize()
virtual void MouseButtonDown(const MouseEvent &rMEvt)
virtual void MouseButtonUp(const MouseEvent &rMEvt)
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)
const OUString & GetHelpId() const
virtual bool PreNotify(NotifyEvent &rNEvt)
virtual css::uno::Reference< css::accessibility::XAccessible > CreateAccessible()
virtual void MouseMove(const MouseEvent &rMEvt)
virtual void DataChanged(const DataChangedEvent &rDCEvt)
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle, SystemParentData *pSystemParentData)
const OUString & GetHelpText() const
void SetHelpId(const OUString &)
virtual void SetCurPageId(const OUString &rName) override
void Clear(EHistoryType eHistory)
NONE
void SetMirrored(tools::Long &nPageLeftMargin, tools::Long &nPageRightMargin, tools::Long &nPageTopMargin, tools::Long &nPageBottomMargin, bool &bMirrored)
long Long
#define SVT_DLLPUBLIC
Definition: svtdllapi.h:27
#define SVT_DLLPRIVATE
Definition: svtdllapi.h:29
TabBarAllowRenamingReturnCode
Definition: tabbar.hxx:298
@ TABBAR_RENAMING_NO
Definition: tabbar.hxx:299
@ TABBAR_RENAMING_CANCEL
Definition: tabbar.hxx:301
@ TABBAR_RENAMING_YES
Definition: tabbar.hxx:300
TabBarPageBits
Definition: tabbar.hxx:282
StateChangedType
sal_Int64 WinBits