| 1 | /////////////////////////////////////////////////////////////////////////////// |
| 2 | // Name: src/gtk/renderer.cpp |
| 3 | // Purpose: implementation of wxRendererNative for wxGTK |
| 4 | // Author: Vadim Zeitlin |
| 5 | // Modified by: |
| 6 | // Created: 20.07.2003 |
| 7 | // RCS-ID: $Id$ |
| 8 | // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org> |
| 9 | // License: wxWindows licence |
| 10 | /////////////////////////////////////////////////////////////////////////////// |
| 11 | |
| 12 | // ============================================================================ |
| 13 | // declarations |
| 14 | // ============================================================================ |
| 15 | |
| 16 | // ---------------------------------------------------------------------------- |
| 17 | // headers |
| 18 | // ---------------------------------------------------------------------------- |
| 19 | |
| 20 | // for compilers that support precompilation, includes "wx.h". |
| 21 | #include "wx/wxprec.h" |
| 22 | |
| 23 | #ifdef __BORLANDC__ |
| 24 | #pragma hdrstop |
| 25 | #endif |
| 26 | |
| 27 | #include "wx/renderer.h" |
| 28 | |
| 29 | #ifndef WX_PRECOMP |
| 30 | #include "wx/window.h" |
| 31 | #include "wx/dcclient.h" |
| 32 | #include "wx/settings.h" |
| 33 | #include "wx/module.h" |
| 34 | #endif |
| 35 | |
| 36 | #include "wx/dcgraph.h" |
| 37 | #include "wx/gtk/dc.h" |
| 38 | #include "wx/gtk/private.h" |
| 39 | |
| 40 | #include <gtk/gtk.h> |
| 41 | |
| 42 | // ---------------------------------------------------------------------------- |
| 43 | // wxRendererGTK: our wxRendererNative implementation |
| 44 | // ---------------------------------------------------------------------------- |
| 45 | |
| 46 | class WXDLLEXPORT wxRendererGTK : public wxDelegateRendererNative |
| 47 | { |
| 48 | public: |
| 49 | // draw the header control button (used by wxListCtrl) |
| 50 | virtual int DrawHeaderButton(wxWindow *win, |
| 51 | wxDC& dc, |
| 52 | const wxRect& rect, |
| 53 | int flags = 0, |
| 54 | wxHeaderSortIconType sortArrow = wxHDR_SORT_ICON_NONE, |
| 55 | wxHeaderButtonParams* params = NULL); |
| 56 | |
| 57 | virtual int GetHeaderButtonHeight(wxWindow *win); |
| 58 | |
| 59 | |
| 60 | // draw the expanded/collapsed icon for a tree control item |
| 61 | virtual void DrawTreeItemButton(wxWindow *win, |
| 62 | wxDC& dc, |
| 63 | const wxRect& rect, |
| 64 | int flags = 0); |
| 65 | |
| 66 | virtual void DrawSplitterBorder(wxWindow *win, |
| 67 | wxDC& dc, |
| 68 | const wxRect& rect, |
| 69 | int flags = 0); |
| 70 | virtual void DrawSplitterSash(wxWindow *win, |
| 71 | wxDC& dc, |
| 72 | const wxSize& size, |
| 73 | wxCoord position, |
| 74 | wxOrientation orient, |
| 75 | int flags = 0); |
| 76 | |
| 77 | virtual void DrawComboBoxDropButton(wxWindow *win, |
| 78 | wxDC& dc, |
| 79 | const wxRect& rect, |
| 80 | int flags = 0); |
| 81 | |
| 82 | virtual void DrawDropArrow(wxWindow *win, |
| 83 | wxDC& dc, |
| 84 | const wxRect& rect, |
| 85 | int flags = 0); |
| 86 | |
| 87 | virtual void DrawCheckBox(wxWindow *win, |
| 88 | wxDC& dc, |
| 89 | const wxRect& rect, |
| 90 | int flags = 0); |
| 91 | |
| 92 | virtual void DrawPushButton(wxWindow *win, |
| 93 | wxDC& dc, |
| 94 | const wxRect& rect, |
| 95 | int flags = 0); |
| 96 | |
| 97 | virtual void DrawItemSelectionRect(wxWindow *win, |
| 98 | wxDC& dc, |
| 99 | const wxRect& rect, |
| 100 | int flags = 0); |
| 101 | |
| 102 | virtual void DrawChoice(wxWindow* win, |
| 103 | wxDC& dc, |
| 104 | const wxRect& rect, |
| 105 | int flags=0); |
| 106 | |
| 107 | virtual void DrawComboBox(wxWindow* win, |
| 108 | wxDC& dc, |
| 109 | const wxRect& rect, |
| 110 | int flags=0); |
| 111 | |
| 112 | virtual void DrawTextCtrl(wxWindow* win, |
| 113 | wxDC& dc, |
| 114 | const wxRect& rect, |
| 115 | int flags=0); |
| 116 | |
| 117 | virtual void DrawRadioBitmap(wxWindow* win, |
| 118 | wxDC& dc, |
| 119 | const wxRect& rect, |
| 120 | int flags=0); |
| 121 | |
| 122 | virtual void DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags = 0); |
| 123 | |
| 124 | virtual wxSize GetCheckBoxSize(wxWindow *win); |
| 125 | |
| 126 | virtual wxSplitterRenderParams GetSplitterParams(const wxWindow *win); |
| 127 | }; |
| 128 | |
| 129 | // ============================================================================ |
| 130 | // implementation |
| 131 | // ============================================================================ |
| 132 | |
| 133 | /* static */ |
| 134 | wxRendererNative& wxRendererNative::GetDefault() |
| 135 | { |
| 136 | static wxRendererGTK s_rendererGTK; |
| 137 | |
| 138 | return s_rendererGTK; |
| 139 | } |
| 140 | |
| 141 | static GdkWindow* wxGetGdkWindowForDC(wxWindow* win, wxDC& dc) |
| 142 | { |
| 143 | GdkWindow* gdk_window = NULL; |
| 144 | |
| 145 | #if wxUSE_GRAPHICS_CONTEXT |
| 146 | if ( dc.IsKindOf( CLASSINFO(wxGCDC) ) ) |
| 147 | gdk_window = win->GTKGetDrawingWindow(); |
| 148 | else |
| 149 | #endif |
| 150 | { |
| 151 | #if wxUSE_NEW_DC |
| 152 | wxDCImpl *impl = dc.GetImpl(); |
| 153 | wxGTKDCImpl *gtk_impl = wxDynamicCast( impl, wxGTKDCImpl ); |
| 154 | if (gtk_impl) |
| 155 | gdk_window = gtk_impl->GetGDKWindow(); |
| 156 | #else |
| 157 | gdk_window = dc.GetGDKWindow(); |
| 158 | #endif |
| 159 | } |
| 160 | |
| 161 | #if !wxUSE_GRAPHICS_CONTEXT |
| 162 | wxUnusedVar(win); |
| 163 | #endif |
| 164 | |
| 165 | return gdk_window; |
| 166 | } |
| 167 | |
| 168 | // ---------------------------------------------------------------------------- |
| 169 | // list/tree controls drawing |
| 170 | // ---------------------------------------------------------------------------- |
| 171 | |
| 172 | int |
| 173 | wxRendererGTK::DrawHeaderButton(wxWindow *win, |
| 174 | wxDC& dc, |
| 175 | const wxRect& rect, |
| 176 | int flags, |
| 177 | wxHeaderSortIconType sortArrow, |
| 178 | wxHeaderButtonParams* params) |
| 179 | { |
| 180 | |
| 181 | GtkWidget *button = wxGTKPrivate::GetHeaderButtonWidget(); |
| 182 | if (flags & wxCONTROL_SPECIAL) |
| 183 | button = wxGTKPrivate::GetHeaderButtonWidgetFirst(); |
| 184 | if (flags & wxCONTROL_DIRTY) |
| 185 | button = wxGTKPrivate::GetHeaderButtonWidgetLast(); |
| 186 | |
| 187 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
| 188 | wxASSERT_MSG( gdk_window, |
| 189 | wxT("cannot use wxRendererNative on wxDC of this type") ); |
| 190 | |
| 191 | int x_diff = 0; |
| 192 | if (win->GetLayoutDirection() == wxLayout_RightToLeft) |
| 193 | x_diff = rect.width; |
| 194 | |
| 195 | GtkStateType state = GTK_STATE_NORMAL; |
| 196 | if (flags & wxCONTROL_DISABLED) |
| 197 | state = GTK_STATE_INSENSITIVE; |
| 198 | else |
| 199 | { |
| 200 | if (flags & wxCONTROL_CURRENT) |
| 201 | state = GTK_STATE_PRELIGHT; |
| 202 | } |
| 203 | |
| 204 | gtk_paint_box |
| 205 | ( |
| 206 | button->style, |
| 207 | gdk_window, |
| 208 | state, |
| 209 | GTK_SHADOW_OUT, |
| 210 | NULL, |
| 211 | button, |
| 212 | "button", |
| 213 | dc.LogicalToDeviceX(rect.x) - x_diff, rect.y, rect.width, rect.height |
| 214 | ); |
| 215 | |
| 216 | return DrawHeaderButtonContents(win, dc, rect, flags, sortArrow, params); |
| 217 | } |
| 218 | |
| 219 | int wxRendererGTK::GetHeaderButtonHeight(wxWindow *WXUNUSED(win)) |
| 220 | { |
| 221 | GtkWidget *button = wxGTKPrivate::GetHeaderButtonWidget(); |
| 222 | |
| 223 | GtkRequisition req; |
| 224 | GTK_WIDGET_GET_CLASS(button)->size_request(button, &req); |
| 225 | |
| 226 | return req.height; |
| 227 | } |
| 228 | |
| 229 | |
| 230 | // draw a ">" or "v" button |
| 231 | void |
| 232 | wxRendererGTK::DrawTreeItemButton(wxWindow* win, |
| 233 | wxDC& dc, const wxRect& rect, int flags) |
| 234 | { |
| 235 | GtkWidget *tree = wxGTKPrivate::GetTreeWidget(); |
| 236 | |
| 237 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
| 238 | wxASSERT_MSG( gdk_window, |
| 239 | wxT("cannot use wxRendererNative on wxDC of this type") ); |
| 240 | |
| 241 | GtkStateType state; |
| 242 | if ( flags & wxCONTROL_CURRENT ) |
| 243 | state = GTK_STATE_PRELIGHT; |
| 244 | else |
| 245 | state = GTK_STATE_NORMAL; |
| 246 | |
| 247 | int x_diff = 0; |
| 248 | if (win->GetLayoutDirection() == wxLayout_RightToLeft) |
| 249 | x_diff = rect.width; |
| 250 | |
| 251 | // VZ: I don't know how to get the size of the expander so as to centre it |
| 252 | // in the given rectangle, +2/3 below is just what looks good here... |
| 253 | gtk_paint_expander |
| 254 | ( |
| 255 | tree->style, |
| 256 | gdk_window, |
| 257 | state, |
| 258 | NULL, |
| 259 | tree, |
| 260 | "treeview", |
| 261 | dc.LogicalToDeviceX(rect.x) + 6 - x_diff, |
| 262 | dc.LogicalToDeviceY(rect.y) + 3, |
| 263 | flags & wxCONTROL_EXPANDED ? GTK_EXPANDER_EXPANDED |
| 264 | : GTK_EXPANDER_COLLAPSED |
| 265 | ); |
| 266 | } |
| 267 | |
| 268 | |
| 269 | // ---------------------------------------------------------------------------- |
| 270 | // splitter sash drawing |
| 271 | // ---------------------------------------------------------------------------- |
| 272 | |
| 273 | static int GetGtkSplitterFullSize(GtkWidget* widget) |
| 274 | { |
| 275 | gint handle_size; |
| 276 | gtk_widget_style_get(widget, "handle_size", &handle_size, NULL); |
| 277 | |
| 278 | return handle_size; |
| 279 | } |
| 280 | |
| 281 | wxSplitterRenderParams |
| 282 | wxRendererGTK::GetSplitterParams(const wxWindow *WXUNUSED(win)) |
| 283 | { |
| 284 | // we don't draw any border, hence 0 for the second field |
| 285 | return wxSplitterRenderParams |
| 286 | ( |
| 287 | GetGtkSplitterFullSize(wxGTKPrivate::GetSplitterWidget()), |
| 288 | 0, |
| 289 | true // hot sensitive |
| 290 | ); |
| 291 | } |
| 292 | |
| 293 | void |
| 294 | wxRendererGTK::DrawSplitterBorder(wxWindow * WXUNUSED(win), |
| 295 | wxDC& WXUNUSED(dc), |
| 296 | const wxRect& WXUNUSED(rect), |
| 297 | int WXUNUSED(flags)) |
| 298 | { |
| 299 | // nothing to do |
| 300 | } |
| 301 | |
| 302 | void |
| 303 | wxRendererGTK::DrawSplitterSash(wxWindow* win, |
| 304 | wxDC& dc, |
| 305 | const wxSize& size, |
| 306 | wxCoord position, |
| 307 | wxOrientation orient, |
| 308 | int flags) |
| 309 | { |
| 310 | if ( !win->m_wxwindow->window ) |
| 311 | { |
| 312 | // window not realized yet |
| 313 | return; |
| 314 | } |
| 315 | |
| 316 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
| 317 | wxASSERT_MSG( gdk_window, |
| 318 | wxT("cannot use wxRendererNative on wxDC of this type") ); |
| 319 | |
| 320 | wxCoord full_size = GetGtkSplitterFullSize(wxGTKPrivate::GetSplitterWidget()); |
| 321 | |
| 322 | // are we drawing vertical or horizontal splitter? |
| 323 | const bool isVert = orient == wxVERTICAL; |
| 324 | |
| 325 | GdkRectangle rect; |
| 326 | |
| 327 | if ( isVert ) |
| 328 | { |
| 329 | rect.x = position; |
| 330 | rect.y = 0; |
| 331 | rect.width = full_size; |
| 332 | rect.height = size.y; |
| 333 | } |
| 334 | else // horz |
| 335 | { |
| 336 | rect.x = 0; |
| 337 | rect.y = position; |
| 338 | rect.height = full_size; |
| 339 | rect.width = size.x; |
| 340 | } |
| 341 | |
| 342 | int x_diff = 0; |
| 343 | if (win->GetLayoutDirection() == wxLayout_RightToLeft) |
| 344 | x_diff = rect.width; |
| 345 | |
| 346 | gtk_paint_handle |
| 347 | ( |
| 348 | win->m_wxwindow->style, |
| 349 | gdk_window, |
| 350 | flags & wxCONTROL_CURRENT ? GTK_STATE_PRELIGHT : GTK_STATE_NORMAL, |
| 351 | GTK_SHADOW_NONE, |
| 352 | NULL /* no clipping */, |
| 353 | win->m_wxwindow, |
| 354 | "paned", |
| 355 | dc.LogicalToDeviceX(rect.x) - x_diff, |
| 356 | dc.LogicalToDeviceY(rect.y), |
| 357 | rect.width, |
| 358 | rect.height, |
| 359 | isVert ? GTK_ORIENTATION_VERTICAL : GTK_ORIENTATION_HORIZONTAL |
| 360 | ); |
| 361 | } |
| 362 | |
| 363 | void |
| 364 | wxRendererGTK::DrawDropArrow(wxWindow* win, |
| 365 | wxDC& dc, |
| 366 | const wxRect& rect, |
| 367 | int flags) |
| 368 | { |
| 369 | GtkWidget *button = wxGTKPrivate::GetButtonWidget(); |
| 370 | |
| 371 | // If we give WX_PIZZA(win->m_wxwindow)->bin_window as |
| 372 | // a window for gtk_paint_xxx function, then it won't |
| 373 | // work for wxMemoryDC. So that is why we assume wxDC |
| 374 | // is wxWindowDC (wxClientDC, wxMemoryDC and wxPaintDC |
| 375 | // are derived from it) and use its m_window. |
| 376 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
| 377 | wxASSERT_MSG( gdk_window, |
| 378 | wxT("cannot use wxRendererNative on wxDC of this type") ); |
| 379 | |
| 380 | // draw arrow so that there is even space horizontally |
| 381 | // on both sides |
| 382 | int arrowX = rect.width/4 + 1; |
| 383 | int arrowWidth = rect.width - (arrowX*2); |
| 384 | |
| 385 | // scale arrow's height accoording to the width |
| 386 | int arrowHeight = rect.width/3; |
| 387 | int arrowY = (rect.height-arrowHeight)/2 + |
| 388 | ((rect.height-arrowHeight) & 1); |
| 389 | |
| 390 | GtkStateType state; |
| 391 | |
| 392 | if ( flags & wxCONTROL_PRESSED ) |
| 393 | state = GTK_STATE_ACTIVE; |
| 394 | else if ( flags & wxCONTROL_DISABLED ) |
| 395 | state = GTK_STATE_INSENSITIVE; |
| 396 | else if ( flags & wxCONTROL_CURRENT ) |
| 397 | state = GTK_STATE_PRELIGHT; |
| 398 | else |
| 399 | state = GTK_STATE_NORMAL; |
| 400 | |
| 401 | // draw arrow on button |
| 402 | gtk_paint_arrow |
| 403 | ( |
| 404 | button->style, |
| 405 | gdk_window, |
| 406 | state, |
| 407 | flags & wxCONTROL_PRESSED ? GTK_SHADOW_IN : GTK_SHADOW_OUT, |
| 408 | NULL, |
| 409 | button, |
| 410 | "arrow", |
| 411 | GTK_ARROW_DOWN, |
| 412 | FALSE, |
| 413 | rect.x + arrowX, |
| 414 | rect.y + arrowY, |
| 415 | arrowWidth, |
| 416 | arrowHeight |
| 417 | ); |
| 418 | } |
| 419 | |
| 420 | void |
| 421 | wxRendererGTK::DrawComboBoxDropButton(wxWindow *win, |
| 422 | wxDC& dc, |
| 423 | const wxRect& rect, |
| 424 | int flags) |
| 425 | { |
| 426 | DrawPushButton(win,dc,rect,flags); |
| 427 | DrawDropArrow(win,dc,rect); |
| 428 | } |
| 429 | |
| 430 | wxSize |
| 431 | wxRendererGTK::GetCheckBoxSize(wxWindow *WXUNUSED(win)) |
| 432 | { |
| 433 | gint indicator_size, indicator_spacing; |
| 434 | gtk_widget_style_get(wxGTKPrivate::GetCheckButtonWidget(), |
| 435 | "indicator_size", &indicator_size, |
| 436 | "indicator_spacing", &indicator_spacing, |
| 437 | NULL); |
| 438 | |
| 439 | int size = indicator_size + indicator_spacing * 2; |
| 440 | return wxSize(size, size); |
| 441 | } |
| 442 | |
| 443 | void |
| 444 | wxRendererGTK::DrawCheckBox(wxWindow* win, |
| 445 | wxDC& dc, |
| 446 | const wxRect& rect, |
| 447 | int flags ) |
| 448 | { |
| 449 | GtkWidget *button = wxGTKPrivate::GetCheckButtonWidget(); |
| 450 | |
| 451 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
| 452 | wxASSERT_MSG( gdk_window, |
| 453 | wxT("cannot use wxRendererNative on wxDC of this type") ); |
| 454 | |
| 455 | gint indicator_size, indicator_spacing; |
| 456 | gtk_widget_style_get(button, |
| 457 | "indicator_size", &indicator_size, |
| 458 | "indicator_spacing", &indicator_spacing, |
| 459 | NULL); |
| 460 | |
| 461 | GtkStateType state; |
| 462 | |
| 463 | if ( flags & wxCONTROL_PRESSED ) |
| 464 | state = GTK_STATE_ACTIVE; |
| 465 | else if ( flags & wxCONTROL_DISABLED ) |
| 466 | state = GTK_STATE_INSENSITIVE; |
| 467 | else if ( flags & wxCONTROL_CURRENT ) |
| 468 | state = GTK_STATE_PRELIGHT; |
| 469 | else |
| 470 | state = GTK_STATE_NORMAL; |
| 471 | |
| 472 | gtk_paint_check |
| 473 | ( |
| 474 | button->style, |
| 475 | gdk_window, |
| 476 | state, |
| 477 | flags & wxCONTROL_CHECKED ? GTK_SHADOW_IN : GTK_SHADOW_OUT, |
| 478 | NULL, |
| 479 | button, |
| 480 | "cellcheck", |
| 481 | dc.LogicalToDeviceX(rect.x) + indicator_spacing, |
| 482 | dc.LogicalToDeviceY(rect.y) + indicator_spacing, |
| 483 | indicator_size, indicator_size |
| 484 | ); |
| 485 | } |
| 486 | |
| 487 | void |
| 488 | wxRendererGTK::DrawPushButton(wxWindow* win, |
| 489 | wxDC& dc, |
| 490 | const wxRect& rect, |
| 491 | int flags) |
| 492 | { |
| 493 | GtkWidget *button = wxGTKPrivate::GetButtonWidget(); |
| 494 | |
| 495 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
| 496 | wxASSERT_MSG( gdk_window, |
| 497 | wxT("cannot use wxRendererNative on wxDC of this type") ); |
| 498 | |
| 499 | // draw button |
| 500 | GtkStateType state; |
| 501 | |
| 502 | if ( flags & wxCONTROL_PRESSED ) |
| 503 | state = GTK_STATE_ACTIVE; |
| 504 | else if ( flags & wxCONTROL_DISABLED ) |
| 505 | state = GTK_STATE_INSENSITIVE; |
| 506 | else if ( flags & wxCONTROL_CURRENT ) |
| 507 | state = GTK_STATE_PRELIGHT; |
| 508 | else |
| 509 | state = GTK_STATE_NORMAL; |
| 510 | |
| 511 | gtk_paint_box |
| 512 | ( |
| 513 | button->style, |
| 514 | gdk_window, |
| 515 | state, |
| 516 | flags & wxCONTROL_PRESSED ? GTK_SHADOW_IN : GTK_SHADOW_OUT, |
| 517 | NULL, |
| 518 | button, |
| 519 | "button", |
| 520 | dc.LogicalToDeviceX(rect.x), |
| 521 | dc.LogicalToDeviceY(rect.y), |
| 522 | rect.width, |
| 523 | rect.height |
| 524 | ); |
| 525 | } |
| 526 | |
| 527 | void |
| 528 | wxRendererGTK::DrawItemSelectionRect(wxWindow* win, |
| 529 | wxDC& dc, |
| 530 | const wxRect& rect, |
| 531 | int flags ) |
| 532 | { |
| 533 | GtkWidget *tree = wxGTKPrivate::GetTreeWidget(); |
| 534 | |
| 535 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
| 536 | wxASSERT_MSG( gdk_window, |
| 537 | wxT("cannot use wxRendererNative on wxDC of this type") ); |
| 538 | |
| 539 | int x_diff = 0; |
| 540 | if (win->GetLayoutDirection() == wxLayout_RightToLeft) |
| 541 | x_diff = rect.width; |
| 542 | |
| 543 | GtkStateType state = GTK_STATE_NORMAL; |
| 544 | |
| 545 | if (flags & wxCONTROL_SELECTED) |
| 546 | { |
| 547 | // the wxCONTROL_FOCUSED state is deduced |
| 548 | // directly from the m_wxwindow by GTK+ |
| 549 | state = GTK_STATE_SELECTED; |
| 550 | |
| 551 | gtk_paint_flat_box( tree->style, // win->m_widget->style, |
| 552 | gdk_window, |
| 553 | state, |
| 554 | GTK_SHADOW_NONE, |
| 555 | NULL, |
| 556 | win->m_wxwindow, |
| 557 | "cell_even", |
| 558 | dc.LogicalToDeviceX(rect.x) - x_diff, |
| 559 | dc.LogicalToDeviceY(rect.y), |
| 560 | rect.width, |
| 561 | rect.height ); |
| 562 | } |
| 563 | else // !wxCONTROL_SELECTED |
| 564 | { |
| 565 | state = GTK_STATE_NORMAL; |
| 566 | } |
| 567 | |
| 568 | if ((flags & wxCONTROL_CURRENT) && (flags & wxCONTROL_FOCUSED)) |
| 569 | { |
| 570 | if (flags & wxCONTROL_SELECTED) |
| 571 | state = GTK_STATE_SELECTED; |
| 572 | |
| 573 | gtk_paint_focus( tree->style, |
| 574 | gdk_window, |
| 575 | state, |
| 576 | NULL, |
| 577 | win->m_wxwindow, |
| 578 | // Detail "treeview" causes warning with GTK+ 2.12 Clearlooks theme: |
| 579 | // "... no property named `row-ending-details'" |
| 580 | // Using "treeview-middle" would fix the warning, but the right |
| 581 | // edge of the focus rect is not getting erased properly either. |
| 582 | // Better to not specify this detail unless the drawing is fixed. |
| 583 | "", |
| 584 | dc.LogicalToDeviceX(rect.x), |
| 585 | dc.LogicalToDeviceY(rect.y), |
| 586 | rect.width, |
| 587 | rect.height ); |
| 588 | } |
| 589 | } |
| 590 | |
| 591 | void wxRendererGTK::DrawFocusRect(wxWindow* win, wxDC& dc, const wxRect& rect, int flags) |
| 592 | { |
| 593 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
| 594 | wxASSERT_MSG( gdk_window, |
| 595 | wxT("cannot use wxRendererNative on wxDC of this type") ); |
| 596 | |
| 597 | GtkStateType state; |
| 598 | if (flags & wxCONTROL_SELECTED) |
| 599 | state = GTK_STATE_SELECTED; |
| 600 | else |
| 601 | state = GTK_STATE_NORMAL; |
| 602 | |
| 603 | gtk_paint_focus( win->m_widget->style, |
| 604 | gdk_window, |
| 605 | state, |
| 606 | NULL, |
| 607 | win->m_wxwindow, |
| 608 | NULL, |
| 609 | dc.LogicalToDeviceX(rect.x), |
| 610 | dc.LogicalToDeviceY(rect.y), |
| 611 | rect.width, |
| 612 | rect.height ); |
| 613 | } |
| 614 | |
| 615 | // Uses the theme to draw the border and fill for something like a wxTextCtrl |
| 616 | void wxRendererGTK::DrawTextCtrl(wxWindow* win, wxDC& dc, const wxRect& rect, int flags) |
| 617 | { |
| 618 | GtkWidget *entry = wxGTKPrivate::GetTextEntryWidget(); |
| 619 | |
| 620 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
| 621 | |
| 622 | GtkStateType state = GTK_STATE_NORMAL; |
| 623 | if ( flags & wxCONTROL_DISABLED ) |
| 624 | state = GTK_STATE_INSENSITIVE; |
| 625 | |
| 626 | if (flags & wxCONTROL_CURRENT ) |
| 627 | GTK_WIDGET_SET_FLAGS( entry, GTK_HAS_FOCUS ); |
| 628 | else |
| 629 | GTK_WIDGET_UNSET_FLAGS( entry, GTK_HAS_FOCUS ); |
| 630 | |
| 631 | gtk_paint_shadow |
| 632 | ( |
| 633 | entry->style, |
| 634 | gdk_window, |
| 635 | state, |
| 636 | GTK_SHADOW_OUT, |
| 637 | NULL, |
| 638 | entry, |
| 639 | "entry", |
| 640 | dc.LogicalToDeviceX(rect.x), |
| 641 | dc.LogicalToDeviceY(rect.y), |
| 642 | rect.width, |
| 643 | rect.height |
| 644 | ); |
| 645 | } |
| 646 | |
| 647 | // Draw the equivallent of a wxComboBox |
| 648 | void wxRendererGTK::DrawComboBox(wxWindow* win, wxDC& dc, const wxRect& rect, int flags) |
| 649 | { |
| 650 | GtkWidget *combo = wxGTKPrivate::GetComboBoxWidget(); |
| 651 | |
| 652 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
| 653 | |
| 654 | GtkStateType state = GTK_STATE_NORMAL; |
| 655 | if ( flags & wxCONTROL_DISABLED ) |
| 656 | state = GTK_STATE_INSENSITIVE; |
| 657 | |
| 658 | if (flags & wxCONTROL_CURRENT ) |
| 659 | GTK_WIDGET_SET_FLAGS( combo, GTK_HAS_FOCUS ); |
| 660 | else |
| 661 | GTK_WIDGET_UNSET_FLAGS( combo, GTK_HAS_FOCUS ); |
| 662 | |
| 663 | gtk_paint_shadow |
| 664 | ( |
| 665 | combo->style, |
| 666 | gdk_window, |
| 667 | state, |
| 668 | GTK_SHADOW_OUT, |
| 669 | NULL, |
| 670 | combo, |
| 671 | "combobox", |
| 672 | dc.LogicalToDeviceX(rect.x), |
| 673 | dc.LogicalToDeviceY(rect.y), |
| 674 | rect.width, |
| 675 | rect.height |
| 676 | ); |
| 677 | |
| 678 | wxRect r = rect; |
| 679 | int extent = rect.height / 2; |
| 680 | r.x += rect.width - extent - extent/2; |
| 681 | r.y += extent/2; |
| 682 | r.width = extent; |
| 683 | r.height = extent; |
| 684 | |
| 685 | gtk_paint_arrow |
| 686 | ( |
| 687 | combo->style, |
| 688 | gdk_window, |
| 689 | state, |
| 690 | GTK_SHADOW_OUT, |
| 691 | NULL, |
| 692 | combo, |
| 693 | "arrow", |
| 694 | GTK_ARROW_DOWN, |
| 695 | TRUE, |
| 696 | dc.LogicalToDeviceX(r.x), |
| 697 | dc.LogicalToDeviceY(r.y), |
| 698 | r.width, |
| 699 | r.height |
| 700 | ); |
| 701 | |
| 702 | r = rect; |
| 703 | r.x += rect.width - 2*extent; |
| 704 | r.width = 2; |
| 705 | |
| 706 | gtk_paint_box |
| 707 | ( |
| 708 | combo->style, |
| 709 | gdk_window, |
| 710 | state, |
| 711 | GTK_SHADOW_ETCHED_OUT, |
| 712 | NULL, |
| 713 | combo, |
| 714 | "vseparator", |
| 715 | dc.LogicalToDeviceX(r.x), |
| 716 | dc.LogicalToDeviceY(r.y+1), |
| 717 | r.width, |
| 718 | r.height-2 |
| 719 | ); |
| 720 | } |
| 721 | |
| 722 | |
| 723 | void wxRendererGTK::DrawChoice(wxWindow* win, wxDC& dc, |
| 724 | const wxRect& rect, int flags) |
| 725 | { |
| 726 | DrawComboBox( win, dc, rect, flags ); |
| 727 | } |
| 728 | |
| 729 | |
| 730 | // Draw a themed radio button |
| 731 | void wxRendererGTK::DrawRadioBitmap(wxWindow* win, wxDC& dc, const wxRect& rect, int flags) |
| 732 | { |
| 733 | GtkWidget *button = wxGTKPrivate::GetRadioButtonWidget(); |
| 734 | |
| 735 | GdkWindow* gdk_window = wxGetGdkWindowForDC(win, dc); |
| 736 | |
| 737 | GtkShadowType shadow_type = GTK_SHADOW_OUT; |
| 738 | if ( flags & wxCONTROL_CHECKED ) |
| 739 | shadow_type = GTK_SHADOW_IN; |
| 740 | else if ( flags & wxCONTROL_UNDETERMINED ) |
| 741 | shadow_type = GTK_SHADOW_ETCHED_IN; |
| 742 | |
| 743 | GtkStateType state = GTK_STATE_NORMAL; |
| 744 | if ( flags & wxCONTROL_DISABLED ) |
| 745 | state = GTK_STATE_INSENSITIVE; |
| 746 | if ( flags & wxCONTROL_PRESSED ) |
| 747 | state = GTK_STATE_ACTIVE; |
| 748 | /* |
| 749 | Don't know when to set this |
| 750 | state_type = GTK_STATE_PRELIGHT; |
| 751 | */ |
| 752 | |
| 753 | gtk_paint_option |
| 754 | ( |
| 755 | button->style, |
| 756 | gdk_window, |
| 757 | state, |
| 758 | shadow_type, |
| 759 | NULL, |
| 760 | button, |
| 761 | "radiobutton", |
| 762 | dc.LogicalToDeviceX(rect.x), |
| 763 | dc.LogicalToDeviceY(rect.y), |
| 764 | rect.width, rect.height |
| 765 | ); |
| 766 | } |