static editor neweditor(void) { int x, y, w, h, w0, h0; editor c; menuitem m; textbox t; long flags; font editorfn = (consolefn ? consolefn : FixedFont); EditorData p = neweditordata(0, NULL); DWORD rand; w = (pagercol + 1)*fontwidth(editorfn); h = (pagerrow + 1)*fontheight(editorfn) + 1; #ifdef USE_MDI if(ismdi()) { RECT *pR = RgetMDIsize(); w0 = pR->right; h0 = pR->bottom; } else { #endif w0 = devicewidth(NULL); h0 = deviceheight(NULL); #ifdef USE_MDI } #endif x = (w0 - w) / 2; x = x > 20 ? x : 20; y = (h0 - h) / 2; y = y > 20 ? y : 20; rand = GetTickCount(); w0 = 0.4*x; h0 = 0.4*y; w0 = w0 > 20 ? w0 : 20; h0 = h0 > 20 ? h0 : 20; x += (rand % w0) - w0/2; y += ((rand/w0) % h0) - h0/2; flags = StandardWindow | Menubar; #ifdef USE_MDI if (ismdi()) flags |= Document; #endif c = (editor) newwindow("", rect(x, y, w, h), flags); t = newrichtextarea(NULL, rect(0, 0, w, h)); setdata(c, t); setdata(t, p); gsetcursor(c, ArrowCursor); setforeground(c, guiColors[editorfg]); setbackground(c, guiColors[editorbg]); setbackground(t, guiColors[editorbg]); #ifdef USE_MDI if (ismdi() && (RguiMDI & RW_TOOLBAR)) { int btsize = 24; rect r = rect(2, 2, btsize, btsize); control tb, bt; addto(c); MCHECK(tb = newtoolbar(btsize + 4)); addto(tb); MCHECK(bt = newtoolbutton(open_image, r, menueditoropen)); MCHECK(addtooltip(bt, G_("Open script"))); setdata(bt, c); r.x += (btsize + 1) ; MCHECK(bt = newtoolbutton(save_image, r, menueditorsave)); MCHECK(addtooltip(bt, G_("Save script"))); setdata(bt, c); r.x += (btsize + 6); MCHECK(bt = newtoolbutton(copy1_image, r, menueditorrun)); MCHECK(addtooltip(bt, G_("Run line or selection"))); setdata(bt, t); r.x += (btsize + 6); MCHECK(bt = newtoolbutton(console_image, r, editorconsole)); MCHECK(addtooltip(bt, G_("Return focus to Console"))); r.x += (btsize + 6); MCHECK(bt = newtoolbutton(print_image, r, editorprint)); MCHECK(addtooltip(bt, G_("Print script"))); setdata(bt, t); MCHECK(addtooltip(bt, G_("Print"))); } #endif addto(c); /* Right-click context menu */ MCHECK(m = gpopup(editormenuact, EditorPopup)); setdata(m, t); setdata(EditorPopup[0].m, t); setdata(EditorPopup[2].m, t); setdata(p->mpopcut = EditorPopup[4].m, t); setdata(p->mpopcopy = EditorPopup[5].m, t); setdata(EditorPopup[6].m, t); setdata(p->mpopdelete = EditorPopup[7].m, t); setdata(EditorPopup[9].m, t); addto(c); MCHECK(m = newmenubar(editormenuact)); setdata(m, t); MCHECK(newmenu(G_("File"))); MCHECK(m = newmenuitem(G_("New script"), 'N', menueditornew)); setdata(m, c); MCHECK(m = newmenuitem(G_("Open script..."), 'O', menueditoropen)); setdata(m, c); MCHECK(m = newmenuitem(G_("Save"), 'S', menueditorsave)); setdata(m, c); MCHECK(m = newmenuitem(G_("Save as..."), 0, menueditorsaveas)); setdata(m, c); MCHECK(m = newmenuitem("-", 0, NULL)); MCHECK(m = newmenuitem(G_("Print..."), 0, editorprint)); setdata(m, t); MCHECK(m = newmenuitem("-", 0, NULL)); MCHECK(m = newmenuitem(G_("Close script"), 0, menueditorclose)); setdata(m, c); MCHECK(newmenu(G_("Edit"))); MCHECK(m = newmenuitem(G_("Undo"), 'Z', editorundo)); setdata(m, t); MCHECK(m = newmenuitem("-", 0, NULL)); MCHECK(p->mcut = newmenuitem(G_("Cut"), 'X', editorcut)); setdata(p->mcut, t); MCHECK(p->mcopy = newmenuitem(G_("Copy"), 'C', editorcopy)); setdata(p->mcopy, t); MCHECK(m = newmenuitem(G_("Paste"), 'V', editorpaste)); setdata(m, t); MCHECK(p->mdelete = newmenuitem(G_("Delete"), 0, editordelete)); setdata(p->mdelete, t); MCHECK(m = newmenuitem(G_("Select all"), 'A', editorselectall)); setdata(m, t); MCHECK(newmenuitem(G_("Clear console"), 'L', menuclear)); MCHECK(m = newmenuitem("-", 0, NULL)); MCHECK(m = newmenuitem(G_("Run line or selection"), 'R', menueditorrun)); setdata(m, t); MCHECK(m = newmenuitem(G_("Run all"), 0, editorrunall)); setdata(m, t); MCHECK(m = newmenuitem("-", 0, NULL)); MCHECK(p->mfind = newmenuitem(G_("Find..."), 'F', editorfind)); setdata(p->mfind, t); MCHECK(p->mreplace = newmenuitem(G_("Replace..."), 'H', editorreplace)); setdata(p->mreplace, t); MCHECK(m = newmenuitem("-", 0, NULL)); MCHECK(newmenuitem(G_("GUI preferences..."), 0, menuconfig)); /* Packages menu should go here */ p->pmenu = (PkgMenuItems) malloc(sizeof(struct structPkgMenuItems)); RguiPackageMenu(p->pmenu); #ifdef USE_MDI newmdimenu(); /* Create and fill the 'Window' menu */ #endif MCHECK(m = newmenu(G_("Help"))); MCHECK(newmenuitem(G_("Editor"), 0, menueditorhelp)); MCHECK(newmenuitem("-", 0, NULL)); p->hmenu = (HelpMenuItems) malloc(sizeof(struct structHelpMenuItems)); RguiCommonHelp(m, p->hmenu); settextfont(t, editorfn); setforeground(t, guiColors[editorfg]); setresize(c, editorresize); setclose(c, editorclose); setdel(c, editordel); setdel(t, textboxdel); setonfocus(c, editorfocus); setkeyaction(t, editorcontrolkeydown); setkeydown(t, editorasciikeydown); /* Store pointer to new editor in global array */ REditors[neditors] = c; ++neditors; return c; }
static void showDialog(Gui gui) { char buf[100]; wconfig = newwindow(G_("Rgui Configuration Editor"), rect(0, 0, 550, 450), Titlebar | Centered | Modal); setbackground(wconfig, dialog_bg()); l_mdi = newlabel("Single or multiple windows", rect(10, 10, 140, 20), AlignLeft); rb_mdi = newradiobutton("MDI", rect(150, 10 , 70, 20), cMDI); rb_sdi = newradiobutton("SDI", rect(220, 10 , 70, 20), cSDI); toolbar = newcheckbox("MDI toolbar", rect(300, 10, 100, 20), NULL); if(gui->toolbar) check(toolbar); statusbar = newcheckbox("MDI statusbar", rect(420, 10, 130, 20), NULL); if(gui->statusbar) check(statusbar); if(gui->MDI) { check(rb_mdi); cMDI(rb_mdi); } else { check(rb_sdi); cSDI(rb_sdi); } l_mwin = newlabel("Pager style", rect(10, 40, 90, 20), AlignLeft); g_mwin = newradiogroup(); rb_mwin = newradiobutton("multiple windows", rect(150, 40, 150, 20), NULL); rb_swin = newradiobutton("single window", rect(150, 60 , 150, 20), NULL); if(gui->pagerMultiple) check(rb_mwin); else check(rb_swin); l_lang = newlabel("Language for menus\nand messages", rect(320, 40, 130, 40), AlignLeft); f_lang = newfield(gui->language, rect(450, 45, 60, 20)); /* Font, pointsize, style */ l_font = newlabel("Font", rect(10, 100, 40, 20), AlignLeft); f_font = newdropfield(FontsList, rect(50, 100, 120, 20), scrollFont); tt_font = newcheckbox("TrueType only", rect(180, 100, 110, 20), changeFont); if (gui->tt_font) check(tt_font); settext(f_font, gui->font); l_point = newlabel("size", rect(310, 100, 30, 20), AlignLeft); d_point = newdropfield(PointsList, rect(345, 100, 50, 20), scrollPoints); snprintf(buf, 100, "%d", gui->pointsize); settext(d_point, buf); l_style = newlabel("style", rect(410, 100, 40, 20), AlignLeft); f_style = newdroplist(StyleList, rect(450, 100, 80, 20), scrollStyle); setlistitem(f_style, cmatch(gui->style, StyleList)); /* Console size, set widthonresize */ l_crows = newlabel("Console rows", rect(10, 150, 100, 20), AlignLeft); snprintf(buf, 100, "%d", gui->crows); f_crows = newfield(buf, rect(110, 150, 30, 20)); l_ccols = newlabel("columns", rect(150, 150, 60, 20), AlignLeft); snprintf(buf, 100, "%d", gui->ccols); f_ccols = newfield(buf, rect(220, 150, 30, 20)); l_cx = newlabel("Initial left", rect(270, 150, 70, 20), AlignLeft); snprintf(buf, 100, "%d", gui->cx); f_cx = newfield(buf, rect(350, 150, 40, 20)); l_cy = newlabel("top", rect(430, 150, 30, 20), AlignLeft); snprintf(buf, 100, "%d", gui->cy); f_cy = newfield(buf, rect(480, 150, 40, 20)); c_resize = newcheckbox("set options(width) on resize?", rect(20, 175, 200, 20), NULL); if(gui->setWidthOnResize) check(c_resize); l_cbb = newlabel("buffer chars", rect(270, 175, 70, 20), AlignLeft); snprintf(buf, 100, "%d", gui->cbb); f_cbb = newfield(buf, rect(350, 175, 60, 20)); l_cbl = newlabel("lines", rect(430, 175, 50, 20), AlignLeft); snprintf(buf, 100, "%d", gui->cbl); f_cbl = newfield(buf, rect(480, 175, 40, 20)); c_buff = newcheckbox("buffer console by default?", rect(20, 190, 200, 20), NULL); if(gui->buffered) check(c_buff); /* Cursor blink */ l_blink = newlabel("Cursor blink", rect(270, 200,100, 30), AlignLeft); f_blink = newdroplist(BlinkList, rect(350, 200, 80, 20), NULL); setlistitem(f_blink, gui->cursor_blink); /* Pager size */ l_prows = newlabel("Pager rows", rect(10, 230, 100, 20), AlignLeft); snprintf(buf, 100, "%d", gui->prows); f_prows = newfield(buf, rect(110, 230, 30, 20)); l_pcols = newlabel("columns", rect(150, 230, 60, 20), AlignLeft); snprintf(buf, 100, "%d", gui->pcols); f_pcols = newfield(buf, rect(220, 230, 30, 20)); /* Graphics window */ l_grx = newlabel("Graphics windows: initial left", rect(10, 270, 190, 20), AlignLeft); snprintf(buf, 100, "%d", gui->grx); f_grx = newfield(buf, rect(200, 270, 40, 20)); l_gry = newlabel("top", rect(270, 270, 30, 20), AlignLeft); snprintf(buf, 100, "%d", gui->gry); f_gry = newfield(buf, rect(300, 270, 40, 20)); /* Font colours */ l_cols = newlabel("Console and Pager Colours", rect(10, 310, 520, 20), AlignCenter); guielement = newlistbox(GuiElementNames, rect(50, 330, 100, 80), changeElement, NULL); guicolor = newlistbox(ColorName, rect(205, 330, 100, 80), clickColor, NULL); guisample = newrichtextarea("Sample text", rect(350, 330, 150, 55)); for (int i=0; i<numGuiColors; i++) dialogColors[i] = gui->guiColors[i]; setlistitem(guielement, 0); changeElement(guielement, 0); sampleFontNum = cmatch(gettext(f_font), FontsList); samplePointsize = atoi(gettext(d_point)); scrollStyle(f_style, 0); /* the 0 is ignored */ bApply = newbutton("Apply", rect(50, 410, 70, 25), apply); bSave = newbutton("Save...", rect(130, 410, 70, 25), save); bLoad = newbutton("Load...", rect(210, 410, 70, 25), load); bOK = newbutton("OK", rect(350, 410, 70, 25), ok); bCancel = newbutton("Cancel", rect(430, 410, 70, 25), cancel); show(wconfig); }