2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $TOG: WindowSystemMotif.C /main/35 1998/04/20 12:54:36 mgreess $ */
25 * (c) Copyright 1996 Digital Equipment Corporation.
26 * (c) Copyright 1996 Hewlett-Packard Company.
27 * (c) Copyright 1996 International Business Machines Corp.
28 * (c) Copyright 1996 Sun Microsystems, Inc.
29 * (c) Copyright 1996 Novell, Inc.
30 * (c) Copyright 1994, 1995, 1996 FUJITSU LIMITED.
31 * (c) Copyright 1996 Hitachi.
34 * Copyright (c) 1991 HaL Computer Systems, Inc. All rights reserved.
35 * UNPUBLISHED -- rights reserved under the Copyright Laws of the United
36 * States. Use of a copyright notice is precautionary only and does not
37 * imply publication or disclosure.
39 * This software contains confidential information and trade secrets of HaL
40 * Computer Systems, Inc. Use, disclosure, or reproduction is prohibited
41 * without the prior express written permission of HaL Computer Systems, Inc.
43 * RESTRICTED RIGHTS LEGEND
44 * Use, duplication, or disclosure by the Government is subject to
45 * restrictions as set forth in subparagraph (c)(l)(ii) of the Rights in
46 * Technical Data and Computer Software clause at DFARS 252.227-7013.
47 * HaL Computer Systems, Inc.
48 * 1315 Dell Avenue, Campbell, CA 95008
52 #include <X11/Xmu/Editres.h>
55 #include <Xm/Protocols.h>
61 #include <Dt/EnvControlP.h>
72 extern "C" void _DtSimpleError(
80 extern "C" int _DtPrintDefaultErrorSafe(
88 #include <X11/IntrinsicP.h>
89 #include <X11/CoreP.h>
90 #include <X11/StringDefs.h>
91 #endif /* XmVersion < 1002 */
93 #include <X11/Xmu/Converters.h>
96 #include <Xm/RepType.h>
97 #include <Xm/AtomMgr.h>
98 #endif /* XmVersion >= 1002 */
100 #define C_TOC_Element
103 #define C_WindowGeometryPref
104 #define L_Preferences
110 #define C_WindowSystem
120 #define USES_OLIAS_FONT
124 #include "Other/XmStringLocalized.hh"
125 #include "Managers/CatMgr.hh"
127 #include "Registration.hh"
129 #include <WWL/WApplicationShell.h>
130 #include <WWL/WXmMessageBox.h>
131 #include <WWL/WXmPushButton.h>
133 // These guys are backups for when there is not enough
134 // colors to display the standard ones
136 #include "graphic_unavailable.xbm"
137 #include "detached_bw.xbm"
139 #include "graphic_unavailable.xpm"
140 #include "detached_bw.xpm"
143 // four bitmap images for user marks
145 #define mark_single_width 13
146 #define mark_single_height 13
147 static unsigned char mark_single_bits[] = {
148 0x00, 0x00, 0xfe, 0x01, 0x82, 0x02, 0x82, 0x04, 0x82, 0x08, 0x82, 0x0f,
149 0x02, 0x08, 0x02, 0x08, 0x02, 0x08, 0x02, 0x08, 0x02, 0x08, 0xfe, 0x0f,
152 #define mark_double_width 15
153 #define mark_double_height 15
154 static unsigned char mark_double_bits[] = {
155 0x00, 0x00, 0xf8, 0x07, 0x08, 0x0a, 0x0e, 0x12, 0x0a, 0x22, 0x0a, 0x3e,
156 0x0a, 0x20, 0x0a, 0x20, 0x0a, 0x20, 0x0a, 0x20, 0x0a, 0x20, 0xfa, 0x3f,
157 0x02, 0x08, 0xfe, 0x0f, 0x00, 0x00};
159 #define anno_single_width 13
160 #define anno_single_height 13
161 static unsigned char anno_single_bits[] = {
162 0x00, 0x00, 0xfe, 0x01, 0x82, 0x02, 0xba, 0x04, 0x82, 0x08, 0xba, 0x0f,
163 0x02, 0x08, 0xfa, 0x0b, 0x02, 0x08, 0xfa, 0x0b, 0x02, 0x08, 0xfe, 0x0f,
166 #define anno_double_width 15
167 #define anno_double_height 15
168 static unsigned char anno_double_bits[] = {
169 0x00, 0x00, 0xf8, 0x07, 0x08, 0x0a, 0xee, 0x12, 0x0a, 0x22, 0xea, 0x3e,
170 0x0a, 0x20, 0xea, 0x2f, 0x0a, 0x20, 0xea, 0x2f, 0x0a, 0x20, 0xfa, 0x3f,
171 0x02, 0x08, 0xfe, 0x0f, 0x00, 0x00};
176 #include <sys/signal.h>
180 typedef void (*SIG_PF)();
186 #include <DtI/ActionsI.h>
188 // virtual root finder
193 extern Boolean print_server_error;
195 static String fallbacks[] = {
196 "Dtinfo.Print*background:white",
197 "Dtinfo.Print*renderTable:-dt-application-bold-r-normal-serif-0-0-0-0-p-0-iso8859-1",
198 "Dtinfo.Print*shadowThickness:0",
199 "Dtinfo.Print*highlightThickness:0",
200 "Dtinfo.Print*pform.marginHeight: 1in",
201 "Dtinfo.Print*pform.marginWidth: 1in",
202 "Dtinfo.Print*ptext.Attachment:attach_form",
207 static XtActionsRec DrawnBActions[] =
209 {"DeSelectAll" , _DtHelpDeSelectAll },
210 {"SelectAll" , _DtHelpSelectAll },
211 {"ActivateLink" , _DtHelpActivateLink },
212 {"CopyToClipboard", _DtHelpCopyAction },
213 {"PageUpOrDown" , _DtHelpPageUpOrDown },
214 {"PageLeftOrRight", _DtHelpPageLeftOrRight},
215 {"NextLink" , _DtHelpNextLink }
220 WindowSystem *WindowSystem::f_window_system;
221 static Atom XA_WM_STATE;
225 Shell_Info (Widget w)
233 XSizeHints *f_size_hints;
234 bool f_has_size_hints : 1;
237 bool f_has_wm_state : 1;
241 // /////////////////////////////////////////////////////////////////
243 // /////////////////////////////////////////////////////////////////
245 WindowSystem::WindowSystem (int &argc, char *argv[])
247 f_default_pixmap (NULL),
251 f_detached_pixmap(NULL),
252 f_cursor_stack_pos(-1),
254 f_dtinfo_space_font(NULL)
258 f_window_system = this;
261 f_modal_cursor = create_cursor ("xm_noenter16");
262 f_wait_cursor = create_cursor ("xm_hour16");
263 f_bomb_cursor = create_cursor ("bomb");
265 /* -------- Debugging setup. Should be a function. -------- */
267 bool debugging = get_boolean_app_resource("debug");
270 signal (SIGABRT, /*DWC IBM (SIG_PF)*/ core_dump_handler);
271 signal (SIGBUS, /*(SIG_PF)*/ core_dump_handler);
272 signal (SIGSEGV, /*(SIG_PF)*/ core_dump_handler);
273 signal (SIGINT, interrupt_handler);
276 /* Reference the scale widget so Veritas Replay Xt lib can link. */
277 WidgetClass xxx = xmScaleWidgetClass;
280 char **names = XListFonts(window_system().display(),
281 "-dt-dtinfo-*-14-*-dtinfo-?", 1, &count);
285 f_dtinfo_font = XmFontListEntryLoad(f_display, *names,
286 XmFONT_IS_FONT, "olias");
287 f_dtinfo_space_font = XmFontListEntryLoad(f_display, *names,
288 XmFONT_IS_FONT, "ospace");
289 XFreeFontNames(names);
293 // /////////////////////////////////////////////////////////////////////////
295 // /////////////////////////////////////////////////////////////////////////
297 WindowSystem::~WindowSystem()
299 signal (SIGABRT, SIG_DFL);
300 signal (SIGBUS, SIG_DFL);
301 signal (SIGSEGV, SIG_DFL);
305 WindowSystem::dtinfo_font()
307 return f_dtinfo_font;
311 WindowSystem::dtinfo_space_font()
313 return f_dtinfo_space_font;
317 WindowSystem::toplevel()
320 return (f_print_toplevel);
328 WindowSystem::printToplevel()
330 return (f_print_toplevel);
334 WindowSystem::onlineToplevel()
340 WindowSystem::display()
343 return (f_print_display);
351 WindowSystem::screen()
354 return (f_print_screen);
362 WindowSystem::onlineDisplay()
368 WindowSystem::printDisplay()
370 return (f_print_display);
374 WindowSystem::printing()
380 WindowSystem::setPrintDisplay(Widget widget)
382 f_print_toplevel = widget;
383 f_print_display = XtDisplay(widget);
384 f_print_screen = XtScreen(widget);
388 WindowSystem::setPrinting(Boolean state)
394 WindowSystem::update_display()
396 XmUpdateDisplay (f_toplevel);
400 // /////////////////////////////////////////////////////////////////
402 // /////////////////////////////////////////////////////////////////
405 extern "C" { void tml_dp_set_font_display(Display *); }
408 // command line options
410 // include "dbg" so we can use the startup script -debug flag independently
411 XrmOptionDescRec options[] = {
412 {"-debug", "*debug", XrmoptionNoArg, "True"},
413 {"-dbg", "*debug", XrmoptionNoArg, "True"},
414 {"-author", "*author", XrmoptionNoArg, "True"},
415 {"-readonly", "*readonly", XrmoptionNoArg, "True"},
416 {"-ro", "*readonly", XrmoptionNoArg, "True"},
417 {"-autohelp", "*AutomaticHelp", XrmoptionNoArg, "On"},
418 {"-nofonts", "*NoFonts", XrmoptionNoArg, "True"},
419 {"-print", "printOnly", XrmoptionNoArg, "True"},
420 {"-hierarchy", "hierarchy", XrmoptionNoArg, "True"},
421 {"-printer", "printer", XrmoptionSepArg, NULL},
422 {"-copies", "copies", XrmoptionSepArg, NULL},
423 {"-paperSize", "paperSize", XrmoptionSepArg, NULL},
424 {"-silent", "silent", XrmoptionNoArg, "True"},
425 {"-outputFile", "outputFile", XrmoptionSepArg, NULL}
428 static XtResource VideoResources[] =
430 {"printOnly", "PrintOnly", XmRBoolean, sizeof (Boolean),
431 XtOffsetOf (VideoShell, print_only), XmRImmediate, (XtPointer)False,
433 {"outputFile", "OutputFile", XmRString, sizeof (char *),
434 XtOffsetOf (VideoShell, file_name), XmRImmediate, (XtPointer)NULL,
436 {"hierarchy", "Hierarchy", XmRBoolean, sizeof (Boolean),
437 XtOffsetOf (VideoShell, hierarchy), XmRImmediate, (XtPointer)False,
439 {"printer", "Printer", XmRString, sizeof (char *),
440 XtOffsetOf (VideoShell, printer), XmRImmediate, (XtPointer)NULL,
442 {"copies", "Copies", XmRInt, sizeof (int),
443 XtOffsetOf (VideoShell, copies), XmRImmediate, (XtPointer)1,
445 {"paperSize", "PaperSize", XmRString, sizeof (char *),
446 XtOffsetOf (VideoShell, paper_size), XmRImmediate, (XtPointer)NULL,
448 {"silent", "Silent", XmRBoolean, sizeof (Boolean),
449 XtOffsetOf (VideoShell, silent), XmRImmediate, (XtPointer)False,
454 * static function declarations
456 VideoShell* VideoShell_new(Display* display);
460 * ------------------------------------------------------------------------
465 * Access function for f_video_shell containing application resources
466 * and command line options.
470 * A pointer to the VideoShell structure.
473 WindowSystem::videoShell()
475 return (f_video_shell);
479 * ------------------------------------------------------------------------
480 * Name: VideoShell_new
484 * Allocates a new VideoShell data structure.
486 * This function creates a top level application shell on the passed
491 * A pointer to the new VideoShell structure.
494 VideoShell_new(Display*, Widget app_shell)
496 VideoShell* me = (VideoShell*)XtCalloc(1, sizeof(VideoShell));
498 me->widget = app_shell;
500 XtGetApplicationResources(me->widget, me,
501 VideoResources, XtNumber(VideoResources),
504 // Modify the videoShell data based on environment variable settings
506 // if DTPRINTSILENT is set then turn silent printing on
508 if (getenv("DTPRINTSILENT") != NULL) {
516 xevent_error_aborter(Display *display, XErrorEvent* error_event)
518 #define _DTINFO_BUFSIZE 1024
519 char error_msg[_DTINFO_BUFSIZE];
523 _DtPrintDefaultErrorSafe(display, error_event, error_msg, _DTINFO_BUFSIZE);
524 _DtSimpleError("dtinfo", DtWarning, NULL, error_msg, NULL);
526 // if the error occured on the print display we're going to set
527 // a variable so that and when the job is done, right before calling
528 // XpEndJob, we call XpCancelJob, and notify the user.
530 if ( (display == window_system().printDisplay()) &&
531 (error_event->error_code == BadAlloc) ) {
532 print_server_error = True;
545 XtSetLanguageProc(NULL, (XtLanguageProc)NULL, NULL);
547 _DtEnvControl(DT_ENV_SET);
549 Widget app_shell = XtAppInitialize(&f_application_context, CLASS_NAME,
550 options, XtNumber(options),
551 f_argc, f_argv, fallbacks, NULL, 0);
552 f_display = XtDisplay(app_shell);
555 XSynchronize(f_display, True);
557 XSync(f_display, False);
558 XSetErrorHandler(xevent_error_aborter);
561 XtAppSetFallbackResources(f_application_context, fallbacks);
564 // exit if display cannot be opened. this code will need to be revised
565 // if we ever want to handle gui-less printing
567 if (f_display == (Display*)NULL)
569 fprintf(stderr, CATGETS(Set_WindowSystem, 3, "Unable to open display.\n"));
573 // Create the top level video shell
575 f_video_shell = VideoShell_new(f_display, app_shell);
577 // Create a new AppPrintData object here and initialize it since
578 // the $%^& doesn't seem to get called.
580 f_AppPrintData = new AppPrintData;
581 f_AppPrintData->f_print_data = (DtPrintSetupData*)XtCalloc(1, sizeof(DtPrintSetupData));
582 f_AppPrintData->f_pform = NULL ;
583 f_AppPrintData->f_print_dialog = NULL;
584 f_AppPrintData->f_print_shell = NULL;
585 f_AppPrintData->f_print_only = f_video_shell->print_only;
586 f_toplevel = f_video_shell->widget;
588 if (DtAppInitialize( f_application_context,
589 f_display, f_toplevel, f_argv[0], CLASS_NAME) == False)
591 /* DtAppInitialize() has already logged an appropriate error msg */
595 // Make sure this shell never appears.
596 XtSetMappedWhenManaged (f_toplevel, False);
598 XtAppAddActions (f_application_context, DrawnBActions, XtNumber (DrawnBActions));
600 // register_shell (f_toplevel)
602 f_display = XtDisplay(f_toplevel);
603 // NOTE: Check for failure DJB
605 tml_dp_set_font_display(f_display);
608 // Create atom used elsewhere by agents
609 f_wm_delete_window = XmInternAtom (f_display, "WM_DELETE_WINDOW", False);
610 XA_WM_STATE = XmInternAtom (f_display, "WM_STATE", False);
612 // -------- Add some converters -------- //
615 // This converter let's us specify form connections in resources
616 static XtConvertArgRec parentCvtArg[] = {
617 { XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.parent),
620 XtSetTypeConverter (XtRString, XtRWindow, XmuNewCvtStringToWidget,
621 parentCvtArg, XtNumber (parentCvtArg), XtCacheNone, NULL);
622 #endif /* XmVersion < 1002 */
624 XtAddConverter (XtRString, XtRGravity, XmuCvtStringToGravity, NULL, 0);
626 #if XmVersion >= 1002
627 XmRepTypeInstallTearOffModelConverter();
628 #endif /* XmVersion >= 1002 */
630 // NOTE: Really need to install a string to pixmap converter!
631 /* -------- Get some pixmaps. -------- */
633 f_screen = XtScreen(f_toplevel);
634 f_nofonts = get_boolean_default ("NoFonts");
636 f_locked_pixmap = NULL;
637 f_semilocked_pixmap = NULL;
638 f_unlocked_pixmap = NULL;
640 XImage *mark_single =
641 XCreateImage(f_display, DefaultVisualOfScreen(f_screen),
642 1, XYBitmap, 0, (char*)mark_single_bits,
643 mark_single_width, mark_single_height, 8, 0);
644 mark_single->byte_order = LSBFirst;
645 mark_single->bitmap_bit_order = LSBFirst;
646 mark_single->bitmap_unit = 8;
648 XImage *mark_double =
649 XCreateImage(f_display, DefaultVisualOfScreen(f_screen),
650 1, XYBitmap, 0, (char*)mark_double_bits,
651 mark_double_width, mark_double_height, 8, 0);
652 mark_double->byte_order = LSBFirst;
653 mark_double->bitmap_bit_order = LSBFirst;
654 mark_double->bitmap_unit = 8;
656 XImage *anno_single =
657 XCreateImage(f_display, DefaultVisualOfScreen(f_screen),
658 1, XYBitmap, 0, (char*)anno_single_bits,
659 anno_single_width, anno_single_height, 8, 0);
660 anno_single->byte_order = LSBFirst;
661 anno_single->bitmap_bit_order = LSBFirst;
662 anno_single->bitmap_unit = 8;
664 XImage *anno_double =
665 XCreateImage(f_display, DefaultVisualOfScreen(f_screen),
666 1, XYBitmap, 0, (char*)anno_double_bits,
667 anno_double_width, anno_double_height, 8, 0);
668 anno_double->byte_order = LSBFirst;
669 anno_double->bitmap_bit_order = LSBFirst;
670 anno_double->bitmap_unit = 8;
672 XmInstallImage(mark_single, "mark_single");
673 XmInstallImage(mark_double, "mark_double");
674 XmInstallImage(anno_single, "anno_single");
675 XmInstallImage(anno_double, "anno_double");
679 WindowSystem::locked_pixmap(Widget w)
683 if (!f_locked_pixmap) {
689 f_locked_pixmap = XmGetPixmap (f_screen, "locked.xbm", fg, bg);
690 if (f_locked_pixmap == XmUNSPECIFIED_PIXMAP) {
691 fprintf(stderr, "Couldn't load locked.xbm.\n");
695 return (f_locked_pixmap);
699 WindowSystem::unlocked_pixmap(Widget w)
704 if (!f_unlocked_pixmap) {
710 f_unlocked_pixmap = XmGetPixmap (f_screen, "unlocked.xbm", fg, bg);
711 if (f_unlocked_pixmap == XmUNSPECIFIED_PIXMAP) {
712 fprintf(stderr, "Couldn't load locked.xbm.\n");
716 return (f_unlocked_pixmap);
720 WindowSystem::semilocked_pixmap(Widget w)
724 if (!f_semilocked_pixmap) {
730 f_semilocked_pixmap = XmGetPixmap (f_screen, "semilocked.xbm", fg, bg);
731 if (f_semilocked_pixmap == XmUNSPECIFIED_PIXMAP) {
732 fprintf(stderr, "Couldn't load locked.xbm.\n");
736 return (f_semilocked_pixmap);
739 // /////////////////////////////////////////////////////////////////
740 // run - main event handling loop
741 // /////////////////////////////////////////////////////////////////
746 // don't realize the toplevel shell if we are doing print only
748 toplevel().Realize();
750 service_manager().establish_server();
752 XtAppMainLoop (app_context());
756 // return value is success/failure value
758 WindowSystem::get_color( const char * colorval, unsigned long &pixel) const
760 // NOTE: do we have to free these colors on exit ???
763 pixel = 0 ; // a reasonable value on failures !
767 Colormap colormap = DefaultColormap(f_display,DefaultScreen(f_display));
769 status = XParseColor( f_display,
774 // return now if call failed
778 // now see if we can get the requested color
779 status = XAllocColor( f_display,
784 pixel = xcolor.pixel ;
791 // /////////////////////////////////////////////////////////////////
792 // register_shell - register a toplevel shell for cursor stuff
793 // /////////////////////////////////////////////////////////////////
795 // TMP hack for bogus HGL help lib
796 extern "C" { void olias_register_shell (Widget); }
797 void olias_register_shell (Widget shell)
799 window_system().register_shell ((WShell *) shell);
803 WindowSystem::register_shell (WShell *shell)
805 Shell_Info *si = new Shell_Info (*shell);
806 f_shell_list.append ((FolioObject *) si);
808 shell->SetDestroyCallback (this, (WWL_FUN)&WindowSystem::unregister_shell,
811 XtAddEventHandler (*shell, (EventMask) 0, TRUE,
812 (XtEventHandler) _XEditResCheckMessages, NULL);
816 WindowSystem::register_full_modal_shell (WShell *shell)
818 Shell_Info *si = new Shell_Info (*shell);
819 f_shell_list.append ((FolioObject *) si);
821 shell->SetPopupCallback (this, (WWL_FUN) &WindowSystem::full_modal_cursor);
822 shell->SetPopdownCallback (this,(WWL_FUN) &WindowSystem::reset_cursor);
823 shell->SetDestroyCallback (this, (WWL_FUN) &WindowSystem::unregister_shell,
826 XtAddEventHandler (*shell, (EventMask) 0, TRUE,
827 (XtEventHandler) _XEditResCheckMessages, NULL);
831 WindowSystem::register_primary_modal_shell (WShell *shell)
833 Shell_Info *si = new Shell_Info (*shell);
834 shell->SetPopupCallback (this, (WWL_FUN)&WindowSystem::primary_modal_cursor);
835 shell->SetPopdownCallback (this,(WWL_FUN) &WindowSystem::reset_cursor);
836 shell->SetDestroyCallback (this, (WWL_FUN) &WindowSystem::unregister_shell,
839 XtAddEventHandler (*shell, (EventMask) 0, TRUE,
840 (XtEventHandler) _XEditResCheckMessages, NULL);
844 // /////////////////////////////////////////////////////////////////
846 // /////////////////////////////////////////////////////////////////
849 WindowSystem::unregister_shell (WCallback *wcb)
851 // Reset the cursor if it is currently set because of this shell.
852 if (f_cursor_stack_pos >= 0 &&
853 f_cursor_stack[f_cursor_stack_pos].exception == wcb->GetWidget())
856 Shell_Info *si = (Shell_Info *) wcb->ClientData();
857 f_shell_list.remove ((FolioObject *) si);
858 if (si->f_size_hints != NULL)
859 XFree ((char *) si->f_size_hints);
864 // /////////////////////////////////////////////////////////////////
865 // set_cursor - turn a cursor on
866 // /////////////////////////////////////////////////////////////////
869 WindowSystem::set_cursor (Cursor cursor, Widget exception)
872 // ON_DEBUG (printf ("Cursor change <%d>\n", f_cursor_stack_pos));
873 for (int i = 0; i < f_shell_list.length(); i++)
875 shell = ((Shell_Info *) f_shell_list[i])->f_shell;
876 if (shell != exception && XtWindow (shell) != 0)
878 // ON_DEBUG (printf(" Setting cursor on %s\n", XtName(shell)));
879 XDefineCursor (f_display, XtWindow (shell), cursor);
883 // Save the cursor setting on the cursor stack.
884 ON_DEBUG (printf ("Setting cursor #%d\n", f_cursor_stack_pos + 1));
885 assert (f_cursor_stack_pos <
886 (int)(sizeof(f_cursor_stack) / sizeof(f_cursor_stack[0])));
887 f_cursor_stack_pos++;
888 f_cursor_stack[f_cursor_stack_pos].cursor = cursor;
889 f_cursor_stack[f_cursor_stack_pos].exception = exception;
893 // /////////////////////////////////////////////////////////////////
894 // reset_cursor - reset the cursor to the previous
895 // /////////////////////////////////////////////////////////////////
898 WindowSystem::reset_cursor (WCallback *wcb)
900 // Make sure a cursor has been set first.
901 assert (f_cursor_stack_pos >= 0);
903 Widget exception = wcb ? wcb->GetWidget() : NULL;
904 f_cursor_stack_pos--;
906 if (f_cursor_stack_pos >= 0)
907 cursor = f_cursor_stack[f_cursor_stack_pos].cursor;
909 for (int i = 0; i < f_shell_list.length(); i++)
911 shell = ((Shell_Info *) f_shell_list[i])->f_shell;
912 if (shell != exception && XtWindow (shell) != 0)
913 // Reset the previous cursor if there's one on the stack, revert
914 // to default cursor if the stack is empty.
915 // printf ("Resetting cursor on %s\n", XtName(shell));
916 if (f_cursor_stack_pos >= 0 &&
917 shell != f_cursor_stack[f_cursor_stack_pos].exception)
918 XDefineCursor (f_display, XtWindow (shell), cursor);
920 XUndefineCursor (f_display, XtWindow (shell));
926 // /////////////////////////////////////////////////////////////////
927 // modal_cursor - turn on the modal cursor
928 // /////////////////////////////////////////////////////////////////
931 WindowSystem::full_modal_cursor (WCallback *wcb)
933 set_cursor (f_modal_cursor, wcb ? wcb->GetWidget() : (Widget) NULL);
934 // Make sure the cursor of a freshly popped up dialog is the default.
935 if (wcb && wcb->GetWidget())
936 XUndefineCursor (f_display, XtWindow (wcb->GetWidget()));
940 WindowSystem::primary_modal_cursor (WCallback *wcb)
942 // NOTE: really needs to traverse up hierarchy setting cursor on shell
944 set_cursor (f_modal_cursor, wcb ? wcb->GetWidget() : (Widget) NULL);
948 // /////////////////////////////////////////////////////////////////
950 // /////////////////////////////////////////////////////////////////
953 WindowSystem::create_cursor (const char *filename)
956 Pixmap cursor_bits, cursor_mask;
957 Screen *screen = DefaultScreenOfDisplay (f_display);
958 static XColor white = { 0, ~0, ~0, ~0, DoRed | DoGreen | DoBlue };
959 static XColor black = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue };
964 // Get the cursor pixmap.
965 cursor_bits = XmGetPixmapByDepth (screen, (char *) filename, 1, 0, 1);
966 if (cursor_bits == XmUNSPECIFIED_PIXMAP)
968 fprintf (stderr, "Unable to load bitmap %s\n", filename);
972 success = XmeGetPixmapData (screen, cursor_bits, //
975 0, 0, // foreground, background
977 0, 0); // width, height
981 // Get the cursor mask pixmap.
982 char *mask_filename = new char [strlen(filename) + 2];
983 strcpy (mask_filename, filename);
984 strcat (mask_filename, "m");
985 cursor_mask = XmGetPixmapByDepth (screen, mask_filename, 1, 0, 1);
986 if (cursor_mask == XmUNSPECIFIED_PIXMAP)
988 fprintf (stderr, "Unable to load bitmap %s\n", mask_filename);
992 delete [] mask_filename;
994 cursor = XCreatePixmapCursor (f_display, cursor_bits, cursor_mask,
995 &black, &white, hot_x, hot_y);
997 XmDestroyPixmap (screen, cursor_bits);
998 XmDestroyPixmap (screen, cursor_mask);
1004 // /////////////////////////////////////////////////////////////////
1005 // core_dump_handler
1006 // /////////////////////////////////////////////////////////////////
1009 WindowSystem::core_dump_handler (int signal_number)
1011 if ((XtWindow ((Widget)window_system().toplevel())) != 0)
1013 WXmMessageDialog byebye (window_system().toplevel(), "core_dump");
1014 XtVaSetValues((Widget)byebye, XmNmessageString,
1015 (XmString)XmStringLocalized(CATGETS(Set_WindowSystem, 2,
1016 "Bombing...")), NULL);
1018 WShell shell (XtParent ((Widget) byebye));
1019 window_system().register_shell (&shell);
1020 window_system().set_cursor (window_system().f_bomb_cursor);
1021 XtVaSetValues((Widget)shell, XmNtitle,
1022 CATGETS(Set_WindowSystem, 1, "Dtinfo: Fatal Error"), NULL);
1024 byebye.OkPB().Unmanage();
1025 byebye.CancelPB().Unmanage();
1026 byebye.HelpPB().Unmanage();
1027 byebye.Separator().Unmanage();
1030 // Wait for window manager then process events.
1031 // The best solution would be to wait for the dialog to be mapped,
1032 // but this generally works.
1033 XSync (window_system().f_display, False);
1034 XmUpdateDisplay (byebye);
1036 XmUpdateDisplay (byebye);
1040 fputs ("Fatal error: core dumping...\n", stderr);
1043 signal (signal_number, SIG_DFL);
1044 kill (getpid(), signal_number);
1047 // /////////////////////////////////////////////////////////////////
1048 // Get default pixmap
1049 // /////////////////////////////////////////////////////////////////
1052 WindowSystem::default_pixmap (Dimension *width, Dimension *height)
1055 Dimension temp_width, temp_height;
1057 // if printing return default print pixmap info
1060 if (f_default_print_pixmap) {
1061 *width = f_print_defpix_width;
1062 *height = f_print_defpix_height;
1063 return f_default_print_pixmap;
1068 // if not printing return default print pixmap info
1071 if (f_default_pixmap) {
1072 *width = f_defpix_width;
1073 *height = f_defpix_height;
1074 return f_default_pixmap;
1078 // NOTE: name should be a resource
1079 temp_pixmap = read_pixmap("default.xpm", width, height);
1080 temp_width = *width ;
1081 temp_height = *height ;
1083 if (temp_pixmap == 0){
1086 Screen* screen = XtScreen((Widget)toplevel());
1088 XCreatePixmapFromBitmapData(f_display, XtWindow((Widget)toplevel()),
1089 default_bits, default_width, default_height,
1090 screen->black_pixel, screen->white_pixel,
1091 DefaultDepthOfScreen(screen));
1094 throw(CASTEXCEPT Exception());
1096 temp_width = default_width;
1097 temp_height = default_height;
1100 XpmAttributes xpm_attr ;
1101 xpm_attr.valuemask = 0 ;
1103 status = XmeXpmCreatePixmapFromData(f_display,
1104 XtWindow((Widget)toplevel()),
1105 graphic_unavailable_data,
1108 temp_width = xpm_attr.width;
1109 temp_height = xpm_attr.height ;
1112 *width = temp_width ;
1113 *height = temp_height ;
1116 // if printing, store values in print variables
1119 f_default_print_pixmap = temp_pixmap;
1120 f_print_defpix_width = temp_width;
1121 f_print_defpix_height = temp_height;
1124 // if not printing store values in display variables
1127 f_default_pixmap = temp_pixmap;
1128 f_defpix_width = temp_width;
1129 f_defpix_height = temp_height;
1136 WindowSystem::detached_pixmap(Dimension *width, Dimension *height)
1138 if (f_detached_pixmap){
1139 *width = f_detached_width ;
1140 *height = f_detached_height ;
1142 // NOTE: name should be a resource
1143 f_detached_pixmap = read_pixmap("detached.xpm", width, height);
1144 f_detached_width = *width ;
1145 f_detached_height = *height ;
1146 if (f_detached_pixmap == 0) {
1148 Screen* screen = XtScreen((Widget)toplevel());
1150 XCreatePixmapFromBitmapData(f_display, XtWindow((Widget)toplevel()),
1151 detached_bits, detached_width, detached_height,
1152 screen->black_pixel, screen->white_pixel,
1153 DefaultDepthOfScreen(screen));
1155 int status = f_detached_pixmap ? 0 : 1;
1157 f_detached_width = detached_width;
1158 f_detached_height = detached_height;
1160 XpmAttributes xpm_attr;
1161 xpm_attr.valuemask = 0 ;
1163 int status = XmeXpmCreatePixmapFromData(f_display,
1164 XtWindow((Widget)toplevel()),
1165 detached_pixmap_data,
1168 f_detached_width = xpm_attr.width ;
1169 f_detached_height = xpm_attr.height ;
1172 if (status != XpmSuccess){
1173 fprintf(stderr, "missing pixmap \"detached.xpm\"\n");
1174 throw(CASTEXCEPT Exception());
1176 *width = f_detached_width ;
1177 *height = f_detached_height ;
1181 return f_detached_pixmap ;
1186 WindowSystem::read_pixmap(const char *pname,
1187 Dimension *width, Dimension *height)
1190 XpmAttributes xpm_attributes;
1196 xpm_attributes.valuemask = 0;
1198 strcpy(fname, pname);
1201 status = xpm_lib().ReadFileToPixmap (f_display, XtWindow ((Widget)toplevel()),
1202 fname, &pixmap, NULL, &xpm_attributes);
1204 status = XmeXpmReadFileToPixmap (f_display, XtWindow ((Widget)toplevel()),
1205 fname, &pixmap, NULL, &xpm_attributes);
1208 if (status != XpmSuccess) {
1213 // NOTE: exception to throw here!
1217 *width = xpm_attributes.width;
1218 *height = xpm_attributes.height;
1226 WindowSystem::get_boolean_default (const char *name)
1230 XtResource resource [1];
1232 resource[0].resource_name = (char *) name;
1233 resource[0].resource_class = (char *) name;
1234 resource[0].resource_type = XtRBoolean;
1235 resource[0].resource_size = sizeof(Boolean);
1236 resource[0].resource_offset = NULL;
1237 resource[0].default_type = XtRImmediate;
1238 resource[0].default_addr = False;
1240 XtGetApplicationResources(toplevel(), &value, resource, 1, NULL, 0);
1242 return ((bool) value);
1246 WindowSystem::get_int_default (const char *name)
1250 XtResource resource [1];
1252 resource[0].resource_name = (char *) name;
1253 resource[0].resource_class = (char *) name;
1254 resource[0].resource_type = XtRInt;
1255 resource[0].resource_size = sizeof(int);
1256 resource[0].resource_offset = NULL;
1257 resource[0].default_type = XtRImmediate ;
1258 resource[0].default_addr = 0;
1260 XtGetApplicationResources(toplevel(), &value, resource, 1, NULL, 0);
1266 WindowSystem::get_string_default (const char *name)
1268 XtResource resource [1];
1271 resource[0].resource_name = (char *) name;
1272 resource[0].resource_class = (char *) name;
1273 resource[0].resource_type = XtRString;
1274 resource[0].resource_size = sizeof(String);
1275 resource[0].resource_offset = NULL;
1276 resource[0].default_type = XtRString;
1277 resource[0].default_addr = "";
1279 XtGetApplicationResources(toplevel(), &string, resource, 1, NULL, 0);
1284 const WindowGeometry &
1285 WindowSystem::get_geometry_default (const char *name)
1287 XtResource resource [1];
1289 static WindowGeometry wg;
1291 resource[0].resource_name = (char *) name;
1292 resource[0].resource_class = (char *) name;
1293 resource[0].resource_type = XtRString;
1294 resource[0].resource_size = sizeof(String);
1295 resource[0].resource_offset = NULL;
1296 resource[0].default_type = XtRString;
1297 resource[0].default_addr = "0x0";
1299 XtGetApplicationResources(toplevel(), &string, resource, 1, NULL, 0);
1301 // -1 is sentinel value for now.
1302 wg.ulx = wg.uly = -1;
1303 wg.width = wg.height = 0;
1304 XParseGeometry (string, &wg.ulx, &wg.uly, &wg.width, &wg.height);
1311 WindowSystem::get_color_default(const char *name)
1315 XtResource resource [1];
1317 resource[0].resource_name = (char *) name;
1318 resource[0].resource_class = (char *) name;
1319 resource[0].resource_type = XtRPixel;
1320 resource[0].resource_size = sizeof(Pixel);
1321 resource[0].resource_offset = NULL;
1322 resource[0].default_type = XtRImmediate ;
1323 resource[0].default_addr = (XtPointer)
1324 WhitePixelOfScreen(DefaultScreenOfDisplay(f_display));
1326 XtGetApplicationResources(toplevel(), &value, resource, 1, NULL, 0);
1333 WindowSystem::get_message (const char *message_name)
1335 XtResource resource[1];
1337 static char default_message[256];
1339 resource[0].resource_name = (char *) message_name;
1340 resource[0].resource_class = "Message";
1341 resource[0].resource_type = XtRString;
1342 resource[0].resource_size = sizeof(String);
1343 resource[0].resource_offset = NULL;
1344 resource[0].default_type = XtRString;
1345 resource[0].default_addr = default_message;
1347 XtGetApplicationResources (toplevel(), &string, resource, 1, NULL, 0);
1349 if (string == default_message)
1350 sprintf (string, "%s (Message description not found)", message_name);
1356 WindowSystem::make_space (int space_to_fill, Widget w)
1358 // make sure we can deal with bad args, as space is usually a calculated
1360 if (space_to_fill <= 0)
1361 return WXmString("").disown();
1363 char space_array[256];
1366 // Check for missing fonts case
1369 // get the font that the widget is using
1370 XmFontList fontlist;
1371 XtVaGetValues (w, XmNfontList, &fontlist, NULL);
1373 // Get width of space character in the font
1375 Dimension width = XmStringWidth (fontlist, sp);
1377 // compute closest number of spaces
1378 int nspaces = space_to_fill / width + 1;
1380 // generate space string
1381 for (i = 0; i < nspaces && i < 255; i++)
1382 space_array[i] = ' ';
1383 space_array[i] = '\0';
1385 return WXmString (space_array).disown();
1388 int thirty_two, sixteen, eight, four, two, one ;
1390 thirty_two = space_to_fill / 32 ;
1391 space_to_fill -= 32 * thirty_two ;
1393 sixteen = space_to_fill / 16 ;
1394 space_to_fill -= 16 * sixteen ;
1396 eight = space_to_fill / 8 ;
1397 space_to_fill -= 8 * eight ;
1399 four = space_to_fill / 4 ;
1400 space_to_fill -= 4 * four ;
1402 two = space_to_fill / 2 ;
1403 space_to_fill -= 2 * two ;
1405 one = space_to_fill ;
1407 space_array[0] = 0 ;
1409 if (thirty_two != 0){
1410 for (i = 0 ; i < thirty_two ; i++)
1411 space_array[i] = OLIAS_SPACE32 ;
1412 space_array[i] = 0 ;
1414 WXmString string_32(space_array, OLIAS_SPACE_FONT) ;
1417 space_array[0] = 0 ;
1419 for (i = 0 ; i < sixteen ; i++)
1420 space_array[i] = OLIAS_SPACE16 ;
1421 space_array[i] = 0 ;
1423 WXmString string_16(space_array, OLIAS_SPACE_FONT) ;
1425 space_array[0] = 0 ;
1427 for (i = 0 ; i < eight ; i++)
1428 space_array[i] = OLIAS_SPACE08 ;
1429 space_array[i] = 0 ;
1431 WXmString string_8(space_array, OLIAS_SPACE_FONT) ;
1433 space_array[0] = 0 ;
1435 for (i = 0 ; i < four; i++)
1436 space_array[i] = OLIAS_SPACE04 ;
1437 space_array[i] = 0 ;
1439 WXmString string_4(space_array, OLIAS_SPACE_FONT) ;
1441 space_array[0] = 0 ;
1443 for (i = 0 ; i < two ; i++)
1444 space_array[i] = OLIAS_SPACE02 ;
1445 space_array[i] = 0 ;
1447 WXmString string_2(space_array, OLIAS_SPACE_FONT) ;
1449 space_array[0] = 0 ;
1451 for (i = 0 ; i < one ; i++)
1452 space_array[i] = OLIAS_SPACE01 ;
1453 space_array[i] = 0 ;
1455 WXmString string_1(space_array, OLIAS_SPACE_FONT) ;
1457 WXmString space = string_32 + string_16 + string_8 + string_4 + string_2 + string_1 ;
1459 return space.disown();
1463 // /////////////////////////////////////////////////////////////////
1465 // /////////////////////////////////////////////////////////////////
1468 wait_for_wm (Widget, XtPointer client_data, XEvent *event, Boolean *)
1470 // See if the property we're waiting for has changed.
1471 if (event->type == PropertyNotify &&
1472 event->xproperty.atom == XA_WM_STATE)
1474 // Got our event. waiting_for_wm = False.
1475 *((bool *) client_data) = False;
1479 // /////////////////////////////////////////////////////////////////
1481 // /////////////////////////////////////////////////////////////////
1484 /* Here's how this routine works:
1486 For each shell window
1487 if the window needs to be restored
1489 restore the initial state to normal if it was iconic
1490 restore the size hints if there were any
1495 WindowSystem::show_all_windows()
1498 Boolean waiting_for_wm;
1500 for (int i = 0; i < f_shell_list.length(); i++)
1502 si = (Shell_Info *) f_shell_list[i];
1505 // Set up an event handler so we can tell when the window
1506 // manager has finished dealing with our map request.
1507 if (si->f_has_wm_state)
1509 waiting_for_wm = True;
1510 XtAddEventHandler (si->f_shell, PropertyChangeMask, False,
1511 (XtEventHandler) wait_for_wm,
1515 // Get the window back on the screen.
1516 XMapWindow (f_display, XtWindow (si->f_shell));
1518 // Wait for wm if one is running.
1519 if (si->f_has_wm_state)
1522 ON_DEBUG (printf ("Wait for wm to handle 0x%p", si->f_shell));
1523 while (waiting_for_wm)
1525 XtAppNextEvent (f_application_context, &event);
1526 XtDispatchEvent (&event);
1528 // Get rid of event handler now.
1529 XtRemoveEventHandler (si->f_shell, PropertyChangeMask, False,
1530 (XtEventHandler) wait_for_wm,
1534 ON_DEBUG (printf (" - done\n"));
1535 // Now that the wm is finished (if there is one), we can reset
1536 // the various state variables.
1539 // If it was iconic, reset the initial state.
1540 WWMShell (si->f_shell).InitialState (NormalState);
1544 // Restore the the size hints, because we set USPosition
1545 // and USSize to prevent interactive placement.
1546 if (si->f_has_size_hints)
1547 XSetWMNormalHints (f_display, XtWindow (si->f_shell),
1551 // Reset the restore flag.
1552 si->f_restore = FALSE;
1557 // /////////////////////////////////////////////////////////////////
1558 // generally necessary after a fork to avoid weird conditions
1559 // /////////////////////////////////////////////////////////////////
1562 WindowSystem::close_display_connection()
1564 close (ConnectionNumber(display()));
1568 // /////////////////////////////////////////////////////////////////
1569 // interrupt_handler - deal with user interrupt (usually ^C)
1570 // /////////////////////////////////////////////////////////////////
1573 WindowSystem::interrupt_handler (int /* signal_number */)
1575 // I'm probably forgetting why it's bad to call the message_mgr
1576 // from within the WindowSystem object. We'll find out why
1577 // eventually, I'm sure. 20:56 04-May-94 DJB
1581 if (!(window_system().videoShell()->silent)) {
1582 message_mgr().quit_dialog (
1583 (char*)UAS_String(CATGETS(Set_Messages, 6, "Quit Dtinfo?")));
1589 #if defined(SVR4) || defined(hpux) || defined(_IBMR2)
1590 signal (SIGINT, interrupt_handler);