1 ///////////////////////////////////////////////////////////////////////////// 
   2 // Name:        src/os2/brush.cpp 
   4 // Author:      David Webster 
   8 // Copyright:   (c) David Webster 
   9 // Licence:     wxWindows licence 
  10 ///////////////////////////////////////////////////////////////////////////// 
  12 // For compilers that support precompilation, includes "wx.h". 
  13 #include "wx/wxprec.h" 
  24 #include "wx/os2/private.h" 
  26 class WXDLLEXPORT wxBrushRefData
: public wxGDIRefData
 
  28     friend class WXDLLIMPEXP_FWD_CORE wxBrush
; 
  30     wxBrushRefData(const wxColour
& colour 
= wxNullColour
, wxBrushStyle style 
= wxBRUSHSTYLE_SOLID
); 
  31     wxBrushRefData(const wxBitmap
& stipple
); 
  32     wxBrushRefData(const wxBrushRefData
& rData
); 
  33     virtual ~wxBrushRefData(); 
  35     bool operator == (const wxBrushRefData
& data
) const 
  37         return (m_nStyle 
== data
.m_nStyle 
&& 
  38                 m_vStipple
.IsSameAs(data
.m_vStipple
) && 
  39                 m_vColour 
== data
.m_vColour
); 
  43     wxBrushStyle m_nStyle
; 
  46     WXHBRUSH     m_hBrush
; // in OS/2 GPI this will be the PS the pen is associated with 
  50 #define M_BRUSHDATA ((wxBrushRefData *)m_refData) 
  52 // ============================================================================ 
  53 // wxBrushRefData implementation 
  54 // ============================================================================ 
  56 IMPLEMENT_DYNAMIC_CLASS(wxBrush
, wxGDIObject
) 
  58 // ---------------------------------------------------------------------------- 
  59 // wxBrushRefData ctors/dtor 
  60 // ---------------------------------------------------------------------------- 
  62 wxBrushRefData::wxBrushRefData(const wxColour
& colour
, wxBrushStyle style
) 
  67     memset(&m_vBundle
, '\0', sizeof(AREABUNDLE
)); 
  68 } // end of wxBrushRefData::wxBrushRefData 
  70 wxBrushRefData::wxBrushRefData(const wxBitmap
& stipple
) 
  73     m_nStyle 
= stipple
.GetMask() ? wxBRUSHSTYLE_STIPPLE_MASK_OPAQUE
 
  74                                  : wxBRUSHSTYLE_STIPPLE
; 
  77     memset(&m_vBundle
, '\0', sizeof(AREABUNDLE
)); 
  80 wxBrushRefData::wxBrushRefData(const wxBrushRefData
& rData
) 
  82                 m_vStipple(rData
.m_vStipple
), 
  83                 m_vColour(rData
.m_vColour
) 
  85     m_nStyle   
= rData
.m_nStyle
; 
  87     memcpy(&m_vBundle
, &rData
.m_vBundle
, sizeof(AREABUNDLE
)); 
  88 } // end of wxBrushRefData::wxBrushRefData 
  90 wxBrushRefData::~wxBrushRefData() 
  92 } // end of wxBrushRefData::~wxBrushRefData 
  94 // ============================================================================ 
  95 // wxBrush implementation 
  96 // ============================================================================ 
  98 // ---------------------------------------------------------------------------- 
 100 // ---------------------------------------------------------------------------- 
 104 } // end of wxBrush::wxBrush 
 108 } // end of wxBrush::~wxBrush 
 111   const wxColour
&                   rColour
 
 112 , wxBrushStyle                      nStyle
 
 115     m_refData 
= new wxBrushRefData(rColour
, nStyle
); 
 118 } // end of wxBrush::wxBrush 
 120 #if FUTURE_WXWIN_COMPATIBILITY_3_0 
 121 wxBrush::wxBrush(const wxColour
& col
, int style
) 
 123     m_refData 
= new wxBrushRefData(col
, (wxBrushStyle
)style
); 
 129 wxBrush::wxBrush(const wxBitmap
& rStipple
) 
 131     m_refData 
= new wxBrushRefData(rStipple
); 
 134 } // end of wxBrush::wxBrush 
 136 bool wxBrush::RealizeResource() 
 142     if (M_BRUSHDATA 
&& M_BRUSHDATA
->m_hBrush 
== 0L) 
 144         SIZEL                   vSize 
= {0, 0}; 
 145         DEVOPENSTRUC            vDop 
