14#import <winpr/assert.h> 
   15#import <freerdp/client/cmdline.h> 
   18void AppDelegate_ConnectionResultEventHandler(
void *context, 
const ConnectionResultEventArgs *e);
 
   19void AppDelegate_ErrorInfoEventHandler(
void *ctx, 
const ErrorInfoEventArgs *e);
 
   20void AppDelegate_EmbedWindowEventHandler(
void *context, 
const EmbedWindowEventArgs *e);
 
   21void AppDelegate_ResizeWindowEventHandler(
void *context, 
const ResizeWindowEventArgs *e);
 
   22void mac_set_view_size(rdpContext *context, 
MRDPView *view);
 
   31@synthesize window = window;
 
   33@synthesize context = context;
 
   35- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
 
   39  _singleDelegate = 
self;
 
   41  status = [
self ParseCommandLineArguments];
 
   45  mfc->view = (
void *)mrdpView;
 
   49    NSScreen *screen = [[NSScreen screens] objectAtIndex:0];
 
   50    NSRect screenFrame = [screen frame];
 
   51    rdpSettings *settings = context->settings;
 
   53    WINPR_ASSERT(settings);
 
   58                                        screenFrame.size.width);
 
   60                                        screenFrame.size.height);
 
   63    PubSub_SubscribeConnectionResult(context->pubSub, AppDelegate_ConnectionResultEventHandler);
 
   64    PubSub_SubscribeErrorInfo(context->pubSub, AppDelegate_ErrorInfoEventHandler);
 
   65    PubSub_SubscribeEmbedWindow(context->pubSub, AppDelegate_EmbedWindowEventHandler);
 
   66    PubSub_SubscribeResizeWindow(context->pubSub, AppDelegate_ResizeWindowEventHandler);
 
   67    freerdp_client_start(context);
 
   71    if (WindowTitle && WindowTitle[0])
 
   73      winTitle = [[NSString alloc]
 
   74          initWithFormat:@"%@", [NSString stringWithCString:WindowTitle
 
   75                                                   encoding:NSUTF8StringEncoding]];
 
   81      winTitle = [[NSString alloc]
 
   82          initWithFormat:@"%@:%u",
 
   83                         [NSString stringWithCString:name encoding:NSUTF8StringEncoding],
 
   87    [window setTitle:winTitle];
 
   91    [NSApp terminate:self];
 
   95- (void)applicationWillBecomeActive:(NSNotification *)notification
 
  100- (void)applicationWillResignActive:(NSNotification *)notification
 
  105- (void)applicationWillTerminate:(NSNotification *)notification
 
  107  NSLog(
@"Stopping...\n");
 
  108  freerdp_client_stop(context);
 
  109  [mrdpView releaseResources];
 
  110  _singleDelegate = nil;
 
  111  NSLog(
@"Stopped.\n");
 
  112  [NSApp terminate:self];
 
  115- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)sender
 
  120- (BOOL)applicationSupportsSecureRestorableState:(NSApplication *)app
 
  125- (int)ParseCommandLineArguments
 
  131  NSArray *args = [[NSProcessInfo processInfo] arguments];
 
  132  context->argc = (int)[args count];
 
  133  context->argv = malloc(
sizeof(
char *) * context->argc);
 
  136  for (NSString *str in args)
 
  139    if ([str isEqualToString:
@"YES"])
 
  142    if ([str isEqualToString:
@"-NSDocumentRevisionsDebugMode"])
 
  145    length = (int)([str lengthOfBytesUsingEncoding:NSUTF8StringEncoding] + 1);
 
  146    cptr = (
char *)malloc(length);
 
  147    sprintf_s(cptr, length, 
"%s", [str UTF8String]);
 
  148    context->argv[i++] = cptr;
 
  152  status = freerdp_client_settings_parse_command_line(context->settings, context->argc,
 
  153                                                      context->argv, FALSE);
 
  154  freerdp_client_settings_command_line_status_print(context->settings, status, context->argc,
 
  161  RDP_CLIENT_ENTRY_POINTS clientEntryPoints = { 0 };
 
  163  clientEntryPoints.Size = 
sizeof(RDP_CLIENT_ENTRY_POINTS);
 
  164  clientEntryPoints.Version = RDP_CLIENT_INTERFACE_VERSION;
 
  165  RdpClientEntry(&clientEntryPoints);
 
  166  context = freerdp_client_context_new(&clientEntryPoints);
 
  169- (void)ReleaseContext
 
  175  [view exitFullScreenModeWithOptions:nil];
 
  176  [view releaseResources];
 
  179  freerdp_client_context_free(context);
 
  187- (void)rdpConnectError:(NSString *)withMessage
 
  193  [view exitFullScreenModeWithOptions:nil];
 
  194  NSString *message = withMessage ? withMessage : 
@"Error connecting to server";
 
  195  NSAlert *alert = [[NSAlert alloc] init];
 
  196  [alert setMessageText:message];
 
  197  [alert beginSheetModalForWindow:[
self window]
 
  199                   didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
 
  207- (void)alertDidEnd:(NSAlert *)a returnCode:(NSInteger)rc contextInfo:(
void *)ci
 
  209  [NSApp terminate:nil];
 
  218void AppDelegate_ConnectionResultEventHandler(
void *ctx, 
const ConnectionResultEventArgs *e)
 
  220  rdpContext *context = (rdpContext *)ctx;
 
  221  NSLog(
@"ConnectionResult event result:%d\n", e->result);
 
  227      NSString *message = nil;
 
  228      DWORD code = freerdp_get_last_error(context);
 
  231        case FREERDP_ERROR_AUTHENTICATION_FAILED:
 
  233              stringWithFormat:@"%@", @"Authentication failure, check credentials."];
 
  240      [_singleDelegate performSelectorOnMainThread:@selector(rdpConnectError:)
 
  242                                     waitUntilDone:FALSE];
 
  247void AppDelegate_ErrorInfoEventHandler(
void *ctx, 
const ErrorInfoEventArgs *e)
 
  249  NSLog(
@"ErrorInfo event code:%d\n", e->code);
 
  254    NSString *message = nil;
 
  256    if (e->code != ERRINFO_NONE)
 
  258      const char *errorMessage = freerdp_get_error_info_string(e->code);
 
  259      message = [[NSString alloc] initWithUTF8String:errorMessage];
 
  263    [_singleDelegate performSelectorOnMainThread:@selector(rdpConnectError:)
 
  270void AppDelegate_EmbedWindowEventHandler(
void *ctx, 
const EmbedWindowEventArgs *e)
 
  272  rdpContext *context = (rdpContext *)ctx;
 
  277    _singleDelegate->mrdpView = mfc->view;
 
  279    if (_singleDelegate->window)
 
  281      [[_singleDelegate->window contentView] addSubview:mfc->view];
 
  284    dispatch_async(dispatch_get_main_queue(), ^{
 
  285      mac_set_view_size(context, mfc->view);
 
  290void AppDelegate_ResizeWindowEventHandler(
void *ctx, 
const ResizeWindowEventArgs *e)
 
  292  rdpContext *context = (rdpContext *)ctx;
 
  293  (void)fprintf(stderr, 
"ResizeWindowEventHandler: %d %d\n", e->width, e->height);
 
  298    dispatch_async(dispatch_get_main_queue(), ^{
 
  299      mac_set_view_size(context, mfc->view);
 
  304void mac_set_view_size(rdpContext *context, 
MRDPView *view)
 
  308  innerRect.origin.x = 0;
 
  309  innerRect.origin.y = 0;
 
  312  [view setFrame:innerRect];
 
  314  NSRect outerRect = [[view window] frame];
 
  315  outerRect.size = [[view window] frameRectForContentRect:innerRect].size;
 
  317  [[view window] setContentMaxSize:innerRect.size];
 
  319  [[view window] setFrame:outerRect display:YES];
 
  321  [NSApp activateIgnoringOtherApps:YES];
 
  324    [[view window] toggleFullScreen:nil];
 
 
FREERDP_API UINT32 freerdp_settings_get_uint32(const rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id)
Returns a UINT32 settings value.
 
FREERDP_API BOOL freerdp_settings_get_bool(const rdpSettings *settings, FreeRDP_Settings_Keys_Bool id)
Returns a boolean settings value.
 
FREERDP_API BOOL freerdp_settings_set_uint32(rdpSettings *settings, FreeRDP_Settings_Keys_UInt32 id, UINT32 param)
Sets a UINT32 settings value.
 
FREERDP_API const char * freerdp_settings_get_string(const rdpSettings *settings, FreeRDP_Settings_Keys_String id)
Returns a immutable string settings value.