1 /////////////////////////////////////////////////////////////////////////////// 
   2 // Name:        mac/renderer.cpp 
   3 // Purpose:     implementation of wxRendererNative for Mac 
   4 // Author:      Vadim Zeitlin 
   8 // Copyright:   (c) 2003 Vadim Zeitlin <vadim@wxwindows.org> 
   9 // License:     wxWindows licence 
  10 /////////////////////////////////////////////////////////////////////////////// 
  12 // ============================================================================ 
  14 // ============================================================================ 
  16 // ---------------------------------------------------------------------------- 
  18 // ---------------------------------------------------------------------------- 
  20 // for compilers that support precompilation, includes "wx.h". 
  21 #include "wx/wxprec.h" 
  28     #include "wx/string.h" 
  30     #include "wx/bitmap.h" 
  31     #include "wx/settings.h" 
  34 #include "wx/renderer.h" 
  36 // ---------------------------------------------------------------------------- 
  37 // wxRendererMac: our wxRendererNative implementation 
  38 // ---------------------------------------------------------------------------- 
  40 class WXDLLEXPORT wxRendererMac 
: public wxDelegateRendererNative
 
  43     // draw the header control button (used by wxListCtrl) 
  44     virtual void DrawHeaderButton(wxWindow 
*win
, 
  49     // draw the expanded/collapsed icon for a tree control item 
  50     virtual void DrawTreeItemButton(wxWindow 
*win
, 
  55     // draw a (vertical) sash 
  56     virtual void DrawSplitterSash(wxWindow 
*win
, 
  65     wxBitmap m_bmpTreeExpanded
, 
  69 // ---------------------------------------------------------------------------- 
  71 // ---------------------------------------------------------------------------- 
  74 static const char *aqua_arrow_right_xpm
[] = { 
  75 /* columns rows colors chars-per-pixel */ 
  96 static const char *aqua_arrow_down_xpm
[] = { 
  97 /* columns rows colors chars-per-pixel */ 
 117 // ============================================================================ 
 119 // ============================================================================ 
 122 wxRendererNative
& wxRendererNative::GetDefault() 
 124     static wxRendererMac s_rendererMac
; 
 126     return s_rendererMac
; 
 130 wxRendererMac::DrawHeaderButton(wxWindow 
*win
, 
 135     const int CORNER 
= 1; 
 137     const wxCoord x 
= rect
.x
-1, 
 143     wxGetOsVersion( &major
, &minor 
); 
 145     dc
.SetBrush( *wxTRANSPARENT_BRUSH 
); 
 149         dc
.SetPen( wxPen( wxColour( 0xC5 , 0xC5 , 0xC5 ) , 1 , wxSOLID 
) ); 
 150         dc
.DrawRectangle( x
, y
+CORNER
, 1, h
-CORNER 
);                           // left 
 151         // The right border is overdrawn by the left border of the right neighbouring 
 152         // header (to maintain a proper single pixel border). Except for the  
 153         // rightmost header of the listctrl. 
 154         dc
.DrawRectangle( x
+w
+(CORNER
*2), y
+CORNER
, 1, h
-CORNER 
);      // right 
 155         dc
.SetPen( wxPen( wxColour( 0xB1 , 0xB1 , 0xB1 ) , 1 , wxSOLID 
) );     
 156         dc
.DrawRectangle( x
, y
+h
, w
+(CORNER
*3), 1 );                    // bottom 
 157         dc
.DrawRectangle( x
, y
, w
+(CORNER
*3), 1 );                          // top 
 159         // Do a fill of the interior for background: 
 160         dc
.SetPen( wxPen( wxColour( 0xF6 , 0xF6 , 0xF6 ) , 1 , wxSOLID 
) );  
 161         dc
.DrawRectangle( x
+CORNER
, y
+CORNER
, w
+CORNER
, h
-CORNER 
); 
 163         // Do the gradient fill: 
 164         static int grayValues
[] =  
 166             0xF6, 0xF2, 0xEF, 0xED, 0xED, 0xEB, 0xEA, 0xEA, 0xE8,  
 167             0xE8, 0xE2, 0xE5, 0xE8, 0xEB, 0xEF, 0xF2, 0xFD 
 170         for (i
=0; i 
< h 
&& i 
< (int)WXSIZEOF(grayValues
); i
++)  
 172             dc
.SetPen( wxPen( wxColour( grayValues
[i
] , grayValues
[i
] , grayValues
[i
] ), 
 174             dc
.DrawRectangle( x
+CORNER
, y
+CORNER
+i
, w
+CORNER
, 1 ); 
 179         dc
.SetPen( wxPen( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNSHADOW 
) , 1 , wxSOLID 
) ); 
 180         dc
.DrawLine( x
+w
-CORNER
+1, y
, x
+w
, y
+h 
);       // right (outer) 
 181         dc
.DrawRectangle( x
, y
+h
, w
+1, 1 );             // bottom (outer) 
 183         wxPen 
pen( wxColour( 0x88 , 0x88 , 0x88 ), 1, wxSOLID 
); 
 186         dc
.DrawLine( x
+w
-CORNER
, y
, x
+w
-1, y
+h 
);       // right (inner) 
 187         dc
.DrawRectangle( x
+1, y
+h
-1, w
-2, 1 );         // bottom (inner) 
 189         dc
.SetPen( *wxWHITE_PEN 
); 
 190         dc
.DrawRectangle( x
, y
, w
-CORNER
+1, 1 );        // top (outer) 
 191         dc
.DrawRectangle( x
, y
, 1, h 
);                 // left (outer) 
 192         dc
.DrawLine( x
, y
+h
-1, x
+1, y
+h
-1 ); 
 193         dc
.DrawLine( x
+w
-1, y
, x
+w
-1, y
+1 ); 
 198 wxRendererMac::DrawTreeItemButton(wxWindow 
*win
, 
 203     // init the buttons on demand 
 204     if ( !m_bmpTreeExpanded
.Ok() ) 
 206         m_bmpTreeExpanded 
= wxBitmap(aqua_arrow_down_xpm
); 
 207         m_bmpTreeCollapsed 
= wxBitmap(aqua_arrow_right_xpm
); 
 212     // VZ: this is the old code from treectlg.cpp which apparently doesn't work 
 213     //     but I kept it here just in case it is needed -- if not, please 
 215 #if 0 // def __WXMAC__ 
 216     wxMacPortSetter 
helper(&dc
) ; 
 217     wxMacWindowClipper 
clipper(this) ; 
 218     wxDC::MacSetupBackgroundForCurrentPort( MacGetBackgroundBrush() ) ; 
 221     int loc_y 
= y_mid 
- 6 ; 
 222     MacWindowToRootWindow( & loc_x 
, & loc_y 
) ; 
 223     Rect bounds 
= { loc_y 
, loc_x 
, loc_y 
+ 18 , loc_x 
+ 12 } ; 
 224     ThemeButtonDrawInfo info 
= { kThemeStateActive 
, item
->IsExpanded() ? kThemeDisclosureDown 
: kThemeDisclosureRight 
, 
 225         kThemeAdornmentNone 
};  
 226     DrawThemeButton( &bounds
, kThemeDisclosureButton 
,  
 227         &info 
, NULL 
, NULL 
, NULL 
, NULL 
) ; 
 229     dc
.DrawBitmap(flags 
& wxCONTROL_EXPANDED 
? m_bmpTreeExpanded
 
 230                                              : m_bmpTreeCollapsed
, 
 231                   rect
.x
, rect
.y
, true /* use mask */); 
 236 wxRendererMac::DrawSplitterSash(wxWindow 
*win
, 
 240                                 wxOrientation orient
, 
 243     // VZ: we have to somehow determine if we're drawing a normal sash or 
 244     //     a brushed metal one as they look quite differently... this is 
 245     //     completely bogus anyhow, of course (TODO) 
 248     dc
.SetPen(*wxLIGHT_GREY_PEN
); 
 249     dc
.SetBrush(*wxWHITE_BRUSH
); 
 250     if ( orient 
== wxVERTICAL 
) 
 251         dc
.DrawRectangle(position
, 0, 7, size
.y
); 
 253         dc
.DrawRectangle(0, position
, size
.x
, 7); 
 255     // Do the gradient fill: 
 256     static int grayValues
[] =  
 258         0xA0, 0xF6, 0xED, 0xE4, 0xE2, 0xD0, 0xA0 
 260     dc
.SetBrush( *wxTRANSPARENT_BRUSH 
); 
 261     if ( orient 
== wxVERTICAL 
) 
 264         for (i
=0; i 
< (int)WXSIZEOF(grayValues
); i
++)  
 266             dc
.SetPen( wxPen( wxColour( grayValues
[i
] , grayValues
[i
] , grayValues
[i
] ), 
 268             dc
.DrawRectangle( position
+i
, 0, 1, size
.y 
); 
 274         for (i
=0; i 
< (int)WXSIZEOF(grayValues
); i
++)  
 276             dc
.SetPen( wxPen( wxColour( grayValues
[i
] , grayValues
[i
] , grayValues
[i
] ), 
 278             dc
.DrawRectangle( 0, position
+i
, size
.x
, 1 );