/* Copyright (C) 2015 The Android Open Source Project
 **
 ** This software is licensed under the terms of the GNU General Public
 ** License version 2, as published by the Free Software Foundation, and
 ** may be copied, distributed, and modified under those terms.
 **
 ** This program 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.
 */

#include <Cocoa/Cocoa.h>

#import "android/skin/qt/mac-native-window.h"

void* getNSWindow(void* ns_view) {
    NSView *view = (NSView *)ns_view;
    if (!view) {
        return NULL;
    }
    Class viewClass = [view class];
    Class nsviewClass = [NSView class];
    if ([viewClass isSubclassOfClass:nsviewClass ]) {
        return [view window];
    } else {
        return view;
    }

}

void nsWindowHideWindowButtons(void* ns_window) {
    NSWindow *window = (NSWindow *)ns_window;
    if (!window) {
        return;
    }
    [[window standardWindowButton:NSWindowCloseButton] setHidden:true];
    [[window standardWindowButton:NSWindowMiniaturizeButton] setHidden:true];
    [[window standardWindowButton:NSWindowZoomButton] setHidden:true];
    [window setCollectionBehavior:NSWindowCollectionBehaviorFullScreenAuxiliary];
}

int numHeldMouseButtons() {
    return (int) [NSEvent pressedMouseButtons];
}
