comparison src/w32xfns.c @ 15153:c1494aa589e8

Include frame.h. (hEvent): Renamed to h_input_available. (init_crit, delete_crit, get_next_msg, post_msg): Use h_input_available. (GetFrameDC, ReleaseFrameDC): New functions. (leave_crit): Function removed.
author Geoff Voelker <voelker@cs.washington.edu>
date Fri, 03 May 1996 18:49:20 +0000
parents 61fc696a0c6a
children 481b7874a1e9
comparison
equal deleted inserted replaced
15152:2dd4961cefaa 15153:c1494aa589e8
20 20
21 #include <signal.h> 21 #include <signal.h>
22 #include <config.h> 22 #include <config.h>
23 #include <stdio.h> 23 #include <stdio.h>
24 #include "lisp.h" 24 #include "lisp.h"
25 #include "frame.h"
25 #include "blockinput.h" 26 #include "blockinput.h"
26 #include "w32term.h" 27 #include "w32term.h"
27 #include "windowsx.h" 28 #include "windowsx.h"
28 29
29 #define myalloc(cb) GlobalAllocPtr (GPTR, cb) 30 #define myalloc(cb) GlobalAllocPtr (GPTR, cb)
30 #define myfree(lp) GlobalFreePtr (lp) 31 #define myfree(lp) GlobalFreePtr (lp)
31 32
32 CRITICAL_SECTION critsect; 33 CRITICAL_SECTION critsect;
33 extern HANDLE keyboard_handle; 34 extern HANDLE keyboard_handle;
34 HANDLE hEvent = NULL; 35 HANDLE input_available = NULL;
35 36
36 void 37 void
37 init_crit () 38 init_crit ()
38 { 39 {
39 InitializeCriticalSection (&critsect); 40 InitializeCriticalSection (&critsect);
40 keyboard_handle = hEvent = CreateEvent (NULL, FALSE, FALSE, NULL); 41
41 } 42 /* For safety, input_available should only be reset by get_next_msg
42 43 when the input queue is empty, so make it a manual reset event. */
43 void 44 keyboard_handle = input_available = CreateEvent (NULL, TRUE, FALSE, NULL);
44 enter_crit ()
45 {
46 EnterCriticalSection (&critsect);
47 }
48
49 void
50 leave_crit ()
51 {
52 LeaveCriticalSection (&critsect);
53 } 45 }
54 46
55 void 47 void
56 delete_crit () 48 delete_crit ()
57 { 49 {
58 DeleteCriticalSection (&critsect); 50 DeleteCriticalSection (&critsect);
59 if (hEvent) 51
60 { 52 if (input_available)
61 CloseHandle (hEvent); 53 {
62 hEvent = NULL; 54 CloseHandle (input_available);
63 } 55 input_available = NULL;
56 }
57 }
58
59 void
60 select_palette (FRAME_PTR f, HDC hdc)
61 {
62 if (!NILP (Vwin32_enable_palette))
63 f->output_data.win32->old_palette =
64 SelectPalette (hdc, one_win32_display_info.palette, FALSE);
65 else
66 f->output_data.win32->old_palette = NULL;
67
68 if (RealizePalette (hdc))
69 {
70 Lisp_Object frame, framelist;
71 FOR_EACH_FRAME (framelist, frame)
72 {
73 SET_FRAME_GARBAGED (XFRAME (frame));
74 }
75 }
76 }
77
78 void
79 deselect_palette (FRAME_PTR f, HDC hdc)
80 {
81 if (f->output_data.win32->old_palette)
82 SelectPalette (hdc, f->output_data.win32->old_palette, FALSE);
83 }
84
85 /* Get a DC for frame and select palette for drawing; force an update of
86 all frames if palette's mapping changes. */
87 HDC
88 get_frame_dc (FRAME_PTR f)
89 {
90 HDC hdc;
91
92 enter_crit ();
93
94 hdc = GetDC (f->output_data.win32->window_desc);
95 select_palette (f, hdc);
96
97 return hdc;
98 }
99
100 int
101 release_frame_dc (FRAME_PTR f, HDC hdc)
102 {
103 int ret;
104
105 deselect_palette (f, hdc);
106 ret = ReleaseDC (f->output_data.win32->window_desc, hdc);
107
108 leave_crit ();
109
110 return ret;
64 } 111 }
65 112
66 typedef struct int_msg 113 typedef struct int_msg
67 { 114 {
68 Win32Msg w32msg; 115 Win32Msg w32msg;
85 /* The while loop takes care of multiple sets */ 132 /* The while loop takes care of multiple sets */
86 133
87 while (!nQueue && bWait) 134 while (!nQueue && bWait)
88 { 135 {
89 leave_crit (); 136 leave_crit ();
90 WaitForSingleObject (hEvent, INFINITE); 137 WaitForSingleObject (input_available, INFINITE);
91 enter_crit (); 138 enter_crit ();
92 } 139 }
93 140
94 if (nQueue) 141 if (nQueue)
95 { 142 {
105 152
106 nQueue--; 153 nQueue--;
107 154
108 bRet = TRUE; 155 bRet = TRUE;
109 } 156 }
157
158 if (nQueue == 0)
159 ResetEvent (input_available);
110 160
111 leave_crit (); 161 leave_crit ();
112 162
113 return (bRet); 163 return (bRet);
114 } 164 }
117 post_msg (lpmsg) 167 post_msg (lpmsg)
118 Win32Msg * lpmsg; 168 Win32Msg * lpmsg;
119 { 169 {
120 int_msg * lpNew = (int_msg *) myalloc (sizeof (int_msg)); 170 int_msg * lpNew = (int_msg *) myalloc (sizeof (int_msg));
121 171
122 if (!lpNew) return (FALSE); 172 if (!lpNew)
173 return (FALSE);
123 174
124 bcopy (lpmsg, &(lpNew->w32msg), sizeof (Win32Msg)); 175 bcopy (lpmsg, &(lpNew->w32msg), sizeof (Win32Msg));
125 lpNew->lpNext = NULL; 176 lpNew->lpNext = NULL;
126 177
127 enter_crit (); 178 enter_crit ();
131 lpTail->lpNext = lpNew; 182 lpTail->lpNext = lpNew;
132 } 183 }
133 else 184 else
134 { 185 {
135 lpHead = lpNew; 186 lpHead = lpNew;
136 SetEvent (hEvent);
137 } 187 }
138 188
139 lpTail = lpNew; 189 lpTail = lpNew;
190 SetEvent (input_available);
140 191
141 leave_crit (); 192 leave_crit ();
142 193
143 return (TRUE); 194 return (TRUE);
144 } 195 }