| 1 | /****************************************************************************
|
|---|
| 2 | ** $Id: qstylefactory.cpp 2 2005-11-16 15:49:26Z dmik $
|
|---|
| 3 | **
|
|---|
| 4 | ** Implementation of QStyleFactory class
|
|---|
| 5 | **
|
|---|
| 6 | ** Created : 001103
|
|---|
| 7 | **
|
|---|
| 8 | ** Copyright (C) 1992-2002 Trolltech AS. All rights reserved.
|
|---|
| 9 | **
|
|---|
| 10 | ** This file is part of the widgets 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 licenses may use this
|
|---|
| 22 | ** file in accordance with the Qt Commercial License Agreement provided
|
|---|
| 23 | ** 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 "qstyleinterface_p.h" // up here for GCC 2.7.* compatibility
|
|---|
| 39 | #include "qstylefactory.h"
|
|---|
| 40 |
|
|---|
| 41 | #ifndef QT_NO_STYLE
|
|---|
| 42 |
|
|---|
| 43 | #include "qapplication.h"
|
|---|
| 44 | #include "qwindowsstyle.h"
|
|---|
| 45 | #include "qmotifstyle.h"
|
|---|
| 46 | #include "qcdestyle.h"
|
|---|
| 47 | #include "qmotifplusstyle.h"
|
|---|
| 48 | #include "qplatinumstyle.h"
|
|---|
| 49 | #include "qsgistyle.h"
|
|---|
| 50 | #include "qcompactstyle.h"
|
|---|
| 51 | #ifndef QT_NO_STYLE_WINDOWSXP
|
|---|
| 52 | #include "qwindowsxpstyle.h"
|
|---|
| 53 | #endif
|
|---|
| 54 | #ifndef QT_NO_STYLE_AQUA
|
|---|
| 55 | #include "qaquastyle.h"
|
|---|
| 56 | #endif
|
|---|
| 57 | #ifndef QT_NO_STYLE_POCKETPC
|
|---|
| 58 | #include "qpocketpcstyle_wce.h"
|
|---|
| 59 | #endif
|
|---|
| 60 |
|
|---|
| 61 | #if !defined( QT_NO_STYLE_MAC ) && defined( Q_WS_MAC )
|
|---|
| 62 | QCString p2qstring(const unsigned char *c); //qglobal.cpp
|
|---|
| 63 | #include "qt_mac.h"
|
|---|
| 64 | #include "qmacstyle_mac.h"
|
|---|
| 65 | #endif
|
|---|
| 66 | #include <stdlib.h>
|
|---|
| 67 |
|
|---|
| 68 | #include <private/qpluginmanager_p.h>
|
|---|
| 69 | #ifndef QT_NO_COMPONENT
|
|---|
| 70 | class QStyleFactoryPrivate : public QObject
|
|---|
| 71 | {
|
|---|
| 72 | public:
|
|---|
| 73 | QStyleFactoryPrivate();
|
|---|
| 74 | ~QStyleFactoryPrivate();
|
|---|
| 75 |
|
|---|
| 76 | static QPluginManager<QStyleFactoryInterface> *manager;
|
|---|
| 77 | };
|
|---|
| 78 |
|
|---|
| 79 | static QStyleFactoryPrivate *instance = 0;
|
|---|
| 80 | QPluginManager<QStyleFactoryInterface> *QStyleFactoryPrivate::manager = 0;
|
|---|
| 81 |
|
|---|
| 82 | QStyleFactoryPrivate::QStyleFactoryPrivate()
|
|---|
| 83 | : QObject( qApp )
|
|---|
| 84 | {
|
|---|
| 85 | manager = new QPluginManager<QStyleFactoryInterface>( IID_QStyleFactory, QApplication::libraryPaths(), "/styles", FALSE );
|
|---|
| 86 | }
|
|---|
| 87 |
|
|---|
| 88 | QStyleFactoryPrivate::~QStyleFactoryPrivate()
|
|---|
| 89 | {
|
|---|
| 90 | delete manager;
|
|---|
| 91 | manager = 0;
|
|---|
| 92 |
|
|---|
| 93 | instance = 0;
|
|---|
| 94 | }
|
|---|
| 95 |
|
|---|
| 96 | #endif //QT_NO_COMPONENT
|
|---|
| 97 |
|
|---|
| 98 | /*!
|
|---|
| 99 | \class QStyleFactory qstylefactory.h
|
|---|
| 100 | \brief The QStyleFactory class creates QStyle objects.
|
|---|
| 101 |
|
|---|
| 102 | The style factory creates a QStyle object for a given key with
|
|---|
| 103 | QStyleFactory::create(key).
|
|---|
| 104 |
|
|---|
| 105 | The styles are either built-in or dynamically loaded from a style
|
|---|
| 106 | plugin (see \l QStylePlugin).
|
|---|
| 107 |
|
|---|
| 108 | QStyleFactory::keys() returns a list of valid keys, typically
|
|---|
| 109 | including "windows", "motif", "cde", "motifplus", "platinum",
|
|---|
| 110 | "sgi" and "compact". Depending on the platform, "windowsxp",
|
|---|
| 111 | "aqua" or "macintosh" may be available.
|
|---|
| 112 | */
|
|---|
| 113 |
|
|---|
| 114 | /*!
|
|---|
| 115 | Creates a QStyle object that matches \a key. This is either a
|
|---|
| 116 | built-in style, or a style from a style plugin.
|
|---|
| 117 |
|
|---|
| 118 | \sa keys()
|
|---|
| 119 | */
|
|---|
| 120 | QStyle *QStyleFactory::create( const QString& key )
|
|---|
| 121 | {
|
|---|
| 122 | QStyle *ret = 0;
|
|---|
| 123 | QString style = key.lower();
|
|---|
| 124 | #ifndef QT_NO_STYLE_WINDOWS
|
|---|
| 125 | if ( style == "windows" )
|
|---|
| 126 | ret = new QWindowsStyle;
|
|---|
| 127 | else
|
|---|
| 128 | #endif
|
|---|
| 129 | #ifndef QT_NO_STYLE_WINDOWSXP
|
|---|
| 130 | if ( style == "windowsxp" )
|
|---|
| 131 | ret = new QWindowsXPStyle;
|
|---|
| 132 | else
|
|---|
| 133 | #endif
|
|---|
| 134 | #ifndef QT_NO_STYLE_MOTIF
|
|---|
| 135 | if ( style == "motif" )
|
|---|
| 136 | ret = new QMotifStyle;
|
|---|
| 137 | else
|
|---|
| 138 | #endif
|
|---|
| 139 | #ifndef QT_NO_STYLE_CDE
|
|---|
| 140 | if ( style == "cde" )
|
|---|
| 141 | ret = new QCDEStyle;
|
|---|
| 142 | else
|
|---|
| 143 | #endif
|
|---|
| 144 | #ifndef QT_NO_STYLE_MOTIFPLUS
|
|---|
| 145 | if ( style == "motifplus" )
|
|---|
| 146 | ret = new QMotifPlusStyle;
|
|---|
| 147 | else
|
|---|
| 148 | #endif
|
|---|
| 149 | #ifndef QT_NO_STYLE_PLATINUM
|
|---|
| 150 | if ( style == "platinum" )
|
|---|
| 151 | ret = new QPlatinumStyle;
|
|---|
| 152 | else
|
|---|
| 153 | #endif
|
|---|
| 154 | #ifndef QT_NO_STYLE_SGI
|
|---|
| 155 | if ( style == "sgi")
|
|---|
| 156 | ret = new QSGIStyle;
|
|---|
| 157 | else
|
|---|
| 158 | #endif
|
|---|
| 159 | #ifndef QT_NO_STYLE_COMPACT
|
|---|
| 160 | if ( style == "compact" )
|
|---|
| 161 | ret = new QCompactStyle;
|
|---|
| 162 | else
|
|---|
| 163 | #endif
|
|---|
| 164 | #ifndef QT_NO_STYLE_AQUA
|
|---|
| 165 | if ( style == "aqua" )
|
|---|
| 166 | ret = new QAquaStyle;
|
|---|
| 167 | #endif
|
|---|
| 168 | #ifndef QT_NO_STYLE_POCKETPC
|
|---|
| 169 | if ( style == "pocketpc" )
|
|---|
| 170 | ret = new QPocketPCStyle;
|
|---|
| 171 | #endif
|
|---|
| 172 | #if !defined( QT_NO_STYLE_MAC ) && defined( Q_WS_MAC )
|
|---|
| 173 | if( style.left(9) == "macintosh" )
|
|---|
| 174 | ret = new QMacStyle;
|
|---|
| 175 | #endif
|
|---|
| 176 | { } // Keep these here - they make the #ifdefery above work
|
|---|
| 177 |
|
|---|
| 178 | #ifndef QT_NO_COMPONENT
|
|---|
| 179 | if(!ret) {
|
|---|
| 180 | if ( !instance )
|
|---|
| 181 | instance = new QStyleFactoryPrivate;
|
|---|
| 182 |
|
|---|
| 183 | QInterfacePtr<QStyleFactoryInterface> iface;
|
|---|
| 184 | QStyleFactoryPrivate::manager->queryInterface( style, &iface );
|
|---|
| 185 |
|
|---|
| 186 | if ( iface )
|
|---|
| 187 | ret = iface->create( style );
|
|---|
| 188 | }
|
|---|
| 189 | if(ret)
|
|---|
| 190 | ret->setName(key);
|
|---|
| 191 | #endif
|
|---|
| 192 | return ret;
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | #ifndef QT_NO_STRINGLIST
|
|---|
| 196 | /*!
|
|---|
| 197 | Returns the list of keys this factory can create styles for.
|
|---|
| 198 |
|
|---|
| 199 | \sa create()
|
|---|
| 200 | */
|
|---|
| 201 | QStringList QStyleFactory::keys()
|
|---|
| 202 | {
|
|---|
| 203 | QStringList list;
|
|---|
| 204 | #ifndef QT_NO_COMPONENT
|
|---|
| 205 | if ( !instance )
|
|---|
| 206 | instance = new QStyleFactoryPrivate;
|
|---|
| 207 |
|
|---|
| 208 | list = QStyleFactoryPrivate::manager->featureList();
|
|---|
| 209 | #endif //QT_NO_COMPONENT
|
|---|
| 210 |
|
|---|
| 211 | #ifndef QT_NO_STYLE_WINDOWS
|
|---|
| 212 | if ( !list.contains( "Windows" ) )
|
|---|
| 213 | list << "Windows";
|
|---|
| 214 | #endif
|
|---|
| 215 | #ifndef QT_NO_STYLE_WINDOWSXP
|
|---|
| 216 | if ( !list.contains( "WindowsXP" ) && QWindowsXPStyle::resolveSymbols() )
|
|---|
| 217 | list << "WindowsXP";
|
|---|
| 218 | #endif
|
|---|
| 219 | #ifndef QT_NO_STYLE_MOTIF
|
|---|
| 220 | if ( !list.contains( "Motif" ) )
|
|---|
| 221 | list << "Motif";
|
|---|
| 222 | #endif
|
|---|
| 223 | #ifndef QT_NO_STYLE_CDE
|
|---|
| 224 | if ( !list.contains( "CDE" ) )
|
|---|
| 225 | list << "CDE";
|
|---|
| 226 | #endif
|
|---|
| 227 | #ifndef QT_NO_STYLE_MOTIFPLUS
|
|---|
| 228 | if ( !list.contains( "MotifPlus" ) )
|
|---|
| 229 | list << "MotifPlus";
|
|---|
| 230 | #endif
|
|---|
| 231 | #ifndef QT_NO_STYLE_PLATINUM
|
|---|
| 232 | if ( !list.contains( "Platinum" ) )
|
|---|
| 233 | list << "Platinum";
|
|---|
| 234 | #endif
|
|---|
| 235 | #ifndef QT_NO_STYLE_SGI
|
|---|
| 236 | if ( !list.contains( "SGI" ) )
|
|---|
| 237 | list << "SGI";
|
|---|
| 238 | #endif
|
|---|
| 239 | #ifndef QT_NO_STYLE_COMPACT
|
|---|
| 240 | if ( !list.contains( "Compact" ) )
|
|---|
| 241 | list << "Compact";
|
|---|
| 242 | #endif
|
|---|
| 243 | #ifndef QT_NO_STYLE_AQUA
|
|---|
| 244 | if ( !list.contains( "Aqua" ) )
|
|---|
| 245 | list << "Aqua";
|
|---|
| 246 | #endif
|
|---|
| 247 | #if !defined( QT_NO_STYLE_MAC ) && defined( Q_WS_MAC )
|
|---|
| 248 | QString mstyle = "Macintosh";
|
|---|
| 249 | Collection c = NewCollection();
|
|---|
| 250 | if (c) {
|
|---|
| 251 | GetTheme(c);
|
|---|
| 252 | Str255 str;
|
|---|
| 253 | long int s = 256;
|
|---|
| 254 | if(!GetCollectionItem(c, kThemeNameTag, 0, &s, &str))
|
|---|
| 255 | mstyle += " (" + p2qstring(str) + ")";
|
|---|
| 256 | }
|
|---|
| 257 | if (!list.contains(mstyle))
|
|---|
| 258 | list << mstyle;
|
|---|
| 259 | DisposeCollection(c);
|
|---|
| 260 | #endif
|
|---|
| 261 |
|
|---|
| 262 | return list;
|
|---|
| 263 | }
|
|---|
| 264 | #endif
|
|---|
| 265 | #endif // QT_NO_STYLE
|
|---|