summaryrefslogtreecommitdiffstats
path: root/bundles/org.eclipse.swt/Eclipse SWT/gtk/org/eclipse/swt/widgets/TableItem.java
blob: 0b634d43e867ea8b7ace68b4abfdd75d8577123b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
package org.eclipse.swt.widgets;

/*

 * Copyright (c) 2000, 2002 IBM Corp.  All rights reserved.
 * This file is made available under the terms of the Common Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/cpl-v10.html

 */

import org.eclipse.swt.*;
import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.gtk.*;
import org.eclipse.swt.graphics.*;
import org.eclipse.swt.graphics.*;

/**
 * Instances of this class represent a selectable user interface object
 * that represents an item in a table.
 * <dl>
 * <dt><b>Styles:</b></dt>
 * <dd>(none)</dd>
 * <dt><b>Events:</b></dt>
 * <dd>(none)</dd>
 * </dl>
 * <p>
 * IMPORTANT: This class is <em>not</em> intended to be subclassed.
 * </p>
 */
public class TableItem extends Item {
	Table parent;
	
/**
 * Constructs a new instance of this class given its parent
 * (which must be a <code>Table</code>), a style value
 * describing its behavior and appearance, and the index
 * at which to place it in the items maintained by its parent.
 * <p>
 * The style value is either one of the style constants defined in
 * class <code>SWT</code> which is applicable to instances of this
 * class, or must be built by <em>bitwise OR</em>'ing together 
 * (that is, using the <code>int</code> "|" operator) two or more
 * of those <code>SWT</code> style constants. The class description
 * lists the style constants that are applicable to the class.
 * Style bits are also inherited from superclasses.
 * </p>
 *
 * @param parent a composite control which will be the parent of the new instance (cannot be null)
 * @param style the style of control to construct
 * @param index the index to store the receiver in its parent
 *
 * @exception IllegalArgumentException <ul>
 *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
 * </ul>
 * @exception SWTException <ul>
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
 *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
 * </ul>
 *
 * @see SWT
 * @see Widget#checkSubclass
 * @see Widget#getStyle
 */
public TableItem (Table parent, int style, int index) {
	super (parent, style);
	this.parent = parent;
	parent.createItem (this, index);
}

/**
 * Constructs a new instance of this class given its parent
 * (which must be a <code>Table</code>) and a style value
 * describing its behavior and appearance. The item is added
 * to the end of the items maintained by its parent.
 * <p>
 * The style value is either one of the style constants defined in
 * class <code>SWT</code> which is applicable to instances of this
 * class, or must be built by <em>bitwise OR</em>'ing together 
 * (that is, using the <code>int</code> "|" operator) two or more
 * of those <code>SWT</code> style constants. The class description
 * lists the style constants that are applicable to the class.
 * Style bits are also inherited from superclasses.
 * </p>
 *
 * @param parent a composite control which will be the parent of the new instance (cannot be null)
 * @param style the style of control to construct
 *
 * @exception IllegalArgumentException <ul>
 *    <li>ERROR_NULL_ARGUMENT - if the parent is null</li>
 * </ul>
 * @exception SWTException <ul>
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the parent</li>
 *    <li>ERROR_INVALID_SUBCLASS - if this class is not an allowed subclass</li>
 * </ul>
 *
 * @see SWT
 * @see Widget#checkSubclass
 * @see Widget#getStyle
 */
public TableItem (Table parent, int style) {
	super (parent, style);
	this.parent = parent;
	parent.createItem (this, parent.getItemCount ());
}

/**

 * Returns the receiver's background color.

 *

 * @return the background color

 *

 * @exception SWTException <ul>

 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>

 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>

 * </ul>

 * 

 * @since 2.0

 * 

 */
public Color getBackground () {
	checkWidget ();
	Table parent = getParent();
	return parent.getBackground();
}

/**

 * Returns a rectangle describing the receiver's size and location

 * relative to its parent at a column in the table.

 *

 * @param index the index that specifies the column

 * @return the receiver's bounding column rectangle

 *

 * @exception SWTException <ul>

 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>

 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>

 * </ul>

 */
public Rectangle getBounds (int index) {
	checkWidget();
	int CELL_SPACING = 1;
	int clist = parent.handle;
	int columnHandle = OS.GTK_CLIST_COLUMN (clist);
	columnHandle= columnHandle + index * GtkCListColumn.sizeof;
	GtkCListColumn column = new GtkCListColumn ();
	OS.memmove (column, columnHandle, GtkCListColumn.sizeof);
	int x = column.area_x + OS.GTK_CLIST_HOFFSET (clist);
	int width = column.area_width;
	int height = OS.GTK_CLIST_ROW_HEIGHT (clist);
	int row = parent.indexOf (this);
	int headerHeight = OS.GTK_CLIST_COLUMN_TITLE_AREA_HEIGHT (clist);
	int y = headerHeight + OS.GTK_CLIST_VOFFSET (clist) + (height + CELL_SPACING) * row + 3;
	return new Rectangle (x, y, width, height);
}

/**

 * Returns <code>true</code> if the receiver is checked,

 * and false otherwise.  When the parent does not have

 * the <code>CHECK style, return false.

 *

 * @return the checked state of the checkbox

 *

 * @exception SWTException <ul>

 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>

 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>

 * </ul>

 */
public boolean getChecked () {
	checkWidget();
	if ((parent.style & SWT.CHECK) == 0) return false;
	int row = parent.indexOf (this);
	if (row == -1) return false;
	int clist = parent.handle;
	int [] pixmap = new int [1];
	OS.gtk_clist_get_pixtext (clist, row, 0, null, null, pixmap, null);
	return pixmap [0] == parent.check;
}

public Display getDisplay () {
	Table parent = this.parent;
	if (parent == null) error (SWT.ERROR_WIDGET_DISPOSED);
	return parent.getDisplay ();
}

/**

 * Returns the foreground color that the receiver will use to draw.

 *

 * @return the receiver's foreground color

 *

 * @exception SWTException <ul>

 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>

 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>

 * </ul>

 * 

 * @since 2.0

 * 

 */
public Color getForeground () {
	checkWidget ();
	Table parent = getParent();
	return parent.getForeground();
}

/**

 * Returns <code>true</code> if the receiver is grayed,

 * and false otherwise. When the parent does not have

 * the <code>CHECK</code> style, return false.

 *

 * @return the grayed state of the checkbox

 *

 * @exception SWTException <ul>

 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>

 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>

 * </ul>

 */
public boolean getGrayed () {
	checkWidget ();
	//NOT DONE

	if ((parent.style & SWT.CHECK) == 0) return false;
	return false;
}

/**
 * Returns the image stored at the given column index in the receiver,
 * or null if the image has not been set or if the column does not exist.
 *
 * @param index the column index
 * @return the image stored at the given column index in the receiver
 *
 * @exception SWTException <ul>
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
 * </ul>
 */
public Image getImage (int index) {
	checkWidget ();
	if (index == 0) return getImage ();
	int row = parent.indexOf (this);
	if (row == -1) return null;
	int clist = parent.handle;
	int [] pixmap = new int [1], mask = new int [1];
	OS.gtk_clist_get_pixtext (clist, row, index, null, null, pixmap, null);
	if (pixmap [0] == 0) return null;
	Display display = getDisplay ();
	return Image.gtk_new (display, mask [0] == 0 ? SWT.BITMAP : SWT.ICON, pixmap [0], mask [0]);
}

/**
 * Returns a rectangle describing the size and location
 * relative to its parent of an image at a column in the
 * table.
 *
 * @param index the index that specifies the column
 * @return the receiver's bounding image rectangle
 *
 * @exception SWTException <ul>
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
 * </ul>
 */
public Rectangle getImageBounds (int index) {
	checkWidget ();
	int CELL_SPACING = 1;
	int clist = parent.handle;
	int columnHandle = OS.GTK_CLIST_COLUMN (clist);
	columnHandle= columnHandle + index * GtkCListColumn.sizeof;
	GtkCListColumn column = new GtkCListColumn ();
	OS.memmove (column, columnHandle, GtkCListColumn.sizeof);
	int x = column.area_x + OS.GTK_CLIST_HOFFSET (clist) + 1;
	int height = OS.GTK_CLIST_ROW_HEIGHT (clist);
	int row = parent.indexOf (this);
	int headerHeight = OS.GTK_CLIST_COLUMN_TITLE_AREA_HEIGHT (clist);
	int y = headerHeight + OS.GTK_CLIST_VOFFSET (clist) + (height + CELL_SPACING) * row + 3;
	int width = 0;
	if (!(index == 0 && (parent.style & SWT.CHECK) != 0)) {
		int [] pixmap = new int [1];
		OS.gtk_clist_get_pixtext (clist, row, index, null, null, pixmap, null);
		if (pixmap [0] != 0) {
			int [] w = new int [1], h = new int [1];
			OS.gdk_drawable_get_size (pixmap [0], w, h);
			width = w [0];
		}
	}
	return new Rectangle (x, y, width, height);
}

/**
 * Gets the image indent.
 *
 * @return the indent
 *
 * @exception SWTException <ul>
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
 * </ul>
 */
public int getImageIndent () {
	checkWidget ();
	/* Image indent is not supported on GTK */
	return 0;
}

/**
 * Returns the receiver's parent, which must be a <code>Table</code>.
 *
 * @return the receiver's parent
 *
 * @exception SWTException <ul>
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
 * </ul>
 */
public Table getParent () {
	checkWidget ();
	return parent;
}

/**
 * Returns the text stored at the given column index in the receiver,
 * or empty string if the text has not been set.
 *
 * @param index the column index
 * @return the text stored at the given column index in the receiver
 *
 * @exception SWTException <ul>
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
 * </ul>
 * @exception SWTError <ul>
 *    <li>ERROR_CANNOT_GET_TEXT - if the column at index does not exist</li>
 * </ul>
 */
public String getText (int index) {
	checkWidget ();
	if (index == 0) return getText ();
	int row = parent.indexOf (this);
	if (row == -1) error (SWT.ERROR_CANNOT_GET_TEXT);
	int clist = parent.handle;
	int [] address = new int [1];
	int [] pixmap = new int [1];
	OS.gtk_clist_get_pixtext (clist, row, index, address, null, pixmap, null);
	if (pixmap [0] == 0) {
		OS.gtk_clist_get_text (clist, row, index, address);
	}
	if (address [0] == 0) return "";
	byte [] buffer = new byte [OS.strlen (address [0])];
	OS.memmove (buffer, address [0], buffer.length);
	return new String (Converter.mbcsToWcs (null, buffer));
}

void releaseChild () {
	super.releaseChild ();
	parent.destroyItem (this);
}

void releaseWidget () {
	super.releaseWidget ();
	parent = null;
}

/**

 * Sets the receiver's background color to the color specified

 * by the argument, or to the default system color for the item

 * if the argument is null.

 *

 * @param color the new color (or null)

 *

 * @exception IllegalArgumentException <ul>

 *    <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> 

 * </ul>

 * @exception SWTException <ul>

 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>

 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>

 * </ul>

 * 

 * @since 2.0

 * 

 */
public void setBackground (Color color) {
	checkWidget ();
	if (color != null && color.isDisposed ()) {
		SWT.error (SWT.ERROR_INVALID_ARGUMENT);
	}
	int row = parent.indexOf (this);
	if (row == -1) return;
	int clist = parent.handle;
	OS.gtk_clist_set_background (clist, row, color != null ? color.handle : null);
}

/**

 * Sets the checked state of the checkbox for this item.  This state change 

 * only applies if the Table was created with the SWT.CHECK style.

 *

 * @param checked the new checked state of the checkbox

 *

 * @exception SWTException <ul>

 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>

 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>

 * </ul>

 */
public void setChecked (boolean checked) {
	checkWidget();
	int row = parent.indexOf (this);
	if (row == -1) return;
	int ctable = parent.handle;
	byte [] buffer = Converter.wcsToMbcs (null, text, true);
	int pixmap = checked ? parent.check : parent.uncheck;
	byte [] spacing = new byte [1];
	OS.gtk_clist_get_pixtext(ctable, row, 0, null, spacing, null, null);
	OS.gtk_clist_set_pixtext (ctable, row, 0, buffer, spacing [0], pixmap, 0);
}

/**

 * Sets the receiver's foreground color to the color specified

 * by the argument, or to the default system color for the item

 * if the argument is null.

 *

 * @param color the new color (or null)

 *

 * @exception IllegalArgumentException <ul>

 *    <li>ERROR_INVALID_ARGUMENT - if the argument has been disposed</li> 

 * </ul>

 * @exception SWTException <ul>

 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>

 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>

 * </ul>

 * 

 * @since 2.0

 * 

 */
public void setForeground (Color color){
	checkWidget ();
	if (color != null && color.isDisposed ()) {
		SWT.error (SWT.ERROR_INVALID_ARGUMENT);
	}
	int row = parent.indexOf (this);
	if (row == -1) return;
	int clist = parent.handle;
	OS.gtk_clist_set_foreground (clist, row, color != null ? color.handle : null);
}

/**

 * Sets the grayed state of the checkbox for this item.  This state change 

 * only applies if the Table was created with the SWT.CHECK style.

 *

 * @param grayed the new grayed state of the checkbox

 *

 * @exception SWTException <ul>

 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>

 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>

 * </ul>

 */
public void setGrayed (boolean grayed) {
	checkWidget();
	//NOT IMPLEMENTED

}

/**
 * Sets the receiver's image at a column.
 *
 * @param index the column index
 * @param image the new image
 *
 * @exception IllegalArgumentException <ul>
 *    <li>ERROR_INVALID_ARGUMENT - if the image has been disposed</li>
 * </ul>
 * @exception SWTException <ul>
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
 * </ul>
 */
public void setImage (int index, Image image) {
	checkWidget ();
	if (image != null && image.isDisposed()) {
		error(SWT.ERROR_INVALID_ARGUMENT);
	}
	if (index == 0) {
		if ((parent.style & SWT.CHECK) != 0) return;
		super.setImage (image);
	}
	int row = parent.indexOf (this);
	if (row == -1) return;
	int clist = parent.handle;
	String string = getText (index);
	byte [] buffer = Converter.wcsToMbcs (null, string, true);
	if (image == null) {
		OS.gtk_clist_set_text (clist, row, index, buffer);
	} else {
		int pixmap = image.pixmap, mask = image.mask;
		byte [] spacing = new byte [] {2};
//		OS.gtk_clist_get_pixtext (clist, row, index, null, spacing, null, null);

		OS.gtk_clist_set_pixtext (clist, row, index, buffer, spacing [0], pixmap, mask);
		if (parent.imageHeight == 0) {	
			int [] width = new int [1], height = new int [1];
			OS.gdk_drawable_get_size (pixmap, width, height);
			if (height [0] > OS.GTK_CLIST_ROW_HEIGHT (parent.handle)) {
				parent.imageHeight = height [0];
				OS.gtk_widget_realize (clist);
				OS.gtk_clist_set_row_height (clist, height [0]);
			}
		}
	}
}

public void setImage (Image image) {
	checkWidget ();
	setImage (0, image);
}

/**
 * Sets the image for multiple columns in the Table. 
 * 
 * @param images the array of new images
 *
 * @exception IllegalArgumentException <ul>
 *    <li>ERROR_NULL_ARGUMENT - if the array of images is null</li>
 *    <li>ERROR_INVALID_ARGUMENT - if one of the images has been disposed</li>
 * </ul>
 * @exception SWTException <ul>
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
 * </ul>
 */
public void setImage (Image [] images) {
	checkWidget ();
	if (images == null) error (SWT.ERROR_NULL_ARGUMENT);
	for (int i=0; i<images.length; i++) {
		setImage (i, images [i]);
	}
}

/**
 * Sets the image indent.
 *
 * @param indent the new indent
 *
 * </ul>
 * @exception SWTException <ul>
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
 * </ul>
 */
public void setImageIndent (int indent) {
	checkWidget ();
	/* Image indent is not supported on GTK */
}

/**
 * Sets the receiver's text at a column
 *
 * @param index the column index
 * @param string the new text
 *
 * @exception IllegalArgumentException <ul>
 *    <li>ERROR_NULL_ARGUMENT - if the text is null</li>
 * </ul>
 * @exception SWTException <ul>
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
 * </ul>
 */
public void setText (int index, String string) {
	checkWidget ();
	if (string == null) error (SWT.ERROR_NULL_ARGUMENT);
	if (index == 0) {
		super.setText (string);
	}
	int row = parent.indexOf (this);
	if (row == -1) return;
	int clist = parent.handle;
	byte [] buffer = Converter.wcsToMbcs (null, string, true);
	byte [] spacing = new byte [1];
	int [] pixmap = new int [1], mask = new int [1];
	OS.gtk_clist_get_pixtext (clist, row, index, null, spacing, pixmap, mask);
	if (pixmap [0] == 0) {
		OS.gtk_clist_set_text (clist, row, index, buffer);
	} else {
		OS.gtk_clist_set_pixtext (clist, row, index, buffer, spacing [0], pixmap [0], mask [0]);
	}
}

public void setText (String string) {
	checkWidget ();
	setText (0, string);
}

/**
 * Sets the text for multiple columns in the table. 
 * 
 * @param strings the array of new strings
 *
 * @exception IllegalArgumentException <ul>
 *    <li>ERROR_NULL_ARGUMENT - if the text is null</li>
 * </ul>
 * @exception SWTException <ul>
 *    <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed</li>
 *    <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver</li>
 * </ul>
 */
public void setText (String [] strings) {
	checkWidget ();
	if (strings == null) error (SWT.ERROR_NULL_ARGUMENT);
	for (int i=0; i<strings.length; i++) {
		String string = strings [i];
		if (string != null) setText (i, string);
	}
}

}