RDK Documentation (Open Sourced RDK Components)
cocoa_window.mm
Go to the documentation of this file.
1 /*
2  * If not stated otherwise in this file or this component's license file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2018 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 /**
20  * @file cocoa_window.mm
21  * Advanced Adaptive Media Player (AAMP)
22  */
23 
24 #import <Cocoa/Cocoa.h>
25 #import "cocoa_window.h"
26 extern guintptr (*gCbgetWindowContentView)();
27 
28 @interface VideoWindow: NSWindow <NSApplicationDelegate>
29 {
30  gboolean m_windowActive;
31 }
32 - (gboolean) isActive;
33 - (id) initializeWindow:(NSRect) cordinates;
34 @end
35 
36 static VideoWindow *gCocoaWindow=nil;
37 static NSApplication* application;
38 
39 @implementation VideoWindow
40 
41 - (id) initializeWindow:(NSRect)cordinates
42 {
43  self = [super initWithContentRect: cordinates
44  styleMask: (NSWindowStyleMaskClosable | NSWindowStyleMaskTitled | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskResizable)
45  backing: NSBackingStoreBuffered defer: NO screen: nil];
46 
47  [application setDelegate:self];
48  [self setReleasedWhenClosed:NO];
49  m_windowActive = TRUE;
50  [self setTitle:@"AAMP Test Player"];
51  return self;
52 }
53 
54 - (BOOL) windowShouldClose:(id)sender
55 {
56  m_windowActive = FALSE;
57  return YES;
58 }
59 
60 - (void) applicationDidFinishLaunching: (NSNotification *)note
61 {
62  [self makeMainWindow];
63  [self center];
64  [self orderFront:self];
65 }
66 
67 - (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication {
68  return YES;
69 }
70 
71 - (gboolean) isActive
72 {
73  return m_windowActive;
74 }
75 
76 @end
77 
78 guintptr getWindowContentView()
79 {
80  return (guintptr)[gCocoaWindow contentView];
81 }
82 
83 int createAndRunCocoaWindow()
84 {
85  NSRect windowCordinates;
86  windowCordinates.size.width = 640;
87  windowCordinates.size.height = 480;
88  windowCordinates.origin.x = 0;
89  windowCordinates.origin.y = 0;
90 
91  application = [NSApplication sharedApplication];
92  [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular];
93  gCocoaWindow = [[VideoWindow alloc] initializeWindow:windowCordinates];
94 
95  [gCocoaWindow orderFront:nil];
96  [gCocoaWindow setLevel: NSNormalWindowLevel];
97  gCbgetWindowContentView = &getWindowContentView;
98  [application run];
99  return 0;
100 }
101 
102 void setSimulatorWindowTitle( const char *title )
103 {
104  if( gCocoaWindow )
105  {
106  NSString *nsTitle = [NSString stringWithUTF8String:title];
107  dispatch_async(dispatch_get_main_queue(), ^{
108  [gCocoaWindow setTitle:nsTitle];
109  });
110  }
111 }
cocoa_window.h
VideoWindow
Definition: cocoa_window.mm:28
TRUE
#define TRUE
Defines for TRUE/FALSE/ENABLE flags.
Definition: wifi_common_hal.h:199