1 static char *rcsid = "$Id: UiPage.c,v 1.4 1992/03/26 18:13:50 kny Exp kny $";
3 #include "UiIncludes.h"
6 static uiHierarchy_t *uifindoraddhierarchy(char *topaddress);
7 static uiHierarchy_t *uifindhierarchy(char *topaddress);
8 static int uideletehierarchy(uiHierarchy_t * hierarchy);
9 static uiPage_t *uifindpage(HText_t * htext, uiHierarchy_t * hierarchy);
11 uiaddpage(HText_t * htext, HTextObject_t * htextobject,
12 uiHierarchy_t * hierarchy, uiPage_t * prevpage);
13 static int uideletepage(uiPage_t * page, uiHierarchy_t * hierarchy);
14 static void uideletepagecallbacks(uiPage_t * page);
15 static uiPage_t *uifindshadowpage(uiHierarchy_t * hierarchy, uiPage_t * page);
16 static int uicreatepagewidgets(uiPage_t * page, uiPage_t * prevpage,
18 static void uicreatepageform(uiPage_t * page, char *title, Widget topwdg);
19 static Widget uicreatepagemenu(uiPage_t * page, Widget formwdg);
20 static Widget uicreatepagemenuitem(uiPage_t * page, Widget menuwdg,
21 int itempos, int level);
22 static int uifindnextitem(int itempos, int level);
23 static Widget uicreatepagecontrol(uiPage_t * page, Widget formwdg, char *title);
24 static void uicreatepagelabel(Widget parentwdg, char *label);
25 static void uicreatepagebutton(uiPage_t * page, Widget parentwdg, char *name,
26 int leftpos, int rightpos);
27 static Widget uicreatepagefind(uiPage_t * page, Widget formwdg,
29 static Widget uicreatepagescroll(uiPage_t * page, Widget formwdg,
30 Widget menuwdg, Widget controlwdg);
31 static void uiconnectpage(uiPage_t * page);
32 static void uipageupdatescrollbars(uiPage_t * page);
33 static uiActionData_t *uicreatepageactiondata(uiPage_t * page,
35 static void uisetcurrentpage(uiPage_t * page);
36 static int uideletepageinternal(char *topaddress, HText_t * htext);
38 static void uipageactivatecb(Widget wdg, uiActionData_t * actiondata,
39 XmAnyCallbackStruct * calldata);
40 static void uipagekludgecb(Widget wdg, uiActionData_t * actiondata,
42 static void uipageexposecb(Widget wdg, uiPage_t * page,
43 XmDrawingAreaCallbackStruct * calldata);
44 static void uipageresizecb(Widget wdg, uiPage_t * page,
45 XmDrawingAreaCallbackStruct * calldata);
46 static void uipageinputcb(char *topaddress, HText_t * htext,
47 HTextObject_t * htextobject, void *parameter);
48 static void uipagescrollbarcb(char *topaddress, HText_t * htext,
49 HTextObject_t * htextobject, void *parameter);
50 static void uipagedowncb(char *topaddress, HText_t * htext,
51 HTextObject_t * htextobject, void *parameter);
52 static void uipageupcb(char *topaddress, HText_t * htext,
53 HTextObject_t * htextobject, void *parameter);
54 static void uipagetopcb(char *topaddress, HText_t * htext,
55 HTextObject_t * htextobject, void *parameter);
56 static void uipagebottomcb(char *topaddress, HText_t * htext,
57 HTextObject_t * htextobject, void *parameter);
59 uiPageInfo_t uiPageInfo =
67 int UiDisplayPage(topaddress, prevhtext, htext, htextobject, title)
71 HTextObject_t *htextobject;
74 uiHierarchy_t *hierarchy;
75 uiPage_t *prevpage, *page;
77 if (!(hierarchy = uifindoraddhierarchy(topaddress)))
80 if (!(page = uifindpage(htext, hierarchy)) || !page->Visible) {
81 prevpage = uifindpage(prevhtext, hierarchy);
84 if (!(page = uiaddpage(htext, htextobject, hierarchy, prevpage))) {
85 if (!hierarchy->Pages)
86 (void) uideletehierarchy(hierarchy); /* already an error */
90 if (uicreatepagewidgets(page, prevpage, title) == UI_OK) {
91 uisetcurrentpage(page);
97 XRaiseWindow(XtDisplay(page->Gfx.TopWdg), XtWindow(page->Gfx.TopWdg));
98 uisetcurrentpage(page);
105 int UiDeletePage(topaddress, htext)
109 uiHierarchy_t *hierarchy;
110 uiPage_t *page, *shadowpage;
111 uiAction_t *tmpaction;
113 if (!(hierarchy = uifindhierarchy(topaddress)))
116 if (!(page = uifindpage(htext, hierarchy)))
121 shadowpage = uifindshadowpage(hierarchy, page);
124 XtDestroyWidget(XtParent(page->Gfx.FormWdg));
125 uideletepage(page, hierarchy);
127 if (shadowpage) { /* Recursive destroy, oh yeah */
128 tmpaction = uiFindAction("Close");
129 (tmpaction->Callback) (topaddress, shadowpage->HText,
130 shadowpage->HTextObject, tmpaction->Parameter);
136 int UiSetCursor(topaddress, htext, htextobject)
139 HTextObject_t *htextobject;
141 uiHierarchy_t *hierarchy;
145 if (!(hierarchy = uifindhierarchy(topaddress)))
148 if (!(page = uifindpage(htext, hierarchy)))
151 page->HTextObject = htextobject;
156 XlSetCursor(htext, htextobject);
158 XlGetCoordinates(&tmpx, &tmpy, htextobject);
159 if (tmpx < page->Layout.X || tmpx > page->Layout.X + page->Layout.Width)
160 page->Layout.X = tmpx - page->Layout.Width / 2;
161 if (tmpy < page->Layout.Y || tmpy > page->Layout.Y + page->Layout.Height)
162 page->Layout.Y = tmpy - page->Layout.Height / 2;
164 uipageupdatescrollbars(page);
165 XlMoveWindow(page->Layout.X, page->Layout.Y, page->HText);
171 void uiPageUpdateWindow(page)
174 HTextObject_t *htextobject;
177 if (page->Settings.UseFixed)
178 tmpwidth = page->Settings.FixedWidth - page->Settings.LeftMargin -
179 page->Settings.RightMargin;
181 tmpwidth = page->Layout.Width - page->Settings.LeftMargin -
182 page->Settings.RightMargin;
184 htextobject = XlLocateHTextObject(0, 0, page->HText);
185 XlFormatText(page->Settings.LeftMargin, tmpwidth,
186 page->Settings.TopMargin, &page->Layout.VirtualWidth,
187 &page->Layout.VirtualHeight, page->HText);
188 XlGetCoordinates(&page->Layout.X, &page->Layout.Y, htextobject);
190 if (page->Layout.VirtualWidth > tmpwidth + page->Settings.LeftMargin)
191 page->Layout.VirtualWidth += page->Settings.RightMargin;
193 page->Layout.VirtualWidth = tmpwidth + page->Settings.LeftMargin +
194 page->Settings.RightMargin;
195 page->Layout.VirtualHeight += page->Settings.BottomMargin;
197 if (!page->Settings.UseFixed)
199 uipageupdatescrollbars(page);
201 XlSetPageCoordinates(page->Layout.X, page->Layout.Y, page->HText);
205 void uiPageAttachCallbacks()
207 UiAttachCallback("Top", uipagetopcb, (void *) NULL);
208 UiAttachCallback("Bottom", uipagebottomcb, (void *) NULL);
212 void uiPageDefineKeys()
214 UiBindKey("space", UI_NONE, uipagedowncb, (void *) NULL);
215 UiBindKey("Delete", UI_NONE, uipageupcb, (void *) NULL);
217 UiBindKey("less", UI_SHIFT, uipagetopcb, (void *) NULL);
218 UiBindKey("greater", UI_SHIFT, uipagebottomcb, (void *) NULL);
222 static uiHierarchy_t *
223 uifindoraddhierarchy(topaddress)
226 uiHierarchy_t *tmphierarchy;
228 if (!(tmphierarchy = uifindhierarchy(topaddress))) {
229 tmphierarchy = uiTopLevel.Hierarchies;
231 tmphierarchy = uiTopLevel.Hierarchies =
232 (uiHierarchy_t *) uiMalloc(sizeof(*tmphierarchy));
234 while (tmphierarchy->Next)
235 tmphierarchy = tmphierarchy->Next;
236 tmphierarchy = tmphierarchy->Next =
237 (uiHierarchy_t *) uiMalloc(sizeof(*tmphierarchy));
239 tmphierarchy->Address = topaddress;
240 tmphierarchy->Pages = (uiPage_t *) NULL;
241 tmphierarchy->Next = (uiHierarchy_t *) NULL;
247 static uiHierarchy_t *
248 uifindhierarchy(topaddress)
251 uiHierarchy_t *tmphierarchy = uiTopLevel.Hierarchies;
253 while (tmphierarchy && strcmp(tmphierarchy->Address, topaddress))
254 tmphierarchy = tmphierarchy->Next;
260 static int uideletehierarchy(hierarchy)
261 uiHierarchy_t *hierarchy;
263 uiHierarchy_t *tmphierarchy = uiTopLevel.Hierarchies;
265 if (hierarchy == tmphierarchy)
266 if (tmphierarchy->Next) {
267 uiTopLevel.Hierarchies = hierarchy->Next;
268 uisetcurrentpage(hierarchy->Next->Pages);
270 uiTopLevel.Hierarchies = (uiHierarchy_t *) NULL;
271 uisetcurrentpage((uiPage_t *) NULL);
274 while (tmphierarchy->Next && tmphierarchy->Next != hierarchy)
275 tmphierarchy = tmphierarchy->Next;
276 if (tmphierarchy->Next) {
277 tmphierarchy->Next = tmphierarchy->Next->Next;
278 uisetcurrentpage(tmphierarchy->Pages);
280 /* This shouldn't happen unless we have a stray pointer */
281 uiDisplayWarning("Messed up hierarchy-list");
294 uifindpage(htext, hierarchy)
296 uiHierarchy_t *hierarchy;
298 uiPage_t *tmppage = hierarchy->Pages;
300 while (tmppage && tmppage->HText != htext)
301 tmppage = tmppage->Next;
308 uiaddpage(htext, htextobject, hierarchy, prevpage)
310 HTextObject_t *htextobject;
311 uiHierarchy_t *hierarchy;
314 uiPage_t *tmppage = hierarchy->Pages;
317 tmppage = hierarchy->Pages =
318 (uiPage_t *) uiMalloc(sizeof(*tmppage));
320 while (tmppage->Next)
321 tmppage = tmppage->Next;
322 tmppage = tmppage->Next =
323 (uiPage_t *) uiMalloc(sizeof(*tmppage));
325 tmppage->HText = htext;
326 tmppage->HTextObject = htextobject;
327 tmppage->Hierarchy = hierarchy;
330 tmppage->Settings.TopMargin = prevpage->Settings.TopMargin;
331 tmppage->Settings.BottomMargin = prevpage->Settings.BottomMargin;
332 tmppage->Settings.LeftMargin = prevpage->Settings.LeftMargin;
333 tmppage->Settings.RightMargin = prevpage->Settings.RightMargin;
334 tmppage->Settings.OnePageMode = prevpage->Settings.OnePageMode;
335 tmppage->Settings.UseFixed = prevpage->Settings.UseFixed;
336 tmppage->Settings.FixedWidth = prevpage->Settings.FixedWidth;
337 tmppage->Layout.Width = prevpage->Layout.Width;
338 tmppage->Layout.Height = prevpage->Layout.Height;
340 uiGlobalSettings_t *gs = &uiTopLevel.GlobalSettings;
342 tmppage->Settings.TopMargin = gs->TopMargin;
343 tmppage->Settings.BottomMargin = gs->BottomMargin;
344 tmppage->Settings.LeftMargin = gs->LeftMargin;
345 tmppage->Settings.RightMargin = gs->RightMargin;
346 tmppage->Settings.OnePageMode = gs->OnePageMode;
347 tmppage->Settings.UseFixed = gs->UseFixed;
348 tmppage->Settings.FixedWidth = gs->FixedWidth;
349 tmppage->Layout.Width = gs->Width;
350 tmppage->Layout.Height = gs->Height;
353 /* X and Y are href-dependent, Width and Height default, or previous */
354 tmppage->Layout.X = 0;
355 tmppage->Layout.Y = 0;
357 tmppage->Callbacks = (uiPageCBList_t *) NULL;
358 tmppage->Next = (uiPage_t *) NULL;
364 static int uideletepage(page, hierarchy)
366 uiHierarchy_t *hierarchy;
368 uiPage_t *tmppage = hierarchy->Pages;
372 hierarchy->Pages = tmppage->Next;
373 uisetcurrentpage(tmppage->Next);
375 uideletehierarchy(hierarchy);
377 while (tmppage->Next && tmppage->Next != page)
378 tmppage = tmppage->Next;
380 tmppage->Next = tmppage->Next->Next;
382 uisetcurrentpage(tmppage->Next);
384 uisetcurrentpage(tmppage);
386 /* This shouldn't happen unless we have a stray pointer */
387 uiDisplayWarning("Messed up page-list");
393 uiListUpdateDialog(page);
394 uideletepagecallbacks(page);
401 static void uideletepagecallbacks(page)
404 uiPageCBList_t *tmpcb = page->Callbacks;
408 uiFree(page->Callbacks);
409 page->Callbacks = tmpcb;
415 uifindshadowpage(hierarchy, page)
416 uiHierarchy_t *hierarchy;
419 uiPage_t *tmppage = hierarchy->Pages;
422 if (tmppage != page && tmppage->Gfx.TopWdg == page->Gfx.TopWdg)
425 tmppage = tmppage->Next;
427 return (uiPage_t *) NULL;
431 static int uicreatepagewidgets(page, prevpage, title)
436 uiTopLevelGfx_t *topgfx = &uiTopLevel.TopGfx;
437 uiPageGfx_t *pagegfx = &page->Gfx;
438 Widget topwdg, bottomwdg;
440 /* Ahemm, we could of course try to salvage as much as possible
441 of the widget tree, but why bother? No, just destroy everything
442 except for the toplevel shell, no need to remove callbacks and
445 if (prevpage && prevpage->Settings.OnePageMode) {
446 topwdg = prevpage->Gfx.TopWdg;
447 uideletepageinternal(prevpage->Hierarchy->Address, prevpage->HText);
448 uicreatepageform(page, title, topwdg);
450 uicreatepageform(page, title, (Widget) NULL);
452 page->Visible = TRUE;
453 pagegfx->MenuWdg = uicreatepagemenu(page, pagegfx->FormWdg);
454 XtManageChild(pagegfx->MenuWdg);
455 pagegfx->ControlWdg = uicreatepagecontrol(page, pagegfx->FormWdg, title);
456 XtManageChild(pagegfx->ControlWdg);
457 page->Gfx.FindTextWdg = (Widget) NULL;
458 if (HTAnchor_isIndex(page->HText->node_anchor)) {
459 pagegfx->FindWdg = uicreatepagefind(page, pagegfx->FormWdg,
460 pagegfx->ControlWdg);
461 XtManageChild(pagegfx->FindWdg);
462 bottomwdg = pagegfx->FindWdg;
464 bottomwdg = pagegfx->ControlWdg;
465 pagegfx->DrawAreaWdg = uicreatepagescroll(page, pagegfx->FormWdg,
466 pagegfx->MenuWdg, bottomwdg);
468 XtManageChild(pagegfx->FormWdg);
469 XtRealizeWidget(pagegfx->TopWdg);
471 /* Do setup that cannot be done before managing the form */
472 XtVaSetValues(pagegfx->HScrollBarWdg,
473 XmNrightAttachment, XmATTACH_FORM,
474 XmNrightOffset, uiGetArg(pagegfx->FormWdg, XmNwidth) -
475 uiGetArg(pagegfx->DrawAreaWdg, XmNwidth), NULL);
478 /* Is this really necessary?
479 XmUpdateDisplay(XtParent(pagegfx->FormWdg));
480 Nope, don't think so */
486 static void uicreatepageform(page, title, topwdg)
496 page->Gfx.TopWdg = topwdg;
498 page->Gfx.TopWdg = XtCreateApplicationShell("Page",
499 topLevelShellWidgetClass,
502 tmptitle = uiMalloc(strlen(UI_ERWISE_TITLE) + strlen(title) + 4);
503 sprintf(tmptitle, "%s - %s", UI_ERWISE_TITLE, title);
504 XtVaSetValues(page->Gfx.TopWdg,
505 XmNtitle, tmptitle, NULL);
508 XtVaSetValues(page->Gfx.TopWdg,
509 XmNtitle, UI_ERWISE_TITLE, NULL);
511 args = uiVaSetArgs(&nargs,
513 page->Gfx.FormWdg = XmCreateForm(page->Gfx.TopWdg, "Form", args, nargs);
517 static char *uimenu[] =
523 " Load to file", "Load to file",
525 " Settings", "Settings",
528 "Movement", "Movement",
531 " Prev tag", "Prev tag",
532 " Next tag", "Next tag",
537 " Prev page", "Prev page",
538 " Next page", "Next page",
540 " hierarchy", "Close hierarchy",
542 " Connections", "Connections",
543 " Controlpanel", "Controlpanel",
544 " Defaults", "Defaults",
546 " On function", "On function",
552 uicreatepagemenu(page, formwdg)
558 Widget menuwdg, tmpmenuwdg;
561 args = uiVaSetArgs(&nargs,
562 XmNleftAttachment, XmATTACH_FORM,
563 XmNrightAttachment, XmATTACH_FORM,
564 XmNtopAttachment, XmATTACH_FORM, NULL);
565 menuwdg = XmCreateMenuBar(formwdg, "menubar", args, nargs);
568 tmpmenuwdg = uicreatepagemenuitem(page, menuwdg, itempos, 0);
569 if (ui_HELPMENU(uimenu[itempos]))
570 XtVaSetValues(menuwdg,
571 XmNmenuHelpWidget, tmpmenuwdg, NULL);
572 itempos = uifindnextitem(itempos, 0);
574 while (ui_VALID(itempos));
581 uicreatepagemenuitem(page, menuwdg, itempos, level)
587 int childitempos = itempos;
588 int childlevel = level + 1;
595 uiActionData_t *actiondata;
597 label = &uimenu[itempos][level];
598 if (ui_VALID(uifindnextitem(itempos, childlevel))) {
599 pulldownwdg = XmCreatePulldownMenu(menuwdg, "Pulldown", NULL, 0);
600 args = uiVaSetArgs(&nargs, XmNsubMenuId, pulldownwdg, NULL);
601 cascadewdg = XmCreateCascadeButtonGadget(menuwdg, label, args, nargs);
602 XtManageChild(cascadewdg);
604 while (ui_VALID(childitempos =
605 uifindnextitem(childitempos, childlevel)))
606 uicreatepagemenuitem(page, pulldownwdg, childitempos, childlevel);
611 if (ui_TOGGLE(label)) {
612 tmpwdg = XmCreateToggleButtonGadget(menuwdg, label, NULL, 0);
614 tmpwdg = XmCreatePushButtonGadget(menuwdg, label, NULL, 0);
615 actiondata = uicreatepageactiondata(page, uimenu[itempos + 1]);
616 XtAddCallback(tmpwdg, XmNactivateCallback,
617 (XtCallbackProc) uipageactivatecb,
618 (caddr_t) actiondata);
621 tmpwdg = XmCreateSeparatorGadget(menuwdg, "Separator", NULL, 0);
622 XtManageChild(tmpwdg);
629 static int uifindnextitem(itempos, level)
636 (uimenu[i][level] == ' ' || uimenu[i][level] == '*'))
639 (level && uimenu[i][level - 1] != ' ' && uimenu[i][level - 1] != '*'))
647 uicreatepagecontrol(page, formwdg, title)
656 args = uiVaSetArgs(&nargs,
658 XmNshadowThickness, 2,
659 XmNleftAttachment, XmATTACH_FORM,
660 XmNrightAttachment, XmATTACH_FORM,
661 XmNbottomAttachment, XmATTACH_FORM, NULL);
662 controlwdg = XmCreateForm(formwdg, "Control", args, nargs);
664 uicreatepagelabel(controlwdg,
665 HTAnchor_address((HTAnchor *) page->HText->node_anchor));
667 uicreatepagebutton(page, controlwdg, "Prev tag", 1, 16);
668 uicreatepagebutton(page, controlwdg, "Next tag", 17, 32);
669 uicreatepagebutton(page, controlwdg, "Prev page", 35, 50);
670 uicreatepagebutton(page, controlwdg, "Back", 51, 66);
671 uicreatepagebutton(page, controlwdg, "Next page", 67, 82);
672 uicreatepagebutton(page, controlwdg, "Close", 85, 99);
678 static void uicreatepagelabel(parentwdg, label)
685 labelstr = XmStringCreateSimple(label);
686 labelwdg = XmCreateLabelGadget(parentwdg, "Label", (ArgList) NULL, 0);
687 XtVaSetValues(labelwdg,
688 XmNtopAttachment, XmATTACH_FORM,
690 XmNleftAttachment, XmATTACH_FORM,
692 XmNrightAttachment, XmATTACH_FORM,
694 XmNlabelString, labelstr, NULL);
696 XtManageChild(labelwdg);
700 static void uicreatepagebutton(page, parentwdg, name, leftpos, rightpos)
708 uiActionData_t *actiondata;
710 tmpwdg = XmCreatePushButtonGadget(parentwdg, name, (ArgList) NULL, 0);
711 XtVaSetValues(tmpwdg,
712 XmNbottomAttachment, XmATTACH_FORM,
714 XmNleftAttachment, XmATTACH_POSITION,
715 XmNleftPosition, leftpos,
716 XmNrightAttachment, XmATTACH_POSITION,
717 XmNrightPosition, rightpos, NULL);
718 actiondata = uicreatepageactiondata(page, name);
719 XtAddCallback(tmpwdg, XmNactivateCallback, uipageactivatecb,
720 (caddr_t) actiondata);
722 XtManageChild(tmpwdg);
727 uicreatepagefind(page, formwdg, controlwdg)
732 Widget framewdg, findformwdg, buttonwdg, textwdg;
733 uiActionData_t *actiondata;
736 labelstr = XmStringCreateSimple(" Find: ");
738 framewdg = XmCreateFrame(formwdg, "FindFrame", (ArgList) NULL, 0);
739 XtVaSetValues(framewdg,
740 XmNshadowType, XmSHADOW_OUT,
743 XmNleftAttachment, XmATTACH_FORM,
744 XmNrightAttachment, XmATTACH_FORM,
745 XmNbottomAttachment, XmATTACH_WIDGET,
746 XmNbottomWidget, controlwdg,
747 XmNbottomOffset, 1, NULL);
749 findformwdg = XmCreateForm(framewdg, "FindForm", (ArgList) NULL, 0);
750 XtManageChild(findformwdg);
752 buttonwdg = XmCreatePushButtonGadget(findformwdg, "FindButton",
754 XtVaSetValues(buttonwdg,
755 XmNlabelString, labelstr,
756 XmNtopAttachment, XmATTACH_FORM,
757 XmNleftAttachment, XmATTACH_FORM,
758 XmNbottomAttachment, XmATTACH_FORM, NULL);
759 actiondata = uicreatepageactiondata(page, "IndexFind");
760 XtAddCallback(buttonwdg, XmNactivateCallback, uipageactivatecb,
761 (caddr_t) actiondata);
762 XmStringFree(labelstr);
763 XtManageChild(buttonwdg);
765 textwdg = XmCreateText(findformwdg, "FindText", (ArgList) NULL, 0);
766 XtVaSetValues(textwdg,
767 XmNtopAttachment, XmATTACH_FORM,
768 XmNleftAttachment, XmATTACH_WIDGET,
769 XmNleftWidget, buttonwdg,
770 XmNrightAttachment, XmATTACH_FORM,
771 XmNbottomAttachment, XmATTACH_FORM, NULL);
772 XtAddCallback(textwdg, XmNactivateCallback, uipageactivatecb,
773 (caddr_t) actiondata);
774 XtAddCallback(textwdg, XmNactivateCallback,
775 (XtCallbackProc) uiDialogVariableCB, (caddr_t) "FindText");
776 XtAddCallback(textwdg, XmNlosingFocusCallback,
777 (XtCallbackProc) uiDialogVariableCB, (caddr_t) "FindText");
778 XtAddCallback(textwdg, XmNvalueChangedCallback,
779 (XtCallbackProc) uiDialogVariableCB, (caddr_t) "FindText");
780 (void) uiAddWidgetInfo("FindText", textwdg, uiWTtext); /* Ignore */
781 page->Gfx.FindTextWdg = textwdg;
782 XtManageChild(textwdg);
789 uicreatepagescroll(page, formwdg, menuwdg, bottomwdg)
797 Widget drawwdg, hsbwdg, vsbwdg;
798 uiActionData_t *actiondata;
800 args = uiVaSetArgs(&nargs,
801 XmNorientation, XmHORIZONTAL,
802 XmNwidth, page->Layout.Width,
803 XmNbottomAttachment, XmATTACH_WIDGET,
804 XmNbottomWidget, bottomwdg,
805 XmNbottomOffset, 2, NULL);
806 hsbwdg = XmCreateScrollBar(formwdg, "HScrollBar", args, nargs);
807 page->Gfx.HScrollBarWdg = hsbwdg;
808 actiondata = uicreatepageactiondata(page, "HScrollBar");
809 XtAddCallback(hsbwdg, XmNvalueChangedCallback,
810 (XtCallbackProc) uipageactivatecb, (caddr_t *) actiondata);
811 UiAttachCallback("HScrollBar", uipagescrollbarcb, (void *) "HScrollBar");
813 args = uiVaSetArgs(&nargs,
814 XmNorientation, XmVERTICAL,
815 XmNheight, page->Layout.Height,
816 XmNtopAttachment, XmATTACH_WIDGET,
817 XmNtopWidget, menuwdg,
818 XmNrightAttachment, XmATTACH_FORM,
819 XmNbottomAttachment, XmATTACH_WIDGET,
820 XmNbottomWidget, hsbwdg, NULL);
821 vsbwdg = XmCreateScrollBar(formwdg, "VScrollBar", args, nargs);
822 page->Gfx.VScrollBarWdg = vsbwdg;
823 actiondata = uicreatepageactiondata(page, "VScrollBar");
824 XtAddCallback(vsbwdg, XmNvalueChangedCallback,
825 (XtCallbackProc) uipageactivatecb, (caddr_t *) actiondata);
826 UiAttachCallback("VScrollBar", uipagescrollbarcb, (void *) "VScrollBar");
828 args = uiVaSetArgs(&nargs,
829 XmNwidth, page->Layout.Width,
830 XmNheight, page->Layout.Height,
831 XmNtopAttachment, XmATTACH_WIDGET,
832 XmNtopWidget, menuwdg,
833 XmNleftAttachment, XmATTACH_FORM,
834 XmNrightAttachment, XmATTACH_WIDGET,
835 XmNrightWidget, vsbwdg,
836 XmNbottomAttachment, XmATTACH_WIDGET,
837 XmNbottomWidget, hsbwdg, NULL);
838 drawwdg = XmCreateDrawingArea(formwdg, "Draw", args, nargs);
839 XtAddCallback(drawwdg, XmNexposeCallback, (XtCallbackProc) uipageexposecb,
841 XtAddCallback(drawwdg, XmNresizeCallback, (XtCallbackProc) uipageresizecb,
843 actiondata = uicreatepageactiondata(page, "PageInput");
844 XtAddCallback(drawwdg, XmNinputCallback, (XtCallbackProc) uipageactivatecb,
845 (caddr_t) actiondata);
846 XtAddEventHandler(drawwdg, KeyPressMask, FALSE, uipagekludgecb,
847 (caddr_t) actiondata);
848 UiAttachCallback("PageInput", uipageinputcb, (void *) NULL);
850 XtManageChild(drawwdg);
851 XtManageChild(hsbwdg);
852 XtManageChild(vsbwdg);
858 static void uiconnectpage(page)
861 Widget drawwdg = page->Gfx.DrawAreaWdg;
862 Widget hsbwdg = page->Gfx.HScrollBarWdg;
863 Widget vsbwdg = page->Gfx.VScrollBarWdg;
866 XlSetupText(XtDisplay(drawwdg), XtWindow(drawwdg),
867 (Pixel) uiGetArg(drawwdg, XmNforeground),
868 (Pixel) uiGetArg(drawwdg, XmNbackground), page->HText);
870 if (page->Settings.UseFixed)
871 tmpwidth = page->Settings.FixedWidth - page->Settings.LeftMargin -
872 page->Settings.RightMargin;
874 tmpwidth = page->Layout.Width - page->Settings.LeftMargin -
875 page->Settings.RightMargin;
877 XlFormatText(page->Settings.LeftMargin, tmpwidth,
878 page->Settings.TopMargin, &page->Layout.VirtualWidth,
879 &page->Layout.VirtualHeight, page->HText);
881 if (page->Layout.VirtualWidth > tmpwidth + page->Settings.LeftMargin)
882 page->Layout.VirtualWidth += page->Settings.RightMargin;
884 page->Layout.VirtualWidth = tmpwidth + page->Settings.LeftMargin +
885 page->Settings.RightMargin;
886 page->Layout.VirtualHeight += page->Settings.BottomMargin;
888 if (page->HTextObject)
889 XlGetCoordinates(&page->Layout.X, &page->Layout.Y, page->HTextObject);
891 uipageupdatescrollbars(page);
892 if (page->HTextObject)
893 XlMoveWindow(page->Layout.X, page->Layout.Y, page->HText);
895 XlSetCursor(page->HText, page->HTextObject);
899 static void uipageupdatescrollbars(page)
902 Widget hsbwdg = page->Gfx.HScrollBarWdg;
903 Widget vsbwdg = page->Gfx.VScrollBarWdg;
904 int maxwidth, maxheight;
905 int hsbwidth, vsbheight;
907 maxwidth = page->Layout.VirtualWidth;
908 if (page->Layout.X + page->Layout.Width > maxwidth)
909 page->Layout.X -= ((page->Layout.X + page->Layout.Width) - maxwidth);
910 hsbwidth = (page->Layout.Width > maxwidth) ? maxwidth : page->Layout.Width;
911 if (page->Layout.X < 0)
914 maxheight = page->Layout.VirtualHeight;
915 if (page->Layout.Y + page->Layout.Height > maxheight)
916 page->Layout.Y -= ((page->Layout.Y + page->Layout.Height) - maxheight);
918 (page->Layout.Height > maxheight) ? maxheight : page->Layout.Height;
919 if (page->Layout.Y < 0)
923 XtVaSetValues(hsbwdg,
924 XmNmaximum, maxwidth,
925 XmNvalue, page->Layout.X,
926 XmNsliderSize, hsbwidth,
927 XmNincrement, hsbwidth / 10,
928 XmNpageIncrement, hsbwidth, NULL);
929 XtVaSetValues(vsbwdg,
930 XmNmaximum, maxheight,
931 XmNvalue, page->Layout.Y,
932 XmNsliderSize, vsbheight,
933 XmNincrement, vsbheight / 10,
934 XmNpageIncrement, vsbheight, NULL);
939 uicreatepageactiondata(page, actionname)
943 uiPageCBList_t *tmppagecb = page->Callbacks;
947 page->Callbacks = (uiPageCBList_t *) uiMalloc(sizeof(*tmppagecb));
949 while (tmppagecb->Next)
950 tmppagecb = tmppagecb->Next;
951 tmppagecb = tmppagecb->Next =
952 (uiPageCBList_t *) uiMalloc(sizeof(*tmppagecb));
954 tmppagecb->ActionData.ActionName = actionname;
955 tmppagecb->ActionData.Page = page;
956 tmppagecb->Next = (uiPageCBList_t *) NULL;
958 return &tmppagecb->ActionData;
962 static void uisetcurrentpage(page)
967 oldpage = uiPageInfo.CurrentPage;
968 uiPageInfo.CurrentPage = page;
970 if (oldpage != page) {
971 uiPageSettingsUpdateDialog();
972 uiSearchUpdateDialog();
973 uiControlPanelUpdateDialog();
974 uiPrintUpdateDialog();
975 uiRecallUpdateDialog();
976 uiConnectionsUpdateDialog();
981 static int uideletepageinternal(topaddress, htext)
985 uiHierarchy_t *hierarchy;
989 if (!(hierarchy = uifindhierarchy(topaddress)))
992 if (!(page = uifindpage(htext, hierarchy)))
995 /* XlDeleteText(htext);*/
997 topwdg = page->Gfx.TopWdg;
998 page = hierarchy->Pages;
1000 if (page->Gfx.TopWdg == topwdg) {
1002 XtDestroyWidget(page->Gfx.FormWdg);
1003 page->Visible = FALSE;
1007 /* uideletepage(page, hierarchy);*/
1013 static void uipageactivatecb(wdg, actiondata, calldata)
1015 uiActionData_t *actiondata;
1016 XmAnyCallbackStruct *calldata;
1018 uiAction_t *tmpaction;
1020 uiPageInfo.Wdg = wdg;
1021 uiPageInfo.CallData = (void *) calldata;
1022 uisetcurrentpage(actiondata->Page);
1023 if (actiondata->Page->Gfx.FindTextWdg) {
1024 (void) uiAddWidgetInfo("FindText", actiondata->Page->Gfx.FindTextWdg,
1025 uiWTtext); /* Ignore */
1026 (void) uiDialogVariableCB((Widget) NULL, "FindText",
1027 (XmAnyCallbackStruct *) NULL); /* Hmm? */
1029 if (tmpaction = uiFindAction(actiondata->ActionName)) {
1030 uiDefineCursor(uiBusyCursor);
1031 if (uiHelpOnActionCB) {
1032 (*uiHelpOnActionCB) (actiondata->ActionName);
1033 uiHelpOnActionCB = (void (*) (char *actionstring)) NULL;
1035 (*tmpaction->Callback) (actiondata->Page->Hierarchy->Address,
1036 actiondata->Page->HText,
1037 actiondata->Page->HTextObject,
1038 tmpaction->Parameter);
1045 * Massive braindamage ahead ... default translation in
1046 * drawingarea-widget for return is activate, even if the widget
1047 * doesn't support activate. Gawd! Anyway, we have to resort to this:
1050 static void uipagekludgecb(wdg, actiondata, event)
1052 uiActionData_t *actiondata;
1055 XKeyEvent *kevent = (XKeyEvent *) event;
1056 XmAnyCallbackStruct tmpstruct;
1058 if (XLookupKeysym(kevent, kevent->state) == XK_Return) {
1059 tmpstruct.event = event;
1060 uipageactivatecb(wdg, actiondata, &tmpstruct);
1065 static void uipageexposecb(wdg, page, calldata)
1068 XmDrawingAreaCallbackStruct *calldata;
1070 XExposeEvent *event = (XExposeEvent *) calldata->event;
1073 printf("Explode: %d %d %d %d %x\n",
1074 event->x, event->y, event->width, event->height, page->HText);
1076 XlRedraw(event->x, event->y, event->width, event->height, page->HText);
1080 static void uipageresizecb(wdg, page, calldata)
1083 XmDrawingAreaCallbackStruct *calldata;
1085 Widget hsbwdg = page->Gfx.HScrollBarWdg;
1086 Widget vsbwdg = page->Gfx.VScrollBarWdg;
1087 HTextObject_t *htextobject;
1090 printf("Resize: %d %d\n",
1091 (int) ((Dimension) uiGetArg(wdg, XmNwidth)),
1092 (int) ((Dimension) uiGetArg(wdg, XmNheight)));
1095 if (!XtIsRealized(page->Gfx.DrawAreaWdg))
1098 XlClearWindow(page->Layout.Width, page->Layout.Height, page->HText);
1100 page->Layout.Width = (int) ((Dimension) uiGetArg(wdg, XmNwidth));
1101 page->Layout.Height = (int) ((Dimension) uiGetArg(wdg, XmNheight));
1103 uiPageUpdateWindow(page);
1107 static void uipageinputcb(topaddress, htext, htextobject, parameter)
1110 HTextObject_t *htextobject;
1113 Widget wdg = uiPageInfo.Wdg;
1114 uiPage_t *page = uiPageInfo.CurrentPage;
1115 XmDrawingAreaCallbackStruct *calldata =
1116 (XmDrawingAreaCallbackStruct *) uiPageInfo.CallData;
1117 XButtonEvent *bevent = (XButtonEvent *) calldata->event;
1118 XKeyEvent *kevent = (XKeyEvent *) calldata->event;
1119 static int dragx, dragy;
1120 static Time oldtime = (Time) 0;
1121 uiAction_t *tmpaction;
1125 switch (bevent->type) {
1127 switch (bevent->button) {
1129 page->HTextObject = XlLocateHTextObject(bevent->x, bevent->y,
1131 XlSetCursor(htext, page->HTextObject);
1132 if (page->HTextObject) {
1133 if (bevent->time - oldtime <
1134 uiTopLevel.GlobalSettings.DoubleClickTime)
1135 tmpaction = uiFindAction("Get page");
1137 tmpaction = uiFindAction("Click page");
1139 uiDefineCursor(uiBusyCursor);
1140 if (uiHelpOnActionCB) {
1141 (*uiHelpOnActionCB) ("Get page");
1142 uiHelpOnActionCB = (void (*) (char *actionstring)) NULL;
1144 (*tmpaction->Callback) (topaddress, htext,
1146 tmpaction->Parameter);
1151 oldtime = bevent->time;
1160 switch (bevent->button) {
1162 page->Layout.X -= (bevent->x - dragx);
1163 page->Layout.Y -= (bevent->y - dragy);
1164 uipageupdatescrollbars(page);
1165 XlMoveWindow(page->Layout.X, page->Layout.Y, page->HText);
1170 keysym = XLookupKeysym(kevent, 0);
1171 if (keysym != NoSymbol && (keysymstring = XKeysymToString(keysym))) {
1172 if (tmpkey = uiFindKey(keysymstring, kevent->state)) {
1173 uiDefineCursor(uiBusyCursor);
1174 if (uiHelpOnActionCB) {
1175 (*uiHelpOnActionCB) (keysymstring);
1176 uiHelpOnActionCB = (void (*) (char *actionstring)) NULL;
1178 (*tmpkey->Callback) (topaddress,
1190 static void uipagescrollbarcb(topaddress, htext, htextobject, parameter)
1193 HTextObject_t *htextobject;
1196 XmUpdateDisplay(uiPageInfo.CurrentPage->Gfx.DrawAreaWdg);
1198 if (!strcmp("HScrollBar", (char *) parameter))
1199 uiPageInfo.CurrentPage->Layout.X =
1200 ((XmScrollBarCallbackStruct *) uiPageInfo.CallData)->value;
1202 uiPageInfo.CurrentPage->Layout.Y =
1203 ((XmScrollBarCallbackStruct *) uiPageInfo.CallData)->value;
1206 printf("scrollbar: %d %d\n", uiPageInfo.CurrentPage->Layout.X,
1207 uiPageInfo.CurrentPage->Layout.Y);
1209 XlMoveWindow(uiPageInfo.CurrentPage->Layout.X,
1210 uiPageInfo.CurrentPage->Layout.Y,
1211 uiPageInfo.CurrentPage->HText);
1215 static void uipagedowncb(topaddress, htext, htextobject, parameter)
1218 HTextObject_t *htextobject;
1221 uiPage_t *page = uiPageInfo.CurrentPage;
1223 page->Layout.Y = page->Layout.Y + page->Layout.Height;
1225 uipageupdatescrollbars(page);
1226 XlMoveWindow(page->Layout.X, page->Layout.Y, page->HText);
1230 static void uipageupcb(topaddress, htext, htextobject, parameter)
1233 HTextObject_t *htextobject;
1236 uiPage_t *page = uiPageInfo.CurrentPage;
1238 page->Layout.Y = page->Layout.Y - page->Layout.Height;
1240 uipageupdatescrollbars(page);
1241 XlMoveWindow(page->Layout.X, page->Layout.Y, page->HText);
1245 static void uipagetopcb(topaddress, htext, htextobject, parameter)
1248 HTextObject_t *htextobject;
1251 uiPage_t *page = uiPageInfo.CurrentPage;
1255 uipageupdatescrollbars(page);
1256 XlMoveWindow(page->Layout.X, page->Layout.Y, page->HText);
1260 static void uipagebottomcb(topaddress, htext, htextobject, parameter)
1263 HTextObject_t *htextobject;
1266 uiPage_t *page = uiPageInfo.CurrentPage;
1268 page->Layout.Y = page->Layout.VirtualHeight - page->Layout.Height;
1270 uipageupdatescrollbars(page);
1271 XlMoveWindow(page->Layout.X, page->Layout.Y, page->HText);