root/src/w32term.h

/* [<][>][^][v][top][bottom][index][help] */

INCLUDED FROM


     1 /* Definitions and headers for communication on the Microsoft Windows API.
     2    Copyright (C) 1995, 2001-2023 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 3 of the License, or (at
     9 your option) 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.  If not, see <https://www.gnu.org/licenses/>.  */
    18 
    19 /* Added by Kevin Gallo */
    20 
    21 #include "w32gui.h"
    22 #include "frame.h"
    23 #include "atimer.h"
    24 
    25 /* Stack alignment stuff.  Every CALLBACK and thread function should
    26    have the ALIGN_STACK attribute if it manipulates Lisp objects,
    27    because Windows x86 32-bit ABI only guarantees 4-byte stack
    28    alignment, and that is what we will get when a Windows function
    29    calls us.  The ALIGN_STACK attribute forces GCC to emit a preamble
    30    code to re-align the stack at function entry.  Further details
    31    about this can be found in
    32    https://www.peterstock.co.uk/games/mingw_sse/.  */
    33 #ifdef __GNUC__
    34 # if USE_STACK_LISP_OBJECTS && !defined _WIN64 && !defined __x86_64__   \
    35   && __GNUC__ + (__GNUC_MINOR__ > 1) >= 5
    36 #  define ALIGN_STACK __attribute__((force_align_arg_pointer))
    37 # else
    38 #  define ALIGN_STACK
    39 # endif  /* USE_STACK_LISP_OBJECTS */
    40 #endif
    41 
    42 
    43 #define BLACK_PIX_DEFAULT(f) PALETTERGB(0,0,0)
    44 #define WHITE_PIX_DEFAULT(f) PALETTERGB(255,255,255)
    45 
    46 #define CP_DEFAULT 1004
    47 
    48 /* Indicates whether we are in the readsocket call and the message we
    49    are processing in the current loop */
    50 
    51 extern MSG CurMsg;
    52 extern BOOL bUseDflt;
    53 
    54 /* Structure recording bitmaps and reference count.
    55    If REFCOUNT is 0 then this record is free to be reused.  */
    56 
    57 struct w32_bitmap_record
    58 {
    59   Emacs_Pixmap pixmap;
    60   char *file;
    61   HINSTANCE hinst; /* Used to load the file */
    62   int refcount;
    63   /* Record some info about this pixmap.  */
    64   int height, width, depth;
    65 };
    66 
    67 struct w32_palette_entry {
    68   struct w32_palette_entry * next;
    69   PALETTEENTRY entry;
    70 #if 0
    71   unsigned refcount;
    72 #endif
    73 };
    74 
    75 extern void w32_regenerate_palette (struct frame *f);
    76 extern void w32_fullscreen_rect (HWND hwnd, int fsmode, RECT normal,
    77                                  RECT *rect);
    78 
    79 /* For each display (currently only one on w32), we have a structure that
    80    records information about it.  */
    81 
    82 struct w32_display_info
    83 {
    84   /* Chain of all w32_display_info structures.  */
    85   struct w32_display_info *next;
    86 
    87   /* The generic display parameters corresponding to this w32 display.  */
    88   struct terminal *terminal;
    89 
    90   /* This is a cons cell of the form (NAME . FONT-LIST-CACHE).  */
    91   Lisp_Object name_list_element;
    92 
    93   /* Number of frames that are on this display.  */
    94   int reference_count;
    95 
    96   /* Dots per inch of the screen.  */
    97   double resx, resy;
    98 
    99   /* Number of planes on this screen.  */
   100   int n_planes;
   101 
   102   /* Number of bits per pixel on this screen.  */
   103   int n_cbits;
   104 
   105   /* Mask of things that cause the mouse to be grabbed.  */
   106   int grabbed;
   107 
   108   /* Emacs bitmap-id of the default icon bitmap for this frame.
   109      Or -1 if none has been allocated yet.  */
   110   ptrdiff_t icon_bitmap_id;
   111 
   112   /* The root window of this screen.  */
   113   Window root_window;
   114 
   115   /* The cursor to use for vertical scroll bars.  */
   116   HCURSOR vertical_scroll_bar_cursor;
   117 
   118   /* The cursor to use for horizontal scroll bars.  */
   119   HCURSOR horizontal_scroll_bar_cursor;
   120 
   121   /* Resource data base */
   122   const char *rdb;
   123 
   124   /* color palette information.  */
   125   int has_palette;
   126   struct w32_palette_entry * color_list;
   127   unsigned num_colors;
   128   HPALETTE palette;
   129 
   130   /* deferred action flags checked when starting frame update.  */
   131   int regen_palette;
   132 
   133   /* Keystroke that has been faked by Emacs and will be ignored when
   134      received; value is reset after key is received.  */
   135   int faked_key;
   136 
   137   /* Minimum width over all characters in all fonts in font_table.  */
   138   int smallest_char_width;
   139 
   140   /* Minimum font height over all fonts in font_table.  */
   141   int smallest_font_height;
   142 
   143   /* Reusable Graphics Context for drawing a cursor in a non-default face. */
   144   Emacs_GC *scratch_cursor_gc;
   145 
   146   /* Information about the range of text currently shown in
   147      mouse-face.  */
   148   Mouse_HLInfo mouse_highlight;
   149 
   150   char *w32_id_name;
   151 
   152   /* The number of fonts actually stored in w32_font_table.
   153      font_table[n] is used and valid if 0 <= n < n_fonts. 0 <=
   154      n_fonts <= font_table_size. and font_table[i].name != 0. */
   155   int n_fonts;
   156 
   157   /* Pointer to bitmap records.  */
   158   struct w32_bitmap_record *bitmaps;
   159 
   160   /* Allocated size of bitmaps field.  */
   161   ptrdiff_t bitmaps_size;
   162 
   163   /* Last used bitmap index.  */
   164   ptrdiff_t bitmaps_last;
   165 
   166   /* The frame (if any) which has the window that has keyboard focus.
   167      Zero if none.  This is examined by Ffocus_frame in w32fns.c.  Note
   168      that a mere EnterNotify event can set this; if you need to know the
   169      last frame specified in a FocusIn or FocusOut event, use
   170      w32_focus_event_frame.  */
   171   struct frame *w32_focus_frame;
   172 
   173   /* The last frame mentioned in a FocusIn or FocusOut event.  This is
   174      separate from w32_focus_frame, because whether or not LeaveNotify
   175      events cause us to lose focus depends on whether or not we have
   176      received a FocusIn event for it.  */
   177   struct frame *w32_focus_event_frame;
   178 
   179   /* The frame which currently has the visual highlight, and should get
   180      keyboard input (other sorts of input have the frame encoded in the
   181      event).  It points to the focus frame's selected window's
   182      frame.  It differs from w32_focus_frame when we're using a global
   183      minibuffer.  */
   184   struct frame *highlight_frame;
   185 
   186   /* The frame waiting to be auto-raised in w32_read_socket.  */
   187   struct frame *w32_pending_autoraise_frame;
   188 
   189   /* The frame where the mouse was last time we reported a mouse event.  */
   190   struct frame *last_mouse_frame;
   191 
   192   /* The frame where the mouse was last time we reported a mouse motion.  */
   193   struct frame *last_mouse_motion_frame;
   194 
   195   /* The frame where the mouse was last time we reported a mouse position.  */
   196   struct frame *last_mouse_glyph_frame;
   197 
   198   /* Position where the mouse was last time we reported a motion.
   199      This is a position on last_mouse_motion_frame.  */
   200   int last_mouse_motion_x;
   201   int last_mouse_motion_y;
   202 
   203   /* Where the mouse was last time we reported a mouse position.
   204      This is a rectangle on last_mouse_glyph_frame.  */
   205   RECT last_mouse_glyph;
   206 
   207   /* The scroll bar in which the last motion event occurred.  */
   208   struct scroll_bar *last_mouse_scroll_bar;
   209 
   210   /* Mouse position on the scroll bar above.
   211      FIXME: shouldn't it be a member of struct scroll_bar?  */
   212   int last_mouse_scroll_bar_pos;
   213 
   214   /* Time of last mouse movement.  */
   215   Time last_mouse_movement_time;
   216 
   217   /* Value returned by last call of ShowCursor.  */
   218   int cursor_display_counter;
   219 };
   220 
   221 /* This is a chain of structures for all the displays currently in use.  */
   222 extern struct w32_display_info *x_display_list;
   223 extern struct w32_display_info one_w32_display_info;
   224 
   225 /* These 2 are set by w32fns.c and examined in w32term.c.  */
   226 extern HMENU current_popup_menu;
   227 extern int menubar_in_use;
   228 
   229 extern struct frame *w32_window_to_frame (struct w32_display_info *, HWND);
   230 
   231 extern void w32_real_positions (struct frame *f, int *xptr, int *yptr);
   232 
   233 extern void w32_clear_under_internal_border (struct frame *);
   234 
   235 extern void w32_change_tab_bar_height (struct frame *, int);
   236 extern void w32_change_tool_bar_height (struct frame *, int);
   237 extern void w32_implicitly_set_name (struct frame *, Lisp_Object, Lisp_Object);
   238 extern void w32_set_scroll_bar_default_width (struct frame *);
   239 extern void w32_set_scroll_bar_default_height (struct frame *);
   240 
   241 
   242 extern struct w32_display_info *w32_term_init (Lisp_Object,
   243                                                char *, char *);
   244 extern bool w32_defined_color (struct frame *, const char *, Emacs_Color *,
   245                                bool, bool);
   246 extern int w32_display_pixel_height (struct w32_display_info *);
   247 extern int w32_display_pixel_width (struct w32_display_info *);
   248 extern void initialize_frame_menubar (struct frame *);
   249 extern void w32_dialog_in_progress (Lisp_Object in_progress);
   250 extern void w32_query_frame_background_color (struct frame *f,
   251                                               Emacs_Color *bgcolor);
   252 
   253 extern void w32_make_frame_visible (struct frame *f);
   254 extern void w32_make_frame_invisible (struct frame *f);
   255 extern void w32_iconify_frame (struct frame *f);
   256 extern void w32_free_frame_resources (struct frame *);
   257 extern void w32_wm_set_size_hint (struct frame *, long, bool);
   258 
   259 /* w32inevt.c */
   260 extern int w32_kbd_patch_key (KEY_EVENT_RECORD *event, int cpId);
   261 extern int w32_kbd_mods_to_emacs (DWORD mods, WORD key);
   262 
   263 /* w32console.c */
   264 extern void w32con_hide_cursor (void);
   265 extern void w32con_show_cursor (void);
   266 
   267 /* w32reg.c */
   268 extern const char *w32_get_string_resource (void *v_rdb,
   269                                             const char *name,
   270                                             const char *class);
   271 
   272 /* w32fns.c */
   273 extern void w32_default_font_parameter (struct frame* f, Lisp_Object parms);
   274 
   275 
   276 #define PIX_TYPE COLORREF
   277 
   278 /* Each W32 frame object points to its own struct w32_display object
   279    in the output_data.w32 field.  The w32_display structure contains all
   280    the information that is specific to W32 windows.  */
   281 
   282 /* Put some things in x_output for compatibility.
   283    NTEMACS_TODO: Move all common things here to eliminate unnecessary
   284    diffs between X and w32 code.  */
   285 struct x_output
   286 {
   287   /* Keep track of focus.  May be EXPLICIT if we received a FocusIn for this
   288      frame, or IMPLICIT if we received an EnterNotify.
   289      FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
   290   int focus_state;
   291 };
   292 
   293 enum
   294 {
   295   /* Values for focus_state, used as bit mask.
   296      EXPLICIT means we received a FocusIn for the frame and know it has
   297      the focus.  IMPLICIT means we received an EnterNotify and the frame
   298      may have the focus if no window manager is running.
   299      FocusOut and LeaveNotify clears EXPLICIT/IMPLICIT. */
   300   FOCUS_NONE     = 0,
   301   FOCUS_IMPLICIT = 1,
   302   FOCUS_EXPLICIT = 2
   303 };
   304 
   305 struct w32_output
   306 {
   307   /* Placeholder for things accessed through output_data.x.  */
   308   struct x_output x_compatible;
   309 
   310   /* Menubar "widget" handle.  */
   311   HMENU menubar_widget;
   312 
   313   /* Original palette (used to deselect real palette after drawing) */
   314   HPALETTE old_palette;
   315 
   316   /* Here are the Graphics Contexts for the default font.  */
   317   Emacs_GC *cursor_gc;                  /* cursor drawing */
   318 
   319   /* The window used for this frame.
   320      May be zero while the frame object is being created
   321      and the window has not yet been created.  */
   322   Window window_desc;
   323 
   324   /* The window that is the parent of this window.
   325      Usually this is a window that was made by the window manager,
   326      but it can be the root window, and it can be explicitly specified
   327      (see the explicit_parent field, below).  */
   328   Window parent_desc;
   329 
   330   /* Default ASCII font of this frame. */
   331   struct font *font;
   332 
   333   /* The baseline offset of the default ASCII font.  */
   334   int baseline_offset;
   335 
   336   /* If a fontset is specified for this frame instead of font, this
   337      value contains an ID of the fontset, else -1.  */
   338   int fontset;
   339 
   340   /* Pixel values used for various purposes.
   341      border_pixel may be -1 meaning use a gray tile.  */
   342   COLORREF cursor_pixel;
   343   COLORREF border_pixel;
   344   COLORREF mouse_pixel;
   345   COLORREF cursor_foreground_pixel;
   346 
   347   /* Foreground color for scroll bars.  A value of -1 means use the
   348      default (black for non-toolkit scroll bars).  */
   349   COLORREF scroll_bar_foreground_pixel;
   350 
   351   /* Background color for scroll bars.  A value of -1 means use the
   352      default (background color of the frame for non-toolkit scroll
   353      bars).  */
   354   COLORREF scroll_bar_background_pixel;
   355 
   356   /* Descriptor for the cursor in use for this window.  */
   357   HCURSOR text_cursor;
   358   HCURSOR nontext_cursor;
   359   HCURSOR modeline_cursor;
   360   HCURSOR hand_cursor;
   361   HCURSOR hourglass_cursor;
   362   HCURSOR horizontal_drag_cursor;
   363   HCURSOR vertical_drag_cursor;
   364   HCURSOR left_edge_cursor;
   365   HCURSOR top_left_corner_cursor;
   366   HCURSOR top_edge_cursor;
   367   HCURSOR top_right_corner_cursor;
   368   HCURSOR right_edge_cursor;
   369   HCURSOR bottom_right_corner_cursor;
   370   HCURSOR bottom_edge_cursor;
   371   HCURSOR bottom_left_corner_cursor;
   372 
   373   /* Non-zero means hourglass cursor is currently displayed.  */
   374   unsigned hourglass_p : 1;
   375 
   376   /* Non-hourglass cursor that is currently active.  */
   377   HCURSOR current_cursor;
   378 
   379   /* The window style for this frame.  Set up when the frame is
   380      created and updated when adding/removing decorations in
   381      w32_set_undecorated.  Used by w32_set_window_size to adjust the
   382      frame's window rectangle.  */
   383   DWORD dwStyle;
   384 
   385   /* This is the Emacs structure for the display this frame is on.  */
   386   /* struct w32_display_info *display_info; */
   387 
   388   /* Nonzero means our parent is another application's window
   389      and was explicitly specified.  */
   390   unsigned explicit_parent : 1;
   391 
   392   /* Nonzero means tried already to make this frame visible.  */
   393   unsigned asked_for_visible : 1;
   394 
   395   /* Nonzero means menubar is currently active.  */
   396   unsigned menubar_active : 1;
   397 
   398   /* Relief GCs, colors etc.  */
   399   struct relief
   400   {
   401     Emacs_GC *gc;
   402     unsigned long pixel;
   403   }
   404   black_relief, white_relief;
   405 
   406   /* The background for which the above relief GCs were set up.
   407      They are changed only when a different background is involved.  */
   408   unsigned long relief_background;
   409 
   410   /* Frame geometry and full-screen mode before it was resized by
   411      specifying the 'fullscreen' frame parameter.  Used to restore the
   412      geometry when 'fullscreen' is reset to nil.  */
   413   WINDOWPLACEMENT normal_placement;
   414   int prev_fsmode;
   415 
   416   /* The back buffer if there is an ongoing double-buffered drawing
   417      operation.  */
   418   HBITMAP paint_buffer;
   419 
   420   /* The handle of the back buffer and a DC that ought to be released
   421      alongside the back buffer.  */
   422   HDC paint_dc, paint_buffer_handle;
   423 
   424   /* The object previously selected into `paint_dc'.  */
   425   HGDIOBJ paint_dc_object;
   426 
   427   /* The width and height of `paint_buffer'.  */
   428   int paint_buffer_width, paint_buffer_height;
   429 
   430   /* Whether or not some painting was done to this window that has not
   431      yet been drawn.  */
   432   unsigned paint_buffer_dirty : 1;
   433 
   434   /* Whether or not this frame should be double buffered.  */
   435   unsigned want_paint_buffer : 1;
   436 };
   437 
   438 extern struct w32_output w32term_display;
   439 
   440 /* Return the output data for frame F.  */
   441 #define FRAME_OUTPUT_DATA(f) ((f)->output_data.w32)
   442 
   443 /* Return the window associated with the frame F.  */
   444 #define FRAME_W32_WINDOW(f) ((f)->output_data.w32->window_desc)
   445 #define FRAME_NATIVE_WINDOW(f) FRAME_W32_WINDOW (f)
   446 
   447 #define FRAME_FONT(f) ((f)->output_data.w32->font)
   448 #define FRAME_FONTSET(f) ((f)->output_data.w32->fontset)
   449 #define FRAME_BASELINE_OFFSET(f) ((f)->output_data.w32->baseline_offset)
   450 
   451 /* This gives the w32_display_info structure for the display F is on.  */
   452 #define FRAME_DISPLAY_INFO(f) ((void) (f), (&one_w32_display_info))
   453 
   454 #define FRAME_NORMAL_PLACEMENT(F) ((F)->output_data.w32->normal_placement)
   455 #define FRAME_PREV_FSMODE(F)      ((F)->output_data.w32->prev_fsmode)
   456 
   457 
   458 /* W32-specific scroll bar stuff.  */
   459 
   460 /* We represent scroll bars as lisp vectors.  This allows us to place
   461    references to them in windows without worrying about whether we'll
   462    end up with windows referring to dead scroll bars; the garbage
   463    collector will free it when its time comes.
   464 
   465    We use struct scroll_bar as a template for accessing fields of the
   466    vector.  */
   467 
   468 struct scroll_bar {
   469 
   470   /* This field is shared by all vectors.  */
   471   union vectorlike_header header;
   472 
   473   /* The window we're a scroll bar for.  */
   474   Lisp_Object window;
   475 
   476   /* The next and previous in the chain of scroll bars in this frame.  */
   477   Lisp_Object next, prev;
   478 
   479   /* The window representing this scroll bar.  Since this is a full
   480      32-bit quantity, we store it split into two 32-bit values.  */
   481   Lisp_Object w32_window_low, w32_window_high;
   482 
   483   /* Same as above for the widget.  */
   484   Lisp_Object w32_widget_low, w32_widget_high;
   485 
   486   /* The position and size of the scroll bar in pixels, relative to the
   487      frame.  */
   488   int top, left, width, height;
   489 
   490   /* The starting and ending positions of the handle, relative to the
   491      handle area (i.e. zero is the top position, not
   492      SCROLL_BAR_TOP_BORDER).  If they're equal, that means the handle
   493      hasn't been drawn yet.
   494 
   495      These are not actually the locations where the beginning and end
   496      are drawn; in order to keep handles from becoming invisible when
   497      editing large files, we establish a minimum height by always
   498      drawing handle bottoms VERTICAL_SCROLL_BAR_MIN_HANDLE pixels below
   499      where they would be normally; the bottom and top are in a
   500      different coordinate system.  */
   501   int start, end;
   502 
   503   /* If the scroll bar handle is currently being dragged by the user,
   504      this is the number of pixels from the top of the handle to the
   505      place where the user grabbed it.  If the handle isn't currently
   506      being dragged, this is Qnil.  */
   507   int dragging;
   508 
   509   /* true if the scroll bar is horizontal.  */
   510   bool horizontal;
   511 };
   512 
   513 /* Turning a lisp vector value into a pointer to a struct scroll_bar.  */
   514 #define XSCROLL_BAR(vec) ((struct scroll_bar *) XVECTOR (vec))
   515 
   516 #ifdef _WIN64
   517 /* Building a 64-bit C integer from two 32-bit lisp integers.  */
   518 #define SCROLL_BAR_PACK(low, high) (XFIXNUM (high) << 32 | XFIXNUM (low))
   519 
   520 /* Setting two lisp integers to the low and high words of a 64-bit C int.  */
   521 #define SCROLL_BAR_UNPACK(low, high, int64) \
   522   (XSETINT ((low),   ((DWORDLONG)(int64))        & 0xffffffff), \
   523    XSETINT ((high), ((DWORDLONG)(int64) >> 32) & 0xffffffff))
   524 #else  /* not _WIN64 */
   525 /* Building a 32-bit C unsigned integer from two 16-bit lisp integers.  */
   526 #define SCROLL_BAR_PACK(low, high) ((UINT_PTR)(XFIXNUM (high) << 16 | XFIXNUM (low)))
   527 
   528 /* Setting two lisp integers to the low and high words of a 32-bit C int.  */
   529 #define SCROLL_BAR_UNPACK(low, high, int32) \
   530   (XSETINT ((low),   (int32)        & 0xffff), \
   531    XSETINT ((high), ((int32) >> 16) & 0xffff))
   532 #endif  /* not _WIN64 */
   533 
   534 /* Extract the window id of the scroll bar from a struct scroll_bar.  */
   535 #define SCROLL_BAR_W32_WINDOW(ptr) \
   536   ((Window) SCROLL_BAR_PACK ((ptr)->w32_window_low, (ptr)->w32_window_high))
   537 
   538 /* Store a window id in a struct scroll_bar.  */
   539 #define SET_SCROLL_BAR_W32_WINDOW(ptr, id) \
   540   (SCROLL_BAR_UNPACK ((ptr)->w32_window_low, (ptr)->w32_window_high, (intptr_t) id))
   541 
   542 /* Return the inside width of a vertical scroll bar, given the outside
   543    width.  */
   544 #define VERTICAL_SCROLL_BAR_INSIDE_WIDTH(f,width)       \
   545   ((width)                                              \
   546    - VERTICAL_SCROLL_BAR_LEFT_BORDER                    \
   547    - VERTICAL_SCROLL_BAR_RIGHT_BORDER)
   548 
   549 /* Return the length of the rectangle within which the top of the
   550    handle must stay.  This isn't equivalent to the inside height,
   551    because the scroll bar handle has a minimum height.
   552 
   553    This is the real range of motion for the scroll bar, so when we're
   554    scaling buffer positions to scroll bar positions, we use this, not
   555    VERTICAL_SCROLL_BAR_INSIDE_HEIGHT.  */
   556 #define VERTICAL_SCROLL_BAR_TOP_RANGE(f,height)                         \
   557   (VERTICAL_SCROLL_BAR_INSIDE_HEIGHT (f, height) - VERTICAL_SCROLL_BAR_MIN_HANDLE)
   558 
   559 /* Return the inside height of vertical scroll bar, given the outside
   560    height.  See VERTICAL_SCROLL_BAR_TOP_RANGE too.  */
   561 #define VERTICAL_SCROLL_BAR_INSIDE_HEIGHT(f,height)                     \
   562   ((height) - VERTICAL_SCROLL_BAR_TOP_BORDER - VERTICAL_SCROLL_BAR_BOTTOM_BORDER)
   563 
   564 /* Return the inside height of a horizontal scroll bar, given the
   565    outside height.  */
   566 #define HORIZONTAL_SCROLL_BAR_INSIDE_HEIGHT(f,height) \
   567   ((height)                                           \
   568    - HORIZONTAL_SCROLL_BAR_TOP_BORDER                 \
   569    - HORIZONTAL_SCROLL_BAR_BOTTOM_BORDER)
   570 
   571 /* Return the length of the rectangle within which the left of the
   572    handle must stay.  This isn't equivalent to the inside width,
   573    because the scroll bar handle has a minimum width.
   574 
   575    This is the real range of motion for the scroll bar, so when we're
   576    scaling buffer positions to scroll bar positions, we use this, not
   577    HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH.  */
   578 #define HORIZONTAL_SCROLL_BAR_LEFT_RANGE(f,width)                       \
   579   (HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH (f, width) - HORIZONTAL_SCROLL_BAR_MIN_HANDLE)
   580 
   581 /* Return the inside width of horizontal scroll bar, given the outside
   582    width.  See HORIZONTAL_SCROLL_BAR_LEFT_RANGE too.  */
   583 #define HORIZONTAL_SCROLL_BAR_INSIDE_WIDTH(f,width)                     \
   584   ((width) - HORIZONTAL_SCROLL_BAR_LEFT_BORDER - HORIZONTAL_SCROLL_BAR_RIGHT_BORDER)
   585 
   586 
   587 /* Border widths for scroll bars.
   588 
   589    Scroll bar windows don't have any borders; their border width is
   590    set to zero, and we redraw borders ourselves.  This makes the code
   591    a bit cleaner, since we don't have to convert between outside width
   592    (used when relating to the rest of the screen) and inside width
   593    (used when sizing and drawing the scroll bar window itself).
   594 
   595    The handle moves up and down/back and forth in a rectangle inset
   596    from the edges of the scroll bar.  These are widths by which we
   597    inset the handle boundaries from the scroll bar edges.  */
   598 #define VERTICAL_SCROLL_BAR_LEFT_BORDER (0)
   599 #define VERTICAL_SCROLL_BAR_RIGHT_BORDER (0)
   600 #define VERTICAL_SCROLL_BAR_TOP_BORDER (vertical_scroll_bar_top_border)
   601 #define VERTICAL_SCROLL_BAR_BOTTOM_BORDER (vertical_scroll_bar_bottom_border)
   602 
   603 #define HORIZONTAL_SCROLL_BAR_LEFT_BORDER (horizontal_scroll_bar_left_border)
   604 #define HORIZONTAL_SCROLL_BAR_RIGHT_BORDER (horizontal_scroll_bar_right_border)
   605 #define HORIZONTAL_SCROLL_BAR_TOP_BORDER (0)
   606 #define HORIZONTAL_SCROLL_BAR_BOTTOM_BORDER (0)
   607 
   608 /* Minimum lengths for scroll bar handles, in pixels.  */
   609 #define VERTICAL_SCROLL_BAR_MIN_HANDLE (vertical_scroll_bar_min_handle)
   610 #define HORIZONTAL_SCROLL_BAR_MIN_HANDLE (horizontal_scroll_bar_min_handle)
   611 
   612 struct frame;  /* from frame.h */
   613 
   614 extern void w32_fill_rect (struct frame *, HDC, COLORREF, RECT *);
   615 extern void w32_clear_window (struct frame *);
   616 
   617 #define w32_fill_area(f,hdc,pix,x,y,nx,ny) \
   618 do { \
   619     RECT rect; \
   620     rect.left = x; \
   621     rect.top = y; \
   622     rect.right = x + nx; \
   623     rect.bottom = y + ny; \
   624     w32_fill_rect (f,hdc,pix,&rect); \
   625 } while (0)
   626 
   627 #define w32_fill_area_abs(f,hdc,pix,x0,y0,x1,y1) \
   628 do { \
   629     RECT rect; \
   630     rect.left = x0; \
   631     rect.top = y0; \
   632     rect.right = x1; \
   633     rect.bottom = y1; \
   634     w32_fill_rect (f,hdc,pix,&rect); \
   635 } while (0)
   636 
   637 #define w32_clear_rect(f,hdc,lprect) \
   638   w32_fill_rect (f, hdc, FRAME_BACKGROUND_PIXEL (f), lprect)
   639 
   640 #define w32_clear_area(f,hdc,px,py,nx,ny) \
   641   w32_fill_area (f, hdc, FRAME_BACKGROUND_PIXEL (f), px, py, nx, ny)
   642 
   643 /* Define for earlier versions of Visual C */
   644 #ifndef WM_MOUSEWHEEL
   645 #define WM_MOUSEWHEEL                  (WM_MOUSELAST + 1)
   646 #endif /* WM_MOUSEWHEEL */
   647 #ifndef MSH_MOUSEWHEEL
   648 #define MSH_MOUSEWHEEL                 "MSWHEEL_ROLLMSG"
   649 #endif /* MSH_MOUSEWHEEL */
   650 #ifndef WM_XBUTTONDOWN
   651 #define WM_XBUTTONDOWN                 (WM_MOUSEWHEEL + 1)
   652 #define WM_XBUTTONUP                   (WM_MOUSEWHEEL + 2)
   653 #endif /* WM_XBUTTONDOWN */
   654 #ifndef WM_MOUSEHWHEEL
   655 #define WM_MOUSEHWHEEL                 (WM_MOUSEWHEEL + 4)
   656 #endif /* WM_MOUSEHWHEEL  */
   657 #ifndef WM_APPCOMMAND
   658 #define WM_APPCOMMAND 0x319
   659 #define GET_APPCOMMAND_LPARAM(lParam)  (HIWORD(lParam) & 0x7fff)
   660 #endif
   661 #ifndef WM_UNICHAR
   662 #define WM_UNICHAR 0x109
   663 #endif
   664 #ifndef UNICODE_NOCHAR
   665 #define UNICODE_NOCHAR 0xFFFF
   666 #endif
   667 
   668 #define WM_EMACS_START                 (WM_USER + 1)
   669 #define WM_EMACS_KILL                  (WM_EMACS_START + 0)
   670 #define WM_EMACS_CREATEWINDOW          (WM_EMACS_START + 1)
   671 #define WM_EMACS_DONE                  (WM_EMACS_START + 2)
   672 #define WM_EMACS_CREATEVSCROLLBAR      (WM_EMACS_START + 3)
   673 #define WM_EMACS_CREATEHSCROLLBAR      (WM_EMACS_START + 4)
   674 #define WM_EMACS_SHOWWINDOW            (WM_EMACS_START + 5)
   675 #define WM_EMACS_SETWINDOWPOS          (WM_EMACS_START + 6)
   676 #define WM_EMACS_DESTROYWINDOW         (WM_EMACS_START + 7)
   677 #define WM_EMACS_TRACKPOPUPMENU        (WM_EMACS_START + 8)
   678 #define WM_EMACS_SETFOCUS              (WM_EMACS_START + 9)
   679 #define WM_EMACS_SETFOREGROUND         (WM_EMACS_START + 10)
   680 #define WM_EMACS_SETLOCALE             (WM_EMACS_START + 11)
   681 #define WM_EMACS_SETKEYBOARDLAYOUT     (WM_EMACS_START + 12)
   682 #define WM_EMACS_REGISTER_HOT_KEY      (WM_EMACS_START + 13)
   683 #define WM_EMACS_UNREGISTER_HOT_KEY    (WM_EMACS_START + 14)
   684 #define WM_EMACS_TOGGLE_LOCK_KEY       (WM_EMACS_START + 15)
   685 #define WM_EMACS_TRACK_CARET           (WM_EMACS_START + 16)
   686 #define WM_EMACS_DESTROY_CARET         (WM_EMACS_START + 17)
   687 #define WM_EMACS_SHOW_CARET            (WM_EMACS_START + 18)
   688 #define WM_EMACS_HIDE_CARET            (WM_EMACS_START + 19)
   689 #define WM_EMACS_SETCURSOR             (WM_EMACS_START + 20)
   690 #define WM_EMACS_SHOWCURSOR            (WM_EMACS_START + 21)
   691 #define WM_EMACS_PAINT                 (WM_EMACS_START + 22)
   692 #define WM_EMACS_BRINGTOTOP            (WM_EMACS_START + 23)
   693 #define WM_EMACS_INPUT_READY           (WM_EMACS_START + 24)
   694 #define WM_EMACS_FILENOTIFY            (WM_EMACS_START + 25)
   695 #define WM_EMACS_IME_STATUS            (WM_EMACS_START + 26)
   696 #define WM_EMACS_END                   (WM_EMACS_START + 27)
   697 
   698 #define WND_FONTWIDTH_INDEX    (0)
   699 #define WND_LINEHEIGHT_INDEX   (4)
   700 #define WND_BORDER_INDEX       (8)
   701 #define WND_VSCROLLBAR_INDEX   (12)
   702 #define WND_HSCROLLBAR_INDEX   (16)
   703 #define WND_BACKGROUND_INDEX   (20)
   704 #define WND_LAST_INDEX         (24)
   705 
   706 #define WND_EXTRA_BYTES     (WND_LAST_INDEX)
   707 
   708 extern DWORD dwWindowsThreadId;
   709 extern HANDLE hWindowsThread;
   710 extern DWORD dwMainThreadId;
   711 extern HANDLE hMainThread;
   712 
   713 typedef struct W32Msg {
   714     MSG msg;
   715     DWORD dwModifiers;
   716     RECT rect;
   717 } W32Msg;
   718 
   719 extern BOOL prepend_msg (W32Msg *lpmsg);
   720 
   721 /* Structure for recording message when input thread must return a
   722    result that depends on lisp thread to compute.  Lisp thread can
   723    complete deferred messages out of order.  */
   724 typedef struct deferred_msg
   725 {
   726   struct deferred_msg * next;
   727   W32Msg                w32msg;
   728   LRESULT               result;
   729   int                   completed;
   730 } deferred_msg;
   731 
   732 extern CRITICAL_SECTION critsect;
   733 
   734 extern void init_crit (void);
   735 extern void delete_crit (void);
   736 
   737 extern void signal_quit (void);
   738 
   739 #define enter_crit() EnterCriticalSection (&critsect)
   740 #define leave_crit() LeaveCriticalSection (&critsect)
   741 
   742 extern void select_palette (struct frame * f, HDC hdc);
   743 extern void deselect_palette (struct frame * f, HDC hdc);
   744 extern HDC get_frame_dc (struct frame * f);
   745 extern int release_frame_dc (struct frame * f, HDC hDC);
   746 
   747 extern int drain_message_queue (void);
   748 
   749 extern BOOL get_next_msg (W32Msg *, BOOL);
   750 extern BOOL post_msg (W32Msg *);
   751 extern void complete_deferred_msg (HWND hwnd, UINT msg, LRESULT result);
   752 
   753 extern BOOL parse_button (int, int, int *, int *);
   754 
   755 extern void w32_sys_ring_bell (struct frame *f);
   756 extern void w32_query_color (struct frame *, Emacs_Color *);
   757 extern void w32_delete_display (struct w32_display_info *dpyinfo);
   758 
   759 #define FILE_NOTIFICATIONS_SIZE 16384
   760 /* Notifications come in sets.  We use a doubly linked list with a
   761    sentinel to communicate those sets from the watching threads to the
   762    main thread.  */
   763 struct notifications_set {
   764   LPBYTE notifications;
   765   DWORD size;
   766   void *desc;
   767   struct notifications_set *next;
   768   struct notifications_set *prev;
   769 };
   770 extern struct notifications_set *notifications_set_head;
   771 extern Lisp_Object w32_get_watch_object (void *);
   772 extern Lisp_Object w32_lispy_file_action (DWORD);
   773 extern int handle_file_notifications (struct input_event *);
   774 
   775 extern void w32_initialize_display_info (Lisp_Object);
   776 extern void initialize_w32_display (struct terminal *, int *, int *);
   777 
   778 extern bool w32_image_rotations_p (void);
   779 
   780 #ifdef WINDOWSNT
   781 /* Keyboard hooks.  */
   782 extern void setup_w32_kbdhook (void);
   783 extern void remove_w32_kbdhook (void);
   784 extern int check_w32_winkey_state (int);
   785 #define w32_kbdhook_active (os_subtype != OS_SUBTYPE_9X)
   786 #else
   787 #define w32_kbdhook_active 0
   788 #endif
   789 
   790 /* Keypad command key support.  W32 doesn't have virtual keys defined
   791    for the function keys on the keypad (they are mapped to the standard
   792    function keys), so we define our own.  */
   793 #define VK_NUMPAD_BEGIN         0x92
   794 #define VK_NUMPAD_CLEAR         (VK_NUMPAD_BEGIN + 0)
   795 #define VK_NUMPAD_ENTER         (VK_NUMPAD_BEGIN + 1)
   796 #define VK_NUMPAD_PRIOR         (VK_NUMPAD_BEGIN + 2)
   797 #define VK_NUMPAD_NEXT          (VK_NUMPAD_BEGIN + 3)
   798 #define VK_NUMPAD_END           (VK_NUMPAD_BEGIN + 4)
   799 #define VK_NUMPAD_HOME          (VK_NUMPAD_BEGIN + 5)
   800 #define VK_NUMPAD_LEFT          (VK_NUMPAD_BEGIN + 6)
   801 #define VK_NUMPAD_UP            (VK_NUMPAD_BEGIN + 7)
   802 #define VK_NUMPAD_RIGHT         (VK_NUMPAD_BEGIN + 8)
   803 #define VK_NUMPAD_DOWN          (VK_NUMPAD_BEGIN + 9)
   804 #define VK_NUMPAD_INSERT        (VK_NUMPAD_BEGIN + 10)
   805 #define VK_NUMPAD_DELETE        (VK_NUMPAD_BEGIN + 11)
   806 
   807 #ifndef VK_LWIN
   808 /* Older compiler environments don't have these defined.  */
   809 #define VK_LWIN                 0x5B
   810 #define VK_RWIN                 0x5C
   811 #define VK_APPS                 0x5D
   812 #endif
   813 
   814 /* Support for treating Windows and Apps keys as modifiers.  These
   815    constants must not overlap with any of the dwControlKeyState flags in
   816    KEY_EVENT_RECORD.  */
   817 #define LEFT_WIN_PRESSED       0x8000
   818 #define RIGHT_WIN_PRESSED      0x4000
   819 #define APPS_PRESSED           0x2000
   820 
   821 /* The current ANSI input codepage for GUI sessions.  */
   822 extern int w32_keyboard_codepage;
   823 
   824 /* When compiling on Windows 9x/ME and NT 3.x, the following are not defined
   825    (even though they are supported on 98 and ME.  */
   826 #ifndef WM_MOUSELEAVE
   827 #define WM_MOUSELEAVE 0x02A3
   828 #define TME_LEAVE 0x00000002;
   829 
   830 typedef struct tagTRACKMOUSEEVENT
   831 {
   832   DWORD cbSize;
   833   DWORD dwFlags;
   834   HWND hwndTrack;
   835   DWORD dwHoverTime;
   836 } TRACKMOUSEEVENT;
   837 #endif
   838 
   839 struct image;
   840 struct face;
   841 
   842 Emacs_GC *XCreateGC (void *, HWND, unsigned long, Emacs_GC *);
   843 
   844 typedef DWORD (WINAPI * ClipboardSequence_Proc) (void);
   845 typedef BOOL (WINAPI * AppendMenuW_Proc) (
   846     IN HMENU,
   847     IN UINT,
   848     IN UINT_PTR,
   849     IN LPCWSTR);
   850 
   851 extern HWND w32_system_caret_hwnd;
   852 extern int w32_system_caret_height;
   853 extern int w32_system_caret_x;
   854 extern int w32_system_caret_y;
   855 extern struct window *w32_system_caret_window;
   856 extern int w32_system_caret_hdr_height;
   857 extern int w32_system_caret_mode_height;
   858 
   859 extern Window tip_window;
   860 
   861 #ifdef _MSC_VER
   862 #ifndef EnumSystemLocales
   863 /* MSVC headers define these only for _WIN32_WINNT >= 0x0500.  */
   864 typedef BOOL (CALLBACK *LOCALE_ENUMPROCA)(LPSTR);
   865 typedef BOOL (CALLBACK *LOCALE_ENUMPROCW)(LPWSTR);
   866 BOOL WINAPI EnumSystemLocalesA(LOCALE_ENUMPROCA,DWORD);
   867 BOOL WINAPI EnumSystemLocalesW(LOCALE_ENUMPROCW,DWORD);
   868 #ifdef UNICODE
   869 #define EnumSystemLocales EnumSystemLocalesW
   870 #else
   871 #define EnumSystemLocales EnumSystemLocalesA
   872 #endif
   873 #endif
   874 #endif
   875 
   876 #if EMACSDEBUG
   877 extern const char*
   878 w32_name_of_message (UINT msg);
   879 #endif /* EMACSDEBUG */
   880 
   881 #ifdef NTGUI_UNICODE
   882 extern Lisp_Object ntgui_encode_system (Lisp_Object str);
   883 #define GUISTR(x) (L ## x)
   884 #define GUI_ENCODE_FILE GUI_ENCODE_SYSTEM
   885 #define GUI_ENCODE_SYSTEM(x) ntgui_encode_system (x)
   886 #define GUI_FN(fn) fn ## W
   887 typedef wchar_t guichar_t;
   888 #else /* !NTGUI_UNICODE */
   889 #define GUISTR(x) x
   890 #define GUI_ENCODE_FILE ENCODE_FILE
   891 #define GUI_ENCODE_SYSTEM ENCODE_SYSTEM
   892 #define GUI_FN(fn) fn
   893 typedef char guichar_t;
   894 #endif /* NTGUI_UNICODE */
   895 
   896 #define GUI_SDATA(x) ((guichar_t*) SDATA (x))
   897 
   898 extern Lisp_Object w32_popup_dialog (struct frame *, Lisp_Object, Lisp_Object);
   899 extern void w32_arrow_cursor (void);
   900 extern void w32_release_paint_buffer (struct frame *);
   901 extern void w32_flip_buffers_if_dirty (struct frame *);
   902 
   903 extern void syms_of_w32term (void);
   904 extern void syms_of_w32menu (void);
   905 extern void syms_of_w32fns (void);
   906 
   907 extern void globals_of_w32menu (void);
   908 extern void globals_of_w32fns (void);
   909 extern void globals_of_w32notify (void);
   910 
   911 extern void w32_init_main_thread (void);
   912 
   913 #ifdef CYGWIN
   914 extern int w32_message_fd;
   915 #endif /* CYGWIN */

/* [<][>][^][v][top][bottom][index][help] */