forked from enlightenment/efl
ecore_cocoa: add more safety checks
Signed-off-by: Cedric BAIL <cedric@osg.samsung.com>
This commit is contained in:
parent
b61fc5814b
commit
0bb310f2ad
|
@ -57,11 +57,10 @@ static NSCursor *_cursors[__ECORE_COCOA_CURSOR_LAST];
|
||||||
NSLog(@"window is going to be closed");
|
NSLog(@"window is going to be closed");
|
||||||
Ecore_Cocoa_Event_Window *event;
|
Ecore_Cocoa_Event_Window *event;
|
||||||
|
|
||||||
event = malloc(sizeof(Ecore_Cocoa_Event_Window));
|
event = malloc(sizeof(*event));
|
||||||
if (event == NULL)
|
if (EINA_UNLIKELY(event == NULL))
|
||||||
{
|
{
|
||||||
// FIXME Use Eina_Log
|
CRI("Failed to allocate Ecore_Cocoa_Event_Window");
|
||||||
printf("Failed to allocate Ecore_Cocoa_Event_Window_destroy\n");
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
event->wid = [notification object];
|
event->wid = [notification object];
|
||||||
|
@ -73,10 +72,10 @@ static NSCursor *_cursors[__ECORE_COCOA_CURSOR_LAST];
|
||||||
Ecore_Cocoa_Event_Video_Resize *event;
|
Ecore_Cocoa_Event_Video_Resize *event;
|
||||||
NSSize size = self.frame.size;
|
NSSize size = self.frame.size;
|
||||||
|
|
||||||
event = malloc(sizeof(Ecore_Cocoa_Event_Video_Resize));
|
event = malloc(sizeof(*event));
|
||||||
if (event == NULL)
|
if (EINA_UNLIKELY(event == NULL))
|
||||||
{
|
{
|
||||||
DBG("Failed to allocate Ecore_Cocoa_Event_Video_Resize\n");
|
CRI("Failed to allocate Ecore_Cocoa_Event_Video_Resize");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
event->w = size.width;
|
event->w = size.width;
|
||||||
|
@ -90,10 +89,10 @@ static NSCursor *_cursors[__ECORE_COCOA_CURSOR_LAST];
|
||||||
{
|
{
|
||||||
Ecore_Cocoa_Event_Window *e;
|
Ecore_Cocoa_Event_Window *e;
|
||||||
|
|
||||||
e = malloc(sizeof(Ecore_Cocoa_Event_Window));
|
e = malloc(sizeof(*e));
|
||||||
if (!e)
|
if (EINA_UNLIKELY(e == NULL))
|
||||||
{
|
{
|
||||||
DBG("GOT_FOCUS: Failed to allocate Ecore_Cocoa_Event_Window\n");
|
CRI("Failed to allocate Ecore_Cocoa_Event_Window");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e->wid = [notification object];
|
e->wid = [notification object];
|
||||||
|
@ -104,10 +103,10 @@ static NSCursor *_cursors[__ECORE_COCOA_CURSOR_LAST];
|
||||||
{
|
{
|
||||||
Ecore_Cocoa_Event_Window *e;
|
Ecore_Cocoa_Event_Window *e;
|
||||||
|
|
||||||
e = malloc(sizeof(Ecore_Cocoa_Event_Window));
|
e = malloc(sizeof(*e));
|
||||||
if (!e)
|
if (EINA_UNLIKELY(e == NULL))
|
||||||
{
|
{
|
||||||
DBG("LOST_FOCUS: Failed to allocate Ecore_Cocoa_Event_Window\n");
|
CRI("Failed to allocate Ecore_Cocoa_Event_Window");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
e->wid = [notification object];
|
e->wid = [notification object];
|
||||||
|
@ -133,7 +132,12 @@ static NSCursor *_cursors[__ECORE_COCOA_CURSOR_LAST];
|
||||||
}
|
}
|
||||||
|
|
||||||
Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button));
|
Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button));
|
||||||
if (!ev) return;
|
|
||||||
|
if (EINA_UNLIKELY(!ev))
|
||||||
|
{
|
||||||
|
CRI("Failed to allocate Ecore_Event_Mouse_Button");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ev->x = x;
|
ev->x = x;
|
||||||
ev->y = y;
|
ev->y = y;
|
||||||
|
@ -185,8 +189,12 @@ static NSCursor *_cursors[__ECORE_COCOA_CURSOR_LAST];
|
||||||
int x = pt.x;
|
int x = pt.x;
|
||||||
int y = h - pt.y;
|
int y = h - pt.y;
|
||||||
|
|
||||||
Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button));
|
Ecore_Event_Mouse_Button *ev = calloc(1, sizeof(*ev));
|
||||||
if (!ev) return;
|
if (EINA_UNLIKELY(!ev))
|
||||||
|
{
|
||||||
|
CRI("Failed to allocate Ecore_Event_Mouse_Button");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ev->x = x;
|
ev->x = x;
|
||||||
ev->y = y;
|
ev->y = y;
|
||||||
|
@ -229,8 +237,12 @@ static NSCursor *_cursors[__ECORE_COCOA_CURSOR_LAST];
|
||||||
- (void) mouseMoved:(NSEvent*) event
|
- (void) mouseMoved:(NSEvent*) event
|
||||||
{
|
{
|
||||||
unsigned int time = (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff);
|
unsigned int time = (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff);
|
||||||
Ecore_Event_Mouse_Move * ev = calloc(1, sizeof(Ecore_Event_Mouse_Move));
|
Ecore_Event_Mouse_Move *ev = calloc(1, sizeof(*ev));
|
||||||
if (!ev) return;
|
if (EINA_UNLIKELY(!ev))
|
||||||
|
{
|
||||||
|
CRI("Failed to allocate Ecore_Event_Mouse_Move");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
NSView *view = [self contentView];
|
NSView *view = [self contentView];
|
||||||
NSPoint event_location = [event locationInWindow];
|
NSPoint event_location = [event locationInWindow];
|
||||||
|
@ -271,8 +283,11 @@ ecore_cocoa_window_new(int x,
|
||||||
backing:NSBackingStoreBuffered
|
backing:NSBackingStoreBuffered
|
||||||
defer:NO];
|
defer:NO];
|
||||||
|
|
||||||
if (!window)
|
if (EINA_UNLIKELY(!window))
|
||||||
|
{
|
||||||
|
CRI("Failed to create EcoreCocoaWindow");
|
||||||
return NULL;
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
//Set the process to be a foreground process,
|
//Set the process to be a foreground process,
|
||||||
//without that it prevents the window to become the key window and
|
//without that it prevents the window to become the key window and
|
||||||
|
@ -282,8 +297,10 @@ ecore_cocoa_window_new(int x,
|
||||||
|
|
||||||
|
|
||||||
w = calloc(1, sizeof(Ecore_Cocoa_Window));
|
w = calloc(1, sizeof(Ecore_Cocoa_Window));
|
||||||
if (w == NULL)
|
if (EINA_UNLIKELY(w == NULL))
|
||||||
{
|
{
|
||||||
|
CRI("Failed to allocate Ecore_Cocoa_Window");
|
||||||
|
[window release];
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
w->window = window;
|
w->window = window;
|
||||||
|
@ -309,8 +326,8 @@ ecore_cocoa_window_size_min_set(Ecore_Cocoa_Window *window,
|
||||||
unsigned int w,
|
unsigned int w,
|
||||||
unsigned int h)
|
unsigned int h)
|
||||||
{
|
{
|
||||||
if (!window)
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
||||||
return;
|
|
||||||
NSSize size = {w,h};
|
NSSize size = {w,h};
|
||||||
window->window.contentMinSize = size;
|
window->window.contentMinSize = size;
|
||||||
}
|
}
|
||||||
|
@ -320,8 +337,8 @@ ecore_cocoa_window_size_max_set(Ecore_Cocoa_Window *window,
|
||||||
unsigned int w,
|
unsigned int w,
|
||||||
unsigned int h)
|
unsigned int h)
|
||||||
{
|
{
|
||||||
if (!window)
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
||||||
return;
|
|
||||||
NSSize size = {w,h};
|
NSSize size = {w,h};
|
||||||
window->window.contentMaxSize = size;
|
window->window.contentMaxSize = size;
|
||||||
}
|
}
|
||||||
|
@ -331,8 +348,8 @@ ecore_cocoa_window_size_step_set(Ecore_Cocoa_Window *window,
|
||||||
unsigned int w,
|
unsigned int w,
|
||||||
unsigned int h)
|
unsigned int h)
|
||||||
{
|
{
|
||||||
if (!window)
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
||||||
return;
|
|
||||||
NSSize size = {w,h};
|
NSSize size = {w,h};
|
||||||
window->window.contentResizeIncrements = size;
|
window->window.contentResizeIncrements = size;
|
||||||
}
|
}
|
||||||
|
@ -342,10 +359,9 @@ ecore_cocoa_window_move(Ecore_Cocoa_Window *window,
|
||||||
int x,
|
int x,
|
||||||
int y)
|
int y)
|
||||||
{
|
{
|
||||||
NSRect win_frame;
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
||||||
|
|
||||||
if (!window)
|
NSRect win_frame;
|
||||||
return;
|
|
||||||
|
|
||||||
win_frame = [window->window frame];
|
win_frame = [window->window frame];
|
||||||
win_frame.origin.x = x;
|
win_frame.origin.x = x;
|
||||||
|
@ -359,7 +375,7 @@ ecore_cocoa_window_resize(Ecore_Cocoa_Window *window,
|
||||||
int width,
|
int width,
|
||||||
int height)
|
int height)
|
||||||
{
|
{
|
||||||
if (!window) return;
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
||||||
|
|
||||||
NSRect win_frame;
|
NSRect win_frame;
|
||||||
|
|
||||||
|
@ -378,7 +394,7 @@ ecore_cocoa_window_move_resize(Ecore_Cocoa_Window *window,
|
||||||
int width,
|
int width,
|
||||||
int height)
|
int height)
|
||||||
{
|
{
|
||||||
if (!window) return;
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
||||||
|
|
||||||
NSRect win_frame;
|
NSRect win_frame;
|
||||||
|
|
||||||
|
@ -395,8 +411,8 @@ ecore_cocoa_window_move_resize(Ecore_Cocoa_Window *window,
|
||||||
EAPI void
|
EAPI void
|
||||||
ecore_cocoa_window_title_set(Ecore_Cocoa_Window *window, const char *title)
|
ecore_cocoa_window_title_set(Ecore_Cocoa_Window *window, const char *title)
|
||||||
{
|
{
|
||||||
if (!window || !title)
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
||||||
return;
|
EINA_SAFETY_ON_NULL_RETURN(title);
|
||||||
|
|
||||||
[window->window setTitle:[NSString stringWithUTF8String:title]];
|
[window->window setTitle:[NSString stringWithUTF8String:title]];
|
||||||
}
|
}
|
||||||
|
@ -404,48 +420,39 @@ ecore_cocoa_window_title_set(Ecore_Cocoa_Window *window, const char *title)
|
||||||
EAPI void
|
EAPI void
|
||||||
ecore_cocoa_window_show(Ecore_Cocoa_Window *window)
|
ecore_cocoa_window_show(Ecore_Cocoa_Window *window)
|
||||||
{
|
{
|
||||||
if (!window || [window->window isVisible])
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
||||||
{
|
|
||||||
DBG("Window(%p) is not visible\n", window->window);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
if (![window->window isVisible])
|
||||||
[window->window makeKeyAndOrderFront:NSApp];
|
[window->window makeKeyAndOrderFront:NSApp];
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
ecore_cocoa_window_hide(Ecore_Cocoa_Window *window)
|
ecore_cocoa_window_hide(Ecore_Cocoa_Window *window)
|
||||||
{
|
{
|
||||||
if (!window || ![window->window isVisible])
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
||||||
return;
|
|
||||||
|
|
||||||
|
if (![window->window isVisible])
|
||||||
[window->window orderOut:NSApp];
|
[window->window orderOut:NSApp];
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
ecore_cocoa_window_raise(Ecore_Cocoa_Window *window)
|
ecore_cocoa_window_raise(Ecore_Cocoa_Window *window)
|
||||||
{
|
{
|
||||||
if (!window)
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
||||||
return;
|
|
||||||
|
|
||||||
[window->window orderFront:nil];
|
[window->window orderFront:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
ecore_cocoa_window_lower(Ecore_Cocoa_Window *window)
|
ecore_cocoa_window_lower(Ecore_Cocoa_Window *window)
|
||||||
{
|
{
|
||||||
if (!window)
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
||||||
return;
|
|
||||||
|
|
||||||
[window->window orderBack:nil];
|
[window->window orderBack:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
EAPI void
|
EAPI void
|
||||||
ecore_cocoa_window_activate(Ecore_Cocoa_Window *window)
|
ecore_cocoa_window_activate(Ecore_Cocoa_Window *window)
|
||||||
{
|
{
|
||||||
if (!window)
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
||||||
return;
|
|
||||||
|
|
||||||
[window->window makeKeyAndOrderFront:nil];
|
[window->window makeKeyAndOrderFront:nil];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -453,8 +460,7 @@ EAPI void
|
||||||
ecore_cocoa_window_iconified_set(Ecore_Cocoa_Window *window,
|
ecore_cocoa_window_iconified_set(Ecore_Cocoa_Window *window,
|
||||||
int on)
|
int on)
|
||||||
{
|
{
|
||||||
if (!window)
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
||||||
return;
|
|
||||||
|
|
||||||
if (on)
|
if (on)
|
||||||
{
|
{
|
||||||
|
@ -470,8 +476,7 @@ EAPI void
|
||||||
ecore_cocoa_window_borderless_set(Ecore_Cocoa_Window *window,
|
ecore_cocoa_window_borderless_set(Ecore_Cocoa_Window *window,
|
||||||
int on)
|
int on)
|
||||||
{
|
{
|
||||||
if (!window)
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
||||||
return;
|
|
||||||
|
|
||||||
if (on)
|
if (on)
|
||||||
[window->window setContentBorderThickness:0.0
|
[window->window setContentBorderThickness:0.0
|
||||||
|
@ -482,8 +487,8 @@ EAPI void
|
||||||
ecore_cocoa_window_view_set(Ecore_Cocoa_Window *window,
|
ecore_cocoa_window_view_set(Ecore_Cocoa_Window *window,
|
||||||
void *view)
|
void *view)
|
||||||
{
|
{
|
||||||
if (!window || !view)
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
||||||
return;
|
EINA_SAFETY_ON_NULL_RETURN(view);
|
||||||
|
|
||||||
//[[window->window contentView] addSubview:view];
|
//[[window->window contentView] addSubview:view];
|
||||||
NSView *v = view;
|
NSView *v = view;
|
||||||
|
@ -503,8 +508,7 @@ ecore_cocoa_window_view_set(Ecore_Cocoa_Window *window,
|
||||||
EAPI Ecore_Cocoa_Window_Id
|
EAPI Ecore_Cocoa_Window_Id
|
||||||
ecore_cocoa_window_get_window_id(const Ecore_Cocoa_Window *window)
|
ecore_cocoa_window_get_window_id(const Ecore_Cocoa_Window *window)
|
||||||
{
|
{
|
||||||
if (!window)
|
EINA_SAFETY_ON_NULL_RETURN_VAL(window, NULL);
|
||||||
return 0;
|
|
||||||
|
|
||||||
DBG("Return : %p", window->window);
|
DBG("Return : %p", window->window);
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue