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