user.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  1. /*
  2. * Wine server USER definitions
  3. *
  4. * Copyright (C) 2001 Alexandre Julliard
  5. *
  6. * This library is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 2.1 of the License, or (at your option) any later version.
  10. *
  11. * This library 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 GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this library; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
  19. */
  20. #ifndef __WINE_SERVER_USER_H
  21. #define __WINE_SERVER_USER_H
  22. #include "wine/server_protocol.h"
  23. struct thread;
  24. struct region;
  25. struct window;
  26. struct msg_queue;
  27. struct hook_table;
  28. struct window_class;
  29. struct atom_table;
  30. struct clipboard;
  31. enum user_object
  32. {
  33. USER_WINDOW = 1,
  34. USER_HOOK,
  35. USER_CLIENT /* arbitrary client handle */
  36. };
  37. #define DESKTOP_ATOM ((atom_t)32769)
  38. struct winstation
  39. {
  40. struct object obj; /* object header */
  41. unsigned int flags; /* winstation flags */
  42. struct list entry; /* entry in global winstation list */
  43. struct list desktops; /* list of desktops of this winstation */
  44. struct clipboard *clipboard; /* clipboard information */
  45. struct atom_table *atom_table; /* global atom table */
  46. struct namespace *desktop_names; /* namespace for desktops of this winstation */
  47. };
  48. struct global_cursor
  49. {
  50. int x; /* cursor position */
  51. int y;
  52. rectangle_t clip; /* cursor clip rectangle */
  53. unsigned int last_change; /* time of last position change */
  54. user_handle_t win; /* window that contains the cursor */
  55. };
  56. struct desktop
  57. {
  58. struct object obj; /* object header */
  59. unsigned int flags; /* desktop flags */
  60. struct winstation *winstation; /* winstation this desktop belongs to */
  61. struct list entry; /* entry in winstation list of desktops */
  62. struct window *top_window; /* desktop window for this desktop */
  63. struct window *msg_window; /* HWND_MESSAGE top window */
  64. struct hook_table *global_hooks; /* table of global hooks on this desktop */
  65. struct list hotkeys; /* list of registered hotkeys */
  66. struct timeout_user *close_timeout; /* timeout before closing the desktop */
  67. struct thread_input *foreground_input; /* thread input of foreground thread */
  68. unsigned int users; /* processes and threads using this desktop */
  69. struct global_cursor cursor; /* global cursor information */
  70. unsigned char keystate[256]; /* asynchronous key state */
  71. };
  72. /* user handles functions */
  73. extern user_handle_t alloc_user_handle( void *ptr, enum user_object type );
  74. extern void *get_user_object( user_handle_t handle, enum user_object type );
  75. extern void *get_user_object_handle( user_handle_t *handle, enum user_object type );
  76. extern user_handle_t get_user_full_handle( user_handle_t handle );
  77. extern void *free_user_handle( user_handle_t handle );
  78. extern void *next_user_handle( user_handle_t *handle, enum user_object type );
  79. extern void free_process_user_handles( struct process *process );
  80. /* clipboard functions */
  81. extern void cleanup_clipboard_window( struct desktop *desktop, user_handle_t window );
  82. extern void cleanup_clipboard_thread( struct thread *thread );
  83. /* hook functions */
  84. extern void remove_thread_hooks( struct thread *thread );
  85. extern unsigned int get_active_hooks(void);
  86. extern struct thread *get_first_global_hook( int id );
  87. /* queue functions */
  88. extern void free_msg_queue( struct thread *thread );
  89. extern struct hook_table *get_queue_hooks( struct thread *thread );
  90. extern void set_queue_hooks( struct thread *thread, struct hook_table *hooks );
  91. extern void inc_queue_paint_count( struct thread *thread, int incr );
  92. extern void queue_cleanup_window( struct thread *thread, user_handle_t win );
  93. extern int init_thread_queue( struct thread *thread );
  94. extern int attach_thread_input( struct thread *thread_from, struct thread *thread_to );
  95. extern void detach_thread_input( struct thread *thread_from );
  96. extern void set_clip_rectangle( struct desktop *desktop, const rectangle_t *rect,
  97. unsigned int flags, int reset );
  98. extern void post_message( user_handle_t win, unsigned int message,
  99. lparam_t wparam, lparam_t lparam );
  100. extern void send_notify_message( user_handle_t win, unsigned int message,
  101. lparam_t wparam, lparam_t lparam );
  102. extern void post_win_event( struct thread *thread, unsigned int event,
  103. user_handle_t win, unsigned int object_id,
  104. unsigned int child_id, client_ptr_t proc,
  105. const WCHAR *module, data_size_t module_size,
  106. user_handle_t handle );
  107. extern void free_hotkeys( struct desktop *desktop, user_handle_t window );
  108. /* region functions */
  109. extern struct region *create_empty_region(void);
  110. extern struct region *create_region_from_req_data( const void *data, data_size_t size );
  111. extern void free_region( struct region *region );
  112. extern void set_region_rect( struct region *region, const rectangle_t *rect );
  113. extern rectangle_t *get_region_data( const struct region *region, data_size_t max_size,
  114. data_size_t *total_size );
  115. extern rectangle_t *get_region_data_and_free( struct region *region, data_size_t max_size,
  116. data_size_t *total_size );
  117. extern int is_region_empty( const struct region *region );
  118. extern int is_region_equal( const struct region *region1, const struct region *region2 );
  119. extern void get_region_extents( const struct region *region, rectangle_t *rect );
  120. extern void offset_region( struct region *region, int x, int y );
  121. extern void mirror_region( const rectangle_t *client_rect, struct region *region );
  122. extern void scale_region( struct region *region, unsigned int dpi_from, unsigned int dpi_to );
  123. extern struct region *copy_region( struct region *dst, const struct region *src );
  124. extern struct region *intersect_region( struct region *dst, const struct region *src1,
  125. const struct region *src2 );
  126. extern struct region *subtract_region( struct region *dst, const struct region *src1,
  127. const struct region *src2 );
  128. extern struct region *union_region( struct region *dst, const struct region *src1,
  129. const struct region *src2 );
  130. extern struct region *xor_region( struct region *dst, const struct region *src1,
  131. const struct region *src2 );
  132. extern int point_in_region( struct region *region, int x, int y );
  133. extern int rect_in_region( struct region *region, const rectangle_t *rect );
  134. /* window functions */
  135. extern struct process *get_top_window_owner( struct desktop *desktop );
  136. extern void get_top_window_rectangle( struct desktop *desktop, rectangle_t *rect );
  137. extern void post_desktop_message( struct desktop *desktop, unsigned int message,
  138. lparam_t wparam, lparam_t lparam );
  139. extern void free_window_handle( struct window *win );
  140. extern void destroy_thread_windows( struct thread *thread );
  141. extern int is_child_window( user_handle_t parent, user_handle_t child );
  142. extern int is_valid_foreground_window( user_handle_t window );
  143. extern int is_window_visible( user_handle_t window );
  144. extern int is_window_transparent( user_handle_t window );
  145. extern int make_window_active( user_handle_t window );
  146. extern struct thread *get_window_thread( user_handle_t handle );
  147. extern user_handle_t shallow_window_from_point( struct desktop *desktop, int x, int y );
  148. extern struct thread *window_thread_from_point( user_handle_t scope, int x, int y );
  149. extern user_handle_t find_window_to_repaint( user_handle_t parent, struct thread *thread );
  150. extern struct window_class *get_window_class( user_handle_t window );
  151. /* window class functions */
  152. extern void destroy_process_classes( struct process *process );
  153. extern struct window_class *grab_class( struct process *process, atom_t atom,
  154. mod_handle_t instance, int *extra_bytes );
  155. extern void release_class( struct window_class *class );
  156. extern int is_desktop_class( struct window_class *class );
  157. extern int is_hwnd_message_class( struct window_class *class );
  158. extern int get_class_style( struct window_class *class );
  159. extern atom_t get_class_atom( struct window_class *class );
  160. extern client_ptr_t get_class_client_ptr( struct window_class *class );
  161. /* windows station functions */
  162. extern struct desktop *get_desktop_obj( struct process *process, obj_handle_t handle, unsigned int access );
  163. extern struct winstation *get_process_winstation( struct process *process, unsigned int access );
  164. extern struct desktop *get_thread_desktop( struct thread *thread, unsigned int access );
  165. extern void connect_process_winstation( struct process *process, struct thread *parent_thread,
  166. struct process *parent_process );
  167. extern void set_process_default_desktop( struct process *process, struct desktop *desktop,
  168. obj_handle_t handle );
  169. extern void close_process_desktop( struct process *process );
  170. extern void set_thread_default_desktop( struct thread *thread, struct desktop *desktop, obj_handle_t handle );
  171. extern void release_thread_desktop( struct thread *thread, int close );
  172. /* checks if two rectangles are identical */
  173. static inline int is_rect_equal( const rectangle_t *rect1, const rectangle_t *rect2 )
  174. {
  175. return (rect1->left == rect2->left && rect1->right == rect2->right &&
  176. rect1->top == rect2->top && rect1->bottom == rect2->bottom);
  177. }
  178. static inline int is_rect_empty( const rectangle_t *rect )
  179. {
  180. return (rect->left >= rect->right || rect->top >= rect->bottom);
  181. }
  182. static inline int point_in_rect( const rectangle_t *rect, int x, int y )
  183. {
  184. return (x >= rect->left && x < rect->right && y >= rect->top && y < rect->bottom);
  185. }
  186. static inline int scale_dpi( int val, unsigned int dpi_from, unsigned int dpi_to )
  187. {
  188. if (val >= 0) return (val * dpi_to + (dpi_from / 2)) / dpi_from;
  189. return (val * dpi_to - (dpi_from / 2)) / dpi_from;
  190. }
  191. static inline void scale_dpi_rect( rectangle_t *rect, unsigned int dpi_from, unsigned int dpi_to )
  192. {
  193. rect->left = scale_dpi( rect->left, dpi_from, dpi_to );
  194. rect->top = scale_dpi( rect->top, dpi_from, dpi_to );
  195. rect->right = scale_dpi( rect->right, dpi_from, dpi_to );
  196. rect->bottom = scale_dpi( rect->bottom, dpi_from, dpi_to );
  197. }
  198. /* offset the coordinates of a rectangle */
  199. static inline void offset_rect( rectangle_t *rect, int offset_x, int offset_y )
  200. {
  201. rect->left += offset_x;
  202. rect->top += offset_y;
  203. rect->right += offset_x;
  204. rect->bottom += offset_y;
  205. }
  206. /* mirror a rectangle respective to the window client area */
  207. static inline void mirror_rect( const rectangle_t *client_rect, rectangle_t *rect )
  208. {
  209. int width = client_rect->right - client_rect->left;
  210. int tmp = rect->left;
  211. rect->left = width - rect->right;
  212. rect->right = width - tmp;
  213. }
  214. /* compute the intersection of two rectangles; return 0 if the result is empty */
  215. static inline int intersect_rect( rectangle_t *dst, const rectangle_t *src1, const rectangle_t *src2 )
  216. {
  217. dst->left = max( src1->left, src2->left );
  218. dst->top = max( src1->top, src2->top );
  219. dst->right = min( src1->right, src2->right );
  220. dst->bottom = min( src1->bottom, src2->bottom );
  221. return !is_rect_empty( dst );
  222. }
  223. /* validate a window handle and return the full handle */
  224. static inline user_handle_t get_valid_window_handle( user_handle_t win )
  225. {
  226. if (get_user_object_handle( &win, USER_WINDOW )) return win;
  227. set_win32_error( ERROR_INVALID_WINDOW_HANDLE );
  228. return 0;
  229. }
  230. #endif /* __WINE_SERVER_USER_H */