screen.c revision c9e2be55
1c9e2be55Smrg/* 2c9e2be55Smrg * $XConsortium: screen.c,v 2.65 95/01/06 16:39:19 swick Exp $ 3c9e2be55Smrg * 4c9e2be55Smrg * 5c9e2be55Smrg * COPYRIGHT 1987, 1989 6c9e2be55Smrg * DIGITAL EQUIPMENT CORPORATION 7c9e2be55Smrg * MAYNARD, MASSACHUSETTS 8c9e2be55Smrg * ALL RIGHTS RESERVED. 9c9e2be55Smrg * 10c9e2be55Smrg * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND 11c9e2be55Smrg * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION. 12c9e2be55Smrg * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR 13c9e2be55Smrg * ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED WARRANTY. 14c9e2be55Smrg * 15c9e2be55Smrg * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT 16c9e2be55Smrg * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN 17c9e2be55Smrg * ADDITION TO THAT SET FORTH ABOVE. 18c9e2be55Smrg * 19c9e2be55Smrg * Permission to use, copy, modify, and distribute this software and its 20c9e2be55Smrg * documentation for any purpose and without fee is hereby granted, provided 21c9e2be55Smrg * that the above copyright notice appear in all copies and that both that 22c9e2be55Smrg * copyright notice and this permission notice appear in supporting 23c9e2be55Smrg * documentation, and that the name of Digital Equipment Corporation not be 24c9e2be55Smrg * used in advertising or publicity pertaining to distribution of the software 25c9e2be55Smrg * without specific, written prior permission. 26c9e2be55Smrg */ 27c9e2be55Smrg/* $XFree86: xc/programs/xmh/screen.c,v 1.2 2001/10/28 03:34:39 tsi Exp $ */ 28c9e2be55Smrg 29c9e2be55Smrg/* scrn.c -- management of scrns. */ 30c9e2be55Smrg 31c9e2be55Smrg#include "xmh.h" 32c9e2be55Smrg 33c9e2be55SmrgXmhMenuEntryRec folderMenu[] = { 34c9e2be55Smrg {"open", DoOpenFolder}, 35c9e2be55Smrg {"openInNew", DoOpenFolderInNewWindow}, 36c9e2be55Smrg {"create", DoCreateFolder}, 37c9e2be55Smrg {"delete", DoDeleteFolder}, 38c9e2be55Smrg {"line", (XtCallbackProc) NULL}, 39c9e2be55Smrg {"close", DoClose}, 40c9e2be55Smrg}; 41c9e2be55Smrg 42c9e2be55SmrgXmhMenuEntryRec tocMenu[] = { 43c9e2be55Smrg {"inc", DoIncorporateNewMail}, 44c9e2be55Smrg {"commit", DoCommit}, 45c9e2be55Smrg {"pack", DoPack}, 46c9e2be55Smrg {"sort", DoSort}, 47c9e2be55Smrg {"rescan", DoForceRescan}, 48c9e2be55Smrg}; 49c9e2be55Smrg 50c9e2be55SmrgXmhMenuEntryRec messageMenu[] = { 51c9e2be55Smrg {"compose", DoComposeMessage}, 52c9e2be55Smrg {"next", DoNextView}, 53c9e2be55Smrg {"prev", DoPrevView}, 54c9e2be55Smrg {"delete", DoDelete}, 55c9e2be55Smrg {"move", DoMove}, 56c9e2be55Smrg {"copy", DoCopy}, 57c9e2be55Smrg {"unmark", DoUnmark}, 58c9e2be55Smrg {"viewNew", DoViewNew}, 59c9e2be55Smrg {"reply", DoReply}, 60c9e2be55Smrg {"forward", DoForward}, 61c9e2be55Smrg {"useAsComp", DoTocUseAsComp}, 62c9e2be55Smrg {"print", DoPrint}, 63c9e2be55Smrg}; 64c9e2be55Smrg 65c9e2be55SmrgXmhMenuEntryRec sequenceMenu[] = { 66c9e2be55Smrg {"pick", DoPickMessages}, 67c9e2be55Smrg {"openSeq", DoOpenSeq}, 68c9e2be55Smrg {"addToSeq", DoAddToSeq}, 69c9e2be55Smrg {"removeFromSeq", DoRemoveFromSeq}, 70c9e2be55Smrg {"deleteSeq", DoDeleteSeq}, 71c9e2be55Smrg {"line", (XtCallbackProc) NULL}, 72c9e2be55Smrg {"all", DoSelectSequence}, 73c9e2be55Smrg}; 74c9e2be55Smrg 75c9e2be55SmrgXmhMenuEntryRec viewMenu[] = { 76c9e2be55Smrg {"reply", DoViewReply}, 77c9e2be55Smrg {"forward", DoViewForward}, 78c9e2be55Smrg {"useAsComp", DoViewUseAsComposition}, 79c9e2be55Smrg {"edit", DoEditView}, 80c9e2be55Smrg {"save", DoSaveView}, 81c9e2be55Smrg {"print", DoPrintView}, 82c9e2be55Smrg}; 83c9e2be55Smrg 84c9e2be55SmrgXmhMenuEntryRec optionMenu[] = { 85c9e2be55Smrg {"reverse", DoReverseReadOrder}, 86c9e2be55Smrg}; 87c9e2be55Smrg 88c9e2be55SmrgXmhMenuButtonDescRec MenuBoxButtons[] = { 89c9e2be55Smrg {"folderButton", "folderMenu", XMH_FOLDER, folderMenu, 90c9e2be55Smrg XtNumber(folderMenu) }, 91c9e2be55Smrg {"tocButton", "tocMenu", XMH_TOC, tocMenu, 92c9e2be55Smrg XtNumber(tocMenu) }, 93c9e2be55Smrg {"messageButton", "messageMenu", XMH_MESSAGE, messageMenu, 94c9e2be55Smrg XtNumber(messageMenu) }, 95c9e2be55Smrg {"sequenceButton", "sequenceMenu", XMH_SEQUENCE, sequenceMenu, 96c9e2be55Smrg XtNumber(sequenceMenu) }, 97c9e2be55Smrg {"viewButton", "viewMenu", XMH_VIEW, viewMenu, 98c9e2be55Smrg XtNumber(viewMenu) }, 99c9e2be55Smrg {"optionButton", "optionMenu", XMH_OPTION, optionMenu, 100c9e2be55Smrg XtNumber(optionMenu) }, 101c9e2be55Smrg}; 102c9e2be55Smrg 103c9e2be55Smrg 104c9e2be55Smrg/* Fill in the buttons for the view commands. */ 105c9e2be55Smrg 106c9e2be55Smrgstatic void FillViewButtons( 107c9e2be55SmrgScrn scrn) 108c9e2be55Smrg{ 109c9e2be55Smrg ButtonBox buttonbox = scrn->viewbuttons; 110c9e2be55Smrg BBoxAddButton(buttonbox, "close", commandWidgetClass, True); 111c9e2be55Smrg BBoxAddButton(buttonbox, "reply", commandWidgetClass, True); 112c9e2be55Smrg BBoxAddButton(buttonbox, "forward", commandWidgetClass, True); 113c9e2be55Smrg BBoxAddButton(buttonbox, "useAsComp", commandWidgetClass, True); 114c9e2be55Smrg BBoxAddButton(buttonbox, "edit", commandWidgetClass, True); 115c9e2be55Smrg BBoxAddButton(buttonbox, "save", commandWidgetClass, False); 116c9e2be55Smrg BBoxAddButton(buttonbox, "print", commandWidgetClass, True); 117c9e2be55Smrg BBoxAddButton(buttonbox, "delete", commandWidgetClass, True); 118c9e2be55Smrg} 119c9e2be55Smrg 120c9e2be55Smrg 121c9e2be55Smrg 122c9e2be55Smrgstatic void FillCompButtons( 123c9e2be55SmrgScrn scrn) 124c9e2be55Smrg{ 125c9e2be55Smrg ButtonBox buttonbox = scrn->viewbuttons; 126c9e2be55Smrg BBoxAddButton(buttonbox, "close", commandWidgetClass, True); 127c9e2be55Smrg BBoxAddButton(buttonbox, "send", commandWidgetClass, True); 128c9e2be55Smrg BBoxAddButton(buttonbox, "reset", commandWidgetClass, True); 129c9e2be55Smrg BBoxAddButton(buttonbox, "compose", commandWidgetClass, True); 130c9e2be55Smrg BBoxAddButton(buttonbox, "save", commandWidgetClass, True); 131c9e2be55Smrg BBoxAddButton(buttonbox, "insert", commandWidgetClass, True); 132c9e2be55Smrg} 133c9e2be55Smrg 134c9e2be55Smrg 135c9e2be55Smrgstatic void MakeCommandMenu( 136c9e2be55Smrg Scrn scrn, 137c9e2be55Smrg XmhMenuButtonDesc mbd) 138c9e2be55Smrg{ 139c9e2be55Smrg register Cardinal i; 140c9e2be55Smrg Cardinal n; 141c9e2be55Smrg Widget menu; 142c9e2be55Smrg ButtonBox buttonbox = scrn->mainbuttons; 143c9e2be55Smrg XmhMenuEntry e; 144c9e2be55Smrg Boolean indent; 145c9e2be55Smrg WidgetClass widgetclass; 146c9e2be55Smrg Arg args[4]; 147c9e2be55Smrg static XtCallbackRec callbacks[] = { 148c9e2be55Smrg { (XtCallbackProc) NULL, (XtPointer) NULL}, 149c9e2be55Smrg { (XtCallbackProc) NULL, (XtPointer) NULL}, 150c9e2be55Smrg { (XtCallbackProc) NULL, (XtPointer) NULL}, 151c9e2be55Smrg }; 152c9e2be55Smrg 153c9e2be55Smrg /* Menus are created as childen of the Paned widget of the scrn in order 154c9e2be55Smrg * that they can be used both as pop-up and as pull-down menus. 155c9e2be55Smrg */ 156c9e2be55Smrg 157c9e2be55Smrg n = 0; 158c9e2be55Smrg if (mbd->id == XMH_SEQUENCE) { 159c9e2be55Smrg XtSetArg(args[n], XtNallowShellResize, True); n++; 160c9e2be55Smrg } 161c9e2be55Smrg menu = XtCreatePopupShell(mbd->menu_name, simpleMenuWidgetClass, 162c9e2be55Smrg scrn->widget, args, n); 163c9e2be55Smrg 164c9e2be55Smrg indent = (mbd->id == XMH_SEQUENCE || mbd->id == XMH_OPTION) ? True : False; 165c9e2be55Smrg e = mbd->entry; 166c9e2be55Smrg for (i=0; i < mbd->num_entries; i++, e++) { 167c9e2be55Smrg n = 0; 168c9e2be55Smrg if (e->function) { 169c9e2be55Smrg callbacks[0].callback = e->function; 170c9e2be55Smrg callbacks[0].closure = (XtPointer) scrn; 171c9e2be55Smrg callbacks[1].callback = (app_resources.sticky_menu 172c9e2be55Smrg ? (XtCallbackProc) DoRememberMenuSelection 173c9e2be55Smrg : (XtCallbackProc) NULL); 174c9e2be55Smrg XtSetArg(args[n], XtNcallback, callbacks); n++; 175c9e2be55Smrg 176c9e2be55Smrg if (indent) { XtSetArg(args[n], XtNleftMargin, 18); n++; } 177c9e2be55Smrg widgetclass = smeBSBObjectClass; 178c9e2be55Smrg } else 179c9e2be55Smrg widgetclass = smeLineObjectClass; 180c9e2be55Smrg XtCreateManagedWidget(e->name, widgetclass, menu, args, n); 181c9e2be55Smrg } 182c9e2be55Smrg 183c9e2be55Smrg AttachMenuToButton( BBoxFindButtonNamed( buttonbox, mbd->button_name), 184c9e2be55Smrg menu, mbd->menu_name); 185c9e2be55Smrg if (mbd->id == XMH_OPTION && app_resources.reverse_read_order) 186c9e2be55Smrg ToggleMenuItem(XtNameToWidget(menu, "reverse"), True); 187c9e2be55Smrg} 188c9e2be55Smrg 189c9e2be55Smrg 190c9e2be55Smrg/* Create subwidgets for a toc&view window. */ 191c9e2be55Smrg 192c9e2be55Smrgstatic void MakeTocAndView(Scrn scrn) 193c9e2be55Smrg{ 194c9e2be55Smrg register int i; 195c9e2be55Smrg XmhMenuButtonDesc mbd; 196c9e2be55Smrg ButtonBox buttonbox; 197c9e2be55Smrg char *name; 198c9e2be55Smrg static XawTextSelectType sarray[] = {XawselectLine, 199c9e2be55Smrg XawselectPosition, 200c9e2be55Smrg XawselectAll, 201c9e2be55Smrg XawselectNull}; 202c9e2be55Smrg static Arg args[] = { 203c9e2be55Smrg { XtNselectTypes, (XtArgVal) sarray}, 204c9e2be55Smrg { XtNdisplayCaret, (XtArgVal) False} 205c9e2be55Smrg }; 206c9e2be55Smrg 207c9e2be55Smrg scrn->mainbuttons = BBoxCreate(scrn, "menuBox"); 208c9e2be55Smrg scrn->folderlabel = CreateTitleBar(scrn, "folderTitlebar"); 209c9e2be55Smrg scrn->folderbuttons = BBoxCreate(scrn, "folders"); 210c9e2be55Smrg scrn->toclabel = CreateTitleBar(scrn, "tocTitlebar"); 211c9e2be55Smrg scrn->tocwidget = CreateTextSW(scrn, "toc", args, XtNumber(args)); 212c9e2be55Smrg if (app_resources.command_button_count > 0) 213c9e2be55Smrg scrn->miscbuttons = BBoxCreate(scrn, "commandBox"); 214c9e2be55Smrg scrn->viewlabel = CreateTitleBar(scrn, "viewTitlebar"); 215c9e2be55Smrg scrn->viewwidget = CreateTextSW(scrn, "view", args, (Cardinal) 0); 216c9e2be55Smrg 217c9e2be55Smrg /* the command buttons and menus */ 218c9e2be55Smrg 219c9e2be55Smrg buttonbox = scrn->mainbuttons; 220c9e2be55Smrg mbd = MenuBoxButtons; 221c9e2be55Smrg for (i=0; i < XtNumber(MenuBoxButtons); i++, mbd++) { 222c9e2be55Smrg name = mbd->button_name; 223c9e2be55Smrg BBoxAddButton(buttonbox, name, menuButtonWidgetClass, True); 224c9e2be55Smrg MakeCommandMenu(scrn, mbd); 225c9e2be55Smrg } 226c9e2be55Smrg 227c9e2be55Smrg /* the folder buttons; folder menus are created on demand. */ 228c9e2be55Smrg 229c9e2be55Smrg buttonbox = scrn->folderbuttons; 230c9e2be55Smrg for (i=0 ; i<numFolders ; i++) { 231c9e2be55Smrg name = TocName(folderList[i]); 232c9e2be55Smrg if (! IsSubfolder(name)) 233c9e2be55Smrg BBoxAddButton(buttonbox, name, menuButtonWidgetClass, True); 234c9e2be55Smrg if (app_resources.new_mail_check && 235c9e2be55Smrg numScrns > 1 && 236c9e2be55Smrg TocCanIncorporate(folderList[i])) 237c9e2be55Smrg BBoxMailFlag(buttonbox, name, TocHasMail(folderList[i])); 238c9e2be55Smrg } 239c9e2be55Smrg 240c9e2be55Smrg /* the optional miscellaneous command buttons */ 241c9e2be55Smrg 242c9e2be55Smrg if (app_resources.command_button_count > 0) { 243c9e2be55Smrg char name[12]; 244c9e2be55Smrg if (app_resources.command_button_count > 500) 245c9e2be55Smrg app_resources.command_button_count = 500; 246c9e2be55Smrg for (i=1; i <= app_resources.command_button_count; i++) { 247c9e2be55Smrg sprintf(name, "button%d", i); 248c9e2be55Smrg BBoxAddButton(scrn->miscbuttons, name, commandWidgetClass, True); 249c9e2be55Smrg } 250c9e2be55Smrg } 251c9e2be55Smrg} 252c9e2be55Smrg 253c9e2be55Smrgstatic void MakeView(Scrn scrn) 254c9e2be55Smrg{ 255c9e2be55Smrg scrn->viewlabel = CreateTitleBar(scrn, "viewTitlebar"); 256c9e2be55Smrg scrn->viewwidget = CreateTextSW(scrn, "view", (ArgList)NULL, (Cardinal)0); 257c9e2be55Smrg scrn->viewbuttons = BBoxCreate(scrn, "viewButtons"); 258c9e2be55Smrg FillViewButtons(scrn); 259c9e2be55Smrg} 260c9e2be55Smrg 261c9e2be55Smrg 262c9e2be55Smrgstatic void MakeComp(Scrn scrn) 263c9e2be55Smrg{ 264c9e2be55Smrg scrn->viewlabel = CreateTitleBar(scrn, "composeTitlebar"); 265c9e2be55Smrg scrn->viewwidget = CreateTextSW(scrn, "comp", (ArgList)NULL, (Cardinal)0); 266c9e2be55Smrg scrn->viewbuttons = BBoxCreate(scrn, "compButtons"); 267c9e2be55Smrg FillCompButtons(scrn); 268c9e2be55Smrg} 269c9e2be55Smrg 270c9e2be55Smrg 271c9e2be55Smrg/* Create a scrn of the given type. */ 272c9e2be55Smrg 273c9e2be55SmrgScrn CreateNewScrn(ScrnKind kind) 274c9e2be55Smrg{ 275c9e2be55Smrg int i; 276c9e2be55Smrg Scrn scrn; 277c9e2be55Smrg static Arg arglist[] = { 278c9e2be55Smrg { XtNgeometry, (XtArgVal) NULL}, 279c9e2be55Smrg { XtNinput, (XtArgVal) True} 280c9e2be55Smrg }; 281c9e2be55Smrg 282c9e2be55Smrg for (i=0 ; i<numScrns ; i++) 283c9e2be55Smrg if (scrnList[i]->kind == kind && !scrnList[i]->mapped) 284c9e2be55Smrg return scrnList[i]; 285c9e2be55Smrg switch (kind) { 286c9e2be55Smrg case STtocAndView: arglist[0].value = 287c9e2be55Smrg (XtArgVal)app_resources.toc_geometry; break; 288c9e2be55Smrg case STview: arglist[0].value = 289c9e2be55Smrg (XtArgVal)app_resources.view_geometry; break; 290c9e2be55Smrg case STcomp: arglist[0].value = 291c9e2be55Smrg (XtArgVal)app_resources.comp_geometry; break; 292c9e2be55Smrg case STpick: arglist[0].value = 293c9e2be55Smrg (XtArgVal)app_resources.pick_geometry; break; 294c9e2be55Smrg } 295c9e2be55Smrg 296c9e2be55Smrg numScrns++; 297c9e2be55Smrg scrnList = (Scrn *) 298c9e2be55Smrg XtRealloc((char *) scrnList, (unsigned) numScrns*sizeof(Scrn)); 299c9e2be55Smrg scrn = scrnList[numScrns - 1] = XtNew(ScrnRec); 300c9e2be55Smrg bzero((char *)scrn, sizeof(ScrnRec)); 301c9e2be55Smrg scrn->kind = kind; 302c9e2be55Smrg if (numScrns == 1) scrn->parent = toplevel; 303c9e2be55Smrg else scrn->parent = XtCreatePopupShell( 304c9e2be55Smrg progName, topLevelShellWidgetClass, 305c9e2be55Smrg toplevel, arglist, XtNumber(arglist)); 306c9e2be55Smrg XtAugmentTranslations(scrn->parent, 307c9e2be55Smrg app_resources.wm_protocols_translations); 308c9e2be55Smrg scrn->widget = 309c9e2be55Smrg XtCreateManagedWidget(progName, panedWidgetClass, scrn->parent, 310c9e2be55Smrg (ArgList) NULL, (Cardinal) 0); 311c9e2be55Smrg 312c9e2be55Smrg switch (kind) { 313c9e2be55Smrg case STtocAndView: MakeTocAndView(scrn); break; 314c9e2be55Smrg case STview: MakeView(scrn); break; 315c9e2be55Smrg case STcomp: MakeComp(scrn); break; 316c9e2be55Smrg default: break; 317c9e2be55Smrg } 318c9e2be55Smrg 319c9e2be55Smrg if (kind != STpick) { 320c9e2be55Smrg int theight, min, max; 321c9e2be55Smrg Arg args[1]; 322c9e2be55Smrg 323c9e2be55Smrg DEBUG("Realizing...") 324c9e2be55Smrg XtRealizeWidget(scrn->parent); 325c9e2be55Smrg DEBUG(" done.\n") 326c9e2be55Smrg 327c9e2be55Smrg switch (kind) { 328c9e2be55Smrg case STtocAndView: 329c9e2be55Smrg BBoxLockSize(scrn->mainbuttons); 330c9e2be55Smrg BBoxLockSize(scrn->folderbuttons); 331c9e2be55Smrg theight = GetHeight(scrn->tocwidget) + GetHeight(scrn->viewwidget); 332c9e2be55Smrg theight = app_resources.toc_percentage * theight / 100; 333c9e2be55Smrg XawPanedGetMinMax((Widget) scrn->tocwidget, &min, &max); 334c9e2be55Smrg XawPanedSetMinMax((Widget) scrn->tocwidget, theight, theight); 335c9e2be55Smrg XawPanedSetMinMax((Widget) scrn->tocwidget, min, max); 336c9e2be55Smrg if (scrn->miscbuttons) 337c9e2be55Smrg BBoxLockSize(scrn->miscbuttons); 338c9e2be55Smrg 339c9e2be55Smrg /* fall through */ 340c9e2be55Smrg 341c9e2be55Smrg case STview: 342c9e2be55Smrg 343c9e2be55Smrg /* Install accelerators; not active while editing in the view */ 344c9e2be55Smrg 345c9e2be55Smrg XtSetArg(args[0], XtNtranslations, &(scrn->edit_translations)); 346c9e2be55Smrg XtGetValues(scrn->viewwidget, args, (Cardinal) 1); 347c9e2be55Smrg XtInstallAllAccelerators(scrn->widget, scrn->widget); 348c9e2be55Smrg if (kind == STtocAndView) 349c9e2be55Smrg XtInstallAllAccelerators(scrn->tocwidget, scrn->widget); 350c9e2be55Smrg XtInstallAllAccelerators(scrn->viewwidget, scrn->widget); 351c9e2be55Smrg XtSetArg(args[0], XtNtranslations, &(scrn->read_translations)); 352c9e2be55Smrg XtGetValues(scrn->viewwidget, args, (Cardinal) 1); 353c9e2be55Smrg 354c9e2be55Smrg if (kind == STview) 355c9e2be55Smrg BBoxLockSize(scrn->viewbuttons); 356c9e2be55Smrg break; 357c9e2be55Smrg 358c9e2be55Smrg case STcomp: 359c9e2be55Smrg BBoxLockSize(scrn->viewbuttons); 360c9e2be55Smrg XtInstallAllAccelerators(scrn->viewwidget, scrn->widget); 361c9e2be55Smrg XtSetKeyboardFocus(scrn->parent, scrn->viewwidget); 362c9e2be55Smrg break; 363c9e2be55Smrg 364c9e2be55Smrg default: 365c9e2be55Smrg break; 366c9e2be55Smrg } 367c9e2be55Smrg 368c9e2be55Smrg InitBusyCursor(scrn); 369c9e2be55Smrg XDefineCursor(XtDisplay(scrn->parent), XtWindow(scrn->parent), 370c9e2be55Smrg app_resources.cursor); 371c9e2be55Smrg (void) XSetWMProtocols(XtDisplay(scrn->parent), XtWindow(scrn->parent), 372c9e2be55Smrg protocolList, XtNumber(protocolList)); 373c9e2be55Smrg } 374c9e2be55Smrg scrn->mapped = False; 375c9e2be55Smrg return scrn; 376c9e2be55Smrg} 377c9e2be55Smrg 378c9e2be55Smrg 379c9e2be55SmrgScrn NewViewScrn(void) 380c9e2be55Smrg{ 381c9e2be55Smrg return CreateNewScrn(STview); 382c9e2be55Smrg} 383c9e2be55Smrg 384c9e2be55SmrgScrn NewCompScrn(void) 385c9e2be55Smrg{ 386c9e2be55Smrg Scrn scrn; 387c9e2be55Smrg scrn = CreateNewScrn(STcomp); 388c9e2be55Smrg scrn->assocmsg = (Msg)NULL; 389c9e2be55Smrg return scrn; 390c9e2be55Smrg} 391c9e2be55Smrg 392c9e2be55Smrgvoid ScreenSetAssocMsg(Scrn scrn, Msg msg) 393c9e2be55Smrg{ 394c9e2be55Smrg scrn->assocmsg = msg; 395c9e2be55Smrg} 396c9e2be55Smrg 397c9e2be55Smrg/* Destroy the screen. If unsaved changes are in a msg, too bad. */ 398c9e2be55Smrg 399c9e2be55Smrgvoid DestroyScrn(Scrn scrn) 400c9e2be55Smrg{ 401c9e2be55Smrg if (scrn->mapped) { 402c9e2be55Smrg scrn->mapped = False; 403c9e2be55Smrg XtPopdown(scrn->parent); 404c9e2be55Smrg TocSetScrn((Toc) NULL, scrn); 405c9e2be55Smrg MsgSetScrnForce((Msg) NULL, scrn); 406c9e2be55Smrg lastInput.win = -1; 407c9e2be55Smrg } 408c9e2be55Smrg} 409c9e2be55Smrg 410c9e2be55Smrg 411c9e2be55Smrgvoid MapScrn(Scrn scrn) 412c9e2be55Smrg{ 413c9e2be55Smrg if (!scrn->mapped) { 414c9e2be55Smrg XtPopup(scrn->parent, XtGrabNone); 415c9e2be55Smrg scrn->mapped = True; 416c9e2be55Smrg } 417c9e2be55Smrg} 418c9e2be55Smrg 419c9e2be55Smrg 420c9e2be55SmrgScrn ScrnFromWidget(Widget w) /* heavily used, should be efficient */ 421c9e2be55Smrg{ 422c9e2be55Smrg register int i; 423c9e2be55Smrg while (w && ! XtIsTopLevelShell(w)) 424c9e2be55Smrg w = XtParent(w); 425c9e2be55Smrg if (w) { 426c9e2be55Smrg for (i=0 ; i<numScrns ; i++) { 427c9e2be55Smrg if (w == (Widget) scrnList[i]->parent) 428c9e2be55Smrg return scrnList[i]; 429c9e2be55Smrg } 430c9e2be55Smrg } 431c9e2be55Smrg Punt("ScrnFromWidget failed!"); 432c9e2be55Smrg return NULL; 433c9e2be55Smrg} 434c9e2be55Smrg 435c9e2be55Smrg 436c9e2be55Smrg/* Figure out which buttons should and shouldn't be enabled in the given 437c9e2be55Smrg * screen. This should be called whenever something major happens to the 438c9e2be55Smrg * screen. 439c9e2be55Smrg */ 440c9e2be55Smrg 441c9e2be55Smrg 442c9e2be55Smrg/*ARGSUSED*/ 443c9e2be55Smrgstatic void EnableCallback(Widget w, XtPointer data, XtPointer junk) 444c9e2be55Smrg{ 445c9e2be55Smrg EnableProperButtons( (Scrn) data); 446c9e2be55Smrg} 447c9e2be55Smrg 448c9e2be55Smrg#define SetButton(buttonbox, name, value) \ 449c9e2be55Smrg if (value) BBoxEnable(BBoxFindButtonNamed(buttonbox, name)); \ 450c9e2be55Smrg else BBoxDisable(BBoxFindButtonNamed(buttonbox, name)); 451c9e2be55Smrg 452c9e2be55Smrg 453c9e2be55Smrgvoid EnableProperButtons(Scrn scrn) 454c9e2be55Smrg{ 455c9e2be55Smrg int value, changed, reapable; 456c9e2be55Smrg Button button; 457c9e2be55Smrg 458c9e2be55Smrg if (scrn) { 459c9e2be55Smrg switch (scrn->kind) { 460c9e2be55Smrg case STtocAndView: 461c9e2be55Smrg button = BBoxFindButtonNamed 462c9e2be55Smrg (scrn->mainbuttons, MenuBoxButtons[XMH_TOC].button_name); 463c9e2be55Smrg value = TocCanIncorporate(scrn->toc); 464c9e2be55Smrg SendMenuEntryEnableMsg(button, "inc", value); 465c9e2be55Smrg 466c9e2be55Smrg button = BBoxFindButtonNamed 467c9e2be55Smrg (scrn->mainbuttons, MenuBoxButtons[XMH_SEQUENCE].button_name); 468c9e2be55Smrg value = TocHasSequences(scrn->toc); 469c9e2be55Smrg SendMenuEntryEnableMsg(button, "openSeq", value); 470c9e2be55Smrg SendMenuEntryEnableMsg(button, "addToSeq", value); 471c9e2be55Smrg SendMenuEntryEnableMsg(button, "removeFromSeq", value); 472c9e2be55Smrg SendMenuEntryEnableMsg(button, "deleteSeq", value); 473c9e2be55Smrg 474c9e2be55Smrg button = BBoxFindButtonNamed 475c9e2be55Smrg (scrn->mainbuttons, MenuBoxButtons[XMH_VIEW].button_name); 476c9e2be55Smrg value = (scrn->msg != NULL && !MsgGetEditable(scrn->msg)); 477c9e2be55Smrg SendMenuEntryEnableMsg(button, "edit", value); 478c9e2be55Smrg SendMenuEntryEnableMsg(button, "save", 479c9e2be55Smrg scrn->msg != NULL && !value); 480c9e2be55Smrg break; 481c9e2be55Smrg case STview: 482c9e2be55Smrg value = (scrn->msg != NULL && !MsgGetEditable(scrn->msg)); 483c9e2be55Smrg SetButton(scrn->viewbuttons, "edit", value); 484c9e2be55Smrg SetButton(scrn->viewbuttons, "save", scrn->msg != NULL && !value); 485c9e2be55Smrg break; 486c9e2be55Smrg case STcomp: 487c9e2be55Smrg if (scrn->msg != NULL) { 488c9e2be55Smrg changed = MsgChanged(scrn->msg); 489c9e2be55Smrg reapable = MsgGetReapable(scrn->msg); 490c9e2be55Smrg SetButton(scrn->viewbuttons, "send", changed || !reapable); 491c9e2be55Smrg SetButton(scrn->viewbuttons, "save", changed || reapable); 492c9e2be55Smrg SetButton(scrn->viewbuttons, "insert", 493c9e2be55Smrg scrn->assocmsg != NULL ? True : False); 494c9e2be55Smrg 495c9e2be55Smrg if (!changed) 496c9e2be55Smrg MsgSetCallOnChange(scrn->msg, EnableCallback, 497c9e2be55Smrg (XtPointer) scrn); 498c9e2be55Smrg else 499c9e2be55Smrg MsgSetCallOnChange(scrn->msg, (XtCallbackProc) NULL, 500c9e2be55Smrg (XtPointer) NULL); 501c9e2be55Smrg 502c9e2be55Smrg } else { 503c9e2be55Smrg BBoxDisable( BBoxFindButtonNamed(scrn->viewbuttons, "send")); 504c9e2be55Smrg BBoxDisable( BBoxFindButtonNamed(scrn->viewbuttons, "save")); 505c9e2be55Smrg BBoxDisable( BBoxFindButtonNamed(scrn->viewbuttons, "insert")); 506c9e2be55Smrg } 507c9e2be55Smrg break; 508c9e2be55Smrg default: 509c9e2be55Smrg break; 510c9e2be55Smrg } 511c9e2be55Smrg } 512c9e2be55Smrg} 513