Mercurial > projects > dwt-linux
comparison dwt/widgets/TreeItem.d @ 240:ce446666f5a2
Update to SWT 3.4M7
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Mon, 12 May 2008 19:13:01 +0200 |
parents | 380bad9f6852 |
children | 5a30aa9820f3 |
comparison
equal
deleted
inserted
replaced
239:06a1f6829310 | 240:ce446666f5a2 |
---|---|
219 | 219 |
220 protected override void checkSubclass () { | 220 protected override void checkSubclass () { |
221 if (!isValidSubclass ()) error (DWT.ERROR_INVALID_SUBCLASS); | 221 if (!isValidSubclass ()) error (DWT.ERROR_INVALID_SUBCLASS); |
222 } | 222 } |
223 | 223 |
224 Color _getBackground () { | |
225 void* ptr; | |
226 OS.gtk_tree_model_get1 (parent.modelHandle, handle, Tree.BACKGROUND_COLUMN, &ptr); | |
227 if (ptr is null) return parent.getBackground (); | |
228 GdkColor* gdkColor = new GdkColor (); | |
229 *gdkColor = *cast(GdkColor*) ptr; | |
230 return Color.gtk_new (display, gdkColor); | |
231 } | |
232 | |
233 Color _getBackground (int index) { | |
234 int count = Math.max (1, parent.columnCount); | |
235 if (0 > index || index > count - 1) return _getBackground (); | |
236 void* ptr; | |
237 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; | |
238 OS.gtk_tree_model_get1 (parent.modelHandle, handle, modelIndex + Tree.CELL_BACKGROUND, &ptr); | |
239 if (ptr is null) return _getBackground (); | |
240 GdkColor* gdkColor = new GdkColor (); | |
241 *gdkColor = *cast(GdkColor*) ptr; | |
242 return Color.gtk_new (display, gdkColor); | |
243 } | |
244 | |
245 bool _getChecked () { | |
246 void* ptr; | |
247 OS.gtk_tree_model_get1 (parent.modelHandle, handle, Tree.CHECKED_COLUMN, &ptr); | |
248 return ptr !is null; | |
249 } | |
250 | |
251 Color _getForeground () { | |
252 void* ptr; | |
253 OS.gtk_tree_model_get1 (parent.modelHandle, handle, Tree.FOREGROUND_COLUMN, &ptr); | |
254 if (ptr is null) return parent.getForeground (); | |
255 GdkColor* gdkColor = new GdkColor (); | |
256 *gdkColor = *cast(GdkColor*) ptr; | |
257 return Color.gtk_new (display, gdkColor); | |
258 } | |
259 | |
260 Color _getForeground (int index) { | |
261 int count = Math.max (1, parent.columnCount); | |
262 if (0 > index || index > count - 1) return _getForeground (); | |
263 void* ptr; | |
264 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; | |
265 OS.gtk_tree_model_get1 (parent.modelHandle, handle, modelIndex + Tree.CELL_FOREGROUND, &ptr); | |
266 if (ptr is null) return _getForeground (); | |
267 GdkColor* gdkColor = new GdkColor (); | |
268 *gdkColor = *cast(GdkColor*) ptr; | |
269 return Color.gtk_new (display, gdkColor); | |
270 } | |
271 | |
272 Image _getImage (int index) { | |
273 int count = Math.max (1, parent.getColumnCount ()); | |
274 if (0 > index || index > count - 1) return null; | |
275 void* ptr; | |
276 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; | |
277 OS.gtk_tree_model_get1 (parent.modelHandle, handle, modelIndex + Tree.CELL_PIXBUF, &ptr); | |
278 if (ptr is null) return null; | |
279 ImageList imageList = parent.imageList; | |
280 int imageIndex = imageList.indexOf (ptr); | |
281 if (imageIndex is -1) return null; | |
282 return imageList.get (imageIndex); | |
283 } | |
284 | |
285 String _getText (int index) { | |
286 int count = Math.max (1, parent.getColumnCount ()); | |
287 if (0 > index || index > count - 1) return ""; | |
288 void* ptr; | |
289 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; | |
290 OS.gtk_tree_model_get1 (parent.modelHandle, handle, modelIndex + Tree.CELL_TEXT, &ptr); | |
291 if (ptr is null) return ""; //$NON-NLS-1$ | |
292 char[] buffer = tango.stdc.stringz.fromStringz( cast(char*)ptr).dup; | |
293 OS.g_free (ptr); | |
294 return buffer; | |
295 } | |
296 | |
224 void clear () { | 297 void clear () { |
225 if (parent.currentItem is this) return; | 298 if (parent.currentItem is this) return; |
226 if (cached || (parent.style & DWT.VIRTUAL) is 0) { | 299 if (cached || (parent.style & DWT.VIRTUAL) is 0) { |
227 int columnCount = OS.gtk_tree_model_get_n_columns (parent.modelHandle); | 300 int columnCount = OS.gtk_tree_model_get_n_columns (parent.modelHandle); |
228 for (int i=Tree.CHECKED_COLUMN; i<columnCount; i++) { | 301 for (int i=Tree.CHECKED_COLUMN; i<columnCount; i++) { |
316 * | 389 * |
317 */ | 390 */ |
318 public Color getBackground () { | 391 public Color getBackground () { |
319 checkWidget (); | 392 checkWidget (); |
320 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | 393 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); |
321 void* ptr; | 394 return _getBackground (); |
322 OS.gtk_tree_model_get1 (parent.modelHandle, handle, Tree.BACKGROUND_COLUMN, &ptr); | |
323 if (ptr is null) return parent.getBackground (); | |
324 GdkColor* gdkColor = cast(GdkColor*)ptr; | |
325 return Color.gtk_new (display, gdkColor); | |
326 } | 395 } |
327 | 396 |
328 /** | 397 /** |
329 * Returns the background color at the given column index in the receiver. | 398 * Returns the background color at the given column index in the receiver. |
330 * | 399 * |
339 * @since 3.1 | 408 * @since 3.1 |
340 */ | 409 */ |
341 public Color getBackground (int index) { | 410 public Color getBackground (int index) { |
342 checkWidget (); | 411 checkWidget (); |
343 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | 412 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); |
344 int count = Math.max (1, parent.columnCount); | 413 return _getBackground (index); |
345 if (0 > index || index > count - 1) return getBackground (); | |
346 void* ptr; | |
347 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; | |
348 OS.gtk_tree_model_get1 (parent.modelHandle, handle, modelIndex + Tree.CELL_BACKGROUND, &ptr); | |
349 if (ptr is null) return getBackground (); | |
350 GdkColor* gdkColor = cast(GdkColor*)ptr; | |
351 return Color.gtk_new (display, gdkColor); | |
352 } | 414 } |
353 | 415 |
354 /** | 416 /** |
355 * Returns a rectangle describing the receiver's size and location | 417 * Returns a rectangle describing the receiver's size and location |
356 * relative to its parent at a column in the tree. | 418 * relative to its parent at a column in the tree. |
379 if (column is null) return new Rectangle (0, 0, 0, 0); | 441 if (column is null) return new Rectangle (0, 0, 0, 0); |
380 auto path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); | 442 auto path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); |
381 OS.gtk_widget_realize (parentHandle); | 443 OS.gtk_widget_realize (parentHandle); |
382 GdkRectangle rect; | 444 GdkRectangle rect; |
383 OS.gtk_tree_view_get_cell_area (parentHandle, path, column, &rect); | 445 OS.gtk_tree_view_get_cell_area (parentHandle, path, column, &rect); |
384 OS.gtk_tree_path_free (path); | 446 if ((parent.getStyle () & DWT.MIRRORED) !is 0) rect.x = parent.getClientWidth () - rect.width - rect.x; |
385 | 447 |
386 if (OS.GTK_VERSION < OS.buildVERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (parentHandle) is column) { | 448 if (OS.GTK_VERSION < OS.buildVERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (parentHandle) is column) { |
387 int buffer; | 449 int buffer; |
388 OS.gtk_widget_style_get1 (parentHandle, OS.expander_size.ptr, &buffer); | 450 OS.gtk_widget_style_get1 (parentHandle, OS.expander_size.ptr, &buffer); |
389 rect.x += buffer + TreeItem.EXPANDER_EXTRA_PADDING; | 451 rect.x += buffer + TreeItem.EXPANDER_EXTRA_PADDING; |
390 rect.width -= buffer + TreeItem.EXPANDER_EXTRA_PADDING; | 452 rect.width -= buffer + TreeItem.EXPANDER_EXTRA_PADDING; |
391 OS.gtk_widget_style_get1 (parentHandle, OS.horizontal_separator.ptr, &buffer); | 453 OS.gtk_widget_style_get1 (parentHandle, OS.horizontal_separator.ptr, &buffer); |
392 rect.x += buffer; | 454 rect.x += buffer; |
393 //rect.width -= buffer [0]; // TODO Is this required for some versions? | 455 //rect.width -= buffer [0]; // TODO Is this required for some versions? |
394 } | 456 } |
457 /* | |
458 * Bug in GTK. In GTK 2.8.x, the cell area is left aligned even | |
459 * when the widget is mirrored. The fix is to sum up the indentation | |
460 * of the expanders. | |
461 */ | |
462 if ((parent.getStyle () & DWT.MIRRORED) !is 0 && (OS.GTK_VERSION < OS.buildVERSION (2, 10, 0))) { | |
463 int depth = OS.gtk_tree_path_get_depth (path); | |
464 int expanderSize; | |
465 OS.gtk_widget_style_get1 (parentHandle, OS.expander_size.ptr, &expanderSize); | |
466 rect.x += depth * (expanderSize + TreeItem.EXPANDER_EXTRA_PADDING); | |
467 } | |
468 OS.gtk_tree_path_free (path); | |
395 | 469 |
396 if (index is 0 && (parent.style & DWT.CHECK) !is 0) { | 470 if (index is 0 && (parent.style & DWT.CHECK) !is 0) { |
397 if (OS.GTK_VERSION >= OS.buildVERSION (2, 1, 3)) { | 471 if (OS.GTK_VERSION >= OS.buildVERSION (2, 1, 3)) { |
398 int x, w; | 472 int x, w; |
399 OS.gtk_tree_view_column_cell_get_position (column, parent.checkRenderer, &x, &w); | 473 OS.gtk_tree_view_column_cell_get_position (column, parent.checkRenderer, &x, &w); |
406 OS.gtk_widget_style_get1 (parentHandle, OS.horizontal_separator.ptr, &buffer); | 480 OS.gtk_widget_style_get1 (parentHandle, OS.horizontal_separator.ptr, &buffer); |
407 rect.x += w + buffer; | 481 rect.x += w + buffer; |
408 rect.width -= w + buffer; | 482 rect.width -= w + buffer; |
409 } | 483 } |
410 } | 484 } |
411 return new Rectangle (rect.x, rect.y, rect.width + 1, rect.height + 1); | 485 int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0; |
486 return new Rectangle (rect.x, rect.y, width, rect.height + 1); | |
412 } | 487 } |
413 | 488 |
414 /** | 489 /** |
415 * Returns a rectangle describing the receiver's size and location | 490 * Returns a rectangle describing the receiver's size and location |
416 * relative to its parent. | 491 * relative to its parent. |
441 bool isExpanded = cast(bool)OS.gtk_tree_view_row_expanded (parentHandle, path); | 516 bool isExpanded = cast(bool)OS.gtk_tree_view_row_expanded (parentHandle, path); |
442 OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, isExpander, isExpanded); | 517 OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, isExpander, isExpanded); |
443 | 518 |
444 GdkRectangle rect; | 519 GdkRectangle rect; |
445 OS.gtk_tree_view_get_cell_area (parentHandle, path, column, &rect); | 520 OS.gtk_tree_view_get_cell_area (parentHandle, path, column, &rect); |
446 OS.gtk_tree_path_free (path); | 521 if ((parent.getStyle () & DWT.MIRRORED) !is 0) rect.x = parent.getClientWidth () - rect.width - rect.x; |
447 int right = rect.x + rect.width; | 522 int right = rect.x + rect.width; |
448 | 523 |
449 int x, w; | 524 int x, w; |
450 parent.ignoreSize = true; | 525 parent.ignoreSize = true; |
451 OS.gtk_cell_renderer_get_size (textRenderer, parentHandle, null, null, null, &w, null); | 526 OS.gtk_cell_renderer_get_size (textRenderer, parentHandle, null, null, null, &w, null); |
454 int buffer; | 529 int buffer; |
455 if (OS.GTK_VERSION < OS.buildVERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (parentHandle) is column) { | 530 if (OS.GTK_VERSION < OS.buildVERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (parentHandle) is column) { |
456 OS.gtk_widget_style_get1 (parentHandle, OS.expander_size.ptr, &buffer); | 531 OS.gtk_widget_style_get1 (parentHandle, OS.expander_size.ptr, &buffer); |
457 rect.x += buffer + TreeItem.EXPANDER_EXTRA_PADDING; | 532 rect.x += buffer + TreeItem.EXPANDER_EXTRA_PADDING; |
458 } | 533 } |
534 /* | |
535 * Bug in GTK. In GTK 2.8.x, the cell area is left aligned even | |
536 * when the widget is mirrored. The fix is to sum up the indentation | |
537 * of the expanders. | |
538 */ | |
539 if ((parent.getStyle () & DWT.MIRRORED) !is 0 && (OS.GTK_VERSION < OS.buildVERSION (2, 10, 0))) { | |
540 int depth = OS.gtk_tree_path_get_depth (path); | |
541 int expanderSize; | |
542 OS.gtk_widget_style_get1 (parentHandle, OS.expander_size.ptr, &expanderSize); | |
543 rect.x += depth * (expanderSize + TreeItem.EXPANDER_EXTRA_PADDING); | |
544 } | |
545 OS.gtk_tree_path_free (path); | |
546 | |
459 OS.gtk_widget_style_get1 (parentHandle, OS.horizontal_separator.ptr, &buffer); | 547 OS.gtk_widget_style_get1 (parentHandle, OS.horizontal_separator.ptr, &buffer); |
460 int horizontalSeparator = buffer; | 548 int horizontalSeparator = buffer; |
461 rect.x += horizontalSeparator; | 549 rect.x += horizontalSeparator; |
462 | 550 |
463 if (OS.GTK_VERSION >= OS.buildVERSION (2, 1, 3)) { | 551 if (OS.GTK_VERSION >= OS.buildVERSION (2, 1, 3)) { |
474 if (parent.columnCount > 0) { | 562 if (parent.columnCount > 0) { |
475 if (rect.x + rect.width > right) { | 563 if (rect.x + rect.width > right) { |
476 rect.width = Math.max (0, right - rect.x); | 564 rect.width = Math.max (0, right - rect.x); |
477 } | 565 } |
478 } | 566 } |
479 return new Rectangle (rect.x, rect.y, rect.width + 1, rect.height + 1); | 567 int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0; |
568 return new Rectangle (rect.x, rect.y, width, rect.height + 1); | |
480 } | 569 } |
481 | 570 |
482 /** | 571 /** |
483 * Returns <code>true</code> if the receiver is checked, | 572 * Returns <code>true</code> if the receiver is checked, |
484 * and false otherwise. When the parent does not have | 573 * and false otherwise. When the parent does not have |
494 */ | 583 */ |
495 public bool getChecked () { | 584 public bool getChecked () { |
496 checkWidget(); | 585 checkWidget(); |
497 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | 586 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); |
498 if ((parent.style & DWT.CHECK) is 0) return false; | 587 if ((parent.style & DWT.CHECK) is 0) return false; |
499 void* ptr; | 588 return _getChecked (); |
500 OS.gtk_tree_model_get1 (parent.modelHandle, handle, Tree.CHECKED_COLUMN, &ptr); | |
501 return ptr !is null; | |
502 } | 589 } |
503 | 590 |
504 /** | 591 /** |
505 * Returns <code>true</code> if the receiver is expanded, | 592 * Returns <code>true</code> if the receiver is expanded, |
506 * and false otherwise. | 593 * and false otherwise. |
577 * | 664 * |
578 */ | 665 */ |
579 public Color getForeground () { | 666 public Color getForeground () { |
580 checkWidget (); | 667 checkWidget (); |
581 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | 668 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); |
582 void* ptr; | 669 return _getForeground (); |
583 OS.gtk_tree_model_get1 (parent.modelHandle, handle, Tree.FOREGROUND_COLUMN, &ptr); | |
584 if (ptr is null) return parent.getForeground (); | |
585 GdkColor* gdkColor = cast(GdkColor*)ptr; | |
586 return Color.gtk_new (display, gdkColor); | |
587 } | 670 } |
588 | 671 |
589 /** | 672 /** |
590 * | 673 * |
591 * Returns the foreground color at the given column index in the receiver. | 674 * Returns the foreground color at the given column index in the receiver. |
601 * @since 3.1 | 684 * @since 3.1 |
602 */ | 685 */ |
603 public Color getForeground (int index) { | 686 public Color getForeground (int index) { |
604 checkWidget (); | 687 checkWidget (); |
605 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | 688 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); |
606 int count = Math.max (1, parent.columnCount); | 689 return _getForeground (index); |
607 if (0 > index || index > count - 1) return getForeground (); | |
608 void* ptr; | |
609 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; | |
610 OS.gtk_tree_model_get1 (parent.modelHandle, handle, modelIndex + Tree.CELL_FOREGROUND, &ptr); | |
611 if (ptr is null) return getForeground (); | |
612 GdkColor* gdkColor = cast(GdkColor*)ptr; | |
613 return Color.gtk_new (display, gdkColor); | |
614 } | 690 } |
615 | 691 |
616 /** | 692 /** |
617 * Returns <code>true</code> if the receiver is grayed, | 693 * Returns <code>true</code> if the receiver is grayed, |
618 * and false otherwise. When the parent does not have | 694 * and false otherwise. When the parent does not have |
654 * @since 3.1 | 730 * @since 3.1 |
655 */ | 731 */ |
656 public Image getImage (int index) { | 732 public Image getImage (int index) { |
657 checkWidget (); | 733 checkWidget (); |
658 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | 734 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); |
659 int count = Math.max (1, parent.getColumnCount ()); | 735 return _getImage (index); |
660 if (0 > index || index > count - 1) return null; | |
661 void* ptr; | |
662 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; | |
663 OS.gtk_tree_model_get1 (parent.modelHandle, handle, modelIndex + Tree.CELL_PIXBUF, &ptr); | |
664 if (ptr is null) return null; | |
665 ImageList imageList = parent.imageList; | |
666 int imageIndex = imageList.indexOf (ptr); | |
667 if (imageIndex is -1) return null; | |
668 return imageList.get (imageIndex); | |
669 } | 736 } |
670 | 737 |
671 /** | 738 /** |
672 * Returns a rectangle describing the size and location | 739 * Returns a rectangle describing the size and location |
673 * relative to its parent of an image at a column in the | 740 * relative to its parent of an image at a column in the |
699 if (pixbufRenderer is null) return new Rectangle (0, 0, 0, 0); | 766 if (pixbufRenderer is null) return new Rectangle (0, 0, 0, 0); |
700 GdkRectangle rect; | 767 GdkRectangle rect; |
701 auto path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); | 768 auto path = OS.gtk_tree_model_get_path (parent.modelHandle, handle); |
702 OS.gtk_widget_realize (parentHandle); | 769 OS.gtk_widget_realize (parentHandle); |
703 OS.gtk_tree_view_get_cell_area (parentHandle, path, column, &rect); | 770 OS.gtk_tree_view_get_cell_area (parentHandle, path, column, &rect); |
704 OS.gtk_tree_path_free (path); | 771 if ((parent.getStyle () & DWT.MIRRORED) !is 0) rect.x = parent.getClientWidth () - rect.width - rect.x; |
705 | |
706 if (OS.GTK_VERSION < OS.buildVERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (parentHandle) is column) { | 772 if (OS.GTK_VERSION < OS.buildVERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (parentHandle) is column) { |
707 int buffer; | 773 int buffer; |
708 OS.gtk_widget_style_get1 (parentHandle, OS.expander_size.ptr, &buffer); | 774 OS.gtk_widget_style_get1 (parentHandle, OS.expander_size.ptr, &buffer); |
709 rect.x += buffer + TreeItem.EXPANDER_EXTRA_PADDING; | 775 rect.x += buffer + TreeItem.EXPANDER_EXTRA_PADDING; |
710 rect.width -= buffer + TreeItem.EXPANDER_EXTRA_PADDING; | 776 rect.width -= buffer + TreeItem.EXPANDER_EXTRA_PADDING; |
711 //OS.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0); | 777 //OS.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0); |
712 //int horizontalSeparator = buffer[0]; | 778 //int horizontalSeparator = buffer[0]; |
713 //rect.x += horizontalSeparator; | 779 //rect.x += horizontalSeparator; |
714 } | 780 } |
781 /* | |
782 * Bug in GTK. In GTK 2.8.x, the cell area is left aligned even | |
783 * when the widget is mirrored. The fix is to sum up the indentation | |
784 * of the expanders. | |
785 */ | |
786 if ((parent.getStyle () & DWT.MIRRORED) !is 0 && (OS.GTK_VERSION < OS.buildVERSION (2, 10, 0))) { | |
787 int depth = OS.gtk_tree_path_get_depth (path); | |
788 int expanderSize; | |
789 OS.gtk_widget_style_get1 (parentHandle, OS.expander_size.ptr, &expanderSize); | |
790 rect.x += depth * (expanderSize + TreeItem.EXPANDER_EXTRA_PADDING); | |
791 } | |
792 OS.gtk_tree_path_free (path); | |
715 | 793 |
716 /* | 794 /* |
717 * The OS call gtk_cell_renderer_get_size() provides the width of image to be drawn | 795 * The OS call gtk_cell_renderer_get_size() provides the width of image to be drawn |
718 * by the cell renderer. If there is no image in the cell, the width is zero. If the table contains | 796 * by the cell renderer. If there is no image in the cell, the width is zero. If the table contains |
719 * images of varying widths, gtk_cell_renderer_get_size() will return the width of the image, | 797 * images of varying widths, gtk_cell_renderer_get_size() will return the width of the image, |
731 int w; | 809 int w; |
732 OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, false, false); | 810 OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, false, false); |
733 OS.gtk_cell_renderer_get_size (pixbufRenderer, parentHandle, null, null, null, &w, null); | 811 OS.gtk_cell_renderer_get_size (pixbufRenderer, parentHandle, null, null, null, &w, null); |
734 rect.width = w; | 812 rect.width = w; |
735 } | 813 } |
736 return new Rectangle (rect.x, rect.y, rect.width, rect.height + 1); | 814 int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width : 0; |
815 return new Rectangle (rect.x, rect.y, width, rect.height + 1); | |
737 } | 816 } |
738 | 817 |
739 /** | 818 /** |
740 * Returns the number of items contained in the receiver | 819 * Returns the number of items contained in the receiver |
741 * that are direct item children of the receiver. | 820 * that are direct item children of the receiver. |
872 * @since 3.1 | 951 * @since 3.1 |
873 */ | 952 */ |
874 public String getText (int index) { | 953 public String getText (int index) { |
875 checkWidget (); | 954 checkWidget (); |
876 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); | 955 if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED); |
877 int count = Math.max (1, parent.getColumnCount ()); | 956 return _getText (index); |
878 if (0 > index || index > count - 1) return ""; | |
879 void* ptr; | |
880 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; | |
881 OS.gtk_tree_model_get1 (parent.modelHandle, handle, modelIndex + Tree.CELL_TEXT, &ptr); | |
882 if (ptr is null) return ""; //$NON-NLS-1$ | |
883 String res = tango.stdc.stringz.fromStringz( cast(char*)ptr ).dup; | |
884 OS.g_free (ptr); | |
885 return res; | |
886 } | 957 } |
887 | 958 |
888 /** | 959 /** |
889 * Returns a rectangle describing the size and location | 960 * Returns a rectangle describing the size and location |
890 * relative to its parent of the text at a column in the | 961 * relative to its parent of the text at a column in the |
926 bool isExpanded = cast(bool)OS.gtk_tree_view_row_expanded (parentHandle, path); | 997 bool isExpanded = cast(bool)OS.gtk_tree_view_row_expanded (parentHandle, path); |
927 OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, isExpander, isExpanded); | 998 OS.gtk_tree_view_column_cell_set_cell_data (column, parent.modelHandle, handle, isExpander, isExpanded); |
928 | 999 |
929 GdkRectangle rect; | 1000 GdkRectangle rect; |
930 OS.gtk_tree_view_get_cell_area (parentHandle, path, column, &rect); | 1001 OS.gtk_tree_view_get_cell_area (parentHandle, path, column, &rect); |
931 OS.gtk_tree_path_free (path); | 1002 if ((parent.getStyle () & DWT.MIRRORED) !is 0) rect.x = parent.getClientWidth () - rect.width - rect.x; |
932 int right = rect.x + rect.width; | 1003 int right = rect.x + rect.width; |
933 | 1004 |
934 int x, w; | 1005 int x, w; |
935 parent.ignoreSize = true; | 1006 parent.ignoreSize = true; |
936 OS.gtk_cell_renderer_get_size (textRenderer, parentHandle, null, null, null, &w, null); | 1007 OS.gtk_cell_renderer_get_size (textRenderer, parentHandle, null, null, null, &w, null); |
938 int buffer; | 1009 int buffer; |
939 if (OS.GTK_VERSION < OS.buildVERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (parentHandle) is column) { | 1010 if (OS.GTK_VERSION < OS.buildVERSION (2, 8, 18) && OS.gtk_tree_view_get_expander_column (parentHandle) is column) { |
940 OS.gtk_widget_style_get1 (parentHandle, OS.expander_size.ptr, &buffer); | 1011 OS.gtk_widget_style_get1 (parentHandle, OS.expander_size.ptr, &buffer); |
941 rect.x += buffer + TreeItem.EXPANDER_EXTRA_PADDING; | 1012 rect.x += buffer + TreeItem.EXPANDER_EXTRA_PADDING; |
942 } | 1013 } |
1014 /* | |
1015 * Bug in GTK. In GTK 2.8.x, the cell area is left aligned even | |
1016 * when the widget is mirrored. The fix is to sum up the indentation | |
1017 * of the expanders. | |
1018 */ | |
1019 if ((parent.getStyle () & DWT.MIRRORED) !is 0 && (OS.GTK_VERSION < OS.buildVERSION (2, 10, 0))) { | |
1020 int depth = OS.gtk_tree_path_get_depth (path); | |
1021 int expanderSize; | |
1022 OS.gtk_widget_style_get1 (parentHandle, OS.expander_size.ptr, &expanderSize); | |
1023 rect.x += depth * (expanderSize + TreeItem.EXPANDER_EXTRA_PADDING); | |
1024 } | |
1025 OS.gtk_tree_path_free (path); | |
1026 | |
943 OS.gtk_widget_style_get1 (parentHandle, OS.horizontal_separator.ptr, &buffer); | 1027 OS.gtk_widget_style_get1 (parentHandle, OS.horizontal_separator.ptr, &buffer); |
944 int horizontalSeparator = buffer; | 1028 int horizontalSeparator = buffer; |
945 rect.x += horizontalSeparator; | 1029 rect.x += horizontalSeparator; |
946 if (OS.GTK_VERSION >= OS.buildVERSION (2, 1, 3)) { | 1030 if (OS.GTK_VERSION >= OS.buildVERSION (2, 1, 3)) { |
947 OS.gtk_tree_view_column_cell_get_position (column, textRenderer, &x, null); | 1031 OS.gtk_tree_view_column_cell_get_position (column, textRenderer, &x, null); |
957 if (parent.columnCount > 0) { | 1041 if (parent.columnCount > 0) { |
958 if (rect.x + rect.width > right) { | 1042 if (rect.x + rect.width > right) { |
959 rect.width = Math.max (0, right - rect.x); | 1043 rect.width = Math.max (0, right - rect.x); |
960 } | 1044 } |
961 } | 1045 } |
962 return new Rectangle (rect.x, rect.y, rect.width + 1, rect.height + 1); | 1046 int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0; |
1047 return new Rectangle (rect.x, rect.y, width, rect.height + 1); | |
963 } | 1048 } |
964 | 1049 |
965 /** | 1050 /** |
966 * Searches the receiver's list starting at the first item | 1051 * Searches the receiver's list starting at the first item |
967 * (index 0) until an item is found that is equal to the | 1052 * (index 0) until an item is found that is equal to the |
1093 public void setBackground (Color color) { | 1178 public void setBackground (Color color) { |
1094 checkWidget (); | 1179 checkWidget (); |
1095 if (color !is null && color.isDisposed ()) { | 1180 if (color !is null && color.isDisposed ()) { |
1096 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | 1181 DWT.error (DWT.ERROR_INVALID_ARGUMENT); |
1097 } | 1182 } |
1183 if (_getBackground ().opEquals (color)) return; | |
1098 GdkColor* gdkColor = color !is null ? color.handle : null; | 1184 GdkColor* gdkColor = color !is null ? color.handle : null; |
1099 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, Tree.BACKGROUND_COLUMN, gdkColor); | 1185 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, Tree.BACKGROUND_COLUMN, gdkColor); |
1100 /* | 1186 /* |
1101 * Bug in GTK. When using fixed-height-mode, | 1187 * Bug in GTK. When using fixed-height-mode, |
1102 * row changes do not cause the row to be repainted. The fix is to | 1188 * row changes do not cause the row to be repainted. The fix is to |
1132 public void setBackground (int index, Color color) { | 1218 public void setBackground (int index, Color color) { |
1133 checkWidget (); | 1219 checkWidget (); |
1134 if (color !is null && color.isDisposed ()) { | 1220 if (color !is null && color.isDisposed ()) { |
1135 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | 1221 DWT.error (DWT.ERROR_INVALID_ARGUMENT); |
1136 } | 1222 } |
1223 if (_getBackground (index).opEquals (color)) return; | |
1137 int count = Math.max (1, parent.getColumnCount ()); | 1224 int count = Math.max (1, parent.getColumnCount ()); |
1138 if (0 > index || index > count - 1) return; | 1225 if (0 > index || index > count - 1) return; |
1139 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; | 1226 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; |
1140 GdkColor* gdkColor = color !is null ? color.handle : null; | 1227 GdkColor* gdkColor = color !is null ? color.handle : null; |
1141 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, modelIndex + Tree.CELL_BACKGROUND, gdkColor); | 1228 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, modelIndex + Tree.CELL_BACKGROUND, gdkColor); |
1189 * </ul> | 1276 * </ul> |
1190 */ | 1277 */ |
1191 public void setChecked (bool checked) { | 1278 public void setChecked (bool checked) { |
1192 checkWidget(); | 1279 checkWidget(); |
1193 if ((parent.style & DWT.CHECK) is 0) return; | 1280 if ((parent.style & DWT.CHECK) is 0) return; |
1281 if (_getChecked () is checked) return; | |
1194 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, Tree.CHECKED_COLUMN, cast(void*)cast(int)checked); | 1282 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, Tree.CHECKED_COLUMN, cast(void*)cast(int)checked); |
1195 /* | 1283 /* |
1196 * GTK+'s "inconsistent" state does not match DWT's concept of grayed. To | 1284 * GTK+'s "inconsistent" state does not match DWT's concept of grayed. To |
1197 * show checked+grayed differently from unchecked+grayed, we must toggle the | 1285 * show checked+grayed differently from unchecked+grayed, we must toggle the |
1198 * grayed state on check and uncheck. | 1286 * grayed state on check and uncheck. |
1250 public void setFont (Font font){ | 1338 public void setFont (Font font){ |
1251 checkWidget (); | 1339 checkWidget (); |
1252 if (font !is null && font.isDisposed ()) { | 1340 if (font !is null && font.isDisposed ()) { |
1253 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | 1341 DWT.error (DWT.ERROR_INVALID_ARGUMENT); |
1254 } | 1342 } |
1255 if (this.font is font) return; | 1343 Font oldFont = this.font; |
1256 if (this.font !is null && this.font ==/*eq*/font) return; | 1344 if (oldFont is font) return; |
1257 this.font = font; | 1345 this.font = font; |
1258 auto fontHandle = font !is null ? font.handle : null; | 1346 if (oldFont !is null && oldFont.opEquals (font)) return; |
1347 void* fontHandle = font !is null ? font.handle : null; | |
1259 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, Tree.FONT_COLUMN, fontHandle); | 1348 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, Tree.FONT_COLUMN, fontHandle); |
1260 /* | 1349 /* |
1261 * Bug in GTK. When using fixed-height-mode, | 1350 * Bug in GTK. When using fixed-height-mode, |
1262 * row changes do not cause the row to be repainted. The fix is to | 1351 * row changes do not cause the row to be repainted. The fix is to |
1263 * invalidate the row when it is cleared. | 1352 * invalidate the row when it is cleared. |
1295 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | 1384 DWT.error (DWT.ERROR_INVALID_ARGUMENT); |
1296 } | 1385 } |
1297 int count = Math.max (1, parent.getColumnCount ()); | 1386 int count = Math.max (1, parent.getColumnCount ()); |
1298 if (0 > index || index > count - 1) return; | 1387 if (0 > index || index > count - 1) return; |
1299 if (cellFont is null) { | 1388 if (cellFont is null) { |
1389 if (font is null) return; | |
1300 cellFont = new Font [count]; | 1390 cellFont = new Font [count]; |
1301 } | 1391 } |
1302 if (cellFont [index] is font) return; | 1392 Font oldFont = cellFont [index]; |
1303 if (cellFont [index] !is null && cellFont [index] ==/*eq*/font ) return; | 1393 if (oldFont is font) return; |
1304 cellFont [index] = font; | 1394 cellFont [index] = font; |
1395 if (oldFont !is null && oldFont.opEquals (font)) return; | |
1305 | 1396 |
1306 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; | 1397 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; |
1307 auto fontHandle = font !is null ? font.handle : null; | 1398 auto fontHandle = font !is null ? font.handle : null; |
1308 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, modelIndex + Tree.CELL_FONT, fontHandle); | 1399 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, modelIndex + Tree.CELL_FONT, fontHandle); |
1309 /* | 1400 /* |
1367 public void setForeground (Color color){ | 1458 public void setForeground (Color color){ |
1368 checkWidget (); | 1459 checkWidget (); |
1369 if (color !is null && color.isDisposed ()) { | 1460 if (color !is null && color.isDisposed ()) { |
1370 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | 1461 DWT.error (DWT.ERROR_INVALID_ARGUMENT); |
1371 } | 1462 } |
1463 if (_getForeground ().opEquals (color)) return; | |
1372 GdkColor *gdkColor = color !is null ? color.handle : null; | 1464 GdkColor *gdkColor = color !is null ? color.handle : null; |
1373 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, Tree.FOREGROUND_COLUMN, gdkColor); | 1465 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, Tree.FOREGROUND_COLUMN, gdkColor); |
1374 /* | 1466 /* |
1375 * Bug in GTK. When using fixed-height-mode, | 1467 * Bug in GTK. When using fixed-height-mode, |
1376 * row changes do not cause the row to be repainted. The fix is to | 1468 * row changes do not cause the row to be repainted. The fix is to |
1406 public void setForeground (int index, Color color){ | 1498 public void setForeground (int index, Color color){ |
1407 checkWidget (); | 1499 checkWidget (); |
1408 if (color !is null && color.isDisposed ()) { | 1500 if (color !is null && color.isDisposed ()) { |
1409 DWT.error (DWT.ERROR_INVALID_ARGUMENT); | 1501 DWT.error (DWT.ERROR_INVALID_ARGUMENT); |
1410 } | 1502 } |
1503 if (_getForeground (index).opEquals (color)) return; | |
1411 int count = Math.max (1, parent.getColumnCount ()); | 1504 int count = Math.max (1, parent.getColumnCount ()); |
1412 if (0 > index || index > count - 1) return; | 1505 if (0 > index || index > count - 1) return; |
1413 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; | 1506 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; |
1414 GdkColor *gdkColor = color !is null ? color.handle : null; | 1507 GdkColor *gdkColor = color !is null ? color.handle : null; |
1415 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, modelIndex + Tree.CELL_FOREGROUND, gdkColor); | 1508 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, modelIndex + Tree.CELL_FOREGROUND, gdkColor); |
1463 * </ul> | 1556 * </ul> |
1464 */ | 1557 */ |
1465 public void setGrayed (bool grayed) { | 1558 public void setGrayed (bool grayed) { |
1466 checkWidget(); | 1559 checkWidget(); |
1467 if ((parent.style & DWT.CHECK) is 0) return; | 1560 if ((parent.style & DWT.CHECK) is 0) return; |
1561 if (this.grayed is grayed) return; | |
1468 this.grayed = grayed; | 1562 this.grayed = grayed; |
1469 /* | 1563 /* |
1470 * GTK+'s "inconsistent" state does not match DWT's concept of grayed. | 1564 * GTK+'s "inconsistent" state does not match DWT's concept of grayed. |
1471 * Render checked+grayed as "inconsistent", unchecked+grayed as blank. | 1565 * Render checked+grayed as "inconsistent", unchecked+grayed as blank. |
1472 */ | 1566 */ |
1494 */ | 1588 */ |
1495 public void setImage (int index, Image image) { | 1589 public void setImage (int index, Image image) { |
1496 checkWidget (); | 1590 checkWidget (); |
1497 if (image !is null && image.isDisposed()) { | 1591 if (image !is null && image.isDisposed()) { |
1498 error(DWT.ERROR_INVALID_ARGUMENT); | 1592 error(DWT.ERROR_INVALID_ARGUMENT); |
1593 } | |
1594 if (image !is null && image.type is DWT.ICON) { | |
1595 if (image.opEquals (_getImage (index))) return; | |
1499 } | 1596 } |
1500 int count = Math.max (1, parent.getColumnCount ()); | 1597 int count = Math.max (1, parent.getColumnCount ()); |
1501 if (0 > index || index > count - 1) return; | 1598 if (0 > index || index > count - 1) return; |
1502 GdkPixbuf* pixbuf; | 1599 GdkPixbuf* pixbuf; |
1503 if (image !is null) { | 1600 if (image !is null) { |
1539 * There is no direct way to clear the cell renderer width so we | 1636 * There is no direct way to clear the cell renderer width so we |
1540 * are relying on the fact that it is done as part of modifying | 1637 * are relying on the fact that it is done as part of modifying |
1541 * the style. | 1638 * the style. |
1542 */ | 1639 */ |
1543 auto style = OS.gtk_widget_get_modifier_style (parentHandle); | 1640 auto style = OS.gtk_widget_get_modifier_style (parentHandle); |
1544 OS.gtk_widget_modify_style (parentHandle, style); | 1641 parent.modifyStyle (parentHandle, style); |
1545 } | 1642 } |
1546 } | 1643 } |
1547 } | 1644 } |
1548 } | 1645 } |
1549 cached = true; | 1646 cached = true; |
1613 * @since 3.1 | 1710 * @since 3.1 |
1614 */ | 1711 */ |
1615 public void setText (int index, String string) { | 1712 public void setText (int index, String string) { |
1616 checkWidget (); | 1713 checkWidget (); |
1617 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); | 1714 if (string is null) error (DWT.ERROR_NULL_ARGUMENT); |
1715 if (_getText (index).equals (string)) return; | |
1618 int count = Math.max (1, parent.getColumnCount ()); | 1716 int count = Math.max (1, parent.getColumnCount ()); |
1619 if (0 > index || index > count - 1) return; | 1717 if (0 > index || index > count - 1) return; |
1620 char* buffer = tango.stdc.stringz.toStringz(string); | 1718 char* buffer = tango.stdc.stringz.toStringz(string); |
1621 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; | 1719 int modelIndex = parent.columnCount is 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; |
1622 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, modelIndex + Tree.CELL_TEXT, buffer); | 1720 OS.gtk_tree_store_set1 (parent.modelHandle, cast(GtkTreeIter*)handle, modelIndex + Tree.CELL_TEXT, buffer); |