diff dwt/widgets/TableItem.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
line wrap: on
line diff
--- a/dwt/widgets/TableItem.d	Mon May 12 15:36:37 2008 +0200
+++ b/dwt/widgets/TableItem.d	Mon May 12 19:13:01 2008 +0200
@@ -136,6 +136,79 @@
     return control;
 }
 
+Color _getBackground () {
+    void* ptr;
+    OS.gtk_tree_model_get1 (parent.modelHandle, handle, Table.BACKGROUND_COLUMN, &ptr);
+    if (ptr is null) return parent.getBackground ();
+    GdkColor* gdkColor = new GdkColor ();
+    *gdkColor = *cast(GdkColor*) ptr;
+    return Color.gtk_new (display, gdkColor);
+}
+
+Color _getBackground (int index) {
+    int count = Math.max (1, parent.columnCount);
+    if (0 > index || index > count - 1) return _getBackground ();
+    void* ptr;
+    int modelIndex = parent.columnCount is 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex;
+    OS.gtk_tree_model_get1 (parent.modelHandle, handle, modelIndex + Table.CELL_BACKGROUND, &ptr);
+    if (ptr is null) return _getBackground ();
+    GdkColor* gdkColor = new GdkColor ();
+    *gdkColor = *cast(GdkColor*) ptr;
+    return Color.gtk_new (display, gdkColor);
+}
+
+bool _getChecked () {
+    void* ptr;
+    OS.gtk_tree_model_get1 (parent.modelHandle, handle, Table.CHECKED_COLUMN, &ptr);
+    return ptr !is null;
+}
+
+Color _getForeground () {
+    void* ptr;
+    OS.gtk_tree_model_get1 (parent.modelHandle, handle, Table.FOREGROUND_COLUMN, &ptr);
+    if (ptr is null) return parent.getForeground ();
+    GdkColor* gdkColor = new GdkColor ();
+    *gdkColor = *cast(GdkColor*) ptr;
+    return Color.gtk_new (display, gdkColor);
+}
+
+Color _getForeground (int index) {
+    int count = Math.max (1, parent.columnCount);
+    if (0 > index || index > count - 1) return _getForeground ();
+    void* ptr;
+    int modelIndex =  parent.columnCount is 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex;
+    OS.gtk_tree_model_get1 (parent.modelHandle, handle, modelIndex + Table.CELL_FOREGROUND, &ptr);
+    if (ptr is null) return _getForeground ();
+    GdkColor* gdkColor = new GdkColor ();
+    *gdkColor = *cast(GdkColor*) ptr;
+    return Color.gtk_new (display, gdkColor);
+}
+
+Image _getImage (int index) {
+    int count = Math.max (1, parent.getColumnCount ());
+    if (0 > index || index > count - 1) return null;
+    void* ptr;
+    int modelIndex = parent.columnCount is 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex;
+    OS.gtk_tree_model_get1 (parent.modelHandle, handle, modelIndex + Table.CELL_PIXBUF, &ptr);
+    if (ptr is null) return null;
+    ImageList imageList = parent.imageList;
+    int imageIndex = imageList.indexOf (ptr);
+    if (imageIndex is -1) return null;
+    return imageList.get (imageIndex);
+}
+
+String _getText (int index) {
+    int count = Math.max (1, parent.getColumnCount ());
+    if (0 > index || index > count - 1) return "";
+    void* ptr;
+    int modelIndex = parent.columnCount is 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex;
+    OS.gtk_tree_model_get1 (parent.modelHandle, handle, modelIndex + Table.CELL_TEXT, &ptr);
+    if (ptr is null) return "";
+    char[] buffer = tango.stdc.stringz.fromStringz( cast(char*)ptr).dup;
+    OS.g_free (ptr);
+    return buffer;
+}
+
 protected override void checkSubclass () {
     if (!isValidSubclass ()) error (DWT.ERROR_INVALID_SUBCLASS);
 }
@@ -183,11 +256,7 @@
 public Color getBackground () {
     checkWidget ();
     if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED);
