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