From addf7d8e73363865180c612729af6205fe0e22da Mon Sep 17 00:00:00 2001
From: Vasili Gulevich
* Here is an example of using a Tree with style VIRTUAL:
- * final Tree tree = new Tree(parent, SWT.VIRTUAL | SWT.BORDER);
- * tree.setItemCount(20);
- * tree.addListener(SWT.SetData, new Listener() {
- * public void handleEvent(Event event) {
+ * final Tree tree = new Tree (parent, SWT.VIRTUAL | SWT.BORDER);
+ * tree.setItemCount (20);
+ * tree.addListener (SWT.SetData, new Listener () {
+ * public void handleEvent (Event event) {
* TreeItem item = (TreeItem)event.item;
- * TreeItem parentItem = item.getParentItem();
+ * TreeItem parentItem = item.getParentItem ();
* String text = null;
* if (parentItem == null) {
- * text = "node " + tree.indexOf(item);
+ * text = "node " + tree.indexOf (item);
* } else {
- * text = parentItem.getText() + " - " + parentItem.indexOf(item);
+ * text = parentItem.getText () + " - " + parentItem.indexOf (item);
* }
- * item.setText(text);
- * System.out.println(text);
- * item.setItemCount(10);
+ * item.setText (text);
+ * System.out.println (text);
+ * item.setItemCount (10);
* }
* });
*
@@ -87,7 +87,7 @@ public class Tree extends Composite {
int columnCount, sortDirection;
int selectionCountOnPress,selectionCountOnRelease;
long ignoreCell;
- TreeItem[] items;
+ TreeItem [] items;
int nextId;
TreeColumn [] columns;
TreeColumn sortColumn;
@@ -205,14 +205,14 @@ TreeItem _getItem (long parentIter, long iter, int index) {
return items [id] = new TreeItem (this, parentIter, SWT.NONE, index, iter);
}
-void reallocateIds(int newSize) {
+void reallocateIds (int newSize) {
TreeItem [] newItems = new TreeItem [newSize];
System.arraycopy (items, 0, newItems, 0, items.length);
items = newItems;
}
-int findAvailableId() {
- // Adapt to cases where items[] array was resized since last search
+int findAvailableId () {
+ // Adapt to cases where items [] array was resized since last search
// This also fixes cases where +1 below went too far
if (nextId >= items.length)
nextId = 0;
@@ -232,7 +232,7 @@ int findAvailableId() {
if (drawCount <= 0) {
reallocateIds (items.length + 4);
} else {
- // '.setRedraw(false)' is typically used during bulk operations.
+ // '.setRedraw (false)' is typically used during bulk operations.
// Reallocate to 1.5x the old size to avoid frequent reallocations.
reallocateIds ((items.length + 1) * 3 / 2);
}
@@ -242,12 +242,12 @@ int findAvailableId() {
int getId (long iter, boolean queryModel) {
if (queryModel) {
- int[] value = new int[1];
+ int [] value = new int [1];
GTK.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, value, -1);
if (value [0] != -1) return value [0];
}
- int id = findAvailableId();
+ int id = findAvailableId ();
nextId = id + 1;
GTK.gtk_tree_store_set (modelHandle, iter, ID_COLUMN, id, -1);
@@ -319,8 +319,8 @@ long cellDataProc (long tree_column, long cell, long tree_model, long iter, long
ptr [0] = 0;
GTK.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_TEXT, ptr, -1);
if (ptr [0] != 0) {
- OS.g_object_set (cell, OS.text, ptr[0], 0);
- OS.g_free (ptr[0]);
+ OS.g_object_set (cell, OS.text, ptr [0], 0);
+ OS.g_free (ptr [0]);
}
}
}
@@ -329,8 +329,8 @@ long cellDataProc (long tree_column, long cell, long tree_model, long iter, long
ptr [0] = 0;
GTK.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_BACKGROUND, ptr, -1);
if (ptr [0] != 0) {
- OS.g_object_set (cell, OS.cell_background_rgba, ptr[0], 0);
- GDK.gdk_rgba_free(ptr [0]);
+ OS.g_object_set (cell, OS.cell_background_rgba, ptr [0], 0);
+ GDK.gdk_rgba_free (ptr [0]);
}
}
if (!isPixbuf) {
@@ -343,7 +343,7 @@ long cellDataProc (long tree_column, long cell, long tree_model, long iter, long
ptr [0] = 0;
GTK.gtk_tree_model_get (tree_model, iter, modelIndex + CELL_FONT, ptr, -1);
if (ptr [0] != 0) {
- OS.g_object_set (cell, OS.font_desc, ptr[0], 0);
+ OS.g_object_set (cell, OS.font_desc, ptr [0], 0);
OS.pango_font_description_free (ptr [0]);
}
}
@@ -439,7 +439,7 @@ public void addSelectionListener (SelectionListener listener) {
* @see TreeListener
* @see #removeTreeListener
*/
-public void addTreeListener(TreeListener listener) {
+public void addTreeListener (TreeListener listener) {
checkWidget ();
if (listener == null) error (SWT.ERROR_NULL_ARGUMENT);
TypedListener typedListener = new TypedListener (listener);
@@ -450,7 +450,7 @@ public void addTreeListener(TreeListener listener) {
int calculateWidth (long column, long iter, boolean recurse) {
GTK.gtk_tree_view_column_cell_set_cell_data (column, modelHandle, iter, false, false);
/*
- * Bug in GTK. The width calculated by gtk_tree_view_column_cell_get_size()
+ * Bug in GTK. The width calculated by gtk_tree_view_column_cell_get_size ()
* always grows in size regardless of the text or images in the table.
* The fix is to determine the column width from the cell renderers.
*/
@@ -464,16 +464,16 @@ int calculateWidth (long column, long iter, boolean recurse) {
long path = 0;
/*
- * gtk_tree_view_get_expander_column() returns 0 if the expander column is not visible.
+ * gtk_tree_view_get_expander_column () returns 0 if the expander column is not visible.
* When pack is called for the first time, the expander arrow indent is not added to
* the width for the expander column. The fix is to always get the expander column as if
* it is visible.
*/
- long expander_column = GTK.gtk_tree_view_get_expander_column(handle);
- if (expander_column == 0 && !GTK.gtk_tree_view_column_get_visible(column)) {
- GTK.gtk_tree_view_column_set_visible(column, true);
- expander_column = GTK.gtk_tree_view_get_expander_column(handle);
- GTK.gtk_tree_view_column_set_visible(column, false);
+ long expander_column = GTK.gtk_tree_view_get_expander_column (handle);
+ if (expander_column == 0 && !GTK.gtk_tree_view_column_get_visible (column)) {
+ GTK.gtk_tree_view_column_set_visible (column, true);
+ expander_column = GTK.gtk_tree_view_get_expander_column (handle);
+ GTK.gtk_tree_view_column_set_visible (column, false);
}
if (expander_column == column) {
/* indent */
@@ -483,11 +483,11 @@ int calculateWidth (long column, long iter, boolean recurse) {
GTK.gtk_tree_view_get_cell_area (handle, path, column, rect);
width += rect.x;
/* expander */
- if (!GTK.gtk_tree_view_column_get_visible(column)) {
+ if (!GTK.gtk_tree_view_column_get_visible (column)) {
if (GTK.GTK4) {
- long image = GTK4.gtk_image_new_from_icon_name(GTK.GTK_NAMED_ICON_PAN_DOWN);
+ long image = GTK4.gtk_image_new_from_icon_name (GTK.GTK_NAMED_ICON_PAN_DOWN);
GtkRequisition requisition = new GtkRequisition ();
- GTK.gtk_widget_get_preferred_size(image, requisition, null);
+ GTK.gtk_widget_get_preferred_size (image, requisition, null);
width += requisition.width + TreeItem.EXPANDER_EXTRA_PADDING;
} else {
GTK3.gtk_widget_style_get (handle, OS.expander_size, w, 0);
@@ -500,10 +500,10 @@ int calculateWidth (long column, long iter, boolean recurse) {
* to the size of the widget.
*/
if (!GTK.GTK4) {
- GTK3.gtk_widget_style_get(handle, OS.focus_line_width, w, 0);
+ GTK3.gtk_widget_style_get (handle, OS.focus_line_width, w, 0);
width += 2 * w [0];
}
- long list = GTK.gtk_cell_layout_get_cells(column);
+ long list = GTK.gtk_cell_layout_get_cells (column);
if (list == 0) return 0;
long temp = list;
while (temp != 0) {
@@ -531,7 +531,7 @@ int calculateWidth (long column, long iter, boolean recurse) {
}
if (path != 0) GTK.gtk_tree_path_free (path);
- if (GTK.gtk_tree_view_get_grid_lines(handle) > GTK.GTK_TREE_VIEW_GRID_LINES_NONE) {
+ if (GTK.gtk_tree_view_get_grid_lines (handle) > GTK.GTK_TREE_VIEW_GRID_LINES_NONE) {
/*
* Grid line width is handled via CSS in GTK4.
*/
@@ -566,15 +566,15 @@ int calculateWidth (long column, long iter, boolean recurse) {
*
* @since 3.2
*/
-public void clear(int index, boolean all) {
+public void clear (int index, boolean all) {
checkWidget ();
clear (0, index, all);
}
void clear (long parentIter, int index, boolean all) {
long iter = OS.g_malloc (GTK.GtkTreeIter_sizeof ());
- GTK.gtk_tree_model_iter_nth_child(modelHandle, iter, parentIter, index);
- int[] value = new int[1];
+ GTK.gtk_tree_model_iter_nth_child (modelHandle, iter, parentIter, index);
+ int [] value = new int [1];
GTK.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, value, -1);
if (value [0] != -1) {
TreeItem item = items [value [0]];
@@ -612,7 +612,7 @@ void clearAll (boolean all, long parentIter) {
if (length == 0) return;
long iter = OS.g_malloc (GTK.GtkTreeIter_sizeof ());
boolean valid = GTK.gtk_tree_model_iter_children (modelHandle, iter, parentIter);
- int[] value = new int[1];
+ int [] value = new int [1];
while (valid) {
GTK.gtk_tree_model_get (modelHandle, iter, ID_COLUMN, value, -1);
if (value [0] != -1) {
@@ -632,31 +632,31 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
/*
* Bug 546490: Set all the TreeColumn buttons visible otherwise
- * gtk_widget_get_preferred_size() will not take their size
+ * gtk_widget_get_preferred_size () will not take their size
* into account.
*/
if (!GTK.GTK4) {
if (firstCompute) {
for (TreeColumn column : columns) {
- if (column != null) GTK.gtk_widget_set_visible(column.buttonHandle, true);
+ if (column != null) GTK.gtk_widget_set_visible (column.buttonHandle, true);
}
firstCompute = false;
}
}
- GTK.gtk_widget_realize(handle);
+ GTK.gtk_widget_realize (handle);
Point size = computeNativeSize (handle, wHint, hHint, changed);
/*
- * In GTK 3, computeNativeSize(..) sometimes just returns the header
+ * In GTK 3, computeNativeSize (..) sometimes just returns the header
* height as height. In that case, calculate the tree height based on
* the number of items at the root of the tree.
*/
- if (hHint == SWT.DEFAULT && size.y == getHeaderHeight()) {
- int itemHeight = getItemHeightInPixels();
+ if (hHint == SWT.DEFAULT && size.y == getHeaderHeight ()) {
+ int itemHeight = getItemHeightInPixels ();
// Initialize to height of root items & header
- size.y = getItemCount() * itemHeight + getHeaderHeight();
+ size.y = getItemCount () * itemHeight + getHeaderHeight ();
for (TreeItem item : items) {
if (item != null && item.isExpanded) {
@@ -685,7 +685,7 @@ Point computeSizeInPixels (int wHint, int hHint, boolean changed) {
}
void copyModel (long oldModel, int oldStart, long newModel, int newStart, long oldParent, long newParent, int modelLength) {
- long iter = OS.g_malloc(GTK.GtkTreeIter_sizeof ());
+ long iter = OS.g_malloc (GTK.GtkTreeIter_sizeof ());
long value = OS.g_malloc (OS.GValue_sizeof ());
// GValue needs to be initialized with G_VALUE_INIT, which is zeroes
C.memset (value, 0, OS.GValue_sizeof ());
@@ -699,13 +699,13 @@ void copyModel (long oldModel, int oldStart, long newModel, int newStart, long o
if (newIterator == 0) error (SWT.ERROR_NO_HANDLES);
GTK.gtk_tree_store_append (newModel, newIterator, newParent);
GTK.gtk_tree_model_get (oldModel, iter, ID_COLUMN, intBuffer, -1);
- int index = intBuffer[0];
+ int index = intBuffer [0];
TreeItem item = null;
if (index != -1) {
item = items [index];
if (item != null) {
long oldIterator = item.handle;
- oldItems[oldIndex++] = oldIterator;
+ oldItems [oldIndex++] = oldIterator;
// Copy header fields
for (int iColumn = 0; iColumn < FIRST_COLUMN; iColumn++) {
@@ -725,14 +725,14 @@ void copyModel (long oldModel, int oldStart, long newModel, int newStart, long o
GTK.gtk_tree_store_set (newModel, newIterator, ID_COLUMN, -1, -1);
}
// recurse through children
- copyModel(oldModel, oldStart, newModel, newStart, iter, newIterator, modelLength);
+ copyModel (oldModel, oldStart, newModel, newStart, iter, newIterator, modelLength);
if (item!= null) {
item.handle = newIterator;
} else {
OS.g_free (newIterator);
}
- } while (GTK.gtk_tree_model_iter_next(oldModel, iter));
+ } while (GTK.gtk_tree_model_iter_next (oldModel, iter));
for (int i = 0; i < oldItems.length; i++) {
long oldItem = oldItems [i];
if (oldItem != 0) {
@@ -819,9 +819,9 @@ void createHandle (int index) {
fixedHandle = OS.g_object_new (display.gtk_fixed_get_type (), 0);
if (fixedHandle == 0) error (SWT.ERROR_NO_HANDLES);
if (GTK.GTK4) {
- scrolledHandle = GTK4.gtk_scrolled_window_new();
+ scrolledHandle = GTK4.gtk_scrolled_window_new ();
} else {
- GTK3.gtk_widget_set_has_window(fixedHandle, true);
+ GTK3.gtk_widget_set_has_window (fixedHandle, true);
scrolledHandle = GTK3.gtk_scrolled_window_new (0, 0);
}
if (scrolledHandle == 0) error (SWT.ERROR_NO_HANDLES);
@@ -838,8 +838,8 @@ void createHandle (int index) {
createColumn (null, 0);
if (GTK.GTK4) {
- OS.swt_fixed_add(fixedHandle, scrolledHandle);
- GTK4.gtk_scrolled_window_set_child(scrolledHandle, handle);
+ OS.swt_fixed_add (fixedHandle, scrolledHandle);
+ GTK4.gtk_scrolled_window_set_child (scrolledHandle, handle);
} else {
GTK3.gtk_container_add (fixedHandle, scrolledHandle);
GTK3.gtk_container_add (scrolledHandle, handle);
@@ -854,7 +854,7 @@ void createHandle (int index) {
GTK.gtk_scrolled_window_set_policy (scrolledHandle, hsp, vsp);
if ((style & SWT.BORDER) != 0) {
if (GTK.GTK4) {
- GTK4.gtk_scrolled_window_set_has_frame(scrolledHandle, true);
+ GTK4.gtk_scrolled_window_set_has_frame (scrolledHandle, true);
} else {
GTK3.gtk_scrolled_window_set_shadow_type (scrolledHandle, GTK.GTK_SHADOW_ETCHED_IN);
}
@@ -869,7 +869,7 @@ void createHandle (int index) {
GTK.gtk_tree_view_set_search_column (handle, -1);
}
- if (GTK.GTK4) bindArrowKeyBindings();
+ if (GTK.GTK4) bindArrowKeyBindings ();
}
/**
@@ -880,23 +880,23 @@ void createHandle (int index) {
* Note: This function is to only be called in GTK4.
* Binding of the arrow keys are also done in GTK3,
* however it is done through GtkBindingSets in CSS.
- * See Device.init() for more information, specifically,
+ * See Device.init () for more information, specifically,
* swt_functional_gtk_3_20.css
*/
-void bindArrowKeyBindings() {
+void bindArrowKeyBindings () {
if (!GTK.GTK4) return;
- int[] keyval = new int[1];
- GTK.gtk_accelerator_parse(Converter.javaStringToCString("Left"), keyval, null);
- GTK4.gtk_widget_class_add_binding_signal(GTK.GTK_WIDGET_GET_CLASS(handle), keyval[0], 0,
- Converter.javaStringToCString("expand-collapse-cursor-row"),
- Converter.javaStringToCString("(bbb)"),
+ int [] keyval = new int [1];
+ GTK.gtk_accelerator_parse (Converter.javaStringToCString ("Left"), keyval, null);
+ GTK4.gtk_widget_class_add_binding_signal (GTK.GTK_WIDGET_GET_CLASS (handle), keyval [0], 0,
+ Converter.javaStringToCString ("expand-collapse-cursor-row"),
+ Converter.javaStringToCString ("(bbb)"),
false, false, false);
- GTK.gtk_accelerator_parse(Converter.javaStringToCString("Right"), keyval, null);
- GTK4.gtk_widget_class_add_binding_signal(GTK.GTK_WIDGET_GET_CLASS(handle), keyval[0], 0,
- Converter.javaStringToCString("expand-collapse-cursor-row"),
- Converter.javaStringToCString("(bbb)"),
+ GTK.gtk_accelerator_parse (Converter.javaStringToCString ("Right"), keyval, null);
+ GTK4.gtk_widget_class_add_binding_signal (GTK.GTK_WIDGET_GET_CLASS (handle), keyval [0], 0,
+ Converter.javaStringToCString ("expand-collapse-cursor-row"),
+ Converter.javaStringToCString ("(bbb)"),
false, true, false);
}
@@ -931,10 +931,10 @@ void createItem (TreeColumn column, int index) {
if (imageHandle == 0) error (SWT.ERROR_NO_HANDLES);
if (GTK.GTK4) {
- GTK4.gtk_box_append(boxHandle, imageHandle);
- GTK4.gtk_box_append(boxHandle, labelHandle);
+ GTK4.gtk_box_append (boxHandle, imageHandle);
+ GTK4.gtk_box_append (boxHandle, labelHandle);
- GTK.gtk_widget_hide(imageHandle);
+ GTK.gtk_widget_hide (imageHandle);
} else {
GTK3.gtk_container_add (boxHandle, imageHandle);
GTK3.gtk_container_add (boxHandle, labelHandle);
@@ -946,8 +946,8 @@ void createItem (TreeColumn column, int index) {
column.labelHandle = labelHandle;
column.imageHandle = imageHandle;
GTK.gtk_tree_view_column_set_widget (column.handle, boxHandle);
- column.buttonHandle = GTK.gtk_tree_view_column_get_button(column.handle);
- GTK.gtk_widget_set_focus_on_click(column.buttonHandle, false);
+ column.buttonHandle = GTK.gtk_tree_view_column_get_button (column.handle);
+ GTK.gtk_widget_set_focus_on_click (column.buttonHandle, false);
if (columnCount == columns.length) {
TreeColumn [] newColumns = new TreeColumn [columns.length + 4];
System.arraycopy (columns, 0, newColumns, 0, columns.length);
@@ -984,11 +984,11 @@ void createItem (TreeColumn column, int index) {
}
}
- updateHeaderCSS();
+ updateHeaderCSS ();
}
/**
- * The fastest way to insert many items is documented in {@link TreeItem#TreeItem(org.eclipse.swt.widgets.Tree,int,int)}
+ * The fastest way to insert many items is documented in {@link TreeItem#TreeItem (org.eclipse.swt.widgets.Tree,int,int)}
* and {@link TreeItem#setItemCount}
*/
void createItem (TreeItem item, long parentIter, int index) {
@@ -999,22 +999,22 @@ void createItem (TreeItem item, long parentIter, int index) {
*/
if (index == 0) {
item.handle = OS.g_malloc (GTK.GtkTreeIter_sizeof ());
- if (item.handle == 0) error(SWT.ERROR_NO_HANDLES);
+ if (item.handle == 0) error (SWT.ERROR_NO_HANDLES);
GTK.gtk_tree_store_prepend (modelHandle, item.handle, parentIter);
} else if (index == -1) {
item.handle = OS.g_malloc (GTK.GtkTreeIter_sizeof ());
- if (item.handle == 0) error(SWT.ERROR_NO_HANDLES);
+ if (item.handle == 0) error (SWT.ERROR_NO_HANDLES);
GTK.gtk_tree_store_append (modelHandle, item.handle, parentIter);
} else {
int count = GTK.gtk_tree_model_iter_n_children (modelHandle, parentIter);
if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE);
item.handle = OS.g_malloc (GTK.GtkTreeIter_sizeof ());
- if (item.handle == 0) error(SWT.ERROR_NO_HANDLES);
+ if (item.handle == 0) error (SWT.ERROR_NO_HANDLES);
/*
* Feature in GTK. It is much faster to append to a tree store
- * than to insert at the end using gtk_tree_store_insert().
+ * than to insert at the end using gtk_tree_store_insert ().
*/
if (index == count) {
GTK.gtk_tree_store_append (modelHandle, item.handle, parentIter);
@@ -1055,7 +1055,7 @@ void createRenderers (long columnHandle, int modelIndex, boolean check, int colu
long pixbufRenderer;
if (GTK.GTK4) {
- pixbufRenderer = GTK.gtk_cell_renderer_pixbuf_new();
+ pixbufRenderer = GTK.gtk_cell_renderer_pixbuf_new ();
} else {
pixbufRenderer = isOwnerDrawn ? OS.g_object_new (display.gtk_cell_renderer_pixbuf_get_type (), 0) : GTK.gtk_cell_renderer_pixbuf_new ();
}
@@ -1072,13 +1072,13 @@ void createRenderers (long columnHandle, int modelIndex, boolean check, int colu
* styles. Fix for bug 480261.
*/
if ((style & SWT.VIRTUAL) != 0 && pixbufSizeSet) {
- GTK.gtk_cell_renderer_set_fixed_size(pixbufRenderer, pixbufHeight, pixbufWidth);
+ GTK.gtk_cell_renderer_set_fixed_size (pixbufRenderer, pixbufHeight, pixbufWidth);
} else {
/*
* For all other styles, set render size to 0x0 until we
* actually add images, fix for bugs 469277 & 476419.
*/
- GTK.gtk_cell_renderer_set_fixed_size(pixbufRenderer, 0, 0);
+ GTK.gtk_cell_renderer_set_fixed_size (pixbufRenderer, 0, 0);
}
}
}
@@ -1102,12 +1102,12 @@ void createRenderers (long columnHandle, int modelIndex, boolean check, int colu
/* Set alignment */
if ((columnStyle & SWT.RIGHT) != 0) {
- OS.g_object_set(textRenderer, OS.xalign, 1f, 0);
+ OS.g_object_set (textRenderer, OS.xalign, 1f, 0);
GTK.gtk_tree_view_column_pack_end (columnHandle, textRenderer, true);
GTK.gtk_tree_view_column_pack_end (columnHandle, pixbufRenderer, false);
GTK.gtk_tree_view_column_set_alignment (columnHandle, 1f);
} else if ((columnStyle & SWT.CENTER) != 0) {
- OS.g_object_set(textRenderer, OS.xalign, 0.5f, 0);
+ OS.g_object_set (textRenderer, OS.xalign, 0.5f, 0);
GTK.gtk_tree_view_column_pack_start (columnHandle, pixbufRenderer, false);
GTK.gtk_tree_view_column_pack_end (columnHandle, textRenderer, true);
GTK.gtk_tree_view_column_set_alignment (columnHandle, 0.5f);
@@ -1156,12 +1156,12 @@ void createWidget (int index) {
columnCount = 0;
// In GTK 3 font description is inherited from parent widget which is not how SWT has always worked,
// reset to default font to get the usual behavior
- setFontDescription(defaultFont().handle);
+ setFontDescription (defaultFont ().handle);
}
@Override
GdkRGBA defaultBackground () {
- return display.getSystemColor(SWT.COLOR_LIST_BACKGROUND).handle;
+ return display.getSystemColor (SWT.COLOR_LIST_BACKGROUND).handle;
}
@Override
@@ -1209,8 +1209,8 @@ public void deselect (TreeItem item) {
* - * The fastest way to insert many items is documented in {@link TreeItem#TreeItem(Tree,int,int)} + * The fastest way to insert many items is documented in {@link TreeItem#TreeItem (Tree,int,int)} * and {@link TreeItem#setItemCount} * * @param count the number of items @@ -3596,7 +3596,7 @@ public void select (TreeItem item) { * */ public void selectAll () { - checkWidget(); + checkWidget (); if ((style & SWT.SINGLE) != 0) return; boolean fixColumn = showFirstColumn (); long selection = GTK.gtk_tree_view_get_selection (handle); @@ -3611,23 +3611,23 @@ void setBackgroundGdkRGBA (long context, long handle, GdkRGBA rgba) { /* Setting the background color overrides the selected background color. * To prevent this, we need to re-set the default. This can be done with CSS * on GTK3.14+, or by using GtkStateFlags as an argument to - * gtk_widget_override_background_color() on versions of GTK3 less than 3.16. + * gtk_widget_override_background_color () on versions of GTK3 less than 3.16. */ if (rgba == null) { - background = defaultBackground(); + background = defaultBackground (); } else { background = rgba; } - GdkRGBA selectedBackground = display.getSystemColor(SWT.COLOR_LIST_SELECTION).handle; - String css = "treeview {background-color: " + display.gtk_rgba_to_css_string(background) + ";}\n" - + "treeview:selected {background-color: " + display.gtk_rgba_to_css_string(selectedBackground) + ";}"; + GdkRGBA selectedBackground = display.getSystemColor (SWT.COLOR_LIST_SELECTION).handle; + String css = "treeview {background-color: " + display.gtk_rgba_to_css_string (background) + ";}\n" + + "treeview:selected {background-color: " + display.gtk_rgba_to_css_string (selectedBackground) + ";}"; // Cache background color cssBackground = css; // Apply background color and any foreground color String finalCss = display.gtk_css_create_css_color_string (cssBackground, cssForeground, SWT.BACKGROUND); - gtk_css_provider_load_from_css(context, finalCss); + gtk_css_provider_load_from_css (context, finalCss); } @Override @@ -3671,9 +3671,9 @@ int setBounds (int x, int y, int width, int height, boolean move, boolean resize *
TreeItem and inserts it into Tree.
* Item is inserted as last direct child of the tree.
*
- * The fastest way to insert many items is documented in {@link TreeItem#TreeItem(Tree,int,int)}
+ * The fastest way to insert many items is documented in {@link TreeItem#TreeItem (Tree,int,int)}
* and {@link TreeItem#setItemCount}
*
* @param parent a tree control which will be the parent of the new instance (cannot be null)
@@ -110,7 +110,7 @@ public TreeItem (Tree parent, int style, int index) {
* Constructs TreeItem and inserts it into Tree.
* Item is inserted as last direct child of the specified TreeItem.
*
- * The fastest way to insert many items is documented in {@link TreeItem#TreeItem(Tree,int,int)}
+ * The fastest way to insert many items is documented in {@link TreeItem#TreeItem (Tree,int,int)}
* and {@link TreeItem#setItemCount}
*
* @param parentItem a tree control which will be the parent of the new instance (cannot be null)
@@ -136,7 +136,7 @@ public TreeItem (TreeItem parentItem, int style) {
* Constructs TreeItem and inserts it into Tree.
* Item is inserted as index direct child of the specified TreeItem.
*
- * The fastest way to insert many items is documented in {@link TreeItem#TreeItem(Tree,int,int)} + * The fastest way to insert many items is documented in {@link TreeItem#TreeItem (Tree,int,int)} * and {@link TreeItem#setItemCount} * * @param parentItem a tree control which will be the parent of the new instance (cannot be null) @@ -169,8 +169,8 @@ public TreeItem (TreeItem parentItem, int style, int index) { } else { assert handle == 0; handle = OS.g_malloc (GTK.GtkTreeIter_sizeof ()); - if (handle == 0) error(SWT.ERROR_NO_HANDLES); - C.memmove(handle, iter, GTK.GtkTreeIter_sizeof ()); + if (handle == 0) error (SWT.ERROR_NO_HANDLES); + C.memmove (handle, iter, GTK.GtkTreeIter_sizeof ()); } } @@ -199,9 +199,9 @@ Color _getBackground () { GTK.gtk_tree_model_get (parent.modelHandle, handle, Tree.BACKGROUND_COLUMN, ptr, -1); if (ptr [0] == 0) return parent.getBackground (); GdkRGBA gdkRGBA = new GdkRGBA (); - OS.memmove(gdkRGBA, ptr [0], GdkRGBA.sizeof); + OS.memmove (gdkRGBA, ptr [0], GdkRGBA.sizeof); GDK.gdk_rgba_free (ptr [0]); - return Color.gtk_new(display, gdkRGBA); + return Color.gtk_new (display, gdkRGBA); } Color _getBackground (int index) { @@ -212,9 +212,9 @@ Color _getBackground (int index) { GTK.gtk_tree_model_get (parent.modelHandle, handle, modelIndex + Tree.CELL_BACKGROUND, ptr, -1); if (ptr [0] == 0) return _getBackground (); GdkRGBA gdkRGBA = new GdkRGBA (); - OS.memmove(gdkRGBA, ptr [0], GdkRGBA.sizeof); + OS.memmove (gdkRGBA, ptr [0], GdkRGBA.sizeof); GDK.gdk_rgba_free (ptr [0]); - return Color.gtk_new(display, gdkRGBA); + return Color.gtk_new (display, gdkRGBA); } boolean _getChecked () { @@ -228,9 +228,9 @@ Color _getForeground () { GTK.gtk_tree_model_get (parent.modelHandle, handle, Tree.FOREGROUND_COLUMN, ptr, -1); if (ptr [0] == 0) return parent.getForeground (); GdkRGBA gdkRGBA = new GdkRGBA (); - OS.memmove(gdkRGBA, ptr [0], GdkRGBA.sizeof); + OS.memmove (gdkRGBA, ptr [0], GdkRGBA.sizeof); GDK.gdk_rgba_free (ptr [0]); - return Color.gtk_new(display, gdkRGBA); + return Color.gtk_new (display, gdkRGBA); } Color _getForeground (int index) { @@ -241,25 +241,25 @@ Color _getForeground (int index) { GTK.gtk_tree_model_get (parent.modelHandle, handle, modelIndex + Tree.CELL_FOREGROUND, ptr, -1); if (ptr [0] == 0) return _getForeground (); GdkRGBA gdkRGBA = new GdkRGBA (); - OS.memmove(gdkRGBA, ptr [0], GdkRGBA.sizeof); + OS.memmove (gdkRGBA, ptr [0], GdkRGBA.sizeof); GDK.gdk_rgba_free (ptr [0]); - return Color.gtk_new(display, gdkRGBA); + return Color.gtk_new (display, gdkRGBA); } -Image _getImage(int index) { - int count = Math.max(1, parent.getColumnCount()); +Image _getImage (int index) { + int count = Math.max (1, parent.getColumnCount ()); if (0 > index || index > count - 1) return null; - long[] surfaceHandle = new long[1]; - int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns[index].modelIndex; + long [] surfaceHandle = new long [1]; + int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; GTK.gtk_tree_model_get (parent.modelHandle, handle, modelIndex + Tree.CELL_SURFACE, surfaceHandle, -1); - if (surfaceHandle[0] == 0) return null; + if (surfaceHandle [0] == 0) return null; - int imageIndex = parent.imageList.indexOf(surfaceHandle[0]); + int imageIndex = parent.imageList.indexOf (surfaceHandle [0]); if (imageIndex == -1) { return null; } else { - return parent.imageList.get(imageIndex); + return parent.imageList.get (imageIndex); } } @@ -271,7 +271,7 @@ String _getText (int index) { GTK.gtk_tree_model_get (parent.modelHandle, handle, modelIndex + Tree.CELL_TEXT, ptr, -1); if (ptr [0] == 0) return ""; //$NON-NLS-1$ int length = C.strlen (ptr [0]); - byte[] buffer = new byte [length]; + byte [] buffer = new byte [length]; C.memmove (buffer, ptr [0], length); OS.g_free (ptr [0]); return new String (Converter.mbcsToWcs (buffer)); @@ -412,7 +412,7 @@ public Rectangle getBounds (int index) { Rectangle getBoundsInPixels (int index) { // TODO fully test on early and later versions of GTK - checkWidget(); + checkWidget (); if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); long parentHandle = parent.handle; long column = 0; @@ -491,13 +491,13 @@ Rectangle getBoundsInPixels () { int horizontalSeparator; if (GTK.GTK4) { - long separator = GTK.gtk_separator_new(GTK.GTK_ORIENTATION_HORIZONTAL); + long separator = GTK.gtk_separator_new (GTK.GTK_ORIENTATION_HORIZONTAL); GtkAllocation allocation = new GtkAllocation (); - GTK.gtk_widget_get_allocation(separator, allocation); + GTK.gtk_widget_get_allocation (separator, allocation); horizontalSeparator = allocation.height; } else { GTK3.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0); - horizontalSeparator = buffer[0]; + horizontalSeparator = buffer [0]; } rect.x += horizontalSeparator; @@ -526,7 +526,7 @@ Rectangle getBoundsInPixels () { * */ public boolean getChecked () { - checkWidget(); + checkWidget (); if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); if ((parent.style & SWT.CHECK) == 0) return false; return _getChecked (); @@ -544,7 +544,7 @@ public boolean getChecked () { * */ public boolean getExpanded () { - checkWidget(); + checkWidget (); long path = GTK.gtk_tree_model_get_path (parent.modelHandle, handle); boolean answer = GTK.gtk_tree_view_row_expanded (parent.handle, path); GTK.gtk_tree_path_free (path); @@ -694,7 +694,7 @@ public Image getImage (int index) { */ public Rectangle getImageBounds (int index) { checkWidget (); - return DPIUtil.autoScaleDown(getImageBoundsInPixels(index)); + return DPIUtil.autoScaleDown (getImageBoundsInPixels (index)); } Rectangle getImageBoundsInPixels (int index) { @@ -751,7 +751,7 @@ Rectangle getImageBoundsInPixels (int index) { * "main-widget" have separate GdkWindows. */ if (parent!= null && parent.getHeaderVisible () && GTK.GTK4) { - r.y += parent.getHeaderHeight(); + r.y += parent.getHeaderHeight (); } return r; } @@ -768,7 +768,7 @@ Rectangle getImageBoundsInPixels (int index) { * */ public int getItemCount () { - checkWidget(); + checkWidget (); if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); return GTK.gtk_tree_model_iter_n_children (parent.modelHandle, handle); } @@ -791,7 +791,7 @@ public int getItemCount () { * @since 3.1 */ public TreeItem getItem (int index) { - checkWidget(); + checkWidget (); if (index < 0) error (SWT.ERROR_INVALID_RANGE); if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); @@ -821,7 +821,7 @@ public TreeItem getItem (int index) { * */ public TreeItem [] getItems () { - checkWidget(); + checkWidget (); if (!parent.checkData (this)) error (SWT.ERROR_WIDGET_DISPOSED); return parent.getItems (handle); } @@ -862,7 +862,7 @@ public Tree getParent () { * */ public TreeItem getParentItem () { - checkWidget(); + checkWidget (); long path = GTK.gtk_tree_model_get_path (parent.modelHandle, handle); TreeItem item = null; int depth = GTK.gtk_tree_path_get_depth (path); @@ -928,7 +928,7 @@ public String getText (int index) { */ public Rectangle getTextBounds (int index) { checkWidget (); - return DPIUtil.autoScaleDown(getTextBoundsInPixels(index)); + return DPIUtil.autoScaleDown (getTextBoundsInPixels (index)); } Rectangle getTextBoundsInPixels (int index) { @@ -971,13 +971,13 @@ Rectangle getTextBoundsInPixels (int index) { int horizontalSeparator; if (GTK.GTK4) { - long separator = GTK.gtk_separator_new(GTK.GTK_ORIENTATION_HORIZONTAL); + long separator = GTK.gtk_separator_new (GTK.GTK_ORIENTATION_HORIZONTAL); GtkAllocation allocation = new GtkAllocation (); - GTK.gtk_widget_get_allocation(separator, allocation); + GTK.gtk_widget_get_allocation (separator, allocation); horizontalSeparator = allocation.height; } else { GTK3.gtk_widget_style_get (parentHandle, OS.horizontal_separator, buffer, 0); - horizontalSeparator = buffer[0]; + horizontalSeparator = buffer [0]; } rect.x += horizontalSeparator; gtk_tree_view_column_cell_get_position (column, textRenderer, x, null); @@ -988,10 +988,10 @@ Rectangle getTextBoundsInPixels (int index) { * NOTE: this change has been ported to Tables since Tables/Trees both use the * same underlying GTK structure. */ - Image image = _getImage(index); + Image image = _getImage (index); int imageWidth = 0; if (image != null) { - if (DPIUtil.useCairoAutoScale()) { + if (DPIUtil.useCairoAutoScale ()) { imageWidth = image.getBounds ().width; } else { imageWidth = image.getBoundsInPixels ().width; @@ -1032,16 +1032,16 @@ Rectangle getTextBoundsInPixels (int index) { * @since 3.1 */ public int indexOf (TreeItem item) { - checkWidget(); + checkWidget (); if (item == null) error (SWT.ERROR_NULL_ARGUMENT); - if (item.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); + if (item.isDisposed ()) error (SWT.ERROR_INVALID_ARGUMENT); int index = -1; boolean isParent = false; long currentPath = GTK.gtk_tree_model_get_path (parent.modelHandle, handle); long parentPath = GTK.gtk_tree_model_get_path (parent.modelHandle, item.handle); int depth = GTK.gtk_tree_path_get_depth (parentPath); - if (depth > 1 && GTK.gtk_tree_path_up(parentPath)) { - if (GTK.gtk_tree_path_compare(currentPath, parentPath) == 0) isParent = true; + if (depth > 1 && GTK.gtk_tree_path_up (parentPath)) { + if (GTK.gtk_tree_path_compare (currentPath, parentPath) == 0) isParent = true; } GTK.gtk_tree_path_free (currentPath); GTK.gtk_tree_path_free (parentPath); @@ -1050,9 +1050,9 @@ public int indexOf (TreeItem item) { if (depth > 1) { long indices = GTK.gtk_tree_path_get_indices (path); if (indices != 0) { - int[] temp = new int[depth]; + int [] temp = new int [depth]; C.memmove (temp, indices, 4 * temp.length); - index = temp[temp.length - 1]; + index = temp [temp.length - 1]; } } GTK.gtk_tree_path_free (path); @@ -1087,11 +1087,11 @@ void releaseWidget () { public void dispose () { // Workaround to Bug489751, avoid selecting next node when selected node is disposed. Tree tmpParent = null; - if (parent != null && parent.getItemCount() > 0 && parent.getSelectionCount() == 0) { + if (parent != null && parent.getItemCount () > 0 && parent.getSelectionCount () == 0) { tmpParent = parent; } - super.dispose(); - if (tmpParent != null && !tmpParent.isDisposed()) tmpParent.deselectAll(); + super.dispose (); + if (tmpParent != null && !tmpParent.isDisposed ()) tmpParent.deselectAll (); } /** @@ -1224,7 +1224,7 @@ public void setBackground (int index, Color color) { * */ public void setChecked (boolean checked) { - checkWidget(); + checkWidget (); if ((parent.style & SWT.CHECK) == 0) return; if (_getChecked () == checked) return; GTK.gtk_tree_store_set (parent.modelHandle, handle, Tree.CHECKED_COLUMN, checked, -1); @@ -1248,7 +1248,7 @@ public void setChecked (boolean checked) { * */ public void setExpanded (boolean expanded) { - checkWidget(); + checkWidget (); long path = GTK.gtk_tree_model_get_path (parent.modelHandle, handle); if (expanded != GTK.gtk_tree_view_row_expanded (parent.handle, path)) { if (expanded) { @@ -1462,7 +1462,7 @@ public void setForeground (int index, Color color){ * */ public void setGrayed (boolean grayed) { - checkWidget(); + checkWidget (); if ((parent.style & SWT.CHECK) == 0) return; if (this.grayed == grayed) return; this.grayed = grayed; @@ -1492,31 +1492,31 @@ public void setGrayed (boolean grayed) { * * @since 3.1 */ -public void setImage(int index, Image image) { +public void setImage (int index, Image image) { checkWidget (); - if (image != null && image.isDisposed()) { - error(SWT.ERROR_INVALID_ARGUMENT); + if (image != null && image.isDisposed ()) { + error (SWT.ERROR_INVALID_ARGUMENT); } if (image != null && image.type == SWT.ICON) { - if (image.equals(_getImage(index))) return; + if (image.equals (_getImage (index))) return; } - int count = Math.max(1, parent.getColumnCount()); + int count = Math.max (1, parent.getColumnCount ()); if (0 > index || index > count - 1) return; long pixbuf = 0, surface = 0; if (image != null) { ImageList imageList = parent.imageList; - if (imageList == null) imageList = parent.imageList = new ImageList(); - int imageIndex = imageList.indexOf(image); + if (imageList == null) imageList = parent.imageList = new ImageList (); + int imageIndex = imageList.indexOf (image); // When we create a blank image surface gets created with dimensions 0, 0. // This call recreates the surface with correct dimensions - long tempSurface = ImageList.convertSurface(image); - Cairo.cairo_surface_destroy(tempSurface); + long tempSurface = ImageList.convertSurface (image); + Cairo.cairo_surface_destroy (tempSurface); if (imageIndex == -1) { - imageIndex = imageList.add(image); + imageIndex = imageList.add (image); } - surface = imageList.getSurface(imageIndex); - pixbuf = ImageList.createPixbuf(surface); + surface = imageList.getSurface (imageIndex); + pixbuf = ImageList.createPixbuf (surface); } int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; @@ -1529,7 +1529,7 @@ public void setImage(int index, Image image) { if (!parent.pixbufSizeSet) { if (image != null) { int iWidth, iHeight; - if (DPIUtil.useCairoAutoScale()) { + if (DPIUtil.useCairoAutoScale ()) { iWidth = image.getBounds ().width; iHeight = image.getBounds ().height; } else { @@ -1556,7 +1556,7 @@ public void setImage(int index, Image image) { * supposed to be rendered in. See bug 513761. */ boolean check = modelIndex == Tree.FIRST_COLUMN && (parent.style & SWT.CHECK) != 0; - parent.createRenderers(column, modelIndex, check, parent.style); + parent.createRenderers (column, modelIndex, check, parent.style); } } } @@ -1564,23 +1564,23 @@ public void setImage(int index, Image image) { /* * Bug 483112: We check to see if the cached value is greater than the size of the pixbufRenderer. * If it is, then we change the size of the pixbufRenderer accordingly. - * Bug 489025: There is a corner case where the below is triggered when current(Width|Height) is -1, + * Bug 489025: There is a corner case where the below is triggered when current (Width|Height) is -1, * which results in icons being set to 0. Fix is to compare only positive sizes. */ - if (parent.pixbufWidth > Math.max(currentWidth [0], 0) || parent.pixbufHeight > Math.max(currentHeight [0], 0)) { + if (parent.pixbufWidth > Math.max (currentWidth [0], 0) || parent.pixbufHeight > Math.max (currentHeight [0], 0)) { GTK.gtk_cell_renderer_set_fixed_size (pixbufRenderer, parent.pixbufWidth, parent.pixbufHeight); } } - GTK.gtk_tree_store_set(parent.modelHandle, handle, modelIndex + Tree.CELL_PIXBUF, pixbuf, -1); + GTK.gtk_tree_store_set (parent.modelHandle, handle, modelIndex + Tree.CELL_PIXBUF, pixbuf, -1); /* - * Bug 573633: gtk_tree_store_set() will reference the handle. So we unref the pixbuf here, + * Bug 573633: gtk_tree_store_set () will reference the handle. So we unref the pixbuf here, * and leave the destruction of the handle to be done later on by the GTK+ tree. */ if (pixbuf != 0) { - OS.g_object_unref(pixbuf); + OS.g_object_unref (pixbuf); } - GTK.gtk_tree_store_set(parent.modelHandle, handle, modelIndex + Tree.CELL_SURFACE, surface, -1); + GTK.gtk_tree_store_set (parent.modelHandle, handle, modelIndex + Tree.CELL_SURFACE, surface, -1); cached = true; updated = true; } @@ -1673,10 +1673,10 @@ public void setText (int index, String string) { if (string.equals (strings [index])) return; strings [index] = string; } - if ((string != null) && (string.length() > TEXT_LIMIT)) { - string = string.substring(0, TEXT_LIMIT - ELLIPSIS.length()) + ELLIPSIS; + if ((string != null) && (string.length () > TEXT_LIMIT)) { + string = string.substring (0, TEXT_LIMIT - ELLIPSIS.length ()) + ELLIPSIS; } - byte[] buffer = Converter.wcsToMbcs (string, true); + byte [] buffer = Converter.wcsToMbcs (string, true); int modelIndex = parent.columnCount == 0 ? Tree.FIRST_COLUMN : parent.columns [index].modelIndex; GTK.gtk_tree_store_set (parent.modelHandle, handle, modelIndex + Tree.CELL_TEXT, buffer, -1); cached = true;