📄 macctrls.c
字号:
return 0;
}
#endif
static void macctrl_listbox(struct macctrls *mcs, WindowPtr window,
struct mac_layoutstate *curstate,
union control *ctrl)
{
union macctrl *mc = snew(union macctrl);
Rect bounds, upbounds, downbounds;
Size olen;
/* XXX Use label */
assert(ctrl->listbox.percentwidth == 100);
mc->generic.type = MACCTRL_LISTBOX;
mc->generic.ctrl = ctrl;
mc->generic.privdata = NULL;
/* The list starts off empty */
mc->listbox.nids = 0;
mc->listbox.ids = NULL;
bounds.left = curstate->pos.h;
bounds.right = bounds.left + curstate->width;
bounds.top = curstate->pos.v;
bounds.bottom = bounds.top + 16 * ctrl->listbox.height + 2;
if (ctrl->listbox.draglist) {
upbounds = downbounds = bounds;
upbounds.left = upbounds.right - 58;
upbounds.bottom = upbounds.top + 20;
downbounds.left = downbounds.right - 58;
downbounds.top = upbounds.bottom + 6;
downbounds.bottom = downbounds.top + 20;
bounds.right -= 64; /* enough for 6 px gap and a button */
}
if (mac_gestalts.apprvers >= 0x100) {
InsetRect(&bounds, 3, 3);
mc->listbox.tbctrl = NewControl(window, &bounds, NULL, FALSE,
ldes_Default, 0, 0,
kControlListBoxProc, (long)mc);
if (GetControlData(mc->listbox.tbctrl, kControlEntireControl,
kControlListBoxListHandleTag,
sizeof(mc->listbox.list), &mc->listbox.list,
&olen) != noErr) {
DisposeControl(mc->listbox.tbctrl);
sfree(mc);
return;
}
}
#if !TARGET_API_MAC_CARBON
else {
InsetRect(&bounds, -3, -3);
mc->listbox.tbctrl = NewControl(window, &bounds, NULL, FALSE,
0, 0, 0,
SYS7_LISTBOX_PROC, (long)mc);
mc->listbox.list = (ListHandle)(*mc->listbox.tbctrl)->contrlData;
(*mc->listbox.list)->refCon = (long)mc;
}
#endif
if (!ctrl->listbox.multisel) {
#if TARGET_API_MAC_CARBON
SetListSelectionFlags(mc->listbox.list, lOnlyOne);
#else
(*mc->listbox.list)->selFlags = lOnlyOne;
#endif
}
if (ctrl->listbox.draglist) {
mc->listbox.tbup = NewControl(window, &upbounds, "\pUp", FALSE, 0, 0, 1,
pushButProc, (long)mc);
mc->listbox.tbdown = NewControl(window, &downbounds, "\pDown", FALSE, 0, 0, 1,
pushButProc, (long)mc);
}
add234(mcs->byctrl, mc);
curstate->pos.v += 6 + 16 * ctrl->listbox.height + 2;
mc->generic.next = mcs->panels[curstate->panelnum];
mcs->panels[curstate->panelnum] = mc;
ctrlevent(mcs, mc, EVENT_REFRESH);
#if TARGET_API_MAC_CARBON
HideControl(GetListVerticalScrollBar(mc->listbox.list));
#else
HideControl((*mc->listbox.list)->vScroll);
#endif
}
#if !TARGET_API_MAC_CARBON
static pascal SInt32 macctrl_sys7_listbox_cdef(SInt16 variant,
ControlRef control,
ControlDefProcMessage msg,
SInt32 param)
{
RgnHandle rgn;
Rect rect;
ListHandle list;
long ssfs;
Point mouse;
ListBounds bounds;
Point csize;
short savefont;
short savesize;
GrafPtr curport;
switch (msg) {
case initCntl:
rect = (*control)->contrlRect;
InsetRect(&rect, 4, 4);
rect.right -= 15; /* scroll bar */
bounds.top = bounds.bottom = bounds.left = 0;
bounds.right = 1;
csize.h = csize.v = 0;
GetPort(&curport);
savefont = curport->txFont;
savesize = curport->txSize;
ssfs = GetScriptVariable(smSystemScript, smScriptSysFondSize);
TextFont(HiWord(ssfs));
TextSize(LoWord(ssfs));
list = LNew(&rect, &bounds, csize, 0, (*control)->contrlOwner,
TRUE, FALSE, FALSE, TRUE);
SetControlReference((*list)->vScroll, (long)list);
(*control)->contrlData = (Handle)list;
TextFont(savefont);
TextSize(savesize);
return noErr;
case dispCntl:
/*
* If the dialogue box is being destroyed, the scroll bar
* might have gone already. In our situation, this is the
* only time we destroy a control, so NULL out the scroll bar
* handle to prevent LDispose trying to free it.
*/
list = (ListHandle)(*control)->contrlData;
(*list)->vScroll = NULL;
LDispose(list);
return 0;
case drawCntl:
if ((*control)->contrlVis) {
rect = (*control)->contrlRect;
/* XXX input focus highlighting? */
InsetRect(&rect, 3, 3);
PenNormal();
FrameRect(&rect);
list = (ListHandle)(*control)->contrlData;
LActivate((*control)->contrlHilite != kControlInactivePart, list);
GetPort(&curport);
LUpdate(curport->visRgn, list);
}
return 0;
case testCntl:
mouse.h = LoWord(param);
mouse.v = HiWord(param);
rect = (*control)->contrlRect;
InsetRect(&rect, 4, 4);
/*
* We deliberately exclude the scrollbar so that LClick() can see it.
*/
rect.right -= 15;
return PtInRect(mouse, &rect) ? kControlListBoxPart : kControlNoPart;
case calcCRgns:
if (param & (1 << 31)) {
param &= ~(1 << 31);
goto calcthumbrgn;
}
/* FALLTHROUGH */
case calcCntlRgn:
rgn = (RgnHandle)param;
RectRgn(rgn, &(*control)->contrlRect);
return 0;
case calcThumbRgn:
calcthumbrgn:
rgn = (RgnHandle)param;
SetEmptyRgn(rgn);
return 0;
}
return 0;
}
#endif
#if !TARGET_API_MAC_CARBON
static pascal SInt32 macctrl_sys7_groupbox_cdef(SInt16 variant,
ControlRef control,
ControlDefProcMessage msg,
SInt32 param)
{
RgnHandle rgn;
Rect rect;
PenState savestate;
switch (msg) {
case drawCntl:
if ((*control)->contrlVis) {
rect = (*control)->contrlRect;
GetPenState(&savestate);
PenNormal();
PenSize(3, 3);
PenPat(&qd.gray);
FrameRect(&rect);
SetPenState(&savestate);
}
return 0;
case calcCRgns:
if (param & (1 << 31)) {
param &= ~(1 << 31);
goto calcthumbrgn;
}
/* FALLTHROUGH */
case calcCntlRgn:
rgn = (RgnHandle)param;
RectRgn(rgn, &(*control)->contrlRect);
return 0;
case calcThumbRgn:
calcthumbrgn:
rgn = (RgnHandle)param;
SetEmptyRgn(rgn);
return 0;
}
return 0;
}
#endif
static void macctrl_popup(struct macctrls *mcs, WindowPtr window,
struct mac_layoutstate *curstate,
union control *ctrl)
{
union macctrl *mc = snew(union macctrl);
Rect bounds;
Str255 title;
unsigned int labelwidth;
static int nextmenuid = MENU_MIN;
int menuid;
MenuRef menu;
/*
* <http://developer.apple.com/qa/tb/tb42.html> explains how to
* create a popup menu with dynamic content.
*/
assert(ctrl->listbox.height == 0);
assert(!ctrl->listbox.draglist);
assert(!ctrl->listbox.multisel);
mc->generic.type = MACCTRL_POPUP;
mc->generic.ctrl = ctrl;
mc->generic.privdata = NULL;
c2pstrcpy(title, ctrl->button.label == NULL ? "" : ctrl->button.label);
/* Find a spare menu ID and create the menu */
while (GetMenuHandle(nextmenuid) != NULL)
if (++nextmenuid >= MENU_MAX) nextmenuid = MENU_MIN;
menuid = nextmenuid++;
menu = NewMenu(menuid, "\pdummy");
if (menu == NULL) return;
mc->popup.menu = menu;
mc->popup.menuid = menuid;
InsertMenu(menu, kInsertHierarchicalMenu);
/* The menu starts off empty */
mc->popup.nids = 0;
mc->popup.ids = NULL;
bounds.left = curstate->pos.h;
bounds.right = bounds.left + curstate->width;
bounds.top = curstate->pos.v;
bounds.bottom = bounds.top + 20;
/* XXX handle percentwidth == 100 */
labelwidth = curstate->width * (100 - ctrl->listbox.percentwidth) / 100;
mc->popup.tbctrl = NewControl(window, &bounds, title, FALSE,
popupTitleLeftJust, menuid, labelwidth,
popupMenuProc + popupFixedWidth, (long)mc);
add234(mcs->byctrl, mc);
curstate->pos.v += 26;
mc->generic.next = mcs->panels[curstate->panelnum];
mcs->panels[curstate->panelnum] = mc;
ctrlevent(mcs, mc, EVENT_REFRESH);
}
static void macctrl_groupbox(struct macctrls *mcs, WindowPtr window,
struct mac_layoutstate *curstate,
union control *ctrl)
{
union macctrl *mc = snew (union macctrl);
Str255 ptitle;
Rect r;
r.top = curstate->boxpos.v;
r.left = curstate->boxpos.h;
r.bottom = curstate->pos.v;
r.right = curstate->boxpos.h + curstate->width;
mc->generic.type = MACCTRL_GROUPBOX;
mc->generic.privdata = NULL;
mc->generic.ctrl = ctrl;
mc->generic.ctrl->generic.handler = NULL;
if (curstate->boxname)
c2pstrcpy(ptitle, curstate->boxname);
else
c2pstrcpy(ptitle, "");
if (mac_gestalts.apprvers >= 0x100) { /* Appearance Manager */
mc->groupbox.tbctrl = NewControl(window, &r, ptitle, FALSE, 0, 0, 1,
kControlGroupBoxTextTitleProc, (long)mc);
} else {
mc->groupbox.tbctrl = NewControl(window, &r, ptitle, FALSE, 0, 0, 1,
SYS7_GROUPBOX_PROC, (long)mc);
}
add234(mcs->byctrl, mc);
mc->generic.next = mcs->panels[curstate->panelnum];
mcs->panels[curstate->panelnum] = mc;
}
void macctrl_activate(WindowPtr window, EventRecord *event)
{
struct macctrls *mcs = mac_winctrls(window);
Boolean active = (event->modifiers & activeFlag) != 0;
GrafPtr saveport;
int i, j;
ControlPartCode state;
union macctrl *mc;
GetPort(&saveport);
SetPort((GrafPtr)GetWindowPort(window));
if (mac_gestalts.apprvers >= 0x100)
SetThemeWindowBackground(window, active ?
kThemeBrushModelessDialogBackgroundActive :
kThemeBrushModelessDialogBackgroundInactive,
TRUE);
state = active ? kControlNoPart : kControlInactivePart;
for (i = 0; i <= mcs->curpanel; i += mcs->curpanel)
for (mc = mcs->panels[i]; mc != NULL; mc = mc->generic.next) {
switch (mc->generic.type) {
case MACCTRL_TEXT:
HiliteControl(mc->text.tbctrl, state);
break;
case MACCTRL_EDITBOX:
HiliteControl(mc->editbox.tbctrl, state);
if (mc->editbox.tblabel != NULL)
HiliteControl(mc->editbox.tblabel, state);
if (mc->editbox.tbbutton != NULL)
HiliteControl(mc->editbox.tbbutton, state);
break;
case MACCTRL_RADIO:
for (j = 0; j < mc->generic.ctrl->radio.nbuttons; j++)
HiliteControl(mc->radio.tbctrls[j], state);
if (mc->radio.tblabel != NULL)
HiliteControl(mc->radio.tblabel, state);
break;
case MACCTRL_CHECKBOX:
HiliteControl(mc->checkbox.tbctrl, state);
break;
case MACCTRL_BUTTON:
HiliteControl(mc->button.tbctrl, state);
if (mc->button.tbring != NULL)
HiliteControl(mc->button.tbring, state);
break;
case MACCTRL_LISTBOX:
HiliteControl(mc->listbox.tbctrl, state);
if (mc->listbox.tbup != NULL)
HiliteControl(mc->listbox.tbup, state);
if (mc->listbox.tbdown != NULL)
HiliteControl(mc->listbox.tbdown, state);
break;
case MACCTRL_POPUP:
HiliteControl(mc->popup.tbctrl, state);
break;
case MACCTRL_GROUPBOX:
HiliteControl(mc->popup.tbctrl, state);
}
#if !TARGET_API_MAC_CARBON
if (mcs->focus == mc) {
if (active)
macctrl_enfocus(mc);
else
macctrl_defocus(mc);
}
#endif
}
SetPort(saveport);
}
void macctrl_click(WindowPtr window, EventRecord *event)
{
Point mouse;
ControlHandle control, oldfocus;
int part, trackresult;
GrafPtr saveport;
union macctrl *mc;
struct macctrls *mcs = mac_winctrls(window);
int i;
UInt32 features;
GetPort(&saveport);
SetPort((GrafPtr)GetWindowPort(window));
mouse = event->where;
GlobalToLocal(&mouse);
part = FindControl(mouse, window, &control);
if (control != NULL) {
#if !TARGET_API_MAC_CARBON
/*
* Special magic for scroll bars in list boxes, whose refcon
* is the list.
*/
if (part == kControlUpButtonPart || part == kControlDownButtonPart ||
part == kControlPageUpPart || part == kControlPageDownPart ||
part == kControlIndicatorPart)
mc = (union macctrl *)
(*(ListHandle)GetControlReference(control))->refCon;
else
#endif
mc = (union macctrl *)GetControlReference(control);
if (mac_gestalts.apprvers >= 0x100) {
if (GetControlFeatures(control, &features) == noErr &&
(features & kControlSupportsFocus) &&
(features & kControlGetsFocusOnClick) &&
GetKeyboardFocus(window, &oldfocus) == noErr &&
control != oldfocus)
SetKeyboardFocus(window, control, part);
trackresult = HandleControlClick(control, mouse, event->modifiers,
(ControlActionUPP)-1);
} else {
#if !TARGET_API_MAC_CARBON
if (mc->generic.type == MACCTRL_EDITBOX &&
control == mc->editbox.tbctrl) {
TEHandle te = (TEHandle)(*control)->contrlData;
macctrl_setfocus(mcs, mc);
TEClick(mouse, !!(event->modifiers & shiftKey), te);
goto done;
}
if (mc->generic.type == MACCTRL_EDITBOX &&
control == mc->editbox.tbbutton) {
dlg_editbox_set(mc->generic.ctrl, mcs,
cp_enumerate(dlg_listbox_index(mc->generic.ctrl, mcs)));
ctrlevent(mcs, mc, EVENT_VALCHANGE);
}
if (mc->generic.type == MACCTRL_LISTBOX &&
(control == mc->listbox.tbctrl ||
control == (*mc->listbox.list)->vScroll)) {
macctrl_setfocus(mcs, mc);
if (LClick(mouse, event->modifiers, mc->listbox.list))
/* double-click */
ctrlevent(mcs, mc, EVENT_ACTION);
else
ctrlevent(mcs, mc, EVENT_SELCHANGE);
goto done;
}
if (mc->generic.type == MACCTRL_LISTBOX &&
control == mc->listbox.tbup)
draglist_up(mc, mcs);
if (mc->generic.type == MACCTRL_LISTBOX &&
control == mc->listbox.tbdown)
draglist_down(mc, mcs);
#endif
trackresult = TrackControl(control, mouse, (ControlActionUPP)-1);
}
switch (mc->generic.type) {
case MACCTRL_RADIO:
if (trackresult != 0) {
for (i = 0; i < mc->generic.ctrl->radio.nbuttons; i++)
if (mc->radio.tbctrls[i] == control)
SetControlValue(mc->radio.tbctrls[i],
kControlRadioButtonCheckedValue);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -