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