~ubuntu-branches/ubuntu/oneiric/clif/oneiric

« back to all changes in this revision

Viewing changes to wind_w.c

  • Committer: Bazaar Package Importer
  • Author(s): Adrian Bunk
  • Date: 2002-01-25 14:05:49 UTC
  • Revision ID: james.westby@ubuntu.com-20020125140549-v5mmddxqlcrgzhd2
Tags: upstream-0.93
ImportĀ upstreamĀ versionĀ 0.93

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
    Clif - A C-like Interpreter Framework
 
3
    Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997 T. Hruz, L. Koren
 
4
 
 
5
    This program is free software; you can redistribute it and/or modify
 
6
    it under the terms of the GNU General Public License as published by
 
7
    the Free Software Foundation; either version 2 of the License, or
 
8
    (at your option) any later version.
 
9
 
 
10
    This program is distributed in the hope that it will be useful,
 
11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
    GNU General Public License for more details.
 
14
 
 
15
    You should have received a copy of the GNU General Public License
 
16
    along with this program; if not, write to the Free Software
 
17
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
18
 
 
19
*/
 
20
 
 
21
/*
 
22
 * wind_w.c
 
23
 *
 
24
 * Alphanumerical window opening.
 
25
 */
 
26
#include <X11/Xlib.h>
 
27
 
 
28
 
 
29
#ifndef PROTO
 
30
#if defined (USE_PROTOTYPES) ? USE_PROTOTYPES : defined(__STDC__)
 
31
#define PROTO(ARGS) ARGS
 
32
#else
 
33
#define PROTO(ARGS) ()
 
34
#endif 
 
35
#endif
 
36
 
 
37
extern char *callocx PROTO((unsigned, unsigned));
 
38
extern void error_message PROTO((int));
 
39
 
 
40
 
 
41
XGCValues value;
 
42
XEvent event;
 
43
 
 
44
 
 
45
char **list;
 
46
char *path;
 
47
int *act_cnt;
 
48
 
 
49
int wind_w PROTO((void));
 
50
 
 
51
int
 
52
wind_w ()
 
