source: trunk/src/gui/kernel/qx11info_x11.cpp@ 322

Last change on this file since 322 was 2, checked in by Dmitry A. Kuminov, 17 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 14.5 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the QtGui module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#include "qwidget.h"
43#include "qpixmap.h"
44#include "qx11info_x11.h"
45#include "qt_x11_p.h"
46
47QT_BEGIN_NAMESPACE
48
49/*!
50 \class QX11Info
51 \brief The QX11Info class provides information about the X display
52 configuration.
53
54 \ingroup shared
55
56 The class provides two APIs: a set of non-static functions that
57 provide information about a specific widget or pixmap, and a set
58 of static functions that provide the default information for the
59 application.
60
61 \warning This class is only available on X11. For querying
62 per-screen information in a portable way, use QDesktopWidget.
63
64 \sa QWidget::x11Info(), QPixmap::x11Info(), QDesktopWidget
65*/
66
67/*!
68 Constructs an empty QX11Info object.
69*/
70QX11Info::QX11Info()
71 : x11data(0)
72{
73}
74
75/*!
76 Constructs a copy of \a other.
77*/
78QX11Info::QX11Info(const QX11Info &other)
79{
80 x11data = other.x11data;
81 if (x11data)
82 ++x11data->ref;
83}
84
85/*!
86 Assigns \a other to this object and returns a reference to this
87 object.
88*/
89QX11Info &QX11Info::operator=(const QX11Info &other)
90{
91 if (other.x11data)
92 ++other.x11data->ref;
93 if (x11data && !--x11data->ref)
94 delete x11data;
95 x11data = other.x11data;
96 return *this;
97}
98
99/*!
100 Destroys the QX11Info object.
101*/
102QX11Info::~QX11Info()
103{
104 if (x11data && !--x11data->ref)
105 delete x11data;
106}
107
108/*!
109 \internal
110 Makes a shallow copy of the X11-specific data of \a fromDevice, if it is not
111 null. Otherwise this function sets it to null.
112*/
113
114void QX11Info::copyX11Data(const QPaintDevice *fromDevice)
115{
116 QX11InfoData *xd = 0;
117 if (fromDevice) {
118 if (fromDevice->devType() == QInternal::Widget)
119 xd = static_cast<const QWidget *>(fromDevice)->x11Info().x11data;
120 else if (fromDevice->devType() == QInternal::Pixmap)
121 xd = static_cast<const QPixmap *>(fromDevice)->x11Info().x11data;
122 }
123 setX11Data(xd);
124}
125
126/*!
127 \internal
128 Makes a deep copy of the X11-specific data of \a fromDevice, if it is not
129 null. Otherwise this function sets it to null.
130*/
131
132void QX11Info::cloneX11Data(const QPaintDevice *fromDevice)
133{
134 QX11InfoData *d = 0;
135 if (fromDevice) {
136 QX11InfoData *xd;
137 if (fromDevice->devType() == QInternal::Widget) {
138 xd = static_cast<const QWidget *>(fromDevice)->x11Info().x11data;
139 } else {
140 Q_ASSERT(fromDevice->devType() == QInternal::Pixmap);
141 xd = static_cast<const QPixmap *>(fromDevice)->x11Info().x11data;
142 }
143 d = new QX11InfoData(*xd);
144 d->ref = 0;
145 }
146 setX11Data(d);
147}
148
149/*!
150 \internal
151 Makes a shallow copy of the X11-specific data \a d and assigns it to this
152 class. This function increments the reference code of \a d.
153*/
154
155void QX11Info::setX11Data(const QX11InfoData* d)
156{
157 if (x11data && !--x11data->ref)
158 delete x11data;
159 x11data = (QX11InfoData *)d;
160 if (x11data)
161 ++x11data->ref;
162}
163
164
165/*!
166 \internal
167 If \a def is false, returns a deep copy of the x11Data, or 0 if x11Data is 0.
168 If \a def is true, makes a QX11Data struct filled with the default
169 values.
170
171 In either case the caller is responsible for deleting the returned
172 struct. But notice that the struct is a shared class, so other
173 classes might also have a reference to it. The reference count of
174 the returned QX11Data* is 0.
175*/
176
177QX11InfoData* QX11Info::getX11Data(bool def) const
178{
179 QX11InfoData* res = 0;
180 if (def) {
181 res = new QX11InfoData;
182 res->screen = appScreen();
183 res->depth = appDepth();
184 res->cells = appCells();
185 res->colormap = colormap();
186 res->defaultColormap = appDefaultColormap();
187 res->visual = (Visual*) appVisual();
188 res->defaultVisual = appDefaultVisual();
189 } else if (x11data) {
190 res = new QX11InfoData;
191 *res = *x11data;
192 }
193 res->ref = 0;
194 return res;
195}
196
197/*!
198 Returns the horizontal resolution of the given \a screen in terms of the
199 number of dots per inch.
200
201 The \a screen argument is an X screen number. Be aware that if
202 the user's system uses Xinerama (as opposed to traditional X11
203 multiscreen), there is only one X screen. Use QDesktopWidget to
204 query for information about Xinerama screens.
205
206 \sa setAppDpiX(), appDpiY()
207*/
208int QX11Info::appDpiX(int screen)
209{
210 if (!X11)
211 return 75;
212 if (screen < 0)
213 screen = X11->defaultScreen;
214 if (screen > X11->screenCount)
215 return 0;