Initial revision
[bpt/emacs.git] / src / w32term.h
CommitLineData
c3b8ccce
GV
1/* Definitions and headers for communication with Win32 GUI.
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
18the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
19
20/* Added by Kevin Gallo */
21
22#include <win32.h>
23
24/* The class of this X application. */
25#define EMACS_CLASS "Emacs"
26\f
27#define BLACK_PIX_DEFAULT(f) RGB(0,0,0)
28#define WHITE_PIX_DEFAULT(f) RGB(255,255,255)
29
30#define FONT_WIDTH(f) ((f)->tm.tmMaxCharWidth)
31#define FONT_HEIGHT(f) ((f)->tm.tmHeight)
32#define FONT_BASE(f) ((f)->tm.tmAscent)
33
34#define CHECK_WIN32_FRAME(f, frame) \
35 if (NILP (frame)) \
36 f = selected_frame; \
37 else \
38 { \
39 CHECK_LIVE_FRAME (frame, 0); \
40 f = XFRAME (frame); \
41 } \
42 if (! FRAME_WIN32_P (f))
43
44/* Indicates whether we are in the readsocket call and the message we
45 are processing in the current loop */
46
47extern MSG CurMsg;
48extern BOOL bUseDflt;
49
50extern struct frame *x_window_to_frame ();
51
52enum text_cursor_kinds {
53 filled_box_cursor, hollow_box_cursor, bar_cursor
54};
55
56/* This data type is used for the font_table field
57 of struct win32_display_info. */
58
59struct font_info
60{
61 XFontStruct *font;
62 char *name;
63};
64
65/* Structure recording bitmaps and reference count.
66 If REFCOUNT is 0 then this record is free to be reused. */
67
68struct win32_bitmap_record
69{
70 Pixmap pixmap;
71 char *file;
72 HINSTANCE hinst; /* Used to load the file */
73 int refcount;
74 /* Record some info about this pixmap. */
75 int height, width, depth;
76};
77\f
78/* For each display (currently only one on win32), we have a structure that
79 records information about it. */
80
81struct win32_display_info
82{
83 /* Chain of all win32_display_info structures. */
84 struct win32_display_info *next;
85 /* This is a cons cell of the form (NAME . FONT-LIST-CACHE).
86 The same cons cell also appears in x_display_name_list. */
87 Lisp_Object name_list_element;
88 /* Number of frames that are on this display. */
89 int reference_count;
90 /* Number of planes on this screen. */
91 int n_planes;
92 /* Number of bits per pixel on this screen. */
93 int n_cbits;
94 /* Dimensions of this screen. */
95 int height, width;
96 int height_in,width_in;
97 /* Mask of things that cause the mouse to be grabbed. */
98 int grabbed;
99 /* The root window of this screen. */
100 Window root_window;
101 /* The cursor to use for vertical scroll bars. */
102 Cursor vertical_scroll_bar_cursor;
103
104 /* A table of all the fonts we have already loaded. */
105 struct font_info *font_table;
106
107 /* The current capacity of x_font_table. */
108 int font_table_size;
109
110 /* These variables describe the range of text currently shown
111 in its mouse-face, together with the window they apply to.
112 As long as the mouse stays within this range, we need not
113 redraw anything on its account. */
114 int mouse_face_beg_row, mouse_face_beg_col;
115 int mouse_face_end_row, mouse_face_end_col;
116 int mouse_face_past_end;
117 Lisp_Object mouse_face_window;
118 int mouse_face_face_id;
119
120 /* 1 if a mouse motion event came and we didn't handle it right away because
121 gc was in progress. */
122 int mouse_face_deferred_gc;
123
124 /* FRAME and X, Y position of mouse when last checked for
125 highlighting. X and Y can be negative or out of range for the frame. */
126 struct frame *mouse_face_mouse_frame;
127 int mouse_face_mouse_x, mouse_face_mouse_y;
128
129 /* Nonzero means defer mouse-motion highlighting. */
130 int mouse_face_defer;
131
132 char *win32_id_name;
133
134 /* The number of fonts actually stored in win32_font_table.
135 font_table[n] is used and valid iff 0 <= n < n_fonts.
136 0 <= n_fonts <= font_table_size. */
137 int n_fonts;
138
139 /* Pointer to bitmap records. */
140 struct win32_bitmap_record *bitmaps;
141
142 /* Allocated size of bitmaps field. */
143 int bitmaps_size;
144
145 /* Last used bitmap index. */
146 int bitmaps_last;
147
148 /* The frame (if any) which has the window that has keyboard focus.
149 Zero if none. This is examined by Ffocus_frame in w32fns.c. Note
150 that a mere EnterNotify event can set this; if you need to know the
151 last frame specified in a FocusIn or FocusOut event, use
152 win32_focus_event_frame. */
153 struct frame *win32_focus_frame;
154
155 /* The last frame mentioned in a FocusIn or FocusOut event. This is
156 separate from win32_focus_frame, because whether or not LeaveNotify
157 events cause us to lose focus depends on whether or not we have
158 received a FocusIn event for it. */
159 struct frame *win32_focus_event_frame;
160
161 /* The frame which currently has the visual highlight, and should get
162 keyboard input (other sorts of input have the frame encoded in the
163 event). It points to the focus frame's selected window's
164 frame. It differs from win32_focus_frame when we're using a global
165 minibuffer. */
166 struct frame *win32_highlight_frame;
167};
168
169/* This is a chain of structures for all the displays currently in use. */
170extern struct win32_display_info one_win32_display_info;
171
172/* This is a list of cons cells, each of the form (NAME . FONT-LIST-CACHE),
173 one for each element of win32_display_list and in the same order.
174 NAME is the name of the frame.
175 FONT-LIST-CACHE records previous values returned by x-list-fonts. */
176extern Lisp_Object win32_display_name_list;
177
178extern struct win32_display_info *x_display_info_for_display ();
179extern struct win32_display_info *x_display_info_for_name ();
180
181extern struct win32_display_info *win32_term_init ();
182\f
183/* Each Win32 frame object points to its own struct win32_display object
184 in the output_data.win32 field. The win32_display structure contains all
185 the information that is specific to Win32 windows. */
186
187struct win32_output
188{
189 /* Position of the Win32 window (x and y offsets in root window). */
190 int left_pos;
191 int top_pos;
192
193 /* Border width of the Win32 window as known by the window system. */
194 int border_width;
195
196 /* Size of the Win32 window in pixels. */
197 int pixel_height, pixel_width;
198
199 /* Height of a line, in pixels. */
200 int line_height;
201
202 /* Width of the internal border. This is a line of background color
203 just inside the window's border. When the frame is selected,
204 a highlighting is displayed inside the internal border. */
205 int internal_border_width;
206
207 /* The window used for this frame.
208 May be zero while the frame object is being created
209 and the window has not yet been created. */
210 Window window_desc;
211
212 /* The window that is the parent of this window.
213 Usually this is a window that was made by the window manager,
214 but it can be the root window, and it can be explicitly specified
215 (see the explicit_parent field, below). */
216 Window parent_desc;
217
218 XFontStruct *font;
219
220 /* Pixel values used for various purposes.
221 border_pixel may be -1 meaning use a gray tile. */
222 unsigned long background_pixel;
223 unsigned long foreground_pixel;
224 unsigned long cursor_pixel;
225 unsigned long border_pixel;
226 unsigned long mouse_pixel;
227 unsigned long cursor_foreground_pixel;
228
229 /* Descriptor for the cursor in use for this window. */
230 Cursor text_cursor;
231 Cursor nontext_cursor;
232 Cursor modeline_cursor;
233 Cursor cross_cursor;
234
235 /* Flag to set when the window needs to be completely repainted. */
236 int needs_exposure;
237
238 /* What kind of text cursor is drawn in this window right now?
239 (If there is no cursor (phys_cursor_x < 0), then this means nothing.) */
240 enum text_cursor_kinds current_cursor;
241
242 /* What kind of text cursor should we draw in the future?
243 This should always be filled_box_cursor or bar_cursor. */
244 enum text_cursor_kinds desired_cursor;
245
246 /* Width of bar cursor (if we are using that). */
247 int cursor_width;
248
249 DWORD dwStyle;
250
251 /* The size of the extra width currently allotted for vertical
252 scroll bars, in pixels. */
253 int vertical_scroll_bar_extra;
254
255 /* Table of parameter faces for this frame. Any resources (pixel
256 values, fonts) referred to here have been allocated explicitly
257 for this face, and should be freed if we change the face. */
258 struct face **param_faces;
259 int n_param_faces;
260
261 /* Table of computed faces for this frame. These are the faces
262 whose indexes go into the upper bits of a glyph, computed by
263 combining the parameter faces specified by overlays, text
264 properties, and what have you. The resources mentioned here
265 are all shared with parameter faces. */
266 struct face **computed_faces;
267 int n_computed_faces; /* How many are valid */
268 int size_computed_faces; /* How many are allocated */
269
270 /* This is the gravity value for the specified window position. */
271 int win_gravity;
272
273 /* The geometry flags for this window. */
274 int size_hint_flags;
275
276 /* This is the Emacs structure for the display this frame is on. */
277 /* struct win32_display_info *display_info; */
278
279 /* Nonzero means our parent is another application's window
280 and was explicitly specified. */
281 char explicit_parent;
282
283 /* Nonzero means tried already to make this frame visible. */
284 char asked_for_visible;
285};
286
287/* Get at the computed faces of an X window frame. */
288#define FRAME_PARAM_FACES(f) ((f)->output_data.win32->param_faces)
289#define FRAME_N_PARAM_FACES(f) ((f)->output_data.win32->n_param_faces)
290#define FRAME_DEFAULT_PARAM_FACE(f) (FRAME_PARAM_FACES (f)[0])
291#define FRAME_MODE_LINE_PARAM_FACE(f) (FRAME_PARAM_FACES (f)[1])
292
293#define FRAME_COMPUTED_FACES(f) ((f)->output_data.win32->computed_faces)
294#define FRAME_N_COMPUTED_FACES(f) ((f)->output_data.win32->n_computed_faces)
295#define FRAME_SIZE_COMPUTED_FACES(f) ((f)->output_data.win32->size_computed_faces)
296#define FRAME_DEFAULT_FACE(f) ((f)->output_data.win32->computed_faces[0])
297#define FRAME_MODE_LINE_FACE(f) ((f)->output_data.win32->computed_faces[1])
298
299/* Return the window associated with the frame F. */
300#define FRAME_WIN32_WINDOW(f) ((f)->output_data.win32->window_desc)
301
302#define FRAME_FOREGROUND_PIXEL(f) ((f)->output_data.win32->foreground_pixel)
303#define FRAME_BACKGROUND_PIXEL(f) ((f)->output_data.win32->background_pixel)
304#define FRAME_FONT(f) ((f)->output_data.win32->font)
305#define FRAME_INTERNAL_BORDER_WIDTH(f) ((f)->output_data.win32->internal_border_width)
306
307/* This gives the win32_display_info structure for the display F is on. */
308#define FRAME_WIN32_DISPLAY_INFO(f) (&one_win32_display_info)
309
310/* These two really ought to be called FRAME_PIXEL_{WIDTH,HEIGHT}. */
311#define PIXEL_WIDTH(f) ((f)->output_data.win32->pixel_width)
312#define PIXEL_HEIGHT(f) ((f)->output_data.win32->pixel_height)
313#define FRAME_LINE_HEIGHT(f) ((f)->output_data.win32->line_height)
314
315#define FRAME_DESIRED_CURSOR(f) ((f)->output_data.win32->desired_cursor)
316
317\f
318/* Win32-specific scroll bar stuff. */
319
320/* We represent scroll bars as lisp vectors. This allows us to place
321 references to them in windows without worrying about whether we'll
322 end up with windows referring to dead scroll bars; the garbage
323 collector will free it when its time comes.
324
325 We use struct scroll_bar as a template for accessing fields of the
326 vector. */
327
328struct scroll_bar {
329
330 /* These fields are shared by all vectors. */
331 EMACS_INT size_from_Lisp_Vector_struct;
332 struct Lisp_Vector *next_from_Lisp_Vector_struct;
333
334 /* The window we're a scroll bar for. */
335 Lisp_Object window;
336
337 /* The next and previous in the chain of scroll bars in this frame. */
338 Lisp_Object next, prev;
339
340 /* The window representing this scroll bar. Since this is a full
341 32-bit quantity, we store it split into two 32-bit values. */
342 Lisp_Object win32_window_low, win32_window_high;
343
344 /* The position and size of the scroll bar in pixels, relative to the
345 frame. */
346 Lisp_Object top, left, width, height;
347
348 /* The starting and ending positions of the handle, relative to the
349 handle area (i.e. zero is the top position, not
350 SCROLL_BAR_TOP_BORDER). If they're equal, that means the handle
351 hasn't been drawn yet.
352
353 These are not actually the locations where the beginning and end
354 are drawn; in order to keep handles from becoming invisible when
355 editing large files, we establish a minimum height by always
356 drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
357 where they would be normally; the bottom and top are in a
358 different co-ordinate system. */
359 Lisp_Object start, end;
360
361 /* If the scroll bar handle is currently being dragged by the user,
362 this is the number of pixels from the top of the handle to the
363 place where the user grabbed it. If the handle isn't currently
364 being dragged, this is Qnil. */
365 Lisp_Object dragging;
366};
367
368/* The number of elements a vector holding a struct scroll_bar needs. */
369#define SCROLL_BAR_VEC_SIZE \
370 ((sizeof (struct scroll_bar) \
371 - sizeof (EMACS_INT) - sizeof (struct Lisp_Vector *)) \
372 / sizeof (Lisp_Object))
373
374/* Turning a lisp vector value into a pointer to a struct scroll_bar. */
375#define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
376
377
378/* Building a 32-bit C integer from two 16-bit lisp integers. */
379#define SCROLL_BAR_PACK(low, high) (XINT (high) << 16 | XINT (low))
380
381/* Setting two lisp integers to the low and high words of a 32-bit C int. */
382#define SCROLL_BAR_UNPACK(low, high, int32) \
383 (XSETINT ((low), (int32) & 0xffff), \
384 XSETINT ((high), ((int32) >> 16) & 0xffff))
385
386
387/* Extract the window id of the scroll bar from a struct scroll_bar. */
388#define SCROLL_BAR_WIN32_WINDOW(ptr) \
389 ((Window) SCROLL_BAR_PACK ((ptr)->win32_window_low, (ptr)->win32_window_high))
390
391/* Store a window id in a struct scroll_bar. */
392#define SET_SCROLL_BAR_WIN32_WINDOW(ptr, id) \
393 (SCROLL_BAR_UNPACK ((ptr)->win32_window_low, (ptr)->win32_window_high, (int) id))
394
395
396/* Return the outside pixel height for a vertical scroll bar HEIGHT
397 rows high on frame F. */
398#define VERTICAL_SCROLL_BAR_PIXEL_HEIGHT(f, height) \
399 ((height) * (f)->output_data.win32->line_height)
400
401/* Return the inside width of a vertical scroll bar, given the outside
402 width. */
403#define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(width) \
404 ((width) - VERTICAL_SCROLL_BAR_LEFT_BORDER - VERTICAL_SCROLL_BAR_RIGHT_BORDER)
405
406/* Return the length of the rectangle within which the top of the
407 handle must stay. This isn't equivalent to the inside height,
408 because the scroll bar handle has a minimum height.
409
410 This is the real range of motion for the scroll bar, so when we're
411 scaling buffer positions to scroll bar positions, we use this, not
412 VERTICAL_SCROLL_BAR_INSIDE_HEIGHT. */
413#define VERTICAL_SCROLL_BAR_TOP_RANGE(height) \
414 (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (height) - VERTICAL_SCROLL_BAR_MIN_HANDLE)
415
416/* Return the inside height of vertical scroll bar, given the outside
417 height. See VERTICAL_SCROLL_BAR_TOP_RANGE too. */
418#define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(height) \
419 ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER)
420
421
422/* Border widths for scroll bars.
423
424 Scroll bar windows don't have any borders; their border width is
425 set to zero, and we redraw borders ourselves. This makes the code
426 a bit cleaner, since we don't have to convert between outside width
427 (used when relating to the rest of the screen) and inside width
428 (used when sizing and drawing the scroll bar window itself).
429
430 The handle moves up and down/back and forth in a rectangle inset
431 from the edges of the scroll bar. These are widths by which we
432 inset the handle boundaries from the scroll bar edges. */
433#define VERTICAL_SCROLL_BAR_LEFT_BORDER (0)
434#define VERTICAL_SCROLL_BAR_RIGHT_BORDER (0)
435#define VERTICAL_SCROLL_BAR_TOP_BORDER (0)
436#define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (0)
437
438/* Minimum lengths for scroll bar handles, in pixels. */
439#define VERTICAL_SCROLL_BAR_MIN_HANDLE (0)
440
441\f
442/* Manipulating pixel sizes and character sizes.
443 Knowledge of which factors affect the overall size of the window should
444 be hidden in these macros, if that's possible.
445
446 Return the upper/left pixel position of the character cell on frame F
447 at ROW/COL. */
448#define CHAR_TO_PIXEL_ROW(f, row) \
449 ((f)->output_data.win32->internal_border_width \
450 + (row) * (f)->output_data.win32->line_height)
451#define CHAR_TO_PIXEL_COL(f, col) \
452 ((f)->output_data.win32->internal_border_width \
453 + (col) * FONT_WIDTH ((f)->output_data.win32->font))
454
455/* Return the pixel width/height of frame F if it has
456 WIDTH columns/HEIGHT rows. */
457#define CHAR_TO_PIXEL_WIDTH(f, width) \
458 (CHAR_TO_PIXEL_COL (f, width) \
459 + (f)->output_data.win32->vertical_scroll_bar_extra \
460 + (f)->output_data.win32->internal_border_width)
461#define CHAR_TO_PIXEL_HEIGHT(f, height) \
462 (CHAR_TO_PIXEL_ROW (f, height) \
463 + (f)->output_data.win32->internal_border_width)
464
465
466/* Return the row/column (zero-based) of the character cell containing
467 the pixel on FRAME at ROW/COL. */
468#define PIXEL_TO_CHAR_ROW(f, row) \
469 (((row) - (f)->output_data.win32->internal_border_width) \
470 / (f)->output_data.win32->line_height)
471#define PIXEL_TO_CHAR_COL(f, col) \
472 (((col) - (f)->output_data.win32->internal_border_width) \
473 / FONT_WIDTH ((f)->output_data.win32->font))
474
475/* How many columns/rows of text can we fit in WIDTH/HEIGHT pixels on
476 frame F? */
477#define PIXEL_TO_CHAR_WIDTH(f, width) \
478 (PIXEL_TO_CHAR_COL (f, ((width) \
479 - (f)->output_data.win32->internal_border_width \
480 - (f)->output_data.win32->vertical_scroll_bar_extra)))
481#define PIXEL_TO_CHAR_HEIGHT(f, height) \
482 (PIXEL_TO_CHAR_ROW (f, ((height) \
483 - (f)->output_data.win32->internal_border_width)))
484\f
485/* Interface to the face code functions. */
486
487/* Create the first two computed faces for a frame -- the ones that
488 have GC's. */
489extern void init_frame_faces (/* FRAME_PTR */);
490
491/* Free the resources for the faces associated with a frame. */
492extern void free_frame_faces (/* FRAME_PTR */);
493
494/* Given a computed face, find or make an equivalent display face
495 in face_vector, and return a pointer to it. */
496extern struct face *intern_face (/* FRAME_PTR, struct face * */);
497
498/* Given a frame and a face name, return the face's ID number, or
499 zero if it isn't a recognized face name. */
500extern int face_name_id_number (/* FRAME_PTR, Lisp_Object */);
501
502/* Return non-zero if FONT1 and FONT2 have the same size bounding box.
503 We assume that they're both character-cell fonts. */
504extern int same_size_fonts (/* XFontStruct *, XFontStruct * */);
505
506/* Recompute the GC's for the default and modeline faces.
507 We call this after changing frame parameters on which those GC's
508 depend. */
509extern void recompute_basic_faces (/* FRAME_PTR */);
510
511/* Return the face ID associated with a buffer position POS. Store
512 into *ENDPTR the next position at which a different face is
513 needed. This does not take account of glyphs that specify their
514 own face codes. F is the frame in use for display, and W is a
515 window displaying the current buffer.
516
517 REGION_BEG, REGION_END delimit the region, so it can be highlighted. */
518extern int compute_char_face (/* FRAME_PTR frame,
519 struct window *w,
520 int pos,
521 int region_beg, int region_end,
522 int *endptr */);
523/* Return the face ID to use to display a special glyph which selects
524 FACE_CODE as the face ID, assuming that ordinarily the face would
525 be BASIC_FACE. F is the frame. */
526extern int compute_glyph_face (/* FRAME_PTR, int */);
527
528extern void win32_fill_rect ();
529extern void win32_clear_window ();
530
531#define win32_fill_area(f,hdc,pix,x,y,nx,ny) \
532{ \
533 RECT rect; \
534 rect.left = x; \
535 rect.top = y; \
536 rect.right = x + nx; \
537 rect.bottom = y + ny; \
538 win32_fill_rect (f,hdc,pix,&rect); \
539}
540
541#define win32_clear_rect(f,hdc,lprect) \
542win32_fill_rect (f,hdc,f->output_data.win32->background_pixel,lprect)
543
544#define win32_clear_area(f,hdc,x,y,nx,ny) \
545win32_fill_area (f,hdc,f->output_data.win32->background_pixel,x,y,nx,ny)
546
547extern XFontStruct *win32_load_font ();
548extern void win32_unload_font ();
549
550extern HDC map_mode();
551
552#define my_get_dc(hwnd) (map_mode (GetDC (hwnd)))
553
554#define WM_EMACS_START (WM_USER + 1)
555#define WM_EMACS_KILL (WM_EMACS_START + 0x00)
556#define WM_EMACS_CREATEWINDOW (WM_EMACS_START + 0x01)
557#define WM_EMACS_DONE (WM_EMACS_START + 0x02)
558#define WM_EMACS_CREATESCROLLBAR (WM_EMACS_START + 0x03)
559#define WM_EMACS_DESTROYWINDOW (WM_EMACS_START + 0x04)
560#define WM_EMACS_END (WM_EMACS_START + 0x10)
561
562#define WND_X_UNITS_INDEX (0)
563#define WND_Y_UNITS_INDEX (4)
564#define WND_BACKGROUND_INDEX (8)
565
566#define WND_LAST_INDEX (16)
567#define WND_EXTRA_BYTES (WND_LAST_INDEX)
568
569extern DWORD dwWinThreadId;
570extern HANDLE hWinThread;
571extern DWORD dwMainThreadId;
572extern HANDLE hMainThread;
573
574typedef struct Win32Msg {
575 MSG msg;
576 DWORD dwModifiers;
577 RECT rect;
578} Win32Msg;
579
580extern void init_crit ();
581extern void enter_crit ();
582extern void leave_crit ();
583extern void delete_crit ();
584
585extern BOOL get_next_msg ();
586extern BOOL post_msg ();
587extern void wait_for_sync ();
588
589extern BOOL parse_button ();