[8] | 1 | /****************************************************************************
|
---|
| 2 | ** $Id: qdesktopwidget_pm.cpp 110 2006-07-30 17:11:51Z dmik $
|
---|
| 3 | **
|
---|
| 4 | ** Implementation of QDesktopWidget class for OS/2
|
---|
| 5 | **
|
---|
| 6 | ** Copyright (C) 1992-2001 Trolltech AS. All rights reserved.
|
---|
| 7 | ** Copyright (C) 2004 Norman ASA. Initial OS/2 Port.
|
---|
| 8 | ** Copyright (C) 2005 netlabs.org. Further OS/2 Development.
|
---|
| 9 | **
|
---|
| 10 | ** This file is part of the kernel module of the Qt GUI Toolkit.
|
---|
| 11 | **
|
---|
| 12 | ** This file may be distributed under the terms of the Q Public License
|
---|
| 13 | ** as defined by Trolltech AS of Norway and appearing in the file
|
---|
| 14 | ** LICENSE.QPL included in the packaging of this file.
|
---|
| 15 | **
|
---|
| 16 | ** This file may be distributed and/or modified under the terms of the
|
---|
| 17 | ** GNU General Public License version 2 as published by the Free Software
|
---|
| 18 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
---|
| 19 | ** packaging of this file.
|
---|
| 20 | **
|
---|
| 21 | ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
|
---|
| 22 | ** licenses may use this file in accordance with the Qt Commercial License
|
---|
| 23 | ** Agreement provided with the Software.
|
---|
| 24 | **
|
---|
| 25 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
|
---|
| 26 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
---|
| 27 | **
|
---|
| 28 | ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
|
---|
| 29 | ** information about Qt Commercial License Agreements.
|
---|
| 30 | ** See http://www.trolltech.com/qpl/ for QPL licensing information.
|
---|
| 31 | ** See http://www.trolltech.com/gpl/ for GPL licensing information.
|
---|
| 32 | **
|
---|
| 33 | ** Contact info@trolltech.com if any conditions of this licensing are
|
---|
| 34 | ** not clear to you.
|
---|
| 35 | **
|
---|
| 36 | **********************************************************************/
|
---|
| 37 |
|
---|
| 38 | #include "qdesktopwidget.h"
|
---|
| 39 |
|
---|
| 40 | /*
|
---|
| 41 | \omit
|
---|
| 42 | Function is commented out in header
|
---|
| 43 | \fn void *QDesktopWidget::handle( int screen ) const
|
---|
| 44 |
|
---|
| 45 | Returns the window system handle of the display device with the
|
---|
| 46 | index \a screen, for low-level access. Using this function is not
|
---|
| 47 | portable.
|
---|
| 48 |
|
---|
| 49 | The return type varies with platform; see qwindowdefs.h for details.
|
---|
| 50 |
|
---|
| 51 | \sa x11Display(), QPaintDevice::handle()
|
---|
| 52 | \endomit
|
---|
| 53 | */
|
---|
| 54 |
|
---|
[110] | 55 | // just stolen from xWorkplace sources
|
---|
| 56 | static
|
---|
| 57 | APIRET qt_DosQueryProcAddr( PCSZ pcszModuleName, ULONG ulOrdinal, PFN *ppfn )
|
---|
| 58 | {
|
---|
| 59 | HMODULE hmod = NULL;
|
---|
| 60 | APIRET rc = 0;
|
---|
| 61 | if ( !(rc = DosQueryModuleHandle( (PSZ)pcszModuleName, &hmod )) ) {
|
---|
| 62 | if ( (rc = DosQueryProcAddr( hmod, ulOrdinal, NULL, ppfn )) ) {
|
---|
| 63 | // the CP programming guide and reference says use
|
---|
| 64 | // DosLoadModule if DosQueryProcAddr fails with this error
|
---|
| 65 | if ( rc == ERROR_INVALID_HANDLE ) {
|
---|
| 66 | if ( !(rc = DosLoadModule( NULL, 0, (PSZ) pcszModuleName,
|
---|
| 67 | &hmod )) ) {
|
---|
| 68 | rc = DosQueryProcAddr( hmod, ulOrdinal, NULL, ppfn );
|
---|
| 69 | }
|
---|
| 70 | }
|
---|
| 71 | }
|
---|
| 72 | }
|
---|
| 73 | return rc;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | class QDesktopWidgetPrivate
|
---|
| 77 | {
|
---|
| 78 | public:
|
---|
| 79 |
|
---|
| 80 | QRect workArea;
|
---|
| 81 | };
|
---|
| 82 |
|
---|
[8] | 83 | /*!
|
---|
| 84 | \class QDesktopWidget qdesktopwidget.h
|
---|
| 85 | \brief The QDesktopWidget class provides access to screen information on multi-head systems.
|
---|
| 86 |
|
---|
| 87 | \ingroup advanced
|
---|
| 88 | \ingroup environment
|
---|
| 89 |
|
---|
| 90 | Systems with more than one graphics card and monitor can manage the
|
---|
| 91 | physical screen space available either as multiple desktops, or as a
|
---|
| 92 | large virtual desktop, which usually has the size of the bounding
|
---|
| 93 | rectangle of all the screens (see isVirtualDesktop()). For an
|
---|
| 94 | application, one of the available screens is the primary screen, i.e.
|
---|
| 95 | the screen where the main widget resides (see primaryScreen()). All
|
---|
| 96 | windows opened in the context of the application must be
|
---|
| 97 | constrained to the boundaries of the primary screen; for example,
|
---|
| 98 | it would be inconvenient if a dialog box popped up on a different
|
---|
| 99 | screen, or split over two screens.
|
---|
| 100 |
|
---|
| 101 | The QDesktopWidget provides information about the geometry of the
|
---|
| 102 | available screens with screenGeometry(). The number of screens
|
---|
| 103 | available is returned by numScreens(). The screen number that a
|
---|
| 104 | particular point or widget is located in is returned by
|
---|
| 105 | screenNumber().
|
---|
| 106 |
|
---|
| 107 | Widgets provided by Qt use this class, for example, to place
|
---|
| 108 | tooltips, menus and dialog boxes according to the parent or
|
---|
| 109 | application widget.
|
---|
| 110 |
|
---|
| 111 | Applications can use this class to save window positions, or to place
|
---|
| 112 | child widgets on one screen.
|
---|
| 113 |
|
---|
| 114 | \img qdesktopwidget.png Managing Multiple Screens
|
---|
| 115 |
|
---|
| 116 | In the illustration above, Application One's primary screen is
|
---|
| 117 | screen 0, and App Two's primary screen is screen 1.
|
---|
| 118 |
|
---|
| 119 |
|
---|
| 120 | */
|
---|
| 121 |
|
---|
| 122 | /*!
|
---|
| 123 | Creates the desktop widget.
|
---|
| 124 |
|
---|
| 125 | If the system supports a virtual desktop, this widget will have
|
---|
| 126 | the size of the virtual desktop; otherwise this widget will have
|
---|
| 127 | the size of the primary screen.
|
---|
| 128 |
|
---|
| 129 | Instead of using QDesktopWidget directly, use
|
---|
| 130 | QAppliation::desktop().
|
---|
| 131 | */
|
---|
| 132 | QDesktopWidget::QDesktopWidget()
|
---|
| 133 | : QWidget( 0, "desktop", WType_Desktop )
|
---|
| 134 | {
|
---|
[110] | 135 | d = new QDesktopWidgetPrivate();
|
---|
[8] | 136 | }
|
---|
| 137 |
|
---|
| 138 | /*!
|
---|
| 139 | Destroy the object and free allocated resources.
|
---|
| 140 | */
|
---|
| 141 | QDesktopWidget::~QDesktopWidget()
|
---|
| 142 | {
|
---|
[110] | 143 | delete d;
|
---|
[8] | 144 | }
|
---|
| 145 |
|
---|
| 146 | /*!
|
---|
| 147 | Returns TRUE if the system manages the available screens in a
|
---|
| 148 | virtual desktop; otherwise returns FALSE.
|
---|
| 149 |
|
---|
| 150 | For virtual desktops, screen() will always return the same widget.
|
---|
| 151 | The size of the virtual desktop is the size of this desktop
|
---|
| 152 | widget.
|
---|
| 153 | */
|
---|
| 154 | bool QDesktopWidget::isVirtualDesktop() const
|
---|
| 155 | {
|
---|
| 156 | return FALSE;
|
---|
| 157 | }
|
---|
| 158 |
|
---|
| 159 | /*!
|
---|
| 160 | Returns the index of the primary screen.
|
---|
| 161 |
|
---|
| 162 | \sa numScreens()
|
---|
| 163 | */
|
---|
| 164 | int QDesktopWidget::primaryScreen() const
|
---|
| 165 | {
|
---|
| 166 | return 0;
|
---|
| 167 | }
|
---|
| 168 |
|
---|
| 169 | /*!
|
---|
| 170 | Returns the number of available screens.
|
---|
| 171 |
|
---|
| 172 | \sa primaryScreen()
|
---|
| 173 | */
|
---|
| 174 | int QDesktopWidget::numScreens() const
|
---|
| 175 | {
|
---|
| 176 | return 1;
|
---|
| 177 | }
|
---|
| 178 |
|
---|
| 179 | /*!
|
---|
| 180 | Returns a widget that represents the screen with index \a screen.
|
---|
| 181 | This widget can be used to draw directly on the desktop, using an
|
---|
| 182 | unclipped painter like this:
|
---|
| 183 |
|
---|
| 184 | \code
|
---|
| 185 | QPainter paint( QApplication::desktop()->screen( 0 ), TRUE );
|
---|
| 186 | paint.draw...
|
---|
| 187 | ...
|
---|
| 188 | paint.end();
|
---|
| 189 | \endcode
|
---|
| 190 |
|
---|
| 191 | If the system uses a virtual desktop, the returned widget will
|
---|
| 192 | have the geometry of the entire virtual desktop i.e. bounding
|
---|
| 193 | every \a screen.
|
---|
| 194 |
|
---|
| 195 | \sa primaryScreen(), numScreens(), isVirtualDesktop()
|
---|
| 196 | */
|
---|
| 197 | QWidget *QDesktopWidget::screen( int /*screen*/ )
|
---|
| 198 | {
|
---|
| 199 | // It seems that a WType_Desktop cannot be moved?
|
---|
| 200 | return this;
|
---|
| 201 | }
|
---|
| 202 |
|
---|
| 203 | /*!
|
---|
| 204 | Returns the available geometry of the screen with index \a screen. What
|
---|
| 205 | is available will be subrect of screenGeometry() based on what the
|
---|
| 206 | platform decides is available (for example excludes the Dock and Menubar
|
---|
| 207 | on Mac OS X, or the taskbar on Windows).
|
---|
| 208 |
|
---|
| 209 | \sa screenNumber(), screenGeometry()
|
---|
| 210 | */
|
---|
| 211 | const QRect& QDesktopWidget::availableGeometry( int /*screen*/ ) const
|
---|
| 212 | {
|
---|
[110] | 213 | typedef
|
---|
| 214 | BOOL (APIENTRY *WinQueryDesktopWorkArea_T) (HWND hwndDesktop,
|
---|
| 215 | PRECTL pwrcWorkArea);
|
---|
| 216 | static WinQueryDesktopWorkArea_T WinQueryDesktopWorkArea =
|
---|
| 217 | (WinQueryDesktopWorkArea_T) ~0;
|
---|
| 218 |
|
---|
| 219 | if ( (ULONG) WinQueryDesktopWorkArea == (ULONG) ~0 ) {
|
---|
| 220 | if ( qt_DosQueryProcAddr( "PMMERGE", 5469,
|
---|
| 221 | (PFN *) &WinQueryDesktopWorkArea ) )
|
---|
| 222 | WinQueryDesktopWorkArea = NULL;
|
---|
| 223 | }
|
---|
| 224 |
|
---|
| 225 | if ( WinQueryDesktopWorkArea ) {
|
---|
| 226 | RECTL rcl;
|
---|
| 227 | if ( WinQueryDesktopWorkArea( HWND_DESKTOP, &rcl ) ) {
|
---|
| 228 | // flip y coordinates
|
---|
| 229 | d->workArea.setCoords( rcl.xLeft, height() - rcl.yTop,
|
---|
| 230 | rcl.xRight - 1,
|
---|
| 231 | height() - (rcl.yBottom + 1) );
|
---|
| 232 | return d->workArea;
|
---|
| 233 | }
|
---|
| 234 | }
|
---|
| 235 |
|
---|
[8] | 236 | return geometry();
|
---|
| 237 | }
|
---|
| 238 |
|
---|
| 239 | /*!
|
---|
| 240 | \overload const QRect &QDesktopWidget::availableGeometry( QWidget *widget ) const
|
---|
| 241 |
|
---|
| 242 | Returns the available geometry of the screen which contains \a widget.
|
---|
| 243 |
|
---|
| 244 | \sa screenGeometry()
|
---|
| 245 | */
|
---|
| 246 |
|
---|
| 247 | /*!
|
---|
| 248 | \overload const QRect &QDesktopWidget::availableGeometry( const QPoint &p ) const
|
---|
| 249 |
|
---|
| 250 | Returns the available geometry of the screen which contains \a p.
|
---|
| 251 |
|
---|
| 252 | \sa screenGeometry()
|
---|
| 253 | */
|
---|
| 254 |
|
---|
| 255 |
|
---|
| 256 | /*!
|
---|
| 257 | Returns the geometry of the screen with index \a screen.
|
---|
| 258 |
|
---|
| 259 | \sa screenNumber()
|
---|
| 260 | */
|
---|
| 261 | const QRect& QDesktopWidget::screenGeometry( int /*screen*/ ) const
|
---|
| 262 | {
|
---|
| 263 | return geometry();
|
---|
| 264 | }
|
---|
| 265 |
|
---|
| 266 | /*!
|
---|
| 267 | \overload const QRect &QDesktopWidget::screenGeometry( QWidget *widget ) const
|
---|
| 268 |
|
---|
| 269 | Returns the geometry of the screen which contains \a widget.
|
---|
| 270 | */
|
---|
| 271 |
|
---|
| 272 | /*!
|
---|
| 273 | \overload const QRect &QDesktopWidget::screenGeometry( const QPoint &p ) const
|
---|
| 274 |
|
---|
| 275 | Returns the geometry of the screen which contains \a p.
|
---|
| 276 | */
|
---|
| 277 |
|
---|
| 278 |
|
---|
| 279 | /*!
|
---|
| 280 | Returns the index of the screen that contains the largest
|
---|
| 281 | part of \a widget, or -1 if the widget not on a screen.
|
---|
| 282 |
|
---|
| 283 | \sa primaryScreen()
|
---|
| 284 | */
|
---|
| 285 | int QDesktopWidget::screenNumber( QWidget */*widget*/ ) const
|
---|
| 286 | {
|
---|
| 287 | return 0;
|
---|
| 288 | }
|
---|
| 289 |
|
---|
| 290 | /*!
|
---|
| 291 | \overload
|
---|
| 292 | Returns the index of the screen that contains \a point, or -1 if
|
---|
| 293 | no screen contains the point.
|
---|
| 294 |
|
---|
| 295 | \sa primaryScreen()
|
---|
| 296 | */
|
---|
| 297 | int QDesktopWidget::screenNumber( const QPoint &/*point*/ ) const
|
---|
| 298 | {
|
---|
| 299 | return 0;
|
---|
| 300 | }
|
---|
| 301 |
|
---|
| 302 | /*!
|
---|
| 303 | \reimp
|
---|
| 304 | */
|
---|
[110] | 305 | void QDesktopWidget::resizeEvent( QResizeEvent *e )
|
---|
[8] | 306 | {
|
---|
[110] | 307 | if ( e && !e->size().isValid() && !e->oldSize().isValid() ) {
|
---|
| 308 | // This is a Work Area Changed notification, see WM_SYSVALUECHANGED
|
---|
| 309 | // in qapplication_pm.cpp
|
---|
| 310 | emit workAreaResized( 0 );
|
---|
| 311 | return;
|
---|
| 312 | }
|
---|
| 313 |
|
---|
| 314 | // nothing to do, the desktop cannot be dynamically resized in OS/2
|
---|
[8] | 315 | }
|
---|
| 316 |
|
---|
| 317 | /*! \fn void QDesktopWidget::insertChild( QObject *child )
|
---|
| 318 | \reimp
|
---|
| 319 | */
|
---|
| 320 |
|
---|
| 321 | /*! \fn void QDesktopWidget::resized( int screen )
|
---|
| 322 | This signal is emitted when the size of \a screen changes.
|
---|
| 323 | */
|
---|
| 324 |
|
---|
| 325 | /*! \fn void QDesktopWidget::workAreaResized( int screen )
|
---|
| 326 | \internal
|
---|
| 327 | This signal is emitted when the work area available on \a screen changes.
|
---|
| 328 | */
|
---|