📄 osxctrls.m
字号:
rect = [b frame];
[parent addSubview:b];
c->button = b;
if (kh < rect.size.height)
kh = rect.size.height;
ch += VSPACING + kh;
if (cw < rect.size.width * 4)
cw = rect.size.width * 4;
}
break;
case CTRL_LISTBOX:
{
int listp = ctrl->listbox.percentwidth;
int labelp = listp == 100 ? 100 : 100 - listp;
NSTextField *tf;
NSPopUpButton *pb;
NSTableView *tv;
NSScrollView *sv;
if (ctrl->generic.label) {
tf = [[NSTextField alloc]
initWithFrame:NSMakeRect(0,0,1,1)];
[tf setEditable:NO];
[tf setSelectable:NO];
[tf setBordered:NO];
[tf setDrawsBackground:NO];
[tf setStringValue:
[NSString stringWithCString:ctrl->generic.label]];
[tf sizeToFit];
rect = [tf frame];
[parent addSubview:tf];
c->label = tf;
cw = rect.size.width;
ch = rect.size.height;
} else {
cw = 0;
ch = -VSPACING; /* compensate for next advance */
}
if (ctrl->listbox.height == 0) {
pb = [[NSPopUpButton alloc]
initWithFrame:NSMakeRect(0,0,1,1)];
[pb sizeToFit];
rect = [pb frame];
[parent addSubview:pb];
c->popupbutton = pb;
[pb setTarget:d->rec];
[pb setAction:@selector(popupMenuSelected:)];
add_widget(d, c, pb);
} else {
assert(listp == 100);
if (ctrl->listbox.draglist) {
int bi;
listp = 75;
for (bi = 0; bi < 2; bi++) {
NSButton *b;
b = [[MyButton alloc]
initWithFrame:NSMakeRect(0, 0, 1, 1)];
[b setBezelStyle:NSRoundedBezelStyle];
if (bi == 0)
[b setTitle:@"Up"];
else
[b setTitle:@"Down"];
[b sizeToFit];
rect = [b frame];
[parent addSubview:b];
if (bi == 0)
c->button = b;
else
c->button2 = b;
[b setTarget:d->rec];
[b setAction:@selector(dragListButton:)];
add_widget(d, c, b);
if (cw < rect.size.width * 4)
cw = rect.size.width * 4;
}
}
sv = [[NSScrollView alloc] initWithFrame:
NSMakeRect(20,20,10,10)];
[sv setBorderType:NSLineBorder];
tv = [[NSTableView alloc] initWithFrame:[sv frame]];
[[tv headerView] setFrame:NSMakeRect(0,0,0,0)];
[sv setDocumentView:tv];
[parent addSubview:sv];
[sv setHasVerticalScroller:YES];
[sv setAutohidesScrollers:YES];
[tv setAllowsColumnReordering:NO];
[tv setAllowsColumnResizing:NO];
[tv setAllowsMultipleSelection:ctrl->listbox.multisel];
[tv setAllowsEmptySelection:YES];
[tv setAllowsColumnSelection:YES];
[tv setDataSource:[[MyTableSource alloc] init]];
rect = [tv frame];
/*
* For some reason this consistently comes out
* one short. Add one.
*/
rect.size.height = (ctrl->listbox.height+1)*[tv rowHeight];
[sv setFrame:rect];
c->tableview = tv;
c->scrollview = sv;
[tv setDelegate:d->rec];
[tv setTarget:d->rec];
[tv setDoubleAction:@selector(listDoubleClicked:)];
add_widget(d, c, tv);
}
if (c->tableview) {
int ncols, *percentages;
int hundred = 100;
if (ctrl->listbox.ncols) {
ncols = ctrl->listbox.ncols;
percentages = ctrl->listbox.percentages;
} else {
ncols = 1;
percentages = &hundred;
}
for (j = 0; j < ncols; j++) {
NSTableColumn *col;
col = [[NSTableColumn alloc] initWithIdentifier:
[NSNumber numberWithInt:j]];
[c->tableview addTableColumn:col];
}
}
if (labelp == 100) {
/* the list and its label are vertically separated */
ch += VSPACING + rect.size.height;
} else {
/* the list and its label are horizontally separated */
if (ch < rect.size.height)
ch = rect.size.height;
}
if (cw < rect.size.width * 100 / listp)
cw = rect.size.width * 100 / listp;
}
break;
}
/*
* Update the width and height data for the control we've
* just created.
*/
ytop = 0;
for (j = colstart; j < colend; j++) {
if (ytop < cypos[j])
ytop = cypos[j];
}
for (j = colstart; j < colend; j++)
cypos[j] = ytop + ch + VSPACING;
if (hmin < ytop + ch)
hmin = ytop + ch;
wthis = (cw + HSPACING) * 100 / (ccw[colend] - ccw[colstart]);
wthis -= HSPACING;
if (wmin < wthis)
wmin = wthis;
}
if (*s->boxname) {
/*
* Add a bit to the width and height for the box.
*/
wmin += boxw;
hmin += boxh;
}
//printf("For controlset %s/%s, returning w=%d h=%d\n",
// s->pathname, s->boxname, wmin, hmin);
*minw = wmin;
*minh = hmin;
}
int place_ctrls(void *dv, struct controlset *s, int leftx, int topy,
int width)
{
struct fe_dlg *d = (struct fe_dlg *)dv;
int ccw[100]; /* cumulative column widths */
int cypos[100];
int ncols;
int i, j, ret;
int boxh = 0, boxw = 0;
if (!s->boxname && s->boxtitle) {
/* Size and place the panel title. */
NSTextField *tf = find_box(d, s);
NSRect rect;
rect = [tf frame];
[tf setFrame:NSMakeRect(leftx, topy-rect.size.height,
width, rect.size.height)];
return rect.size.height;
}
if (*s->boxname) {
NSRect rect, tmprect;
NSBox *box = find_box(d, s);
assert(box != NULL);
tmprect = [box frame];
[box setFrameFromContentFrame:NSMakeRect(100,100,100,100)];
rect = [box frame];
[box setFrame:tmprect];
boxw = rect.size.width - 100;
boxh = rect.size.height - 100;
if (s->boxtitle)
boxh += [[box titleFont] pointSize];
topy -= boxh;
width -= boxw;
}
ncols = 1;
ccw[0] = 0;
ccw[1] = 100;
cypos[0] = topy;
ret = 0;
/*
* Now iterate through the controls themselves, placing them
* appropriately.
*/
for (i = 0; i < s->ncontrols; i++) {
union control *ctrl = s->ctrls[i];
struct fe_ctrl *c;
int colstart = COLUMN_START(ctrl->generic.column);
int colspan = COLUMN_SPAN(ctrl->generic.column);
int colend = colstart + colspan;
int xthis, ythis, wthis, ch;
NSRect rect;
switch (ctrl->generic.type) {
case CTRL_COLUMNS:
for (j = 1; j < ncols; j++)
if (cypos[0] > cypos[j])
cypos[0] = cypos[j];
assert(ctrl->columns.ncols < lenof(ccw));
ccw[0] = 0;
for (j = 0; j < ctrl->columns.ncols; j++) {
ccw[j+1] = ccw[j] + (ctrl->columns.percentages ?
ctrl->columns.percentages[j] : 100);
cypos[j] = cypos[0];
}
ncols = ctrl->columns.ncols;
continue; /* no actual control created */
case CTRL_TABDELAY:
continue; /* nothing to do here, move along */
}
c = fe_ctrl_byctrl(d, ctrl);
ch = 0;
ythis = topy;
for (j = colstart; j < colend; j++) {
if (ythis > cypos[j])
ythis = cypos[j];
}
xthis = (width + HSPACING) * ccw[colstart] / 100;
wthis = (width + HSPACING) * ccw[colend] / 100 - HSPACING - xthis;
xthis += leftx;
switch (ctrl->generic.type) {
case CTRL_BUTTON:
case CTRL_CHECKBOX:
rect = [c->button frame];
[c->button setFrame:NSMakeRect(xthis,ythis-rect.size.height,wthis,
rect.size.height)];
ch = rect.size.height;
break;
case CTRL_EDITBOX:
{
int editp = ctrl->editbox.percentwidth;
int labelp = editp == 100 ? 100 : 100 - editp;
int lheight, theight, rheight, ynext, editw;
NSControl *edit = (c->editbox ? c->editbox : c->combobox);
rect = [c->label frame];
lheight = rect.size.height;
rect = [edit frame];
theight = rect.size.height;
if (editp == 100)
rheight = lheight;
else
rheight = (lheight < theight ? theight : lheight);
[c->label setFrame:
NSMakeRect(xthis, ythis-(rheight+lheight)/2,
(wthis + HSPACING) * labelp / 100 - HSPACING,
lheight)];
if (editp == 100) {
ynext = ythis - rheight - VSPACING;
rheight = theight;
} else {
ynext = ythis;
}
editw = (wthis + HSPACING) * editp / 100 - HSPACING;
[edit setFrame:
NSMakeRect(xthis+wthis-editw, ynext-(rheight+theight)/2,
editw, theight)];
ch = (ythis - ynext) + theight;
}
break;
case CTRL_TEXT:
[c->textview setFrame:NSMakeRect(xthis, 0, wthis, 1)];
[c->textview sizeToFit];
rect = [c->textview frame];
[c->textview setFrame:NSMakeRect(xthis, ythis-rect.size.height,
wthis, rect.size.height)];
ch = rect.size.height;
break;
case CTRL_RADIO:
{
int j, ynext;
if (c->label) {
rect = [c->label frame];
[c->label setFrame:NSMakeRect(xthis,ythis-rect.size.height,
wthis,rect.size.height)];
ynext = ythis - rect.size.height - VSPACING;
} else
ynext = ythis;
for (j = 0; j < ctrl->radio.nbuttons; j++) {
int col = j % ctrl->radio.ncolumns;
int ncols;
int lx,rx;
if (j == ctrl->radio.nbuttons - 1)
ncols = ctrl->radio.ncolumns - col;
else
ncols = 1;
lx = (wthis + HSPACING) * col / ctrl->radio.ncolumns;
rx = ((wthis + HSPACING) *
(col+ncols) / ctrl->radio.ncolumns) - HSPACING;
/*
* Set the frame size.
*/
rect = [c->radiobuttons[j] frame];
[c->radiobuttons[j] setFrame:
NSMakeRect(lx+xthis, ynext-rect.size.height,
rx-lx, rect.size.height)];
/*
* Advance to next line if we're in the last
* column.
*/
if (col + ncols == ctrl->radio.ncolumns)
ynext -= rect.size.height + VSPACING;
}
ch = (ythis - ynext) - VSPACING;
}
break;
case CTRL_FILESELECT:
case CTRL_FONTSELECT:
{
int ynext, eh, bh, th, mx;
rect = [c->label frame];
[c->label setFrame:NSMakeRect(xthis,ythis-rect.size.height,
wthis,rect.size.height)];
ynext = ythis - rect.size.height - VSPACING;
rect = [c->editbox frame];
eh = rect.size.height;
rect = [c->button frame];
bh = rect.size.height;
th = (eh > bh ? eh : bh);
mx = (wthis + HSPACING) * 3 / 4 - HSPACING;
[c->editbox setFrame:
NSMakeRect(xthis, ynext-(th+eh)/2, mx, eh)];
[c->button setFrame:
NSMakeRect(xthis+mx+HSPACING, ynext-(th+bh)/2,
wthis-mx-HSPACING, bh)];
ch = (ythis - ynext) + th + VSPACING;
}
break;
case CTRL_LISTBOX:
{
int listp = ctrl->listbox.percentwidth;
int labelp = listp == 100 ? 100 : 100 - listp;
int lheight, theight, rheight, ynext, listw, xlist;
NSControl *list = (c->scrollview ? (id)c->scrollview :
(id)c->popupbutton);
if (ctrl->listbox.draglist) {
assert(listp == 100);
listp = 75;
}
rect = [list frame];
theight = rect.size.height;
if (c->label) {
rect = [c->label frame];
lheight = rect.size.height;
if (labelp == 100)
rheight = lheight;
else
rheight = (lheight < theight ? theight : lheight);
[c->label setFrame:
NSMakeRect(xthis, ythis-(rheight+lheight)/2,
(wthis + HSPACING) * labelp / 100 - HSPACING,
lheight)];
if (labelp == 100) {
ynext = ythis - rheight - VSPACING;
rheight = theight;
} else {
ynext = ythis;
}
} else {
ynext = ythis;
rheight = theight;
}
listw = (wthis + HSPACING) * listp / 100 - HSPACING;
if (labelp == 100)
xlist = xthis;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -