]> granicus.if.org Git - python/commitdiff
New internal function BMObj_NewCopied() which copies the BitMap. Used to get the...
authorJack Jansen <jack.jansen@cwi.nl>
Tue, 30 Jan 2001 09:57:13 +0000 (09:57 +0000)
committerJack Jansen <jack.jansen@cwi.nl>
Tue, 30 Jan 2001 09:57:13 +0000 (09:57 +0000)
Mac/Modules/qd/Qdmodule.c
Mac/Modules/qd/qdsupport.py

index 7c9d49bcd2d81ccb9a12f0e70159ea822ed6f66a..34476d4d69c6310f43533d99824bf777c25453ac 100644 (file)
@@ -11,7 +11,7 @@
 #include <QuickDraw.h>
 
 #if !ACCESSOR_CALLS_ARE_FUNCTIONS
-#define GetPortBitMapForCopyBits(port) (((GrafPort)(port))->portBits)
+#define GetPortBitMapForCopyBits(port) ((const struct BitMap *)&((GrafPort *)(port))->portBits)
 #define GetPortPixMap(port) (((CGrafPtr)(port))->portPixMap)
 #define GetPortBounds(port, bounds) (*(bounds) = (port)->portRect, (bounds))
 #define GetPortForeColor(port, color) (*(color) = (port)->rgbFgColor, (color))
@@ -79,6 +79,8 @@
 #define QDIsPortBuffered(port) 0
 #endif /* !TARGET_API_MAC_CARBON  */
 
+staticforward PyObject *BMObj_NewCopied(BitMapPtr);
+
 /*
 ** Parse/generate RGB records
 */
@@ -115,8 +117,6 @@ PyObject *QdFI_New(itself)
                        itself->widMax, itself->leading);
 }
 
-
-
 static PyObject *Qd_Error;
 
 /* ---------------------- Object type GrafPort ---------------------- */
@@ -584,7 +584,7 @@ static PyObject *QDGA_getattr(self, name)
                if ( strcmp(name, "screenBits") == 0 ) {
                        BitMap rv;
                        GetQDGlobalsScreenBits(&rv);
-                       return BMObj_New(&rv);
+                       return BMObj_NewCopied(&rv);
                }
                if ( strcmp(name, "thePort") == 0 ) 
                        return GrafObj_New(GetQDGlobalsThePort());
@@ -4521,7 +4521,7 @@ static PyObject *Qd_GetQDGlobalsScreenBits(_self, _args)
                return NULL;
        GetQDGlobalsScreenBits(&screenBits);
        _res = Py_BuildValue("O&",
-                            BMObj_New, &screenBits);
+                            BMObj_NewCopied, &screenBits);
        return _res;
 }
 
@@ -6162,6 +6162,24 @@ static PyMethodDef Qd_methods[] = {
 
 
 
+/* Like BMObj_New, but the original bitmap data structure is copied (and
+** released when the object is released)
+*/
+PyObject *BMObj_NewCopied(itself)
+       BitMapPtr itself;
+{
+       BitMapObject *it;
+       BitMapPtr itself_copy;
+       
+       if ((itself_copy=(BitMapPtr)malloc(sizeof(BitMap))) == NULL)
+               return PyErr_NoMemory();
+       *itself_copy = *itself;
+       it = (BitMapObject *)BMObj_New(itself_copy);
+       it->referred_bitmap = itself_copy;
+       return (PyObject *)it;
+}
+
+
 
 void initQd()
 {
index b255110d4d8abb5ab74bca7518e03a0aa926a846..f57cf17ecd20e31d1407ac6dcc2df653692b28e5 100644 (file)
@@ -46,7 +46,7 @@ CGrafPtr = OpaqueByValueType("CGrafPtr", "GrafObj")
 GrafPtr = OpaqueByValueType("GrafPtr", "GrafObj")
 BitMap_ptr = OpaqueByValueType("BitMapPtr", "BMObj")
 const_BitMap_ptr = OpaqueByValueType("const BitMap *", "BMObj")
-BitMap = OpaqueType("BitMap", "BMObj")
+BitMap = OpaqueType("BitMap", "BMObj_NewCopied", "BUG")
 RGBColor = OpaqueType('RGBColor', 'QdRGB')
 RGBColor_ptr = RGBColor
 FontInfo = OpaqueType('FontInfo', 'QdFI')
@@ -64,7 +64,7 @@ includestuff = includestuff + """
 #include <%s>""" % MACHEADERFILE + """
 
 #if !ACCESSOR_CALLS_ARE_FUNCTIONS
-#define GetPortBitMapForCopyBits(port) (((GrafPort)(port))->portBits)
+#define GetPortBitMapForCopyBits(port) ((const struct BitMap *)&((GrafPort *)(port))->portBits)
 #define GetPortPixMap(port) (((CGrafPtr)(port))->portPixMap)
 #define GetPortBounds(port, bounds) (*(bounds) = (port)->portRect, (bounds))
 #define GetPortForeColor(port, color) (*(color) = (port)->rgbFgColor, (color))
@@ -132,6 +132,8 @@ includestuff = includestuff + """
 #define QDIsPortBuffered(port) 0
 #endif /* !TARGET_API_MAC_CARBON  */
 
+staticforward PyObject *BMObj_NewCopied(BitMapPtr);
+
 /*
 ** Parse/generate RGB records
 */
@@ -167,7 +169,25 @@ PyObject *QdFI_New(itself)
        return Py_BuildValue("hhhh", itself->ascent, itself->descent,
                        itself->widMax, itself->leading);
 }
+"""
 
+finalstuff = finalstuff + """
+/* Like BMObj_New, but the original bitmap data structure is copied (and
+** released when the object is released)
+*/
+PyObject *BMObj_NewCopied(itself)
+       BitMapPtr itself;
+{
+       BitMapObject *it;
+       BitMapPtr itself_copy;
+       
+       if ((itself_copy=(BitMapPtr)malloc(sizeof(BitMap))) == NULL)
+               return PyErr_NoMemory();
+       *itself_copy = *itself;
+       it = (BitMapObject *)BMObj_New(itself_copy);
+       it->referred_bitmap = itself_copy;
+       return (PyObject *)it;
+}
 
 """
 
@@ -458,7 +478,7 @@ class QDGlobalsAccessObjectDefinition(ObjectDefinition):
        if ( strcmp(name, "screenBits") == 0 ) {
                BitMap rv;
                GetQDGlobalsScreenBits(&rv);
-               return BMObj_New(&rv);
+               return BMObj_NewCopied(&rv);
        }
        if ( strcmp(name, "thePort") == 0 ) 
                return GrafObj_New(GetQDGlobalsThePort());