]> git.saurik.com Git - wxWidgets.git/blobdiff - src/msw/brush.cpp
mention wx[Flex]GridSizer too
[wxWidgets.git] / src / msw / brush.cpp
index 43dbfae9332da7b75e5dac130acb5e843cf354c9..83f9652783a2e69f3d9836fa4d93dee2fb3761a7 100644 (file)
 
 #include "assert.h"
 
 
 #include "assert.h"
 
-#if !USE_SHARED_LIBRARIES
 IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
 IMPLEMENT_DYNAMIC_CLASS(wxBrush, wxGDIObject)
-#endif
 
 wxBrushRefData::wxBrushRefData(void)
 {
   m_style = wxSOLID;
 
 wxBrushRefData::wxBrushRefData(void)
 {
   m_style = wxSOLID;
-//  m_stipple = NULL ;
+  m_hBrush = 0;
+}
+
+wxBrushRefData::wxBrushRefData(const wxBrushRefData& data)
+{
+  m_style = data.m_style;
+  m_stipple = data.m_stipple;
+  m_colour = data.m_colour;
   m_hBrush = 0;
 }
 
   m_hBrush = 0;
 }
 
@@ -77,26 +82,16 @@ wxBrush::wxBrush(const wxColour& col, int Style)
     wxTheBrushList->AddBrush(this);
 }
 
     wxTheBrushList->AddBrush(this);
 }
 
-wxBrush::wxBrush(const wxString& col, int Style)
-{
-  m_refData = new wxBrushRefData;
-
-  M_BRUSHDATA->m_colour = col;
-  M_BRUSHDATA->m_style = Style;
-  M_BRUSHDATA->m_hBrush = 0;
-
-  RealizeResource();
-
-  if ( wxTheBrushList )
-    wxTheBrushList->AddBrush(this);
-}
-
 wxBrush::wxBrush(const wxBitmap& stipple)
 {
   m_refData = new wxBrushRefData;
 
 wxBrush::wxBrush(const wxBitmap& stipple)
 {
   m_refData = new wxBrushRefData;
 
-  M_BRUSHDATA->m_style = wxSTIPPLE;
   M_BRUSHDATA->m_stipple = stipple;
   M_BRUSHDATA->m_stipple = stipple;
+  if (M_BRUSHDATA->m_stipple.GetMask())
+         M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
+  else
+         M_BRUSHDATA->m_style = wxSTIPPLE;
+
   M_BRUSHDATA->m_hBrush = 0;
 
   RealizeResource();
   M_BRUSHDATA->m_hBrush = 0;
 
   RealizeResource();
@@ -105,7 +100,7 @@ wxBrush::wxBrush(const wxBitmap& stipple)
     wxTheBrushList->AddBrush(this);
 }
 
     wxTheBrushList->AddBrush(this);
 }
 
-bool wxBrush::RealizeResource(void) 
+bool wxBrush::RealizeResource(void)
 {
   if (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush == 0))
   {
 {
   if (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush == 0))
   {
@@ -132,6 +127,7 @@ bool wxBrush::RealizeResource(void)
                       // - could choose white always for a quick solution
       break;
 ***/
                       // - could choose white always for a quick solution
       break;
 ***/
+#ifndef __WXMICROWIN__
       case wxBDIAGONAL_HATCH:
         M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_BDIAGONAL,ms_colour) ;
         break ;
       case wxBDIAGONAL_HATCH:
         M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateHatchBrush(HS_BDIAGONAL,ms_colour) ;
         break ;
@@ -156,12 +152,19 @@ bool wxBrush::RealizeResource(void)
         else
           M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateSolidBrush(ms_colour) ;
         break ;
         else
           M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateSolidBrush(ms_colour) ;
         break ;
+      case wxSTIPPLE_MASK_OPAQUE:
+        if (M_BRUSHDATA->m_stipple.Ok() && M_BRUSHDATA->m_stipple.GetMask())
+          M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreatePatternBrush((HBITMAP) M_BRUSHDATA->m_stipple.GetMask()->GetMaskBitmap());
+        else
+          M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateSolidBrush(ms_colour) ;
+        break ;
+#endif
       case wxSOLID:
       default:
         M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateSolidBrush(ms_colour) ;
         break;
     }
       case wxSOLID:
       default:
         M_BRUSHDATA->m_hBrush = (WXHBRUSH) CreateSolidBrush(ms_colour) ;
         break;
     }
