1 /////////////////////////////////////////////////////////////////////////////// 
   2 // Name:        gtk/renderer.cpp 
   3 // Purpose:     implementation of wxRendererNative for wxGTK 
   4 // Author:      Vadim Zeitlin 
   8 // Copyright:   (c) 2003 Vadim Zeitlin <vadim@wxwindows.org> 
   9 // License:     wxWindows license 
  10 /////////////////////////////////////////////////////////////////////////////// 
  12 // ============================================================================ 
  14 // ============================================================================ 
  16 // ---------------------------------------------------------------------------- 
  18 // ---------------------------------------------------------------------------- 
  20 // for compilers that support precompilation, includes "wx.h". 
  21 #include "wx/wxprec.h" 
  31 #include "wx/gtk/win_gtk.h" 
  33 #include "wx/window.h" 
  35 #include "wx/renderer.h" 
  38     #include "wx/settings.h" 
  41 // ---------------------------------------------------------------------------- 
  42 // wxRendererGTK: our wxRendererNative implementation 
  43 // ---------------------------------------------------------------------------- 
  45 class WXDLLEXPORT wxRendererGTK 
: public wxDelegateRendererNative
 
  48     // draw the header control button (used by wxListCtrl) 
  49     virtual void DrawHeaderButton(wxWindow 
*win
, 
  55     // draw the expanded/collapsed icon for a tree control item 
  56     virtual void DrawTreeItemButton(wxWindow 
*win
, 
  62     virtual void DrawSplitterBorder(wxWindow 
*win
, 
  65     virtual void DrawSplitterSash(wxWindow 
*win
, 
  69                                   wxOrientation orient
); 
  71     virtual wxPoint 
GetSplitterSashAndBorder(const wxWindow 
*win
); 
  74 // ============================================================================ 
  76 // ============================================================================ 
  79 wxRendererNative
& wxRendererNative::Get() 
  81     static wxRendererGTK s_rendererGTK
; 
  86 // ---------------------------------------------------------------------------- 
  87 // list/tree controls drawing 
  88 // ---------------------------------------------------------------------------- 
  91 wxRendererGTK::DrawHeaderButton(wxWindow 
*win
, 
  98         win
->m_wxwindow
->style
, 
  99         GTK_PIZZA(win
->m_wxwindow
)->bin_window
, 
 100         flags 
& wxCONTROL_DISABLED 
? GTK_STATE_INSENSITIVE 
: GTK_STATE_NORMAL
, 
 102         (GdkRectangle
*) NULL
, 
 104         (char *)"button", // const_cast 
 105         dc
.XLOG2DEV(rect
.x
) - 1, rect
.y 
- 1, rect
.width 
+ 2, rect
.height 
+ 2 
 111 // draw a ">" or "v" button 
 113 // TODO: isn't there a GTK function to draw it? 
 115 wxRendererGTK::DrawTreeItemButton(wxWindow
* WXUNUSED(win
), 
 116                                   wxDC
& dc
, const wxRect
& rect
, int flags
) 
 118     dc
.SetBrush(wxBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT
), 
 120     dc
.SetPen(*wxBLACK_PEN
); 
 123     const wxCoord xMiddle 
= rect
.x 
+ rect
.width
/2; 
 124     const wxCoord yMiddle 
= rect
.y 
+ rect
.height
/2; 
 126     if ( flags 
& wxCONTROL_EXPANDED 
) 
 128         button
[0].x 
= rect
.GetLeft(); 
 129         button
[0].y 
= yMiddle 
- 2; 
 130         button
[1].x 
= rect
.GetRight(); 
 131         button
[1].y 
= yMiddle 
- 2; 
 132         button
[2].x 
= xMiddle
; 
 133         button
[2].y 
= yMiddle 
+ 3; 
 137         button
[0].y 
= rect
.GetBottom(); 
 138         button
[0].x 
= xMiddle 
- 2; 
 139         button
[1].y 
= rect
.GetTop(); 
 140         button
[1].x 
= xMiddle 
- 2; 
 141         button
[2].y 
= yMiddle
; 
 142         button
[2].x 
= xMiddle 
+ 3; 
 145     dc
.DrawPolygon(3, button
); 
 150 // ---------------------------------------------------------------------------- 
 151 // splitter sash drawing 
 152 // ---------------------------------------------------------------------------- 
 154 // the full sash width (should be even) 
 155 static const wxCoord SASH_SIZE 
= 10; 
 157 // margin around the sash 
 158 static const wxCoord SASH_MARGIN 
= 5; 
 161 wxRendererGTK::GetSplitterSashAndBorder(const wxWindow 
* WXUNUSED(win
)) 
 163     // we don't draw any border, hence 0 for the second field, but we must 
 164     // leave some margin around the sash 
 165     return wxPoint(SASH_SIZE 
+ SASH_MARGIN
, 0); 
 169 wxRendererGTK::DrawSplitterBorder(wxWindow 
* WXUNUSED(win
), 
 171                                   const wxRect
& WXUNUSED(rect
)) 
 177 wxRendererGTK::DrawSplitterSash(wxWindow 
*win
, 
 181                                 wxOrientation orient
) 
 183     if ( !win
->m_wxwindow
->window 
) 
 185         // VZ: this happens on startup -- why? 
 189     // are we drawing vertical or horizontal splitter? 
 190     const bool isVert 
= orient 
== wxVERTICAL
; 
 192     // we must erase everything first, otherwise the garbage from the old sash 
 193     // is left when dragging it 
 195     // TODO: is this the right way to draw themed background? 
 201         rect
.width 
= SASH_SIZE 
+ SASH_MARGIN
; 
 202         rect
.height 
= size
.y
; 
 208         rect
.height 
= SASH_SIZE 
+ SASH_MARGIN
; 
 214         win
->m_wxwindow
->style
, 
 215         GTK_PIZZA(win
->m_wxwindow
)->bin_window
, 
 220         (char *)"base", // const_cast 
 225     // leave some margin before sash itself 
 226     position 
+= SASH_MARGIN 
/ 2; 
 228     // and finally draw it using GTK paint functions 
 229     typedef void (*GtkPaintLineFunc
)(GtkStyle 
*, GdkWindow 
*, 
 231                                                 GdkRectangle 
*, GtkWidget 
*, 
 232                                                 gchar 
*, gint
, gint
, gint
); 
 234     GtkPaintLineFunc func 
= isVert 
? gtk_paint_vline 
: gtk_paint_hline
; 
 238         win
->m_wxwindow
->style
, 
 239         GTK_PIZZA(win
->m_wxwindow
)->bin_window
, 
 243         (char *)"paned", // const_cast 
 244         0, isVert 
? size
.y 
: size
.x
, position 
+ SASH_SIZE 
/ 2 - 1 
 249         win
->m_wxwindow
->style
, 
 250         GTK_PIZZA(win
->m_wxwindow
)->bin_window
, 
 253         (GdkRectangle
*) NULL
, 
 255         (char *)"paned", // const_cast 
 256         isVert 
? position 
: size
.x 
- 2*SASH_SIZE
, 
 257         isVert 
? size
.y 
- 2*SASH_SIZE 
: position
,