A simpler, centralized INLINE.
[bpt/emacs.git] / src / w32term.h
CommitLineData
b46a6a83 1/* Definitions and headers for communication on the Microsoft Windows API.
ab422c4d 2 Copyright (C) 1995, 2001-2013 Free Software Foundation, Inc.
c3b8ccce
GV
3
4This file is part of GNU Emacs.
5
b9b1cc14 6GNU Emacs is free software: you can redistribute it and/or modify
c3b8ccce 7it under the terms of the GNU General Public License as published by
b9b1cc14
GM
8the Free Software Foundation, either version 3 of the License, or
9(at your option) any later version.
c3b8ccce
GV
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
b9b1cc14 17along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
c3b8ccce
GV
18
19/* Added by Kevin Gallo */
20
51dcffad 21#include "w32gui.h"
0fda9b75
DC
22#include "frame.h"
23#include "atimer.h"
c3b8ccce 24
c3b8ccce 25\f
3fed86ff
GV
26#define BLACK_PIX_DEFAULT(f) PALETTERGB(0,0,0)
27#define WHITE_PIX_DEFAULT(f) PALETTERGB(255,255,255)
c3b8ccce 28
3af8ab1d
KH
29#define FONT_WIDTH(f) ((f)->max_width)
30#define FONT_HEIGHT(f) ((f)->height)
31#define FONT_BASE(f) ((f)->ascent)
32#define FONT_DESCENT(f) ((f)->descent)
c3b8ccce 33
ad23de76
JR
34#define CP_DEFAULT 1004
35
fbd6baed 36#define CHECK_W32_FRAME(f, frame) \
c3b8ccce 37 if (NILP (frame)) \
51dcffad 38 f = SELECTED_FRAME (); \
c3b8ccce
GV
39 else \
40 { \
41 CHECK_LIVE_FRAME (frame, 0); \
42 f = XFRAME (frame); \
43 } \
fbd6baed 44 if (! FRAME_W32_P (f))
c3b8ccce
GV
45
46/* Indicates whether we are in the readsocket call and the message we
47 are processing in the current loop */
48
49extern MSG CurMsg;
50extern BOOL bUseDflt;
51
c3b8ccce
GV
52/* Structure recording bitmaps and reference count.
53 If REFCOUNT is 0 then this record is free to be reused. */
54
177c0ea7 55struct w32_bitmap_record
c3b8ccce
GV
56{
57 Pixmap pixmap;
58 char *file;
59 HINSTANCE hinst; /* Used to load the file */
60 int refcount;
61 /* Record some info about this pixmap. */
62 int height, width, depth;
63};
aba66c88 64
fbd6baed
GV
65struct w32_palette_entry {
66 struct w32_palette_entry * next;
aba66c88
GV
67 PALETTEENTRY entry;
68#if 0
69 unsigned refcount;
70#endif
71};
72
5e617bc2 73extern void w32_regenerate_palette (struct frame *f);
1f635a07
EC
74extern void w32_fullscreen_rect (HWND hwnd, int fsmode, RECT normal,
75 RECT *rect);
aba66c88 76
c3b8ccce 77\f
fbd6baed 78/* For each display (currently only one on w32), we have a structure that
c3b8ccce
GV
79 records information about it. */
80
fbd6baed 81struct w32_display_info
c3b8ccce 82{
fbd6baed
GV
83 /* Chain of all w32_display_info structures. */
84 struct w32_display_info *next;
51dcffad 85
a032a9a8
JR
86 /* The generic display parameters corresponding to this w32 display. */
87 struct terminal *terminal;
88
c3b8ccce
GV
89 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE).
90 The same cons cell also appears in x_display_name_list. */
91 Lisp_Object name_list_element;
51dcffad 92
c3b8ccce
GV
93 /* Number of frames that are on this display. */
94 int reference_count;
51dcffad
JR
95
96 /* Dots per inch of the screen. */
97 double resx, resy;
98
c3b8ccce
GV
99 /* Number of planes on this screen. */
100 int n_planes;
51dcffad 101
c3b8ccce
GV
102 /* Number of bits per pixel on this screen. */
103 int n_cbits;
51dcffad 104
c3b8ccce
GV
105 /* Mask of things that cause the mouse to be grabbed. */
106 int grabbed;
51dcffad
JR
107
108 /* Emacs bitmap-id of the default icon bitmap for this frame.
109 Or -1 if none has been allocated yet. */
0766b489 110 ptrdiff_t icon_bitmap_id;
51dcffad 111
c3b8ccce
GV
112 /* The root window of this screen. */
113 Window root_window;
51dcffad 114
c3b8ccce
GV
115 /* The cursor to use for vertical scroll bars. */
116 Cursor vertical_scroll_bar_cursor;
117
71147653 118 /* Resource data base */
abdb2fa0 119 XrmDatabase xrdb;
71147653 120
bb355434 121 /* color palette information. */
aba66c88 122 int has_palette;
fbd6baed 123 struct w32_palette_entry * color_list;
aba66c88
GV
124 unsigned num_colors;
125 HPALETTE palette;
126
bb355434 127 /* deferred action flags checked when starting frame update. */
aba66c88
GV
128 int regen_palette;
129
bb355434
GV
130 /* Keystroke that has been faked by Emacs and will be ignored when
131 received; value is reset after key is received. */
132 int faked_key;
133
51dcffad
JR
134 /* Minimum width over all characters in all fonts in font_table. */
135 int smallest_char_width;
136
137 /* Minimum font height over all fonts in font_table. */
138 int smallest_font_height;
139
140 /* Reusable Graphics Context for drawing a cursor in a non-default face. */
141 XGCValues *scratch_cursor_gc;
142
7ea692f6
EZ
143 /* Information about the range of text currently shown in
144 mouse-face. */
145 Mouse_HLInfo mouse_highlight;
51dcffad 146
fbd6baed 147 char *w32_id_name;
c3b8ccce 148
fbd6baed 149 /* The number of fonts actually stored in w32_font_table.
e0f24100 150 font_table[n] is used and valid if 0 <= n < n_fonts. 0 <=
51dcffad 151 n_fonts <= font_table_size. and font_table[i].name != 0. */
c3b8ccce
GV
152 int n_fonts;
153
154 /* Pointer to bitmap records. */
fbd6baed 155 struct w32_bitmap_record *bitmaps;
c3b8ccce
GV
156
157 /* Allocated size of bitmaps field. */
0766b489 158 ptrdiff_t bitmaps_size;
c3b8ccce
GV
159
160 /* Last used bitmap index. */
0766b489 161 ptrdiff_t bitmaps_last;
c3b8ccce
GV
162
163 /* The frame (if any) which has the window that has keyboard focus.
164 Zero if none. This is examined by Ffocus_frame in w32fns.c. Note
165 that a mere EnterNotify event can set this; if you need to know the
166 last frame specified in a FocusIn or FocusOut event, use
fbd6baed
GV
167 w32_focus_event_frame. */
168 struct frame *w32_focus_frame;
c3b8ccce
GV
169
170 /* The last frame mentioned in a FocusIn or FocusOut event. This is
fbd6baed 171 separate from w32_focus_frame, because whether or not LeaveNotify
c3b8ccce
GV
172 events cause us to lose focus depends on whether or not we have
173 received a FocusIn event for it. */
fbd6baed 174 struct frame *w32_focus_event_frame;
c3b8ccce
GV
175
176 /* The frame which currently has the visual highlight, and should get
177 keyboard input (other sorts of input have the frame encoded in the
178 event). It points to the focus frame's selected window's
fbd6baed 179 frame. It differs from w32_focus_frame when we're using a global
c3b8ccce 180 minibuffer. */
6b3acc48 181 struct frame *x_highlight_frame;
baed3603
DA
182
183 /* The frame waiting to be auto-raised in w32_read_socket. */
184 struct frame *w32_pending_autoraise_frame;
7a0c745a
DA
185
186 /* The frame where the mouse was last time we reported a mouse event. */
187 struct frame *last_mouse_frame;
18da0d8a
DA
188
189 /* The frame where the mouse was last time we reported a mouse motion. */
190 struct frame *last_mouse_motion_frame;
191
ced135eb
DA
192 /* The frame where the mouse was last time we reported a mouse position. */
193 struct frame *last_mouse_glyph_frame;
194
18da0d8a
DA
195 /* Position where the mouse was last time we reported a motion.
196 This is a position on last_mouse_motion_frame. */
197 int last_mouse_motion_x;
198 int last_mouse_motion_y;
ced135eb
DA
199
200 /* Where the mouse was last time we reported a mouse position.
201 This is a rectangle on last_mouse_glyph_frame. */
202 RECT last_mouse_glyph;
203
204 /* The scroll bar in which the last motion event occurred. */
205 struct scroll_bar *last_mouse_scroll_bar;
206
207 /* Mouse position on the scroll bar above.
208 FIXME: shouldn't it be a member of struct scroll_bar? */
209 int last_mouse_scroll_bar_pos;
210
211 /* Time of last mouse movement. */
212 Time last_mouse_movement_time;
c3b8ccce
GV
213};
214
215/* This is a chain of structures for all the displays currently in use. */
8911aff3 216extern struct w32_display_info *x_display_list;
fbd6baed 217extern struct w32_display_info one_w32_display_info;
c3b8ccce
GV
218
219/* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE),
fbd6baed 220 one for each element of w32_display_list and in the same order.
c3b8ccce
GV
221 NAME is the name of the frame.
222 FONT-LIST-CACHE records previous values returned by x-list-fonts. */
fbd6baed 223extern Lisp_Object w32_display_name_list;
c3b8ccce 224
361358ea
JB
225extern struct frame *x_window_to_frame (struct w32_display_info *, HWND);
226
227struct w32_display_info *x_display_info_for_name (Lisp_Object);
c3b8ccce 228
383e0970
J
229Lisp_Object display_x_get_resource (struct w32_display_info *,
230 Lisp_Object, Lisp_Object,
231 Lisp_Object, Lisp_Object);
f3c4ec74 232
0fda9b75
DC
233/* also defined in xterm.h XXX: factor out to common header */
234
361358ea
JB
235extern struct w32_display_info *w32_term_init (Lisp_Object,
236 char *, char *);
a10c8269 237extern int w32_defined_color (struct frame *f, const char *color,
0fda9b75 238 XColor *color_def, int alloc);
0fda9b75
DC
239extern void x_set_window_size (struct frame *f, int change_grav,
240 int cols, int rows);
383e0970
J
241extern int x_display_pixel_height (struct w32_display_info *);
242extern int x_display_pixel_width (struct w32_display_info *);
0fda9b75
DC
243extern Lisp_Object x_get_focus_frame (struct frame *);
244extern void x_set_mouse_position (struct frame *f, int h, int v);
245extern void x_set_mouse_pixel_position (struct frame *f, int pix_x, int pix_y);
246extern void x_make_frame_visible (struct frame *f);
247extern void x_make_frame_invisible (struct frame *f);
248extern void x_iconify_frame (struct frame *f);
0fda9b75
DC
249extern void x_set_frame_alpha (struct frame *f);
250extern void x_set_menu_bar_lines (struct frame *, Lisp_Object, Lisp_Object);
251extern void x_set_tool_bar_lines (struct frame *f,
252 Lisp_Object value,
253 Lisp_Object oldval);
254extern void x_activate_menubar (struct frame *);
255extern int x_bitmap_icon (struct frame *, Lisp_Object);
256extern void initialize_frame_menubar (struct frame *);
257extern void x_free_frame_resources (struct frame *);
0fda9b75
DC
258extern void x_real_positions (struct frame *, int *, int *);
259
260/* w32inevt.c */
261extern int w32_kbd_patch_key (KEY_EVENT_RECORD *event, int cpId);
262extern int w32_kbd_mods_to_emacs (DWORD mods, WORD key);
263
a53400f3 264
5e4daaf3
FP
265extern Lisp_Object x_get_focus_frame (struct frame *);
266
c3b8ccce 267\f
51dcffad
JR
268#define PIX_TYPE COLORREF
269
fbd6baed
GV
270/* Each W32 frame object points to its own struct w32_display object
271 in the output_data.w32 field. The w32_display structure contains all
272 the information that is specific to W32 windows. */
c3b8ccce 273
51dcffad 274/* Put some things in x_output for compatibility.
ee7683eb 275 NTEMACS_TODO: Move all common things here to eliminate unnecessary
51dcffad
JR
276 diffs between X and w32 code. */
277struct x_output
278{
bc2223e6
JR
279 /* Keep track of focus. May be EXPLICIT if we received a FocusIn for this
280 frame, or IMPLICIT if we received an EnterNotify.
281 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
282 int focus_state;
51dcffad
JR
283};
284
bc2223e6
JR
285enum
286{
287 /* Values for focus_state, used as bit mask.
288 EXPLICIT means we received a FocusIn for the frame and know it has
c80e3b4a 289 the focus. IMPLICIT means we received an EnterNotify and the frame
bc2223e6
JR
290 may have the focus if no window manager is running.
291 FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
292 FOCUS_NONE = 0,
293 FOCUS_IMPLICIT = 1,
294 FOCUS_EXPLICIT = 2
295};
51dcffad 296
fbd6baed 297struct w32_output
c3b8ccce 298{
51dcffad 299 /* Placeholder for things accessed through output_data.x. */
42bde733 300 struct x_output x_compatible;
51dcffad 301
8694f11b
GV
302 /* Menubar "widget" handle. */
303 HMENU menubar_widget;
304
aba66c88
GV
305 /* Original palette (used to deselect real palette after drawing) */
306 HPALETTE old_palette;
307
51dcffad
JR
308 /* Here are the Graphics Contexts for the default font. */
309 XGCValues *cursor_gc; /* cursor drawing */
310
c3b8ccce
GV
311 /* The window used for this frame.
312 May be zero while the frame object is being created
313 and the window has not yet been created. */
314 Window window_desc;
315
316 /* The window that is the parent of this window.
317 Usually this is a window that was made by the window manager,
318 but it can be the root window, and it can be explicitly specified
319 (see the explicit_parent field, below). */
320 Window parent_desc;
321
d82f9149 322 /* Default ASCII font of this frame. */
3af8ab1d 323 struct font *font;
47e420b5 324
51dcffad
JR
325 /* The baseline offset of the default ASCII font. */
326 int baseline_offset;
d82f9149
GV
327
328 /* If a fontset is specified for this frame instead of font, this
329 value contains an ID of the fontset, else -1. */
330 int fontset;
331
c3b8ccce
GV
332 /* Pixel values used for various purposes.
333 border_pixel may be -1 meaning use a gray tile. */
51dcffad
JR
334 COLORREF cursor_pixel;
335 COLORREF border_pixel;
336 COLORREF mouse_pixel;
337 COLORREF cursor_foreground_pixel;
338
339 /* Foreground color for scroll bars. A value of -1 means use the
340 default (black for non-toolkit scroll bars). */
341 COLORREF scroll_bar_foreground_pixel;
177c0ea7 342
51dcffad
JR
343 /* Background color for scroll bars. A value of -1 means use the
344 default (background color of the frame for non-toolkit scroll
345 bars). */
346 COLORREF scroll_bar_background_pixel;
c3b8ccce
GV
347
348 /* Descriptor for the cursor in use for this window. */
349 Cursor text_cursor;
350 Cursor nontext_cursor;
351 Cursor modeline_cursor;
b8a93676 352 Cursor hand_cursor;
5fa36066 353 Cursor hourglass_cursor;
f03fad22 354 Cursor horizontal_drag_cursor;
51dcffad 355
5fa36066
GM
356 /* Non-zero means hourglass cursor is currently displayed. */
357 unsigned hourglass_p : 1;
c3b8ccce 358
d148e14d
JR
359 /* Non-hourglass cursor that is currently active. */
360 Cursor current_cursor;
361
c3b8ccce
GV
362 DWORD dwStyle;
363
c3b8ccce 364 /* This is the Emacs structure for the display this frame is on. */
fbd6baed 365 /* struct w32_display_info *display_info; */
c3b8ccce
GV
366
367 /* Nonzero means our parent is another application's window
368 and was explicitly specified. */
f418b22e 369 unsigned explicit_parent : 1;
c3b8ccce
GV
370
371 /* Nonzero means tried already to make this frame visible. */
f418b22e 372 unsigned asked_for_visible : 1;
8694f11b
GV
373
374 /* Nonzero means menubar is currently active. */
f418b22e 375 unsigned menubar_active : 1;
51dcffad
JR
376
377 /* Relief GCs, colors etc. */
378 struct relief
379 {
380 XGCValues *gc;
381 unsigned long pixel;
382 int allocated_p;
383 }
384 black_relief, white_relief;
385
386 /* The background for which the above relief GCs were set up.
387 They are changed only when a different background is involved. */
388 unsigned long relief_background;
cdc0d0bd
EZ
389
390 /* Frame geometry and full-screen mode before it was resized by
391 specifying the 'fullscreen' frame parameter. Used to restore the
392 geometry when 'fullscreen' is reset to nil. */
1f635a07 393 WINDOWPLACEMENT normal_placement;
cdc0d0bd 394 int prev_fsmode;
c3b8ccce
GV
395};
396
2d764c78
EZ
397extern struct w32_output w32term_display;
398
8e025dd5
KS
399/* Return the X output data for frame F. */
400#define FRAME_X_OUTPUT(f) ((f)->output_data.w32)
401
c3b8ccce 402/* Return the window associated with the frame F. */
fbd6baed 403#define FRAME_W32_WINDOW(f) ((f)->output_data.w32->window_desc)
17a2cbbd 404#define FRAME_X_WINDOW(f) FRAME_W32_WINDOW (f)
c3b8ccce 405
fbd6baed 406#define FRAME_FONT(f) ((f)->output_data.w32->font)
d82f9149 407#define FRAME_FONTSET(f) ((f)->output_data.w32->fontset)
51dcffad 408#define FRAME_BASELINE_OFFSET(f) ((f)->output_data.w32->baseline_offset)
c3b8ccce 409
fbd6baed 410/* This gives the w32_display_info structure for the display F is on. */
aad3612f 411#define FRAME_DISPLAY_INFO(f) (&one_w32_display_info)
c3b8ccce 412
8e025dd5
KS
413/* This is the `Display *' which frame F is on. */
414#define FRAME_X_DISPLAY(f) (0)
415
1f635a07
EC
416#define FRAME_NORMAL_PLACEMENT(F) ((F)->output_data.w32->normal_placement)
417#define FRAME_PREV_FSMODE(F) ((F)->output_data.w32->prev_fsmode)
cdc0d0bd 418
51dcffad 419\f
fbd6baed 420/* W32-specific scroll bar stuff. */
c3b8ccce
GV
421
422/* We represent scroll bars as lisp vectors. This allows us to place
423 references to them in windows without worrying about whether we'll
424 end up with windows referring to dead scroll bars; the garbage
425 collector will free it when its time comes.
426
427 We use struct scroll_bar as a template for accessing fields of the
428 vector. */
429
430struct scroll_bar {
431
535cc8e9
DA
432 /* This field is shared by all vectors. */
433 struct vectorlike_header header;
c3b8ccce
GV
434
435 /* The window we're a scroll bar for. */
436 Lisp_Object window;
437
438 /* The next and previous in the chain of scroll bars in this frame. */
439 Lisp_Object next, prev;
440
441 /* The window representing this scroll bar. Since this is a full
442 32-bit quantity, we store it split into two 32-bit values. */
fbd6baed 443 Lisp_Object w32_window_low, w32_window_high;
c3b8ccce 444
51dcffad
JR
445 /* Same as above for the widget. */
446 Lisp_Object w32_widget_low, w32_widget_high;
447
c3b8ccce
GV
448 /* The position and size of the scroll bar in pixels, relative to the
449 frame. */
450 Lisp_Object top, left, width, height;
451
452 /* The starting and ending positions of the handle, relative to the
453 handle area (i.e. zero is the top position, not
454 SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle
455 hasn't been drawn yet.
456
457 These are not actually the locations where the beginning and end
458 are drawn; in order to keep handles from becoming invisible when
459 editing large files, we establish a minimum height by always
460 drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
461 where they would be normally; the bottom and top are in a
462 different co-ordinate system. */
463 Lisp_Object start, end;
464
465 /* If the scroll bar handle is currently being dragged by the user,
466 this is the number of pixels from the top of the handle to the
467 place where the user grabbed it. If the handle isn't currently
468 being dragged, this is Qnil. */
469 Lisp_Object dragging;
680e49c3 470
c8ae93b0 471 /* 1 if the background of the fringe that is adjacent to a scroll
680e49c3 472 bar is extended to the gap between the fringe and the bar. */
2fa611b7
EZ
473 /* Note: this could be a bit field, but we need to take its address
474 in ALLOCATE_PSEUDOVECTOR (see x_scroll_bar_create). */
475 bool fringe_extended_p;
c3b8ccce
GV
476};
477
c3b8ccce
GV
478/* Turning a lisp vector value into a pointer to a struct scroll_bar. */
479#define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
480
62aba0d4
FP
481#ifdef _WIN64
482/* Building a 64-bit C integer from two 32-bit lisp integers. */
483#define SCROLL_BAR_PACK(low, high) (XINT (high) << 32 | XINT (low))
484
485/* Setting two lisp integers to the low and high words of a 64-bit C int. */
486#define SCROLL_BAR_UNPACK(low, high, int64) \
487 (XSETINT ((low), ((DWORDLONG)(int64)) & 0xffffffff), \
488 XSETINT ((high), ((DWORDLONG)(int64) >> 32) & 0xffffffff))
489#else /* not _WIN64 */
c3b8ccce
GV
490/* Building a 32-bit C integer from two 16-bit lisp integers. */
491#define SCROLL_BAR_PACK(low, high) (XINT (high) << 16 | XINT (low))
492
493/* Setting two lisp integers to the low and high words of a 32-bit C int. */
494#define SCROLL_BAR_UNPACK(low, high, int32) \
495 (XSETINT ((low), (int32) & 0xffff), \
496 XSETINT ((high), ((int32) >> 16) & 0xffff))
62aba0d4 497#endif /* not _WIN64 */
c3b8ccce
GV
498
499/* Extract the window id of the scroll bar from a struct scroll_bar. */
fbd6baed
GV
500#define SCROLL_BAR_W32_WINDOW(ptr) \
501 ((Window) SCROLL_BAR_PACK ((ptr)->w32_window_low, (ptr)->w32_window_high))
c3b8ccce
GV
502
503/* Store a window id in a struct scroll_bar. */
fbd6baed 504#define SET_SCROLL_BAR_W32_WINDOW(ptr, id) \
62aba0d4 505 (SCROLL_BAR_UNPACK ((ptr)->w32_window_low, (ptr)->w32_window_high, (intptr_t) id))
c3b8ccce 506
c3b8ccce
GV
507/* Return the inside width of a vertical scroll bar, given the outside
508 width. */
51dcffad
JR
509#define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(f,width) \
510 ((width) \
511 - VERTICAL_SCROLL_BAR_LEFT_BORDER \
0eed0355 512 - VERTICAL_SCROLL_BAR_RIGHT_BORDER)
c3b8ccce
GV
513
514/* Return the length of the rectangle within which the top of the
515 handle must stay. This isn't equivalent to the inside height,
177c0ea7 516 because the scroll bar handle has a minimum height.
c3b8ccce
GV
517
518 This is the real range of motion for the scroll bar, so when we're
519 scaling buffer positions to scroll bar positions, we use this, not
520 VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */
51dcffad
JR
521#define VERTICAL_SCROLL_BAR_TOP_RANGE(f,height) \
522 (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, height) - VERTICAL_SCROLL_BAR_MIN_HANDLE)
c3b8ccce
GV
523
524/* Return the inside height of vertical scroll bar, given the outside
525 height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */
51dcffad 526#define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(f,height) \
c3b8ccce
GV
527 ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER)
528
529
530/* Border widths for scroll bars.
531
532 Scroll bar windows don't have any borders; their border width is
533 set to zero, and we redraw borders ourselves. This makes the code
534 a bit cleaner, since we don't have to convert between outside width
535 (used when relating to the rest of the screen) and inside width
536 (used when sizing and drawing the scroll bar window itself).
537
538 The handle moves up and down/back and forth in a rectangle inset
539 from the edges of the scroll bar. These are widths by which we
540 inset the handle boundaries from the scroll bar edges. */
541#define VERTICAL_SCROLL_BAR_LEFT_BORDER (0)
542#define VERTICAL_SCROLL_BAR_RIGHT_BORDER (0)
8694f11b
GV
543#define VERTICAL_SCROLL_BAR_TOP_BORDER (vertical_scroll_bar_top_border)
544#define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (vertical_scroll_bar_bottom_border)
c3b8ccce
GV
545
546/* Minimum lengths for scroll bar handles, in pixels. */
8694f11b
GV
547#define VERTICAL_SCROLL_BAR_MIN_HANDLE (vertical_scroll_bar_min_handle)
548
361358ea
JB
549struct frame; /* from frame.h */
550
551extern void w32_fill_rect (struct frame *, HDC, COLORREF, RECT *);
552extern void w32_clear_window (struct frame *);
c3b8ccce 553
fbd6baed 554#define w32_fill_area(f,hdc,pix,x,y,nx,ny) \
680e49c3 555do { \
c3b8ccce
GV
556 RECT rect; \
557 rect.left = x; \
558 rect.top = y; \
559 rect.right = x + nx; \
560 rect.bottom = y + ny; \
fbd6baed 561 w32_fill_rect (f,hdc,pix,&rect); \
680e49c3 562} while (0)
c3b8ccce 563
fbd6baed 564#define w32_clear_rect(f,hdc,lprect) \
9e75e167 565 w32_fill_rect (f, hdc, FRAME_BACKGROUND_PIXEL (f), lprect)
c3b8ccce 566
51dcffad 567#define w32_clear_area(f,hdc,px,py,nx,ny) \
9e75e167 568 w32_fill_area (f, hdc, FRAME_BACKGROUND_PIXEL (f), px, py, nx, ny)
c3b8ccce 569
8694f11b
GV
570/* Define for earlier versions of Visual C */
571#ifndef WM_MOUSEWHEEL
f11f6cce 572#define WM_MOUSEWHEEL (WM_MOUSELAST + 1)
8694f11b 573#endif /* WM_MOUSEWHEEL */
f11f6cce
GV
574#ifndef MSH_MOUSEWHEEL
575#define MSH_MOUSEWHEEL "MSWHEEL_ROLLMSG"
576#endif /* MSH_MOUSEWHEEL */
76e4fd8c
JR
577#ifndef WM_XBUTTONDOWN
578#define WM_XBUTTONDOWN (WM_MOUSEWHEEL + 1)
579#define WM_XBUTTONUP (WM_MOUSEWHEEL + 2)
580#endif /* WM_XBUTTONDOWN */
c3659876
JR
581#ifndef WM_MOUSEHWHEEL
582#define WM_MOUSEHWHEEL (WM_MOUSEWHEEL + 4)
583#endif /* WM_MOUSEHWHEEL */
0fe216b2
JR
584#ifndef WM_APPCOMMAND
585#define WM_APPCOMMAND 0x319
586#define GET_APPCOMMAND_LPARAM(lParam) (HIWORD(lParam) & 0x7fff)
587#endif
7684e57b 588#ifndef WM_UNICHAR
499180d5
JR
589#define WM_UNICHAR 0x109
590#endif
591#ifndef UNICODE_NOCHAR
592#define UNICODE_NOCHAR 0xFFFF
593#endif
8694f11b 594
c3b8ccce 595#define WM_EMACS_START (WM_USER + 1)
bb355434
GV
596#define WM_EMACS_KILL (WM_EMACS_START + 0)
597#define WM_EMACS_CREATEWINDOW (WM_EMACS_START + 1)
598#define WM_EMACS_DONE (WM_EMACS_START + 2)
599#define WM_EMACS_CREATESCROLLBAR (WM_EMACS_START + 3)
600#define WM_EMACS_SHOWWINDOW (WM_EMACS_START + 4)
601#define WM_EMACS_SETWINDOWPOS (WM_EMACS_START + 5)
602#define WM_EMACS_DESTROYWINDOW (WM_EMACS_START + 6)
603#define WM_EMACS_TRACKPOPUPMENU (WM_EMACS_START + 7)
604#define WM_EMACS_SETFOCUS (WM_EMACS_START + 8)
605#define WM_EMACS_SETFOREGROUND (WM_EMACS_START + 9)
606#define WM_EMACS_SETLOCALE (WM_EMACS_START + 10)
607#define WM_EMACS_SETKEYBOARDLAYOUT (WM_EMACS_START + 11)
608#define WM_EMACS_REGISTER_HOT_KEY (WM_EMACS_START + 12)
609#define WM_EMACS_UNREGISTER_HOT_KEY (WM_EMACS_START + 13)
93066bc2 610#define WM_EMACS_TOGGLE_LOCK_KEY (WM_EMACS_START + 14)
64ade657
JR
611#define WM_EMACS_TRACK_CARET (WM_EMACS_START + 15)
612#define WM_EMACS_DESTROY_CARET (WM_EMACS_START + 16)
ab8b2d20
JR
613#define WM_EMACS_SHOW_CARET (WM_EMACS_START + 17)
614#define WM_EMACS_HIDE_CARET (WM_EMACS_START + 18)
f3358105 615#define WM_EMACS_SETCURSOR (WM_EMACS_START + 19)
f7b146dc 616#define WM_EMACS_PAINT (WM_EMACS_START + 20)
85d0efd1 617#define WM_EMACS_BRINGTOTOP (WM_EMACS_START + 21)
70147944
EZ
618#define WM_EMACS_INPUT_READY (WM_EMACS_START + 22)
619#define WM_EMACS_FILENOTIFY (WM_EMACS_START + 23)
0fda9b75 620#define WM_EMACS_END (WM_EMACS_START + 24)
c3b8ccce 621
177c0ea7
JB
622#define WND_FONTWIDTH_INDEX (0)
623#define WND_LINEHEIGHT_INDEX (4)
624#define WND_BORDER_INDEX (8)
625#define WND_SCROLLBAR_INDEX (12)
626#define WND_BACKGROUND_INDEX (16)
8694f11b 627#define WND_LAST_INDEX (20)
c3b8ccce 628
c3b8ccce
GV
629#define WND_EXTRA_BYTES (WND_LAST_INDEX)
630
de31b97a
GV
631extern DWORD dwWindowsThreadId;
632extern HANDLE hWindowsThread;
c3b8ccce
GV
633extern DWORD dwMainThreadId;
634extern HANDLE hMainThread;
635
fbd6baed 636typedef struct W32Msg {
c3b8ccce
GV
637 MSG msg;
638 DWORD dwModifiers;
639 RECT rect;
fbd6baed 640} W32Msg;
c3b8ccce 641
0fda9b75
DC
642extern BOOL prepend_msg (W32Msg *lpmsg);
643
8694f11b
GV
644/* Structure for recording message when input thread must return a
645 result that depends on lisp thread to compute. Lisp thread can
646 complete deferred messages out of order. */
647typedef struct deferred_msg
648{
649 struct deferred_msg * next;
650 W32Msg w32msg;
651 LRESULT result;
652 int completed;
653} deferred_msg;
654
aba66c88
GV
655extern CRITICAL_SECTION critsect;
656
361358ea
JB
657extern void init_crit (void);
658extern void delete_crit (void);
c3b8ccce 659
361358ea 660extern void signal_quit (void);
b44c3d59 661
aba66c88
GV
662#define enter_crit() EnterCriticalSection (&critsect)
663#define leave_crit() LeaveCriticalSection (&critsect)
664
665extern void select_palette (struct frame * f, HDC hdc);
666extern void deselect_palette (struct frame * f, HDC hdc);
667extern HDC get_frame_dc (struct frame * f);
668extern int release_frame_dc (struct frame * f, HDC hDC);
669
977c6479 670extern int drain_message_queue (void);
b37ac782 671
361358ea
JB
672extern BOOL get_next_msg (W32Msg *, BOOL);
673extern BOOL post_msg (W32Msg *);
8694f11b 674extern void complete_deferred_msg (HWND hwnd, UINT msg, LRESULT result);
c3b8ccce 675
361358ea 676extern BOOL parse_button (int, int, int *, int *);
c684f475 677
a032a9a8
JR
678extern void w32_sys_ring_bell (struct frame *f);
679extern void x_delete_display (struct w32_display_info *dpyinfo);
8cd879af 680
0b86d359 681extern volatile int notification_buffer_in_use;
477f1e50
EZ
682extern BYTE file_notifications[16384];
683extern DWORD notifications_size;
37a4dabe 684extern void *notifications_desc;
0b86d359 685extern Lisp_Object w32_get_watch_object (void *);
182b170f 686extern Lisp_Object lispy_file_action (DWORD);
a032a9a8 687
a68089e4 688extern void w32_initialize_display_info (Lisp_Object);
9337e206 689extern void initialize_w32_display (struct terminal *, int *, int *);
a68089e4 690
fbd6baed 691/* Keypad command key support. W32 doesn't have virtual keys defined
c684f475 692 for the function keys on the keypad (they are mapped to the standard
c5e87d10 693 function keys), so we define our own. */
c684f475
GV
694#define VK_NUMPAD_BEGIN 0x92
695#define VK_NUMPAD_CLEAR (VK_NUMPAD_BEGIN + 0)
696#define VK_NUMPAD_ENTER (VK_NUMPAD_BEGIN + 1)
697#define VK_NUMPAD_PRIOR (VK_NUMPAD_BEGIN + 2)
698#define VK_NUMPAD_NEXT (VK_NUMPAD_BEGIN + 3)
699#define VK_NUMPAD_END (VK_NUMPAD_BEGIN + 4)
700#define VK_NUMPAD_HOME (VK_NUMPAD_BEGIN + 5)
701#define VK_NUMPAD_LEFT (VK_NUMPAD_BEGIN + 6)
702#define VK_NUMPAD_UP (VK_NUMPAD_BEGIN + 7)
703#define VK_NUMPAD_RIGHT (VK_NUMPAD_BEGIN + 8)
704#define VK_NUMPAD_DOWN (VK_NUMPAD_BEGIN + 9)
705#define VK_NUMPAD_INSERT (VK_NUMPAD_BEGIN + 10)
706#define VK_NUMPAD_DELETE (VK_NUMPAD_BEGIN + 11)
707
708#ifndef VK_LWIN
709/* Older compiler environments don't have these defined. */
710#define VK_LWIN 0x5B
711#define VK_RWIN 0x5C
712#define VK_APPS 0x5D
713#endif
bb355434
GV
714
715/* Support for treating Windows and Apps keys as modifiers. These
716 constants must not overlap with any of the dwControlKeyState flags in
717 KEY_EVENT_RECORD. */
718#define LEFT_WIN_PRESSED 0x8000
719#define RIGHT_WIN_PRESSED 0x4000
720#define APPS_PRESSED 0x2000
51dcffad 721
302fc036
EZ
722/* The current ANSI input codepage for GUI sessions. */
723extern int w32_keyboard_codepage;
724
a81bf19b
JR
725/* When compiling on Windows 9x/ME and NT 3.x, the following are not defined
726 (even though they are supported on 98 and ME. */
727#ifndef WM_MOUSELEAVE
728#define WM_MOUSELEAVE 0x02A3
729#define TME_LEAVE 0x00000002;
730
177c0ea7 731typedef struct tagTRACKMOUSEEVENT
a81bf19b
JR
732{
733 DWORD cbSize;
734 DWORD dwFlags;
735 HWND hwndTrack;
736 DWORD dwHoverTime;
737} TRACKMOUSEEVENT;
738#endif
739
9f21c5a2
EZ
740struct image;
741struct face;
742
51dcffad 743XGCValues *XCreateGC (void *, Window, unsigned long, XGCValues *);
f3c4ec74 744
361358ea 745typedef DWORD (WINAPI * ClipboardSequence_Proc) (void);
ee8062ff
JR
746typedef BOOL (WINAPI * AppendMenuW_Proc) (
747 IN HMENU,
748 IN UINT,
749 IN UINT_PTR,
750 IN LPCWSTR);
6b61353c 751
7684e57b
JB
752extern HWND w32_system_caret_hwnd;
753extern int w32_system_caret_height;
754extern int w32_system_caret_x;
755extern int w32_system_caret_y;
b932cad7
EZ
756extern struct window *w32_system_caret_window;
757extern int w32_system_caret_hdr_height;
758extern int w32_system_caret_mode_height;
0fda9b75 759
d8715cdf
EZ
760#ifdef _MSC_VER
761#ifndef EnumSystemLocales
762/* MSVC headers define these only for _WIN32_WINNT >= 0x0500. */
763typedef BOOL (CALLBACK *LOCALE_ENUMPROCA)(LPSTR);
764typedef BOOL (CALLBACK *LOCALE_ENUMPROCW)(LPWSTR);
765BOOL WINAPI EnumSystemLocalesA(LOCALE_ENUMPROCA,DWORD);
88c4a13c 766BOOL WINAPI EnumSystemLocalesW(LOCALE_ENUMPROCW,DWORD);
d8715cdf
EZ
767#ifdef UNICODE
768#define EnumSystemLocales EnumSystemLocalesW
769#else
770#define EnumSystemLocales EnumSystemLocalesA
771#endif
772#endif
773#endif
774
0fda9b75
DC
775#if EMACSDEBUG
776extern const char*
777w32_name_of_message (UINT msg);
778#endif /* EMACSDEBUG */
779
819e2da9
DC
780#ifdef NTGUI_UNICODE
781extern Lisp_Object ntgui_encode_system (Lisp_Object str);
782#define GUISTR(x) (L ## x)
783#define GUI_ENCODE_FILE GUI_ENCODE_SYSTEM
784#define GUI_ENCODE_SYSTEM(x) ntgui_encode_system (x)
785#define GUI_FN(fn) fn ## W
786typedef wchar_t guichar_t;
787#else /* !NTGUI_UNICODE */
788#define GUISTR(x) x
789#define GUI_ENCODE_FILE ENCODE_FILE
790#define GUI_ENCODE_SYSTEM ENCODE_SYSTEM
791#define GUI_FN(fn) fn
792typedef char guichar_t;
793#endif /* NTGUI_UNICODE */
794
795#define GUI_SDATA(x) ((guichar_t*) SDATA (x))
796
0fda9b75
DC
797extern void syms_of_w32term (void);
798extern void syms_of_w32menu (void);
799extern void syms_of_w32fns (void);
800
801extern void globals_of_w32menu (void);
802extern void globals_of_w32fns (void);
37a4dabe 803extern void globals_of_w32notify (void);
0fda9b75
DC
804
805#ifdef CYGWIN
806extern int w32_message_fd;
807#endif /* CYGWIN */