Commit | Line | Data |
---|---|---|
de31b97a | 1 | /* Definitions and headers for communication on the Microsoft W32 API. |
c3b8ccce GV |
2 | Copyright (C) 1995 Free Software Foundation, Inc. |
3 | ||
4 | This file is part of GNU Emacs. | |
5 | ||
6 | GNU Emacs is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GNU Emacs is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU Emacs; see the file COPYING. If not, write to | |
3b7ad313 EN |
18 | the Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
19 | Boston, MA 02111-1307, USA. */ | |
c3b8ccce GV |
20 | |
21 | /* Added by Kevin Gallo */ | |
22 | ||
07bc5c0b | 23 | #include <w32gui.h> |
c3b8ccce GV |
24 | |
25 | /* The class of this X application. */ | |
26 | #define EMACS_CLASS "Emacs" | |
27 | \f | |
3fed86ff GV |
28 | #define BLACK_PIX_DEFAULT(f) PALETTERGB(0,0,0) |
29 | #define WHITE_PIX_DEFAULT(f) PALETTERGB(255,255,255) | |
c3b8ccce | 30 | |
25d9ec8c GV |
31 | #define FONT_WIDTH(f) \ |
32 | ((f)->bdf ? (f)->bdf->width : (f)->tm.tmAveCharWidth) | |
33 | #define FONT_HEIGHT(f) \ | |
34 | ((f)->bdf ? (f)->bdf->height : (f)->tm.tmHeight) | |
35 | /* No idea why 5 seems to work in here, but it does */ | |
36 | #define FONT_BASE(f) \ | |
37 | ((f)->bdf ? (f)->bdf->ury : (f)->tm.tmAscent) | |
38 | #define FONT_MAX_WIDTH(f) \ | |
39 | ((f)->bdf ? (f)->bdf->width : (f)->tm.tmMaxCharWidth) | |
c3b8ccce | 40 | |
fbd6baed | 41 | #define CHECK_W32_FRAME(f, frame) \ |
c3b8ccce GV |
42 | if (NILP (frame)) \ |
43 | f = selected_frame; \ | |
44 | else \ | |
45 | { \ | |
46 | CHECK_LIVE_FRAME (frame, 0); \ | |
47 | f = XFRAME (frame); \ | |
48 | } \ | |
fbd6baed | 49 | if (! FRAME_W32_P (f)) |
c3b8ccce GV |
50 | |
51 | /* Indicates whether we are in the readsocket call and the message we | |
52 | are processing in the current loop */ | |
53 | ||
54 | extern MSG CurMsg; | |
55 | extern BOOL bUseDflt; | |
56 | ||
57 | extern struct frame *x_window_to_frame (); | |
58 | ||
59 | enum text_cursor_kinds { | |
60 | filled_box_cursor, hollow_box_cursor, bar_cursor | |
61 | }; | |
62 | ||
c3b8ccce GV |
63 | /* Structure recording bitmaps and reference count. |
64 | If REFCOUNT is 0 then this record is free to be reused. */ | |
65 | ||
fbd6baed | 66 | struct w32_bitmap_record |
c3b8ccce GV |
67 | { |
68 | Pixmap pixmap; | |
69 | char *file; | |
70 | HINSTANCE hinst; /* Used to load the file */ | |
71 | int refcount; | |
72 | /* Record some info about this pixmap. */ | |
73 | int height, width, depth; | |
74 | }; | |
aba66c88 GV |
75 | |
76 | /* Palette book-keeping stuff for mapping requested colors into the | |
77 | system palette. Keep a ref-counted list of requested colors and | |
78 | regenerate the app palette whenever the requested list changes. */ | |
79 | ||
fbd6baed | 80 | extern Lisp_Object Vw32_enable_palette; |
aba66c88 | 81 | |
fbd6baed GV |
82 | struct w32_palette_entry { |
83 | struct w32_palette_entry * next; | |
aba66c88 GV |
84 | PALETTEENTRY entry; |
85 | #if 0 | |
86 | unsigned refcount; | |
87 | #endif | |
88 | }; | |
89 | ||
fbd6baed | 90 | extern void w32_regenerate_palette(struct frame *f); |
aba66c88 | 91 | |
c3b8ccce | 92 | \f |
fbd6baed | 93 | /* For each display (currently only one on w32), we have a structure that |
c3b8ccce GV |
94 | records information about it. */ |
95 | ||
fbd6baed | 96 | struct w32_display_info |
c3b8ccce | 97 | { |
fbd6baed GV |
98 | /* Chain of all w32_display_info structures. */ |
99 | struct w32_display_info *next; | |
c3b8ccce GV |
100 | /* This is a cons cell of the form (NAME . FONT-LIST-CACHE). |
101 | The same cons cell also appears in x_display_name_list. */ | |
102 | Lisp_Object name_list_element; | |
103 | /* Number of frames that are on this display. */ | |
104 | int reference_count; | |
105 | /* Number of planes on this screen. */ | |
106 | int n_planes; | |
107 | /* Number of bits per pixel on this screen. */ | |
108 | int n_cbits; | |
109 | /* Dimensions of this screen. */ | |
110 | int height, width; | |
111 | int height_in,width_in; | |
112 | /* Mask of things that cause the mouse to be grabbed. */ | |
113 | int grabbed; | |
114 | /* The root window of this screen. */ | |
115 | Window root_window; | |
116 | /* The cursor to use for vertical scroll bars. */ | |
117 | Cursor vertical_scroll_bar_cursor; | |
118 | ||
bb355434 | 119 | /* color palette information. */ |
aba66c88 | 120 | int has_palette; |
fbd6baed | 121 | struct w32_palette_entry * color_list; |
aba66c88 GV |
122 | unsigned num_colors; |
123 | HPALETTE palette; | |
124 | ||
bb355434 | 125 | /* deferred action flags checked when starting frame update. */ |
aba66c88 GV |
126 | int regen_palette; |
127 | ||
bb355434 GV |
128 | /* Keystroke that has been faked by Emacs and will be ignored when |
129 | received; value is reset after key is received. */ | |
130 | int faked_key; | |
131 | ||
c3b8ccce GV |
132 | /* A table of all the fonts we have already loaded. */ |
133 | struct font_info *font_table; | |
134 | ||
d82f9149 | 135 | /* The current capacity of font_table. */ |
c3b8ccce GV |
136 | int font_table_size; |
137 | ||
138 | /* These variables describe the range of text currently shown | |
139 | in its mouse-face, together with the window they apply to. | |
140 | As long as the mouse stays within this range, we need not | |
141 | redraw anything on its account. */ | |
142 | int mouse_face_beg_row, mouse_face_beg_col; | |
143 | int mouse_face_end_row, mouse_face_end_col; | |
144 | int mouse_face_past_end; | |
145 | Lisp_Object mouse_face_window; | |
146 | int mouse_face_face_id; | |
147 | ||
148 | /* 1 if a mouse motion event came and we didn't handle it right away because | |
149 | gc was in progress. */ | |
150 | int mouse_face_deferred_gc; | |
151 | ||
152 | /* FRAME and X, Y position of mouse when last checked for | |
153 | highlighting. X and Y can be negative or out of range for the frame. */ | |
154 | struct frame *mouse_face_mouse_frame; | |
155 | int mouse_face_mouse_x, mouse_face_mouse_y; | |
156 | ||
157 | /* Nonzero means defer mouse-motion highlighting. */ | |
158 | int mouse_face_defer; | |
159 | ||
fbd6baed | 160 | char *w32_id_name; |
c3b8ccce | 161 | |
fbd6baed | 162 | /* The number of fonts actually stored in w32_font_table. |
c3b8ccce GV |
163 | font_table[n] is used and valid iff 0 <= n < n_fonts. |
164 | 0 <= n_fonts <= font_table_size. */ | |
165 | int n_fonts; | |
166 | ||
167 | /* Pointer to bitmap records. */ | |
fbd6baed | 168 | struct w32_bitmap_record *bitmaps; |
c3b8ccce GV |
169 | |
170 | /* Allocated size of bitmaps field. */ | |
171 | int bitmaps_size; | |
172 | ||
173 | /* Last used bitmap index. */ | |
174 | int bitmaps_last; | |
175 | ||
176 | /* The frame (if any) which has the window that has keyboard focus. | |
177 | Zero if none. This is examined by Ffocus_frame in w32fns.c. Note | |
178 | that a mere EnterNotify event can set this; if you need to know the | |
179 | last frame specified in a FocusIn or FocusOut event, use | |
fbd6baed GV |
180 | w32_focus_event_frame. */ |
181 | struct frame *w32_focus_frame; | |
c3b8ccce GV |
182 | |
183 | /* The last frame mentioned in a FocusIn or FocusOut event. This is | |
fbd6baed | 184 | separate from w32_focus_frame, because whether or not LeaveNotify |
c3b8ccce GV |
185 | events cause us to lose focus depends on whether or not we have |
186 | received a FocusIn event for it. */ | |
fbd6baed | 187 | struct frame *w32_focus_event_frame; |
c3b8ccce GV |
188 | |
189 | /* The frame which currently has the visual highlight, and should get | |
190 | keyboard input (other sorts of input have the frame encoded in the | |
191 | event). It points to the focus frame's selected window's | |
fbd6baed | 192 | frame. It differs from w32_focus_frame when we're using a global |
c3b8ccce | 193 | minibuffer. */ |
fbd6baed | 194 | struct frame *w32_highlight_frame; |
c3b8ccce GV |
195 | }; |
196 | ||
197 | /* This is a chain of structures for all the displays currently in use. */ | |
fbd6baed | 198 | extern struct w32_display_info one_w32_display_info; |
c3b8ccce GV |
199 | |
200 | /* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE), | |
fbd6baed | 201 | one for each element of w32_display_list and in the same order. |
c3b8ccce GV |
202 | NAME is the name of the frame. |
203 | FONT-LIST-CACHE records previous values returned by x-list-fonts. */ | |
fbd6baed | 204 | extern Lisp_Object w32_display_name_list; |
c3b8ccce | 205 | |
d82f9149 GV |
206 | /* Regexp matching a font name whose width is the same as `PIXEL_SIZE'. */ |
207 | extern Lisp_Object Vx_pixel_size_width_font_regexp; | |
208 | ||
209 | /* A flag to control how to display unibyte 8-bit character. */ | |
210 | extern int unibyte_display_via_language_environment; | |
211 | ||
fbd6baed GV |
212 | extern struct w32_display_info *x_display_info_for_display (); |
213 | extern struct w32_display_info *x_display_info_for_name (); | |
c3b8ccce | 214 | |
fbd6baed | 215 | extern struct w32_display_info *w32_term_init (); |
c3b8ccce | 216 | \f |
d82f9149 GV |
217 | extern Lisp_Object w32_list_fonts (); |
218 | extern struct font_info *w32_get_font_info (), *w32_query_font (); | |
219 | extern void w32_find_ccl_program(); | |
220 | \f | |
fbd6baed GV |
221 | /* Each W32 frame object points to its own struct w32_display object |
222 | in the output_data.w32 field. The w32_display structure contains all | |
223 | the information that is specific to W32 windows. */ | |
c3b8ccce | 224 | |
fbd6baed | 225 | struct w32_output |
c3b8ccce | 226 | { |
8694f11b GV |
227 | /* Menubar "widget" handle. */ |
228 | HMENU menubar_widget; | |
229 | ||
aba66c88 GV |
230 | /* Original palette (used to deselect real palette after drawing) */ |
231 | HPALETTE old_palette; | |
232 | ||
fbd6baed | 233 | /* Position of the W32 window (x and y offsets in root window). */ |
c3b8ccce GV |
234 | int left_pos; |
235 | int top_pos; | |
236 | ||
fbd6baed | 237 | /* Border width of the W32 window as known by the window system. */ |
c3b8ccce GV |
238 | int border_width; |
239 | ||
fbd6baed | 240 | /* Size of the W32 window in pixels. */ |
c3b8ccce GV |
241 | int pixel_height, pixel_width; |
242 | ||
243 | /* Height of a line, in pixels. */ | |
244 | int line_height; | |
245 | ||
246 | /* Width of the internal border. This is a line of background color | |
247 | just inside the window's border. When the frame is selected, | |
248 | a highlighting is displayed inside the internal border. */ | |
249 | int internal_border_width; | |
250 | ||
251 | /* The window used for this frame. | |
252 | May be zero while the frame object is being created | |
253 | and the window has not yet been created. */ | |
254 | Window window_desc; | |
255 | ||
256 | /* The window that is the parent of this window. | |
257 | Usually this is a window that was made by the window manager, | |
258 | but it can be the root window, and it can be explicitly specified | |
259 | (see the explicit_parent field, below). */ | |
260 | Window parent_desc; | |
261 | ||
d82f9149 | 262 | /* Default ASCII font of this frame. */ |
c3b8ccce GV |
263 | XFontStruct *font; |
264 | ||
d82f9149 GV |
265 | /* The baseline position of the default ASCII font. */ |
266 | int font_baseline; | |
267 | ||
268 | /* If a fontset is specified for this frame instead of font, this | |
269 | value contains an ID of the fontset, else -1. */ | |
270 | int fontset; | |
271 | ||
c3b8ccce GV |
272 | /* Pixel values used for various purposes. |
273 | border_pixel may be -1 meaning use a gray tile. */ | |
274 | unsigned long background_pixel; | |
275 | unsigned long foreground_pixel; | |
276 | unsigned long cursor_pixel; | |
277 | unsigned long border_pixel; | |
278 | unsigned long mouse_pixel; | |
279 | unsigned long cursor_foreground_pixel; | |
280 | ||
281 | /* Descriptor for the cursor in use for this window. */ | |
282 | Cursor text_cursor; | |
283 | Cursor nontext_cursor; | |
284 | Cursor modeline_cursor; | |
285 | Cursor cross_cursor; | |
286 | ||
287 | /* Flag to set when the window needs to be completely repainted. */ | |
288 | int needs_exposure; | |
289 | ||
290 | /* What kind of text cursor is drawn in this window right now? | |
291 | (If there is no cursor (phys_cursor_x < 0), then this means nothing.) */ | |
292 | enum text_cursor_kinds current_cursor; | |
293 | ||
294 | /* What kind of text cursor should we draw in the future? | |
295 | This should always be filled_box_cursor or bar_cursor. */ | |
296 | enum text_cursor_kinds desired_cursor; | |
297 | ||
298 | /* Width of bar cursor (if we are using that). */ | |
299 | int cursor_width; | |
300 | ||
301 | DWORD dwStyle; | |
302 | ||
303 | /* The size of the extra width currently allotted for vertical | |
304 | scroll bars, in pixels. */ | |
305 | int vertical_scroll_bar_extra; | |
306 | ||
307 | /* Table of parameter faces for this frame. Any resources (pixel | |
308 | values, fonts) referred to here have been allocated explicitly | |
309 | for this face, and should be freed if we change the face. */ | |
310 | struct face **param_faces; | |
311 | int n_param_faces; | |
312 | ||
313 | /* Table of computed faces for this frame. These are the faces | |
314 | whose indexes go into the upper bits of a glyph, computed by | |
315 | combining the parameter faces specified by overlays, text | |
316 | properties, and what have you. The resources mentioned here | |
317 | are all shared with parameter faces. */ | |
318 | struct face **computed_faces; | |
319 | int n_computed_faces; /* How many are valid */ | |
320 | int size_computed_faces; /* How many are allocated */ | |
321 | ||
322 | /* This is the gravity value for the specified window position. */ | |
323 | int win_gravity; | |
324 | ||
325 | /* The geometry flags for this window. */ | |
326 | int size_hint_flags; | |
327 | ||
328 | /* This is the Emacs structure for the display this frame is on. */ | |
fbd6baed | 329 | /* struct w32_display_info *display_info; */ |
c3b8ccce GV |
330 | |
331 | /* Nonzero means our parent is another application's window | |
332 | and was explicitly specified. */ | |
333 | char explicit_parent; | |
334 | ||
335 | /* Nonzero means tried already to make this frame visible. */ | |
336 | char asked_for_visible; | |
8694f11b GV |
337 | |
338 | /* Nonzero means menubar is currently active. */ | |
339 | char menubar_active; | |
340 | ||
341 | /* Nonzero means menubar is about to become active, but should be | |
342 | brought up to date first. */ | |
343 | volatile char pending_menu_activation; | |
c3b8ccce GV |
344 | }; |
345 | ||
2d764c78 EZ |
346 | /* A (mostly empty) structure describing a w32 terminal frame display. */ |
347 | extern struct w32_output w32term_display; | |
348 | ||
c3b8ccce | 349 | /* Get at the computed faces of an X window frame. */ |
fbd6baed GV |
350 | #define FRAME_PARAM_FACES(f) ((f)->output_data.w32->param_faces) |
351 | #define FRAME_N_PARAM_FACES(f) ((f)->output_data.w32->n_param_faces) | |
c3b8ccce GV |
352 | #define FRAME_DEFAULT_PARAM_FACE(f) (FRAME_PARAM_FACES (f)[0]) |
353 | #define FRAME_MODE_LINE_PARAM_FACE(f) (FRAME_PARAM_FACES (f)[1]) | |
354 | ||
fbd6baed GV |
355 | #define FRAME_COMPUTED_FACES(f) ((f)->output_data.w32->computed_faces) |
356 | #define FRAME_N_COMPUTED_FACES(f) ((f)->output_data.w32->n_computed_faces) | |
357 | #define FRAME_SIZE_COMPUTED_FACES(f) ((f)->output_data.w32->size_computed_faces) | |
358 | #define FRAME_DEFAULT_FACE(f) ((f)->output_data.w32->computed_faces[0]) | |
359 | #define FRAME_MODE_LINE_FACE(f) ((f)->output_data.w32->computed_faces[1]) | |
c3b8ccce GV |
360 | |
361 | /* Return the window associated with the frame F. */ | |
fbd6baed | 362 | #define FRAME_W32_WINDOW(f) ((f)->output_data.w32->window_desc) |
c3b8ccce | 363 | |
fbd6baed GV |
364 | #define FRAME_FOREGROUND_PIXEL(f) ((f)->output_data.w32->foreground_pixel) |
365 | #define FRAME_BACKGROUND_PIXEL(f) ((f)->output_data.w32->background_pixel) | |
366 | #define FRAME_FONT(f) ((f)->output_data.w32->font) | |
d82f9149 | 367 | #define FRAME_FONTSET(f) ((f)->output_data.w32->fontset) |
fbd6baed | 368 | #define FRAME_INTERNAL_BORDER_WIDTH(f) ((f)->output_data.w32->internal_border_width) |
c3b8ccce | 369 | |
fbd6baed GV |
370 | /* This gives the w32_display_info structure for the display F is on. */ |
371 | #define FRAME_W32_DISPLAY_INFO(f) (&one_w32_display_info) | |
c3b8ccce | 372 | |
d82f9149 GV |
373 | /* This is the 'font_info *' which frame F has. */ |
374 | #define FRAME_W32_FONT_TABLE(f) (FRAME_W32_DISPLAY_INFO (f)->font_table) | |
375 | ||
c3b8ccce | 376 | /* These two really ought to be called FRAME_PIXEL_{WIDTH,HEIGHT}. */ |
fbd6baed GV |
377 | #define PIXEL_WIDTH(f) ((f)->output_data.w32->pixel_width) |
378 | #define PIXEL_HEIGHT(f) ((f)->output_data.w32->pixel_height) | |
379 | #define FRAME_LINE_HEIGHT(f) ((f)->output_data.w32->line_height) | |
c3b8ccce | 380 | |
fbd6baed | 381 | #define FRAME_DESIRED_CURSOR(f) ((f)->output_data.w32->desired_cursor) |
c3b8ccce GV |
382 | |
383 | \f | |
fbd6baed | 384 | /* W32-specific scroll bar stuff. */ |
c3b8ccce GV |
385 | |
386 | /* We represent scroll bars as lisp vectors. This allows us to place | |
387 | references to them in windows without worrying about whether we'll | |
388 | end up with windows referring to dead scroll bars; the garbage | |
389 | collector will free it when its time comes. | |
390 | ||
391 | We use struct scroll_bar as a template for accessing fields of the | |
392 | vector. */ | |
393 | ||
394 | struct scroll_bar { | |
395 | ||
396 | /* These fields are shared by all vectors. */ | |
397 | EMACS_INT size_from_Lisp_Vector_struct; | |
398 | struct Lisp_Vector *next_from_Lisp_Vector_struct; | |
399 | ||
400 | /* The window we're a scroll bar for. */ | |
401 | Lisp_Object window; | |
402 | ||
403 | /* The next and previous in the chain of scroll bars in this frame. */ | |
404 | Lisp_Object next, prev; | |
405 | ||
406 | /* The window representing this scroll bar. Since this is a full | |
407 | 32-bit quantity, we store it split into two 32-bit values. */ | |
fbd6baed | 408 | Lisp_Object w32_window_low, w32_window_high; |
c3b8ccce GV |
409 | |
410 | /* The position and size of the scroll bar in pixels, relative to the | |
411 | frame. */ | |
412 | Lisp_Object top, left, width, height; | |
413 | ||
414 | /* The starting and ending positions of the handle, relative to the | |
415 | handle area (i.e. zero is the top position, not | |
416 | SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle | |
417 | hasn't been drawn yet. | |
418 | ||
419 | These are not actually the locations where the beginning and end | |
420 | are drawn; in order to keep handles from becoming invisible when | |
421 | editing large files, we establish a minimum height by always | |
422 | drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below | |
423 | where they would be normally; the bottom and top are in a | |
424 | different co-ordinate system. */ | |
425 | Lisp_Object start, end; | |
426 | ||
427 | /* If the scroll bar handle is currently being dragged by the user, | |
428 | this is the number of pixels from the top of the handle to the | |
429 | place where the user grabbed it. If the handle isn't currently | |
430 | being dragged, this is Qnil. */ | |
431 | Lisp_Object dragging; | |
432 | }; | |
433 | ||
434 | /* The number of elements a vector holding a struct scroll_bar needs. */ | |
435 | #define SCROLL_BAR_VEC_SIZE \ | |
436 | ((sizeof (struct scroll_bar) \ | |
437 | - sizeof (EMACS_INT) - sizeof (struct Lisp_Vector *)) \ | |
438 | / sizeof (Lisp_Object)) | |
439 | ||
440 | /* Turning a lisp vector value into a pointer to a struct scroll_bar. */ | |
441 | #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec)) | |
442 | ||
443 | ||
444 | /* Building a 32-bit C integer from two 16-bit lisp integers. */ | |
445 | #define SCROLL_BAR_PACK(low, high) (XINT (high) << 16 | XINT (low)) | |
446 | ||
447 | /* Setting two lisp integers to the low and high words of a 32-bit C int. */ | |
448 | #define SCROLL_BAR_UNPACK(low, high, int32) \ | |
449 | (XSETINT ((low), (int32) & 0xffff), \ | |
450 | XSETINT ((high), ((int32) >> 16) & 0xffff)) | |
451 | ||
452 | ||
453 | /* Extract the window id of the scroll bar from a struct scroll_bar. */ | |
fbd6baed GV |
454 | #define SCROLL_BAR_W32_WINDOW(ptr) \ |
455 | ((Window) SCROLL_BAR_PACK ((ptr)->w32_window_low, (ptr)->w32_window_high)) | |
c3b8ccce GV |
456 | |
457 | /* Store a window id in a struct scroll_bar. */ | |
fbd6baed GV |
458 | #define SET_SCROLL_BAR_W32_WINDOW(ptr, id) \ |
459 | (SCROLL_BAR_UNPACK ((ptr)->w32_window_low, (ptr)->w32_window_high, (int) id)) | |
c3b8ccce GV |
460 | |
461 | ||
462 | /* Return the outside pixel height for a vertical scroll bar HEIGHT | |
463 | rows high on frame F. */ | |
464 | #define VERTICAL_SCROLL_BAR_PIXEL_HEIGHT(f, height) \ | |
fbd6baed | 465 | ((height) * (f)->output_data.w32->line_height) |
c3b8ccce GV |
466 | |
467 | /* Return the inside width of a vertical scroll bar, given the outside | |
468 | width. */ | |
469 | #define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(width) \ | |
470 | ((width) - VERTICAL_SCROLL_BAR_LEFT_BORDER - VERTICAL_SCROLL_BAR_RIGHT_BORDER) | |
471 | ||
472 | /* Return the length of the rectangle within which the top of the | |
473 | handle must stay. This isn't equivalent to the inside height, | |
474 | because the scroll bar handle has a minimum height. | |
475 | ||
476 | This is the real range of motion for the scroll bar, so when we're | |
477 | scaling buffer positions to scroll bar positions, we use this, not | |
478 | VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */ | |
479 | #define VERTICAL_SCROLL_BAR_TOP_RANGE(height) \ | |
480 | (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (height) - VERTICAL_SCROLL_BAR_MIN_HANDLE) | |
481 | ||
482 | /* Return the inside height of vertical scroll bar, given the outside | |
483 | height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */ | |
484 | #define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(height) \ | |
485 | ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER) | |
486 | ||
487 | ||
488 | /* Border widths for scroll bars. | |
489 | ||
490 | Scroll bar windows don't have any borders; their border width is | |
491 | set to zero, and we redraw borders ourselves. This makes the code | |
492 | a bit cleaner, since we don't have to convert between outside width | |
493 | (used when relating to the rest of the screen) and inside width | |
494 | (used when sizing and drawing the scroll bar window itself). | |
495 | ||
496 | The handle moves up and down/back and forth in a rectangle inset | |
497 | from the edges of the scroll bar. These are widths by which we | |
498 | inset the handle boundaries from the scroll bar edges. */ | |
499 | #define VERTICAL_SCROLL_BAR_LEFT_BORDER (0) | |
500 | #define VERTICAL_SCROLL_BAR_RIGHT_BORDER (0) | |
8694f11b GV |
501 | #define VERTICAL_SCROLL_BAR_TOP_BORDER (vertical_scroll_bar_top_border) |
502 | #define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (vertical_scroll_bar_bottom_border) | |
c3b8ccce GV |
503 | |
504 | /* Minimum lengths for scroll bar handles, in pixels. */ | |
8694f11b GV |
505 | #define VERTICAL_SCROLL_BAR_MIN_HANDLE (vertical_scroll_bar_min_handle) |
506 | ||
c3b8ccce GV |
507 | |
508 | \f | |
509 | /* Manipulating pixel sizes and character sizes. | |
510 | Knowledge of which factors affect the overall size of the window should | |
511 | be hidden in these macros, if that's possible. | |
512 | ||
513 | Return the upper/left pixel position of the character cell on frame F | |
514 | at ROW/COL. */ | |
515 | #define CHAR_TO_PIXEL_ROW(f, row) \ | |
fbd6baed GV |
516 | ((f)->output_data.w32->internal_border_width \ |
517 | + (row) * (f)->output_data.w32->line_height) | |
c3b8ccce | 518 | #define CHAR_TO_PIXEL_COL(f, col) \ |
fbd6baed GV |
519 | ((f)->output_data.w32->internal_border_width \ |
520 | + (col) * FONT_WIDTH ((f)->output_data.w32->font)) | |
c3b8ccce GV |
521 | |
522 | /* Return the pixel width/height of frame F if it has | |
523 | WIDTH columns/HEIGHT rows. */ | |
524 | #define CHAR_TO_PIXEL_WIDTH(f, width) \ | |
525 | (CHAR_TO_PIXEL_COL (f, width) \ | |
fbd6baed GV |
526 | + (f)->output_data.w32->vertical_scroll_bar_extra \ |
527 | + (f)->output_data.w32->internal_border_width) | |
c3b8ccce GV |
528 | #define CHAR_TO_PIXEL_HEIGHT(f, height) \ |
529 | (CHAR_TO_PIXEL_ROW (f, height) \ | |
fbd6baed | 530 | + (f)->output_data.w32->internal_border_width) |
c3b8ccce GV |
531 | |
532 | ||
533 | /* Return the row/column (zero-based) of the character cell containing | |
534 | the pixel on FRAME at ROW/COL. */ | |
535 | #define PIXEL_TO_CHAR_ROW(f, row) \ | |
fbd6baed GV |
536 | (((row) - (f)->output_data.w32->internal_border_width) \ |
537 | / (f)->output_data.w32->line_height) | |
c3b8ccce | 538 | #define PIXEL_TO_CHAR_COL(f, col) \ |
fbd6baed GV |
539 | (((col) - (f)->output_data.w32->internal_border_width) \ |
540 | / FONT_WIDTH ((f)->output_data.w32->font)) | |
c3b8ccce GV |
541 | |
542 | /* How many columns/rows of text can we fit in WIDTH/HEIGHT pixels on | |
543 | frame F? */ | |
544 | #define PIXEL_TO_CHAR_WIDTH(f, width) \ | |
545 | (PIXEL_TO_CHAR_COL (f, ((width) \ | |
fbd6baed GV |
546 | - (f)->output_data.w32->internal_border_width \ |
547 | - (f)->output_data.w32->vertical_scroll_bar_extra))) | |
c3b8ccce GV |
548 | #define PIXEL_TO_CHAR_HEIGHT(f, height) \ |
549 | (PIXEL_TO_CHAR_ROW (f, ((height) \ | |
fbd6baed | 550 | - (f)->output_data.w32->internal_border_width))) |
c3b8ccce GV |
551 | \f |
552 | /* Interface to the face code functions. */ | |
553 | ||
554 | /* Create the first two computed faces for a frame -- the ones that | |
555 | have GC's. */ | |
556 | extern void init_frame_faces (/* FRAME_PTR */); | |
557 | ||
558 | /* Free the resources for the faces associated with a frame. */ | |
559 | extern void free_frame_faces (/* FRAME_PTR */); | |
560 | ||
561 | /* Given a computed face, find or make an equivalent display face | |
562 | in face_vector, and return a pointer to it. */ | |
563 | extern struct face *intern_face (/* FRAME_PTR, struct face * */); | |
564 | ||
565 | /* Given a frame and a face name, return the face's ID number, or | |
566 | zero if it isn't a recognized face name. */ | |
567 | extern int face_name_id_number (/* FRAME_PTR, Lisp_Object */); | |
568 | ||
569 | /* Return non-zero if FONT1 and FONT2 have the same size bounding box. | |
570 | We assume that they're both character-cell fonts. */ | |
571 | extern int same_size_fonts (/* XFontStruct *, XFontStruct * */); | |
572 | ||
573 | /* Recompute the GC's for the default and modeline faces. | |
574 | We call this after changing frame parameters on which those GC's | |
575 | depend. */ | |
576 | extern void recompute_basic_faces (/* FRAME_PTR */); | |
577 | ||
578 | /* Return the face ID associated with a buffer position POS. Store | |
579 | into *ENDPTR the next position at which a different face is | |
580 | needed. This does not take account of glyphs that specify their | |
581 | own face codes. F is the frame in use for display, and W is a | |
582 | window displaying the current buffer. | |
583 | ||
584 | REGION_BEG, REGION_END delimit the region, so it can be highlighted. */ | |
585 | extern int compute_char_face (/* FRAME_PTR frame, | |
586 | struct window *w, | |
587 | int pos, | |
588 | int region_beg, int region_end, | |
589 | int *endptr */); | |
590 | /* Return the face ID to use to display a special glyph which selects | |
591 | FACE_CODE as the face ID, assuming that ordinarily the face would | |
592 | be BASIC_FACE. F is the frame. */ | |
593 | extern int compute_glyph_face (/* FRAME_PTR, int */); | |
594 | ||
fbd6baed GV |
595 | extern void w32_fill_rect (); |
596 | extern void w32_clear_window (); | |
c3b8ccce | 597 | |
fbd6baed | 598 | #define w32_fill_area(f,hdc,pix,x,y,nx,ny) \ |
c3b8ccce GV |
599 | { \ |
600 | RECT rect; \ | |
601 | rect.left = x; \ | |
602 | rect.top = y; \ | |
603 | rect.right = x + nx; \ | |
604 | rect.bottom = y + ny; \ | |
fbd6baed | 605 | w32_fill_rect (f,hdc,pix,&rect); \ |
c3b8ccce GV |
606 | } |
607 | ||
fbd6baed GV |
608 | #define w32_clear_rect(f,hdc,lprect) \ |
609 | w32_fill_rect (f,hdc,f->output_data.w32->background_pixel,lprect) | |
c3b8ccce | 610 | |
fbd6baed GV |
611 | #define w32_clear_area(f,hdc,x,y,nx,ny) \ |
612 | w32_fill_area (f,hdc,f->output_data.w32->background_pixel,x,y,nx,ny) | |
c3b8ccce | 613 | |
d82f9149 | 614 | extern struct font_info *w32_load_font (); |
fbd6baed | 615 | extern void w32_unload_font (); |
c3b8ccce | 616 | |
8694f11b GV |
617 | /* Define for earlier versions of Visual C */ |
618 | #ifndef WM_MOUSEWHEEL | |
f11f6cce | 619 | #define WM_MOUSEWHEEL (WM_MOUSELAST + 1) |
8694f11b | 620 | #endif /* WM_MOUSEWHEEL */ |
f11f6cce GV |
621 | #ifndef MSH_MOUSEWHEEL |
622 | #define MSH_MOUSEWHEEL "MSWHEEL_ROLLMSG" | |
623 | #endif /* MSH_MOUSEWHEEL */ | |
8694f11b | 624 | |
c3b8ccce | 625 | #define WM_EMACS_START (WM_USER + 1) |
bb355434 GV |
626 | #define WM_EMACS_KILL (WM_EMACS_START + 0) |
627 | #define WM_EMACS_CREATEWINDOW (WM_EMACS_START + 1) | |
628 | #define WM_EMACS_DONE (WM_EMACS_START + 2) | |
629 | #define WM_EMACS_CREATESCROLLBAR (WM_EMACS_START + 3) | |
630 | #define WM_EMACS_SHOWWINDOW (WM_EMACS_START + 4) | |
631 | #define WM_EMACS_SETWINDOWPOS (WM_EMACS_START + 5) | |
632 | #define WM_EMACS_DESTROYWINDOW (WM_EMACS_START + 6) | |
633 | #define WM_EMACS_TRACKPOPUPMENU (WM_EMACS_START + 7) | |
634 | #define WM_EMACS_SETFOCUS (WM_EMACS_START + 8) | |
635 | #define WM_EMACS_SETFOREGROUND (WM_EMACS_START + 9) | |
636 | #define WM_EMACS_SETLOCALE (WM_EMACS_START + 10) | |
637 | #define WM_EMACS_SETKEYBOARDLAYOUT (WM_EMACS_START + 11) | |
638 | #define WM_EMACS_REGISTER_HOT_KEY (WM_EMACS_START + 12) | |
639 | #define WM_EMACS_UNREGISTER_HOT_KEY (WM_EMACS_START + 13) | |
93066bc2 GV |
640 | #define WM_EMACS_TOGGLE_LOCK_KEY (WM_EMACS_START + 14) |
641 | #define WM_EMACS_END (WM_EMACS_START + 15) | |
c3b8ccce | 642 | |
8694f11b GV |
643 | #define WND_FONTWIDTH_INDEX (0) |
644 | #define WND_LINEHEIGHT_INDEX (4) | |
645 | #define WND_BORDER_INDEX (8) | |
646 | #define WND_SCROLLBAR_INDEX (12) | |
647 | #define WND_BACKGROUND_INDEX (16) | |
648 | #define WND_LAST_INDEX (20) | |
c3b8ccce | 649 | |
c3b8ccce GV |
650 | #define WND_EXTRA_BYTES (WND_LAST_INDEX) |
651 | ||
de31b97a GV |
652 | extern DWORD dwWindowsThreadId; |
653 | extern HANDLE hWindowsThread; | |
c3b8ccce GV |
654 | extern DWORD dwMainThreadId; |
655 | extern HANDLE hMainThread; | |
656 | ||
fbd6baed | 657 | typedef struct W32Msg { |
c3b8ccce GV |
658 | MSG msg; |
659 | DWORD dwModifiers; | |
660 | RECT rect; | |
fbd6baed | 661 | } W32Msg; |
c3b8ccce | 662 | |
8694f11b GV |
663 | /* Structure for recording message when input thread must return a |
664 | result that depends on lisp thread to compute. Lisp thread can | |
665 | complete deferred messages out of order. */ | |
666 | typedef struct deferred_msg | |
667 | { | |
668 | struct deferred_msg * next; | |
669 | W32Msg w32msg; | |
670 | LRESULT result; | |
671 | int completed; | |
672 | } deferred_msg; | |
673 | ||
aba66c88 GV |
674 | extern CRITICAL_SECTION critsect; |
675 | ||
c3b8ccce | 676 | extern void init_crit (); |
c3b8ccce GV |
677 | extern void delete_crit (); |
678 | ||
b44c3d59 RS |
679 | extern void signal_quit (); |
680 | ||
aba66c88 GV |
681 | #define enter_crit() EnterCriticalSection (&critsect) |
682 | #define leave_crit() LeaveCriticalSection (&critsect) | |
683 | ||
684 | extern void select_palette (struct frame * f, HDC hdc); | |
685 | extern void deselect_palette (struct frame * f, HDC hdc); | |
686 | extern HDC get_frame_dc (struct frame * f); | |
687 | extern int release_frame_dc (struct frame * f, HDC hDC); | |
688 | ||
b37ac782 AI |
689 | extern void drain_message_queue (); |
690 | ||
c3b8ccce GV |
691 | extern BOOL get_next_msg (); |
692 | extern BOOL post_msg (); | |
8694f11b | 693 | extern void complete_deferred_msg (HWND hwnd, UINT msg, LRESULT result); |
c3b8ccce GV |
694 | extern void wait_for_sync (); |
695 | ||
696 | extern BOOL parse_button (); | |
c684f475 | 697 | |
fbd6baed | 698 | /* Keypad command key support. W32 doesn't have virtual keys defined |
c684f475 GV |
699 | for the function keys on the keypad (they are mapped to the standard |
700 | fuction keys), so we define our own. */ | |
701 | #define VK_NUMPAD_BEGIN 0x92 | |
702 | #define VK_NUMPAD_CLEAR (VK_NUMPAD_BEGIN + 0) | |
703 | #define VK_NUMPAD_ENTER (VK_NUMPAD_BEGIN + 1) | |
704 | #define VK_NUMPAD_PRIOR (VK_NUMPAD_BEGIN + 2) | |
705 | #define VK_NUMPAD_NEXT (VK_NUMPAD_BEGIN + 3) | |
706 | #define VK_NUMPAD_END (VK_NUMPAD_BEGIN + 4) | |
707 | #define VK_NUMPAD_HOME (VK_NUMPAD_BEGIN + 5) | |
708 | #define VK_NUMPAD_LEFT (VK_NUMPAD_BEGIN + 6) | |
709 | #define VK_NUMPAD_UP (VK_NUMPAD_BEGIN + 7) | |
710 | #define VK_NUMPAD_RIGHT (VK_NUMPAD_BEGIN + 8) | |
711 | #define VK_NUMPAD_DOWN (VK_NUMPAD_BEGIN + 9) | |
712 | #define VK_NUMPAD_INSERT (VK_NUMPAD_BEGIN + 10) | |
713 | #define VK_NUMPAD_DELETE (VK_NUMPAD_BEGIN + 11) | |
714 | ||
715 | #ifndef VK_LWIN | |
716 | /* Older compiler environments don't have these defined. */ | |
717 | #define VK_LWIN 0x5B | |
718 | #define VK_RWIN 0x5C | |
719 | #define VK_APPS 0x5D | |
720 | #endif | |
bb355434 GV |
721 | |
722 | /* Support for treating Windows and Apps keys as modifiers. These | |
723 | constants must not overlap with any of the dwControlKeyState flags in | |
724 | KEY_EVENT_RECORD. */ | |
725 | #define LEFT_WIN_PRESSED 0x8000 | |
726 | #define RIGHT_WIN_PRESSED 0x4000 | |
727 | #define APPS_PRESSED 0x2000 |