1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
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>
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
);
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
);
65 EnableChildTransparentMode( sal_False
);
66 SetParentClipMode( 0 );
67 SetPaintTransparent( sal_False
);
69 if ( IsControlBackground() )
70 SetBackground( GetControlBackground() );
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
);
94 if ( !(nStyle
& WB_HIDE
) )
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
)
125 // -----------------------------------------------------------------------
127 void TabPage::DataChanged( const DataChangedEvent
& rDCEvt
)
129 Window::DataChanged( rDCEvt
);
131 if ( (rDCEvt
.GetType() == DATACHANGED_SETTINGS
) &&
132 (rDCEvt
.GetFlags() & SETTINGS_STYLE
) )
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
;
151 nState
&= ~CTRL_STATE_ENABLED
;
153 nState
|= CTRL_STATE_FOCUSED
;
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() )
175 pDev
->SetLineColor();
177 if ( aWallpaper
.IsBitmap() )
178 pDev
->DrawBitmapEx( aPos
, aSize
, aWallpaper
.GetBitmap() );
181 if( aWallpaper
.GetColor() == COL_AUTO
)
182 pDev
->SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
184 pDev
->SetFillColor( aWallpaper
.GetColor() );
185 pDev
->DrawRect( Rectangle( aPos
, aSize
) );
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: */