LibreOffice Module vcl (master)  1
tabctrl.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 #ifndef INCLUDED_VCL_TABCTRL_HXX
21 #define INCLUDED_VCL_TABCTRL_HXX
22 
23 #include <config_options.h>
24 #include <vcl/dllapi.h>
25 #include <vcl/ctrl.hxx>
26 #include <vcl/toolbox.hxx>
27 #include <vcl/EnumContext.hxx>
29 
30 class ImplTabItem;
31 struct ImplTabCtrlData;
32 class TabPage;
33 class Button;
34 class PushButton;
35 class ListBox;
36 
37 #ifndef TAB_APPEND
38 #define TAB_APPEND (sal_uInt16(0xFFFF))
39 #define TAB_PAGE_NOTFOUND (sal_uInt16(0xFFFF))
40 #endif /* !TAB_APPEND */
41 
42 #define TAB_OFFSET 3
43 #define TAB_TABOFFSET_X 3
44 #define TAB_TABOFFSET_Y 3
45 #define TAB_EXTRASPACE_X 6
46 #define TAB_BORDER_LEFT 1
47 #define TAB_BORDER_TOP 1
48 #define TAB_BORDER_RIGHT 2
49 #define TAB_BORDER_BOTTOM 2
50 
52 {
53 protected:
54  std::unique_ptr<ImplTabCtrlData> mpTabCtrlData;
57  sal_uInt16 mnActPageId;
58  sal_uInt16 mnCurPageId;
59  bool mbFormat;
65 
67  SAL_DLLPRIVATE void ImplInitSettings( bool bBackground );
68  SAL_DLLPRIVATE ImplTabItem* ImplGetItem( sal_uInt16 nId ) const;
69  SAL_DLLPRIVATE ImplTabItem* ImplGetItem(const Point& rPt) const;
70  SAL_DLLPRIVATE Size ImplGetItemSize( ImplTabItem* pItem, tools::Long nMaxWidth );
71  SAL_DLLPRIVATE tools::Rectangle ImplGetTabRect( sal_uInt16 nPos, tools::Long nWidth = -1, tools::Long nHeight = -1 );
72  SAL_DLLPRIVATE tools::Rectangle ImplGetTabRect(const ImplTabItem*, tools::Long nWidth, tools::Long nHeight);
73  SAL_DLLPRIVATE void ImplChangeTabPage( sal_uInt16 nId, sal_uInt16 nOldId );
74  SAL_DLLPRIVATE bool ImplPosCurTabPage();
75  virtual void ImplActivateTabPage( bool bNext );
76  SAL_DLLPRIVATE void ImplShowFocus();
77  SAL_DLLPRIVATE void ImplDrawItem(vcl::RenderContext& rRenderContext, ImplTabItem const * pItem,
78  const tools::Rectangle& rCurRect, bool bFirstInGroup,
79  bool bLastInGroup);
80  SAL_DLLPRIVATE void ImplFreeLayoutData();
81  SAL_DLLPRIVATE bool ImplHandleKeyEvent( const KeyEvent& rKeyEvent );
82 
83  DECL_DLLPRIVATE_LINK( ImplListBoxSelectHdl, ListBox&, void );
84  DECL_DLLPRIVATE_LINK( ImplWindowEventListener, VclWindowEvent&, void );
85 
86  using Window::ImplInit;
87  SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
88 
89  virtual void FillLayoutData() const override;
90  virtual const vcl::Font& GetCanonicalFont( const StyleSettings& _rStyle ) const override;
91  virtual const Color& GetCanonicalTextColor( const StyleSettings& _rStyle ) const override;
92  virtual bool ImplPlaceTabs( tools::Long nWidth );
93  SAL_DLLPRIVATE Size ImplCalculateRequisition(sal_uInt16& nHeaderHeight) const;
94 
95 public:
96  TabControl( vcl::Window* pParent,
97  WinBits nStyle = WB_STDTABCONTROL );
98  virtual ~TabControl() override;
99  virtual void dispose() override;
100 
101  virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
102  virtual void KeyInput( const KeyEvent& rKEvt ) override;
103  virtual void Paint( vcl::RenderContext& rRenderContext, const tools::Rectangle& rRect ) override;
104  virtual void Resize() override;
105  virtual void GetFocus() override;
106  virtual void LoseFocus() override;
107  virtual void RequestHelp( const HelpEvent& rHEvt ) override;
108  virtual void Command( const CommandEvent& rCEvt ) override;
109  virtual bool EventNotify( NotifyEvent& rNEvt ) override;
110  virtual void StateChanged( StateChangedType nType ) override;
111  virtual void DataChanged( const DataChangedEvent& rDCEvt ) override;
112  virtual bool PreNotify( NotifyEvent& rNEvt ) override;
113 
114  void ActivatePage();
115  bool DeactivatePage();
116 
117  virtual Size GetOptimalSize() const override;
118 
119  void SetTabPageSizePixel( const Size& rSize );
120 
121  void InsertPage( sal_uInt16 nPageId, const OUString& rText,
122  sal_uInt16 nPos = TAB_APPEND );
123  void RemovePage( sal_uInt16 nPageId );
124 
125  void SetPageEnabled(sal_uInt16 nPageId, bool bEnable = true);
126  void SetPageVisible(sal_uInt16 nPageId, bool bVisible = true);
127 
128  sal_uInt16 GetPagePos( sal_uInt16 nPageId ) const;
129  sal_uInt16 GetPageCount() const;
130  sal_uInt16 GetPageId( sal_uInt16 nPos ) const;
131  sal_uInt16 GetPageId(const Point& rPos) const;
132  sal_uInt16 GetPageId( const OString& rName ) const;
133 
134  void SetCurPageId(sal_uInt16 nPageId);
135  sal_uInt16 GetCurPageId() const;
136 
137  void SelectTabPage( sal_uInt16 nPageId );
138 
139  void SetTabPage(sal_uInt16 nPageId, TabPage* pPage);
140  TabPage* GetTabPage( sal_uInt16 nPageId ) const;
141 
142  void SetPageText( sal_uInt16 nPageId, const OUString& rText );
143  OUString const & GetPageText( sal_uInt16 nPageId ) const;
144 
145  void SetHelpText( sal_uInt16 nPageId, const OUString& rText );
146  const OUString& GetHelpText( sal_uInt16 nPageId ) const;
147 
148  void SetPageName( sal_uInt16 nPageId, const OString& rName ) const;
149  OString GetPageName( sal_uInt16 nPageId ) const;
150 
151  void SetAccessibleName( sal_uInt16 nItemId, const OUString& rStr );
152  OUString GetAccessibleName( sal_uInt16 nItemId ) const;
153 
154  void SetAccessibleDescription( sal_uInt16 nItemId, const OUString& rStr );
155  OUString GetAccessibleDescription( sal_uInt16 nItemId ) const;
156 
157  void SetPageImage( sal_uInt16 nPageId, const Image& rImage );
158 
159  using Control::SetHelpId;
160  using Control::GetHelpId;
161 
162  void SetActivatePageHdl( const Link<TabControl*,void>& rLink ) { maActivateHdl = rLink; }
163  void SetDeactivatePageHdl( const Link<TabControl*, bool>& rLink ) { maDeactivateHdl = rLink; }
164 
165  // returns (control relative) bounding rectangle for the
166  // character at index nIndex relative to the text of page nPageId
168  tools::Rectangle GetCharacterBounds( sal_uInt16 nPageId, tools::Long nIndex ) const;
169 
170  // returns the index relative to the text of page nPageId (also returned)
171  // at position rPoint (control relative)
173  tools::Long GetIndexForPoint( const Point& rPoint, sal_uInt16& rPageId ) const;
174 
175  // returns the rectangle of the tab for page nPageId
176  tools::Rectangle GetTabBounds( sal_uInt16 nPageId ) const;
177 
178  virtual void SetPosPixel(const Point& rPos) override;
179  virtual void SetSizePixel(const Size& rNewSize) override;
180  virtual void SetPosSizePixel(const Point& rNewPos, const Size& rNewSize) override;
181 
182  virtual Size calculateRequisition() const;
183  void setAllocation(const Size &rAllocation);
184 
185  std::vector<sal_uInt16> GetPageIDs() const;
186 
187  virtual FactoryFunction GetUITestFactory() const override;
188 
189  virtual void queue_resize(StateChangedType eReason = StateChangedType::Layout) override;
190 
191  virtual void DumpAsPropertyTree(tools::JsonWriter&) override;
192 };
193 
194 class NotebookBar;
195 
196 class UNLESS_MERGELIBS(VCL_DLLPUBLIC) NotebookbarTabControlBase : public TabControl,
198 {
199 public:
200  NotebookbarTabControlBase( vcl::Window* pParent );
201  ~NotebookbarTabControlBase() override;
202  void dispose() override;
203 
204  void SetContext( vcl::EnumContext::Context eContext ) override;
205  void SetIconClickHdl( Link<NotebookBar*, void> aHdl );
206  void SetToolBox( ToolBox* pToolBox );
207  ToolBox* GetToolBox() { return m_pShortcuts; }
208  Control* GetOpenMenu();
209 
210  virtual Size calculateRequisition() const override;
211  static sal_uInt16 GetHeaderHeight();
212 
213 protected:
214  virtual bool ImplPlaceTabs( tools::Long nWidth ) override;
215  virtual void ImplActivateTabPage( bool bNext ) override;
216 
217 private:
218  bool bLastContextWasSupported;
219  vcl::EnumContext::Context eLastContext;
220  Link<NotebookBar*,void> m_aIconClickHdl;
221  static sal_uInt16 m_nHeaderHeight;
222  VclPtr<ToolBox> m_pShortcuts;
223  VclPtr<PushButton> m_pOpenMenu;
224  DECL_LINK(OpenMenu, Button*, void);
225 };
226 
227 #endif // INCLUDED_VCL_TABCTRL_HXX
228 
229 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual FactoryFunction GetUITestFactory() const
Definition: window.cxx:3931
bool mbLayoutDirty
Definition: tabctrl.hxx:62
bool mbSmallInvalidate
Definition: tabctrl.hxx:61
tools::Long mnLastWidth
Definition: tabctrl.hxx:55
DECL_DLLPRIVATE_LINK(ImplHandlePaintHdl, Timer *, void)
virtual void MouseButtonDown(const MouseEvent &rMEvt)
Definition: mouse.cxx:419
A widget used to choose from a list of items and which has no entry.
Definition: lstbox.hxx:82
#define VCL_DLLPUBLIC
Definition: dllapi.h:29
long Long
tools::Long mnLastHeight
Definition: tabctrl.hxx:56
sal_uInt16 mnActPageId
Definition: tabctrl.hxx:57
const OUString & GetHelpText() const
Definition: window.cxx:3087
virtual void StateChanged(StateChangedType nStateChange) override
Definition: ctrl.cxx:255
virtual void FillLayoutData() const
Definition: ctrl.cxx:79
void SetAccessibleName(const OUString &rName)
Link< TabControl *, bool > maDeactivateHdl
Definition: tabctrl.hxx:64
std::function< std::unique_ptr< UIObject >vcl::Window *)> FactoryFunction
virtual void SetSizePixel(const Size &rNewSize)
Definition: window2.cxx:1256
OUString GetAccessibleDescription() const
std::unique_ptr< ImplTabCtrlData > mpTabCtrlData
Definition: tabctrl.hxx:54
void SetHelpId(const OString &)
Definition: window2.cxx:812
virtual const Color & GetCanonicalTextColor(const StyleSettings &_rStyle) const
Definition: ctrl.cxx:407
virtual Size calculateRequisition() const
Definition: tabctrl.cxx:2146
StateChangedType
Definition: window.hxx:289
OUString GetAccessibleName() const
sal_Int64 WinBits
virtual void DumpAsPropertyTree(tools::JsonWriter &)
Dumps itself and potentially its children to a property tree, to be written easily to JSON...
Definition: window.cxx:3355
virtual void queue_resize(StateChangedType eReason=StateChangedType::Layout)
Definition: window2.cxx:1321
bool mbRestoreHelpId
Definition: tabctrl.hxx:60
void SetHelpText(const OUString &rHelpText)
Definition: window2.cxx:1214
sal_uInt16 mnCurPageId
Definition: tabctrl.hxx:58
const OString & GetHelpId() const
Definition: window2.cxx:817
virtual bool PreNotify(NotifyEvent &rNEvt)
Definition: event.cxx:52
virtual bool ImplPlaceTabs(tools::Long nWidth)
Definition: tabctrl.cxx:391
Link< TabControl *, void > maActivateHdl
Definition: tabctrl.hxx:63
Some things multiple-inherit from VclAbstractDialog and OutputDevice, so we need to use virtual inher...
Definition: outdev.hxx:168
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: ctrl.cxx:57
virtual void LoseFocus()
Definition: window.cxx:1852
void SetActivatePageHdl(const Link< TabControl *, void > &rLink)
Definition: tabctrl.hxx:162
virtual void SetPosSizePixel(const Point &rNewPos, const Size &rNewSize)
Definition: window2.cxx:1262
bool mbFormat
Definition: tabctrl.hxx:59
virtual void KeyInput(const KeyEvent &rKEvt)
Definition: window.cxx:1802
SAL_DLLPRIVATE void ImplInit(vcl::Window *pParent, WinBits nStyle, SystemParentData *pSystemParentData)
Definition: window.cxx:935
virtual Size GetOptimalSize() const override
Definition: ctrl.cxx:368
void SetDeactivatePageHdl(const Link< TabControl *, bool > &rLink)
Definition: tabctrl.hxx:163
virtual void Resize() override
Definition: ctrl.cxx:73
tools::Long GetIndexForPoint(const Point &rPoint) const
Definition: ctrl.cxx:133
virtual void dispose() override
This is intended to be used to clear any locally held references to other Window-subclass objects...
Definition: tabctrl.cxx:198
Definition: ctrl.hxx:81
virtual void GetFocus()
Definition: window.cxx:1838
void SetAccessibleDescription(const OUString &rDescr)
virtual const vcl::Font & GetCanonicalFont(const StyleSettings &_rStyle) const
Definition: ctrl.cxx:402
virtual void ImplActivateTabPage(bool bNext)
Definition: tabctrl.cxx:729
Definition: image.hxx:39
tools::Rectangle GetCharacterBounds(tools::Long nIndex) const
Definition: ctrl.cxx:109
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)
Definition: paint.cxx:1041
void ImplInitSettings()
Definition: ctrl.cxx:422
virtual void SetContext(vcl::EnumContext::Context eContext)=0
virtual void Command(const CommandEvent &rCEvt)
Definition: window.cxx:1920
This implements Widget Layout-based notebook-like menu bar.
Definition: notebookbar.hxx:26
virtual void RequestHelp(const HelpEvent &rHEvt)
Definition: window.cxx:1866
virtual void SetPosPixel(const Point &rNewPos)
Definition: window2.cxx:1251
virtual void DataChanged(const DataChangedEvent &rDCEvt)
Definition: event.cxx:36
virtual bool EventNotify(NotifyEvent &rNEvt) override
Definition: ctrl.cxx:224
#define TAB_APPEND
Definition: tabctrl.hxx:38