1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: window3.cxx,v $
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
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"
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() )
70 if ( !ImplGetGraphics() )
73 return( mpGraphics
->IsNativeControlSupported(nType
, nPart
) );
77 // -----------------------------------------------------------------------
79 BOOL
Window::HitTestNativeControl( ControlType nType
,
81 const Region
& rControlRegion
,
85 if( !IsNativeWidgetEnabled() )
89 if ( !ImplGetGraphics() )
92 ImplInitSalControlHandle();
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() )
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() );
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() );
128 ToolbarValue
* pTVal
= reinterpret_cast<ToolbarValue
*>(aValue
.getOptionalVal());
129 pTVal
->maGripRect
.Move( rDelta
.X(), rDelta
.Y() );
136 BOOL
Window::DrawNativeControl( ControlType nType
,
138 const Region
& rControlRegion
,
140 const ImplControlValue
& aValue
,
143 if( !IsNativeWidgetEnabled() )
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 );
160 ImplInitSalControlHandle();
162 // make sure the current clip region is initialized correctly
164 if ( !ImplGetGraphics() )
167 if ( mbInitClipRegion
)
168 ImplInitClipRegion();
169 if ( mbOutputClipped
)
172 if ( mbInitLineColor
)
174 if ( mbInitFillColor
)
177 // Convert the coordinates from relative to Window-absolute, so we draw
178 // in the correct place in platform code
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
);
201 // -----------------------------------------------------------------------
203 BOOL
Window::DrawNativeControlText(ControlType nType
,
205 const Region
& rControlRegion
,
207 const ImplControlValue
& aValue
,
210 if( !IsNativeWidgetEnabled() )
213 ImplInitSalControlHandle();
215 // make sure the current clip region is initialized correctly
217 if ( !ImplGetGraphics() )
220 if ( mbInitClipRegion
)
221 ImplInitClipRegion();
222 if ( mbOutputClipped
)
225 if ( mbInitLineColor
)
227 if ( mbInitFillColor
)
230 // Convert the coordinates from relative to Window-absolute, so we draw
231 // in the correct place in platform code
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
);
247 // -----------------------------------------------------------------------
249 BOOL
Window::GetNativeControlRegion( ControlType nType
,
251 const Region
& rControlRegion
,
253 const ImplControlValue
& aValue
,
255 Region
&rNativeBoundingRegion
,
256 Region
&rNativeContentRegion
)
258 if( !IsNativeWidgetEnabled() )
262 if ( !ImplGetGraphics() )
265 ImplInitSalControlHandle();
267 // Convert the coordinates from relative to Window-absolute, so we draw
268 // in the correct place in platform code
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 );
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
);
291 // -----------------------------------------------------------------------
293 WaitObject::~WaitObject()
296 mpWindow
->LeaveWait();
299 // -----------------------------------------------------------------------
301 Size
Window::GetOptimalSize(WindowSizeType eType
) const
304 case WINDOWSIZE_MINIMUM
:
306 case WINDOWSIZE_PREFERRED
:
307 return GetOptimalSize( WINDOWSIZE_MINIMUM
);
308 case WINDOWSIZE_MAXIMUM
:
310 return Size( LONG_MAX
, LONG_MAX
);
314 // -----------------------------------------------------------------------
316 void Window::ImplAdjustNWFSizes()
320 case WINDOW_CHECKBOX
:
321 ((CheckBox
*)this)->ImplSetMinimumNWFSize();
323 case WINDOW_RADIOBUTTON
:
324 ((RadioButton
*)this)->ImplSetMinimumNWFSize();
328 // iterate over children
329 Window
* pWin
= GetWindow( WINDOW_FIRSTCHILD
);
332 pWin
->ImplAdjustNWFSizes();
333 pWin
= pWin
->GetWindow( WINDOW_NEXT
);