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 :
21 : #include <tools/rc.h>
22 :
23 : #include <vcl/event.hxx>
24 : #include <vcl/layout.hxx>
25 : #include <vcl/svapp.hxx>
26 : #include <vcl/tabpage.hxx>
27 : #include <vcl/tabctrl.hxx>
28 : #include <vcl/bitmapex.hxx>
29 :
30 : #include <svdata.hxx>
31 :
32 : #include <com/sun/star/accessibility/XAccessible.hpp>
33 :
34 : // =======================================================================
35 :
36 13 : void TabPage::ImplInit( Window* pParent, WinBits nStyle )
37 : {
38 13 : if ( !(nStyle & WB_NODIALOGCONTROL) )
39 13 : nStyle |= WB_DIALOGCONTROL;
40 :
41 13 : Window::ImplInit( pParent, nStyle, NULL );
42 :
43 13 : ImplInitSettings();
44 :
45 : // if the tabpage is drawn (ie filled) by a native widget, make sure all contols will have transparent background
46 : // otherwise they will paint with a wrong background
47 13 : if( IsNativeControlSupported(CTRL_TAB_BODY, PART_ENTIRE_CONTROL) && GetParent() && (GetParent()->GetType() == WINDOW_TABCONTROL) )
48 0 : EnableChildTransparentMode( sal_True );
49 13 : }
50 :
51 : // -----------------------------------------------------------------------
52 :
53 13 : void TabPage::ImplInitSettings()
54 : {
55 13 : Window* pParent = GetParent();
56 13 : if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() )
57 : {
58 0 : EnableChildTransparentMode( sal_True );
59 0 : SetParentClipMode( PARENTCLIPMODE_NOCLIP );
60 0 : SetPaintTransparent( sal_True );
61 0 : SetBackground();
62 : }
63 : else
64 : {
65 13 : EnableChildTransparentMode( sal_False );
66 13 : SetParentClipMode( 0 );
67 13 : SetPaintTransparent( sal_False );
68 :
69 13 : if ( IsControlBackground() )
70 0 : SetBackground( GetControlBackground() );
71 : else
72 13 : SetBackground( pParent->GetBackground() );
73 : }
74 13 : }
75 :
76 : // -----------------------------------------------------------------------
77 :
78 13 : TabPage::TabPage( Window* pParent, WinBits nStyle ) :
79 13 : Window( WINDOW_TABPAGE )
80 : {
81 13 : ImplInit( pParent, nStyle );
82 13 : }
83 :
84 : // -----------------------------------------------------------------------
85 :
86 0 : TabPage::TabPage( Window* pParent, const ResId& rResId ) :
87 0 : Window( WINDOW_TABPAGE )
88 : {
89 0 : rResId.SetRT( RSC_TABPAGE );
90 0 : WinBits nStyle = ImplInitRes( rResId );
91 0 : ImplInit( pParent, nStyle );
92 0 : ImplLoadRes(rResId);
93 :
94 0 : if ( !(nStyle & WB_HIDE) )
95 0 : Show();
96 0 : }
97 :
98 0 : TabPage::TabPage(Window *pParent, const OString& rID, const OUString& rUIXMLDescription)
99 0 : : Window(WINDOW_TABPAGE)
100 : {
101 0 : ImplInit(pParent, 0);
102 0 : m_pUIBuilder = new VclBuilder(this, getUIRootDir(), rUIXMLDescription, rID);
103 0 : }
104 :
105 : // -----------------------------------------------------------------------
106 :
107 30 : void TabPage::StateChanged( StateChangedType nType )
108 : {
109 30 : Window::StateChanged( nType );
110 :
111 30 : if ( nType == STATE_CHANGE_INITSHOW )
112 : {
113 0 : if ( GetSettings().GetStyleSettings().GetAutoMnemonic() )
114 0 : ImplWindowAutoMnemonic( this );
115 : // FIXME: no layouting, workaround some clipping issues
116 0 : ImplAdjustNWFSizes();
117 : }
118 30 : else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
119 : {
120 0 : ImplInitSettings();
121 0 : Invalidate();
122 : }
123 30 : }
124 :
125 : // -----------------------------------------------------------------------
126 :
127 0 : void TabPage::DataChanged( const DataChangedEvent& rDCEvt )
128 : {
129 0 : Window::DataChanged( rDCEvt );
130 :
131 0 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
132 0 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
133 : {
134 0 : ImplInitSettings();
135 0 : Invalidate();
136 : }
137 0 : }
138 :
139 : // -----------------------------------------------------------------------
140 :
141 0 : void TabPage::Paint( const Rectangle& )
142 : {
143 : // draw native tabpage only inside tabcontrols, standalone tabpages look ugly (due to bad dialog design)
144 0 : if( IsNativeControlSupported(CTRL_TAB_BODY, PART_ENTIRE_CONTROL) && GetParent() && (GetParent()->GetType() == WINDOW_TABCONTROL) )
145 : {
146 0 : const ImplControlValue aControlValue;
147 :
148 0 : ControlState nState = CTRL_STATE_ENABLED;
149 0 : int part = PART_ENTIRE_CONTROL;
150 0 : if ( !IsEnabled() )
151 0 : nState &= ~CTRL_STATE_ENABLED;
152 0 : if ( HasFocus() )
153 0 : nState |= CTRL_STATE_FOCUSED;
154 0 : Point aPoint;
155 : // pass the whole window region to NWF as the tab body might be a gradient or bitmap
156 : // that has to be scaled properly, clipping makes sure that we do not paint too much
157 0 : Rectangle aCtrlRegion( aPoint, GetOutputSizePixel() );
158 : DrawNativeControl( CTRL_TAB_BODY, part, aCtrlRegion, nState,
159 0 : aControlValue, OUString() );
160 : }
161 0 : }
162 :
163 : // -----------------------------------------------------------------------
164 0 : void TabPage::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong )
165 : {
166 0 : Point aPos = pDev->LogicToPixel( rPos );
167 0 : Size aSize = pDev->LogicToPixel( rSize );
168 :
169 0 : Wallpaper aWallpaper = GetBackground();
170 0 : if ( !aWallpaper.IsBitmap() )
171 0 : ImplInitSettings();
172 :
173 0 : pDev->Push();
174 0 : pDev->SetMapMode();
175 0 : pDev->SetLineColor();
176 :
177 0 : if ( aWallpaper.IsBitmap() )
178 0 : pDev->DrawBitmapEx( aPos, aSize, aWallpaper.GetBitmap() );
179 : else
180 : {
181 0 : if( aWallpaper.GetColor() == COL_AUTO )
182 0 : pDev->SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
183 : else
184 0 : pDev->SetFillColor( aWallpaper.GetColor() );
185 0 : pDev->DrawRect( Rectangle( aPos, aSize ) );
186 : }
187 :
188 0 : pDev->Pop();
189 0 : }
190 :
191 : // -----------------------------------------------------------------------
192 :
193 13 : void TabPage::ActivatePage()
194 : {
195 13 : }
196 :
197 : // -----------------------------------------------------------------------
198 :
199 0 : void TabPage::DeactivatePage()
200 : {
201 0 : }
202 :
203 0 : Size TabPage::GetOptimalSize() const
204 : {
205 0 : if (isLayoutEnabled(this))
206 0 : return VclContainer::getLayoutRequisition(*GetWindow(WINDOW_FIRSTCHILD));
207 0 : return getLegacyBestSizeForChildren(*this);
208 : }
209 :
210 100 : void TabPage::SetPosSizePixel(const Point& rAllocPos, const Size& rAllocation)
211 : {
212 100 : Window::SetPosSizePixel(rAllocPos, rAllocation);
213 100 : if (isLayoutEnabled(this))
214 0 : VclContainer::setLayoutAllocation(*GetWindow(WINDOW_FIRSTCHILD), Point(0, 0), rAllocation);
215 100 : }
216 :
217 0 : void TabPage::SetSizePixel(const Size& rAllocation)
218 : {
219 0 : Window::SetSizePixel(rAllocation);
220 0 : if (isLayoutEnabled(this))
221 0 : VclContainer::setLayoutAllocation(*GetWindow(WINDOW_FIRSTCHILD), Point(0, 0), rAllocation);
222 0 : }
223 :
224 0 : void TabPage::SetPosPixel(const Point& rAllocPos)
225 : {
226 0 : Window::SetPosPixel(rAllocPos);
227 0 : if (isLayoutEnabled(this))
228 0 : VclContainer::setLayoutAllocation(*GetWindow(WINDOW_FIRSTCHILD), Point(0, 0), GetOutputSizePixel());
229 465 : }
230 :
231 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|