2015-09-04 05:07:52 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include <config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <Ecore_Input.h>
|
|
|
|
|
|
|
|
#include <Ecore.h>
|
|
|
|
#include <Ecore_Cocoa.h>
|
|
|
|
#import "ecore_cocoa_window.h"
|
2015-10-16 01:19:57 -07:00
|
|
|
#import "ecore_cocoa_app.h"
|
2015-09-04 05:07:52 -07:00
|
|
|
#include "ecore_cocoa_private.h"
|
|
|
|
|
2015-10-08 02:58:46 -07:00
|
|
|
static NSCursor *_cursors[__ECORE_COCOA_CURSOR_LAST];
|
|
|
|
|
|
|
|
|
2015-09-04 05:07:52 -07:00
|
|
|
@implementation EcoreCocoaWindow
|
|
|
|
|
|
|
|
@synthesize ecore_window_data;
|
|
|
|
|
|
|
|
- (id) initWithContentRect: (NSRect) contentRect
|
|
|
|
styleMask: (unsigned int) aStyle
|
|
|
|
backing: (NSBackingStoreType) bufferingType
|
|
|
|
defer: (BOOL) flag
|
|
|
|
{
|
2015-10-14 00:32:20 -07:00
|
|
|
if (![super initWithContentRect: contentRect
|
|
|
|
styleMask: aStyle
|
|
|
|
backing: bufferingType
|
|
|
|
defer: flag]) return nil;
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
[self setBackgroundColor: [NSColor whiteColor]];
|
|
|
|
[self makeKeyWindow];
|
|
|
|
[self setDelegate:self];
|
|
|
|
[self setAcceptsMouseMovedEvents:YES];
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
[self setCollectionBehavior:NSWindowCollectionBehaviorFullScreenPrimary];
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
return self;
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)isFullScreen
|
|
|
|
{
|
|
|
|
return (([self styleMask] & NSFullScreenWindowMask) == NSFullScreenWindowMask);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)acceptsFirstResponder
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (BOOL)canBecomeKeyWindow
|
|
|
|
{
|
2015-10-14 00:32:20 -07:00
|
|
|
return YES;
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
2015-10-14 00:18:06 -07:00
|
|
|
- (void)windowWillClose:(NSNotification *) notification
|
2015-09-04 05:07:52 -07:00
|
|
|
{
|
|
|
|
NSLog(@"window is going to be closed");
|
2016-01-06 13:13:42 -08:00
|
|
|
Ecore_Cocoa_Event_Window_Destroy *event;
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:31:45 -07:00
|
|
|
event = malloc(sizeof(*event));
|
|
|
|
if (EINA_UNLIKELY(event == NULL))
|
2015-09-04 05:07:52 -07:00
|
|
|
{
|
2015-10-14 00:31:45 -07:00
|
|
|
CRI("Failed to allocate Ecore_Cocoa_Event_Window");
|
|
|
|
return;
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
2016-01-06 12:38:10 -08:00
|
|
|
event->cocoa_window = [notification object];
|
2015-09-04 05:07:52 -07:00
|
|
|
ecore_event_add(ECORE_COCOA_EVENT_WINDOW_DESTROY, event, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
2015-10-14 00:41:08 -07:00
|
|
|
- (void)windowDidResize:(NSNotification *) notif
|
2015-09-04 05:07:52 -07:00
|
|
|
{
|
2016-01-06 12:56:09 -08:00
|
|
|
Ecore_Cocoa_Event_Window_Resize_Request *event;
|
2015-09-04 05:07:52 -07:00
|
|
|
NSSize size = self.frame.size;
|
|
|
|
|
2015-10-14 00:31:45 -07:00
|
|
|
event = malloc(sizeof(*event));
|
|
|
|
if (EINA_UNLIKELY(event == NULL))
|
2015-09-04 05:07:52 -07:00
|
|
|
{
|
2016-01-06 12:56:09 -08:00
|
|
|
CRI("Failed to allocate Ecore_Cocoa_Event_Window_Resize_Request");
|
2015-09-04 05:07:52 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
event->w = size.width;
|
|
|
|
event->h = size.height -
|
|
|
|
(([self isFullScreen] == YES) ? 0 : ecore_cocoa_titlebar_height_get());
|
2016-01-06 12:38:10 -08:00
|
|
|
event->cocoa_window = [notif object];
|
2016-01-06 12:56:09 -08:00
|
|
|
ecore_event_add(ECORE_COCOA_EVENT_WINDOW_RESIZE_REQUEST, event, NULL, NULL);
|
2015-10-16 01:19:57 -07:00
|
|
|
|
|
|
|
/*
|
|
|
|
* During live resize, NSRunLoop blocks, and prevent the ecore_main_loop
|
|
|
|
* to be run.
|
|
|
|
* This, combined with the -pauseNSRunLoopMonitoring and
|
|
|
|
* -resumeNSRunLoopMonitoring methods invoked in
|
|
|
|
* -windowWillStartLiveResize and -windowDidEndLiveResize
|
|
|
|
* allow the ecore_main_loop to run withing NSRunLoop during the
|
|
|
|
* live resizing of a window.
|
|
|
|
*/
|
|
|
|
ecore_main_loop_iterate();
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)windowDidBecomeKey:(NSNotification *)notification
|
|
|
|
{
|
2016-01-06 13:13:42 -08:00
|
|
|
Ecore_Cocoa_Event_Window_Focused *e;
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
e = malloc(sizeof(*e));
|
|
|
|
if (EINA_UNLIKELY(e == NULL))
|
|
|
|
{
|
|
|
|
CRI("Failed to allocate Ecore_Cocoa_Event_Window");
|
|
|
|
return;
|
|
|
|
}
|
2016-01-06 12:38:10 -08:00
|
|
|
e->cocoa_window = [notification object];
|
2016-01-06 12:56:09 -08:00
|
|
|
ecore_event_add(ECORE_COCOA_EVENT_WINDOW_FOCUSED, e, NULL, NULL);
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
2015-10-16 01:19:57 -07:00
|
|
|
- (void) windowWillStartLiveResize:(NSNotification *) EINA_UNUSED notification
|
|
|
|
{
|
|
|
|
[NSApp pauseNSRunLoopMonitoring];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) windowDidEndLiveResize:(NSNotification *) EINA_UNUSED notification
|
|
|
|
{
|
|
|
|
[NSApp resumeNSRunLoopMonitoring];
|
|
|
|
}
|
|
|
|
|
2015-09-04 05:07:52 -07:00
|
|
|
- (void)windowDidResignKey:(NSNotification *)notification
|
|
|
|
{
|
2016-01-06 13:13:42 -08:00
|
|
|
Ecore_Cocoa_Event_Window_Unfocused *e;
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
e = malloc(sizeof(*e));
|
|
|
|
if (EINA_UNLIKELY(e == NULL))
|
|
|
|
{
|
|
|
|
CRI("Failed to allocate Ecore_Cocoa_Event_Window");
|
|
|
|
return;
|
|
|
|
}
|
2016-01-06 12:38:10 -08:00
|
|
|
e->cocoa_window = [notification object];
|
2016-01-06 12:56:09 -08:00
|
|
|
ecore_event_add(ECORE_COCOA_EVENT_WINDOW_UNFOCUSED, e, NULL, NULL);
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mouseDown:(NSEvent*) event
|
|
|
|
{
|
|
|
|
unsigned int time = (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff);
|
|
|
|
|
|
|
|
NSView *view = [self contentView];
|
|
|
|
NSPoint event_location = [event locationInWindow];
|
|
|
|
NSPoint pt = [view convertPoint:event_location fromView:nil];
|
|
|
|
|
|
|
|
int h = [view frame].size.height;
|
|
|
|
int x = pt.x;
|
|
|
|
int y = h - pt.y;
|
|
|
|
|
2015-10-23 09:18:39 -07:00
|
|
|
//we ignore left click in titlebar as it is handled by the OS (to move window)
|
|
|
|
//and the corresponding mouseUp event isn't sent
|
|
|
|
if (y <= 0 && [event buttonNumber] == 0) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-09-04 05:07:52 -07:00
|
|
|
Ecore_Event_Mouse_Button * ev = calloc(1, sizeof(Ecore_Event_Mouse_Button));
|
2015-10-14 00:31:45 -07:00
|
|
|
|
|
|
|
if (EINA_UNLIKELY(!ev))
|
|
|
|
{
|
|
|
|
CRI("Failed to allocate Ecore_Event_Mouse_Button");
|
|
|
|
return;
|
|
|
|
}
|
2015-09-04 05:07:52 -07:00
|
|
|
|
|
|
|
ev->x = x;
|
|
|
|
ev->y = y;
|
|
|
|
ev->root.x = ev->x;
|
|
|
|
ev->root.y = ev->y;
|
|
|
|
ev->timestamp = time;
|
|
|
|
switch ([event buttonNumber])
|
|
|
|
{
|
|
|
|
case 0: ev->buttons = 1; break;
|
|
|
|
case 1: ev->buttons = 3; break;
|
|
|
|
case 2: ev->buttons = 2; break;
|
|
|
|
default: ev->buttons = 0; break;
|
|
|
|
}
|
|
|
|
ev->window = (Ecore_Window)self.ecore_window_data;
|
|
|
|
ev->event_window = ev->window;
|
|
|
|
|
|
|
|
if ([event clickCount] == 2)
|
|
|
|
ev->double_click = 1;
|
|
|
|
else
|
|
|
|
ev->double_click = 0;
|
|
|
|
|
|
|
|
if ([event clickCount] >= 3)
|
|
|
|
ev->triple_click = 1;
|
|
|
|
else
|
|
|
|
ev->triple_click = 0;
|
|
|
|
|
|
|
|
ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_DOWN, ev, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) rightMouseDown:(NSEvent*) event
|
|
|
|
{
|
2015-10-14 00:32:20 -07:00
|
|
|
[self mouseDown: event];
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) otherMouseDown:(NSEvent*) event
|
|
|
|
{
|
2015-10-14 00:32:20 -07:00
|
|
|
[self mouseDown: event];
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mouseUp:(NSEvent*) event
|
|
|
|
{
|
|
|
|
unsigned int time = (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff);
|
|
|
|
|
|
|
|
NSView *view = [self contentView];
|
|
|
|
NSPoint event_location = [event locationInWindow];
|
|
|
|
NSPoint pt = [view convertPoint:event_location fromView:nil];
|
|
|
|
|
|
|
|
int h = [view frame].size.height;
|
|
|
|
int x = pt.x;
|
|
|
|
int y = h - pt.y;
|
|
|
|
|
2015-10-14 00:31:45 -07:00
|
|
|
Ecore_Event_Mouse_Button *ev = calloc(1, sizeof(*ev));
|
|
|
|
if (EINA_UNLIKELY(!ev))
|
|
|
|
{
|
|
|
|
CRI("Failed to allocate Ecore_Event_Mouse_Button");
|
|
|
|
return;
|
|
|
|
}
|
2015-09-04 05:07:52 -07:00
|
|
|
|
|
|
|
ev->x = x;
|
|
|
|
ev->y = y;
|
|
|
|
ev->root.x = ev->x;
|
|
|
|
ev->root.y = ev->y;
|
|
|
|
ev->timestamp = time;
|
|
|
|
switch ([event buttonNumber])
|
|
|
|
{
|
|
|
|
case 0: ev->buttons = 1; break;
|
|
|
|
case 1: ev->buttons = 3; break;
|
|
|
|
case 2: ev->buttons = 2; break;
|
|
|
|
default: ev->buttons = 0; break;
|
|
|
|
}
|
|
|
|
ev->window = (Ecore_Window)self.ecore_window_data;
|
|
|
|
ev->event_window = ev->window;
|
|
|
|
|
|
|
|
if ([event clickCount] == 2)
|
|
|
|
ev->double_click = 1;
|
|
|
|
else
|
|
|
|
ev->double_click = 0;
|
|
|
|
|
|
|
|
if ([event clickCount] >= 3)
|
|
|
|
ev->triple_click = 1;
|
|
|
|
else
|
|
|
|
ev->triple_click = 0;
|
|
|
|
|
|
|
|
ecore_event_add(ECORE_EVENT_MOUSE_BUTTON_UP, ev, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) rightMouseUp:(NSEvent*) event
|
|
|
|
{
|
2015-10-14 00:32:20 -07:00
|
|
|
[self mouseUp: event];
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) otherMouseUp:(NSEvent*) event
|
|
|
|
{
|
2015-10-14 00:32:20 -07:00
|
|
|
[self mouseUp: event];
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mouseMoved:(NSEvent*) event
|
|
|
|
{
|
2015-10-06 09:49:53 -07:00
|
|
|
unsigned int time = (unsigned int)((unsigned long long)(ecore_time_get() * 1000.0) & 0xffffffff);
|
2015-10-14 00:31:45 -07:00
|
|
|
Ecore_Event_Mouse_Move *ev = calloc(1, sizeof(*ev));
|
|
|
|
if (EINA_UNLIKELY(!ev))
|
|
|
|
{
|
|
|
|
CRI("Failed to allocate Ecore_Event_Mouse_Move");
|
|
|
|
return;
|
|
|
|
}
|
2015-09-04 05:07:52 -07:00
|
|
|
|
|
|
|
NSView *view = [self contentView];
|
|
|
|
NSPoint event_location = [event locationInWindow];
|
|
|
|
NSPoint pt = [view convertPoint:event_location fromView:nil];
|
|
|
|
|
|
|
|
ev->x = pt.x;
|
|
|
|
ev->y = [view frame].size.height - pt.y;
|
|
|
|
ev->root.x = ev->x;
|
|
|
|
ev->root.y = ev->y;
|
|
|
|
ev->timestamp = time;
|
|
|
|
ev->window = (Ecore_Window)self.ecore_window_data;
|
|
|
|
ev->event_window = ev->window;
|
|
|
|
ev->modifiers = 0; /* FIXME: keep modifier around. */
|
|
|
|
|
|
|
|
ecore_event_add(ECORE_EVENT_MOUSE_MOVE, ev, NULL, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) mouseDragged: (NSEvent*) event
|
|
|
|
{
|
|
|
|
[self mouseMoved:event];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2015-10-13 02:01:15 -07:00
|
|
|
EAPI Ecore_Cocoa_Window *
|
2015-09-04 05:07:52 -07:00
|
|
|
ecore_cocoa_window_new(int x,
|
2015-10-14 00:32:20 -07:00
|
|
|
int y,
|
2016-01-06 13:01:41 -08:00
|
|
|
int w,
|
|
|
|
int h)
|
2015-10-14 00:32:20 -07:00
|
|
|
{
|
2016-01-06 13:01:41 -08:00
|
|
|
Ecore_Cocoa_Window *win;
|
2015-10-15 04:58:52 -07:00
|
|
|
EcoreCocoaWindow *window;
|
|
|
|
NSUInteger style =
|
|
|
|
NSTitledWindowMask |
|
|
|
|
NSClosableWindowMask |
|
|
|
|
NSResizableWindowMask |
|
|
|
|
NSMiniaturizableWindowMask;
|
|
|
|
|
2016-01-06 13:01:41 -08:00
|
|
|
window = [[EcoreCocoaWindow alloc] initWithContentRect:NSMakeRect(x, y, w, h)
|
2015-10-15 04:58:52 -07:00
|
|
|
styleMask:style
|
|
|
|
backing:NSBackingStoreBuffered
|
|
|
|
defer:NO];
|
2015-10-14 00:32:20 -07:00
|
|
|
if (EINA_UNLIKELY(!window))
|
|
|
|
{
|
|
|
|
CRI("Failed to create EcoreCocoaWindow");
|
|
|
|
return NULL;
|
|
|
|
}
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2016-01-06 13:01:41 -08:00
|
|
|
win = calloc(1, sizeof(*win));
|
|
|
|
if (EINA_UNLIKELY(win == NULL))
|
2015-10-14 00:32:20 -07:00
|
|
|
{
|
|
|
|
CRI("Failed to allocate Ecore_Cocoa_Window");
|
|
|
|
[window release];
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-01-06 13:01:41 -08:00
|
|
|
win->window = window;
|
|
|
|
win->borderless = 0;
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2016-01-06 13:01:41 -08:00
|
|
|
window.ecore_window_data = win;
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2016-01-06 13:01:41 -08:00
|
|
|
return win;
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
2015-10-13 02:01:15 -07:00
|
|
|
EAPI void
|
2015-09-04 05:07:52 -07:00
|
|
|
ecore_cocoa_window_free(Ecore_Cocoa_Window *window)
|
|
|
|
{
|
2015-10-14 00:32:20 -07:00
|
|
|
if (!window)
|
|
|
|
return;
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
[window->window release];
|
|
|
|
free(window);
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
2015-10-13 02:01:15 -07:00
|
|
|
EAPI void
|
2015-09-04 05:07:52 -07:00
|
|
|
ecore_cocoa_window_size_min_set(Ecore_Cocoa_Window *window,
|
2016-01-05 15:16:16 -08:00
|
|
|
int w,
|
|
|
|
int h)
|
2015-09-04 05:07:52 -07:00
|
|
|
{
|
2015-10-14 00:31:45 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
|
|
|
|
2016-01-05 14:51:54 -08:00
|
|
|
window->window.contentMinSize = NSMakeSize(w, h);
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
2016-01-05 14:50:52 -08:00
|
|
|
EAPI void
|
|
|
|
ecore_cocoa_window_size_min_get(const Ecore_Cocoa_Window *window,
|
2016-01-05 15:16:16 -08:00
|
|
|
int *w,
|
|
|
|
int *h)
|
2016-01-05 14:50:52 -08:00
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
|
|
|
|
|
|
|
const NSSize size = window->window.contentMinSize;
|
2016-01-05 15:16:16 -08:00
|
|
|
if (w) *w = size.width;
|
|
|
|
if (h) *h = size.height;
|
2016-01-05 14:50:52 -08:00
|
|
|
}
|
|
|
|
|
2015-10-13 02:01:15 -07:00
|
|
|
EAPI void
|
2015-09-04 05:07:52 -07:00
|
|
|
ecore_cocoa_window_size_max_set(Ecore_Cocoa_Window *window,
|
2016-01-05 15:16:16 -08:00
|
|
|
int w,
|
|
|
|
int h)
|
2015-09-04 05:07:52 -07:00
|
|
|
{
|
2015-10-14 00:31:45 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
|
|
|
|
2016-01-05 14:51:54 -08:00
|
|
|
window->window.contentMaxSize = NSMakeSize(w, h);
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
2016-01-05 14:54:57 -08:00
|
|
|
EAPI void
|
|
|
|
ecore_cocoa_window_size_max_get(const Ecore_Cocoa_Window *window,
|
2016-01-05 15:16:16 -08:00
|
|
|
int *w,
|
|
|
|
int *h)
|
2016-01-05 14:54:57 -08:00
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
|
|
|
|
|
|
|
const NSSize size = window->window.contentMaxSize;
|
2016-01-05 15:16:16 -08:00
|
|
|
if (w) *w = size.width;
|
|
|
|
if (h) *h = size.height;
|
2016-01-05 14:54:57 -08:00
|
|
|
}
|
|
|
|
|
2015-10-13 02:01:15 -07:00
|
|
|
EAPI void
|
2015-09-04 05:07:52 -07:00
|
|
|
ecore_cocoa_window_size_step_set(Ecore_Cocoa_Window *window,
|
2016-01-05 15:16:16 -08:00
|
|
|
int w,
|
|
|
|
int h)
|
2015-09-04 05:07:52 -07:00
|
|
|
{
|
2015-10-14 00:31:45 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
|
|
|
|
2016-01-05 14:51:54 -08:00
|
|
|
window->window.contentResizeIncrements = NSMakeSize(w, h);
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
2016-01-05 14:58:04 -08:00
|
|
|
EAPI void
|
|
|
|
ecore_cocoa_window_size_step_get(const Ecore_Cocoa_Window *window,
|
2016-01-05 15:16:16 -08:00
|
|
|
int *w,
|
|
|
|
int *h)
|
2016-01-05 14:58:04 -08:00
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
|
|
|
|
|
|
|
const NSSize size = window->window.contentResizeIncrements;
|
2016-01-05 15:16:16 -08:00
|
|
|
if (w) *w = size.width;
|
|
|
|
if (h) *h = size.height;
|
2016-01-05 14:58:04 -08:00
|
|
|
}
|
|
|
|
|
2015-10-13 02:01:15 -07:00
|
|
|
EAPI void
|
2015-09-04 05:07:52 -07:00
|
|
|
ecore_cocoa_window_move(Ecore_Cocoa_Window *window,
|
2015-10-14 00:32:20 -07:00
|
|
|
int x,
|
|
|
|
int y)
|
2015-09-04 05:07:52 -07:00
|
|
|
{
|
2015-10-14 00:31:45 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
NSRect win_frame;
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
win_frame = [window->window frame];
|
|
|
|
win_frame.origin.x = x;
|
|
|
|
win_frame.origin.y = y;
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
[window->window setFrame:win_frame display:YES];
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
2015-10-13 02:01:15 -07:00
|
|
|
EAPI void
|
2015-09-04 05:07:52 -07:00
|
|
|
ecore_cocoa_window_resize(Ecore_Cocoa_Window *window,
|
2016-01-06 13:01:41 -08:00
|
|
|
int w,
|
|
|
|
int h)
|
2015-09-04 05:07:52 -07:00
|
|
|
{
|
2015-10-14 00:31:45 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
NSRect win_frame;
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
win_frame = [window->window frame];
|
2016-01-06 13:01:41 -08:00
|
|
|
win_frame.size.height = h +
|
2015-10-14 00:32:20 -07:00
|
|
|
(([window->window isFullScreen] == YES) ? 0 : ecore_cocoa_titlebar_height_get());
|
2016-01-06 13:01:41 -08:00
|
|
|
win_frame.size.width = w;
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
[window->window setFrame:win_frame display:YES];
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
2016-01-05 14:45:50 -08:00
|
|
|
EAPI void
|
|
|
|
ecore_cocoa_window_geometry_get(const Ecore_Cocoa_Window *window,
|
|
|
|
int *x,
|
|
|
|
int *y,
|
|
|
|
int *w,
|
|
|
|
int *h)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
|
|
|
|
|
|
|
const NSRect frame = window->window.frame;
|
|
|
|
if (x) *x = frame.origin.x;
|
|
|
|
if (y) *y = frame.origin.y;
|
|
|
|
if (w) *w = frame.size.width;
|
|
|
|
if (h) *h = frame.size.height;
|
|
|
|
}
|
|
|
|
|
2016-01-05 14:47:30 -08:00
|
|
|
EAPI void
|
|
|
|
ecore_cocoa_window_size_get(const Ecore_Cocoa_Window *window,
|
|
|
|
int *w,
|
|
|
|
int *h)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
|
|
|
|
|
|
|
const NSSize size = window->window.frame.size;
|
|
|
|
if (w) *w = size.width;
|
|
|
|
if (h) *h = size.height;
|
|
|
|
}
|
|
|
|
|
2015-10-13 02:01:15 -07:00
|
|
|
EAPI void
|
2015-09-04 05:07:52 -07:00
|
|
|
ecore_cocoa_window_move_resize(Ecore_Cocoa_Window *window,
|
2015-10-14 00:32:20 -07:00
|
|
|
int x,
|
|
|
|
int y,
|
2016-01-05 15:16:16 -08:00
|
|
|
int w,
|
|
|
|
int h)
|
2015-09-04 05:07:52 -07:00
|
|
|
{
|
2015-10-14 00:31:45 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
NSRect win_frame;
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
win_frame = [window->window frame];
|
2016-01-05 15:16:16 -08:00
|
|
|
win_frame.size.height = h +
|
2015-10-14 00:32:20 -07:00
|
|
|
(([window->window isFullScreen] == YES) ? 0 : ecore_cocoa_titlebar_height_get());
|
2016-01-05 15:16:16 -08:00
|
|
|
win_frame.size.width = w;
|
2015-10-14 00:32:20 -07:00
|
|
|
win_frame.origin.x = x;
|
|
|
|
win_frame.origin.y = y;
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
[window->window setFrame:win_frame display:YES];
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
2015-10-13 02:01:15 -07:00
|
|
|
EAPI void
|
2015-09-04 05:07:52 -07:00
|
|
|
ecore_cocoa_window_title_set(Ecore_Cocoa_Window *window, const char *title)
|
|
|
|
{
|
2015-10-14 00:31:45 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(title);
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
[window->window setTitle:[NSString stringWithUTF8String:title]];
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
2015-10-13 02:01:15 -07:00
|
|
|
EAPI void
|
2015-09-04 05:07:52 -07:00
|
|
|
ecore_cocoa_window_show(Ecore_Cocoa_Window *window)
|
|
|
|
{
|
2015-10-14 00:31:45 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
if (![window->window isVisible])
|
|
|
|
[window->window makeKeyAndOrderFront:NSApp];
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
2015-10-13 02:01:15 -07:00
|
|
|
EAPI void
|
2015-09-04 05:07:52 -07:00
|
|
|
ecore_cocoa_window_hide(Ecore_Cocoa_Window *window)
|
|
|
|
{
|
2015-10-14 00:31:45 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2016-06-04 07:00:50 -07:00
|
|
|
if ([window->window isVisible])
|
2015-10-14 00:32:20 -07:00
|
|
|
[window->window orderOut:NSApp];
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
2015-10-13 02:01:15 -07:00
|
|
|
EAPI void
|
|
|
|
ecore_cocoa_window_raise(Ecore_Cocoa_Window *window)
|
2015-09-04 05:07:52 -07:00
|
|
|
{
|
2015-10-14 00:31:45 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
2015-10-14 00:32:20 -07:00
|
|
|
[window->window orderFront:nil];
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
2015-10-13 02:01:15 -07:00
|
|
|
EAPI void
|
|
|
|
ecore_cocoa_window_lower(Ecore_Cocoa_Window *window)
|
2015-09-04 05:07:52 -07:00
|
|
|
{
|
2015-10-14 00:31:45 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
2015-09-04 05:07:52 -07:00
|
|
|
[window->window orderBack:nil];
|
|
|
|
}
|
|
|
|
|
2015-10-13 02:01:15 -07:00
|
|
|
EAPI void
|
|
|
|
ecore_cocoa_window_activate(Ecore_Cocoa_Window *window)
|
2015-09-04 05:07:52 -07:00
|
|
|
{
|
2015-10-14 00:31:45 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
2015-09-04 05:07:52 -07:00
|
|
|
[window->window makeKeyAndOrderFront:nil];
|
|
|
|
}
|
|
|
|
|
2015-10-13 02:01:15 -07:00
|
|
|
EAPI void
|
|
|
|
ecore_cocoa_window_iconified_set(Ecore_Cocoa_Window *window,
|
2016-01-05 15:00:56 -08:00
|
|
|
Eina_Bool on)
|
2015-09-04 05:07:52 -07:00
|
|
|
{
|
2015-10-14 00:31:45 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
2015-09-04 05:07:52 -07:00
|
|
|
|
|
|
|
if (on)
|
|
|
|
{
|
|
|
|
[window->window miniaturize:nil];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[window->window deminiaturize:nil];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-10-13 02:01:15 -07:00
|
|
|
EAPI void
|
2015-09-04 05:07:52 -07:00
|
|
|
ecore_cocoa_window_borderless_set(Ecore_Cocoa_Window *window,
|
2016-01-05 15:00:56 -08:00
|
|
|
Eina_Bool on)
|
2015-09-04 05:07:52 -07:00
|
|
|
{
|
2015-10-14 00:31:45 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
if (on)
|
|
|
|
[window->window setContentBorderThickness:0.0
|
|
|
|
forEdge:NSMinXEdge | NSMinYEdge | NSMaxXEdge | NSMaxYEdge];
|
2016-01-05 15:00:56 -08:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// TODO
|
|
|
|
}
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
2015-10-13 02:01:15 -07:00
|
|
|
EAPI void
|
2015-09-04 05:07:52 -07:00
|
|
|
ecore_cocoa_window_view_set(Ecore_Cocoa_Window *window,
|
2016-01-05 15:03:57 -08:00
|
|
|
Ecore_Cocoa_Object *view)
|
2015-09-04 05:07:52 -07:00
|
|
|
{
|
2015-10-14 00:31:45 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN(window);
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(view);
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
//[[window->window contentView] addSubview:view];
|
|
|
|
NSView *v = view;
|
|
|
|
[window->window setContentView:view];
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:[v frame]
|
|
|
|
options:NSTrackingMouseMoved |
|
|
|
|
NSTrackingActiveInActiveApp |
|
|
|
|
NSTrackingInVisibleRect
|
|
|
|
owner:v
|
|
|
|
userInfo:nil];
|
|
|
|
[v addTrackingArea:area];
|
2015-09-04 05:07:52 -07:00
|
|
|
|
2015-10-14 00:32:20 -07:00
|
|
|
[area release];
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
|
|
|
|
2016-01-06 12:38:10 -08:00
|
|
|
EAPI Ecore_Cocoa_Object *
|
|
|
|
ecore_cocoa_window_get(const Ecore_Cocoa_Window *window)
|
2015-09-04 05:07:52 -07:00
|
|
|
{
|
2015-10-14 00:31:45 -07:00
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(window, NULL);
|
2015-10-14 00:32:20 -07:00
|
|
|
return window->window;
|
2015-09-04 05:07:52 -07:00
|
|
|
}
|
2015-10-08 02:58:46 -07:00
|
|
|
|
|
|
|
EAPI void
|
|
|
|
ecore_cocoa_window_cursor_set(Ecore_Cocoa_Window *win,
|
|
|
|
Ecore_Cocoa_Cursor c)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(win);
|
|
|
|
EINA_SAFETY_ON_FALSE_RETURN((c >= 0) && (c <= __ECORE_COCOA_CURSOR_LAST));
|
|
|
|
|
|
|
|
NSCursor *cursor = _cursors[c];
|
|
|
|
|
|
|
|
DBG("Setting cursor %i (%s)", c, [[cursor description] UTF8String]);
|
|
|
|
[cursor set];
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
ecore_cocoa_window_cursor_show(Ecore_Cocoa_Window *win,
|
|
|
|
Eina_Bool show)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(win);
|
|
|
|
|
|
|
|
if (show) [NSCursor unhide];
|
|
|
|
else [NSCursor hide];
|
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Bool
|
|
|
|
_ecore_cocoa_window_init(void)
|
|
|
|
{
|
|
|
|
_cursors[ECORE_COCOA_CURSOR_ARROW] = [NSCursor arrowCursor];
|
|
|
|
_cursors[ECORE_COCOA_CURSOR_CONTEXTUAL_MENU] = [NSCursor contextualMenuCursor];
|
|
|
|
_cursors[ECORE_COCOA_CURSOR_CLOSED_HAND] = [NSCursor closedHandCursor];
|
|
|
|
_cursors[ECORE_COCOA_CURSOR_CROSSHAIR] = [NSCursor crosshairCursor];
|
|
|
|
_cursors[ECORE_COCOA_CURSOR_DISAPPEARING_ITEM] = [NSCursor disappearingItemCursor];
|
|
|
|
_cursors[ECORE_COCOA_CURSOR_DRAG_COPY] = [NSCursor dragCopyCursor];
|
|
|
|
_cursors[ECORE_COCOA_CURSOR_DRAG_LINK] = [NSCursor dragLinkCursor];
|
|
|
|
_cursors[ECORE_COCOA_CURSOR_IBEAM] = [NSCursor IBeamCursor];
|
|
|
|
_cursors[ECORE_COCOA_CURSOR_OPEN_HAND] = [NSCursor openHandCursor];
|
|
|
|
_cursors[ECORE_COCOA_CURSOR_OPERATION_NOT_ALLOWED] = [NSCursor operationNotAllowedCursor];
|
|
|
|
_cursors[ECORE_COCOA_CURSOR_POINTING_HAND] = [NSCursor pointingHandCursor];
|
|
|
|
_cursors[ECORE_COCOA_CURSOR_RESIZE_DOWN] = [NSCursor resizeDownCursor];
|
|
|
|
_cursors[ECORE_COCOA_CURSOR_RESIZE_LEFT] = [NSCursor resizeLeftCursor];
|
|
|
|
_cursors[ECORE_COCOA_CURSOR_RESIZE_LEFT_RIGHT] = [NSCursor resizeLeftRightCursor];
|
|
|
|
_cursors[ECORE_COCOA_CURSOR_RESIZE_RIGHT] = [NSCursor resizeRightCursor];
|
|
|
|
_cursors[ECORE_COCOA_CURSOR_RESIZE_UP] = [NSCursor resizeUpCursor];
|
|
|
|
_cursors[ECORE_COCOA_CURSOR_RESIZE_UP_DOWN] = [NSCursor resizeUpDownCursor];
|
|
|
|
_cursors[ECORE_COCOA_CURSOR_IBEAM_VERTICAL] = [NSCursor IBeamCursorForVerticalLayout];
|
|
|
|
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|