📄 medit.c
字号:
MOBJECT _colform002; search_shell = MCreateShell("Search String", SF_MODAL); MObjectSetBackgroundRGB(search_shell, 216, 208, 184); MObjectSetBackgroundImageFile(search_shell, "tile6.bmp", BI_TILED); MObjectSetShadow(search_shell, WS_SHADOW_IN, 1, 0); search_e = MCreateEdit(search_shell, "", 40, FIXED_MEDIUM); MTopAttach(search_e, F_ATT_FORM, 10, NULL); MLeftAttach(search_e, F_ATT_FORM, 10, NULL); MObjectSetBackgroundRGB(search_e, 224, 224, 176); ignore_case_tb = MCreateTButton(search_shell, "Ignore case", HELV_SMALL); MTButtonSetCallback(ignore_case_tb, IgnoreCaseCB, NULL); MTopAttach(ignore_case_tb, F_ATT_OBJ, 10, search_e); _colform002 = MCreateColForm(search_shell); MTopAttach(_colform002, F_ATT_OBJ, 10, ignore_case_tb); MObjectSetBackgroundRGB(_colform002, 160, 112, 112); MObjectSetResize(_colform002, True, False); search_f_pb = MCreatePButton(_colform002, "Forward", TIMES_MEDIUM); MPButtonSetMargin(search_f_pb, 8, 2); MPButtonSetCallback(search_f_pb, SearchForwardCB, NULL); search_b_pb = MCreatePButton(_colform002, "Backward", TIMES_MEDIUM); MPButtonSetMargin(search_b_pb, 8, 2); MPButtonSetCallback(search_b_pb, SearchBackwardCB, NULL); search_cancel_pb = MCreatePButton(_colform002, "Cancel", TIMES_MEDIUM); MPButtonSetMargin(search_cancel_pb, 8, 2); MPButtonSetCallback(search_cancel_pb, CancelCB, NULL);MButtonSetAccelerator(search_cancel_pb, ESC); return search_shell;}MOBJECT MDCreatemain_shell(void){ MOBJECT _rowform000; MOBJECT _colform003; main_shell = MCreateShell("M-Edit 1.9", 0); MObjectSetBackgroundRGB(main_shell, 56, 112, 112); _rowform000 = MCreateRowForm(main_shell); MFormSetSpacing(_rowform000, 0); MTopAttach(_rowform000, F_ATT_FORM, 1, NULL); MBottomAttach(_rowform000, F_ATT_FORM, 1, NULL); MLeftAttach(_rowform000, F_ATT_FORM, 1, NULL); MRightAttach(_rowform000, F_ATT_FORM, 1, NULL); MObjectSetBackgroundRGB(_rowform000, 56, 112, 112); MObjectSetShadow(_rowform000, WS_NONE, 0, 0); { MOBJECT pd; MENU_ITEM item; menu = MCreateMenuBar(_rowform000, HELV_MEDIUM); MMenuBarSetAcc(menu, F10); file_pd = MCreateMenu(menu, "File"); new_mi = MMenuAddItem(file_pd, "New Window", NewCB, main_shell); open_mi = MMenuAddItem(file_pd, "Open New ...", OpenNewCB, main_shell); load_mi = MMenuAddItem(file_pd, "Load File ...", LoadFileCB, main_shell); insert_file_mi = MMenuAddItem(file_pd, "Insert File ...", InsertFileCB, main_shell); item = MMenuAddItem(file_pd, "Revert to saved", RevertCB, main_shell); MMenuAddSeparator(file_pd); save_mi = MMenuAddItem(file_pd, "Save", SaveCB, main_shell); item = MMenuAddItem(file_pd, "Save as ...", SaveAsCB, main_shell); MMenuAddSeparator(file_pd); write_sel_mi = MMenuAddItem(file_pd, "Write Selection ...", WriteSelCB, main_shell); print_mi = MMenuAddItem(file_pd, "Print ...", PrintCB, main_shell); MMenuAddSeparator(file_pd); close_mi = MMenuAddItem(file_pd, "Close", CloseCB, main_shell); quit_mi = MMenuAddItem(file_pd, "Quit", QuitCB, main_shell); edit_pd = MCreateMenu(menu, "Edit"); undo_mi = MMenuAddItem(edit_pd, "Undo", UndoCB, main_shell); redo_mi = MMenuAddItem(edit_pd, "Redo", RedoCB, main_shell); search_pd = MCreateMenu(menu, "Search"); goto_mi = MMenuAddItem(search_pd, "Go to Line ...", GoToLineCB, main_shell); MMenuAddSeparator(search_pd); search_mi = MMenuAddItem(search_pd, "Search String ...", SearchCB, main_shell); search_next_mi = MMenuAddItem(search_pd, "Search Next", SearchNextCB, main_shell); search_prev_mi = MMenuAddItem(search_pd, "Search Previous", SearchPrevCB, main_shell); MMenuAddSeparator(search_pd); replace_mi = MMenuAddItem(search_pd, "Replace ...", ReplaceCB, main_shell); options_pd = MCreateMenu(menu, "Options"); large_font_mi = MMenuAddRadioItem(options_pd, "Large Font", LargeFontSelectCB, (void *)FIXED_LARGE); medium_font_mi = MMenuAddRadioItem(options_pd, "Medium Font", MediumFontSelectCB, (void *)FIXED_MEDIUM); small_font_mi = MMenuAddRadioItem(options_pd, "Small Font", SmallFontSelectCB, (void *)FIXED_SMALL); MMenuAddSeparator(options_pd); auto_indent_mi = MMenuAddToggleItem(options_pd, "Auto Indent", AutoIndentCB, main_shell); MMenuAddSeparator(options_pd); item = MMenuAddItem(options_pd, "Customize ...", CustomizeCB, NULL); } MObjectSetBackgroundRGB(menu, 168, 192, 168); MObjectSetBackgroundImageFile(menu, "tile8.bmp", BI_TILED); MObjectEnableOptions(menu, "menu", (CARD32)23); _colform003 = MCreateColForm(_rowform000); MFormSetSpacing(_colform003, 1); MObjectSetBackgroundRGB(_colform003, 56, 112, 112); MObjectSetShadow(_colform003, WS_NONE, 0, 0); MObjectSetResize(_colform003, True, False); filename_l = MCreateLabel(_colform003, "", FIXED_SMALL); MLabelSetAlignment(filename_l, LEFT_ALIGN); MObjectSetBackgroundRGB(filename_l, 200, 200, 144); MObjectSetTransparency(filename_l, 0); MObjectSetShadow(filename_l, WS_SHADOW_OUT, 1, 0); MObjectEnableOptions(filename_l, "filename_l", (CARD32)7); modified_l = MCreateLabel(_colform003, "N", FIXED_SMALL); MObjectSetBackgroundRGB(modified_l, 200, 200, 144); MObjectSetTransparency(modified_l, 0); MObjectSetShadow(modified_l, WS_SHADOW_OUT, 1, 0); MObjectSetResize(modified_l, False, False); curs_y_l = MCreateLabel(_colform003, " ", FIXED_SMALL); MLabelSetAlignment(curs_y_l, RIGHT_ALIGN); MObjectSetBackgroundRGB(curs_y_l, 200, 200, 144); MObjectSetTransparency(curs_y_l, 0); MObjectSetShadow(curs_y_l, WS_SHADOW_OUT, 1, 0); MObjectSetResize(curs_y_l, False, False); curs_x_l = MCreateLabel(_colform003, " ", FIXED_SMALL); MLabelSetAlignment(curs_x_l, RIGHT_ALIGN); MObjectSetBackgroundRGB(curs_x_l, 200, 200, 144); MObjectSetTransparency(curs_x_l, 0); MObjectSetShadow(curs_x_l, WS_SHADOW_OUT, 1, 0); MObjectSetResize(curs_x_l, False, False); text_mle = MCreateScrolledMLEdit(_rowform000, "", 64, 20, FIXED_MEDIUM); MEditSetValueChangeCallback(text_mle, TextChangedCB, NULL); MEditSetCursorPosCallback(text_mle, CursorPosCB, NULL); MObjectSetForegroundRGB(text_mle, 224, 224, 176); MObjectSetBackgroundRGB(text_mle, 56, 112, 112); MObjectSetShadow(text_mle, WS_ETCHED_OUT, 2, 1); MObjectSetResize(text_mle, True, True); MObjectEnableOptions(text_mle, "text_mle", (CARD32)7); {/* * This code is added to link edit window Objects * to file data structure */ extern void StatusLineChangeCB(MOBJECT obj, MEvent *pe, void *ad); FILE_DATA *pfd; pfd = (FILE_DATA *)calloc(1, sizeof(FILE_DATA)); MObjectSetUserData(main_shell, pfd); if (pfd != NULL) { pfd->menu = menu; pfd->edit = text_mle; pfd->curs_x_label = curs_x_l; pfd->curs_y_label = curs_y_l; pfd->fname_label = filename_l; pfd->modified_label = modified_l; pfd->ignore_case = False; pfd->options_pd = options_pd; pfd->auto_indent = auto_indent_mi;/* * In order to set the user picked font to all labels in the status line * (fname_label, modified_label, curs_x_label and curs_y_label), a resize * event notification callback is asked for the fname_label. */ MObjectAddEventNotifyCallback(filename_l, StatusLineChangeCB, EM_RESIZE | EM_SET_COLOR, pfd);/* * This dummy color setting is really needed to set the desired colors * to all labels in the status line */ MObjectSetColor(filename_l, MObjectBackgroundColor(filename_l), MObjectForegroundColor(filename_l)); } MObjectSetUserData(options_pd, main_shell);/* * Since MGUI Designer does not allow yet to set menu item * accelerators... */ MMenuItemSetAccel(new_mi, C_N, "Ctrl+N"); MMenuItemSetAccel(open_mi, C_O, "Ctrl+O"); MMenuItemSetAccel(load_mi, C_L, "Ctrl+L"); MMenuItemSetAccel(insert_file_mi, C_I, "Ctrl+I"); MMenuItemSetAccel(save_mi, C_S, "Ctrl+S"); MMenuItemSetAccel(write_sel_mi, C_W, "Ctrl+W"); MMenuItemSetAccel(print_mi, C_P, "Ctrl+P"); MMenuItemSetAccel(goto_mi, F1, "F1"); MMenuItemSetAccel(search_mi, F2, "F2"); MMenuItemSetAccel(search_next_mi, F3, "F3"); MMenuItemSetAccel(search_prev_mi, F4, "F4"); MMenuItemSetAccel(replace_mi, F5, "F5"); MMenuItemSetAccel(undo_mi, C_U, "Ctrl+U"); MMenuItemSetAccel(redo_mi, C_R, "Ctrl+R"); } return main_shell;}MOBJECT MDCreatecustom_shell(void){ MOBJECT _tablefrm001; MOBJECT _label002; MOBJECT _label003; MOBJECT _label004; MOBJECT _colform004; MOBJECT _pbutton000; MOBJECT _pbutton001; MOBJECT _pbutton002; MOBJECT _pbutton003; custom_shell = MCreateShell("Options", SF_MODAL); MObjectSetBackgroundRGB(custom_shell, 168, 192, 168); MObjectSetBackgroundImageFile(custom_shell, "tile8.bmp", BI_TILED); MObjectSetShadow(custom_shell, WS_SHADOW_IN, 1, 0); _tablefrm001 = MCreateTableForm(custom_shell, 2); MTableFormSetColAlign(_tablefrm001, 1, LEFT_ALIGN); MObjectSetBackgroundRGB(_tablefrm001, 168, 192, 168); MObjectSetTransparency(_tablefrm001, 255); MObjectSetShadow(_tablefrm001, WS_SHADOW_OUT, 1, 0); _label002 = MCreateLabel(_tablefrm001, "Initial width", HELV_MEDIUM); MLabelSetAlignment(_label002, RIGHT_ALIGN); init_w_e = MCreateEdit(_tablefrm001, "", 3, FIXED_MEDIUM); MEditSetFilter(init_w_e, 4, ""); _label003 = MCreateLabel(_tablefrm001, "Initial height", HELV_MEDIUM); MLabelSetAlignment(_label003, RIGHT_ALIGN); init_h_e = MCreateEdit(_tablefrm001, "", 2, FIXED_MEDIUM); MEditSetFilter(init_h_e, 4, ""); _label004 = MCreateLabel(_tablefrm001, "Tab size", HELV_MEDIUM); MLabelSetAlignment(_label004, RIGHT_ALIGN); tab_size_e = MCreateEdit(_tablefrm001, "", 1, FIXED_MEDIUM); MEditSetFilter(tab_size_e, 0, "123456789"); auto_indent_tb = MCreateTButton(custom_shell, "Auto Indent", HELV_SMALL); MObjectSetForegroundRGB(auto_indent_tb, 255, 255, 255); _colform004 = MCreateColForm(custom_shell); MObjectSetBackgroundRGB(_colform004, 56, 112, 112); MObjectSetResize(_colform004, True, False); _pbutton000 = MCreatePButton(_colform004, "Ok", TIMES_MEDIUM); MPButtonSetCallback(_pbutton000, OptionsOkCB, NULL); _pbutton001 = MCreatePButton(_colform004, "Save", TIMES_MEDIUM); MPButtonSetCallback(_pbutton001, OptionsSaveCB, NULL); _pbutton002 = MCreatePButton(_colform004, "Default", TIMES_MEDIUM); MPButtonSetCallback(_pbutton002, OptionsDefaultCB, NULL); _pbutton003 = MCreatePButton(_colform004, "Cancel", TIMES_MEDIUM); MPButtonSetCallback(_pbutton003, OptionsCancelCB, NULL); return custom_shell;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -