Started editable uiTable elements.
This commit is contained in:
parent
49ab4a886f
commit
e0230d73a6
|
@ -5,11 +5,15 @@
|
||||||
// - initial state of table view is off
|
// - initial state of table view is off
|
||||||
// - header cell seems off
|
// - header cell seems off
|
||||||
// - background color shows up for a line or two below selection
|
// - background color shows up for a line or two below selection
|
||||||
|
// - editable NSTextFields have no intrinsic width
|
||||||
|
// - changing a part property does not refresh views
|
||||||
|
// - the target/action thing is wrong; we need to pass the model column for col, not the view column
|
||||||
|
|
||||||
@interface tableModel : NSObject<NSTableViewDataSource, NSTableViewDelegate> {
|
@interface tableModel : NSObject<NSTableViewDataSource, NSTableViewDelegate> {
|
||||||
uiTableModel *libui_m;
|
uiTableModel *libui_m;
|
||||||
}
|
}
|
||||||
- (id)initWithModel:(uiTableModel *)m;
|
- (id)initWithModel:(uiTableModel *)m;
|
||||||
|
- (IBAction)onAction:(id)sender;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
|
@ -23,6 +27,7 @@ enum {
|
||||||
@property int textColorColumn;
|
@property int textColorColumn;
|
||||||
@property int imageColumn;
|
@property int imageColumn;
|
||||||
@property int expand;
|
@property int expand;
|
||||||
|
@property int editable;
|
||||||
- (NSView *)mkView:(uiTableModel *)m row:(int)row;
|
- (NSView *)mkView:(uiTableModel *)m row:(int)row;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -157,6 +162,36 @@ done:
|
||||||
// TODO autorelease color? or release it?
|
// TODO autorelease color? or release it?
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (IBAction)onAction:(id)sender
|
||||||
|
{
|
||||||
|
uiTableModel *m = self->libui_m;
|
||||||
|
NSView *view = (NSView *) sender;
|
||||||
|
NSTableView *tv;
|
||||||
|
NSInteger row;
|
||||||
|
const void *data;
|
||||||
|
|
||||||
|
row = -1;
|
||||||
|
for (tv in m->tables) {
|
||||||
|
row = [tv rowForView:view];
|
||||||
|
if (row != -1)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if (row == -1)
|
||||||
|
implbug("table model action triggered on view with no associated table");
|
||||||
|
|
||||||
|
if ([view isKindOfClass:[NSTextField class]])
|
||||||
|
data = [((NSTextField *) view) stringValue];
|
||||||
|
else
|
||||||
|
implbug("table model editing action triggered on non-editable view");
|
||||||
|
|
||||||
|
(*(m->mh->SetCellValue))(m->mh, m,
|
||||||
|
row, [tv columnForView:view],
|
||||||
|
data);
|
||||||
|
// always refresh the value in case the model rejected it
|
||||||
|
// TODO only affect tv
|
||||||
|
uiTableModelRowChanged(m, row);
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@implementation tablePart
|
@implementation tablePart
|
||||||
|
@ -194,6 +229,11 @@ done:
|
||||||
[tf setTextColor:color];
|
[tf setTextColor:color];
|
||||||
// TODO release color
|
// TODO release color
|
||||||
}
|
}
|
||||||
|
if (self.editable) {
|
||||||
|
[tf setEditable:YES];
|
||||||
|
[tf setTarget:m->m];
|
||||||
|
[tf setAction:@selector(onAction:)];
|
||||||
|
}
|
||||||
view = tf;
|
view = tf;
|
||||||
break;
|
break;
|
||||||
case partImage:
|
case partImage:
|
||||||
|
@ -325,6 +365,14 @@ void uiTableColumnAppendImagePart(uiTableColumn *c, int modelColumn, int expand)
|
||||||
[c->parts addObject:part];
|
[c->parts addObject:part];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void uiTableColumnPartSetEditable(uiTableColumn *c, int part, int editable)
|
||||||
|
{
|
||||||
|
tablePart *p;
|
||||||
|
|
||||||
|
p = (tablePart *) [c->parts objectAtIndex:part];
|
||||||
|
p.editable = editable;
|
||||||
|
}
|
||||||
|
|
||||||
void uiTableColumnPartSetTextColor(uiTableColumn *c, int part, int modelColumn)
|
void uiTableColumnPartSetTextColor(uiTableColumn *c, int part, int modelColumn)
|
||||||
{
|
{
|
||||||
tablePart *p;
|
tablePart *p;
|
||||||
|
|
|
@ -23,6 +23,7 @@ static int modelNumRows(uiTableModelHandler *mh, uiTableModel *m)
|
||||||
}
|
}
|
||||||
|
|
||||||
static uiImage *img[2];
|
static uiImage *img[2];
|
||||||
|
static char row9text[1024];
|
||||||
|
|
||||||
static void *modelCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int col)
|
static void *modelCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int col)
|
||||||
{
|
{
|
||||||
|
@ -49,17 +50,21 @@ static void *modelCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, i
|
||||||
case 0:
|
case 0:
|
||||||
sprintf(buf, "Row %d", row);
|
sprintf(buf, "Row %d", row);
|
||||||
break;
|
break;
|
||||||
case 1:
|
|
||||||
case 2:
|
case 2:
|
||||||
|
if (row == 9)
|
||||||
|
return uiTableModelStrdup(row9text);
|
||||||
|
// fall through
|
||||||
|
case 1:
|
||||||
strcpy(buf, "Part");
|
strcpy(buf, "Part");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
return uiTableModelStrdup(buf);
|
return uiTableModelStrdup(buf);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void modelSetCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int col, void *val)
|
static void modelSetCellValue(uiTableModelHandler *mh, uiTableModel *m, int row, int col, const void *val)
|
||||||
{
|
{
|
||||||
// not implemented yet
|
if (row == 9 && col == 2)
|
||||||
|
strcpy(row9text, (const char *) val);
|
||||||
}
|
}
|
||||||
|
|
||||||
uiBox *makePage16(void)
|
uiBox *makePage16(void)
|
||||||
|
@ -76,6 +81,8 @@ uiBox *makePage16(void)
|
||||||
appendImageNamed(img[1], "tango-icon-theme-0.8.90_16x16_x-office-spreadsheet.png");
|
appendImageNamed(img[1], "tango-icon-theme-0.8.90_16x16_x-office-spreadsheet.png");
|
||||||
appendImageNamed(img[1], "tango-icon-theme-0.8.90_32x32_x-office-spreadsheet.png");
|
appendImageNamed(img[1], "tango-icon-theme-0.8.90_32x32_x-office-spreadsheet.png");
|
||||||
|
|
||||||
|
strcpy(row9text, "Part");
|
||||||
|
|
||||||
page16 = newVerticalBox();
|
page16 = newVerticalBox();
|
||||||
|
|
||||||
mh.NumColumns = modelNumColumns;
|
mh.NumColumns = modelNumColumns;
|
||||||
|
@ -95,6 +102,7 @@ uiBox *makePage16(void)
|
||||||
uiTableColumnAppendTextPart(tc, 1, 0);
|
uiTableColumnAppendTextPart(tc, 1, 0);
|
||||||
uiTableColumnAppendTextPart(tc, 2, 1);
|
uiTableColumnAppendTextPart(tc, 2, 1);
|
||||||
uiTableColumnPartSetTextColor(tc, 1, 4);
|
uiTableColumnPartSetTextColor(tc, 1, 4);
|
||||||
|
uiTableColumnPartSetEditable(tc, 2, 1);
|
||||||
|
|
||||||
uiTableSetRowBackgroundColorModelColumn(t, 3);
|
uiTableSetRowBackgroundColorModelColumn(t, 3);
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ struct uiTableModelHandler {
|
||||||
uiTableModelColumnType (*ColumnType)(uiTableModelHandler *, uiTableModel *, int);
|
uiTableModelColumnType (*ColumnType)(uiTableModelHandler *, uiTableModel *, int);
|
||||||
int (*NumRows)(uiTableModelHandler *, uiTableModel *);
|
int (*NumRows)(uiTableModelHandler *, uiTableModel *);
|
||||||
void *(*CellValue)(uiTableModelHandler *, uiTableModel *, int, int);
|
void *(*CellValue)(uiTableModelHandler *, uiTableModel *, int, int);
|
||||||
void (*SetCellValue)(uiTableModelHandler *, uiTableModel *, int, int, void *);
|
void (*SetCellValue)(uiTableModelHandler *, uiTableModel *, int, int, const void *);
|
||||||
};
|
};
|
||||||
|
|
||||||
_UI_EXTERN void *uiTableModelStrdup(const char *str);
|
_UI_EXTERN void *uiTableModelStrdup(const char *str);
|
||||||
|
@ -41,6 +41,8 @@ typedef struct uiTableColumn uiTableColumn;
|
||||||
_UI_EXTERN void uiTableColumnAppendTextPart(uiTableColumn *c, int modelColumn, int expand);
|
_UI_EXTERN void uiTableColumnAppendTextPart(uiTableColumn *c, int modelColumn, int expand);
|
||||||
// TODO images shouldn't expand...
|
// TODO images shouldn't expand...
|
||||||
_UI_EXTERN void uiTableColumnAppendImagePart(uiTableColumn *c, int modelColumn, int expand);
|
_UI_EXTERN void uiTableColumnAppendImagePart(uiTableColumn *c, int modelColumn, int expand);
|
||||||
|
// TODO Editable?
|
||||||
|
_UI_EXTERN void uiTableColumnPartSetEditable(uiTableColumn *c, int part, int editable);
|
||||||
_UI_EXTERN void uiTableColumnPartSetTextColor(uiTableColumn *c, int part, int modelColumn);
|
_UI_EXTERN void uiTableColumnPartSetTextColor(uiTableColumn *c, int part, int modelColumn);
|
||||||
|
|
||||||
typedef struct uiTable uiTable;
|
typedef struct uiTable uiTable;
|
||||||
|
|
Loading…
Reference in New Issue