Version 4.2.0.1, tag libreoffice-4.2.0.1
[LibreOffice.git] / vcl / source / window / tabpage.cxx
blob67225eaac30a15133fd00e57b77bacc5aed4dde2
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include <tools/rc.h>
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>
30 #include <svdata.hxx>
32 #include <com/sun/star/accessibility/XAccessible.hpp>
34 // =======================================================================
36 void TabPage::ImplInit( Window* pParent, WinBits nStyle )
38 if ( !(nStyle & WB_NODIALOGCONTROL) )
39 nStyle |= WB_DIALOGCONTROL;
41 Window::ImplInit( pParent, nStyle, NULL );
43 ImplInitSettings();
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 if( IsNativeControlSupported(CTRL_TAB_BODY, PART_ENTIRE_CONTROL) && GetParent() && (GetParent()->GetType() == WINDOW_TABCONTROL) )
48 EnableChildTransparentMode( sal_True );
51 // -----------------------------------------------------------------------
53 void TabPage::ImplInitSettings()
55 Window* pParent = GetParent();
56 if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() )
58 EnableChildTransparentMode( sal_True );
59 SetParentClipMode( PARENTCLIPMODE_NOCLIP );
60 SetPaintTransparent( sal_True );
61 SetBackground();
63 else
65 EnableChildTransparentMode( sal_False );
66 SetParentClipMode( 0 );
67 SetPaintTransparent( sal_False );
69 if ( IsControlBackground() )
70 SetBackground( GetControlBackground() );
71 else
72 SetBackground( pParent->GetBackground() );
76 // -----------------------------------------------------------------------
78 TabPage::TabPage( Window* pParent, WinBits nStyle ) :
79 Window( WINDOW_TABPAGE )
81 ImplInit( pParent, nStyle );
84 // -----------------------------------------------------------------------
86 TabPage::TabPage( Window* pParent, const ResId& rResId ) :
87 Window( WINDOW_TABPAGE )
89 rResId.SetRT( RSC_TABPAGE );
90 WinBits nStyle = ImplInitRes( rResId );
91 ImplInit( pParent, nStyle );
92 ImplLoadRes(rResId);
94 if ( !(nStyle & WB_HIDE) )
95 Show();
98 TabPage::TabPage(Window *pParent, const OString& rID, const OUString& rUIXMLDescription)
99 : Window(WINDOW_TABPAGE)
101 ImplInit(pParent, 0);
102 m_pUIBuilder = new VclBuilder(this, getUIRootDir(), rUIXMLDescription, rID);
105 // -----------------------------------------------------------------------
107 void TabPage::StateChanged( StateChangedType nType )
109 Window::StateChanged( nType );
111 if ( nType == STATE_CHANGE_INITSHOW )
113 if ( GetSettings().GetStyleSettings().GetAutoMnemonic() )
114 ImplWindowAutoMnemonic( this );
115 // FIXME: no layouting, workaround some clipping issues
116 ImplAdjustNWFSizes();
118 else if ( nType == STATE_CHANGE_CONTROLBACKGROUND )
120 ImplInitSettings();
121 Invalidate();
125 // -----------------------------------------------------------------------
127 void TabPage::DataChanged( const DataChangedEvent& rDCEvt )
129 Window::DataChanged( rDCEvt );
131 if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
132 (rDCEvt.GetFlags() & SETTINGS_STYLE) )
134 ImplInitSettings();
135 Invalidate();
139 // -----------------------------------------------------------------------
141 void TabPage::Paint( const Rectangle& )
143 // draw native tabpage only inside tabcontrols, standalone tabpages look ugly (due to bad dialog design)
144 if( IsNativeControlSupported(CTRL_TAB_BODY, PART_ENTIRE_CONTROL) && GetParent() && (GetParent()->GetType() == WINDOW_TABCONTROL) )
146 const ImplControlValue aControlValue;
148 ControlState nState = CTRL_STATE_ENABLED;
149 int part = PART_ENTIRE_CONTROL;
150 if ( !IsEnabled() )
151 nState &= ~CTRL_STATE_ENABLED;
152 if ( HasFocus() )
153 nState |= CTRL_STATE_FOCUSED;
154 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 Rectangle aCtrlRegion( aPoint, GetOutputSizePixel() );
158 DrawNativeControl( CTRL_TAB_BODY, part, aCtrlRegion, nState,
159 aControlValue, OUString() );
163 // -----------------------------------------------------------------------
164 void TabPage::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong )
166 Point aPos = pDev->LogicToPixel( rPos );
167 Size aSize = pDev->LogicToPixel( rSize );
169 Wallpaper aWallpaper = GetBackground();
170 if ( !aWallpaper.IsBitmap() )
171 ImplInitSettings();
173 pDev->Push();
174 pDev->SetMapMode();
175 pDev->SetLineColor();
177 if ( aWallpaper.IsBitmap() )
178 pDev->DrawBitmapEx( aPos, aSize, aWallpaper.GetBitmap() );
179 else
181 if( aWallpaper.GetColor() == COL_AUTO )
182 pDev->SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
183 else
184 pDev->SetFillColor( aWallpaper.GetColor() );
185 pDev->DrawRect( Rectangle( aPos, aSize ) );
188 pDev->Pop();
191 // -----------------------------------------------------------------------
193 void TabPage::ActivatePage()
197 // -----------------------------------------------------------------------
199 void TabPage::DeactivatePage()
203 Size TabPage::GetOptimalSize() const
205 if (isLayoutEnabled(this))
206 return VclContainer::getLayoutRequisition(*GetWindow(WINDOW_FIRSTCHILD));
207 return getLegacyBestSizeForChildren(*this);
210 void TabPage::SetPosSizePixel(const Point& rAllocPos, const Size& rAllocation)
212 Window::SetPosSizePixel(rAllocPos, rAllocation);
213 if (isLayoutEnabled(this))
214 VclContainer::setLayoutAllocation(*GetWindow(WINDOW_FIRSTCHILD), Point(0, 0), rAllocation);
217 void TabPage::SetSizePixel(const Size& rAllocation)
219 Window::SetSizePixel(rAllocation);
220 if (isLayoutEnabled(this))
221 VclContainer::setLayoutAllocation(*GetWindow(WINDOW_FIRSTCHILD), Point(0, 0), rAllocation);
224 void TabPage::SetPosPixel(const Point& rAllocPos)
226 Window::SetPosPixel(rAllocPos);
227 if (isLayoutEnabled(this))
228 VclContainer::setLayoutAllocation(*GetWindow(WINDOW_FIRSTCHILD), Point(0, 0), GetOutputSizePixel());
231 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */