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