-    void* ptr;
-    OS.gtk_tree_model_get1 (parent.modelHandle, handle, Table.BACKGROUND_COLUMN, &ptr);
-    if (ptr is null) return parent.getBackground ();
-    GdkColor* gdkColor = cast(GdkColor*)ptr;
-    return Color.gtk_new (display, gdkColor);
+    return _getBackground ();
 }
 
 /**
@@ -225,6 +294,7 @@
     GdkRectangle rect;
     OS.gtk_tree_view_get_cell_area (parentHandle, path, column, &rect);
     OS.gtk_tree_path_free (path);
+    if ((parent.getStyle () & DWT.MIRRORED) !is 0) rect.x = parent.getClientWidth () - rect.width - rect.x;
     int right = rect.x + rect.width;
 
     int x, w;
@@ -257,7 +327,8 @@
             rect.width = Math.max (0, right - rect.x);
         }
     }
-    return new Rectangle (rect.x, rect.y, rect.width + 1, rect.height + 1);
+    int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0;
+    return new Rectangle (rect.x, rect.y, width, rect.height + 1);
 }
 
 /**
@@ -276,14 +347,7 @@
 public Color getBackground (int index) {
     checkWidget ();
     if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED);
-    int count = Math.max (1, parent.columnCount);
-    if (0 > index || index > count - 1) return getBackground ();
-    void* ptr;
-    int modelIndex = parent.columnCount is 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex;
-    OS.gtk_tree_model_get1 (parent.modelHandle, handle, modelIndex + Table.CELL_BACKGROUND, &ptr);
-    if (ptr is null) return getBackground ();
-    GdkColor* gdkColor = cast(GdkColor*)ptr;
-    return Color.gtk_new (display, gdkColor);
+    return _getBackground (index);
 }
 
 /**
@@ -314,6 +378,7 @@
     GdkRectangle rect;
     OS.gtk_tree_view_get_cell_area (parentHandle, path, column, &rect);
     OS.gtk_tree_path_free (path);
+    if ((parent.getStyle () & DWT.MIRRORED) !is 0) rect.x = parent.getClientWidth () - rect.width - rect.x;
 
     if (index is 0 && (parent.style & DWT.CHECK) !is 0) {
         if (OS.GTK_VERSION >= OS.buildVERSION (2, 1, 3)) {
@@ -330,7 +395,8 @@
             rect.width -= w + buffer;
         }
     }
-    return new Rectangle (rect.x, rect.y, rect.width + 1, rect.height + 1);
+    int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0;
+    return new Rectangle (rect.x, rect.y, width, rect.height + 1);
 }
 
 /**
@@ -349,9 +415,7 @@
     checkWidget();
     if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED);
     if ((parent.style & DWT.CHECK) is 0) return false;
-    void* ptr;
-    OS.gtk_tree_model_get1 (parent.modelHandle, handle, Table.CHECKED_COLUMN, &ptr);
-    return ptr !is null;
+    return _getChecked ();
 }
 
 /**
@@ -410,11 +474,7 @@
 public Color getForeground () {
     checkWidget ();
     if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED);
-    void* ptr;
-    OS.gtk_tree_model_get1 (parent.modelHandle, handle, Table.FOREGROUND_COLUMN, &ptr);
-    if (ptr is null) return parent.getForeground ();
-    GdkColor* gdkColor = cast(GdkColor*)ptr;
-    return Color.gtk_new (display, gdkColor);
+    return _getForeground ();
 }
 
 /**
@@ -434,14 +494,7 @@
 public Color getForeground (int index) {
     checkWidget ();
     if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED);
-    int count = Math.max (1, parent.columnCount);
-    if (0 > index || index > count - 1) return getForeground ();
-    void* ptr;
-    int modelIndex =  parent.columnCount is 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex;
-    OS.gtk_tree_model_get1 (parent.modelHandle, handle, modelIndex + Table.CELL_FOREGROUND, &ptr);
-    if (ptr is null) return getForeground ();
-    GdkColor* gdkColor = cast(GdkColor*)ptr;
-    return Color.gtk_new (display, gdkColor);
+    return _getForeground (index);
 }
 
 /**
@@ -484,16 +537,7 @@
 public Image getImage (int index) {
     checkWidget ();
     if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED);
-    int count = Math.max (1, parent.getColumnCount ());
-    if (0 > index || index > count - 1) return null;
-    void* ptr;
-    int modelIndex = parent.columnCount is 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex;
-    OS.gtk_tree_model_get1 (parent.modelHandle, handle, modelIndex + Table.CELL_PIXBUF, &ptr);
-    if (ptr is null) return null;
-    ImageList imageList = parent.imageList;
-    int imageIndex = imageList.indexOf (ptr);
-    if (imageIndex is -1) return null;
-    return imageList.get (imageIndex);
+    return _getImage (index);
 }
 
 /**
@@ -528,7 +572,7 @@
     OS.gtk_widget_realize (parentHandle);
     OS.gtk_tree_view_get_cell_area (parentHandle, path, column, &rect);
     OS.gtk_tree_path_free (path);
-
+    if ((parent.getStyle () & DWT.MIRRORED) !is 0) rect.x = parent.getClientWidth () - rect.width - rect.x;
     /*
     * The OS call gtk_cell_renderer_get_size() provides the width of image to be drawn
     * by the cell renderer.  If there is no image in the cell, the width is zero.  If the table contains
@@ -549,7 +593,8 @@
         OS.gtk_cell_renderer_get_size (pixbufRenderer, parentHandle, null, null, null, &w, null);
         rect.width = w;
     }
-    return new Rectangle (rect.x, rect.y, rect.width, rect.height + 1);
+    int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width : 0;
+    return new Rectangle (rect.x, rect.y, width, rect.height + 1);
 }
 
 /**
@@ -612,15 +657,7 @@
 public String getText (int index) {
     checkWidget ();
     if (!parent.checkData (this)) error (DWT.ERROR_WIDGET_DISPOSED);
-    int count = Math.max (1, parent.getColumnCount ());
-    if (0 > index || index > count - 1) return "";
-    char* ptr;
-    int modelIndex = parent.columnCount is 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex;
-    OS.gtk_tree_model_get1 (parent.modelHandle, handle, modelIndex + Table.CELL_TEXT, cast(void**) &ptr);
-    if (ptr is null) return "";
-    String res = tango.stdc.stringz.fromStringz( ptr ).dup;
-    OS.g_free (ptr);
-    return res;
+    return _getText (index);
 }
 
 /**
@@ -668,6 +705,7 @@
     GdkRectangle rect;
     OS.gtk_tree_view_get_cell_area (parentHandle, path, column, &rect);
     OS.gtk_tree_path_free (path);
+    if ((parent.getStyle () & DWT.MIRRORED) !is 0) rect.x = parent.getClientWidth () - rect.width - rect.x;
     int right = rect.x + rect.width;
 
     int x, w;
@@ -699,7 +737,8 @@
             rect.width = Math.max (0, right - rect.x);
         }
     }
-    return new Rectangle (rect.x, rect.y, rect.width + 1, rect.height + 1);
+    int width = OS.gtk_tree_view_column_get_visible (column) ? rect.width + 1 : 0;
+    return new Rectangle (rect.x, rect.y, width, rect.height + 1);
 }
 
 void redraw () {
@@ -753,6 +792,7 @@
     if (color !is null && color.isDisposed ()) {
         DWT.error (DWT.ERROR_INVALID_ARGUMENT);
     }
+    if (_getBackground ().opEquals (color)) return;
     GdkColor* gdkColor = color !is null ? color.handle : null;
     OS.gtk_list_store_set1 (parent.modelHandle, handle, Table.BACKGROUND_COLUMN, gdkColor);
     /*
@@ -791,6 +831,7 @@
     if (color !is null && color.isDisposed ()) {
         DWT.error (DWT.ERROR_INVALID_ARGUMENT);
     }
+    if (_getBackground (index).opEquals (color)) return;
     int count = Math.max (1, parent.getColumnCount ());
     if (0 > index || index > count - 1) return;
     int modelIndex = parent.columnCount is 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex;
@@ -848,6 +889,7 @@
 public void setChecked (bool checked) {
     checkWidget();
     if ((parent.style & DWT.CHECK) is 0) return;
+    if (_getChecked () is checked) return;
     OS.gtk_list_store_set1 (parent.modelHandle, handle, Table.CHECKED_COLUMN, cast(void*)cast(int)checked);
     /*
     * GTK+'s "inconsistent" state does not match DWT's concept of grayed.  To
@@ -880,9 +922,10 @@
     if (font !is null && font.isDisposed ()) {
         DWT.error (DWT.ERROR_INVALID_ARGUMENT);
     }
-    if (this.font is font) return;
-    if (this.font !is null && this.font ==/*eq*/font ) return;
+    Font oldFont = this.font;
+    if (oldFont is font) return;
     this.font = font;
