home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / include / qpixmap.h < prev    next >
C/C++ Source or Header  |  2001-10-11  |  9KB  |  323 lines

  1. /****************************************************************************
  2. ** $Id:  qt/qpixmap.h   3.0.0   edited Sep 19 10:59 $
  3. **
  4. ** Definition of QPixmap class
  5. **
  6. ** Created : 940501
  7. **
  8. ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
  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. #ifndef QPIXMAP_H
  39. #define QPIXMAP_H
  40.  
  41. #ifndef QT_H
  42. #include "qpaintdevice.h"
  43. #include "qcolor.h" // char*->QColor conversion
  44. #include "qstring.h" // char*->QString conversion
  45. #include "qnamespace.h"
  46. #endif // QT_H
  47.  
  48. class QGfx;
  49. class QPixmapPrivate;
  50.  
  51. #if defined(Q_WS_WIN)
  52. // Internal pixmap memory optimization class for Windows 9x
  53. class QMultiCellPixmap;
  54. #endif
  55.  
  56.  
  57. class Q_EXPORT QPixmap : public QPaintDevice, public Qt
  58. {
  59. public:
  60.     enum ColorMode { Auto, Color, Mono };
  61.     enum Optimization { DefaultOptim, NoOptim, MemoryOptim=NoOptim,
  62.             NormalOptim, BestOptim };
  63.  
  64.     QPixmap();
  65.     QPixmap( const QImage& image );
  66.     QPixmap( int w, int h,  int depth = -1, Optimization = DefaultOptim );
  67.     QPixmap( const QSize &, int depth = -1, Optimization = DefaultOptim );
  68. #ifndef QT_NO_IMAGEIO
  69.     QPixmap( const QString& fileName, const char *format=0,
  70.          ColorMode mode=Auto );
  71.     QPixmap( const QString& fileName, const char *format,
  72.          int conversion_flags );
  73.     QPixmap( const char *xpm[] );
  74.     QPixmap( const QByteArray &data );
  75. #endif
  76.     QPixmap( const QPixmap & );
  77.    ~QPixmap();
  78.  
  79.     QPixmap    &operator=( const QPixmap & );
  80.     QPixmap    &operator=( const QImage     & );
  81.  
  82.     bool    isNull()    const;
  83.  
  84.     int        width()        const { return data->w; }
  85.     int        height()    const { return data->h; }
  86.     QSize    size()        const { return QSize(data->w,data->h); }
  87.     QRect    rect()        const { return QRect(0,0,data->w,data->h); }
  88.     int        depth()        const { return data->d; }
  89.     static int    defaultDepth();
  90.  
  91.     void    fill( const QColor &fillColor = Qt::white );
  92.     void    fill( const QWidget *, int xofs, int yofs );
  93.     void    fill( const QWidget *, const QPoint &ofs );
  94.     void    resize( int width, int height );
  95.     void    resize( const QSize & );
  96.  
  97.     const QBitmap *mask() const;
  98.     void    setMask( const QBitmap & );
  99.     bool    selfMask() const;
  100. #ifndef QT_NO_IMAGE_HEURISTIC_MASK
  101.     QBitmap    createHeuristicMask( bool clipTight = TRUE ) const;
  102. #endif
  103.     static  QPixmap grabWindow( WId, int x=0, int y=0, int w=-1, int h=-1 );
  104.     static  QPixmap grabWidget( QWidget * widget,
  105.                 int x=0, int y=0, int w=-1, int h=-1 );
  106.  
  107. #ifndef QT_NO_PIXMAP_TRANSFORMATION
  108.     QPixmap        xForm( const QWMatrix & ) const;
  109.     static QWMatrix trueMatrix( const QWMatrix &, int w, int h );
  110. #endif
  111.  
  112.     QImage    convertToImage() const;
  113.     bool    convertFromImage( const QImage &, ColorMode mode=Auto );
  114.     bool    convertFromImage( const QImage &, int conversion_flags );
  115. #ifndef QT_NO_IMAGEIO
  116.     static const char* imageFormat( const QString &fileName );
  117.     bool    load( const QString& fileName, const char *format=0,
  118.               ColorMode mode=Auto );
  119.     bool    load( const QString& fileName, const char *format,
  120.               int conversion_flags );
  121.     bool    loadFromData( const uchar *buf, uint len,
  122.                   const char* format=0,
  123.                   ColorMode mode=Auto );
  124.     bool    loadFromData( const uchar *buf, uint len,
  125.                   const char* format,
  126.                   int conversion_flags );
  127.     bool    loadFromData( const QByteArray &data,
  128.                   const char* format=0,
  129.                   int conversion_flags=0 );
  130.     bool    save( const QString& fileName, const char* format, int quality = -1 ) const;
  131. #endif
  132.  
  133. #if defined(Q_WS_WIN)
  134.     HBITMAP    hbm()        const;
  135. #endif
  136.  
  137.     int        serialNumber()    const;
  138.  
  139.     Optimization    optimization() const;
  140.     void        setOptimization( Optimization );
  141.     static Optimization defaultOptimization();
  142.     static void        setDefaultOptimization( Optimization );
  143.  
  144.     virtual void detach();
  145.  
  146.     bool    isQBitmap() const;
  147.  
  148. #if defined(Q_WS_WIN)
  149.     // These functions are internal and used by Windows 9x only
  150.     bool    isMultiCellPixmap() const;
  151.     HDC        multiCellHandle() const;
  152.     HBITMAP    multiCellBitmap() const;
  153.     int        multiCellOffset() const;
  154.     int        allocCell();
  155.     void    freeCell( bool = FALSE );
  156. #endif
  157.  
  158. #if defined(Q_WS_QWS)
  159.     virtual QGfx * graphicsContext(bool clip_children=TRUE) const;
  160.     virtual unsigned char * scanLine(int) const;
  161.     virtual int bytesPerLine() const;
  162.     QRgb * clut() const;
  163.     int numCols() const;
  164. #elif defined(Q_WS_X11)
  165.     static int x11SetDefaultScreen( int screen );
  166.     void x11SetScreen( int screen );
  167. #endif
  168.  
  169. #if defined(Q_FULL_TEMPLATE_INSTANTIATION)
  170.     bool operator==( const QPixmap& ) const { return FALSE; }
  171. #endif
  172.  
  173. protected:
  174.     QPixmap( int w, int h, const uchar *data, bool isXbitmap );
  175.     int metric( int ) const;
  176.  
  177. #if defined(Q_WS_WIN)
  178.     struct QMCPI {                // mem optim for win9x
  179.     QMultiCellPixmap *mcp;
  180.     int    offset;
  181.     };
  182. #endif
  183.  
  184.     struct QPixmapData : public QShared {    // internal pixmap data
  185.     QCOORD    w, h;
  186.     short    d;
  187.     uint    uninit     : 1;
  188.     uint    bitmap     : 1;
  189.     uint    selfmask : 1;
  190. #if defined(Q_WS_WIN)
  191.     uint    mcp     : 1;
  192. #endif
  193.     int    ser_no;
  194.     QBitmap *mask;
  195. #if defined(Q_WS_WIN)
  196.     void   *bits;
  197.     QPixmap *maskpm;
  198.     union {
  199.         HBITMAP hbm;    // if mcp == FALSE
  200.         QMCPI  *mcpi;   // if mcp == TRUE
  201.     } hbm_or_mcpi;
  202.     bool hasRealAlpha;
  203. #elif defined(Q_WS_X11)
  204.     void   *ximage;
  205.     void   *maskgc;
  206.     QPixmap *alphapm;
  207. #elif defined(Q_WS_MAC)
  208.     ColorTable *clut;
  209. #elif defined(Q_WS_QWS)
  210.     int id; // ### should use QPaintDevice::hd, since it is there
  211.     QRgb * clut;
  212.     int numcols;
  213.     int rw;
  214.     int rh;
  215.     bool hasAlpha;
  216. #endif
  217.     Optimization optim;
  218.     } *data;
  219. private:
  220.     QPixmap( int w, int h, int depth, bool, Optimization );
  221.     void    init( int, int, int, bool, Optimization );
  222.     void    deref();
  223.     QPixmap    copy( bool ignoreMask = FALSE ) const;
  224.     static Optimization defOptim;
  225.     friend Q_EXPORT void bitBlt( QPaintDevice *, int, int,
  226.                  const QPaintDevice *,
  227.                  int, int, int, int, RasterOp, bool );
  228.     friend Q_EXPORT void bitBlt( QPaintDevice *, int, int,
  229.                  const QImage* src,
  230.                  int, int, int, int, int conversion_flags );
  231.  
  232. #if defined(Q_WS_X11) && !defined(QT_NO_XRENDER)
  233.     friend void qt_x11_copy_alpha_pixmap(QPixmap *dst, const QPixmap *src);
  234.     friend void qt_x11_blit_alpha_pixmap(QPixmap *dst, int dx, int dy,
  235.                      const QPixmap *src, int sx = 0, int sy = 0,
  236.                      int sw = -1, int sh = -1);
  237. #endif
  238.  
  239.     friend class QBitmap;
  240.     friend class QPaintDevice;
  241.     friend class QPainter;
  242. };
  243.  
  244.  
  245. inline bool QPixmap::isNull() const
  246. {
  247.     return data->w == 0;
  248. }
  249.  
  250. inline void QPixmap::fill( const QWidget *w, const QPoint &ofs )
  251. {
  252.     fill( w, ofs.x(), ofs.y() );
  253. }
  254.  
  255. inline void QPixmap::resize( const QSize &s )
  256. {
  257.     resize( s.width(), s.height() );
  258. }
  259.  
  260. inline const QBitmap *QPixmap::mask() const
  261. {
  262.     return data->mask;
  263. }
  264.  
  265. inline bool QPixmap::selfMask() const
  266. {
  267.     return data->selfmask;
  268. }
  269.  
  270. #if defined(Q_WS_WIN)
  271. inline HBITMAP QPixmap::hbm() const
  272. {
  273.     return data->mcp ? 0 : data->hbm_or_mcpi.hbm;
  274. }
  275. #endif
  276.  
  277. inline int QPixmap::serialNumber() const
  278. {
  279.     return data->ser_no;
  280. }
  281.  
  282. inline QPixmap::Optimization QPixmap::optimization() const
  283. {
  284.     return data->optim;
  285. }
  286.  
  287. inline bool QPixmap::isQBitmap() const
  288. {
  289.     return data->bitmap;
  290. }
  291.  
  292. #if defined(Q_WS_WIN)
  293. inline bool QPixmap::isMultiCellPixmap() const
  294. {
  295.     return data->mcp;
  296. }
  297. #endif
  298.  
  299.  
  300. /*****************************************************************************
  301.   QPixmap stream functions
  302.  *****************************************************************************/
  303.  
  304. #if !defined(QT_NO_DATASTREAM) && !defined(QT_NO_IMAGEIO)
  305. Q_EXPORT QDataStream &operator<<( QDataStream &, const QPixmap & );
  306. Q_EXPORT QDataStream &operator>>( QDataStream &, QPixmap & );
  307. #endif
  308.  
  309. /*****************************************************************************
  310.   QPixmap (and QImage) helper functions
  311.  *****************************************************************************/
  312.  
  313. #ifndef QT_NO_PIXMAP_TRANSFORMATION
  314. #  define QT_XFORM_TYPE_MSBFIRST 0
  315. #  define QT_XFORM_TYPE_LSBFIRST 1
  316. #  if defined(Q_WS_WIN)
  317. #    define QT_XFORM_TYPE_WINDOWSPIXMAP 2
  318. #  endif
  319. bool qt_xForm_helper( const QWMatrix&, int, int, int, uchar*, int, int, int, uchar*, int, int, int );
  320. #endif
  321.  
  322. #endif // QPIXMAP_H
  323.