= {0L, "DISPLAY", NULL
, 0L, 0L, 0L, 0L, 0L, 0L}; 
 146         HDC                     hDC 
= ::DevOpenDC( vHabmain
 
 153         M_BRUSHDATA
->m_hBrush 
= (WXHPEN
)::GpiCreatePS( vHabmain
 
 156                                                       ,PU_PELS 
| GPIT_MICRO 
| GPIA_ASSOC
 
 162         // Set the color table to RGB mode 
 164         if (!::GpiCreateLogColorTable( (HPS
)M_BRUSHDATA
->m_hBrush
 
 172             vError 
= ::WinGetLastError(vHabmain
); 
 173             sError 
= wxPMErrorToStr(vError
); 
 174             wxLogError(wxT("Unable to set current color table to RGB mode. Error: %s\n"), sError
.c_str()); 
 178         if (M_BRUSHDATA
->m_nStyle
==wxTRANSPARENT
) 
 182         COLORREF                    vPmColour 
= 0L; 
 184         vPmColour 
= M_BRUSHDATA
->m_vColour
.GetPixel() ; 
 186         M_BRUSHDATA
->m_vBundle
.usSet 
= LCID_DEFAULT
; 
 187         switch (M_BRUSHDATA
->m_nStyle
) 
 190                 M_BRUSHDATA
->m_hBrush 
= NULL
;  // Must always select a suitable background brush 
 191                 break;                         // - could choose white always for a quick solution 
 193             case wxBDIAGONAL_HATCH
: 
 194                 M_BRUSHDATA
->m_vBundle
.usSymbol 
= PATSYM_DIAG3
; 
 197             case wxCROSSDIAG_HATCH
: 
 198                 M_BRUSHDATA
->m_vBundle
.usSymbol 
= PATSYM_DIAGHATCH
; 
 201             case wxFDIAGONAL_HATCH
: 
 202                 M_BRUSHDATA
->m_vBundle
.usSymbol 
= PATSYM_DIAG1
; 
 206                 M_BRUSHDATA
->m_vBundle
.usSymbol 
= PATSYM_HATCH
; 
 209             case wxHORIZONTAL_HATCH
: 
 210                 M_BRUSHDATA
->m_vBundle
.usSymbol 
= PATSYM_HORIZ
; 
 213             case wxVERTICAL_HATCH
: 
 214                 M_BRUSHDATA
->m_vBundle
.usSymbol 
= PATSYM_VERT
; 
 218                 if (M_BRUSHDATA
->m_vStipple
.IsOk()) 
 220                     ::GpiSetBitmapId( M_BRUSHDATA
->m_hBrush
 
 221                                      ,(USHORT
)M_BRUSHDATA
->m_vStipple
.GetHBITMAP() 
 222                                      ,(USHORT
)M_BRUSHDATA
->m_vStipple
.GetId() 
 224                     ::GpiSetPatternSet( M_BRUSHDATA
->m_hBrush
 
 225                                        ,(USHORT
)M_BRUSHDATA
->m_vStipple
.GetId() 
 229                     M_BRUSHDATA
->m_vBundle
.usSymbol 
= PATSYM_SOLID
; 
 234                 M_BRUSHDATA
->m_vBundle
.usSymbol 
= PATSYM_SOLID
; 
 237 #ifdef WXDEBUG_CREATE 
 238         if (M_BRUSHDATA
->m_hBrush
==NULL
) wxError("Cannot create brush","Internal error") ; 
 240         M_BRUSHDATA
->m_vBundle
.lColor        
= vPmColour
; 
 241         M_BRUSHDATA
->m_vBundle
.lBackColor    
= RGB_WHITE
; 
 242         M_BRUSHDATA
->m_vBundle
.usMixMode     
= FM_OVERPAINT
; 
 243         M_BRUSHDATA
->m_vBundle
.usBackMixMode 
= BM_OVERPAINT
; 
 245         bOk 
= (bool)::GpiSetAttrs( M_BRUSHDATA
->m_hBrush
 
 247                                   ,ABB_COLOR 
| ABB_BACK_COLOR 
| ABB_MIX_MODE 
| ABB_BACK_MIX_MODE 
| 
 248                                    ABB_SET 
| ABB_SYMBOL 
| ABB_REF_POINT
 
 249                                   ,ABB_SET 
| ABB_SYMBOL 
| ABB_REF_POINT
 
 250                                   ,&M_BRUSHDATA
->m_vBundle
 
 254             vError 
= ::WinGetLastError(vHabmain
); 
 255             sError 
= wxPMErrorToStr(vError
); 
 256             wxLogError(wxT("Can't set Gpi attributes for an AREABUNDLE. Error: %s\n"), sError
.c_str()); 
 261 } // end of wxBrush::RealizeResource 
 263 // ---------------------------------------------------------------------------- 
 265 // ---------------------------------------------------------------------------- 
 267 wxColour 
wxBrush::GetColour() const 
 269     wxCHECK_MSG( IsOk(), wxNullColour
, wxT("invalid brush") ); 
 271     return M_BRUSHDATA
->m_vColour
; 
 274 wxBrushStyle 
wxBrush::GetStyle() const 
 276     wxCHECK_MSG( IsOk(), wxBRUSHSTYLE_INVALID
, wxT("invalid brush") ); 
 278     return M_BRUSHDATA
->m_nStyle
; 
 281 wxBitmap 
*wxBrush::GetStipple() const 
 283     wxCHECK_MSG( IsOk(), NULL
, wxT("invalid brush") ); 
 285     return &(M_BRUSHDATA
->m_vStipple
); 
 288 int wxBrush::GetPS() const 
 290     wxCHECK_MSG( IsOk(), 0, wxT("invalid brush") ); 
 292     return M_BRUSHDATA
->m_hBrush
; 
 295 WXHANDLE 
wxBrush::GetResourceHandle() const 
 297     wxCHECK_MSG( IsOk(), 0, wxT("invalid brush") ); 
 299     return (WXHANDLE
)M_BRUSHDATA
->m_hBrush
; 
 300 } // end of wxBrush::GetResourceHandle 
 302 bool wxBrush::FreeResource( bool WXUNUSED(bForce
) ) 
 304     if (M_BRUSHDATA 
&& (M_BRUSHDATA
->m_hBrush 
!= 0)) 
 306         M_BRUSHDATA
->m_hBrush 
= 0; 
 310 } // end of wxBrush::FreeResource 
 312 bool wxBrush::IsFree() const 
 314   return (M_BRUSHDATA 
&& (M_BRUSHDATA
->m_hBrush 
== 0)); 
 315 } // end of wxBrush::IsFree 
 317 // ---------------------------------------------------------------------------- 
 319 // ---------------------------------------------------------------------------- 
 321 void wxBrush::SetColour( const wxColour
& rColour 
) 
 324     M_BRUSHDATA
->m_vColour 
= rColour
; 
 328 void wxBrush::SetColour(unsigned char cRed
, unsigned char cGreen
, unsigned char cBlue
) 
 331     M_BRUSHDATA
->m_vColour
.Set( cRed
, cGreen
, cBlue 
); 
 333 } // end of wxBrush::SetColour 
 335 void wxBrush::SetStyle(wxBrushStyle nStyle
) 
 338     M_BRUSHDATA
->m_nStyle 
= nStyle
; 
 340 } // end of wxBrush::SetStyle 
 342 void wxBrush::SetStipple( 
 343   const wxBitmap
&                   rStipple
 
 347     M_BRUSHDATA
->m_vStipple 
= rStipple
; 
 349 } // end of wxBrush::SetStipple 
 356     if (M_BRUSHDATA
->m_hBrush
) 
 357         ::GpiDestroyPS(M_BRUSHDATA
->m_hBrush
); 
 358     M_BRUSHDATA
->m_hBrush 
= hPS
; 
 360 } // end of WxWinGdi_CPen::SetPS 
 362 // ---------------------------------------------------------------------------- 
 363 // wxBrush house keeping stuff 
 364 // ---------------------------------------------------------------------------- 
 366 bool wxBrush::operator == ( 
 370     if (m_refData 
== brush
.m_refData
) return true; 
 372     if (!m_refData 
|| !brush
.m_refData
) return false; 
 374     return ( *(wxBrushRefData
*)m_refData 
== *(wxBrushRefData
*)brush
.m_refData 
); 
 375 } // end of wxBrush::operator == 
 377 wxGDIRefData 
*wxBrush::CreateGDIRefData() const 
 379     return new wxBrushRefData
; 
 382 wxGDIRefData 
*wxBrush::CloneGDIRefData(const wxGDIRefData 
*data
) const 
 384     return new wxBrushRefData(*(const wxBrushRefData 
*)data
);