XEmacs 21.2-b1
[chise/xemacs-chise.git.1] / src / EmacsShell.c
1 /* Emacs shell widget -- glue.
2    Copyright (C) 1994, 1995 Sun Microsystems, Inc.
3
4 This file is part of XEmacs.
5
6 XEmacs is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
10
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with XEmacs; see the file COPYING.  If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21 /* Synched up with: Not in FSF. */
22
23 /* Written by Ben Wing, May, 1994. */
24
25 #include <config.h>
26
27 #include <stdio.h>
28 #include <stdlib.h>
29 #include <X11/StringDefs.h>
30 #include "xintrinsicp.h"
31 #include <X11/Shell.h>
32 #include <X11/ShellP.h>
33 #include <X11/Vendor.h>
34 #include <X11/VendorP.h>
35 #include "EmacsShell.h"
36 #include "ExternalShell.h"
37
38 #if 0 /* Not currently used */
39
40 /* The root_geometry_manager() method in Shell.c is fucked up with regard
41    to the user-specified-position vs. program-specified-position and
42    user-specified-size vs. program-specified-size flag. (It always
43    sets program-specified whenever the program requests a change
44    in its size or position, even when this came from direct user
45    request.) So we provide external entry points to fix this after
46    the program requested a size or position change.  If it turns
47    out that the user-specified-position flag needs to be set at the
48    *same* time that the geometry change request is made, then we
49    will have to duplicate the entire root_geometry_manager() method;
50    but I don't think there are any WM's that require this. */
51
52 /* junk stolen from IntrinsicI.h */
53
54 extern void _XtAllocError( String /* alloc_type */);
55
56 /* junk ungraciously copied from Shell.c */
57
58 static void ComputeWMSizeHints(w, hints)
59     WMShellWidget w;
60     XSizeHints *hints;
61 {
62     long flags;
63     hints->flags = flags = w->wm.size_hints.flags;
64 #define copy(field) hints->field = w->wm.size_hints.field
65     if (flags & (USPosition | PPosition)) {
66         copy(x);
67         copy(y);
68     }
69     if (flags & (USSize | PSize)) {
70         copy(width);
71         copy(height);
72     }
73     if (flags & PMinSize) {
74         copy(min_width);
75         copy(min_height);
76     }
77     if (flags & PMaxSize) {
78         copy(max_width);
79         copy(max_height);
80     }
81     if (flags & PResizeInc) {
82         copy(width_inc);
83         copy(height_inc);
84     }
85     if (flags & PAspect) {
86         copy(min_aspect.x);
87         copy(min_aspect.y);
88         copy(max_aspect.x);
89         copy(max_aspect.y);
90     }
91 #undef copy
92 #define copy(field) hints->field = w->wm.field
93     if (flags & PBaseSize) {
94         copy(base_width);
95         copy(base_height);
96     }
97     if (flags & PWinGravity)
98         copy(win_gravity);
99 #undef copy
100 }
101
102 static void _SetWMSizeHints(w)
103     WMShellWidget w;
104 {
105     XSizeHints *size_hints = XAllocSizeHints();
106
107     if (size_hints == NULL) _XtAllocError("XAllocSizeHints");
108     ComputeWMSizeHints(w, size_hints);
109     XSetWMNormalHints(XtDisplay((Widget)w), XtWindow((Widget)w), size_hints);
110     XFree((char*)size_hints);
111 }
112
113 /* end of junk ungraciously copied from Shell.c */
114
115 #endif /* 0 */
116 #if 0 /* Not currently used */
117
118 void
119 EmacsShellSetSizeUserSpecified (Widget gw)
120 {
121   WMShellWidget w = (WMShellWidget) gw;
122   w->wm.size_hints.flags |= USSize;
123   w->wm.size_hints.flags &= ~PSize;
124   if (!w->shell.override_redirect && XtIsRealized (gw))
125     _SetWMSizeHints (w);
126 }
127
128 void
129 EmacsShellSetPositionUserSpecified (Widget gw)
130 {
131   WMShellWidget w = (WMShellWidget) gw;
132   w->wm.size_hints.flags |= USPosition;
133   w->wm.size_hints.flags &= ~PPosition;
134   if (!w->shell.override_redirect && XtIsRealized (gw))
135     _SetWMSizeHints (w);
136 }
137
138 #endif /* 0 */
139
140 void
141 EmacsShellSmashIconicHint (Widget shell, int iconic_p)
142 {
143   /* See comment in xfns.c about this */
144   WMShellWidget wmshell;
145   int old, new;
146   if (! XtIsSubclass (shell, wmShellWidgetClass)) abort ();
147   wmshell = (WMShellWidget) shell;
148   old = (wmshell->wm.wm_hints.flags & StateHint
149          ? wmshell->wm.wm_hints.initial_state
150          : NormalState);
151   new = (iconic_p ? IconicState : NormalState);
152   wmshell->wm.wm_hints.flags |= StateHint;
153   wmshell->wm.wm_hints.initial_state = new;
154 }
155
156 void
157 EmacsShellUpdateSizeHints (Widget gw)
158 {
159   if (XtIsSubclass (gw, topLevelEmacsShellWidgetClass))
160     TopLevelEmacsShellUpdateSizeHints (gw);
161 #ifdef EXTERNAL_WIDGET
162   else if (XtIsSubclass (gw, externalShellWidgetClass))
163     /* do what ??? Don't abort! */;
164 #endif
165   else if (XtIsSubclass (gw, transientEmacsShellWidgetClass))
166     TransientEmacsShellUpdateSizeHints (gw);
167   else
168     abort ();
169 }