src/gui/kernel/qx11info_x11.cpp

Go to the documentation of this file.
00001 /****************************************************************************
00002 **
00003 ** Copyright (C) 1992-2006 Trolltech ASA. All rights reserved.
00004 **
00005 ** This file is part of the QtGui module of the Qt Toolkit.
00006 **
00007 ** This file may be used under the terms of the GNU General Public
00008 ** License version 2.0 as published by the Free Software Foundation
00009 ** and appearing in the file LICENSE.GPL included in the packaging of
00010 ** this file.  Please review the following information to ensure GNU
00011 ** General Public Licensing requirements will be met:
00012 ** http://www.trolltech.com/products/qt/opensource.html
00013 **
00014 ** If you are unsure which license is appropriate for your use, please
00015 ** review the following information:
00016 ** http://www.trolltech.com/products/qt/licensing.html or contact the
00017 ** sales department at sales@trolltech.com.
00018 **
00019 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00020 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00021 **
00022 ****************************************************************************/
00023 
00024 #include "qwidget.h"
00025 #include "qpixmap.h"
00026 #include "qx11info_x11.h"
00027 #include "qt_x11_p.h"
00028 
00050 QX11Info::QX11Info()
00051     : x11data(0)
00052 {
00053 }
00054 
00058 QX11Info::QX11Info(const QX11Info &other)
00059 {
00060     x11data = other.x11data;
00061     if (x11data)
00062         ++x11data->ref;
00063 }
00064 
00069 QX11Info &QX11Info::operator=(const QX11Info &other)
00070 {
00071     QX11InfoData *x = other.x11data;
00072     if (x)
00073         ++x->ref;
00074     x = qAtomicSetPtr(&x11data, x);
00075     if (x && !--x->ref)
00076         delete x;
00077     return *this;
00078 }
00079 
00083 QX11Info::~QX11Info()
00084 {
00085     if (x11data && !--x11data->ref)
00086         delete x11data;
00087 }
00088 
00095 void QX11Info::copyX11Data(const QPaintDevice *fromDevice)
00096 {
00097     QX11InfoData *xd = 0;
00098     if (fromDevice) {
00099         if (fromDevice->devType() == QInternal::Widget)
00100             xd = static_cast<const QWidget *>(fromDevice)->x11Info().x11data;
00101         else if (fromDevice->devType() == QInternal::Pixmap)
00102             xd = static_cast<const QPixmap *>(fromDevice)->x11Info().x11data;
00103     }
00104     setX11Data(xd);
00105 }
00106 
00113 void QX11Info::cloneX11Data(const QPaintDevice *fromDevice)
00114 {
00115     QX11InfoData *d = 0;
00116     if (fromDevice) {
00117         QX11InfoData *xd;
00118         if (fromDevice->devType() == QInternal::Widget) {
00119             xd = static_cast<const QWidget *>(fromDevice)->x11Info().x11data;
00120   } else {
00121       Q_ASSERT(fromDevice->devType() == QInternal::Pixmap);
00122             xd = static_cast<const QPixmap *>(fromDevice)->x11Info().x11data;
00123   }
00124         d = new QX11InfoData(*xd);
00125         d->ref = 0;
00126     }
00127     setX11Data(d);
00128 }
00129 
00136 void QX11Info::setX11Data(const QX11InfoData* d)
00137 {
00138     if (x11data && !--x11data->ref)
00139         delete x11data;
00140     x11data = (QX11InfoData *)d;
00141     if (x11data)
00142         ++x11data->ref;
00143 }
00144 
00145 
00158 QX11InfoData* QX11Info::getX11Data(bool def) const
00159 {
00160     QX11InfoData* res = 0;
00161     if (def) {
00162         res = new QX11InfoData;
00163         res->screen = appScreen();
00164         res->depth = appDepth();
00165         res->cells = appCells();
00166         res->colormap = colormap();
00167         res->defaultColormap = appDefaultColormap();
00168         res->visual = (Visual*) appVisual();
00169         res->defaultVisual = appDefaultVisual();
00170     } else if (x11data) {
00171         res = new QX11InfoData;
00172         *res = *x11data;
00173     }
00174     res->ref = 0;
00175     return res;
00176 }
00177 
00189 int QX11Info::appDpiX(int screen)
00190 {
00191     if (!X11)
00192         return 75;
00193     if (screen < 0)
00194         screen = X11->defaultScreen;
00195     if (screen > X11->screenCount)
00196         return 0;
00197     return X11->screens[screen].dpiX;
00198 }
00199 
00212 void QX11Info::setAppDpiX(int screen, int xdpi)
00213 {
00214     if (!X11)
00215         return;
00216     if (screen < 0)
00217         screen = X11->defaultScreen;
00218     if (screen > X11->screenCount)
00219         return;
00220     X11->screens[screen].dpiX = xdpi;
00221 }
00222 
00235 int QX11Info::appDpiY(int screen)
00236 {
00237     if (!X11)
00238         return 75;
00239     if (screen < 0)
00240         screen = X11->defaultScreen;
00241     if (screen > X11->screenCount)
00242         return 0;
00243     return X11->screens[screen].dpiY;
00244 }
00245 
00257 void QX11Info::setAppDpiY(int screen, int ydpi)
00258 {
00259     if (!X11)
00260         return;
00261     if (screen < 0)
00262         screen = X11->defaultScreen;
00263     if (screen > X11->screenCount)
00264         return;
00265     X11->screens[screen].dpiY = ydpi;
00266 }
00267 
00273 unsigned long QX11Info::appTime()
00274 {
00275     return X11 ? X11->time : 0;
00276 }
00277 
00283 void QX11Info::setAppTime(unsigned long time)
00284 {
00285     if (X11) {
00286         X11->time = time;
00287     }
00288 }
00289 
00295 unsigned long QX11Info::appUserTime()
00296 {
00297     return X11 ? X11->userTime : 0;
00298 }
00299 
00305 void QX11Info::setAppUserTime(unsigned long time)
00306 {
00307     if (X11) {
00308         X11->userTime = time;
00309     }
00310 }
00311 
00312 
00327 Display *QX11Info::display()
00328 {
00329     return X11 ? X11->display : 0;
00330 }
00331 
00338 int QX11Info::appScreen()
00339 {
00340     return X11 ? X11->defaultScreen : 0;
00341 }
00342 
00353 Qt::HANDLE QX11Info::appColormap(int screen)
00354 {
00355     return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].colormap : 0;
00356 }
00357 
00370 void *QX11Info::appVisual(int screen)
00371 {
00372     return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].visual : 0;
00373 }
00374 
00385 Qt::HANDLE QX11Info::appRootWindow(int screen)
00386 {
00387     return X11 ? RootWindow(X11->display, screen == -1 ? X11->defaultScreen : screen) : 0;
00388 }
00389 
00402 int QX11Info::appDepth(int screen)
00403 {
00404     return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].depth : 32;
00405 }
00406 
00418 int QX11Info::appCells(int screen)
00419 { return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].cells : 0; }
00420 
00430 bool QX11Info::appDefaultColormap(int screen)
00431 { return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].defaultColormap : true; }
00432 
00442 bool QX11Info::appDefaultVisual(int screen)
00443 { return X11 ? X11->screens[screen == -1 ? X11->defaultScreen : screen].defaultVisual : true; }
00444 
00455 int QX11Info::screen() const
00456 { return x11data ? x11data->screen : QX11Info::appScreen(); }
00457 
00464 int QX11Info::depth() const
00465 { return x11data ? x11data->depth : QX11Info::appDepth(); }
00466 
00473 int QX11Info::cells() const
00474 { return x11data ? x11data->cells : QX11Info::appCells(); }
00475 
00482 Qt::HANDLE QX11Info::colormap() const
00483 { return x11data ? x11data->colormap : QX11Info::appColormap(); }
00484 
00491 bool QX11Info::defaultColormap() const
00492 { return x11data ? x11data->defaultColormap : QX11Info::appDefaultColormap(); }
00493 
00500 void *QX11Info::visual() const
00501 { return x11data ? x11data->visual : QX11Info::appVisual(); }
00502 
00509 bool QX11Info::defaultVisual() const
00510 { return x11data ? x11data->defaultVisual : QX11Info::appDefaultVisual(); }

Generated on Thu Mar 15 11:55:19 2007 for Qt 4.2 User's Guide by  doxygen 1.5.1