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