-#ifdef DEBUG_CREATE
+#ifdef WXDEBUG_CREATE
     if (M_BRUSHDATA->m_hBrush==NULL) wxError("Cannot create brush","Internal error") ;
 #endif
     return TRUE;
     if (M_BRUSHDATA->m_hBrush==NULL) wxError("Cannot create brush","Internal error") ;
 #endif
     return TRUE;
@@ -175,7 +178,7 @@ WXHANDLE wxBrush::GetResourceHandle(void)
   return (WXHANDLE) M_BRUSHDATA->m_hBrush;
 }
 
   return (WXHANDLE) M_BRUSHDATA->m_hBrush;
 }
 
-bool wxBrush::FreeResource(bool force)
+bool wxBrush::FreeResource(bool WXUNUSED(force))
 {
   if (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush != 0))
   {
 {
   if (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush != 0))
   {
@@ -186,77 +189,64 @@ bool wxBrush::FreeResource(bool force)
   else return FALSE;
 }
 
   else return FALSE;
 }
 
-/*
-bool wxBrush::UseResource(void)
+bool wxBrush::IsFree() const
 {
 {
-  IncrementResourceUsage();
-  return TRUE;
+  return (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush == 0));
 }
 
 }
 
-bool wxBrush::ReleaseResource(void)
+void wxBrush::Unshare()
 {
 {
-  DecrementResourceUsage();
-  return TRUE;
+       // Don't change shared data
+       if (!m_refData)
+    {
+               m_refData = new wxBrushRefData();
+       }
+    else
+    {
+               wxBrushRefData* ref = new wxBrushRefData(*(wxBrushRefData*)m_refData);
+               UnRef();
+               m_refData = ref;
+       }
 }
 }
-*/
 
 
-bool wxBrush::IsFree(void)
-{
-  return (M_BRUSHDATA && (M_BRUSHDATA->m_hBrush == 0));
-}
 
 void wxBrush::SetColour(const wxColour& col)
 {
 
 void wxBrush::SetColour(const wxColour& col)
 {
-  if ( !M_BRUSHDATA )
-       m_refData = new wxBrushRefData;
+    Unshare();
 
 
-  M_BRUSHDATA->m_colour = col;
+    M_BRUSHDATA->m_colour = col;
 
 
-  if (FreeResource())
     RealizeResource();
 }
 
     RealizeResource();
 }
 
-void wxBrush::SetColour(const wxString& col)
+void wxBrush::SetColour(unsigned char r, unsigned char g, unsigned char b)
 {
 {
-  if ( !M_BRUSHDATA )
-       m_refData = new wxBrushRefData;
+    Unshare();
 
 
-  M_BRUSHDATA->m_colour = col;
+    M_BRUSHDATA->m_colour.Set(r, g, b);
 
 
-  if (FreeResource())
-    RealizeResource();
-}
-
-void wxBrush::SetColour(const unsigned char r, const unsigned char g, const unsigned char b)
-{
-  if ( !M_BRUSHDATA )
-       m_refData = new wxBrushRefData;
-
-  M_BRUSHDATA->m_colour.Set(r, g, b);
-
-  if (FreeResource())
     RealizeResource();
 }
 
 void wxBrush::SetStyle(int Style)
 {
     RealizeResource();
 }
 
 void wxBrush::SetStyle(int Style)
 {
-  if ( !M_BRUSHDATA )
-       m_refData = new wxBrushRefData;
+    Unshare();
 
 
-  M_BRUSHDATA->m_style = Style;
+    M_BRUSHDATA->m_style = Style;
 
 
-  if (FreeResource())
     RealizeResource();
 }
 
 void wxBrush::SetStipple(const wxBitmap& Stipple)
 {
     RealizeResource();
 }
 
 void wxBrush::SetStipple(const wxBitmap& Stipple)
 {
-  if ( !M_BRUSHDATA )
-       m_refData = new wxBrushRefData;
+    Unshare();
 
 
-  M_BRUSHDATA->m_stipple = Stipple;
+    M_BRUSHDATA->m_stipple = Stipple;
+    if (M_BRUSHDATA->m_stipple.GetMask())
+       M_BRUSHDATA->m_style = wxSTIPPLE_MASK_OPAQUE;
+    else
+       M_BRUSHDATA->m_style = wxSTIPPLE;
 
 
-  if (FreeResource())
     RealizeResource();
 }
 
     RealizeResource();
 }