Eneboo - Documentación para desarrolladores
src/qt/src/kernel/qt_mac.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qt/qt_mac.h   3.3.8   edited Jan 11 14:38 $
00003 **
00004 ** Definition of ???
00005 **
00006 ** Copyright (C) 1992-2007 Trolltech ASA.  All rights reserved.
00007 **
00008 ** This file is part of the kernel module of the Qt GUI Toolkit.
00009 **
00010 ** This file may be distributed and/or modified under the terms of the
00011 ** GNU General Public License version 2 as published by the Free Software
00012 ** Foundation and appearing in the file LICENSE.GPL included in the
00013 ** packaging of this file.
00014 **
00015 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00016 ** licenses for Macintosh may use this file in accordance with the Qt Commercial
00017 ** License Agreement provided with the Software.
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 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00023 **   information about Qt Commercial License Agreements.
00024 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00025 **
00026 ** Contact info@trolltech.com if any conditions of this licensing are
00027 ** not clear to you.
00028 **
00029 **********************************************************************/
00030 
00031 #ifndef QT_MAC_H
00032 #define QT_MAC_H
00033 
00034 #undef OLD_DEBUG
00035 #ifdef DEBUG
00036 #define OLD_DEBUG DEBUG
00037 #undef DEBUG
00038 #endif
00039 #define DEBUG 0
00040 
00041 #ifndef __IMAGECAPTURE__
00042 #define __IMAGECAPTURE__
00043 #endif
00044 #include <Carbon/Carbon.h>
00045 #include <QuickTime/Movies.h>
00046 #undef QT_BUILD_KEY
00047 #include <qconfig.h> //We need this to get QT_MACOSX_VERSION
00048 #include "qglobal.h"
00049 
00050 #ifdef Q_OS_MAC9
00051 # define QMAC_DEFAULT_STYLE "QPlatinumStyle" //Default style
00052 # include "qt_mac9.h"
00053 #elif defined(Q_OS_MACX)
00054 # define QMAC_DEFAULT_STYLE "QMacStyle" //DefaultStyle
00055 #endif
00056 
00057 #if !defined(Q_WS_MACX) || QT_MACOSX_VERSION < 0x1020 || (QT_MACOSX_VERSION >= 0x1030 && QT_MACOSX_VERSION <= 0x1040)
00058 # define QMAC_NO_FAKECURSOR
00059 #endif
00060 
00061 /* We don't use the ApplicationEventLoop because it can causes bad behaviour in
00062    multithreaded applications. I've left the code in however because using the
00063    ApplicationEventLoop solved other problems (ages ago) - for example the gumdrop
00064    "hover" effects. */
00065 //#define QMAC_USE_APPLICATION_EVENT_LOOP
00066 
00067 #undef DEBUG
00068 #ifdef OLD_DEBUG
00069 #define DEBUG OLD_DEBUG
00070 #endif
00071 #undef OLD_DEBUG
00072 
00073 #ifdef Q_WS_MAC
00074 #include "qpainter.h"
00075 #include "qwidget.h"
00076 extern int mac_window_count; //qwidget_mac.cpp
00077 #ifdef QT_THREAD_SUPPORT
00078 #include "qthread.h"
00079 extern QMutex *qt_mac_port_mutex; //qapplication_mac.cpp
00080 #endif
00081 
00082 class QMacBlockingFunction : public QObject //done in qapplication_mac.cpp
00083 {
00084 private:
00085     static int block;
00086 public:
00087     QMacBlockingFunction();
00088     ~QMacBlockingFunction() { block--; }
00089     static bool blocking() { return block != 0; }
00090 
00091 protected:
00092     void timerEvent(QTimerEvent *);
00093 };
00094 
00095 class QMacSavedFontInfo 
00096 {
00097 private:
00098     void init(CGrafPtr);
00099 protected:
00100     short tfont, tface;
00101     int tsize;
00102 public:
00103     inline QMacSavedFontInfo() { GWorldPtr w; GDHandle h; GetGWorld(&w, &h); init(w); }
00104     inline QMacSavedFontInfo(CGrafPtr w) { init(w); }
00105     ~QMacSavedFontInfo();
00106 };
00107 
00108 inline QMacSavedFontInfo::~QMacSavedFontInfo() 
00109 {
00110     if(mac_window_count) {
00111         TextFont(tfont);
00112         TextFace(tface);
00113         TextSize(tsize);
00114     }
00115 }
00116 
00117 inline void QMacSavedFontInfo::init(CGrafPtr w) 
00118 {
00119     if(mac_window_count) {
00120         tfont = GetPortTextFont(w);
00121         tface = GetPortTextFace(w);
00122         tsize = GetPortTextSize(w);
00123     }
00124 }
00125 
00126 class QMacFontInfo
00127 {
00128 public:
00129     inline QMacFontInfo() : fi_fnum(0), fi_face(0), fi_size(0), fi_enc(0), fi_astyle(0)
00130         { }
00131     inline ~QMacFontInfo() 
00132         { if(fi_astyle && fi_astyle->deref()) {
00133             ATSUDisposeStyle(fi_astyle->style);
00134             delete fi_astyle;
00135         } }
00136     inline QMacFontInfo &operator=(const QMacFontInfo &rhs) {
00137         setEncoding(rhs.encoding());
00138         setFont(rhs.font());
00139         setStyle(rhs.style());
00140         setSize(rhs.size());
00141         if(rhs.atsuStyle()) {
00142             rhs.atsuStyle()->ref();
00143             setATSUStyle(rhs.atsuStyle());
00144         } else {
00145             if(fi_astyle && fi_astyle->deref()) {
00146                 ATSUDisposeStyle(fi_astyle->style);
00147                 delete fi_astyle;
00148             }
00149             setStyle(0);
00150         }
00151         return *this;
00152     }
00153 
00154     inline TextEncoding encoding() const { return fi_enc; }
00155     inline void setEncoding(TextEncoding f) { fi_enc = f; }
00156 
00157     inline short font() const { return fi_fnum; }
00158     inline void setFont(short f) { fi_fnum = f; }
00159 
00160     inline short style() const { return fi_face; }
00161     inline void setStyle(short f) { fi_face = f; }
00162 
00163     inline int size() const { return fi_size; }
00164     inline void setSize(int f) { fi_size = f; }
00165 
00166     struct QATSUStyle : public QShared {
00167         ATSUStyle style;
00168         RGBColor rgb;
00169     };
00170     inline QATSUStyle *atsuStyle() const { return fi_astyle; }
00171     inline void setATSUStyle(QATSUStyle *s) { fi_astyle = s; }
00172 
00173 private:
00174     short fi_fnum, fi_face;
00175     int fi_size;
00176     TextEncoding fi_enc;
00177     QATSUStyle *fi_astyle;
00178 };
00179 
00180 class QFontEngine;
00181 class QFontDef;
00182 class QFontPrivate;
00183 class QMacSetFontInfo : public QMacSavedFontInfo, public QMacFontInfo 
00184 {
00185 private:
00186     static QMacFontInfo *createFontInfo(const QFontEngine *fe, const QFontDef *def, QPaintDevice *pdev);
00187 
00188 public:
00189     //create this for temporary font settting
00190     inline QMacSetFontInfo(const QFontPrivate *d, QPaintDevice *pdev) : QMacSavedFontInfo(), 
00191                                                                         QMacFontInfo() { setMacFont(d, this, pdev); }
00192     inline QMacSetFontInfo(const QFontEngine *fe, QPaintDevice *pdev) : QMacSavedFontInfo(), 
00193                                                                         QMacFontInfo() { setMacFont(fe, this, pdev); }
00194 
00195     //you can use these to cause font setting, without restoring old
00196     static bool setMacFont(const QMacFontInfo *f, QMacSetFontInfo *sfi=NULL);
00197     static bool setMacFont(const QFontPrivate *d, QMacSetFontInfo *sfi=NULL, QPaintDevice *pdev=NULL);
00198     static bool setMacFont(const QFontEngine *fe, QMacSetFontInfo *sfi=NULL, QPaintDevice *pdev=NULL);
00199 };
00200 
00201 
00202 #include "qptrlist.h"
00203 #include "qpaintdevice.h"
00204 extern QPaintDevice *qt_mac_safe_pdev; //qapplication_mac.cpp
00205 extern QPainter *qt_mac_current_painter; //qpainter_mac.cpp
00206 class QMacSavedPortInfo
00207 {
00208     RgnHandle clip;
00209     GWorldPtr world;
00210     GDHandle handle;
00211     PenState pen; //go pennstate
00212     RGBColor back, fore;
00213     QMacSavedFontInfo *fi;
00214     QPainter *painter;
00215     bool valid_gworld;
00216     void init();
00217     
00218 public:
00219     inline QMacSavedPortInfo() { init(); }
00220     inline QMacSavedPortInfo(QPaintDevice *pd) { init(); setPaintDevice(pd); }
00221     inline QMacSavedPortInfo(QWidget *w, bool set_clip=FALSE) { init(); setPaintDevice(w, set_clip); }
00222     inline QMacSavedPortInfo(QPaintDevice *pd, const QRect &r) 
00223         { init(); setPaintDevice(pd); setClipRegion(r); }
00224     inline QMacSavedPortInfo(QPaintDevice *pd, const QRegion &r) 
00225         { init(); setPaintDevice(pd); setClipRegion(r); }
00226     ~QMacSavedPortInfo();
00227     static bool setClipRegion(const QRect &r);
00228     static bool setClipRegion(const QRegion &r);
00229     static bool setPaintDevice(QPaintDevice *);
00230     static bool setPaintDevice(QWidget *, bool set_clip=FALSE, bool with_child=TRUE);
00231     static bool flush(QPaintDevice *);
00232     static bool flush(QPaintDevice *, QRegion r, bool force=FALSE);
00233     static void setWindowAlpha(QWidget *, float);
00234 };
00235 
00236 inline bool 
00237 QMacSavedPortInfo::flush(QPaintDevice *pdev) 
00238 {
00239 #ifdef Q_WS_MACX
00240     if(pdev->devType() == QInternal::Widget) {
00241         QWidget *w = (QWidget *)pdev;
00242         if(!w->isHidden() && QDIsPortBuffered(GetWindowPort((WindowPtr)w->handle()))) {
00243             QDFlushPortBuffer(GetWindowPort((WindowPtr)w->handle()), NULL);
00244             return TRUE;
00245         }
00246     } 
00247 #else
00248     Q_UNUSED(pdev);
00249 #endif
00250     return FALSE;
00251 }
00252 
00253 inline bool 
00254 QMacSavedPortInfo::flush(QPaintDevice *pdev, QRegion r, bool force) 
00255 {
00256 #ifdef Q_WS_MACX
00257     if(pdev->devType() == QInternal::Widget) {
00258         QWidget *w = (QWidget *)pdev;
00259         r.translate(w->topLevelWidget()->geometry().x(), w->topLevelWidget()->geometry().y());
00260         if(!w->isHidden() || QDIsPortBuffered(GetWindowPort((WindowPtr)w->handle()))) {
00261             QDFlushPortBuffer(GetWindowPort((WindowPtr)w->handle()), r.handle(force));
00262             return TRUE;
00263         }
00264     } 
00265 #else
00266     Q_UNUSED(pdev);
00267     Q_UNUSED(r);
00268     Q_UNUSED(force);
00269 #endif
00270     return FALSE;
00271 }
00272 
00273 #ifdef Q_WS_MACX
00274 extern "C" {
00275     typedef struct CGSConnection *CGSConnectionRef;
00276     typedef struct CGSWindow *CGSWindowRef;
00277     extern OSStatus CGSSetWindowAlpha(CGSConnectionRef, CGSWindowRef, float);
00278     extern CGSWindowRef GetNativeWindowFromWindowRef(WindowRef);
00279     extern CGSConnectionRef _CGSDefaultConnection();
00280 }
00281 #endif
00282 inline void 
00283 QMacSavedPortInfo::setWindowAlpha(QWidget *w, float l)
00284 {
00285 #ifdef Q_WS_MACX
00286     CGSSetWindowAlpha(_CGSDefaultConnection(), 
00287                       GetNativeWindowFromWindowRef((WindowRef)w->handle()), l);
00288 #else
00289     Q_UNUSED(w);
00290     Q_UNUSED(l);
00291 #endif
00292 }
00293 
00294 inline bool 
00295 QMacSavedPortInfo::setClipRegion(const QRect &rect)
00296 {
00297     Rect r;
00298     SetRect(&r, rect.x(), rect.y(), rect.right()+1, rect.bottom()+1);
00299 #if defined(QT_THREAD_SUPPORT)
00300     if(qt_mac_port_mutex)
00301         qt_mac_port_mutex->lock();
00302 #endif
00303     qt_mac_current_painter = NULL;
00304     ClipRect(&r);
00305 #if defined(QT_THREAD_SUPPORT)
00306     if(qt_mac_port_mutex)
00307         qt_mac_port_mutex->unlock();
00308 #endif
00309     return TRUE;
00310 }
00311 
00312 inline bool 
00313 QMacSavedPortInfo::setClipRegion(const QRegion &r)
00314 {
00315     if(r.isNull())
00316         return setClipRegion(QRect());
00317     else if(!r.handle())
00318         return setClipRegion(r.boundingRect());
00319 #if defined(QT_THREAD_SUPPORT)
00320     if(qt_mac_port_mutex)
00321         qt_mac_port_mutex->lock();
00322 #endif
00323     qt_mac_current_painter = NULL;
00324     SetClip(r.handle());
00325 #if defined(QT_THREAD_SUPPORT)
00326     if(qt_mac_port_mutex)
00327         qt_mac_port_mutex->unlock();
00328 #endif
00329     return TRUE;
00330 }
00331 
00332 inline bool
00333 QMacSavedPortInfo::setPaintDevice(QWidget *w, bool set_clip, bool with_child) 
00334 {
00335     if(!w)
00336         return FALSE;
00337     if(!setPaintDevice((QPaintDevice *)w))
00338         return FALSE;
00339     if(set_clip) 
00340         return setClipRegion(w->clippedRegion(with_child));
00341     return TRUE;
00342 }
00343 
00344 inline bool
00345 QMacSavedPortInfo::setPaintDevice(QPaintDevice *pd)
00346 {
00347     if(!pd)
00348         return FALSE;
00349 #if 0
00350     if(qt_mac_current_painter && qt_mac_current_painter->handle() == pd->handle())
00351         return TRUE;
00352 #endif
00353     bool ret = TRUE;
00354 #if defined(QT_THREAD_SUPPORT)
00355     if(qt_mac_port_mutex)
00356         qt_mac_port_mutex->lock();
00357 #endif
00358 //    if(qt_mac_current_painter && qt_mac_current_painter->handle() != pd->handle())
00359         qt_mac_current_painter = NULL;
00360     if(pd->devType() == QInternal::Widget)
00361         SetPortWindowPort((WindowPtr)pd->handle());
00362     else if(pd->devType() == QInternal::Pixmap || pd->devType() == QInternal::Printer)
00363         SetGWorld((GrafPtr)pd->handle(), 0); //set the gworld
00364     else
00365         ret = FALSE;
00366 #if defined(QT_THREAD_SUPPORT)
00367     if(qt_mac_port_mutex)
00368         qt_mac_port_mutex->unlock();
00369 #endif
00370     return ret;
00371 }
00372     
00373 
00374 inline void 
00375 QMacSavedPortInfo::init()
00376 {
00377 #if defined(QT_THREAD_SUPPORT)
00378     if(qt_mac_port_mutex)
00379         qt_mac_port_mutex->lock();
00380 #endif
00381     fi = NULL;
00382     painter = qt_mac_current_painter;
00383     if(mac_window_count) {
00384         GetBackColor(&back);
00385         GetForeColor(&fore);
00386         GetGWorld(&world, &handle);
00387         valid_gworld = TRUE;
00388         fi = new QMacSavedFontInfo(world);
00389         clip = NewRgn();
00390         GetClip(clip);
00391         GetPenState(&pen);
00392     }
00393 }
00394 
00395 inline QMacSavedPortInfo::~QMacSavedPortInfo()
00396 {
00397     if(mac_window_count) {
00398         bool set_state = false;
00399         if(valid_gworld) {
00400             set_state = IsValidPort(world);
00401             if(set_state)
00402                 SetGWorld(world,handle); //always do this one first
00403         } else {
00404             setPaintDevice(qt_mac_safe_pdev);
00405         }
00406         if(set_state) {
00407             SetClip(clip);
00408             SetPenState(&pen);
00409             RGBForeColor(&fore);
00410             RGBBackColor(&back);
00411         }
00412         DisposeRgn(clip);
00413     }
00414     if(fi)
00415         delete fi;
00416     qt_mac_current_painter = painter;
00417 #if defined(QT_THREAD_SUPPORT)
00418     if(qt_mac_port_mutex)
00419         qt_mac_port_mutex->unlock();
00420 #endif
00421 }
00422 
00423 #endif //Q_WS_MAC
00424 #endif // QT_MAC_H
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'