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 .
20 #ifndef INCLUDED_VCL_TABCTRL_HXX
21 #define INCLUDED_VCL_TABCTRL_HXX
23 #include <vcl/dllapi.h>
24 #include <vcl/ctrl.hxx>
25 #include <vcl/toolbox.hxx>
26 #include <vcl/EnumContext.hxx>
27 #include <sfx2/notebookbar/NotebookbarContextControl.hxx>
30 struct ImplTabCtrlData
;
36 #define TAB_APPEND ((sal_uInt16)0xFFFF)
37 #define TAB_PAGE_NOTFOUND ((sal_uInt16)0xFFFF)
38 #endif /* !TAB_APPEND */
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
49 class VCL_DLLPUBLIC TabControl
: public Control
52 ImplTabCtrlData
* mpTabCtrlData
;
56 sal_uInt16 mnActPageId
;
57 sal_uInt16 mnCurPageId
;
60 bool mbSmallInvalidate
;
62 Link
<TabControl
*,void> maActivateHdl
;
63 Link
<TabControl
*,bool> maDeactivateHdl
;
65 using Control::ImplInitSettings
;
66 SAL_DLLPRIVATE
void ImplInitSettings( bool bBackground
);
67 SAL_DLLPRIVATE ImplTabItem
* ImplGetItem( sal_uInt16 nId
) 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
void ImplChangeTabPage( sal_uInt16 nId
, sal_uInt16 nOldId
);
71 SAL_DLLPRIVATE
bool ImplPosCurTabPage();
72 virtual void ImplActivateTabPage( bool bNext
);
73 SAL_DLLPRIVATE
void ImplShowFocus();
74 SAL_DLLPRIVATE
void ImplDrawItem(vcl::RenderContext
& rRenderContext
, ImplTabItem
* pItem
,
75 const tools::Rectangle
& rCurRect
, bool bFirstInGroup
,
77 SAL_DLLPRIVATE
void ImplFreeLayoutData();
78 SAL_DLLPRIVATE
bool ImplHandleKeyEvent( const KeyEvent
& rKeyEvent
);
80 DECL_DLLPRIVATE_LINK( ImplListBoxSelectHdl
, ListBox
&, void );
81 DECL_DLLPRIVATE_LINK( ImplWindowEventListener
, VclWindowEvent
&, void );
83 using Window::ImplInit
;
84 SAL_DLLPRIVATE
void ImplInit( vcl::Window
* pParent
, WinBits nStyle
);
86 virtual void FillLayoutData() const override
;
87 virtual const vcl::Font
& GetCanonicalFont( const StyleSettings
& _rStyle
) const override
;
88 virtual const Color
& GetCanonicalTextColor( const StyleSettings
& _rStyle
) const override
;
89 SAL_DLLPRIVATE
tools::Rectangle
* ImplFindPartRect( const Point
& rPt
);
90 virtual bool ImplPlaceTabs( long nWidth
);
91 virtual void ImplPaint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
);
94 TabControl( vcl::Window
* pParent
,
95 WinBits nStyle
= WB_STDTABCONTROL
);
96 virtual ~TabControl() override
;
97 virtual void dispose() override
;
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
;
112 virtual void ActivatePage();
113 virtual bool DeactivatePage();
115 virtual Size
GetOptimalSize() const override
;
117 void SetTabPageSizePixel( const Size
& rSize
);
118 Size
GetTabPageSizePixel() const;
120 // pixel offset for the tab items, default is (0,0)
121 void SetItemsOffset( const Point
& rOffs
);
122 Point
GetItemsOffset() const;
124 void InsertPage( sal_uInt16 nPageId
, const OUString
& rText
,
125 sal_uInt16 nPos
= TAB_APPEND
);
126 void RemovePage( sal_uInt16 nPageId
);
128 void EnablePage( sal_uInt16 nPageId
, bool bEnable
= true );
130 sal_uInt16
GetPagePos( sal_uInt16 nPageId
) const;
131 sal_uInt16
GetPageCount() const;
132 sal_uInt16
GetPageId( sal_uInt16 nPos
) const;
133 virtual sal_uInt16
GetPageId( const Point
& rPos
) const;
134 sal_uInt16
GetPageId( const TabPage
& rPage
) const;
135 sal_uInt16
GetPageId( const OString
& rName
) const;
137 virtual void SetCurPageId( sal_uInt16 nPageId
);
138 sal_uInt16
GetCurPageId() const;
140 virtual void SelectTabPage( sal_uInt16 nPageId
);
142 void SetTabPage( sal_uInt16 nPageId
, TabPage
* pPage
);
143 TabPage
* GetTabPage( sal_uInt16 nPageId
) const;
145 void SetPageText( sal_uInt16 nPageId
, const OUString
& rText
);
146 OUString
const & GetPageText( sal_uInt16 nPageId
) const;
148 void SetHelpText( sal_uInt16 nPageId
, const OUString
& rText
);
149 const OUString
& GetHelpText( sal_uInt16 nPageId
) const;
151 void SetHelpId( sal_uInt16 nPageId
, const OString
& rId
) const;
152 OString
GetHelpId( sal_uInt16 nPageId
) const;
154 void SetPageName( sal_uInt16 nPageId
, const OString
& rName
) const;
155 OString
GetPageName( sal_uInt16 nPageId
) const;
157 void SetPageImage( sal_uInt16 nPageId
, const Image
& rImage
);
159 using Control::SetHelpId
;
160 using Control::GetHelpId
;
162 void SetActivatePageHdl( const Link
<TabControl
*,void>& rLink
) { maActivateHdl
= rLink
; }
163 void SetDeactivatePageHdl( const Link
<TabControl
*, bool>& rLink
) { maDeactivateHdl
= rLink
; }
165 // returns (control relative) bounding rectangle for the
166 // character at index nIndex relative to the text of page nPageId
167 using Control::GetCharacterBounds
;
168 tools::Rectangle
GetCharacterBounds( sal_uInt16 nPageId
, long nIndex
) const;
170 // returns the index relative to the text of page nPageId (also returned)
171 // at position rPoint (control relative)
172 using Control::GetIndexForPoint
;
173 long GetIndexForPoint( const Point
& rPoint
, sal_uInt16
& rPageId
) const;
175 // returns the rectangle of the tab for page nPageId
176 tools::Rectangle
GetTabBounds( sal_uInt16 nPageId
) const;
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
;
182 virtual Size
calculateRequisition() const;
183 void setAllocation(const Size
&rAllocation
);
185 std::vector
<sal_uInt16
> GetPageIDs() const;
187 virtual FactoryFunction
GetUITestFactory() const override
;
189 virtual void queue_resize(StateChangedType eReason
= StateChangedType::Layout
) override
;
194 class VCL_DLLPUBLIC NotebookbarTabControlBase
: public TabControl
,
195 public NotebookbarContextControl
198 NotebookbarTabControlBase( vcl::Window
* pParent
);
199 ~NotebookbarTabControlBase() override
;
200 void dispose() override
;
202 void SetContext( vcl::EnumContext::Context eContext
) override
;
203 void SetIconClickHdl( Link
<NotebookBar
*, void> aHdl
);
204 void SetToolBox( ToolBox
* pToolBox
);
205 ToolBox
* GetToolBox() { return m_pShortcuts
; }
207 virtual sal_uInt16
GetPageId( const Point
& rPos
) const override
;
208 virtual void SelectTabPage( sal_uInt16 nPageId
) override
;
209 virtual void SetCurPageId( sal_uInt16 nPageId
) override
;
210 virtual Size
calculateRequisition() const override
;
211 static sal_uInt16
GetHeaderHeight();
214 virtual bool ImplPlaceTabs( long nWidth
) override
;
215 virtual void ImplPaint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
& rRect
) override
;
216 virtual void ImplActivateTabPage( bool bNext
) override
;
219 bool bLastContextWasSupported
;
220 vcl::EnumContext::Context eLastContext
;
221 Link
<NotebookBar
*,void> m_aIconClickHdl
;
222 static sal_uInt16 m_nHeaderHeight
;
223 VclPtr
<ToolBox
> m_pShortcuts
;
226 #endif // INCLUDED_VCL_TABCTRL_HXX
228 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */