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