2016-06-21 22:58:17 -05:00
|
|
|
// 21 june 2016
|
|
|
|
#import "uipriv_darwin.h"
|
|
|
|
|
2016-06-21 23:58:10 -05:00
|
|
|
// TODOs
|
2016-06-22 22:08:39 -05:00
|
|
|
// - initial state of table view is off
|
2016-06-21 23:58:10 -05:00
|
|
|
// - header cell seems off
|
2016-06-23 14:06:07 -05:00
|
|
|
// - background color shows up for a line or two below selection
|
2016-06-25 22:04:49 -05:00
|
|
|
// - editable NSTextFields have no intrinsic width
|
|
|
|
// - changing a part property does not refresh views
|
2016-06-26 14:36:46 -05:00
|
|
|
// - is the Y position of checkbox cells correct?
|
2016-06-26 17:19:34 -05:00
|
|
|
// - progressbars appear ABOVE the table header
|
|
|
|
|
|
|
|
// LONGTERM
|
|
|
|
// - reuse row views instead of creating a new one each time
|
2016-06-21 23:58:10 -05:00
|
|
|
|
2016-06-21 22:58:17 -05:00
|
|
|
@interface tableModel : NSObject<NSTableViewDataSource, NSTableViewDelegate> {
|
|
|
|
uiTableModel *libui_m;
|
|
|
|
}
|
|
|
|
- (id)initWithModel:(uiTableModel *)m;
|
2016-06-25 22:04:49 -05:00
|
|
|
- (IBAction)onAction:(id)sender;
|
2016-06-21 22:58:17 -05:00
|
|
|
@end
|
|
|
|
|
|
|
|
enum {
|
|
|
|
partText,
|
2016-06-25 18:18:25 -05:00
|
|
|
partImage,
|
2016-06-26 12:06:33 -05:00
|
|
|
partButton,
|
2016-06-26 14:36:46 -05:00
|
|
|
partCheckbox,
|
2016-06-26 17:19:34 -05:00
|
|
|
partProgressBar,
|
2016-06-21 22:58:17 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
@interface tablePart : NSObject
|
|
|
|
@property int type;
|
2016-06-23 08:56:24 -05:00
|
|
|
@property int textColumn;
|
2016-06-23 21:16:25 -05:00
|
|
|
@property int textColorColumn;
|
2016-06-25 18:18:25 -05:00
|
|
|
@property int imageColumn;
|
2016-06-26 14:36:46 -05:00
|
|
|
@property int valueColumn;
|
2016-06-21 22:58:17 -05:00
|
|
|
@property int expand;
|
2016-06-25 22:04:49 -05:00
|
|
|
@property int editable;
|
2016-06-21 22:58:17 -05:00
|
|
|
- (NSView *)mkView:(uiTableModel *)m row:(int)row;
|
|
|
|
@end
|
|
|
|
|
|
|
|
@interface tableColumn : NSTableColumn
|
|
|
|
@property uiTableColumn *libui_col;
|
|
|
|
@end
|
|
|
|
|
2016-06-23 10:29:43 -05:00
|
|
|
@interface tableView : NSTableView
|
|
|
|
@property uiTable *libui_t;
|
|
|
|
@end
|
|
|
|
|
2016-06-21 22:58:17 -05:00
|
|
|
struct uiTableModel {
|
|
|
|
uiTableModelHandler *mh;
|
|
|
|
tableModel *m;
|
|
|
|
NSMutableArray *tables;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct uiTableColumn {
|
2016-06-21 23:40:30 -05:00
|
|
|
tableColumn *c;
|
2016-06-21 22:58:17 -05:00
|
|
|
NSMutableArray *parts;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct uiTable {
|
|
|
|
uiDarwinControl c;
|
|
|
|
NSScrollView *sv;
|
2016-06-23 10:29:43 -05:00
|
|
|
tableView *tv;
|
2016-06-21 23:40:30 -05:00
|
|
|
struct scrollViewData *d;
|
2016-06-23 10:29:43 -05:00
|
|
|
int backgroundColumn;
|
2016-06-21 22:58:17 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
@implementation tableModel
|
|
|
|
|
|
|
|
- (id)initWithModel:(uiTableModel *)m
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self)
|
|
|
|
self->libui_m = m;
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger)numberOfRowsInTableView:(NSTableView *)tv
|
|
|
|
{
|
|
|
|
uiTableModelHandler *mh = self->libui_m->mh;
|
|
|
|
|
2016-06-21 23:58:10 -05:00
|
|
|
return (*(mh->NumRows))(mh, self->libui_m);
|
2016-06-21 22:58:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// these are according to Interface Builder
|
|
|
|
#define xleft 2
|
|
|
|
#define xmiddle 7 /* between images and text, anyway; let's just use it for everything to be simpler */
|
|
|
|
#define xright 3
|
|
|
|
|
|
|
|
- (NSView *)tableView:(NSTableView *)tv viewForTableColumn:(NSTableColumn *)cc row:(NSInteger)row
|
|
|
|
{
|
2016-06-22 00:06:47 -05:00
|
|
|
NSTableCellView *v;
|
2016-06-21 22:58:17 -05:00
|
|
|
tableColumn *c = (tableColumn *) cc;
|
|
|
|
tablePart *part;
|
|
|
|
NSMutableArray *views;
|
|
|
|
NSView *view, *prev;
|
|
|
|
|
2016-06-22 00:06:47 -05:00
|
|
|
v = [[NSTableCellView alloc] initWithFrame:NSZeroRect];
|
2016-06-21 22:58:17 -05:00
|
|
|
|
|
|
|
views = [NSMutableArray new];
|
|
|
|
for (part in c.libui_col->parts)
|
|
|
|
[views addObject:[part mkView:self->libui_m row:row]];
|
|
|
|
if ([views count] == 0) // empty (TODO allow?)
|
|
|
|
goto done;
|
|
|
|
|
2016-06-21 23:58:10 -05:00
|
|
|
// add to v and arrange horizontally
|
2016-06-21 22:58:17 -05:00
|
|
|
prev = nil;
|
|
|
|
for (view in views) {
|
2016-06-21 23:58:10 -05:00
|
|
|
[v addSubview:view];
|
2016-06-22 00:06:47 -05:00
|
|
|
// TODO set [v imageView] and [v textField] as appropriate?
|
2016-06-21 22:58:17 -05:00
|
|
|
if (prev == nil) { // first view
|
|
|
|
[v addConstraint:mkConstraint(v, NSLayoutAttributeLeading,
|
|
|
|
NSLayoutRelationEqual,
|
|
|
|
view, NSLayoutAttributeLeading,
|
|
|
|
1, -xleft,
|
|
|
|
@"uiTableColumn first part horizontal constraint")];
|
|
|
|
prev = view;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
[v addConstraint:mkConstraint(prev, NSLayoutAttributeTrailing,
|
|
|
|
NSLayoutRelationEqual,
|
|
|
|
view, NSLayoutAttributeLeading,
|
|
|
|
1, -xmiddle,
|
|
|
|
@"uiTableColumn middle horizontal constraint")];
|
|
|
|
prev = view;
|
|
|
|
}
|
|
|
|
[v addConstraint:mkConstraint(prev, NSLayoutAttributeTrailing,
|
|
|
|
NSLayoutRelationEqual,
|
|
|
|
v, NSLayoutAttributeTrailing,
|
|
|
|
1, -xright,
|
|
|
|
@"uiTableColumn last part horizontal constraint")];
|
|
|
|
|
|
|
|
// and vertically
|
2016-06-25 18:18:25 -05:00
|
|
|
for (view in views) {
|
2016-06-21 22:58:17 -05:00
|
|
|
[v addConstraint:mkConstraint(view, NSLayoutAttributeCenterY,
|
|
|
|
NSLayoutRelationEqual,
|
|
|
|
v, NSLayoutAttributeCenterY,
|
|
|
|
1, 0,
|
|
|
|
@"uiTableColumn part vertical constraint")];
|
2016-06-25 18:18:25 -05:00
|
|
|
// TODO avoid the need for this hack
|
|
|
|
if ([view isKindOfClass:[NSImageView class]])
|
|
|
|
[v addConstraint:mkConstraint(view, NSLayoutAttributeTop,
|
|
|
|
NSLayoutRelationEqual,
|
|
|
|
v, NSLayoutAttributeTop,
|
|
|
|
1, 0,
|
|
|
|
@"uiTableColumn part vertical top constraint")];
|
|
|
|
}
|
2016-06-21 22:58:17 -05:00
|
|
|
|
|
|
|
done:
|
|
|
|
[views release];
|
2016-06-21 23:58:10 -05:00
|
|
|
[v setTranslatesAutoresizingMaskIntoConstraints:NO];
|
2016-06-21 22:58:17 -05:00
|
|
|
// TODO autorelease?
|
|
|
|
return v;
|
|
|
|
}
|
|
|
|
|
2016-06-23 10:29:43 -05:00
|
|
|
- (void)tableView:(NSTableView *)nstv didAddRowView:(NSTableRowView *)rv forRow:(NSInteger)row
|
|
|
|
{
|
|
|
|
uiTableModel *m = self->libui_m;
|
|
|
|
tableView *tv = (tableView *) nstv;
|
|
|
|
uiTable *t = tv.libui_t;
|
|
|
|
NSColor *color;
|
|
|
|
|
|
|
|
if (t->backgroundColumn == -1)
|
|
|
|
return;
|
|
|
|
color = (NSColor *) ((*(m->mh->CellValue))(m->mh, m, row, t->backgroundColumn));
|
|
|
|
if (color == nil)
|
|
|
|
return;
|
|
|
|
[rv setBackgroundColor:color];
|
|
|
|
// TODO autorelease color? or release it?
|
|
|
|
}
|
|
|
|
|
2016-06-25 22:04:49 -05:00
|
|
|
- (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]])
|
2016-06-25 22:06:13 -05:00
|
|
|
data = [[((NSTextField *) view) stringValue] UTF8String];
|
2016-06-26 14:36:46 -05:00
|
|
|
else if ([view isKindOfClass:[NSButton class]]) {
|
|
|
|
NSButton *b;
|
|
|
|
|
|
|
|
b = (NSButton *) view;
|
|
|
|
// if ([b buttonType] == NSSwitchButton)
|
|
|
|
data = uiTableModelGiveInt([b state] == NSOnState);
|
|
|
|
// TODO there is no buttonType getter
|
|
|
|
if(1); else
|
|
|
|
data = NULL;
|
|
|
|
} else
|
2016-06-25 22:04:49 -05:00
|
|
|
implbug("table model editing action triggered on non-editable view");
|
|
|
|
|
2016-06-25 23:44:21 -05:00
|
|
|
// note the use of [view tag] — we need the model column, which we store in the view tag for relevant views below
|
2016-06-25 22:04:49 -05:00
|
|
|
(*(m->mh->SetCellValue))(m->mh, m,
|
2016-06-25 23:44:21 -05:00
|
|
|
row, [view tag],
|
2016-06-25 22:04:49 -05:00
|
|
|
data);
|
|
|
|
// always refresh the value in case the model rejected it
|
2016-06-26 12:06:33 -05:00
|
|
|
// TODO only affect tv?
|
2016-06-25 22:04:49 -05:00
|
|
|
uiTableModelRowChanged(m, row);
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:58:17 -05:00
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation tablePart
|
|
|
|
|
2016-06-23 21:16:25 -05:00
|
|
|
- (id)init
|
|
|
|
{
|
|
|
|
self = [super init];
|
|
|
|
if (self) {
|
|
|
|
self.textColumn = -1;
|
|
|
|
self.textColorColumn = -1;
|
|
|
|
}
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2016-06-21 23:58:10 -05:00
|
|
|
- (NSView *)mkView:(uiTableModel *)m row:(int)row
|
2016-06-21 22:58:17 -05:00
|
|
|
{
|
|
|
|
void *data;
|
|
|
|
NSString *str;
|
|
|
|
NSView *view;
|
|
|
|
NSTextField *tf;
|
2016-06-25 18:18:25 -05:00
|
|
|
NSImageView *iv;
|
2016-06-26 12:06:33 -05:00
|
|
|
NSButton *b;
|
2016-06-26 17:19:34 -05:00
|
|
|
NSProgressIndicator *p;
|
|
|
|
int value;
|
2016-06-21 22:58:17 -05:00
|
|
|
|
|
|
|
switch (self.type) {
|
|
|
|
case partText:
|
2016-06-25 18:18:25 -05:00
|
|
|
data = (*(m->mh->CellValue))(m->mh, m, row, self.textColumn);
|
2016-06-21 22:58:17 -05:00
|
|
|
str = toNSString((char *) data);
|
|
|
|
uiFree(data);
|
|
|
|
tf = newLabel(str);
|
2016-06-23 21:16:25 -05:00
|
|
|
// TODO set wrap and ellipsize modes?
|
|
|
|
if (self.textColorColumn != -1) {
|
|
|
|
NSColor *color;
|
|
|
|
|
|
|
|
color = (NSColor *) ((*(m->mh->CellValue))(m->mh, m, row, self.textColorColumn));
|
|
|
|
if (color != nil)
|
|
|
|
[tf setTextColor:color];
|
|
|
|
// TODO release color
|
|
|
|
}
|
2016-06-25 22:04:49 -05:00
|
|
|
if (self.editable) {
|
|
|
|
[tf setEditable:YES];
|
|
|
|
[tf setTarget:m->m];
|
|
|
|
[tf setAction:@selector(onAction:)];
|
|
|
|
}
|
2016-06-26 12:06:33 -05:00
|
|
|
[tf setTag:self.textColumn];
|
2016-06-21 22:58:17 -05:00
|
|
|
view = tf;
|
|
|
|
break;
|
2016-06-25 18:18:25 -05:00
|
|
|
case partImage:
|
|
|
|
data = (*(m->mh->CellValue))(m->mh, m, row, self.imageColumn);
|
|
|
|
iv = [[NSImageView alloc] initWithFrame:NSZeroRect];
|
|
|
|
[iv setImage:imageImage((uiImage *) data)];
|
|
|
|
[iv setImageFrameStyle:NSImageFrameNone];
|
|
|
|
[iv setImageAlignment:NSImageAlignCenter];
|
|
|
|
[iv setImageScaling:NSImageScaleProportionallyDown];
|
|
|
|
[iv setAnimates:NO];
|
|
|
|
[iv setEditable:NO];
|
|
|
|
[iv addConstraint:mkConstraint(iv, NSLayoutAttributeWidth,
|
|
|
|
NSLayoutRelationEqual,
|
|
|
|
iv, NSLayoutAttributeHeight,
|
|
|
|
1, 0,
|
|
|
|
@"uiTable image squareness constraint")];
|
2016-06-26 12:06:33 -05:00
|
|
|
[iv setTag:self.imageColumn];
|
2016-06-25 18:18:25 -05:00
|
|
|
view = iv;
|
|
|
|
break;
|
2016-06-26 12:06:33 -05:00
|
|
|
case partButton:
|
|
|
|
// TODO buttons get clipped
|
|
|
|
data = (*(m->mh->CellValue))(m->mh, m, row, self.textColumn);
|
|
|
|
str = toNSString((char *) data);
|
|
|
|
b = [[NSButton alloc] initWithFrame:NSZeroRect];
|
|
|
|
[b setTitle:str];
|
|
|
|
[b setButtonType:NSMomentaryPushInButton];
|
|
|
|
[b setBordered:YES];
|
|
|
|
[b setBezelStyle:NSRoundRectBezelStyle];
|
|
|
|
uiDarwinSetControlFont(b, NSRegularControlSize);
|
|
|
|
if (self.editable) {
|
|
|
|
[b setTarget:m->m];
|
|
|
|
[b setAction:@selector(onAction:)];
|
|
|
|
} else
|
|
|
|
[b setEnabled:NO];
|
|
|
|
[b setTag:self.textColumn];
|
|
|
|
view = b;
|
|
|
|
break;
|
2016-06-26 14:36:46 -05:00
|
|
|
case partCheckbox:
|
|
|
|
data = (*(m->mh->CellValue))(m->mh, m, row, self.valueColumn);
|
|
|
|
b = [[NSButton alloc] initWithFrame:NSZeroRect];
|
|
|
|
[b setTitle:@""];
|
|
|
|
[b setButtonType:NSSwitchButton];
|
|
|
|
// doesn't seem to have an associated bezel style
|
|
|
|
[b setBordered:NO];
|
|
|
|
[b setTransparent:NO];
|
|
|
|
uiDarwinSetControlFont(b, NSRegularControlSize);
|
|
|
|
if (uiTableModelTakeInt(data) != 0)
|
|
|
|
[b setState:NSOnState];
|
|
|
|
else
|
|
|
|
[b setState:NSOffState];
|
|
|
|
if (self.editable) {
|
|
|
|
[b setTarget:m->m];
|
|
|
|
[b setAction:@selector(onAction:)];
|
|
|
|
} else
|
|
|
|
[b setEnabled:NO];
|
|
|
|
[b setTag:self.valueColumn];
|
|
|
|
view = b;
|
|
|
|
break;
|
2016-06-26 17:19:34 -05:00
|
|
|
case partProgressBar:
|
|
|
|
data = (*(m->mh->CellValue))(m->mh, m, row, self.valueColumn);
|
|
|
|
value = uiTableModelTakeInt(data);
|
|
|
|
// TODO no intrinsic width
|
|
|
|
p = [[NSProgressIndicator alloc] initWithFrame:NSZeroRect];
|
|
|
|
[p setControlSize:NSRegularControlSize];
|
|
|
|
[p setBezeled:YES];
|
|
|
|
[p setStyle:NSProgressIndicatorBarStyle];
|
|
|
|
if (value == -1) {
|
|
|
|
[p setIndeterminate:YES];
|
|
|
|
[p startAnimation:p];
|
|
|
|
} else if (value == 100) {
|
|
|
|
[p setIndeterminate:NO];
|
|
|
|
[p setMaxValue:101];
|
|
|
|
[p setDoubleValue:101];
|
|
|
|
[p setDoubleValue:100];
|
|
|
|
[p setMaxValue:100];
|
|
|
|
} else {
|
|
|
|
[p setIndeterminate:NO];
|
|
|
|
[p setDoubleValue:(value + 1)];
|
|
|
|
[p setDoubleValue:value];
|
|
|
|
}
|
|
|
|
view = p;
|
|
|
|
break;
|
2016-06-21 22:58:17 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
// if stretchy, don't hug, otherwise hug forcibly
|
|
|
|
if (self.expand)
|
|
|
|
[view setContentHuggingPriority:NSLayoutPriorityDefaultLow forOrientation:NSLayoutConstraintOrientationHorizontal];
|
|
|
|
else
|
|
|
|
[view setContentHuggingPriority:NSLayoutPriorityRequired forOrientation:NSLayoutConstraintOrientationHorizontal];
|
2016-06-21 23:58:10 -05:00
|
|
|
[view setTranslatesAutoresizingMaskIntoConstraints:NO];
|
2016-06-21 22:58:17 -05:00
|
|
|
// TODO autorelease?
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
@implementation tableColumn
|
|
|
|
@end
|
|
|
|
|
2016-06-23 10:29:43 -05:00
|
|
|
@implementation tableView
|
|
|
|
@end
|
|
|
|
|
2016-06-21 22:58:17 -05:00
|
|
|
void *uiTableModelStrdup(const char *str)
|
|
|
|
{
|
|
|
|
// TODO don't we have this already?
|
|
|
|
char *dup;
|
|
|
|
|
|
|
|
dup = (char *) uiAlloc((strlen(str) + 1) * sizeof (char), "char[]");
|
|
|
|
strcpy(dup, str);
|
|
|
|
return dup;
|
|
|
|
}
|
|
|
|
|
2016-06-21 23:58:10 -05:00
|
|
|
uiTableModel *uiNewTableModel(uiTableModelHandler *mh)
|
2016-06-21 22:58:17 -05:00
|
|
|
{
|
|
|
|
uiTableModel *m;
|
|
|
|
|
|
|
|
m = uiNew(uiTableModel);
|
|
|
|
m->mh = mh;
|
|
|
|
m->m = [[tableModel alloc] initWithModel:m];
|
|
|
|
m->tables = [NSMutableArray new];
|
|
|
|
return m;
|
|
|
|
}
|
|
|
|
|
2016-06-23 10:29:43 -05:00
|
|
|
void *uiTableModelGiveColor(double r, double g, double b, double a)
|
|
|
|
{
|
|
|
|
return [[NSColor colorWithSRGBRed:r green:g blue:b alpha:a] retain];
|
|
|
|
}
|
|
|
|
|
2016-06-21 22:58:17 -05:00
|
|
|
void uiFreeTableModel(uiTableModel *m)
|
|
|
|
{
|
|
|
|
if ([m->tables count] != 0)
|
|
|
|
userbug("You cannot free a uiTableModel while uiTables are using it.");
|
|
|
|
[m->tables release];
|
|
|
|
[m->m release];
|
|
|
|
uiFree(m);
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiTableModelRowInserted(uiTableModel *m, int newIndex)
|
|
|
|
{
|
|
|
|
NSTableView *tv;
|
|
|
|
NSIndexSet *set;
|
|
|
|
|
2016-06-21 23:58:10 -05:00
|
|
|
set = [NSIndexSet indexSetWithIndex:newIndex];
|
2016-06-21 22:58:17 -05:00
|
|
|
for (tv in m->tables)
|
|
|
|
[tv insertRowsAtIndexes:set withAnimation:NSTableViewAnimationEffectNone];
|
|
|
|
// set is autoreleased
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiTableModelRowChanged(uiTableModel *m, int index)
|
|
|
|
{
|
|
|
|
NSTableView *tv;
|
|
|
|
NSIndexSet *set, *cols;
|
|
|
|
|
|
|
|
set = [NSIndexSet indexSetWithIndex:index];
|
|
|
|
for (tv in m->tables) {
|
|
|
|
cols = [[NSIndexSet alloc] initWithIndexesInRange:NSMakeRange(0, [[tv tableColumns] count])];
|
|
|
|
[tv reloadDataForRowIndexes:set columnIndexes:cols];
|
2016-06-26 12:06:33 -05:00
|
|
|
// TODO this isn't enough
|
2016-06-21 22:58:17 -05:00
|
|
|
[cols release];
|
|
|
|
}
|
|
|
|
// set is autoreleased
|
|
|
|
}
|
|
|
|
|
|
|
|
void uiTableModelRowDeleted(uiTableModel *m, int oldIndex)
|
|
|
|
{
|
|
|
|
NSTableView *tv;
|
|
|
|
NSIndexSet *set;
|
|
|
|
|
2016-06-21 23:58:10 -05:00
|
|
|
set = [NSIndexSet indexSetWithIndex:oldIndex];
|
2016-06-21 22:58:17 -05:00
|
|
|
for (tv in m->tables)
|
|
|
|
[tv removeRowsAtIndexes:set withAnimation:NSTableViewAnimationEffectNone];
|
|
|
|
// set is autoreleased
|
|
|
|
}
|
|
|
|
|
2016-06-23 08:56:24 -05:00
|
|
|
void uiTableColumnAppendTextPart(uiTableColumn *c, int modelColumn, int expand)
|
2016-06-21 23:40:30 -05:00
|
|
|
{
|
2016-06-23 08:56:24 -05:00
|
|
|
tablePart *part;
|
2016-06-21 23:40:30 -05:00
|
|
|
|
2016-06-23 08:56:24 -05:00
|
|
|
part = [tablePart new];
|
|
|
|
part.type = partText;
|
|
|
|
part.textColumn = modelColumn;
|
|
|
|
part.expand = expand;
|
|
|
|
[c->parts addObject:part];
|
2016-06-21 23:40:30 -05:00
|
|
|
}
|
2016-06-23 21:16:25 -05:00
|
|
|
|
2016-06-25 18:18:25 -05:00
|
|
|
void uiTableColumnAppendImagePart(uiTableColumn *c, int modelColumn, int expand)
|
|
|
|
{
|
|
|
|
tablePart *part;
|
|
|
|
|
|
|
|
part = [tablePart new];
|
|
|
|
part.type = partImage;
|
|
|
|
part.imageColumn = modelColumn;
|
|
|
|
part.expand = expand;
|
|
|
|
[c->parts addObject:part];
|
|
|
|
}
|
|
|
|
|
2016-06-26 12:06:33 -05:00
|
|
|
void uiTableColumnAppendButtonPart(uiTableColumn *c, int modelColumn, int expand)
|
|
|
|
{
|
|
|
|
tablePart *part;
|
|
|
|
|
|
|
|
part = [tablePart new];
|
|
|
|
part.type = partButton;
|
|
|
|
part.textColumn = modelColumn;
|
|
|
|
part.expand = expand;
|
|
|
|
part.editable = 1; // editable by default
|
|
|
|
[c->parts addObject:part];
|
|
|
|
}
|
|
|
|
|
2016-06-26 14:36:46 -05:00
|
|
|
void uiTableColumnAppendCheckboxPart(uiTableColumn *c, int modelColumn, int expand)
|
|
|
|
{
|
|
|
|
tablePart *part;
|
|
|
|
|
|
|
|
part = [tablePart new];
|
|
|
|
part.type = partCheckbox;
|
|
|
|
part.valueColumn = modelColumn;
|
|
|
|
part.expand = expand;
|
|
|
|
part.editable = 1; // editable by default
|
|
|
|
[c->parts addObject:part];
|
|
|
|
}
|
|
|
|
|
2016-06-26 17:19:34 -05:00
|
|
|
void uiTableColumnAppendProgressBarPart(uiTableColumn *c, int modelColumn, int expand)
|
|
|
|
{
|
|
|
|
tablePart *part;
|
|
|
|
|
|
|
|
part = [tablePart new];
|
|
|
|
part.type = partProgressBar;
|
|
|
|
part.valueColumn = modelColumn;
|
|
|
|
part.expand = expand;
|
|
|
|
[c->parts addObject:part];
|
|
|
|
}
|
|
|
|
|
2016-06-25 22:04:49 -05:00
|
|
|
void uiTableColumnPartSetEditable(uiTableColumn *c, int part, int editable)
|
|
|
|
{
|
|
|
|
tablePart *p;
|
|
|
|
|
|
|
|
p = (tablePart *) [c->parts objectAtIndex:part];
|
|
|
|
p.editable = editable;
|
|
|
|
}
|
|
|
|
|
2016-06-23 21:16:25 -05:00
|
|
|
void uiTableColumnPartSetTextColor(uiTableColumn *c, int part, int modelColumn)
|
|
|
|
{
|
|
|
|
tablePart *p;
|
|
|
|
|
|
|
|
p = (tablePart *) [c->parts objectAtIndex:part];
|
|
|
|
p.textColorColumn = modelColumn;
|
|
|
|
}
|
2016-06-21 23:40:30 -05:00
|
|
|
|
|
|
|
uiDarwinControlAllDefaultsExceptDestroy(uiTable, sv)
|
|
|
|
|
|
|
|
static void uiTableDestroy(uiControl *c)
|
|
|
|
{
|
|
|
|
uiTable *t = uiTable(c);
|
|
|
|
|
|
|
|
// TODO
|
|
|
|
[t->sv release];
|
|
|
|
uiFreeControl(uiControl(t));
|
|
|
|
}
|
|
|
|
|
|
|
|
uiTableColumn *uiTableAppendColumn(uiTable *t, const char *name)
|
|
|
|
{
|
|
|
|
uiTableColumn *c;
|
|
|
|
|
2016-06-21 23:58:10 -05:00
|
|
|
c = uiNew(uiTableColumn);
|
2016-06-21 23:40:30 -05:00
|
|
|
c->c = [[tableColumn alloc] initWithIdentifier:@""];
|
2016-06-21 23:58:10 -05:00
|
|
|
c->c.libui_col = c;
|
2016-06-21 23:40:30 -05:00
|
|
|
// via Interface Builder
|
|
|
|
[c->c setResizingMask:(NSTableColumnAutoresizingMask | NSTableColumnUserResizingMask)];
|
2016-06-29 07:53:49 -05:00
|
|
|
// 10.10 adds -[NSTableColumn setTitle:]; before then we have to do this
|
|
|
|
[[c->c headerCell] setStringValue:toNSString(name)];
|
2016-06-21 23:40:30 -05:00
|
|
|
// TODO is this sufficient?
|
|
|
|
[[c->c headerCell] setFont:[NSFont systemFontOfSize:[NSFont systemFontSizeForControlSize:NSSmallControlSize]]];
|
|
|
|
c->parts = [NSMutableArray new];
|
|
|
|
[t->tv addTableColumn:c->c];
|
|
|
|
return c;
|
|
|
|
}
|
2016-06-21 22:58:17 -05:00
|
|
|
|
2016-06-23 10:29:43 -05:00
|
|
|
void uiTableSetRowBackgroundColorModelColumn(uiTable *t, int modelColumn)
|
|
|
|
{
|
|
|
|
t->backgroundColumn = modelColumn;
|
|
|
|
}
|
|
|
|
|
2016-06-21 23:40:30 -05:00
|
|
|
uiTable *uiNewTable(uiTableModel *model)
|
|
|
|
{
|
|
|
|
uiTable *t;
|
|
|
|
struct scrollViewCreateParams p;
|
|
|
|
|
|
|
|
uiDarwinNewControl(uiTable, t);
|
|
|
|
|
2016-06-23 10:29:43 -05:00
|
|
|
t->tv = [[tableView alloc] initWithFrame:NSZeroRect];
|
|
|
|
t->tv.libui_t = t;
|
2016-06-21 23:40:30 -05:00
|
|
|
|
2016-06-21 23:58:10 -05:00
|
|
|
[t->tv setDataSource:model->m];
|
|
|
|
[t->tv setDelegate:model->m];
|
|
|
|
[t->tv reloadData];
|
|
|
|
[model->tables addObject:t->tv];
|
2016-06-21 23:40:30 -05:00
|
|
|
|
|
|
|
// TODO is this sufficient?
|
2016-06-21 23:58:10 -05:00
|
|
|
[t->tv setAllowsColumnReordering:NO];
|
|
|
|
[t->tv setAllowsColumnResizing:YES];
|
|
|
|
[t->tv setAllowsMultipleSelection:NO];
|
|
|
|
[t->tv setAllowsEmptySelection:YES];
|
|
|
|
[t->tv setAllowsColumnSelection:NO];
|
|
|
|
[t->tv setUsesAlternatingRowBackgroundColors:YES];
|
|
|
|
[t->tv setSelectionHighlightStyle:NSTableViewSelectionHighlightStyleRegular];
|
|
|
|
[t->tv setGridStyleMask:NSTableViewGridNone];
|
|
|
|
[t->tv setAllowsTypeSelect:YES];
|
2016-06-21 23:40:30 -05:00
|
|
|
// TODO floatsGroupRows — do we even allow group rows?
|
|
|
|
|
|
|
|
memset(&p, 0, sizeof (struct scrollViewCreateParams));
|
|
|
|
p.DocumentView = t->tv;
|
|
|
|
// this is what Interface Builder sets it to
|
|
|
|
// TODO verify
|
|
|
|
p.BackgroundColor = [NSColor colorWithCalibratedWhite:1.0 alpha:1.0];
|
|
|
|
p.DrawsBackground = YES;
|
|
|
|
p.Bordered = YES;
|
|
|
|
p.HScroll = YES;
|
|
|
|
p.VScroll = YES;
|
|
|
|
t->sv = mkScrollView(&p, &(t->d));
|
|
|
|
|
2016-06-23 10:29:43 -05:00
|
|
|
t->backgroundColumn = -1;
|
|
|
|
|
2016-06-21 23:40:30 -05:00
|
|
|
return t;
|
|
|
|
}
|