2 * Wine server USER definitions
4 * Copyright (C) 2001 Alexandre Julliard
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.
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.
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
21 #ifndef __WINE_SERVER_USER_H
22 #define __WINE_SERVER_USER_H
24 #include "wine/server_protocol.h"
40 USER_CLIENT
/* arbitrary client handle */
43 #define DESKTOP_ATOM ((atom_t)32769)
47 struct object obj
; /* object header */
48 unsigned int flags
; /* winstation flags */
49 struct list entry
; /* entry in global winstation list */
50 struct list desktops
; /* list of desktops of this winstation */
51 struct desktop
*input_desktop
; /* desktop receiving user input */
52 struct clipboard
*clipboard
; /* clipboard information */
53 struct atom_table
*atom_table
; /* global atom table */
54 struct namespace *desktop_names
; /* namespace for desktops of this winstation */
59 int x
; /* cursor position */
61 rectangle_t clip
; /* cursor clip rectangle */
62 unsigned int last_change
; /* time of last position change */
63 user_handle_t win
; /* window that contains the cursor */
68 struct object obj
; /* object header */
69 unsigned int flags
; /* desktop flags */
70 struct winstation
*winstation
; /* winstation this desktop belongs to */
71 timeout_t input_time
; /* last time this desktop had the input */
72 struct list entry
; /* entry in winstation list of desktops */
73 struct list threads
; /* list of threads connected to this desktop */
74 struct window
*top_window
; /* desktop window for this desktop */
75 struct window
*msg_window
; /* HWND_MESSAGE top window */
76 struct hook_table
*global_hooks
; /* table of global hooks on this desktop */
77 struct list hotkeys
; /* list of registered hotkeys */
78 struct list pointers
; /* list of active pointers */
79 struct timeout_user
*close_timeout
; /* timeout before closing the desktop */
80 struct thread_input
*foreground_input
; /* thread input of foreground thread */
81 unsigned int users
; /* processes and threads using this desktop */
82 struct global_cursor cursor
; /* global cursor information */
83 unsigned char keystate
[256]; /* asynchronous key state */
86 /* user handles functions */
88 extern user_handle_t
alloc_user_handle( void *ptr
, enum user_object type
);
89 extern void *get_user_object( user_handle_t handle
, enum user_object type
);
90 extern void *get_user_object_handle( user_handle_t
*handle
, enum user_object type
);
91 extern user_handle_t
get_user_full_handle( user_handle_t handle
);
92 extern void *free_user_handle( user_handle_t handle
);
93 extern void *next_user_handle( user_handle_t
*handle
, enum user_object type
);
94 extern void free_process_user_handles( struct process
*process
);
96 /* clipboard functions */
98 extern void cleanup_clipboard_window( struct desktop
*desktop
, user_handle_t window
);
99 extern void cleanup_clipboard_thread( struct thread
*thread
);
103 extern void remove_thread_hooks( struct thread
*thread
);
104 extern unsigned int get_active_hooks(void);
105 extern struct thread
*get_first_global_hook( int id
);
107 /* queue functions */
109 extern void free_msg_queue( struct thread
*thread
);
110 extern struct hook_table
*get_queue_hooks( struct thread
*thread
);
111 extern void set_queue_hooks( struct thread
*thread
, struct hook_table
*hooks
);
112 extern void inc_queue_paint_count( struct thread
*thread
, int incr
);
113 extern void queue_cleanup_window( struct thread
*thread
, user_handle_t win
);
114 extern int init_thread_queue( struct thread
*thread
);
115 extern int attach_thread_input( struct thread
*thread_from
, struct thread
*thread_to
);
116 extern void detach_thread_input( struct thread
*thread_from
);
117 extern void set_clip_rectangle( struct desktop
*desktop
, const rectangle_t
*rect
,
118 unsigned int flags
, int reset
);
119 extern void post_message( user_handle_t win
, unsigned int message
,
120 lparam_t wparam
, lparam_t lparam
);
121 extern void send_notify_message( user_handle_t win
, unsigned int message
,
122 lparam_t wparam
, lparam_t lparam
);
123 extern void post_win_event( struct thread
*thread
, unsigned int event
,
124 user_handle_t win
, unsigned int object_id
,
125 unsigned int child_id
, client_ptr_t proc
,
126 const WCHAR
*module
, data_size_t module_size
,
127 user_handle_t handle
);
128 extern void free_hotkeys( struct desktop
*desktop
, user_handle_t window
);
129 extern void free_pointers( struct desktop
*desktop
);
130 extern void set_rawinput_process( struct process
*process
, int enable
);
132 /* region functions */
134 extern struct region
*create_empty_region(void);
135 extern struct region
*create_region_from_req_data( const void *data
, data_size_t size
);
136 extern void free_region( struct region
*region
);
137 extern void set_region_rect( struct region
*region
, const rectangle_t
*rect
);
138 extern rectangle_t
*get_region_data( const struct region
*region
, data_size_t max_size
,
139 data_size_t
*total_size
);
140 extern rectangle_t
*get_region_data_and_free( struct region
*region
, data_size_t max_size
,
141 data_size_t
*total_size
);
142 extern int is_region_empty( const struct region
*region
);
143 extern int is_region_equal( const struct region
*region1
, const struct region
*region2
);
144 extern void get_region_extents( const struct region
*region
, rectangle_t
*rect
);
145 extern void offset_region( struct region
*region
, int x
, int y
);
146 extern void mirror_region( const rectangle_t
*client_rect
, struct region
*region
);
147 extern void scale_region( struct region
*region
, unsigned int dpi_from
, unsigned int dpi_to
);
148 extern struct region
*copy_region( struct region
*dst
, const struct region
*src
);
149 extern struct region
*intersect_region( struct region
*dst
, const struct region
*src1
,
150 const struct region
*src2
);
151 extern struct region
*subtract_region( struct region
*dst
, const struct region
*src1
,
152 const struct region
*src2
);
153 extern struct region
*union_region( struct region
*dst
, const struct region
*src1
,
154 const struct region
*src2
);
155 extern struct region
*xor_region( struct region
*dst
, const struct region
*src1
,
156 const struct region
*src2
);
157 extern int point_in_region( struct region
*region
, int x
, int y
);
158 extern int rect_in_region( struct region
*region
, const rectangle_t
*rect
);
160 /* window functions */
162 extern struct process
*get_top_window_owner( struct desktop
*desktop
);
163 extern void get_top_window_rectangle( struct desktop
*desktop
, rectangle_t
*rect
);
164 extern void post_desktop_message( struct desktop
*desktop
, unsigned int message
,
165 lparam_t wparam
, lparam_t lparam
);
166 extern void free_window_handle( struct window
*win
);
167 extern void destroy_thread_windows( struct thread
*thread
);
168 extern int is_child_window( user_handle_t parent
, user_handle_t child
);
169 extern int is_valid_foreground_window( user_handle_t window
);
170 extern int is_window_visible( user_handle_t window
);
171 extern int is_window_transparent( user_handle_t window
);
172 extern int make_window_active( user_handle_t window
);
173 extern struct thread
*get_window_thread( user_handle_t handle
);
174 extern user_handle_t
shallow_window_from_point( struct desktop
*desktop
, int x
, int y
);
175 extern struct thread
*window_thread_from_point( user_handle_t scope
, int x
, int y
);
176 extern user_handle_t
find_window_to_repaint( user_handle_t parent
, struct thread
*thread
);
177 extern struct window_class
*get_window_class( user_handle_t window
);
179 /* window class functions */
181 extern void destroy_process_classes( struct process
*process
);
182 extern struct window_class
*grab_class( struct process
*process
, atom_t atom
,
183 mod_handle_t instance
, int *extra_bytes
);
184 extern void release_class( struct window_class
*class );
185 extern int is_desktop_class( struct window_class
*class );
186 extern int is_hwnd_message_class( struct window_class
*class );
187 extern int get_class_style( struct window_class
*class );
188 extern atom_t
get_class_atom( struct window_class
*class );
189 extern client_ptr_t
get_class_client_ptr( struct window_class
*class );
191 /* windows station functions */
193 extern struct winstation
*get_visible_winstation(void);
194 extern struct desktop
*get_input_desktop( struct winstation
*winstation
);
195 extern int set_input_desktop( struct winstation
*winstation
, struct desktop
*new_desktop
);
196 extern struct desktop
*get_desktop_obj( struct process
*process
, obj_handle_t handle
, unsigned int access
);
197 extern struct winstation
*get_process_winstation( struct process
*process
, unsigned int access
);
198 extern struct desktop
*get_thread_desktop( struct thread
*thread
, unsigned int access
);
199 extern void connect_process_winstation( struct process
*process
, struct unicode_str
*desktop_path
,
200 struct thread
*parent_thread
, struct process
*parent_process
);
201 extern void set_process_default_desktop( struct process
*process
, struct desktop
*desktop
,
202 obj_handle_t handle
);
203 extern void close_process_desktop( struct process
*process
);
204 extern void set_thread_default_desktop( struct thread
*thread
, struct desktop
*desktop
, obj_handle_t handle
);
205 extern void release_thread_desktop( struct thread
*thread
, int close
);
207 /* checks if two rectangles are identical */
208 static inline int is_rect_equal( const rectangle_t
*rect1
, const rectangle_t
*rect2
)
210 return (rect1
->left
== rect2
->left
&& rect1
->right
== rect2
->right
&&
211 rect1
->top
== rect2
->top
&& rect1
->bottom
== rect2
->bottom
);
214 static inline int is_rect_empty( const rectangle_t
*rect
)
216 return (rect
->left
>= rect
->right
|| rect
->top
>= rect
->bottom
);
219 static inline int point_in_rect( const rectangle_t
*rect
, int x
, int y
)
221 return (x
>= rect
->left
&& x
< rect
->right
&& y
>= rect
->top
&& y
< rect
->bottom
);
224 static inline int scale_dpi( int val
, unsigned int dpi_from
, unsigned int dpi_to
)
226 if (val
>= 0) return (val
* dpi_to
+ (dpi_from
/ 2)) / dpi_from
;
227 return (val
* dpi_to
- (dpi_from
/ 2)) / dpi_from
;
230 static inline void scale_dpi_rect( rectangle_t
*rect
, unsigned int dpi_from
, unsigned int dpi_to
)
232 rect
->left
= scale_dpi( rect
->left
, dpi_from
, dpi_to
);
233 rect
->top
= scale_dpi( rect
->top
, dpi_from
, dpi_to
);
234 rect
->right
= scale_dpi( rect
->right
, dpi_from
, dpi_to
);
235 rect
->bottom
= scale_dpi( rect
->bottom
, dpi_from
, dpi_to
);
238 /* offset the coordinates of a rectangle */
239 static inline void offset_rect( rectangle_t
*rect
, int offset_x
, int offset_y
)
241 rect
->left
+= offset_x
;
242 rect
->top
+= offset_y
;
243 rect
->right
+= offset_x
;
244 rect
->bottom
+= offset_y
;
247 /* mirror a rectangle respective to the window client area */
248 static inline void mirror_rect( const rectangle_t
*client_rect
, rectangle_t
*rect
)
250 int width
= client_rect
->right
- client_rect
->left
;
251 int tmp
= rect
->left
;
252 rect
->left
= width
- rect
->right
;
253 rect
->right
= width
- tmp
;
256 /* compute the intersection of two rectangles; return 0 if the result is empty */
257 static inline int intersect_rect( rectangle_t
*dst
, const rectangle_t
*src1
, const rectangle_t
*src2
)
259 dst
->left
= max( src1
->left
, src2
->left
);
260 dst
->top
= max( src1
->top
, src2
->top
);
261 dst
->right
= min( src1
->right
, src2
->right
);
262 dst
->bottom
= min( src1
->bottom
, src2
->bottom
);
263 return !is_rect_empty( dst
);
266 /* validate a window handle and return the full handle */
267 static inline user_handle_t
get_valid_window_handle( user_handle_t win
)
269 if (get_user_object_handle( &win
, USER_WINDOW
)) return win
;
270 set_win32_error( ERROR_INVALID_WINDOW_HANDLE
);
274 #endif /* __WINE_SERVER_USER_H */