]> git.saurik.com Git - wxWidgets.git/commitdiff
More tweaks to wxMicroWi
authorJulian Smart <julian@anthemion.co.uk>
Sat, 22 Dec 2001 19:43:44 +0000 (19:43 +0000)
committerJulian Smart <julian@anthemion.co.uk>
Sat, 22 Dec 2001 19:43:44 +0000 (19:43 +0000)
More tweaks to MicroWindows

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@13161 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

12 files changed:
distrib/msw/jpeg.rsp
distrib/msw/tiff.rsp
docs/microwin/readme.txt
include/wx/msw/microwin.h
samples/widgets/makefile.mic
src/msw/bitmap.cpp
src/msw/dc.cpp
src/msw/microwin.c
src/msw/window.cpp
src/univ/checkbox.cpp
src/univ/notebook.cpp
src/univ/themes/win32.cpp

index c3f84fcbc52596241e5a7a326ae27103c1001caf..7095a60175fcef0ea5197772cf58636ae4840775 100644 (file)
@@ -1,6 +1,6 @@
 src/jpeg/make*
-src/jpeg/JpegVC.dsp
-src/jpeg/JpegVC.dsw
+src/jpeg/jpeg.dsp
+src/jpeg/jpeg.dsw
 src/jpeg/*.c
 src/jpeg/*.h
 src/jpeg/README
index cba0610eb3824d8f7abdfc750640e226b3d5737f..5fb9219b644f335d47f0f16148365fb9a2505324 100644 (file)
@@ -1,6 +1,6 @@
 src/tiff/make*
-src/tiff/TiffVC.dsp
-src/tiff/TiffVC.dsw
+src/tiff/tiff.dsp
+src/tiff/tiff.dsw
 src/tiff/*.c
 src/tiff/*.h
 src/tiff/README
index 980f125efe93700598b860a6814f56efd0720034..e916ced79455097180c49bebf18ac1632bd7b65f 100644 (file)
@@ -108,6 +108,33 @@ is preferably to proliferating many #ifdefs in the
 wxMSW/wxMicroWindows port itself.
 
 
+Errors/warnings
+===============
+
+In file ../../src/msw/window.cpp at line 1294: 'UpdateWindow' failed with error 0x00000000 (Success).
+
+  - caused because there are no paint messages pending. Presumed
+    harmless.
+
+In file ../../src/msw/dc.cpp at line 1838: 'BitBlt' failed with error 0x00000000 (Success).
+
+  - caused because the window isn't mapped, and MwPrepareDC in wingdi.c
+    fails (hwnd->unmapcount is non-zero). Presumed harmless.
+
+Recursive paint problem, e.g. when clicking the 'Press Me!'
+button in the widgets sample a few times, until the text control
+is full.
+
+  - possibly the scrollbar is causing the text control to be
+    updated, which somehow effects the scrollbar, which causes
+    a window update, etc.
+
+Sluggish updates.
+
+  - probably because many image to bitmap conversions are being
+    done on update, and bitmaps should probably be cached.
+
+
 Things missing from MicroWindows that need to be worked around
 ==============================================================
 
@@ -136,13 +163,11 @@ So how can we convert from wxImage to wxBitmap in MicroWindows?
 Well, a simple-minded way would be to use CreateCompatibleBitmap
 which returns an HBITMAP, select it into an HDC, and draw
 the pixels from the wxImage to the HDC one by one with SetPixel.
-This is now implemented, but without any mask handling, which will
-be needed.
-
-Unfortunately, there's a crash in malloc, within DeleteObject, when
-passed a bitmap created by CreateCompatibleBitmap, but only after a few
-deletions. This has yet to be tracked down, maybe by trying to create/delete
-some wxBitmaps from XPMs, from within e.g. the minimal sample.
+This is now implemented, but there are problems with masks.
+(a) masks have to be created at screen depth because BitBlt/GrDraw
+can't cope with differing depths, and (b) masked blitting
+is still not working (try enabling mask creation in
+wxBitmap::CreateFromImage by setting USE_MASKS to 1).
 
 
 Other missing features
index 2ea902ceb67d87cc3810edc55e5ed6b3e8cc95d6..6f9098c434bd11afec3157d24c7b518cb3b8bbfa 100644 (file)
@@ -77,6 +77,8 @@ BOOL  SetScrollInfo (HWND hWnd, int iSBar,
                     LPCSCROLLINFO lpsi, BOOL fRedraw);
 BOOL  GetScrollInfo(HWND hWnd, int iSBar, LPSCROLLINFO lpsi);
 BOOL  ShowScrollBar (HWND hWnd, int iSBar, BOOL bShow);
+HBITMAP WINAPI
+CreateBitmap( int width, int height, int nPlanes, int bPP, LPCVOID lpData);
 
 #ifdef __cplusplus
 }
index 75dd78c8e8e671d94b401caa7f935e87e82ed9e4..5b46e72410e26fd95ceb9cf5a108a85e8108da24 100644 (file)
@@ -50,7 +50,7 @@ LIBNAME =
 include $(TOP)/Makefile.rules
 
 # List of objects to compile
-OBJS = widgets.o button.o # combobox.o gauge.o listbox.o notebook.o radiobox.o # slider.o spinbtn.o \
+OBJS = widgets.o button.o combobox.o gauge.o listbox.o notebook.o radiobox.o slider.o spinbtn.o \
  static.o textctrl.o 
 
 all: widgets
index 97a886aff941f534ec241e9c356c091236b652ad..5e6f88a634d25a8b5616076141fcc2e4f704bffb 100644 (file)
@@ -40,6 +40,8 @@
     #include "wx/icon.h"
 #endif
 
+//#include "device.h"
+
 #include "wx/msw/private.h"
 #include "wx/log.h"
 
@@ -89,10 +91,12 @@ void wxBitmapRefData::Free()
     if ( m_hBitmap)
     {
        //      printf("About to delete bitmap %d\n", (int) (HBITMAP) m_hBitmap);
+#if 1
         if ( !::DeleteObject((HBITMAP)m_hBitmap) )
         {
             wxLogLastError(wxT("DeleteObject(hbitmap)"));
         }
+#endif
     }
 
     delete m_bitmapMask;
@@ -381,17 +385,29 @@ bool wxBitmap::Create(int w, int h, int d)
 bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
 {
 #ifdef __WXMICROWIN__
+
+  // Set this to 1 to experiment with mask code,
+  // which currently doesn't work
+#define USE_MASKS 0
+
     m_refData = new wxBitmapRefData();
 
     // Initial attempt at a simple-minded implementation.
     // The bitmap will always be created at the screen depth,
     // so the 'depth' argument is ignored.
-    // TODO: transparency (create a mask image)
     
     HDC hScreenDC = ::GetDC(NULL);
+    //    printf("Screen planes = %d, bpp = %d\n", hScreenDC->psd->planes, hScreenDC->psd->bpp);
     int screenDepth = ::GetDeviceCaps(hScreenDC, BITSPIXEL);
 
     HBITMAP hBitmap = ::CreateCompatibleBitmap(hScreenDC, image.GetWidth(), image.GetHeight());
+    HBITMAP hMaskBitmap = NULL;
+    HBITMAP hOldMaskBitmap = NULL;
+    HDC hMaskDC = NULL;
+    unsigned char maskR = 0;
+    unsigned char maskG = 0;
+    unsigned char maskB = 0;
+
     //    printf("Created bitmap %d\n", (int) hBitmap);
     if (hBitmap == NULL)
     {
@@ -399,9 +415,43 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
        return FALSE;
     }
     HDC hMemDC = ::CreateCompatibleDC(hScreenDC);
-    ::ReleaseDC(NULL, hScreenDC);
 
     HBITMAP hOldBitmap = ::SelectObject(hMemDC, hBitmap);
+    ::ReleaseDC(NULL, hScreenDC);
+
+    // created an mono-bitmap for the possible mask
+    bool hasMask = image.HasMask();
+
+    if ( hasMask )
+    {
+#if USE_MASKS
+        // FIXME: we should be able to pass bpp = 1, but
+        // GdBlit can't handle a different depth
+#if 0
+        hMaskBitmap = ::CreateBitmap( (WORD)image.GetWidth(), (WORD)image.GetHeight(), 1, 1, NULL );
+#else
+        hMaskBitmap = ::CreateCompatibleBitmap( hMemDC, (WORD)image.GetWidth(), (WORD)image.GetHeight());
+#endif
+        maskR = image.GetMaskRed();
+        maskG = image.GetMaskGreen();
+        maskB = image.GetMaskBlue();
+
+        if (!hMaskBitmap)
+        {
+            hasMask = FALSE;
+       }
+        else
+        {
+            hScreenDC = ::GetDC(NULL);
+            hMaskDC = ::CreateCompatibleDC(hScreenDC);
+           ::ReleaseDC(NULL, hScreenDC);
+
+            hOldMaskBitmap = ::SelectObject( hMaskDC, hMaskBitmap);
+       }
+#else
+        hasMask = FALSE;
+#endif
+    }
 
     int i, j;
     for (i = 0; i < image.GetWidth(); i++)
@@ -413,11 +463,28 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth )
            unsigned char blue = image.GetBlue(i, j);
 
            ::SetPixel(hMemDC, i, j, PALETTERGB(red, green, blue));
+
+            if (hasMask)
+            {
+                // scan the bitmap for the transparent colour and set the corresponding
+                // pixels in the mask to BLACK and the rest to WHITE
+                if (maskR == red && maskG == green && maskB == blue)
+                    ::SetPixel(hMaskDC, i, j, PALETTERGB(0, 0, 0));
+                else
+                    ::SetPixel(hMaskDC, i, j, PALETTERGB(255, 255, 255));
+           }
        }
     }
 
     ::SelectObject(hMemDC, hOldBitmap);
     ::DeleteDC(hMemDC);
+    if (hasMask)
+    {
+        ::SelectObject(hMaskDC, hOldMaskBitmap);
+       ::DeleteDC(hMaskDC);
+
+        ((wxBitmapRefData*)m_refData)->m_bitmapMask = new wxMask((WXHBITMAP) hMaskBitmap);
+    }
     
     SetWidth(image.GetWidth());
     SetHeight(image.GetHeight());
index f3d7c453e48e7d46c91b837edc6587c6464ad315..d9093f4de24a4f528fbcee3ca88032beedf2412e 100644 (file)
@@ -886,7 +886,6 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask
             useMask = FALSE;
         }
     }
-
     if ( useMask )
     {
 #ifdef __WIN32__
@@ -902,8 +901,7 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask
         {
             HDC cdc = GetHdc();
             HDC hdcMem = ::CreateCompatibleDC(GetHdc());
-            ::SelectObject(hdcMem, GetHbitmapOf(bmp));
-
+            HBITMAP hOldBitmap = ::SelectObject(hdcMem, GetHbitmapOf(bmp));
 #if wxUSE_PALETTE
             wxPalette *pal = bmp.GetPalette();
             if ( pal && ::GetDeviceCaps(cdc,BITSPIXEL) <= 8 )
@@ -923,6 +921,7 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask
                 ::SelectPalette(hdcMem, oldPal, FALSE);
 #endif // wxUSE_PALETTE
 
+           ::SelectObject(hdcMem, hOldBitmap);
             ::DeleteDC(hdcMem);
         }
 
@@ -959,15 +958,15 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask
         }
 
 #if wxUSE_PALETTE
-            wxPalette *pal = bmp.GetPalette();
-            if ( pal && ::GetDeviceCaps(cdc,BITSPIXEL) <= 8 )
-            {
-                oldPal = ::SelectPalette(memdc, GetHpaletteOf(pal), FALSE);
-                ::RealizePalette(memdc);
-            }
+        wxPalette *pal = bmp.GetPalette();
+        if ( pal && ::GetDeviceCaps(cdc,BITSPIXEL) <= 8 )
+        {
+            oldPal = ::SelectPalette(memdc, GetHpaletteOf(pal), FALSE);
+            ::RealizePalette(memdc);
+        }
 #endif // wxUSE_PALETTE
 
-        ::SelectObject( memdc, hbitmap );
+        HBITMAP hOldBitmap = ::SelectObject( memdc, hbitmap );
         ::BitBlt( cdc, x, y, width, height, memdc, 0, 0, SRCCOPY);
 
 #if wxUSE_PALETTE
@@ -975,6 +974,7 @@ void wxDC::DoDrawBitmap( const wxBitmap &bmp, wxCoord x, wxCoord y, bool useMask
             ::SelectPalette(memdc, oldPal, FALSE);
 #endif // wxUSE_PALETTE
 
+        ::SelectObject( memdc, hOldBitmap );
         ::DeleteDC( memdc );
 
         ::SetTextColor(GetHdc(), old_textground);
@@ -1769,8 +1769,8 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest,
             dc_buffer = ::CreateCompatibleDC(GetHdc());
             buffer_bmap = ::CreateCompatibleBitmap(GetHdc(), width, height);
 #endif // wxUSE_DC_CACHEING/!wxUSE_DC_CACHEING
-            ::SelectObject(dc_mask, (HBITMAP) mask->GetMaskBitmap());
-            ::SelectObject(dc_buffer, buffer_bmap);
+            HBITMAP hOldMaskBitmap = ::SelectObject(dc_mask, (HBITMAP) mask->GetMaskBitmap());
+            HBITMAP hOldBufferBitmap = ::SelectObject(dc_buffer, buffer_bmap);
 
             // copy dest to buffer
             if ( !::BitBlt(dc_buffer, 0, 0, (int)width, (int)height,
@@ -1816,8 +1816,8 @@ bool wxDC::DoBlit(wxCoord xdest, wxCoord ydest,
             }
 
             // tidy up temporary DCs and bitmap
-            ::SelectObject(dc_mask, 0);
-            ::SelectObject(dc_buffer, 0);
+            ::SelectObject(dc_mask, hOldMaskBitmap);
+            ::SelectObject(dc_buffer, hOldBufferBitmap);
 
 #if !wxUSE_DC_CACHEING
             {
index a399e3274969351747126095e636cfb9c61bb313..3921366efc25ac8afe651b980d3b7fd951518c35 100644 (file)
@@ -283,3 +283,87 @@ int GetObject(HGDIOBJ hObj, int sz, LPVOID logObj)
         return 0;
     }
 }
+
+/* Not in wingdi.c in earlier versions of MicroWindows */
+#if 0
+HBITMAP WINAPI
+CreateCompatibleBitmap(HDC hdc, int nWidth, int nHeight)
+{
+       MWBITMAPOBJ *   hbitmap;
+       int             size;
+       int             linelen;
+
+       if(!hdc)
+               return NULL;
+
+       nWidth = MWMAX(nWidth, 1);
+       nHeight = MWMAX(nHeight, 1);
+
+       /* calc memory allocation size and linelen from width and height*/
+       if(!GdCalcMemGCAlloc(hdc->psd, nWidth, nHeight, 0, 0, &size, &linelen))
+               return NULL;
+
+       /* allocate gdi object*/
+       hbitmap = (MWBITMAPOBJ *)GdItemAlloc(sizeof(MWBITMAPOBJ)-1+size);
+       if(!hbitmap)
+               return NULL;
+       hbitmap->hdr.type = OBJ_BITMAP;
+       hbitmap->hdr.stockobj = FALSE;
+       hbitmap->width = nWidth;
+       hbitmap->height = nHeight;
+
+       /* create compatible with hdc*/
+       hbitmap->planes = hdc->psd->planes;
+       hbitmap->bpp = hdc->psd->bpp;
+       hbitmap->linelen = linelen;
+       hbitmap->size = size;
+
+       return (HBRUSH)hbitmap;
+}
+#endif
+
+/* Attempt by JACS to create arbitrary bitmap
+ * TODO: make use of lpData
+ */
+
+HBITMAP WINAPI
+CreateBitmap( int nWidth, int nHeight, int nPlanes, int bPP, LPCVOID lpData)
+{
+       MWBITMAPOBJ *   hbitmap;
+       int             size;
+       int             linelen;
+
+        HDC hScreenDC;
+
+        hScreenDC = GetDC(NULL);
+
+       nWidth = MWMAX(nWidth, 1);
+       nHeight = MWMAX(nHeight, 1);
+
+       /* calc memory allocation size and linelen from width and height*/
+       if(!GdCalcMemGCAlloc(hScreenDC->psd, nWidth, nHeight, nPlanes, bPP, &size, &linelen))
+        {
+                ReleaseDC(NULL, hScreenDC);
+               return NULL;
+       }
+        ReleaseDC(NULL, hScreenDC);
+
+       /* allocate gdi object*/
+       hbitmap = (MWBITMAPOBJ *)GdItemAlloc(sizeof(MWBITMAPOBJ)-1+size);
+       if(!hbitmap)
+               return NULL;
+       hbitmap->hdr.type = OBJ_BITMAP;
+       hbitmap->hdr.stockobj = FALSE;
+       hbitmap->width = nWidth;
+       hbitmap->height = nHeight;
+
+       /* create with specified parameters */
+       hbitmap->planes = nPlanes;
+       hbitmap->bpp = bPP;
+       hbitmap->linelen = linelen;
+       hbitmap->size = size;
+
+        /* TODO: copy data */
+
+       return (HBRUSH)hbitmap;
+}
index a2dca1ea29a4fcef338a514b22a3b9ddff843503..4fdf1856d8fcb537fb0a1d4f225abc9ae8766cb4 100644 (file)
@@ -1446,6 +1446,12 @@ void wxWindowMSW::DoClientToScreen(int *x, int *y) const
 
 void wxWindowMSW::DoMoveWindow(int x, int y, int width, int height)
 {
+    // TODO: is this consistent with other platforms?
+    // Still, negative width or height shouldn't be allowed
+    if (width < 0)
+        width = 0;
+    if (height < 0)
+        height = 0;
     if ( !::MoveWindow(GetHwnd(), x, y, width, height, TRUE) )
     {
         wxLogLastError(wxT("MoveWindow"));
index 295756acd0d7a1f944a98027b02a44862943c8e8..c9a95a631868adeba3d47b40db4700e5ae5f7322 100644 (file)
@@ -154,10 +154,12 @@ void wxCheckBox::DoDraw(wxControlRenderer *renderer)
     if ( m_status == Status_Checked )
         flags |= wxCONTROL_CHECKED;
 
+    wxBitmap bitmap(GetBitmap(GetState(flags), m_status));
+
     renderer->GetRenderer()->
         DrawCheckButton(dc,
                         GetLabel(),
-                        GetBitmap(GetState(flags), m_status),
+                        bitmap,
                         renderer->GetRect(),
                         flags,
                         GetWindowStyle() & wxALIGN_RIGHT ? wxALIGN_RIGHT
index 17d7aefce06f4d25612faa6b2e0cd808731ad451..252723acd71358232492af6fbb8cace98710b220 100644 (file)
@@ -466,6 +466,7 @@ void wxNotebook::DoDrawTab(wxDC& dc, const wxRect& rect, size_t n)
         dc.SelectObject(bmp);
         dc.SetBackground(wxBrush(GetBackgroundColour(), wxSOLID));
         m_imageList->Draw(image, dc, 0, 0, wxIMAGELIST_DRAW_NORMAL, TRUE);
+        dc.SelectObject(wxNullBitmap);
 #else
         bmp = *m_imageList->GetBitmap(image);
 #endif
index 3de3e524150274de0fb6a7c7d7a893207772a777..75adfec94e38d99d608941fff44daf3f1124dab4 100644 (file)
@@ -2239,6 +2239,7 @@ void wxWin32Renderer::DrawCheckOrRadioButton(wxDC& dc,
         rectLabel.SetRight(rect.GetRight());
     }
 
+    // THIS IS THE CULPRIT -- JACS
     dc.DrawBitmap(bitmap, xBmp, yBmp, TRUE /* use mask */);
 
     DoDrawLabel(
@@ -2291,10 +2292,12 @@ void wxWin32Renderer::DrawCheckButton(wxDC& dc,
     else
     {
        wxBitmap cbitmap(GetCheckBitmap(flags));
+#if 1
         DrawCheckOrRadioButton(dc, label,
                              cbitmap,
                              rect, flags, align, indexAccel,
                               0); // no focus rect offset for checkboxes
+#endif
     }
 }