update dev300-m58
[ooovba.git] / vcl / source / window / window3.cxx
blob8c26c000f5e6b0ccc745fcab9311ef5b484b8479
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: window3.cxx,v $
10 * $Revision: 1.13 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_vcl.hxx"
34 #define _SV_WINDOW_CXX
36 #include "svsys.h"
37 #include "vcl/window.h"
38 #include "vcl/window.hxx"
39 #include "vcl/waitobj.hxx"
40 #include "vcl/salgdi.hxx"
41 #include "vcl/salnativewidgets.hxx"
42 #include "vcl/salctrlhandle.hxx"
43 #include "rtl/ustring.hxx"
44 #include "vcl/button.hxx"
46 using namespace rtl;
48 // -----------------------------------------------------------------------
49 // These functions are mainly passthrough functions that allow access to
50 // the SalFrame behind a Window object for native widget rendering purposes.
51 // -----------------------------------------------------------------------
53 void Window::ImplInitSalControlHandle()
55 // create SalControlHandle on demand
56 // not needed for ordinary windows
57 // TODO: move creation to SalGraphics
58 //if( !ImplGetWinData()->mpSalControlHandle )
59 // ImplGetWinData()->mpSalControlHandle = new SalControlHandle;
62 // -----------------------------------------------------------------------
64 BOOL Window::IsNativeControlSupported( ControlType nType, ControlPart nPart )
66 if( !IsNativeWidgetEnabled() )
67 return FALSE;
69 if ( !mpGraphics )
70 if ( !ImplGetGraphics() )
71 return FALSE;
73 return( mpGraphics->IsNativeControlSupported(nType, nPart) );
77 // -----------------------------------------------------------------------
79 BOOL Window::HitTestNativeControl( ControlType nType,
80 ControlPart nPart,
81 const Region& rControlRegion,
82 const Point& aPos,
83 BOOL& rIsInside )
85 if( !IsNativeWidgetEnabled() )
86 return FALSE;
88 if ( !mpGraphics )
89 if ( !ImplGetGraphics() )
90 return FALSE;
92 ImplInitSalControlHandle();
94 Point aWinOffs;
95 aWinOffs = OutputToScreenPixel( aWinOffs );
96 Region screenRegion( rControlRegion );
97 screenRegion.Move( aWinOffs.X(), aWinOffs.Y());
99 return( mpGraphics->HitTestNativeControl(nType, nPart, screenRegion, OutputToScreenPixel( aPos ), *ImplGetWinData()->mpSalControlHandle, rIsInside, this ) );
102 // -----------------------------------------------------------------------
104 void Window::ImplMoveControlValue( ControlType nType, const ImplControlValue& aValue, const Point& rDelta ) const
106 if( aValue.getOptionalVal() )
108 switch( nType )
110 case CTRL_SCROLLBAR:
112 ScrollbarValue* pScVal = reinterpret_cast<ScrollbarValue*>(aValue.getOptionalVal());
113 pScVal->maThumbRect.Move( rDelta.X(), rDelta.Y() );
114 pScVal->maButton1Rect.Move( rDelta.X(), rDelta.Y() );
115 pScVal->maButton2Rect.Move( rDelta.X(), rDelta.Y() );
117 break;
118 case CTRL_SPINBOX:
119 case CTRL_SPINBUTTONS:
121 SpinbuttonValue* pSpVal = reinterpret_cast<SpinbuttonValue*>(aValue.getOptionalVal());
122 pSpVal->maUpperRect.Move( rDelta.X(), rDelta.Y() );
123 pSpVal->maLowerRect.Move( rDelta.X(), rDelta.Y() );
125 break;
126 case CTRL_TOOLBAR:
128 ToolbarValue* pTVal = reinterpret_cast<ToolbarValue*>(aValue.getOptionalVal());
129 pTVal->maGripRect.Move( rDelta.X(), rDelta.Y() );
131 break;
136 BOOL Window::DrawNativeControl( ControlType nType,
137 ControlPart nPart,
138 const Region& rControlRegion,
139 ControlState nState,
140 const ImplControlValue& aValue,
141 OUString aCaption )
143 if( !IsNativeWidgetEnabled() )
144 return FALSE;
147 if( !IsInPaint() && IsPaintTransparent() )
149 // only required if called directly (ie, we're not in Paint() ):
150 // force redraw (Paint()) for transparent controls
151 // to trigger a repaint of the background
152 Region aClipRgn( GetClipRegion() );
153 if( !rControlRegion.IsEmpty() )
154 aClipRgn.Intersect( rControlRegion );
155 Invalidate( aClipRgn, INVALIDATE_UPDATE );
156 return TRUE;
160 ImplInitSalControlHandle();
162 // make sure the current clip region is initialized correctly
163 if ( !mpGraphics )
164 if ( !ImplGetGraphics() )
165 return FALSE;
167 if ( mbInitClipRegion )
168 ImplInitClipRegion();
169 if ( mbOutputClipped )
170 return TRUE;
172 if ( mbInitLineColor )
173 ImplInitLineColor();
174 if ( mbInitFillColor )
175 ImplInitFillColor();
177 // Convert the coordinates from relative to Window-absolute, so we draw
178 // in the correct place in platform code
179 Point aWinOffs;
180 aWinOffs = OutputToScreenPixel( aWinOffs );
181 Region screenRegion( rControlRegion );
182 screenRegion.Move( aWinOffs.X(), aWinOffs.Y());
184 // do so for ImplControlValue members, also
185 ImplMoveControlValue( nType, aValue, aWinOffs );
187 Region aTestRegion( GetActiveClipRegion() );
188 aTestRegion.Intersect( rControlRegion );
189 if( aTestRegion == rControlRegion )
190 nState |= CTRL_CACHING_ALLOWED; // control is not clipped, caching allowed
192 BOOL bRet = mpGraphics->DrawNativeControl(nType, nPart, screenRegion, nState, aValue, *ImplGetWinData()->mpSalControlHandle, aCaption, this );
194 // transform back ImplControlValue members
195 ImplMoveControlValue( nType, aValue, Point()-aWinOffs );
197 return bRet;
201 // -----------------------------------------------------------------------
203 BOOL Window::DrawNativeControlText(ControlType nType,
204 ControlPart nPart,
205 const Region& rControlRegion,
206 ControlState nState,
207 const ImplControlValue& aValue,
208 OUString aCaption )
210 if( !IsNativeWidgetEnabled() )
211 return FALSE;
213 ImplInitSalControlHandle();
215 // make sure the current clip region is initialized correctly
216 if ( !mpGraphics )
217 if ( !ImplGetGraphics() )
218 return false;
220 if ( mbInitClipRegion )
221 ImplInitClipRegion();
222 if ( mbOutputClipped )
223 return true;
225 if ( mbInitLineColor )
226 ImplInitLineColor();
227 if ( mbInitFillColor )
228 ImplInitFillColor();
230 // Convert the coordinates from relative to Window-absolute, so we draw
231 // in the correct place in platform code
232 Point aWinOffs;
233 aWinOffs = OutputToScreenPixel( aWinOffs );
234 Region screenRegion( rControlRegion );
235 screenRegion.Move( aWinOffs.X(), aWinOffs.Y());
236 ImplMoveControlValue( nType, aValue, aWinOffs );
238 BOOL bRet = mpGraphics->DrawNativeControlText(nType, nPart, screenRegion, nState, aValue, *ImplGetWinData()->mpSalControlHandle, aCaption, this );
240 // transform back ImplControlValue members
241 ImplMoveControlValue( nType, aValue, Point()-aWinOffs );
243 return bRet;
247 // -----------------------------------------------------------------------
249 BOOL Window::GetNativeControlRegion( ControlType nType,
250 ControlPart nPart,
251 const Region& rControlRegion,
252 ControlState nState,
253 const ImplControlValue& aValue,
254 OUString aCaption,
255 Region &rNativeBoundingRegion,
256 Region &rNativeContentRegion )
258 if( !IsNativeWidgetEnabled() )
259 return FALSE;
261 if ( !mpGraphics )
262 if ( !ImplGetGraphics() )
263 return FALSE;
265 ImplInitSalControlHandle();
267 // Convert the coordinates from relative to Window-absolute, so we draw
268 // in the correct place in platform code
269 Point aWinOffs;
270 aWinOffs = OutputToScreenPixel( aWinOffs );
271 Region screenRegion( rControlRegion );
272 screenRegion.Move( aWinOffs.X(), aWinOffs.Y());
273 ImplMoveControlValue( nType, aValue, aWinOffs );
275 BOOL bRet = mpGraphics->GetNativeControlRegion(nType, nPart, screenRegion, nState, aValue,
276 *ImplGetWinData()->mpSalControlHandle, aCaption, rNativeBoundingRegion,
277 rNativeContentRegion, this );
278 if( bRet )
280 // transform back native regions
281 rNativeBoundingRegion.Move( -aWinOffs.X(), -aWinOffs.Y() );
282 rNativeContentRegion.Move( -aWinOffs.X(), -aWinOffs.Y() );
284 // transform back ImplControlValue members
285 ImplMoveControlValue( nType, aValue, Point()-aWinOffs );
287 return bRet;
291 // -----------------------------------------------------------------------
293 WaitObject::~WaitObject()
295 if ( mpWindow )
296 mpWindow->LeaveWait();
299 // -----------------------------------------------------------------------
301 Size Window::GetOptimalSize(WindowSizeType eType) const
303 switch (eType) {
304 case WINDOWSIZE_MINIMUM:
305 return Size();
306 case WINDOWSIZE_PREFERRED:
307 return GetOptimalSize( WINDOWSIZE_MINIMUM );
308 case WINDOWSIZE_MAXIMUM:
309 default:
310 return Size( LONG_MAX, LONG_MAX );
314 // -----------------------------------------------------------------------
316 void Window::ImplAdjustNWFSizes()
318 switch( GetType() )
320 case WINDOW_CHECKBOX:
321 ((CheckBox*)this)->ImplSetMinimumNWFSize();
322 break;
323 case WINDOW_RADIOBUTTON:
324 ((RadioButton*)this)->ImplSetMinimumNWFSize();
325 break;
326 default:
328 // iterate over children
329 Window* pWin = GetWindow( WINDOW_FIRSTCHILD );
330 while( pWin )
332 pWin->ImplAdjustNWFSizes();
333 pWin = pWin->GetWindow( WINDOW_NEXT );
336 break;