Commit ed367c50 authored by Ken Thomases's avatar Ken Thomases Committed by Alexandre Julliard

winemac: Implement a WINDOW_CLOSE_REQUESTED event to allow closing windows.

parent 4e83d2fc
......@@ -437,6 +437,10 @@ static BOOL frame_intersects_screens(NSRect frame, NSArray* screens)
*/
- (BOOL)windowShouldClose:(id)sender
{
macdrv_event event;
event.type = WINDOW_CLOSE_REQUESTED;
event.window = (macdrv_window)[self retain];
[queue postEvent:&event];
return NO;
}
......
......@@ -31,6 +31,11 @@ WINE_DEFAULT_DEBUG_CHANNEL(event);
/* return the name of an Mac event */
static const char *dbgstr_event(int type)
{
static const char * const event_names[] = {
"WINDOW_CLOSE_REQUESTED",
};
if (0 <= type && type < NUM_EVENT_TYPES) return event_names[type];
return wine_dbg_sprintf("Unknown event %d", type);
}
......@@ -40,8 +45,14 @@ static const char *dbgstr_event(int type)
*/
static macdrv_event_mask get_event_mask(DWORD mask)
{
macdrv_event_mask event_mask = 0;
if ((mask & QS_ALLINPUT) == QS_ALLINPUT) return -1;
return 0;
if (mask & QS_POSTMESSAGE)
event_mask |= event_mask_for_type(WINDOW_CLOSE_REQUESTED);
return event_mask;
}
......@@ -62,6 +73,9 @@ void macdrv_handle_event(macdrv_event *event)
switch (event->type)
{
case WINDOW_CLOSE_REQUESTED:
macdrv_window_close_requested(hwnd);
break;
default:
TRACE(" ignoring\n");
break;
......
......@@ -117,4 +117,6 @@ extern struct window_surface *create_surface(macdrv_window window, const RECT *r
extern void set_window_surface(macdrv_window window, struct window_surface *window_surface) DECLSPEC_HIDDEN;
extern void set_surface_use_alpha(struct window_surface *window_surface, BOOL use_alpha) DECLSPEC_HIDDEN;
extern void macdrv_window_close_requested(HWND hwnd) DECLSPEC_HIDDEN;
#endif /* __WINE_MACDRV_H */
......@@ -121,6 +121,11 @@ extern void macdrv_free_displays(struct macdrv_display* displays) DECLSPEC_HIDDE
/* event */
enum {
WINDOW_CLOSE_REQUESTED,
NUM_EVENT_TYPES
};
typedef uint32_t macdrv_event_mask;
typedef struct macdrv_event {
......
......@@ -35,6 +35,8 @@ DWORD thread_data_tls_index = TLS_OUT_OF_INDEXES;
*/
static BOOL process_attach(void)
{
assert(NUM_EVENT_TYPES <= sizeof(macdrv_event_mask) * 8);
if ((thread_data_tls_index = TlsAlloc()) == TLS_OUT_OF_INDEXES) return FALSE;
macdrv_err_on = ERR_ON(macdrv);
......
......@@ -1230,3 +1230,52 @@ void CDECL macdrv_WindowPosChanged(HWND hwnd, HWND insert_after, UINT swp_flags,
done:
release_win_data(data);
}
/***********************************************************************
* macdrv_window_close_requested
*
* Handler for WINDOW_CLOSE_REQUESTED events.
*/
void macdrv_window_close_requested(HWND hwnd)
{
/* Ignore the delete window request if the window has been disabled. This
* is to disallow applications from being closed while in a modal state.
*/
if (IsWindowEnabled(hwnd))
{
HMENU hSysMenu;
if (GetClassLongW(hwnd, GCL_STYLE) & CS_NOCLOSE) return;
hSysMenu = GetSystemMenu(hwnd, FALSE);
if (hSysMenu)
{
UINT state = GetMenuState(hSysMenu, SC_CLOSE, MF_BYCOMMAND);
if (state == 0xFFFFFFFF || (state & (MF_DISABLED | MF_GRAYED)))
return;
}
if (GetActiveWindow() != hwnd)
{
LRESULT ma = SendMessageW(hwnd, WM_MOUSEACTIVATE,
(WPARAM)GetAncestor(hwnd, GA_ROOT),
MAKELPARAM(HTCLOSE, WM_NCLBUTTONDOWN));
switch(ma)
{
case MA_NOACTIVATEANDEAT:
case MA_ACTIVATEANDEAT:
return;
case MA_NOACTIVATE:
break;
case MA_ACTIVATE:
case 0:
SetActiveWindow(hwnd);
break;
default:
WARN("unknown WM_MOUSEACTIVATE code %d\n", (int) ma);
break;
}
}
PostMessageW(hwnd, WM_SYSCOMMAND, SC_CLOSE, 0);
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment