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 libraries 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/Shell.h>
53 #include <X11/Xmu/Editres.h>
56 #include <Xm/Protocols.h>
62 #include <Dt/EnvControlP.h>
73 extern "C" void _DtSimpleError(
81 extern "C" int _DtPrintDefaultErrorSafe(
89 #include <X11/IntrinsicP.h>
90 #include <X11/CoreP.h>
91 #include <X11/StringDefs.h>
92 #endif /* XmVersion < 1002 */
94 #include <X11/Xmu/Converters.h>
97 #include <Xm/RepType.h>
98 #include <Xm/AtomMgr.h>
99 #endif /* XmVersion >= 1002 */
101 #define C_TOC_Element
104 #define C_WindowGeometryPref
105 #define L_Preferences
111 #define C_WindowSystem
121 #define USES_OLIAS_FONT
125 #include "Other/XmStringLocalized.hh"
126 #include "Managers/CatMgr.hh"
128 #include "Registration.hh"
130 #include <WWL/WApplicationShell.h>
131 #include <WWL/WXmMessageBox.h>
132 #include <WWL/WXmPushButton.h>
134 // These guys are backups for when there is not enough
135 // colors to display the standard ones
137 #include "graphic_unavailable.xbm"
138 #include "detached_bw.xbm"
140 #include "graphic_unavailable.xpm"
141 #include "detached_bw.xpm"
144 // four bitmap images for user marks
146 #define mark_single_width 13
147 #define mark_single_height 13
148 static unsigned char mark_single_bits[] = {
149 0x00, 0x00, 0xfe, 0x01, 0x82, 0x02, 0x82, 0x04, 0x82, 0x08, 0x82, 0x0f,
150 0x02, 0x08, 0x02, 0x08, 0x02, 0x08, 0x02, 0x08, 0x02, 0x08, 0xfe, 0x0f,
153 #define mark_double_width 15
154 #define mark_double_height 15
155 static unsigned char mark_double_bits[] = {
156 0x00, 0x00, 0xf8, 0x07, 0x08, 0x0a, 0x0e, 0x12, 0x0a, 0x22, 0x0a, 0x3e,
157 0x0a, 0x20, 0x0a, 0x20, 0x0a, 0x20, 0x0a, 0x20, 0x0a, 0x20, 0xfa, 0x3f,
158 0x02, 0x08, 0xfe, 0x0f, 0x00, 0x00};
160 #define anno_single_width 13
161 #define anno_single_height 13
162 static unsigned char anno_single_bits[] = {
163 0x00, 0x00, 0xfe, 0x01, 0x82, 0x02, 0xba, 0x04, 0x82, 0x08, 0xba, 0x0f,
164 0x02, 0x08, 0xfa, 0x0b, 0x02, 0x08, 0xfa, 0x0b, 0x02, 0x08, 0xfe, 0x0f,
167 #define anno_double_width 15
168 #define anno_double_height 15
169 static unsigned char anno_double_bits[] = {
170 0x00, 0x00, 0xf8, 0x07, 0x08, 0x0a, 0xee, 0x12, 0x0a, 0x22, 0xea, 0x3e,
171 0x0a, 0x20, 0xea, 0x2f, 0x0a, 0x20, 0xea, 0x2f, 0x0a, 0x20, 0xfa, 0x3f,
172 0x02, 0x08, 0xfe, 0x0f, 0x00, 0x00};
174 #if defined(SVR4) || defined(__linux__) || defined(CSRG_BASED)
177 #include <sys/signal.h>
181 typedef void (*SIG_PF)();
187 #include <DtI/ActionsI.h>
189 // virtual root finder
194 extern Boolean print_server_error;
196 static String fallbacks[] = {
197 (char*)"Dtinfo.Print*background:white",
198 (char*)"Dtinfo.Print*renderTable:-dt-application-bold-r-normal-serif-0-0-0-0-p-0-iso8859-1",
199 (char*)"Dtinfo.Print*shadowThickness:0",
200 (char*)"Dtinfo.Print*highlightThickness:0",
201 (char*)"Dtinfo.Print*pform.marginHeight: 1in",
202 (char*)"Dtinfo.Print*pform.marginWidth: 1in",
203 (char*)"Dtinfo.Print*ptext.Attachment:attach_form",
208 static XtActionsRec DrawnBActions[] =
210 {(char*)"DeSelectAll" , (DeSelectAll_ptr)_DtHelpDeSelectAll },
211 {(char*)"SelectAll" , (SelectAll_ptr)_DtHelpSelectAll },
212 {(char*)"ActivateLink" , (ActivateLink_ptr)_DtHelpActivateLink },
213 {(char*)"CopyToClipboard", (CopyAction_ptr)_DtHelpCopyAction },
214 {(char*)"PageUpOrDown" , (PageUpOrDown_ptr)_DtHelpPageUpOrDown },
215 {(char*)"PageLeftOrRight", (PageLeftOrRight_ptr)_DtHelpPageLeftOrRight },
216 {(char*)"NextLink" , (NextLink_ptr)_DtHelpNextLink }
221 WindowSystem *WindowSystem::f_window_system;
222 static Atom XA_WM_STATE;
226 Shell_Info (Widget w)
229 f_has_size_hints(False),
232 f_has_wm_state(False)
237 XSizeHints *f_size_hints;
238 bool f_has_size_hints : 1;
241 bool f_has_wm_state : 1;
245 // /////////////////////////////////////////////////////////////////
247 // /////////////////////////////////////////////////////////////////
249 WindowSystem::WindowSystem (int &argc, char *argv[])
250 : f_print_display(NULL),
252 f_default_pixmap (0),
253 f_default_print_pixmap(0),
256 f_print_defpix_width(0),
257 f_print_defpix_height(0),
258 f_detached_pixmap(0),
260 f_detached_height(0),
262 f_cursor_stack_pos(-1),
263 f_print_screen(NULL),
265 f_dtinfo_space_font(NULL)
269 f_window_system = this;
272 f_modal_cursor = create_cursor ("xm_noenter16");
273 f_wait_cursor = create_cursor ("xm_hour16");
274 f_bomb_cursor = create_cursor ("bomb");
276 /* -------- Debugging setup. Should be a function. -------- */
278 bool debugging = get_boolean_app_resource("debug");
282 /*DWC IBM (SIG_PF)*/ (core_dump_handler_ptr)core_dump_handler);
283 signal (SIGBUS, /*(SIG_PF)*/ (core_dump_handler_ptr)core_dump_handler);
284 signal (SIGSEGV, /*(SIG_PF)*/ (core_dump_handler_ptr)core_dump_handler);
285 signal (SIGINT, (interrupt_handler_ptr)interrupt_handler);
288 /* Reference the scale widget so Veritas Replay Xt lib can link. */
289 /* WidgetClass xxx = xmScaleWidgetClass; */
292 char **names = XListFonts(window_system().display(),
293 "-dt-dtinfo-*-14-*-dtinfo-?", 1, &count);
297 f_dtinfo_font = XmFontListEntryLoad(f_display, *names,
298 XmFONT_IS_FONT, (char*)"olias");
299 f_dtinfo_space_font = XmFontListEntryLoad(f_display, *names,
300 XmFONT_IS_FONT, (char*)"ospace");
301 XFreeFontNames(names);
305 // /////////////////////////////////////////////////////////////////////////
307 // /////////////////////////////////////////////////////////////////////////
309 WindowSystem::~WindowSystem()
311 signal (SIGABRT, SIG_DFL);
312 signal (SIGBUS, SIG_DFL);
313 signal (SIGSEGV, SIG_DFL);
317 WindowSystem::dtinfo_font()
319 return f_dtinfo_font;
323 WindowSystem::dtinfo_space_font()
325 return f_dtinfo_space_font;
329 WindowSystem::toplevel()
332 return (f_print_toplevel);
340 WindowSystem::printToplevel()
342 return (f_print_toplevel);
346 WindowSystem::onlineToplevel()
352 WindowSystem::display()
355 return (f_print_display);
363 WindowSystem::screen()
366 return (f_print_screen);
374 WindowSystem::onlineDisplay()
380 WindowSystem::printDisplay()
382 return (f_print_display);
386 WindowSystem::printing()
392 WindowSystem::setPrintDisplay(Widget widget)
394 f_print_toplevel = widget;
395 f_print_display = XtDisplay(widget);
396 f_print_screen = XtScreen(widget);
400 WindowSystem::setPrinting(Boolean state)
406 WindowSystem::update_display()
408 XmUpdateDisplay (f_toplevel);
412 // /////////////////////////////////////////////////////////////////
414 // /////////////////////////////////////////////////////////////////
417 extern "C" { void tml_dp_set_font_display(Display *); }
420 // command line options
422 // include "dbg" so we can use the startup script -debug flag independently
423 XrmOptionDescRec options[] = {
424 {(char*)"-debug", (char*)"*debug", XrmoptionNoArg, (char*)"True"},
425 {(char*)"-dbg", (char*)"*debug", XrmoptionNoArg, (char*)"True"},
426 {(char*)"-author", (char*)"*author", XrmoptionNoArg, (char*)"True"},
427 {(char*)"-readonly", (char*)"*readonly", XrmoptionNoArg, (char*)"True"},
428 {(char*)"-ro", (char*)"*readonly", XrmoptionNoArg, (char*)"True"},
429 {(char*)"-autohelp", (char*)"*AutomaticHelp",XrmoptionNoArg, (char*)"On"},
430 {(char*)"-nofonts", (char*)"*NoFonts", XrmoptionNoArg, (char*)"True"},
431 {(char*)"-print", (char*)"printOnly", XrmoptionNoArg, (char*)"True"},
432 {(char*)"-hierarchy", (char*)"hierarchy", XrmoptionNoArg, (char*)"True"},
433 {(char*)"-printer", (char*)"printer", XrmoptionSepArg, NULL},
434 {(char*)"-copies", (char*)"copies", XrmoptionSepArg, NULL},
435 {(char*)"-paperSize", (char*)"paperSize", XrmoptionSepArg, NULL},
436 {(char*)"-silent", (char*)"silent", XrmoptionNoArg, (char*)"True"},
437 {(char*)"-outputFile",(char*)"outputFile", XrmoptionSepArg, NULL}
440 static XtResource VideoResources[] =
442 {(char*)"printOnly", (char*)"PrintOnly", XmRBoolean, sizeof (Boolean),
443 XtOffsetOf (VideoShell, print_only), XmRImmediate, (XtPointer)False,
445 {(char*)"outputFile", (char*)"OutputFile", XmRString, sizeof (char *),
446 XtOffsetOf (VideoShell, file_name), XmRImmediate, (XtPointer)NULL,
448 {(char*)"hierarchy", (char*)"Hierarchy", XmRBoolean, sizeof (Boolean),
449 XtOffsetOf (VideoShell, hierarchy), XmRImmediate, (XtPointer)False,
451 {(char*)"printer", (char*)"Printer", XmRString, sizeof (char *),
452 XtOffsetOf (VideoShell, printer), XmRImmediate, (XtPointer)NULL,
454 {(char*)"copies", (char*)"Copies", XmRInt, sizeof (int),
455 XtOffsetOf (VideoShell, copies), XmRImmediate, (XtPointer)1,
457 {(char*)"paperSize", (char*)"PaperSize", XmRString, sizeof (char *),
458 XtOffsetOf (VideoShell, paper_size), XmRImmediate, (XtPointer)NULL,
460 {(char*)"silent", (char*)"Silent", XmRBoolean, sizeof (Boolean),
461 XtOffsetOf (VideoShell, silent), XmRImmediate, (XtPointer)False,
466 * static function declarations
468 VideoShell* VideoShell_new(Display* display);
472 * ------------------------------------------------------------------------
477 * Access function for f_video_shell containing application resources
478 * and command line options.
482 * A pointer to the VideoShell structure.
485 WindowSystem::videoShell()
487 return (f_video_shell);
491 * ------------------------------------------------------------------------
492 * Name: VideoShell_new
496 * Allocates a new VideoShell data structure.
498 * This function creates a top level application shell on the passed
503 * A pointer to the new VideoShell structure.
506 VideoShell_new(Display*, Widget app_shell)
508 VideoShell* me = (VideoShell*)XtCalloc(1, sizeof(VideoShell));
510 me->widget = app_shell;
512 XtGetApplicationResources(me->widget, me,
513 VideoResources, XtNumber(VideoResources),
516 // Modify the videoShell data based on environment variable settings
518 // if DTPRINTSILENT is set then turn silent printing on
520 if (getenv("DTPRINTSILENT") != NULL) {
528 xevent_error_aborter(Display *display, XErrorEvent* error_event)
530 #define _DTINFO_BUFSIZE 1024
531 char error_msg[_DTINFO_BUFSIZE];
535 _DtPrintDefaultErrorSafe(display, error_event, error_msg, _DTINFO_BUFSIZE);
536 _DtSimpleError((char*)"dtinfo", DtWarning, NULL, error_msg, NULL);
538 // if the error occurred on the print display we're going to set
539 // a variable so that and when the job is done, right before calling
540 // XpEndJob, we call XpCancelJob, and notify the user.
542 if ( (display == window_system().printDisplay()) &&
543 (error_event->error_code == BadAlloc) ) {
544 print_server_error = True;
554 XtSetLanguageProc(NULL, (XtLanguageProc)NULL, NULL);
556 _DtEnvControl(DT_ENV_SET);
558 Widget app_shell = XtAppInitialize(&f_application_context, CLASS_NAME,
559 options, XtNumber(options),
560 f_argc, f_argv, fallbacks, NULL, 0);
561 f_display = XtDisplay(app_shell);
564 XSynchronize(f_display, True);
566 XSync(f_display, False);
567 XSetErrorHandler((xevent_error_aborter_ptr)xevent_error_aborter);
570 XtAppSetFallbackResources(f_application_context, fallbacks);
573 // exit if display cannot be opened. this code will need to be revised
574 // if we ever want to handle gui-less printing
576 if (f_display == (Display*)NULL)
578 fprintf(stderr, "%s",
579 CATGETS(Set_WindowSystem, 3, "Unable to open display.\n"));
583 // Create the top level video shell
585 f_video_shell = VideoShell_new(f_display, app_shell);
587 // Create a new AppPrintData object here and initialize it since
588 // the $%^& doesn't seem to get called.
590 f_AppPrintData = new AppPrintData;
591 f_AppPrintData->f_print_data = (DtPrintSetupData*)XtCalloc(1, sizeof(DtPrintSetupData));
592 f_AppPrintData->f_pform = NULL ;
593 f_AppPrintData->f_print_dialog = NULL;
594 f_AppPrintData->f_print_shell = NULL;
595 f_AppPrintData->f_print_only = f_video_shell->print_only;
596 f_toplevel = f_video_shell->widget;
598 if (DtAppInitialize( f_application_context,
599 f_display, f_toplevel, f_argv[0], (char*)CLASS_NAME) == False)
601 /* DtAppInitialize() has already logged an appropriate error msg */
605 // Make sure this shell never appears.
606 XtSetMappedWhenManaged (f_toplevel, False);
608 XtAppAddActions (f_application_context, DrawnBActions, XtNumber (DrawnBActions));
610 // register_shell (f_toplevel)
612 f_display = XtDisplay(f_toplevel);
613 // NOTE: Check for failure DJB
615 tml_dp_set_font_display(f_display);
618 // Create atom used elsewhere by agents
619 f_wm_delete_window = XmInternAtom (f_display, (char*)"WM_DELETE_WINDOW", False);
620 XA_WM_STATE = XmInternAtom (f_display, (char*)"WM_STATE", False);
622 // -------- Add some converters -------- //
625 // This converter let's us specify form connections in resources
626 static XtConvertArgRec parentCvtArg[] = {
627 { XtWidgetBaseOffset, (XtPointer) XtOffsetOf(WidgetRec, core.parent),
630 XtSetTypeConverter (XtRString, XtRWindow, XmuNewCvtStringToWidget,
631 parentCvtArg, XtNumber (parentCvtArg), XtCacheNone, NULL);
632 #endif /* XmVersion < 1002 */
634 XtAddConverter (XtRString, XtRGravity,
635 (XmuCvtStringToGravity_ptr)XmuCvtStringToGravity, NULL, 0);
637 #if XmVersion >= 1002
638 XmRepTypeInstallTearOffModelConverter();
639 #endif /* XmVersion >= 1002 */
641 // NOTE: Really need to install a string to pixmap converter!
642 /* -------- Get some pixmaps. -------- */
644 f_screen = XtScreen(f_toplevel);
645 f_nofonts = get_boolean_default ("NoFonts");
648 f_semilocked_pixmap = 0;
649 f_unlocked_pixmap = 0;
651 XImage *mark_single =
652 XCreateImage(f_display, DefaultVisualOfScreen(f_screen),
653 1, XYBitmap, 0, (char*)mark_single_bits,
654 mark_single_width, mark_single_height, 8, 0);
655 mark_single->byte_order = LSBFirst;
656 mark_single->bitmap_bit_order = LSBFirst;
657 mark_single->bitmap_unit = 8;
659 XImage *mark_double =
660 XCreateImage(f_display, DefaultVisualOfScreen(f_screen),
661 1, XYBitmap, 0, (char*)mark_double_bits,
662 mark_double_width, mark_double_height, 8, 0);
663 mark_double->byte_order = LSBFirst;
664 mark_double->bitmap_bit_order = LSBFirst;
665 mark_double->bitmap_unit = 8;
667 XImage *anno_single =
668 XCreateImage(f_display, DefaultVisualOfScreen(f_screen),
669 1, XYBitmap, 0, (char*)anno_single_bits,
670 anno_single_width, anno_single_height, 8, 0);
671 anno_single->byte_order = LSBFirst;
672 anno_single->bitmap_bit_order = LSBFirst;
673 anno_single->bitmap_unit = 8;
675 XImage *anno_double =
676 XCreateImage(f_display, DefaultVisualOfScreen(f_screen),
677 1, XYBitmap, 0, (char*)anno_double_bits,
678 anno_double_width, anno_double_height, 8, 0);
679 anno_double->byte_order = LSBFirst;
680 anno_double->bitmap_bit_order = LSBFirst;
681 anno_double->bitmap_unit = 8;
683 XmInstallImage(mark_single, (char*)"mark_single");
684 XmInstallImage(mark_double, (char*)"mark_double");
685 XmInstallImage(anno_single, (char*)"anno_single");
686 XmInstallImage(anno_double, (char*)"anno_double");
690 WindowSystem::locked_pixmap(Widget w)
694 if (!f_locked_pixmap) {
700 f_locked_pixmap = XmGetPixmap (f_screen, (char*)"locked.xbm", fg, bg);
701 if (f_locked_pixmap == XmUNSPECIFIED_PIXMAP) {
702 fprintf(stderr, "Couldn't load locked.xbm.\n");
706 return (f_locked_pixmap);
710 WindowSystem::unlocked_pixmap(Widget w)
715 if (!f_unlocked_pixmap) {
721 f_unlocked_pixmap = XmGetPixmap (f_screen, (char*)"unlocked.xbm", fg, bg);
722 if (f_unlocked_pixmap == XmUNSPECIFIED_PIXMAP) {
723 fprintf(stderr, "Couldn't load locked.xbm.\n");
727 return (f_unlocked_pixmap);
731 WindowSystem::semilocked_pixmap(Widget w)
735 if (!f_semilocked_pixmap) {
741 f_semilocked_pixmap = XmGetPixmap (f_screen, (char*)"semilocked.xbm", fg, bg);
742 if (f_semilocked_pixmap == XmUNSPECIFIED_PIXMAP) {
743 fprintf(stderr, "Couldn't load locked.xbm.\n");
747 return (f_semilocked_pixmap);
750 // /////////////////////////////////////////////////////////////////
751 // run - main event handling loop
752 // /////////////////////////////////////////////////////////////////
757 // don't realize the toplevel shell if we are doing print only
759 toplevel().Realize();
761 service_manager().establish_server();
763 XtAppMainLoop (app_context());
767 // return value is success/failure value
769 WindowSystem::get_color( const char * colorval, unsigned long &pixel) const
771 // NOTE: do we have to free these colors on exit ???
774 pixel = 0 ; // a reasonable value on failures !
778 Colormap colormap = DefaultColormap(f_display,DefaultScreen(f_display));
780 status = XParseColor( f_display,
785 // return now if call failed
789 // now see if we can get the requested color
790 status = XAllocColor( f_display,
795 pixel = xcolor.pixel ;
802 // /////////////////////////////////////////////////////////////////
803 // register_shell - register a toplevel shell for cursor stuff
804 // /////////////////////////////////////////////////////////////////
806 // TMP hack for bogus HGL help lib
807 extern "C" { void olias_register_shell (Widget); }
808 void olias_register_shell (Widget shell)
810 window_system().register_shell ((WShell *) shell);
814 WindowSystem::register_shell (WShell *shell)
816 Shell_Info *si = new Shell_Info (*shell);
817 f_shell_list.append ((FolioObject *) si);
819 shell->SetDestroyCallback (this, (WWL_FUN)&WindowSystem::unregister_shell,
822 XtAddEventHandler (*shell, (EventMask) 0, TRUE,
823 (XtEventHandler) _XEditResCheckMessages, NULL);
827 WindowSystem::register_full_modal_shell (WShell *shell)
829 Shell_Info *si = new Shell_Info (*shell);
830 f_shell_list.append ((FolioObject *) si);
832 shell->SetPopupCallback (this, (WWL_FUN) &WindowSystem::full_modal_cursor);
833 shell->SetPopdownCallback (this,(WWL_FUN) &WindowSystem::reset_cursor);
834 shell->SetDestroyCallback (this, (WWL_FUN) &WindowSystem::unregister_shell,
837 XtAddEventHandler (*shell, (EventMask) 0, TRUE,
838 (XtEventHandler) _XEditResCheckMessages, NULL);
842 WindowSystem::register_primary_modal_shell (WShell *shell)
844 Shell_Info *si = new Shell_Info (*shell);
845 shell->SetPopupCallback (this, (WWL_FUN)&WindowSystem::primary_modal_cursor);
846 shell->SetPopdownCallback (this,(WWL_FUN) &WindowSystem::reset_cursor);
847 shell->SetDestroyCallback (this, (WWL_FUN) &WindowSystem::unregister_shell,
850 XtAddEventHandler (*shell, (EventMask) 0, TRUE,
851 (XtEventHandler) _XEditResCheckMessages, NULL);
855 // /////////////////////////////////////////////////////////////////
857 // /////////////////////////////////////////////////////////////////
860 WindowSystem::unregister_shell (WCallback *wcb)
862 // Reset the cursor if it is currently set because of this shell.
863 if (f_cursor_stack_pos >= 0 &&
864 f_cursor_stack[f_cursor_stack_pos].exception == wcb->GetWidget())
867 Shell_Info *si = (Shell_Info *) wcb->ClientData();
868 f_shell_list.remove ((FolioObject *) si);
869 if (si->f_size_hints != NULL)
870 XFree ((char *) si->f_size_hints);
875 // /////////////////////////////////////////////////////////////////
876 // set_cursor - turn a cursor on
877 // /////////////////////////////////////////////////////////////////
880 WindowSystem::set_cursor (Cursor cursor, Widget exception)
883 // ON_DEBUG (printf ("Cursor change <%d>\n", f_cursor_stack_pos));
884 for (unsigned int i = 0; i < f_shell_list.length(); i++)
886 shell = ((Shell_Info *) f_shell_list[i])->f_shell;
887 if (shell != exception && XtWindow (shell) != 0)
889 // ON_DEBUG (printf(" Setting cursor on %s\n", XtName(shell)));
890 XDefineCursor (f_display, XtWindow (shell), cursor);
894 // Save the cursor setting on the cursor stack.
895 ON_DEBUG (printf ("Setting cursor #%d\n", f_cursor_stack_pos + 1));
896 assert (f_cursor_stack_pos <
897 (int)(sizeof(f_cursor_stack) / sizeof(f_cursor_stack[0])));
898 f_cursor_stack_pos++;
899 f_cursor_stack[f_cursor_stack_pos].cursor = cursor;
900 f_cursor_stack[f_cursor_stack_pos].exception = exception;
904 // /////////////////////////////////////////////////////////////////
905 // reset_cursor - reset the cursor to the previous
906 // /////////////////////////////////////////////////////////////////
909 WindowSystem::reset_cursor (WCallback *wcb)
911 // Make sure a cursor has been set first.
912 assert (f_cursor_stack_pos >= 0);
914 Widget exception = wcb ? wcb->GetWidget() : NULL;
915 f_cursor_stack_pos--;
917 if (f_cursor_stack_pos >= 0)
918 cursor = f_cursor_stack[f_cursor_stack_pos].cursor;
920 for (unsigned int i = 0; i < f_shell_list.length(); i++)
922 shell = ((Shell_Info *) f_shell_list[i])->f_shell;
923 if (shell != exception && XtWindow (shell) != 0) {
924 // Reset the previous cursor if there's one on the stack, revert
925 // to default cursor if the stack is empty.
926 // printf ("Resetting cursor on %s\n", XtName(shell));
927 if (f_cursor_stack_pos >= 0 &&
928 shell != f_cursor_stack[f_cursor_stack_pos].exception)
929 XDefineCursor (f_display, XtWindow (shell), cursor);
931 XUndefineCursor (f_display, XtWindow (shell));
938 // /////////////////////////////////////////////////////////////////
939 // modal_cursor - turn on the modal cursor
940 // /////////////////////////////////////////////////////////////////
943 WindowSystem::full_modal_cursor (WCallback *wcb)
945 set_cursor (f_modal_cursor, wcb ? wcb->GetWidget() : (Widget) NULL);
946 // Make sure the cursor of a freshly popped up dialog is the default.
947 if (wcb && wcb->GetWidget())
948 XUndefineCursor (f_display, XtWindow (wcb->GetWidget()));
952 WindowSystem::primary_modal_cursor (WCallback *wcb)
954 // NOTE: really needs to traverse up hierarchy setting cursor on shell
956 set_cursor (f_modal_cursor, wcb ? wcb->GetWidget() : (Widget) NULL);
960 // /////////////////////////////////////////////////////////////////
962 // /////////////////////////////////////////////////////////////////
965 WindowSystem::create_cursor (const char *filename)
968 Pixmap cursor_bits, cursor_mask;
969 Screen *screen = DefaultScreenOfDisplay (f_display);
970 unsigned short c = ~0;
971 static XColor white = { 0, c, c, c, DoRed | DoGreen | DoBlue };
972 static XColor black = { 0, 0, 0, 0, DoRed | DoGreen | DoBlue };
977 // Get the cursor pixmap.
978 cursor_bits = XmGetPixmapByDepth (screen, (char *) filename, 1, 0, 1);
979 if (cursor_bits == XmUNSPECIFIED_PIXMAP)
981 fprintf (stderr, "Unable to load bitmap %s\n", filename);
985 success = XmeGetPixmapData (screen, cursor_bits, //
988 0, 0, // foreground, background
990 0, 0); // width, height
996 // Get the cursor mask pixmap.
997 len = strlen(filename);
998 char *mask_filename = new char [len + 2];
999 *((char *) memcpy(mask_filename, filename, len) + len) = '\0';
1000 *((char *) memcpy(mask_filename + len, "m", 1) + 1) = '\0';
1001 cursor_mask = XmGetPixmapByDepth (screen, mask_filename, 1, 0, 1);
1002 if (cursor_mask == XmUNSPECIFIED_PIXMAP)
1004 fprintf (stderr, "Unable to load bitmap %s\n", mask_filename);
1008 delete [] mask_filename;
1010 cursor = XCreatePixmapCursor (f_display, cursor_bits, cursor_mask,
1011 &black, &white, hot_x, hot_y);
1013 XmDestroyPixmap (screen, cursor_bits);
1014 XmDestroyPixmap (screen, cursor_mask);
1020 // /////////////////////////////////////////////////////////////////
1021 // core_dump_handler
1022 // /////////////////////////////////////////////////////////////////
1025 WindowSystem::core_dump_handler (int signal_number)
1027 if ((XtWindow ((Widget)window_system().toplevel())) != 0)
1029 WXmMessageDialog byebye (window_system().toplevel(), (char*)"core_dump");
1030 XtVaSetValues((Widget)byebye, XmNmessageString,
1031 (XmString)XmStringLocalized(CATGETS(Set_WindowSystem, 2,
1032 "Bombing...")), NULL);
1034 WShell shell (XtParent ((Widget) byebye));
1035 window_system().register_shell (&shell);
1036 window_system().set_cursor (window_system().f_bomb_cursor);
1037 XtVaSetValues((Widget)shell, XmNtitle,
1038 CATGETS(Set_WindowSystem, 1, "Dtinfo: Fatal Error"), NULL);
1040 byebye.OkPB().Unmanage();
1041 byebye.CancelPB().Unmanage();
1042 byebye.HelpPB().Unmanage();
1043 byebye.Separator().Unmanage();
1046 // Wait for window manager then process events.
1047 // The best solution would be to wait for the dialog to be mapped,
1048 // but this generally works.
1049 XSync (window_system().f_display, False);
1050 XmUpdateDisplay (byebye);
1052 XmUpdateDisplay (byebye);
1056 fputs ("Fatal error: core dumping...\n", stderr);
1059 signal (signal_number, SIG_DFL);
1060 kill (getpid(), signal_number);
1063 // /////////////////////////////////////////////////////////////////
1064 // Get default pixmap
1065 // /////////////////////////////////////////////////////////////////
1068 WindowSystem::default_pixmap (Dimension *width, Dimension *height)
1071 Dimension temp_width, temp_height;
1073 // if printing return default print pixmap info
1076 if (f_default_print_pixmap) {
1077 *width = f_print_defpix_width;
1078 *height = f_print_defpix_height;
1079 return f_default_print_pixmap;
1084 // if not printing return default print pixmap info
1087 if (f_default_pixmap) {
1088 *width = f_defpix_width;
1089 *height = f_defpix_height;
1090 return f_default_pixmap;
1094 // NOTE: name should be a resource
1095 temp_pixmap = read_pixmap("default.xpm", width, height);
1096 temp_width = *width ;
1097 temp_height = *height ;
1099 if (temp_pixmap == 0){
1102 Screen* screen = XtScreen((Widget)toplevel());
1104 XCreatePixmapFromBitmapData(f_display, XtWindow((Widget)toplevel()),
1105 default_bits, default_width, default_height,
1106 screen->black_pixel, screen->white_pixel,
1107 DefaultDepthOfScreen(screen));
1110 throw(CASTEXCEPT Exception());
1112 temp_width = default_width;
1113 temp_height = default_height;
1115 XpmAttributes xpm_attr ;
1116 xpm_attr.valuemask = 0 ;
1118 XpmCreatePixmapFromData(f_display,
1119 XtWindow((Widget)toplevel()),
1120 (char**)graphic_unavailable_data,
1123 temp_width = xpm_attr.width;
1124 temp_height = xpm_attr.height ;
1127 *width = temp_width ;
1128 *height = temp_height ;
1131 // if printing, store values in print variables
1134 f_default_print_pixmap = temp_pixmap;
1135 f_print_defpix_width = temp_width;
1136 f_print_defpix_height = temp_height;
1139 // if not printing store values in display variables
1142 f_default_pixmap = temp_pixmap;
1143 f_defpix_width = temp_width;
1144 f_defpix_height = temp_height;
1151 WindowSystem::detached_pixmap(Dimension *width, Dimension *height)
1153 if (f_detached_pixmap){
1154 *width = f_detached_width ;
1155 *height = f_detached_height ;
1157 // NOTE: name should be a resource
1158 f_detached_pixmap = read_pixmap("detached.xpm", width, height);
1159 f_detached_width = *width ;
1160 f_detached_height = *height ;
1161 if (f_detached_pixmap == 0) {
1163 Screen* screen = XtScreen((Widget)toplevel());
1165 XCreatePixmapFromBitmapData(f_display, XtWindow((Widget)toplevel()),
1166 detached_bits, detached_width, detached_height,
1167 screen->black_pixel, screen->white_pixel,
1168 DefaultDepthOfScreen(screen));
1170 int status = f_detached_pixmap ? 0 : 1;
1172 f_detached_width = detached_width;
1173 f_detached_height = detached_height;
1175 XpmAttributes xpm_attr;
1176 xpm_attr.valuemask = 0 ;
1178 int status = XpmCreatePixmapFromData(f_display,
1179 XtWindow((Widget)toplevel()),
1180 (char**)detached_pixmap_data,
1183 f_detached_width = xpm_attr.width ;
1184 f_detached_height = xpm_attr.height ;
1187 if (status != XpmSuccess){
1188 fprintf(stderr, "missing pixmap \"detached.xpm\"\n");
1189 throw(CASTEXCEPT Exception());
1191 *width = f_detached_width ;
1192 *height = f_detached_height ;
1196 return f_detached_pixmap ;
1201 WindowSystem::read_pixmap(const char *pname,
1202 Dimension *width, Dimension *height)
1205 XpmAttributes xpm_attributes;
1211 xpm_attributes.valuemask = 0;
1213 int len = MIN(strlen(pname), 255 - 1);
1214 *((char *) memcpy(fname, pname, len) + len) = '\0';
1217 status = xpm_lib().ReadFileToPixmap (f_display, XtWindow ((Widget)toplevel()),
1218 fname, &pixmap, NULL, &xpm_attributes);
1220 status = XpmReadFileToPixmap (f_display, XtWindow ((Widget)toplevel()),
1221 fname, &pixmap, NULL, &xpm_attributes);
1224 if (status != XpmSuccess) {
1229 // NOTE: exception to throw here!
1233 *width = xpm_attributes.width;
1234 *height = xpm_attributes.height;
1242 WindowSystem::get_boolean_default (const char *name)
1246 XtResource resource [1];
1248 resource[0].resource_name = (char *) name;
1249 resource[0].resource_class = (char *) name;
1250 resource[0].resource_type = XtRBoolean;
1251 resource[0].resource_size = sizeof(Boolean);
1252 resource[0].resource_offset = 0;
1253 resource[0].default_type = XtRImmediate;
1254 resource[0].default_addr = False;
1256 XtGetApplicationResources(toplevel(), &value, resource, 1, NULL, 0);
1258 return ((bool) value);
1262 WindowSystem::get_int_default (const char *name)
1266 XtResource resource [1];
1268 resource[0].resource_name = (char *) name;
1269 resource[0].resource_class = (char *) name;
1270 resource[0].resource_type = XtRInt;
1271 resource[0].resource_size = sizeof(int);
1272 resource[0].resource_offset = 0;
1273 resource[0].default_type = XtRImmediate ;
1274 resource[0].default_addr = 0;
1276 XtGetApplicationResources(toplevel(), &value, resource, 1, NULL, 0);
1282 WindowSystem::get_string_default (const char *name)
1284 XtResource resource [1];
1287 resource[0].resource_name = (char *) name;
1288 resource[0].resource_class = (char *) name;
1289 resource[0].resource_type = XtRString;
1290 resource[0].resource_size = sizeof(String);
1291 resource[0].resource_offset = 0;
1292 resource[0].default_type = XtRString;
1293 resource[0].default_addr = (void *) "";
1295 XtGetApplicationResources(toplevel(), &string, resource, 1, NULL, 0);
1300 const WindowGeometry &
1301 WindowSystem::get_geometry_default (const char *name)
1303 XtResource resource [1];
1305 static WindowGeometry wg;
1307 resource[0].resource_name = (char *) name;
1308 resource[0].resource_class = (char *) name;
1309 resource[0].resource_type = XtRString;
1310 resource[0].resource_size = sizeof(String);
1311 resource[0].resource_offset = 0;
1312 resource[0].default_type = XtRString;
1313 resource[0].default_addr = (void *) "0x0";
1315 XtGetApplicationResources(toplevel(), &string, resource, 1, NULL, 0);
1317 // -1 is sentinel value for now.
1318 wg.ulx = wg.uly = -1;
1319 wg.width = wg.height = 0;
1320 XParseGeometry (string, &wg.ulx, &wg.uly, &wg.width, &wg.height);
1327 WindowSystem::get_color_default(const char *name)
1331 XtResource resource [1];
1333 resource[0].resource_name = (char *) name;
1334 resource[0].resource_class = (char *) name;
1335 resource[0].resource_type = XtRPixel;
1336 resource[0].resource_size = sizeof(Pixel);
1337 resource[0].resource_offset = 0;
1338 resource[0].default_type = XtRImmediate ;
1339 resource[0].default_addr = (XtPointer)
1340 WhitePixelOfScreen(DefaultScreenOfDisplay(f_display));
1342 XtGetApplicationResources(toplevel(), &value, resource, 1, NULL, 0);
1349 WindowSystem::get_message (const char *message_name)
1351 XtResource resource[1];
1353 static char default_message[256];
1355 resource[0].resource_name = (char *) message_name;
1356 resource[0].resource_class = (char*)"Message";
1357 resource[0].resource_type = XtRString;
1358 resource[0].resource_size = sizeof(String);
1359 resource[0].resource_offset = 0;
1360 resource[0].default_type = XtRString;
1361 resource[0].default_addr = default_message;
1363 XtGetApplicationResources (toplevel(), &string, resource, 1, NULL, 0);
1365 if (string == default_message)
1366 snprintf (string, sizeof(default_message),
1367 "%s (Message description not found)", message_name);
1373 WindowSystem::make_space (int space_to_fill, Widget w)
1375 // make sure we can deal with bad args, as space is usually a calculated
1377 if (space_to_fill <= 0)
1378 return WXmString("").disown();
1380 char space_array[256];
1383 // Check for missing fonts case
1386 // get the font that the widget is using
1387 XmFontList fontlist;
1388 XtVaGetValues (w, XmNfontList, &fontlist, NULL);
1390 // Get width of space character in the font
1392 Dimension width = XmStringWidth (fontlist, sp);
1394 // compute closest number of spaces
1395 int nspaces = space_to_fill / width + 1;
1397 // generate space string
1398 for (i = 0; i < nspaces && i < 255; i++)
1399 space_array[i] = ' ';
1400 space_array[i] = '\0';
1402 return WXmString (space_array).disown();
1405 int thirty_two, sixteen, eight, four, two, one ;
1407 thirty_two = space_to_fill / 32 ;
1408 space_to_fill -= 32 * thirty_two ;
1410 sixteen = space_to_fill / 16 ;
1411 space_to_fill -= 16 * sixteen ;
1413 eight = space_to_fill / 8 ;
1414 space_to_fill -= 8 * eight ;
1416 four = space_to_fill / 4 ;
1417 space_to_fill -= 4 * four ;
1419 two = space_to_fill / 2 ;
1420 space_to_fill -= 2 * two ;
1422 one = space_to_fill ;
1424 space_array[0] = 0 ;
1426 if (thirty_two != 0){
1427 for (i = 0 ; i < thirty_two ; i++)
1428 space_array[i] = OLIAS_SPACE32 ;
1429 space_array[i] = 0 ;
1431 WXmString string_32(space_array, (char*)OLIAS_SPACE_FONT) ;
1434 space_array[0] = 0 ;
1436 for (i = 0 ; i < sixteen ; i++)
1437 space_array[i] = OLIAS_SPACE16 ;
1438 space_array[i] = 0 ;
1440 WXmString string_16(space_array, (char*)OLIAS_SPACE_FONT) ;
1442 space_array[0] = 0 ;
1444 for (i = 0 ; i < eight ; i++)
1445 space_array[i] = OLIAS_SPACE08 ;
1446 space_array[i] = 0 ;
1448 WXmString string_8(space_array, (char*)OLIAS_SPACE_FONT) ;
1450 space_array[0] = 0 ;
1452 for (i = 0 ; i < four; i++)
1453 space_array[i] = OLIAS_SPACE04 ;
1454 space_array[i] = 0 ;
1456 WXmString string_4(space_array, (char*)OLIAS_SPACE_FONT) ;
1458 space_array[0] = 0 ;
1460 for (i = 0 ; i < two ; i++)
1461 space_array[i] = OLIAS_SPACE02 ;
1462 space_array[i] = 0 ;
1464 WXmString string_2(space_array, (char*)OLIAS_SPACE_FONT) ;
1466 space_array[0] = 0 ;
1468 for (i = 0 ; i < one ; i++)
1469 space_array[i] = OLIAS_SPACE01 ;
1470 space_array[i] = 0 ;
1472 WXmString string_1(space_array, (char*)OLIAS_SPACE_FONT) ;
1474 WXmString space = string_32 + string_16 + string_8 + string_4 + string_2 + string_1 ;
1476 return space.disown();
1480 // /////////////////////////////////////////////////////////////////
1482 // /////////////////////////////////////////////////////////////////
1485 wait_for_wm (Widget, XtPointer client_data, XEvent *event, Boolean *)
1487 // See if the property we're waiting for has changed.
1488 if (event->type == PropertyNotify &&
1489 event->xproperty.atom == XA_WM_STATE)
1491 // Got our event. waiting_for_wm = False.
1492 *((bool *) client_data) = False;
1496 // /////////////////////////////////////////////////////////////////
1498 // /////////////////////////////////////////////////////////////////
1501 /* Here's how this routine works:
1503 For each shell window
1504 if the window needs to be restored
1506 restore the initial state to normal if it was iconic
1507 restore the size hints if there were any
1512 WindowSystem::show_all_windows()
1515 Boolean waiting_for_wm;
1517 for (unsigned int i = 0; i < f_shell_list.length(); i++)
1519 si = (Shell_Info *) f_shell_list[i];
1522 // Set up an event handler so we can tell when the window
1523 // manager has finished dealing with our map request.
1524 if (si->f_has_wm_state)
1526 waiting_for_wm = True;
1527 XtAddEventHandler (si->f_shell, PropertyChangeMask, False,
1528 (XtEventHandler) wait_for_wm,
1532 // Get the window back on the screen.
1533 XMapWindow (f_display, XtWindow (si->f_shell));
1535 // Wait for wm if one is running.
1536 if (si->f_has_wm_state)
1539 ON_DEBUG (printf ("Wait for wm to handle 0x%p", si->f_shell));
1540 while (waiting_for_wm)
1542 XtAppNextEvent (f_application_context, &event);
1543 XtDispatchEvent (&event);
1545 // Get rid of event handler now.
1546 XtRemoveEventHandler (si->f_shell, PropertyChangeMask, False,
1547 (XtEventHandler) wait_for_wm,
1551 ON_DEBUG (printf (" - done\n"));
1552 // Now that the wm is finished (if there is one), we can reset
1553 // the various state variables.
1556 // If it was iconic, reset the initial state.
1557 WWMShell (si->f_shell).InitialState (NormalState);
1561 // Restore the the size hints, because we set USPosition
1562 // and USSize to prevent interactive placement.
1563 if (si->f_has_size_hints)
1564 XSetWMNormalHints (f_display, XtWindow (si->f_shell),
1568 // Reset the restore flag.
1569 si->f_restore = FALSE;
1574 // /////////////////////////////////////////////////////////////////
1575 // generally necessary after a fork to avoid weird conditions
1576 // /////////////////////////////////////////////////////////////////
1579 WindowSystem::close_display_connection()
1581 close (ConnectionNumber(display()));
1585 // /////////////////////////////////////////////////////////////////
1586 // interrupt_handler - deal with user interrupt (usually ^C)
1587 // /////////////////////////////////////////////////////////////////
1590 WindowSystem::interrupt_handler (int /* signal_number */)
1592 // I'm probably forgetting why it's bad to call the message_mgr
1593 // from within the WindowSystem object. We'll find out why
1594 // eventually, I'm sure. 20:56 04-May-94 DJB
1598 if (!(window_system().videoShell()->silent)) {
1599 message_mgr().quit_dialog (
1600 (char*)UAS_String(CATGETS(Set_Messages, 6, "Quit Dtinfo?")));
1606 #if defined(SVR4) || defined(hpux) || defined(_IBMR2)
1607 signal (SIGINT, (interrupt_handler_ptr)interrupt_handler);