+    if (oldFont !is null && oldFont.opEquals (font)) return;
     auto fontHandle = font !is null ? font.handle : null;
     OS.gtk_list_store_set1 (parent.modelHandle, handle, Table.FONT_COLUMN, fontHandle);
     /*
@@ -925,11 +968,13 @@
     int count = Math.max (1, parent.getColumnCount ());
     if (0 > index || index > count - 1) return;
     if (cellFont is null) {
+        if (font is null) return;
         cellFont = new Font [count];
     }
-    if (cellFont [index] is font) return;
-    if (cellFont [index] !is null && cellFont [index] ==/*eq*/ font) return;
+    Font oldFont = cellFont [index];
+    if (oldFont is font) return;
     cellFont [index] = font;
+    if (oldFont !is null && oldFont.opEquals (font)) return;
 
     int modelIndex = parent.columnCount is 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex;
     auto fontHandle  = font !is null ? font.handle : null;
@@ -994,6 +1039,7 @@
     if (color !is null && color.isDisposed ()) {
         DWT.error (DWT.ERROR_INVALID_ARGUMENT);
     }
+    if (_getForeground ().opEquals (color)) return;
     GdkColor* gdkColor = color !is null ? color.handle : null;
     OS.gtk_list_store_set1 (parent.modelHandle, handle, Table.FOREGROUND_COLUMN, gdkColor);
     /*
@@ -1032,6 +1078,7 @@
     if (color !is null && color.isDisposed ()) {
         DWT.error (DWT.ERROR_INVALID_ARGUMENT);
     }
+    if (_getForeground (index).opEquals (color)) return;
     int count = Math.max (1, parent.getColumnCount ());
     if (0 > index || index > count - 1) return;
     int modelIndex = parent.columnCount is 0 ? Table.FIRST_COLUMN : parent.columns [index].modelIndex;
@@ -1089,6 +1136,7 @@
 public void setGrayed (bool grayed) {
     checkWidget();
     if ((parent.style & DWT.CHECK) is 0) return;
+    if (this.grayed is grayed) return;
     this.grayed = grayed;
     /*
     * GTK+'s "inconsistent" state does not match DWT's concept of grayed.
@@ -1119,6 +1167,9 @@
     if (image !is null && image.isDisposed ()) {
         error(DWT.ERROR_INVALID_ARGUMENT);
     }
+    if (image !is null && image.type is DWT.ICON) {
+        if (image.opEquals (_getImage (index))) return;
+    }
     int count = Math.max (1, parent.getColumnCount ());
     if (0 > index || index > count - 1) return;
     void* pixbuf;
@@ -1161,7 +1212,7 @@
                     * the style.
                     */
                     auto style = OS.gtk_widget_get_modifier_style (parentHandle);
-                    OS.gtk_widget_modify_style (parentHandle, style);
+                    parent.modifyStyle (parentHandle, style);
                 }
             }
         }
@@ -1233,6 +1284,7 @@
 public void setText (int index, String string) {
     checkWidget ();
     if (string is null) error (DWT.ERROR_NULL_ARGUMENT);
+    if (_getText (index).equals (string)) return;
     int count = Math.max (1, parent.getColumnCount ());
     if (0 > index || index > count - 1) return;
     char* buffer = tango.stdc.stringz.toStringz( string );