RetroArch/ui/drivers/cocoa/ui_cocoa_window.m

103 lines
3.1 KiB
Mathematica
Raw Normal View History

2016-06-04 07:56:28 +02:00
/* RetroArch - A frontend for libretro.
2017-01-22 13:40:32 +01:00
* Copyright (C) 2011-2017 - Daniel De Matteis
2016-06-04 07:56:28 +02:00
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <boolean.h>
#include <stddef.h>
#include <stdlib.h>
#include <string.h>
2016-06-17 04:07:00 +02:00
#include <string/stdstring.h>
2016-06-04 08:00:19 +02:00
#include "cocoa_common.h"
2016-06-07 16:47:48 +02:00
#include "../ui_cocoa.h"
2016-06-04 07:56:28 +02:00
#include "../../ui_companion_driver.h"
2018-04-30 14:33:05 -04:00
static void* ui_window_cocoa_init(void)
{
return NULL;
}
2016-06-06 07:40:44 +02:00
static void ui_window_cocoa_destroy(void *data)
2016-06-04 07:56:28 +02:00
{
#if !defined(HAVE_COCOA_METAL)
ui_window_cocoa_t *cocoa = (ui_window_cocoa_t*)data;
CocoaView *cocoa_view = (CocoaView*)cocoa->data;
[[cocoa_view window] release];
#endif
2016-06-04 07:56:28 +02:00
}
2016-06-06 07:40:44 +02:00
static void ui_window_cocoa_set_focused(void *data)
2016-06-04 07:56:28 +02:00
{
ui_window_cocoa_t *cocoa = (ui_window_cocoa_t*)data;
CocoaView *cocoa_view = (BRIDGE CocoaView*)cocoa->data;
[[cocoa_view window] makeKeyAndOrderFront:nil];
2016-06-04 07:56:28 +02:00
}
2016-06-06 07:40:44 +02:00
static void ui_window_cocoa_set_visible(void *data,
2016-06-04 07:56:28 +02:00
bool set_visible)
{
ui_window_cocoa_t *cocoa = (ui_window_cocoa_t*)data;
CocoaView *cocoa_view = (BRIDGE CocoaView*)cocoa->data;
if (set_visible)
[[cocoa_view window] makeKeyAndOrderFront:nil];
else
[[cocoa_view window] orderOut:nil];
2016-06-04 07:56:28 +02:00
}
2016-06-06 07:40:44 +02:00
static void ui_window_cocoa_set_title(void *data, char *buf)
2016-06-04 07:56:28 +02:00
{
CocoaView *cocoa_view = (BRIDGE CocoaView*)data;
const char* const text = buf; /* < Can't access buffer directly in the block */
[[cocoa_view window] setTitle:[NSString stringWithCString:text encoding:NSUTF8StringEncoding]];
2016-06-04 07:56:28 +02:00
}
2016-06-06 07:40:44 +02:00
static void ui_window_cocoa_set_droppable(void *data, bool droppable)
2016-06-04 08:38:38 +02:00
{
ui_window_cocoa_t *cocoa = (ui_window_cocoa_t*)data;
CocoaView *cocoa_view = (BRIDGE CocoaView*)cocoa->data;
2016-06-04 08:38:38 +02:00
if (droppable)
{
#if defined(HAVE_COCOA_METAL)
[[cocoa_view window] registerForDraggedTypes:@[NSPasteboardTypeColor, NSPasteboardTypeFileURL]];
#elif defined(HAVE_COCOA)
[[cocoa_view window] registerForDraggedTypes:[NSArray arrayWithObjects:NSColorPboardType, NSFilenamesPboardType, nil]];
#endif
2016-06-04 08:38:38 +02:00
}
else
{
[[cocoa_view window] unregisterDraggedTypes];
}
}
2016-06-06 07:40:44 +02:00
static bool ui_window_cocoa_focused(void *data)
2016-06-04 17:24:46 +02:00
{
ui_window_cocoa_t *cocoa = (ui_window_cocoa_t*)data;
CocoaView *cocoa_view = (BRIDGE CocoaView*)cocoa->data;
return cocoa_view.window.isMainWindow;
2016-06-04 17:24:46 +02:00
}
2018-04-30 14:33:05 -04:00
ui_window_t ui_window_cocoa = {
ui_window_cocoa_init,
2016-06-04 07:56:28 +02:00
ui_window_cocoa_destroy,
ui_window_cocoa_set_focused,
ui_window_cocoa_set_visible,
ui_window_cocoa_set_title,
2016-06-04 08:38:38 +02:00
ui_window_cocoa_set_droppable,
2016-06-04 17:24:46 +02:00
ui_window_cocoa_focused,
2016-06-04 07:56:28 +02:00
"cocoa"
};