📄 macctrls.c
字号:
}};int dlg_radiobutton_get(union control *ctrl, void *dlg){ struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); int i; assert(mc != NULL); for (i = 0; i < ctrl->radio.nbuttons; i++) { if (GetControlValue(mc->radio.tbctrls[i]) == kControlRadioButtonCheckedValue) return i; } return -1;};/* * Check Box control */void dlg_checkbox_set(union control *ctrl, void *dlg, int checked){ struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); if (mc == NULL) return; SetControlValue(mc->checkbox.tbctrl, checked ? kControlCheckBoxCheckedValue : kControlCheckBoxUncheckedValue);}int dlg_checkbox_get(union control *ctrl, void *dlg){ struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); assert(mc != NULL); return GetControlValue(mc->checkbox.tbctrl);}/* * Edit Box control */void dlg_editbox_set(union control *ctrl, void *dlg, char const *text){ struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); GrafPtr saveport; if (mc == NULL) return; assert(mc->generic.type == MACCTRL_EDITBOX); GetPort(&saveport); SetPort((GrafPtr)(GetWindowPort(mcs->window))); if (mac_gestalts.apprvers >= 0x100) SetControlData(mc->editbox.tbctrl, kControlEntireControl, ctrl->editbox.password ? kControlEditTextPasswordTag : kControlEditTextTextTag, strlen(text), text);#if !TARGET_API_MAC_CARBON else TESetText(text, strlen(text), (TEHandle)(*mc->editbox.tbctrl)->contrlData);#endif DrawOneControl(mc->editbox.tbctrl); SetPort(saveport);}void dlg_editbox_get(union control *ctrl, void *dlg, char *buffer, int length){ struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); Size olen; assert(mc != NULL); assert(mc->generic.type == MACCTRL_EDITBOX); if (mac_gestalts.apprvers >= 0x100) { if (GetControlData(mc->editbox.tbctrl, kControlEntireControl, ctrl->editbox.password ? kControlEditTextPasswordTag : kControlEditTextTextTag, length - 1, buffer, &olen) != noErr) olen = 0; if (olen > length - 1) olen = length - 1; }#if !TARGET_API_MAC_CARBON else { TEHandle te = (TEHandle)(*mc->editbox.tbctrl)->contrlData; olen = (*te)->teLength; if (olen > length - 1) olen = length - 1; memcpy(buffer, *(*te)->hText, olen); }#endif buffer[olen] = '\0';}/* * List Box control */static void dlg_macpopup_clear(union control *ctrl, void *dlg){ struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); MenuRef menu = mc->popup.menu; unsigned int i, n; if (mc == NULL) return; n = CountMenuItems(menu); for (i = 0; i < n; i++) DeleteMenuItem(menu, n - i); mc->popup.nids = 0; sfree(mc->popup.ids); mc->popup.ids = NULL; SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));}static void dlg_maclist_clear(union control *ctrl, void *dlg){ struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); if (mc == NULL) return; LDelRow(0, 0, mc->listbox.list); mc->listbox.nids = 0; sfree(mc->listbox.ids); mc->listbox.ids = NULL; DrawOneControl(mc->listbox.tbctrl);}void dlg_listbox_clear(union control *ctrl, void *dlg){ switch (ctrl->generic.type) { case CTRL_LISTBOX: if (ctrl->listbox.height == 0) dlg_macpopup_clear(ctrl, dlg); else dlg_maclist_clear(ctrl, dlg); break; }}static void dlg_macpopup_del(union control *ctrl, void *dlg, int index){ struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); MenuRef menu = mc->popup.menu; if (mc == NULL) return; DeleteMenuItem(menu, index + 1); if (mc->popup.ids != NULL) memcpy(mc->popup.ids + index, mc->popup.ids + index + 1, (mc->popup.nids - index - 1) * sizeof(*mc->popup.ids)); SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));}static void dlg_maclist_del(union control *ctrl, void *dlg, int index){ struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); if (mc == NULL) return; LDelRow(1, index, mc->listbox.list); if (mc->listbox.ids != NULL) memcpy(mc->listbox.ids + index, mc->listbox.ids + index + 1, (mc->listbox.nids - index - 1) * sizeof(*mc->listbox.ids)); DrawOneControl(mc->listbox.tbctrl);}void dlg_listbox_del(union control *ctrl, void *dlg, int index){ switch (ctrl->generic.type) { case CTRL_LISTBOX: if (ctrl->listbox.height == 0) dlg_macpopup_del(ctrl, dlg, index); else dlg_maclist_del(ctrl, dlg, index); break; }}static void dlg_macpopup_add(union control *ctrl, void *dlg, char const *text){ struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); MenuRef menu = mc->popup.menu; Str255 itemstring; if (mc == NULL) return; assert(text[0] != '\0'); c2pstrcpy(itemstring, text); AppendMenu(menu, "\pdummy"); SetMenuItemText(menu, CountMenuItems(menu), itemstring); SetControlMaximum(mc->popup.tbctrl, CountMenuItems(menu));}static void dlg_maclist_add(union control *ctrl, void *dlg, char const *text){ struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); ListBounds bounds; Cell cell = { 0, 0 }; if (mc == NULL) return;#if TARGET_API_MAC_CARBON GetListDataBounds(mc->listbox.list, &bounds);#else bounds = (*mc->listbox.list)->dataBounds;#endif cell.v = bounds.bottom; LAddRow(1, cell.v, mc->listbox.list); LSetCell(text, strlen(text), cell, mc->listbox.list); DrawOneControl(mc->listbox.tbctrl);}void dlg_listbox_add(union control *ctrl, void *dlg, char const *text){ switch (ctrl->generic.type) { case CTRL_LISTBOX: if (ctrl->listbox.height == 0) dlg_macpopup_add(ctrl, dlg, text); else dlg_maclist_add(ctrl, dlg, text); break; }}static void dlg_macpopup_addwithid(union control *ctrl, void *dlg, char const *text, int id){ struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); MenuRef menu = mc->popup.menu; unsigned int index; if (mc == NULL) return; dlg_macpopup_add(ctrl, dlg, text); index = CountMenuItems(menu) - 1; if (mc->popup.nids <= index) { mc->popup.nids = index + 1; mc->popup.ids = sresize(mc->popup.ids, mc->popup.nids, int); } mc->popup.ids[index] = id;}static void dlg_maclist_addwithid(union control *ctrl, void *dlg, char const *text, int id){ struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); ListBounds bounds; int index; if (mc == NULL) return; dlg_maclist_add(ctrl, dlg, text);#if TARGET_API_MAC_CARBON GetListDataBounds(mc->listbox.list, &bounds);#else bounds = (*mc->listbox.list)->dataBounds;#endif index = bounds.bottom; if (mc->listbox.nids <= index) { mc->listbox.nids = index + 1; mc->listbox.ids = sresize(mc->listbox.ids, mc->listbox.nids, int); } mc->listbox.ids[index] = id;}void dlg_listbox_addwithid(union control *ctrl, void *dlg, char const *text, int id){ switch (ctrl->generic.type) { case CTRL_LISTBOX: if (ctrl->listbox.height == 0) dlg_macpopup_addwithid(ctrl, dlg, text, id); else dlg_maclist_addwithid(ctrl, dlg, text, id); break; }}int dlg_listbox_getid(union control *ctrl, void *dlg, int index){ struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); assert(mc != NULL); switch (ctrl->generic.type) { case CTRL_LISTBOX: if (ctrl->listbox.height == 0) { assert(mc->popup.ids != NULL && mc->popup.nids > index); return mc->popup.ids[index]; } else { assert(mc->listbox.ids != NULL && mc->listbox.nids > index); return mc->listbox.ids[index]; } } return -1;}int dlg_listbox_index(union control *ctrl, void *dlg){ struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); Cell cell = { 0, 0 }; assert(mc != NULL); switch (ctrl->generic.type) { case CTRL_LISTBOX: if (ctrl->listbox.height == 0) return GetControlValue(mc->popup.tbctrl) - 1; else { if (LGetSelect(TRUE, &cell, mc->listbox.list)) return cell.v; else return -1; } } return -1;}int dlg_listbox_issel(union control *ctrl, void *dlg, int index){ struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); Cell cell = { 0, 0 }; assert(mc != NULL); switch (ctrl->generic.type) { case CTRL_LISTBOX: if (ctrl->listbox.height == 0) return GetControlValue(mc->popup.tbctrl) - 1 == index; else { cell.v = index; return LGetSelect(FALSE, &cell, mc->listbox.list); } } return FALSE;}void dlg_listbox_select(union control *ctrl, void *dlg, int index){ struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); if (mc == NULL) return; switch (ctrl->generic.type) { case CTRL_LISTBOX: if (ctrl->listbox.height == 0) SetControlValue(mc->popup.tbctrl, index + 1); break; }}/* * Text control */void dlg_text_set(union control *ctrl, void *dlg, char const *text){ struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); if (mc == NULL) return; if (mac_gestalts.apprvers >= 0x100) SetControlData(mc->text.tbctrl, kControlEntireControl, kControlStaticTextTextTag, strlen(text), text);#if !TARGET_API_MAC_CARBON else TESetText(text, strlen(text), (TEHandle)(*mc->text.tbctrl)->contrlData);#endif}/* * File Selector control */void dlg_filesel_set(union control *ctrl, void *dlg, Filename fn){}void dlg_filesel_get(union control *ctrl, void *dlg, Filename *fn){}/* * Font Selector control */void dlg_fontsel_set(union control *ctrl, void *dlg, FontSpec fn){}void dlg_fontsel_get(union control *ctrl, void *dlg, FontSpec *fn){}/* * Printer enumeration */printer_enum *printer_start_enum(int *nprinters){ *nprinters = 0; return NULL;}char *printer_get_name(printer_enum *pe, int thing){ return "<none>";}void printer_finish_enum(printer_enum *pe){}/* * Colour selection stuff */void dlg_coloursel_start(union control *ctrl, void *dlg, int r, int g, int b){ struct macctrls *mcs = dlg; union macctrl *mc = findbyctrl(mcs, ctrl); Point where = {-1, -1}; /* Screen with greatest colour depth */ RGBColor incolour; if (HAVE_COLOR_QD()) { incolour.red = r * 0x0101; incolour.green = g * 0x0101; incolour.blue = b * 0x0101; mcs->gotcolour = GetColor(where, "\pModify Colour:", &incolour, &mcs->thecolour); ctrlevent(mcs, mc, EVENT_CALLBACK); } else dlg_beep(dlg);}int dlg_coloursel_results(union control *ctrl, void *dlg, int *r, int *g, int *b){ struct macctrls *mcs = dlg; if (mcs->gotcolour) { *r = mcs->thecolour.red >> 8; *g = mcs->thecolour.green >> 8; *b = mcs->thecolour.blue >> 8; return 1; } else return 0;}/* * Local Variables: * c-file-style: "simon" * End: */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -