Line data Source code
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 :
26 : struct ImplTabItem;
27 : struct ImplTabCtrlData;
28 : class TabPage;
29 : class PushButton;
30 : class ListBox;
31 :
32 : #ifndef TAB_APPEND
33 : #define TAB_APPEND ((sal_uInt16)0xFFFF)
34 : #define TAB_PAGE_NOTFOUND ((sal_uInt16)0xFFFF)
35 : #endif /* !TAB_APPEND */
36 :
37 : #define TAB_OFFSET 3
38 : #define TAB_TABOFFSET_X 3
39 : #define TAB_TABOFFSET_Y 3
40 : #define TAB_EXTRASPACE_X 6
41 : #define TAB_BORDER_LEFT 1
42 : #define TAB_BORDER_TOP 1
43 : #define TAB_BORDER_RIGHT 2
44 : #define TAB_BORDER_BOTTOM 2
45 :
46 : class VCL_DLLPUBLIC TabControl : public Control
47 : {
48 : private:
49 : ImplTabCtrlData* mpTabCtrlData;
50 : long mnLastWidth;
51 : long mnLastHeight;
52 : long mnBtnSize;
53 : long mnMaxPageWidth;
54 : sal_uInt16 mnActPageId;
55 : sal_uInt16 mnCurPageId;
56 : bool mbFormat;
57 : bool mbRestoreHelpId;
58 : bool mbRestoreUnqId;
59 : bool mbSmallInvalidate;
60 : bool mbLayoutDirty;
61 : Link<> maActivateHdl;
62 : Link<TabControl *, bool> maDeactivateHdl;
63 :
64 : using Control::ImplInitSettings;
65 : SAL_DLLPRIVATE void ImplInitSettings( bool bFont, bool bForeground, bool bBackground );
66 : SAL_DLLPRIVATE ImplTabItem* ImplGetItem( sal_uInt16 nId ) const;
67 : SAL_DLLPRIVATE Size ImplGetItemSize( ImplTabItem* pItem, long nMaxWidth );
68 : SAL_DLLPRIVATE Rectangle ImplGetTabRect( sal_uInt16 nPos, long nWidth = -1, long nHeight = -1 );
69 : SAL_DLLPRIVATE void ImplChangeTabPage( sal_uInt16 nId, sal_uInt16 nOldId );
70 : SAL_DLLPRIVATE bool ImplPosCurTabPage();
71 : SAL_DLLPRIVATE void ImplActivateTabPage( bool bNext );
72 : SAL_DLLPRIVATE void ImplShowFocus();
73 : SAL_DLLPRIVATE void ImplDrawItem(vcl::RenderContext& rRenderContext, ImplTabItem* pItem,
74 : const Rectangle& rCurRect, bool bLayout = false, bool bFirstInGroup = false,
75 : bool bLastInGroup = false, bool bIsCurrentItem = false);
76 : SAL_DLLPRIVATE void ImplPaint(vcl::RenderContext& rRenderContext, const Rectangle& rRect, bool bLayout = false);
77 : SAL_DLLPRIVATE void ImplFreeLayoutData();
78 : SAL_DLLPRIVATE bool ImplHandleKeyEvent( const KeyEvent& rKeyEvent );
79 :
80 : DECL_DLLPRIVATE_LINK( ImplListBoxSelectHdl, void* );
81 : DECL_DLLPRIVATE_LINK( ImplWindowEventListener, VclSimpleEvent* );
82 :
83 :
84 : protected:
85 : using Window::ImplInit;
86 : SAL_DLLPRIVATE void ImplInit( vcl::Window* pParent, WinBits nStyle );
87 :
88 : virtual void FillLayoutData() const SAL_OVERRIDE;
89 : virtual const vcl::Font& GetCanonicalFont( const StyleSettings& _rStyle ) const SAL_OVERRIDE;
90 : virtual const Color& GetCanonicalTextColor( const StyleSettings& _rStyle ) const SAL_OVERRIDE;
91 : SAL_DLLPRIVATE Rectangle* ImplFindPartRect( const Point& rPt );
92 :
93 : public:
94 : TabControl( vcl::Window* pParent,
95 : WinBits nStyle = WB_STDTABCONTROL );
96 : virtual ~TabControl();
97 : virtual void dispose() SAL_OVERRIDE;
98 :
99 : virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
100 : virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
101 : virtual void Paint( vcl::RenderContext& rRenderContext, const Rectangle& rRect ) SAL_OVERRIDE;
102 : virtual void Resize() SAL_OVERRIDE;
103 : virtual void GetFocus() SAL_OVERRIDE;
104 : virtual void LoseFocus() SAL_OVERRIDE;
105 : virtual void RequestHelp( const HelpEvent& rHEvt ) SAL_OVERRIDE;
106 : virtual void Command( const CommandEvent& rCEvt ) SAL_OVERRIDE;
107 : virtual bool Notify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
108 : virtual void StateChanged( StateChangedType nType ) SAL_OVERRIDE;
109 : virtual void DataChanged( const DataChangedEvent& rDCEvt ) SAL_OVERRIDE;
110 : virtual bool PreNotify( NotifyEvent& rNEvt ) SAL_OVERRIDE;
111 :
112 : virtual void ActivatePage();
113 : virtual bool DeactivatePage();
114 :
115 : virtual Size GetOptimalSize() const SAL_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 : void EnablePage( sal_uInt16 nPageId, bool bEnable = true );
129 :
130 : sal_uInt16 GetPagePos( sal_uInt16 nPageId ) const;
131 : sal_uInt16 GetPageCount() const;
132 : sal_uInt16 GetPageId( sal_uInt16 nPos ) const;
133 : sal_uInt16 GetPageId( const Point& rPos ) const;
134 : sal_uInt16 GetPageId( const TabPage& rPage ) const;
135 : sal_uInt16 GetPageId( const OString& rName ) const;
136 :
137 : void SetCurPageId( sal_uInt16 nPageId );
138 : sal_uInt16 GetCurPageId() const;
139 :
140 : void SelectTabPage( sal_uInt16 nPageId );
141 :
142 : void SetMaxPageWidth( long nMaxWidth ) { mnMaxPageWidth = nMaxWidth; }
143 : long GetMaxPageWidth() const { return mnMaxPageWidth; }
144 : void ResetMaxPageWidth() { SetMaxPageWidth( 0 ); }
145 : bool IsMaxPageWidth() const { return mnMaxPageWidth != 0; }
146 :
147 : void SetTabPage( sal_uInt16 nPageId, TabPage* pPage );
148 : TabPage* GetTabPage( sal_uInt16 nPageId ) const;
149 :
150 : void SetPageText( sal_uInt16 nPageId, const OUString& rText );
151 : OUString GetPageText( sal_uInt16 nPageId ) const;
152 :
153 : void SetHelpText( sal_uInt16 nPageId, const OUString& rText );
154 : const OUString& GetHelpText( sal_uInt16 nPageId ) const;
155 :
156 : void SetHelpId( sal_uInt16 nPageId, const OString& rId ) const;
157 : OString GetHelpId( sal_uInt16 nPageId ) const;
158 :
159 : void SetPageName( sal_uInt16 nPageId, const OString& rName ) const;
160 : OString GetPageName( sal_uInt16 nPageId ) const;
161 :
162 : void SetPageImage( sal_uInt16 nPageId, const Image& rImage );
163 :
164 : void SetHelpText( const OUString& rText )
165 : { Control::SetHelpText( rText ); }
166 : const OUString& GetHelpText() const
167 : { return Control::GetHelpText(); }
168 :
169 2 : void SetHelpId( const OString& rId )
170 2 : { Control::SetHelpId( rId ); }
171 41 : const OString& GetHelpId() const
172 41 : { return Control::GetHelpId(); }
173 :
174 2 : void SetActivatePageHdl( const Link<>& rLink ) { maActivateHdl = rLink; }
175 : const Link<>& GetActivatePageHdl() const { return maActivateHdl; }
176 2 : void SetDeactivatePageHdl( const Link<TabControl *, bool>& rLink ) { maDeactivateHdl = rLink; }
177 :
178 : // returns (control relative) bounding rectangle for the
179 : // character at index nIndex relative to the text of page nPageId
180 : using Control::GetCharacterBounds;
181 : Rectangle GetCharacterBounds( sal_uInt16 nPageId, long nIndex ) const;
182 :
183 : // returns the index relative to the text of page nPageId (also returned)
184 : // at position rPoint (control relative)
185 : using Control::GetIndexForPoint;
186 : long GetIndexForPoint( const Point& rPoint, sal_uInt16& rPageId ) const;
187 :
188 : // returns the rectangle of the tab for page nPageId
189 : Rectangle GetTabBounds( sal_uInt16 nPageId ) const;
190 :
191 : virtual void SetPosPixel(const Point& rPos) SAL_OVERRIDE;
192 : virtual void SetSizePixel(const Size& rNewSize) SAL_OVERRIDE;
193 : virtual void SetPosSizePixel(const Point& rNewPos, const Size& rNewSize) SAL_OVERRIDE;
194 :
195 : Size calculateRequisition() const;
196 : void setAllocation(const Size &rAllocation);
197 :
198 537 : void markLayoutDirty()
199 : {
200 537 : mbLayoutDirty = true;
201 537 : }
202 :
203 : virtual void queue_resize(StateChangedType eReason = StateChangedType::Layout) SAL_OVERRIDE;
204 : };
205 :
206 : #endif // INCLUDED_VCL_TABCTRL_HXX
207 :
208 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|