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 41 : void TabPage::ImplInit( vcl::Window* pParent, WinBits nStyle )
35 : {
36 41 : if ( !(nStyle & WB_NODIALOGCONTROL) )
37 41 : nStyle |= WB_DIALOGCONTROL;
38 :
39 41 : Window::ImplInit( pParent, nStyle, NULL );
40 :
41 41 : 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 41 : if( IsNativeControlSupported(CTRL_TAB_BODY, PART_ENTIRE_CONTROL) && GetParent() && (GetParent()->GetType() == WINDOW_TABCONTROL) )
46 0 : EnableChildTransparentMode( true );
47 41 : }
48 :
49 43 : void TabPage::ImplInitSettings()
50 : {
51 43 : vcl::Window* pParent = GetParent();
52 43 : 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 43 : EnableChildTransparentMode( false );
62 43 : SetParentClipMode( ParentClipMode::NONE );
63 43 : SetPaintTransparent( false );
64 :
65 43 : if ( IsControlBackground() )
66 0 : SetBackground( GetControlBackground() );
67 : else
68 43 : SetBackground( pParent->GetBackground() );
69 : }
70 43 : }
71 :
72 41 : TabPage::TabPage( vcl::Window* pParent, WinBits nStyle ) :
73 41 : Window( WINDOW_TABPAGE )
74 : {
75 41 : ImplInit( pParent, nStyle );
76 41 : }
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 123 : TabPage::~TabPage()
89 : {
90 41 : disposeOnce();
91 82 : }
92 :
93 41 : void TabPage::dispose()
94 : {
95 41 : disposeBuilder();
96 41 : vcl::Window::dispose();
97 41 : }
98 :
99 84 : void TabPage::StateChanged( StateChangedType nType )
100 : {
101 84 : Window::StateChanged( nType );
102 :
103 84 : if ( nType == StateChangedType::InitShow )
104 : {
105 0 : if ( GetSettings().GetStyleSettings().GetAutoMnemonic() )
106 0 : ImplWindowAutoMnemonic( this );
107 : // FIXME: no layouting, workaround some clipping issues
108 0 : ImplAdjustNWFSizes();
109 : }
110 84 : else if ( nType == StateChangedType::ControlBackground )
111 : {
112 0 : ImplInitSettings();
113 0 : Invalidate();
114 : }
115 84 : }
116 :
117 2 : void TabPage::DataChanged( const DataChangedEvent& rDCEvt )
118 : {
119 2 : Window::DataChanged( rDCEvt );
120 :
121 8 : if ( (rDCEvt.GetType() == DataChangedEventType::SETTINGS) &&
122 8 : (rDCEvt.GetFlags() & AllSettingsFlags::STYLE) )
123 : {
124 2 : ImplInitSettings();
125 2 : Invalidate();
126 : }
127 2 : }
128 :
129 0 : void TabPage::Paint( vcl::RenderContext& /*rRenderContext*/, const Rectangle& )
130 : {
131 : // draw native tabpage only inside tabcontrols, standalone tabpages look ugly (due to bad dialog design)
132 0 : if( IsNativeControlSupported(CTRL_TAB_BODY, PART_ENTIRE_CONTROL) && GetParent() && (GetParent()->GetType() == WINDOW_TABCONTROL) )
133 : {
134 0 : const ImplControlValue aControlValue;
135 :
136 0 : ControlState nState = ControlState::ENABLED;
137 0 : int part = PART_ENTIRE_CONTROL;
138 0 : if ( !IsEnabled() )
139 0 : nState &= ~ControlState::ENABLED;
140 0 : if ( HasFocus() )
141 0 : nState |= ControlState::FOCUSED;
142 0 : Point aPoint;
143 : // pass the whole window region to NWF as the tab body might be a gradient or bitmap
144 : // that has to be scaled properly, clipping makes sure that we do not paint too much
145 0 : Rectangle aCtrlRegion( aPoint, GetOutputSizePixel() );
146 : DrawNativeControl( CTRL_TAB_BODY, part, aCtrlRegion, nState,
147 0 : aControlValue, OUString() );
148 : }
149 0 : }
150 :
151 0 : void TabPage::Draw( OutputDevice* pDev, const Point& rPos, const Size& rSize, DrawFlags )
152 : {
153 0 : Point aPos = pDev->LogicToPixel( rPos );
154 0 : Size aSize = pDev->LogicToPixel( rSize );
155 :
156 0 : Wallpaper aWallpaper = GetBackground();
157 0 : if ( !aWallpaper.IsBitmap() )
158 0 : ImplInitSettings();
159 :
160 0 : pDev->Push();
161 0 : pDev->SetMapMode();
162 0 : pDev->SetLineColor();
163 :
164 0 : if ( aWallpaper.IsBitmap() )
165 0 : pDev->DrawBitmapEx( aPos, aSize, aWallpaper.GetBitmap() );
166 : else
167 : {
168 0 : if( aWallpaper.GetColor() == COL_AUTO )
169 0 : pDev->SetFillColor( GetSettings().GetStyleSettings().GetDialogColor() );
170 : else
171 0 : pDev->SetFillColor( aWallpaper.GetColor() );
172 0 : pDev->DrawRect( Rectangle( aPos, aSize ) );
173 : }
174 :
175 0 : pDev->Pop();
176 0 : }
177 :
178 41 : void TabPage::ActivatePage()
179 : {
180 41 : }
181 :
182 0 : void TabPage::DeactivatePage()
183 : {
184 0 : }
185 :
186 0 : OString TabPage::GetConfigId() const
187 : {
188 0 : OString sId(GetHelpId());
189 0 : if (sId.isEmpty() && isLayoutEnabled(this))
190 0 : sId = GetWindow(GetWindowType::FirstChild)->GetHelpId();
191 0 : return sId;
192 : }
193 :
194 0 : Size TabPage::GetOptimalSize() const
195 : {
196 0 : if (isLayoutEnabled(this))
197 0 : return VclContainer::getLayoutRequisition(*GetWindow(GetWindowType::FirstChild));
198 0 : return getLegacyBestSizeForChildren(*this);
199 : }
200 :
201 314 : void TabPage::SetPosSizePixel(const Point& rAllocPos, const Size& rAllocation)
202 : {
203 314 : Window::SetPosSizePixel(rAllocPos, rAllocation);
204 314 : if (isLayoutEnabled(this) && rAllocation.Width() && rAllocation.Height())
205 0 : VclContainer::setLayoutAllocation(*GetWindow(GetWindowType::FirstChild), Point(0, 0), rAllocation);
206 314 : }
207 :
208 0 : void TabPage::SetSizePixel(const Size& rAllocation)
209 : {
210 0 : Window::SetSizePixel(rAllocation);
211 0 : if (isLayoutEnabled(this) && rAllocation.Width() && rAllocation.Height())
212 0 : VclContainer::setLayoutAllocation(*GetWindow(GetWindowType::FirstChild), Point(0, 0), rAllocation);
213 0 : }
214 :
215 0 : void TabPage::SetPosPixel(const Point& rAllocPos)
216 : {
217 0 : Window::SetPosPixel(rAllocPos);
218 0 : Size aAllocation(GetOutputSizePixel());
219 0 : if (isLayoutEnabled(this) && aAllocation.Width() && aAllocation.Height())
220 : {
221 0 : VclContainer::setLayoutAllocation(*GetWindow(GetWindowType::FirstChild), Point(0, 0), aAllocation);
222 : }
223 801 : }
224 :
225 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|