53
{
 
54
#ifdef FORK_YES
 
55
  char arg1[32], arg2[32];
 
56
#endif
 
57
 
 
58
  if ((disp = XOpenDisplay (NULL)) == NULL)
 
59
    {
 
60
      printf (" XOpen fails write\n");
 
61
      return (-1);
 
62
    }
 
63
 
 
64
#if 0
 
65
  XSynchronize(disp,1);
 
66
#endif
 
67
 
 
68
  root = XDefaultRootWindow (disp);
 
69
  screen = XDefaultScreen (disp);
 
70
 
 
71
#if 0
 
72
  if (!XGetWindowAttributes (disp, root, &root_window_att))
 
73
    {
 
74
      printf ("get window att failed \n");
 
75
      exit (0);
 
76
    }
 
77
 
 
78
  XSynchronize (disp, 1);
 
79
#endif
 
80
 
 
81
  width = XDisplayWidth (disp, screen);
 
82
#if 0
 
83
  XSynchronize (disp, 1);
 
84
#endif
 
85
  height = XDisplayHeight (disp, screen);
 
86
#if 0
 
87
  XSynchronize (disp, 1);
 
88
  printf ("w: %d, h: %d \n", width, height);
 
89
 
 
90
  default_gc = XDefaultGC (disp, screen);
 
91
  XSynchronize (disp, 1);
 
92
 
 
93
  XSetState (disp, default_gc, 0xffffffL, 0L, GXcopy, 0xffffffffL);
 
94
  XSynchronize (disp, 1);
 
95
  printf ("xsetstate\n");
 
96
#endif
 
97
 
 
98
 
 
99
 
 
100
  width_w = 400;
 
101
  height_w = (((int)(channel[channel_handle].fields/5)) + 1) * 15;
 
102
 
 
103
 
 
104
 
 
105
  /* 
 
106
   * Window attributes.
 
107
   */
 
108
  mywin_att.background_pixmap = None;
 
109
  mywin_att.background_pixel = 0L;
 
110
  mywin_att.border_pixmap = CopyFromParent;
 
111
  mywin_att.border_pixel = 1L;
 
112
  mywin_att.bit_gravity = ForgetGravity;
 
113
  mywin_att.win_gravity = NorthWestGravity;
 
114
  mywin_att.backing_store = Always;
 
115
  mywin_att.backing_planes = 0xffffffffL;
 
116
  mywin_att.backing_pixel = 0L;
 
117
  mywin_att.save_under = True;
 
118
  mywin_att.event_mask = KeyPressMask|ExposureMask|ButtonPressMask|VisibilityChangeMask|SubstructureNotifyMask|StructureNotifyMask;
 
119
  mywin_att.do_not_propagate_mask = NoEventMask;
 
120
  mywin_att.override_redirect = False;
 
121
  mywin_att.colormap = CopyFromParent;
 
122
  mywin_att.cursor = None;
 
123
 
 
124
 
 
125
  /* 
 
126
   * Creates a window.
 
127
   */
 
128
 
 
129
  channel[channel_handle].mywin_write
 
130
    = XCreateWindow (disp, root, x, y, width_w, height_w, border,
 
131
                     CopyFromParent, InputOutput, CopyFromParent,
 
132
                     CWBackPixel|CWSaveUnder|CWBackingStore|CWEventMask|CWBackingPlanes|CWDontPropagate,
 
133
                     &mywin_att);
 
134
 
 
135
 
 
136
#ifdef FORK_YES
 
137
  /* 
 
138
   * Creates a pixmap.
 
139
   * It is used when the exposure event occurs.
 
140
   */
 
141
  channel[channel_handle].mypix_write
 
142
    = XCreatePixmap (disp, channel[channel_handle].mywin_write,
 
143
                     width_w, height_w, XDefaultDepth (disp, screen));
 
144
#endif
 
145
#if 0
 
146
  XSynchronize (disp, 1);
 
147
  printf ("xcreatewritewindow\n");
 
148
#endif
 
149
 
 
150
  value.background = 0L;
 
151
  value.graphics_exposures = True;
 
152
  value.foreground = 0xffffffL;
 
153
 
 
154
  set_gc_write = XCreateGC (disp, channel[channel_handle].mywin_write,
 
155
                            GCForeground|GCBackground|GCGraphicsExposures,
 
156
                            &value);
 
157
 
 
158
 
 
159
 
 
160
  XClearWindow (disp, channel[channel_handle].mywin_write);
 
161
#ifdef FORK_YES
 
162
  XFillRectangle (disp, channel[channel_handle].mypix_write,
 
163
                  default_gc, 0, 0,
 
164
                  channel[channel_handle].w_resolution[0],
 
165
                  channel[channel_handle].w_resolution[1]);
 
166
#endif
 
167
#if 0
 
168
  XSynchronize (disp, 1);
 
169
#endif
 
170
 
 
171
/*
 
172
 * Name of the window.
 
173
 */
 
174
  sprintf (window_name_tmp, "%d", channel_handle);
 
175
  strcat (window_name_wr_cur, window_name_tmp);
 
176
  XStoreName (disp, channel[channel_handle].mywin_write,
 
177
              window_name_wr_cur);
 
178
  strcpy (window_name_wr_cur, window_name_wr_init);
 
179
#if 0
 
180
  XSynchronize (disp, 1);
 
181
  printf ("xstowriterename\n");
 
182
#endif
 
183
 
 
184
  XMapWindow (disp, channel[channel_handle].mywin_write);
 
185
#if 0
 
186
  XSynchronize (disp, 1);
 
187
  printf ("xmapwritewindow\n");
 
188
 
 
189
 
 
190
  XSynchronize (disp, 1);
 
191
 
 
192
 
 
193
  channel[channel_handle].item.chars=" ";
 
194
  channel[channel_handle].item.nchars
 
195
    = strlen (channel[channel_handle].item.chars);
 
196
#endif
 
197
 
 
198
  channel[channel_handle].item.delta = 1;
 
199
  channel[channel_handle].item.font = None;
 
200
 
 
201
#if 0
 
202
  printf ("item filled\n");
 
203
#endif
 
204
 
 
205
/*
 
206
 * Managing fonts.
 
207
 */
 
208
  XSetFontPath (disp, &path, 0);
 
209
#if 0 
 
210
  printf ("xsetfontpath\n");
 
211
#endif
 
212
 
 
213
  if ((act_cnt = (int *) callocx (1, sizeof(int))) == NULL)
 
214
    {
 
215
      error_message (4002);
 
216
      return (-3);
 
217
    }
 
218
  while (*act_cnt == 0)
 
219
    list = XListFonts (disp, "*", 10, act_cnt);
 
220
 
 
221
#if 0
 
222
  printf ("xlistfonts\n");
 
223
#endif
 
224
 
 
225
  channel[channel_handle].item.font = XLoadFont (disp, list[0]);
 
226
#if 0
 
227
  printf ("xloadfont\n");
 
228
#endif
 
229
  channel[channel_handle].myfont
 
230
    = XQueryFont (disp, channel[channel_handle].item.font);
 
231
#if 0
 
232
printf ("xqueryfont\n");
 
233
#endif
 
234
 
 
235
 
 
236
/*
 
237
 * Fork for managers that cannot manage exposure events.
 
238
 */
 
239
#ifdef FORK_YES
 
240
  if ((channel[channel_handle].ch_pid_write = fork ()) < 0)
 
241
    printf ("could not fork %d\n", errno);
 
242
  else if(channel[channel_handle].ch_pid_write == 0)     /* child */
 
243
    {
 
244
      sprintf (arg1, "%ld", channel[channel_handle].mywin_write);
 
245
      sprintf (arg2, "%ld", channel[channel_handle].mypix_write);
 
246
#if 0
 
247
      printf ("fork child\n");
 
248
#endif
 
249
      execl ("rw", "rw", arg1, arg2, (char *)0);
 
250
      printf ("errno %d\n", errno);
 
251
      printf ("bad exec\n");
 
252
    }
 
253
      /* parent */
 
254
#endif /* FORK_YES */
 
255
  return (0);
 
256
}