Back to index

plt-scheme  4.2.1
MemoryDC.cc
Go to the documentation of this file.
00001 /*                                                      -*- C++ -*-
00002  *
00003  * Purpose: device context to draw into wxBitmaps
00004  *
00005  * Authors: Markus Holzem and Julian Smart
00006  *
00007  * Copyright: (C) 2004-2009 PLT Scheme Inc.
00008  * Copyright: (C) 1995, AIAI, University of Edinburgh (Julian)
00009  * Copyright: (C) 1995, GNU (Markus)
00010  *
00011  * This program is free software; you can redistribute it and/or modify
00012  * it under the terms of the GNU General Public License as published by
00013  * the Free Software Foundation; either version 2 of the License, or
00014  * (at your option) any later version.
00015  *
00016  * This program is distributed in the hope that it will be useful,
00017  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  * GNU General Public License for more details.
00020  *
00021  * You should have received a copy of the GNU General Public License
00022  * along with this program; if not, write to the Free Software
00023  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00024  * 02110-1301 USA.
00025  */
00026 
00027 #ifdef __GNUG__
00028 #pragma implementation "MemoryDC.h"
00029 #endif
00030 
00031 #define  Uses_XLib
00032 #define  Uses_wxBitmap
00033 #define  Uses_wxMemoryDC
00034 #include "wx.h"
00035 
00036 wxMemoryDC::wxMemoryDC(Bool ro) : wxCanvasDC()
00037 {
00038     __type = wxTYPE_DC_MEMORY;
00039 
00040     device = wxDEVICE_MEMORY;
00041 
00042     read_only = ro;
00043 
00044     // the memory DC is at construction a unusable class because
00045     // there is no drawable. The initialization will be done with
00046     // wxMemoryDC::SelectObject(wxBitmap *bitmap)
00047 }
00048 
00049 wxMemoryDC::~wxMemoryDC(void)
00050 {
00051   if (selected) {
00052     selected->selectedIntoDC = 0;
00053     selected->selectedTo = NULL;
00054     selected = NULL;
00055   }
00056 
00057 #ifdef WX_USE_XRENDER
00058   X->picture = 0;
00059 #endif
00060 }
00061 
00062 void wxMemoryDC::SelectObject(wxBitmap *bitmap)
00063 {
00064   if (bitmap == selected)
00065     return;
00066 
00067   EndSetPixel();
00068 
00069   /* Skip wxMemoryDC, because the bitmap's cache is fine. */
00070   wxWindowDC::FreeGetPixelCache(); 
00071 #ifdef WX_USE_CAIRO
00072   ReleaseCairoDev();
00073 #endif
00074 
00075   if (!read_only) {
00076     /* Bitmap selection memory and safety */
00077     if (bitmap && bitmap->selectedIntoDC)
00078       bitmap = NULL;
00079 
00080     if (selected) {
00081       selected->selectedIntoDC = 0;
00082       selected->selectedTo = NULL;
00083 #ifdef USE_GL
00084       if (X->wx_gl) {
00085        X->gl_cfg = NULL;
00086        X->wx_gl->Reset(NULL, 0, 0);
00087       }
00088 #endif      
00089     }
00090   } else if (bitmap && bitmap->selectedTo) {
00091     bitmap->selectedTo->FreeGetPixelCache();
00092 #ifdef WX_USE_CAIRO
00093     bitmap->selectedTo->ReleaseCairoDev();
00094 #endif
00095   }
00096 
00097   // free all associated GCs
00098 #ifdef WX_USE_XRENDER
00099   X->picture = 0;
00100 #endif
00101   Destroy();
00102   
00103   if (bitmap && bitmap->Ok()) {
00104     // The bitmap must use the display and screen of the application.
00105     // The drawable is the associated pixmap, width, height and depth
00106     // will be queried with XGetGeometry.
00107     wxWindowDC_Xinit *init;
00108     Pixmap pm;
00109     init = new wxWindowDC_Xinit;
00110     init->dpy      = wxAPP_DISPLAY;
00111     init->scn      = wxAPP_SCREEN;
00112     pm = GETPIXMAP(bitmap);
00113     init->drawable = pm;
00114     Initialize(init);
00115 #ifdef USE_GL
00116     if (X->wx_gl) {
00117       int depth;
00118       depth = bitmap->GetDepth();
00119       X->gl_cfg = bitmap->gl_cfg;
00120       X->wx_gl->Reset(bitmap->gl_cfg, (depth == 1) ? 0 : (long)pm, 1);
00121     }
00122 #endif
00123     // If another colourmap is associated with the bitmap,
00124     //  use it instead of the current colourmap.
00125     if (bitmap->GetColourMap() != current_cmap) {
00126       wxColourMap *cm;
00127       cm = bitmap->GetColourMap();
00128       SetColourMap(cm);
00129     }
00130     selected = bitmap;
00131     if (!read_only) {
00132       bitmap->selectedIntoDC = -1;
00133       selected->selectedTo = this;
00134     }
00135   } else {
00136     DRAWABLE = 0;
00137     WIDTH = HEIGHT = 0;
00138     selected = NULL;
00139   }
00140 }
00141 
00142 #ifdef WX_USE_XRENDER
00143 void wxMemoryDC::InitPicture()
00144 {
00145   long p;
00146   p = selected->GetPicture();
00147   X->picture = p;
00148   if (!read_only)
00149     InitPictureClip();
00150 }
00151 #endif
00152 
00153 wxBitmap *wxMemoryDC::GetObject()
00154 {
00155   return selected;
00156 }
00157 
00158 void wxMemoryDC::GetSize(double *w, double *h)
00159 {
00160   if (selected) {
00161     double v;
00162     v = selected->GetWidth();
00163     *w = v;
00164     v = selected->GetHeight();
00165     *h = v;
00166   } else {
00167     *w = 0;
00168     *h = 0;
00169   }
00170 }
00171 
00172 void wxMemoryDC::FreeGetPixelCache()
00173 {
00174   if (selected)
00175     selected->FreeMaskBit();
00176   wxWindowDC::FreeGetPixelCache();
00177 }