Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 : #include <tools/rc.h>
21 :
22 : #include <vcl/event.hxx>
23 : #include <vcl/layout.hxx>
24 : #include <vcl/svapp.hxx>
25 : #include <vcl/tabpage.hxx>
26 : #include <vcl/tabctrl.hxx>
27 : #include <vcl/bitmapex.hxx>
28 : #include <vcl/settings.hxx>
29 :
30 : #include <svdata.hxx>
31 :
32 : #include <com/sun/star/accessibility/XAccessible.hpp>
33 :
34 52 : void TabPage::ImplInit( vcl::Window* pParent, WinBits nStyle )
35 : {
36 52 : if ( !(nStyle & WB_NODIALOGCONTROL) )
37 52 : nStyle |= WB_DIALOGCONTROL;
38 :
39 52 : Window::ImplInit( pParent, nStyle, NULL );
40 :
41 52 : ImplInitSettings();
42 :
43 : // if the tabpage is drawn (ie filled) by a native widget, make sure all contols will have transparent background
44 : // otherwise they will paint with a wrong background
45 52 : if( IsNativeControlSupported(CTRL_TAB_BODY, PART_ENTIRE_CONTROL) && GetParent() && (GetParent()->GetType() == WINDOW_TABCONTROL) )
46 0 : EnableChildTransparentMode( true );
47 52 : }
48 :
49 54 : void TabPage::ImplInitSettings()
50 : {
51 54 : vcl::Window* pParent = GetParent();
52 54 : if ( pParent->IsChildTransparentModeEnabled() && !IsControlBackground() )
53 : {
54 0 : EnableChildTransparentMode( true );
55 0 : SetParentClipMode( PARENTCLIPMODE_NOCLIP );
56 0 : SetPaintTransparent( true );
57 0 : SetBackground();
58 : }
59 : else
60 : {
61 54 : EnableChildTransparentMode( false );
62 54 : SetParentClipMode( 0 );
63 54 : SetPaintTransparent( false );
64 :
65 54 : if ( IsControlBackground() )
66 0 : SetBackground( GetControlBackground() );
67 : else
68 54 : SetBackground( pParent->GetBackground() );
69 : }
70 54 : }
71 :
72 52 : TabPage::TabPage( vcl::Window* pParent, WinBits nStyle ) :
73 52 : Window( WINDOW_TABPAGE )
74 : {
75 52 : ImplInit( pParent, nStyle );
76 52 : }
77 :
78 0 : TabPage::TabPage(vcl::Window *pParent, const OString& rID, const OUString& rUIXMLDescription)
79 0 : : Window(WINDOW_TABPAGE)
80 : {
81 0 : ImplInit(pParent, 0);
82 0 : m_pUIBuilder = new VclBuilder(this, getUIRootDir(), rUIXMLDescription, rID);
83 0 : set_hexpand(true);
84 0 : set_vexpand(true);
85 0 : set_expand(true);
86 0 : }
87 :
88 108 : void TabPage::StateChanged( StateChangedType nType )
89 : {
90 108 : Window::StateChanged( nType );
91 :
92 108 : if ( nType == StateChangedType::INITSHOW )
93 : {
94 0 : if ( GetSettings().GetStyleSettings().GetAutoMnemonic() )
95 0 : ImplWindowAutoMnemonic( this );
96 : // FIXME: no layouting, workaround some clipping issues
97 0 : ImplAdjustNWFSizes();
98 : }
99 108 : else if ( nType == StateChangedType::CONTROLBACKGROUND )
100 : {
101 0 : ImplInitSettings();
102 0 : Invalidate();
103 : }
104 108 : }
105 :
106 2 : void TabPage::DataChanged( const DataChangedEvent& rDCEvt )
107 : {
108 2 : Window::DataChanged( rDCEvt );
109 :
110 4 : if ( (rDCEvt.GetType() == DATACHANGED_SETTINGS) &&
111 2 : (rDCEvt.GetFlags() & SETTINGS_STYLE) )
112 : {
113 2 : ImplInitSettings();
114 2 : Invalidate();
115 : }
116 2 : }
117 :
118 0 : void TabPage::Paint( const Rectangle& )
119 : {
120 : // draw native tabpage only inside tabcontrols, standalone tabpages look ugly (due to bad dialog design)
121 0 : if( IsNativeControlSupported(CTRL_TAB_BODY, PART_ENTIRE_CONTROL) && GetParent() && (GetParent()->GetType() == WINDOW_TABCONTROL) )
122 : {
123 0 : const ImplControlValue aControlValue;
124 :
125 0 : ControlState nState = CTRL_STATE_ENABLED;
126 0 : int part = PART_ENTIRE_CONTROL;
127 0 : if ( !IsEnabled() )
128 0 : nState &= ~CTRL_STATE_ENABLED;
129 0 : if ( HasFocus() )
130 0 : nState |= CTRL_STATE_FOCUSED;
131 0 : Point aPoint;
132 : // pass the whole window region to NWF as the tab body might be a gradient or bitmap
133 : // that has to be scaled properly, clipping makes sure that we do not paint too much
134 0 : Rectangle aCtrlRegion( aPoint, GetOutputSizePixel() );
135 : DrawNativeControl( CTRL_TAB_BODY, part, aCtrlRegion, nState,
136 0 : aControlValue, OUString() );
137 : }
138 0 : }
139 :
140 0 : void TabPage::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, sal_uLong )
141 : {
142 0 : Point aPos = pDev->LogicToPixel( rPos );
143 0 : Size aSize = pDev->LogicToPixel( rSize );
144 :
145 0 : Wallpaper aWallpaper = GetBackground();
146 0 : if ( !aWallpaper.IsBitmap() )
147 0 : ImplInitSettings();
148 :
149 0 : pDev->Push();
150 0 : pDev->SetMapMode();
151 0 : pDev->SetLineColor();
152 :
153 0 : if ( aWallpaper.IsBitmap() )
154 0 : pDev->DrawBitmapEx( aPos, aSize, aWallpaper.GetBitmap() );
155 : else
156 : {
157 0 : if( aWallpaper.GetColor() == COL_AUTO )
158 0 : pDev->SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
159 : else
160 0 : pDev->SetFillColor( aWallpaper.GetColor() );
161 0 : pDev->DrawRect( Rectangle( aPos, aSize ) );
162 : }
163 :
164 0 : pDev->Pop();
165 0 : }
166 :
167 52 : void TabPage::ActivatePage()
168 : {
169 52 : }
170 :
171 0 : void TabPage::DeactivatePage()
172 : {
173 0 : }
174 :
175 0 : OString TabPage::GetConfigId() const
176 : {
177 0 : OString sId(GetHelpId());
178 0 : if (sId.isEmpty() && isLayoutEnabled(this))
179 0 : sId = GetWindow(WINDOW_FIRSTCHILD)->GetHelpId();
180 0 : return sId;
181 : }
182 :
183 0 : Size TabPage::GetOptimalSize() const
184 : {
185 0 : if (isLayoutEnabled(this))
186 0 : return VclContainer::getLayoutRequisition(*GetWindow(WINDOW_FIRSTCHILD));
187 0 : return getLegacyBestSizeForChildren(*this);
188 : }
189 :
190 416 : void TabPage::SetPosSizePixel(const Point& rAllocPos, const Size& rAllocation)
191 : {
192 416 : Window::SetPosSizePixel(rAllocPos, rAllocation);
193 416 : if (isLayoutEnabled(this) && rAllocation.Width() && rAllocation.Height())
194 0 : VclContainer::setLayoutAllocation(*GetWindow(WINDOW_FIRSTCHILD), Point(0, 0), rAllocation);
195 416 : }
196 :
197 0 : void TabPage::SetSizePixel(const Size& rAllocation)
198 : {
199 0 : Window::SetSizePixel(rAllocation);
200 0 : if (isLayoutEnabled(this) && rAllocation.Width() && rAllocation.Height())
201 0 : VclContainer::setLayoutAllocation(*GetWindow(WINDOW_FIRSTCHILD), Point(0, 0), rAllocation);
202 0 : }
203 :
204 0 : void TabPage::SetPosPixel(const Point& rAllocPos)
205 : {
206 0 : Window::SetPosPixel(rAllocPos);
207 0 : Size aAllocation(GetOutputSizePixel());
208 0 : if (isLayoutEnabled(this) && aAllocation.Width() && aAllocation.Height())
209 : {
210 0 : VclContainer::setLayoutAllocation(*GetWindow(WINDOW_FIRSTCHILD), Point(0, 0), aAllocation);
211 : }
212 1233 : }
213 :
214 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|