xref: /aoo42x/main/vcl/source/window/tabpage.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_vcl.hxx"
30 
31 #include <tools/ref.hxx>
32 #include <tools/rc.h>
33 
34 #include <vcl/svapp.hxx>
35 #include <vcl/event.hxx>
36 #include <vcl/tabpage.hxx>
37 #include <vcl/tabctrl.hxx>
38 #include <vcl/bitmapex.hxx>
39 
40 #include <svdata.hxx>
41 
42 #include <com/sun/star/accessibility/XAccessible.hpp>
43 
44 // =======================================================================
45 
46 void TabPage::ImplInit( Window* pParent, WinBits nStyle )
47 {
48     if ( !(nStyle & WB_NODIALOGCONTROL) )
49         nStyle |= WB_DIALOGCONTROL;
50 
51     Window::ImplInit( pParent, nStyle, NULL );
52 
53     ImplInitSettings();
54 
55     // if the tabpage is drawn (ie filled) by a native widget, make sure all contols will have transparent background
56     // otherwise they will paint with a wrong background
57     if( IsNativeControlSupported(CTRL_TAB_BODY, PART_ENTIRE_CONTROL) && GetParent() && (GetParent()->GetType() == WINDOW_TABCONTROL) )
58         EnableChildTransparentMode( sal_True );
59 }
60 
61 // -----------------------------------------------------------------------
62 
63 void TabPage::ImplInitSettings()
64 {
65     Window* pParent = GetParent();
66     if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() )
67     {
68         EnableChildTransparentMode( sal_True );
69         SetParentClipMode( PARENTCLIPMODE_NOCLIP );
70         SetPaintTransparent( sal_True );
71         SetBackground();
72     }
73     else
74     {
75         EnableChildTransparentMode( sal_False );
76         SetParentClipMode( 0 );
77         SetPaintTransparent( sal_False );
78 
79         if ( IsControlBackground() )
80             SetBackground( GetControlBackground() );
81         else
82             SetBackground( pParent->GetBackground() );
83     }
84 }
85 
86 // -----------------------------------------------------------------------
87 
88 TabPage::TabPage( Window* pParent, WinBits nStyle ) :
89     Window( WINDOW_TABPAGE )
90 {
91     ImplInit( pParent, nStyle );
92 }
93 
94 // -----------------------------------------------------------------------
95 
96 TabPage::TabPage( Window* pParent, const ResId& rResId ) :
97     Window( WINDOW_TABPAGE )
98 {
99     rResId.SetRT( RSC_TABPAGE );
100     WinBits nStyle = ImplInitRes( rResId );
101     ImplInit( pParent, nStyle );
102     ImplLoadRes( rResId );
103 
104     if ( !(nStyle & WB_HIDE) )
105         Show();
106 }
107 
108 // -----------------------------------------------------------------------
109 
110 void TabPage::StateChanged( StateChangedType nType )
111 {
112     Window::StateChanged( nType );
113 
114     if ( nType == STATE_CHANGE_INITSHOW )
115     {
116         if ( GetSettings().GetStyleSettings().GetAutoMnemonic() )
117             ImplWindowAutoMnemonic( this );
118         // FIXME: no layouting, workaround some clipping issues
119         ImplAdjustNWFSizes();
120     }
121     else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
122     {
123         ImplInitSettings();
124         Invalidate();
125     }
126 }
127 
128 // -----------------------------------------------------------------------
129 
130 void TabPage::DataChanged( const DataChangedEvent& rDCEvt )
131 {
132     Window::DataChanged( rDCEvt );
133 
134     if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
135          (rDCEvt.GetFlags() & SETTINGS_STYLE) )
136     {
137         ImplInitSettings();
138         Invalidate();
139     }
140 }
141 
142 // -----------------------------------------------------------------------
143 
144 void TabPage::Paint( const Rectangle& )
145 {
146     // draw native tabpage only inside tabcontrols, standalone tabpages look ugly (due to bad dialog design)
147     if( IsNativeControlSupported(CTRL_TAB_BODY, PART_ENTIRE_CONTROL) && GetParent() && (GetParent()->GetType() == WINDOW_TABCONTROL) )
148     {
149         const ImplControlValue aControlValue;
150 
151         ControlState nState = CTRL_STATE_ENABLED;
152         int part = PART_ENTIRE_CONTROL;
153         if ( !IsEnabled() )
154             nState &= ~CTRL_STATE_ENABLED;
155         if ( HasFocus() )
156             nState |= CTRL_STATE_FOCUSED;
157         Point aPoint;
158         // pass the whole window region to NWF as the tab body might be a gradient or bitmap
159         // that has to be scaled properly, clipping makes sure that we do not paint too much
160         Rectangle aCtrlRegion( aPoint, GetOutputSizePixel() );
161         DrawNativeControl( CTRL_TAB_BODY, part, aCtrlRegion, nState,
162                 aControlValue, rtl::OUString() );
163     }
164 }
165 
166 // -----------------------------------------------------------------------
167 void TabPage::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong )
168 {
169     Point aPos = pDev->LogicToPixel( rPos );
170     Size aSize = pDev->LogicToPixel( rSize );
171 
172     Wallpaper aWallpaper = GetBackground();
173     if ( !aWallpaper.IsBitmap() )
174         ImplInitSettings();
175 
176     pDev->Push();
177     pDev->SetMapMode();
178     pDev->SetLineColor();
179 
180     if ( aWallpaper.IsBitmap() )
181         pDev->DrawBitmapEx( aPos, aSize, aWallpaper.GetBitmap() );
182     else
183     {
184         if( aWallpaper.GetColor() == COL_AUTO )
185             pDev->SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
186         else
187             pDev->SetFillColor( aWallpaper.GetColor() );
188         pDev->DrawRect( Rectangle( aPos, aSize ) );
189     }
190 
191     pDev->Pop();
192 }
193 
194 // -----------------------------------------------------------------------
195 
196 void TabPage::ActivatePage()
197 {
198 }
199 
200 // -----------------------------------------------------------------------
201 
202 void TabPage::DeactivatePage()
203 {
204 }
205 
206 // -----------------------------------------------------------------------
207 
208 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > TabPage::CreateAccessible()
209 {
210     // TODO: remove this method (incompatible)
211 
212     return Window::CreateAccessible();
213 }
214