FreeRDP/client/Mac/MRDPView.m

2233 lines
62 KiB
Mathematica
Raw Normal View History

//
// MRDPView.m
// MacFreeRDP
//
// Created by Laxmikant Rashinkar
// Copyright (c) 2012 FreeRDP.org All rights reserved.
//
/*
* TODO
* + provide a UI for configuring optional parameters, but keep cmd line args
* + audio redirection is delayed considerably
* + caps lock key needs to be sent in func flagsChanged()
* + libfreerdp-utils.1.0.dylib needs to be installed to /usr/local/lib
*
* - MRDPView implementation is incomplete
* - all variables should have consistent nameing scheme - camel case
* - all funcs same as above
* - PolygonSc seems to create a transparent rect
* - ensure mouse cursor changes are working ok after moving to NSTracking area
2013-02-22 06:42:47 +04:00
* - RAIL:
* -
* -
* - tool tips to be correctly positioned
* - dragging is slightly of
* - resize after dragging not working
* - dragging app from macbook to monitor gives exec/access err
* - unable to drag rect out of monitor boundaries
2013-02-22 06:42:47 +04:00
* -
* -
* -
*/
2013-02-22 06:42:47 +04:00
#import "MRDPView.h"
#import "MRDPCursor.h"
// RAIL_TODO DELETE WHEN DONE TESTING
#define MRDP_DRAW_INDIVIDUAL_RECTS
@implementation MRDPView
MRDPView *g_mrdpview;
@synthesize is_connected;
struct kkey g_keys[];
2013-02-22 08:07:35 +04:00
void convert_color_space(char *dest, char *src, NSRect* drawRect, int width, int height);
const char* error_code_names[] =
{
2013-02-22 06:42:47 +04:00
"RAIL_EXEC_S_OK",
"RAIL_EXEC_E_HOOK_NOT_LOADED",
"RAIL_EXEC_E_DECODE_FAILED",
"RAIL_EXEC_E_NOT_IN_ALLOWLIST",
"RAIL_EXEC_E_FILE_NOT_FOUND",
"RAIL_EXEC_E_FAIL",
"RAIL_EXEC_E_SESSION_LOCKED"
};
struct kkey g_keys[256] =
{
2013-02-22 06:42:47 +04:00
{ 0x1e, 0 }, // a 0
{ 0x1f, 0 }, // s
{ 0x20, 0 }, // d
{ 0x21, 0 }, // f
{ 0x23, 0 }, // h
{ 0x22, 0 }, // g
{ 0x2c, 0 }, // z
{ 0x2d, 0 }, // x
{ 0x2e, 0 }, // c
{ 0x2f, 0 }, // v
{ 0x00, 0 }, // 10
{ 0x30, 0 }, // b
{ 0x10, 0 }, // q
{ 0x11, 0 }, // w
{ 0x12, 0 }, // e
{ 0x13, 0 }, // r
{ 0x15, 0 }, // y
{ 0x14, 0 }, // t
{ 0x02, 0 }, // 1
{ 0x03, 0 }, // 2
{ 0x04, 0 }, // 3 20
{ 0x05, 0 }, // 4
{ 0x07, 0 }, // 6
{ 0x06, 0 }, // 5
{ 0x0d, 0 }, // = or +
{ 0x0a, 0 }, // 9
{ 0x08, 0 }, // 7
{ 0x0c, 0 }, // - or _
{ 0x09, 0 }, // 8
{ 0x0b, 0 }, // 0
{ 0x1b, 0 }, // ] or } 30
{ 0x18, 0 }, // o
{ 0x16, 0 }, // u
{ 0x1a, 0 }, // [ or {
{ 0x17, 0 }, // i
{ 0x19, 0 }, // p
{ 0x1c, 0 }, // enter
{ 0x26, 0 }, // l
{ 0x24, 0 }, // j
{ 0x28, 0 }, // ' or "
{ 0x25, 0 }, // k 40
{ 0x27, 0 }, // ; or :
{ 0x2b, 0 }, // \ or |
{ 0x33, 0 }, // , or <
{ 0x35, 0 }, // / or ?
{ 0x31, 0 }, // n
{ 0x32, 0 }, // m
{ 0x34, 0 }, // . or >
{ 0x0f, 0 }, // tab
{ 0x39, 0 }, // space
{ 0x29, 0 }, // ` or ~ 50
{ 0x0e, 0 }, // backspace
{ 0x00, 0 }, //
{ 0x01, 0 }, // esc
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 }, // 60
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x53, 0 }, // KP.
{ 0x00, 0 },
{ 0x37, 0 }, // KP*
{ 0x00, 0 },
{ 0x4e, 0 }, // KP+
{ 0x00, 0 }, // 70
{ 0x45, 0 }, // num lock
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x35, 1 }, // KP/
{ 0x1c, 1 }, // KPEnter
{ 0x00, 0 },
{ 0x4a, 0 }, // KP-
{ 0x00, 0 },
{ 0x00, 0 }, // 80
{ 0x00, 0 },
{ 0x52, 0 }, // KP0
{ 0x4f, 0 }, // KP1
{ 0x50, 0 }, // KP2
{ 0x51, 0 }, // KP3
{ 0x4b, 0 }, // KP4
{ 0x4c, 0 }, // KP5
{ 0x4d, 0 }, // KP6
{ 0x47, 0 }, // KP7
{ 0x00, 0 }, // 90
{ 0x48, 0 }, // KP8
{ 0x49, 0 }, // KP9
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 }, // 100
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x5d, 1 }, // menu 110
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x52, 1 }, // Insert
{ 0x47, 1 }, // Home
{ 0x49, 1 }, // PgUp
{ 0x53, 1 }, // Delete
{ 0x00, 0 },
{ 0x4f, 1 }, // End
{ 0x00, 0 }, // 120
{ 0x51, 1 }, // PgDown
{ 0x3b, 0 }, // f1
{ 0x4b, 1 }, // left
{ 0x4d, 1 }, // right
{ 0x50, 1 }, // down
{ 0x48, 1 }, // up
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
{ 0x00, 0 },
};
/************************************************************************
2013-02-22 06:42:47 +04:00
methods we override
************************************************************************/
/** *********************************************************************
* create MRDPView with specified rectangle
***********************************************************************/
- (id)initWithFrame:(NSRect)frame
{
2013-02-22 06:42:47 +04:00
self = [super initWithFrame:frame];
2013-02-22 07:04:09 +04:00
if (self)
{
2013-02-22 06:42:47 +04:00
// Initialization code here.
}
return self;
}
/** *********************************************************************
* called when MRDPView has been successfully created from the NIB
***********************************************************************/
- (void) awakeFromNib
{
2013-02-22 06:42:47 +04:00
g_mrdpview = self;
// store our window dimensions
width = [self frame].size.width;
height = [self frame].size.height;
titleBarHeight = 22;
[[self window] becomeFirstResponder];
[[self window] setAcceptsMouseMovedEvents:YES];
cursors = [[NSMutableArray alloc] initWithCapacity:10];
firstCreateWindow = TRUE;
skipResizeOnce = YES;
windows = [[NSMutableArray alloc] initWithCapacity:10];
// setup a mouse tracking area
NSTrackingArea * trackingArea = [[NSTrackingArea alloc] initWithRect:[self visibleRect] options:NSTrackingMouseEnteredAndExited | NSTrackingMouseMoved | NSTrackingCursorUpdate | NSTrackingEnabledDuringMouseDrag | NSTrackingActiveWhenFirstResponder owner:self userInfo:nil];
//[self addTrackingArea:trackingArea];
// windows in RemoteApp (RAIL) mode cannot have title bars
NSArray * args = [[NSProcessInfo processInfo] arguments];
for (NSString * str in args)
{
if ([str compare:@"--app"] == NSOrderedSame) {
isRemoteApp = TRUE;
break;
}
}
if (!isRemoteApp)
[self addTrackingArea:trackingArea];
mouseInClientArea = YES;
}
/** *********************************************************************
* become first responder so we can get keyboard and mouse events
***********************************************************************/
2013-02-22 06:42:47 +04:00
- (BOOL)acceptsFirstResponder
{
return YES;
}
/** *********************************************************************
* called when a mouse move event occurrs
2013-02-22 06:42:47 +04:00
*
* ideally we want to be called when the mouse moves over NSView client area,
* but in reality we get called any time the mouse moves anywhere on the screen;
* we could use NSTrackingArea class to handle this but this class is available
* on Mac OS X v10.5 and higher; since we want to be compatible with older
2013-02-22 06:42:47 +04:00
* versions, we do this manually.
*
* TODO: here is how it can be done using legacy methods
* http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/EventOverview/MouseTrackingEvents/MouseTrackingEvents.html#//apple_ref/doc/uid/10000060i-CH11-SW1
***********************************************************************/
2013-02-22 06:42:47 +04:00
- (void) mouseMoved:(NSEvent *)event
{
[super mouseMoved:event];
if (!is_connected)
return;
NSPoint loc = [event locationInWindow];
int x = (int) loc.x;
int y = (int) loc.y;
y = height - y;
// send mouse motion event to RDP server
rdp_instance->input->MouseEvent(rdp_instance->input, PTR_FLAGS_MOVE, x, y);
}
/** *********************************************************************
* called when left mouse button is pressed down
***********************************************************************/
- (void)mouseDown:(NSEvent *) event
{
2013-02-22 06:42:47 +04:00
[super mouseDown:event];
if (!is_connected)
return;
NSPoint loc = [event locationInWindow];
int x = (int) loc.x;
int y = (int) loc.y;
y = height - y;
rdp_instance->input->MouseEvent(rdp_instance->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON1, x, y);
}
/** *********************************************************************
* called when left mouse button is released
***********************************************************************/
- (void) mouseUp:(NSEvent *) event
{
2013-02-22 06:42:47 +04:00
[super mouseUp:event];
if (!is_connected)
return;
NSPoint loc = [event locationInWindow];
int x = (int) loc.x;
int y = (int) loc.y;
y = height - y;
rdp_instance->input->MouseEvent(rdp_instance->input, PTR_FLAGS_BUTTON1, x, y);
}
/** *********************************************************************
* called when right mouse button is pressed down
***********************************************************************/
- (void) rightMouseDown:(NSEvent *)event
{
2013-02-22 06:42:47 +04:00
[super rightMouseDown:event];
if (!is_connected)
return;
NSPoint loc = [event locationInWindow];
int x = (int) loc.x;
int y = (int) loc.y;
y = height - y;
rdp_instance->input->MouseEvent(rdp_instance->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON2, x, y);
}
/** *********************************************************************
* called when right mouse button is released
***********************************************************************/
- (void) rightMouseUp:(NSEvent *)event
{
2013-02-22 06:42:47 +04:00
[super rightMouseUp:event];
if (!is_connected)
return;
NSPoint loc = [event locationInWindow];
int x = (int) loc.x;
int y = (int) loc.y;
y = height - y;
rdp_instance->input->MouseEvent(rdp_instance->input, PTR_FLAGS_BUTTON2, x, y);
}
/** *********************************************************************
* called when middle mouse button is pressed
***********************************************************************/
- (void) otherMouseDown:(NSEvent *)event
{
2013-02-22 06:42:47 +04:00
[super otherMouseDown:event];
if (!is_connected)
return;
NSPoint loc = [event locationInWindow];
int x = (int) loc.x;
int y = (int) loc.y;
y = height - y;
rdp_instance->input->MouseEvent(rdp_instance->input, PTR_FLAGS_DOWN | PTR_FLAGS_BUTTON3, x, y);
}
/** *********************************************************************
* called when middle mouse button is released
***********************************************************************/
- (void) otherMouseUp:(NSEvent *)event
{
2013-02-22 06:42:47 +04:00
[super otherMouseUp:event];
if (!is_connected)
return;
NSPoint loc = [event locationInWindow];
int x = (int) loc.x;
int y = (int) loc.y;
y = height - y;
rdp_instance->input->MouseEvent(rdp_instance->input, PTR_FLAGS_BUTTON3, x, y);
}
- (void) scrollWheel:(NSEvent *)event
{
2013-02-22 08:07:35 +04:00
UINT16 flags;
2013-02-22 06:42:47 +04:00
[super scrollWheel:event];
if (!is_connected)
return;
NSPoint loc = [event locationInWindow];
int x = (int) loc.x;
int y = (int) loc.y;
y = height - y;
flags = PTR_FLAGS_WHEEL;
2013-02-22 07:04:09 +04:00
if ([event deltaY] < 0)
2013-02-22 06:42:47 +04:00
flags |= PTR_FLAGS_WHEEL_NEGATIVE | 0x0088;
2013-02-22 07:04:09 +04:00
else
2013-02-22 06:42:47 +04:00
flags |= 0x0078;
2013-02-22 07:04:09 +04:00
2013-02-22 06:42:47 +04:00
x += (int) [event deltaX];
y += (int) [event deltaY];
2013-02-22 07:04:09 +04:00
2013-02-22 06:42:47 +04:00
rdp_instance->input->MouseEvent(rdp_instance->input, flags, x, y);
}
/** *********************************************************************
* called when mouse is moved with left button pressed
* note: invocation order is: mouseDown, mouseDragged, mouseUp
***********************************************************************/
- (void) mouseDragged:(NSEvent *)event
{
2013-02-22 06:42:47 +04:00
[super mouseDragged:event];
if (!is_connected)
return;
NSPoint loc = [event locationInWindow];
int x = (int) loc.x;
int y = (int) loc.y;
// RAIL_TODO delete this if not reqd
2013-02-22 07:04:09 +04:00
if ((isRemoteApp) && (isMoveSizeInProgress))
{
if (saveInitialDragLoc)
{
2013-02-22 06:42:47 +04:00
saveInitialDragLoc = NO;
savedDragLocation.x = x;
savedDragLocation.y = y;
return;
}
int newX = x - savedDragLocation.x;
int newY = y - savedDragLocation.y;
NSRect r = [[self window] frame];
r.origin.x += newX;
r.origin.y += newY;
[[g_mrdpview window] setFrame:r display:YES];
}
y = height - y;
// send mouse motion event to RDP server
rdp_instance->input->MouseEvent(rdp_instance->input, PTR_FLAGS_MOVE, x, y);
}
/** *********************************************************************
* called when a key is pressed
***********************************************************************/
- (void) keyDown:(NSEvent *) event
{
2013-02-22 06:42:47 +04:00
int key;
2013-02-22 07:04:09 +04:00
if (!is_connected)
2013-02-22 06:42:47 +04:00
return;
key = [event keyCode];
rdp_instance->input->KeyboardEvent(rdp_instance->input, g_keys[key].flags | KBD_FLAGS_DOWN, g_keys[key].key_code);
}
/** *********************************************************************
* called when a key is released
***********************************************************************/
- (void) keyUp:(NSEvent *) event
{
2013-02-22 06:42:47 +04:00
int key;
2013-02-22 07:04:09 +04:00
if (!is_connected)
2013-02-22 06:42:47 +04:00
return;
key = [event keyCode];
rdp_instance->input->KeyboardEvent(rdp_instance->input, g_keys[key].flags | KBD_FLAGS_RELEASE, g_keys[key].key_code);
}
/** *********************************************************************
* called when shift, control, alt and meta keys are pressed/released
***********************************************************************/
2013-02-22 08:07:35 +04:00
- (void) flagsChanged:(NSEvent*) event
{
2013-02-22 06:42:47 +04:00
NSUInteger mf = [event modifierFlags];
2013-02-22 08:07:35 +04:00
if (!is_connected)
2013-02-22 06:42:47 +04:00
return;
// caps lock
if (mf == 0x10100) {
printf("TODO: caps lock is on\n");
kdcapslock = 1;
}
if (kdcapslock && (mf == 0x100)) {
kdcapslock = 0;
printf("TODO: caps lock is off\n");
}
// left shift
if ((kdlshift == 0) && ((mf & 2) != 0)) {
// left shift went down
rdp_instance->input->KeyboardEvent(rdp_instance->input, KBD_FLAGS_DOWN, 0x2a);
kdlshift = 1;
}
if ((kdlshift != 0) && ((mf & 2) == 0)) {
// left shift went up
rdp_instance->input->KeyboardEvent(rdp_instance->input, KBD_FLAGS_RELEASE, 0x2a);
kdlshift = 0;
}
// right shift
if ((kdrshift == 0) && ((mf & 4) != 0)) {
// right shift went down
rdp_instance->input->KeyboardEvent(rdp_instance->input, KBD_FLAGS_DOWN, 0x36);
kdrshift = 1;
}
if ((kdrshift != 0) && ((mf & 4) == 0)) {
// right shift went up
rdp_instance->input->KeyboardEvent(rdp_instance->input, KBD_FLAGS_RELEASE, 0x36);
kdrshift = 0;
}
// left ctrl
if ((kdlctrl == 0) && ((mf & 1) != 0)) {
// left ctrl went down
rdp_instance->input->KeyboardEvent(rdp_instance->input, KBD_FLAGS_DOWN, 0x1d);
kdlctrl = 1;
}
if ((kdlctrl != 0) && ((mf & 1) == 0)) {
// left ctrl went up
rdp_instance->input->KeyboardEvent(rdp_instance->input, KBD_FLAGS_RELEASE, 0x1d);
kdlctrl = 0;
}
// right ctrl
if ((kdrctrl == 0) && ((mf & 0x2000) != 0)) {
// right ctrl went down
rdp_instance->input->KeyboardEvent(rdp_instance->input, 1 | KBD_FLAGS_DOWN, 0x1d);
kdrctrl = 1;
}
if ((kdrctrl != 0) && ((mf & 0x2000) == 0)) {
// right ctrl went up
rdp_instance->input->KeyboardEvent(rdp_instance->input, 1 | KBD_FLAGS_RELEASE, 0x1d);
kdrctrl = 0;
}
// left alt
if ((kdlalt == 0) && ((mf & 0x20) != 0)) {
// left alt went down
rdp_instance->input->KeyboardEvent(rdp_instance->input, KBD_FLAGS_DOWN, 0x38);
kdlalt = 1;
}
if ((kdlalt != 0) && ((mf & 0x20) == 0)) {
// left alt went up
rdp_instance->input->KeyboardEvent(rdp_instance->input, KBD_FLAGS_RELEASE, 0x38);
kdlalt = 0;
}
// right alt
if ((kdralt == 0) && ((mf & 0x40) != 0)) {
// right alt went down
rdp_instance->input->KeyboardEvent(rdp_instance->input, 1 | KBD_FLAGS_DOWN, 0x38);
kdralt = 1;
}
if ((kdralt != 0) && ((mf & 0x40) == 0)) {
// right alt went up
rdp_instance->input->KeyboardEvent(rdp_instance->input, 1 | KBD_FLAGS_RELEASE, 0x38);
kdralt = 0;
}
// left meta
if ((kdlmeta == 0) && ((mf & 0x08) != 0)) {
// left meta went down
rdp_instance->input->KeyboardEvent(rdp_instance->input, 1 | KBD_FLAGS_DOWN, 0x5b);
kdlmeta = 1;
}
if ((kdlmeta != 0) && ((mf & 0x08) == 0)) {
// left meta went up
rdp_instance->input->KeyboardEvent(rdp_instance->input, 1 | KBD_FLAGS_RELEASE, 0x5b);
kdlmeta = 0;
}
// right meta
if ((kdrmeta == 0) && ((mf & 0x10) != 0)) {
// right meta went down
rdp_instance->input->KeyboardEvent(rdp_instance->input, 1 | KBD_FLAGS_DOWN, 0x5c);
kdrmeta = 1;
}
if ((kdrmeta != 0) && ((mf & 0x10) == 0)) {
// right meta went up
rdp_instance->input->KeyboardEvent(rdp_instance->input, 1 | KBD_FLAGS_RELEASE, 0x5c);
kdrmeta = 0;
}
}
- (void) releaseResources
{
2013-02-22 06:42:47 +04:00
int i;
for (i = 0; i < argc; i++)
{
if (argv[i])
free(argv[i]);
}
for (MRDPWindow * w in windows)
{
[w setWindow:nil];
[w setView:nil];
}
if (!is_connected)
return;
freerdp_channels_global_uninit();
if (pixel_data)
free(pixel_data);
if (run_loop_src != 0)
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), run_loop_src_channels, kCFRunLoopDefaultMode);
if (run_loop_src != 0)
CFRunLoopRemoveSource(CFRunLoopGetCurrent(), run_loop_src, kCFRunLoopDefaultMode);
}
/** *********************************************************************
* called when our view needs refreshing
***********************************************************************/
- (void) drawRect:(NSRect)dirtyRect
{
2013-02-22 06:42:47 +04:00
if (!rdp_context)
return;
2013-02-22 07:04:09 +04:00
if (g_mrdpview->isRemoteApp && g_mrdpview->currentWindow)
2013-02-22 06:42:47 +04:00
return;
2013-02-22 07:04:09 +04:00
if (!bmiRep)
{
2013-02-22 06:42:47 +04:00
pixel_data = (char *) malloc(width * height * sizeof(struct rgba_data));
bmiRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:(unsigned char **) &pixel_data
pixelsWide:width
pixelsHigh:height
bitsPerSample:8
samplesPerPixel:sizeof(struct rgba_data)
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bitmapFormat:0 //NSAlphaFirstBitmapFormat
bytesPerRow:width * sizeof(struct rgba_data)
bitsPerPixel:0];
}
[bmiRep drawInRect:dirtyRect fromRect:dirtyRect operation:NSCompositeCopy fraction:1.0 respectFlipped:NO hints:nil];
}
/************************************************************************
2013-02-22 06:42:47 +04:00
instance methods
************************************************************************/
/** *********************************************************************
* called when RDP server wants us to update a rect with new data
***********************************************************************/
2013-02-22 07:04:09 +04:00
- (void) my_draw_rect:(void*)context
{
2013-02-22 08:07:35 +04:00
int w;
int h;
2013-02-22 06:42:47 +04:00
2013-02-22 07:04:09 +04:00
rdpContext* ctx = (rdpContext*) context;
2013-02-22 06:42:47 +04:00
struct rgba_data
{
char red;
char green;
char blue;
char alpha;
};
2013-02-22 07:04:09 +04:00
if (isRemoteApp && currentWindow)
{
2013-02-22 06:42:47 +04:00
NSRect vrect = [ [currentWindow view] frame];
[[currentWindow view] setNeedsDisplayInRect:vrect];
// actual drawing will be done in MRDPRailView:drawRect()
return;
}
w = width;
h = height;
rect.origin.x = 0;
rect.origin.y = 0;
rect.size.width = w;
rect.size.height = h;
2013-02-22 07:04:09 +04:00
if (!bmiRep)
{
2013-02-22 06:42:47 +04:00
pixel_data = (char *) malloc(w * h * sizeof(struct rgba_data));
bmiRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:(unsigned char **) &pixel_data
pixelsWide:w
pixelsHigh:h
bitsPerSample:8
samplesPerPixel:sizeof(struct rgba_data)
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bitmapFormat:0 //NSAlphaFirstBitmapFormat
bytesPerRow:w * sizeof(struct rgba_data)
bitsPerPixel:0];
}
#ifdef MRDP_DRAW_INDIVIDUAL_RECTS
2013-02-22 06:42:47 +04:00
[self setNeedsDisplayInRect:rect];
return;
#endif
2013-02-22 06:42:47 +04:00
convert_color_space(pixel_data, (char *) ctx->gdi->primary_buffer, &rect, w, h);
[self setNeedsDisplayInRect:rect];
}
/** *********************************************************************
* save state info for use by other methods later on
***********************************************************************/
- (void) saveStateInfo:(freerdp *) instance:(rdpContext *) context
{
2013-02-22 06:42:47 +04:00
rdp_instance = instance;
rdp_context = context;
}
/** *********************************************************************
* double check that a mouse event occurred in our client view
***********************************************************************/
- (BOOL) eventIsInClientArea :(NSEvent *) event :(int *) xptr :(int *) yptr
{
2013-02-22 06:42:47 +04:00
NSPoint loc = [event locationInWindow];
int x = (int) loc.x;
int y = (int) loc.y;
2013-02-22 07:04:09 +04:00
if ((x < 0) || (y < 0))
{
if (mouseInClientArea)
{
2013-02-22 06:42:47 +04:00
// set default cursor before leaving client area
mouseInClientArea = NO;
NSCursor *cur = [NSCursor arrowCursor];
[cur set];
}
2013-02-22 07:04:09 +04:00
2013-02-22 06:42:47 +04:00
return NO;
}
2013-02-22 07:04:09 +04:00
if ((x > width) || (y > height))
{
if (mouseInClientArea)
{
2013-02-22 06:42:47 +04:00
// set default cursor before leaving client area
mouseInClientArea = NO;
NSCursor *cur = [NSCursor arrowCursor];
[cur set];
}
2013-02-22 07:04:09 +04:00
2013-02-22 06:42:47 +04:00
return NO;
}
// on Mac origin is at lower left, but we want it on upper left
y = height - y;
*xptr = x;
*yptr = y;
mouseInClientArea = YES;
return YES;
}
/** *********************************************************************
* called when we fail to connect to a RDP server
***********************************************************************/
- (void) rdpConnectError
{
2013-02-22 06:42:47 +04:00
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:@"Error connecting to server"];
[alert beginSheetModalForWindow:[g_mrdpview window]
modalDelegate:g_mrdpview
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
/** *********************************************************************
* called when we fail to launch remote app on RDP server
***********************************************************************/
- (void) rdpRemoteAppError
{
2013-02-22 06:42:47 +04:00
NSAlert *alert = [[NSAlert alloc] init];
[alert setMessageText:@"Error starting remote app on specified server"];
[alert beginSheetModalForWindow:[g_mrdpview window]
modalDelegate:g_mrdpview
didEndSelector:@selector(alertDidEnd:returnCode:contextInfo:)
contextInfo:nil];
}
/** *********************************************************************
* just a terminate selector for above call
***********************************************************************/
2013-02-22 06:42:47 +04:00
- (void) alertDidEnd:(NSAlert *)a returnCode:(NSInteger)rc contextInfo:(void *)ci
{
2013-02-22 06:42:47 +04:00
[NSApp terminate:nil];
}
2013-02-22 08:07:35 +04:00
- (void) onPasteboardTimerFired :(NSTimer*) timer
{
2013-02-22 08:07:35 +04:00
int i;
NSArray* types;
2013-02-22 06:42:47 +04:00
i = (int) [pasteboard_rd changeCount];
2013-02-22 07:04:09 +04:00
2013-02-22 06:42:47 +04:00
if (i != pasteboard_changecount)
{
pasteboard_changecount = i;
types = [NSArray arrayWithObject:NSStringPboardType];
NSString *str = [pasteboard_rd availableTypeFromArray:types];
if (str != nil)
{
cliprdr_send_supported_format_list(rdp_instance);
}
}
}
- (void) setViewSize : (int) w : (int) h
{
2013-02-22 06:42:47 +04:00
// store current dimensions
width = w;
height = h;
// compute difference between window and client area
NSRect outerRect = [[g_mrdpview window] frame];
NSRect innerRect = [g_mrdpview frame];
int widthDiff = outerRect.size.width - innerRect.size.width;
int heightDiff = outerRect.size.height - innerRect.size.height;
2013-02-22 07:04:09 +04:00
if (!g_mrdpview->isRemoteApp)
{
2013-02-22 06:42:47 +04:00
// we are not in RemoteApp mode, disable resizing
outerRect.size.width = w + widthDiff;
outerRect.size.height = h + heightDiff;
[[g_mrdpview window] setMaxSize:outerRect.size];
[[g_mrdpview window] setMinSize:outerRect.size];
[[g_mrdpview window] setFrame:outerRect display:YES];
// set client area to specified dimensions
innerRect.size.width = w;
innerRect.size.height = h;
[g_mrdpview setFrame:innerRect];
return;
}
// we are in RemoteApp mode
outerRect.origin.x = 0;
outerRect.origin.y = 0;
outerRect.size.width = width + widthDiff;
outerRect.size.height = height + heightDiff;
[[g_mrdpview window] setFrame:outerRect display:YES];
2013-02-22 06:42:47 +04:00
// set client area to specified dimensions
innerRect.size.width = width;
innerRect.size.height = height;
[g_mrdpview setFrame:innerRect];
// main window displays desktop background - hide it
[[g_mrdpview window] orderOut:g_mrdpview];
}
// RAIL_TODO is this func required
2013-02-22 08:07:35 +04:00
- (void) windowDidResize:(NSNotification*) notification
{
2013-02-22 06:42:47 +04:00
RAIL_WINDOW_MOVE_ORDER windowMove;
printf("RAIL_TODO: MRDPView: windowDidResize() - not yet implemented\n");
return;
// window resize valid only in RemoteApp mode
if (!g_mrdpview->isRemoteApp)
return;
// window has resized, let server know
NSRect r = [[g_mrdpview window] frame];
printf("----- LK_TODO: MRDPView:windowDidResize (%d,%d %dx%d)\n",
(int) r.origin.x, (int) r.origin.y,
(int) r.size.width, (int) r.size.height);
windowMove.windowId = [currentWindow windowID];
2013-02-22 08:07:35 +04:00
windowMove.left = (UINT16) r.origin.x; // x-cordinate of top left corner
windowMove.right = (UINT16) (windowMove.left + r.size.width); // x-cordinate of bottom right corner
windowMove.top = (UINT16) r.origin.y; // y-cordinate of top left corner
windowMove.bottom = (UINT16) (windowMove.top + r.size.height); // y-cordinate of bottom right corner
2013-02-22 06:42:47 +04:00
printf("----- LK_TODO: MRDPView:windowDidResize windowID=%d left=%d top=%d right=%d bottom=x%d width=%f height=%f\n",
[currentWindow windowID], windowMove.left, windowMove.top, windowMove.right, windowMove.bottom, r.size.width, r.size.height);
//mac_send_rail_client_event(g_mrdpview->rdp_instance->context->channels, RDP_EVENT_TYPE_RAIL_CLIENT_WINDOW_MOVE, &windowMove);
}
/************************************************************************
* *
* C functions *
* *
***********************************************************************/
/** *********************************************************************
* connect to RDP server
*
* @return 0 on success, -1 on failure
***********************************************************************/
int rdp_connect()
{
2013-02-22 08:07:35 +04:00
int status;
freerdp* instance;
2013-02-22 06:42:47 +04:00
freerdp_channels_global_init();
2013-02-22 08:07:35 +04:00
instance = freerdp_new();
instance->PreConnect = mac_pre_connect;
instance->PostConnect = mac_post_connect;
instance->context_size = sizeof(struct mac_context);
instance->ContextNew = mac_context_new;
instance->ContextFree = mac_context_free;
instance->ReceiveChannelData = receive_channel_data;
freerdp_context_new(instance);
2013-02-22 06:42:47 +04:00
2013-02-22 08:07:35 +04:00
status = freerdp_connect(instance);
2013-02-22 07:04:09 +04:00
if (status)
{
2013-02-22 08:07:35 +04:00
freerdp_check_fds(instance);
2013-02-22 06:42:47 +04:00
[g_mrdpview setIs_connected:1];
return 0;
}
2013-02-22 07:04:09 +04:00
2013-02-22 06:42:47 +04:00
[g_mrdpview setIs_connected:0];
[g_mrdpview rdpConnectError];
2013-02-22 07:04:09 +04:00
2013-02-22 06:42:47 +04:00
return -1;
}
/** *********************************************************************
* a callback given to freerdp_connect() to process the pre-connect operations.
*
2013-02-22 06:42:47 +04:00
* @param inst - pointer to a rdp_freerdp struct that contains the connection's parameters, and
* will be filled with the appropriate informations.
*
* @return true if successful. false otherwise.
************************************************************************/
2013-02-22 08:07:35 +04:00
BOOL mac_pre_connect(freerdp* instance)
{
2013-02-22 08:07:35 +04:00
int i;
int len;
2012-11-23 00:32:21 +04:00
int status;
2013-02-22 08:07:35 +04:00
char* cptr;
instance->settings->OffscreenSupportLevel = FALSE;
instance->settings->GlyphSupportLevel = GLYPH_SUPPORT_FULL;
instance->settings->OrderSupport[NEG_GLYPH_INDEX_INDEX] = TRUE;
instance->settings->OrderSupport[NEG_FAST_GLYPH_INDEX] = FALSE;
instance->settings->OrderSupport[NEG_FAST_INDEX_INDEX] = FALSE;
instance->settings->OrderSupport[NEG_SCRBLT_INDEX] = TRUE;
instance->settings->OrderSupport[NEG_SAVEBITMAP_INDEX] = FALSE;
instance->settings->BitmapCacheEnabled = TRUE;
instance->settings->OrderSupport[NEG_MEMBLT_INDEX] = TRUE;
instance->settings->OrderSupport[NEG_MEMBLT_V2_INDEX] = TRUE;
instance->settings->OrderSupport[NEG_MEM3BLT_INDEX] = FALSE;
instance->settings->OrderSupport[NEG_MEM3BLT_V2_INDEX] = FALSE;
instance->settings->BitmapCacheV2NumCells = 3; // 5;
instance->settings->BitmapCacheV2CellInfo[0].numEntries = 0x78; // 600;
instance->settings->BitmapCacheV2CellInfo[0].persistent = FALSE;
instance->settings->BitmapCacheV2CellInfo[1].numEntries = 0x78; // 600;
instance->settings->BitmapCacheV2CellInfo[1].persistent = FALSE;
instance->settings->BitmapCacheV2CellInfo[2].numEntries = 0x150; // 2048;
instance->settings->BitmapCacheV2CellInfo[2].persistent = FALSE;
instance->settings->BitmapCacheV2CellInfo[3].numEntries = 0; // 4096;
instance->settings->BitmapCacheV2CellInfo[3].persistent = FALSE;
instance->settings->BitmapCacheV2CellInfo[4].numEntries = 0; // 2048;
instance->settings->BitmapCacheV2CellInfo[4].persistent = FALSE;
instance->settings->OrderSupport[NEG_MULTIDSTBLT_INDEX] = FALSE;
instance->settings->OrderSupport[NEG_MULTIPATBLT_INDEX] = FALSE;
instance->settings->OrderSupport[NEG_MULTISCRBLT_INDEX] = FALSE;
instance->settings->OrderSupport[NEG_MULTIOPAQUERECT_INDEX] = FALSE;
instance->settings->OrderSupport[NEG_POLYLINE_INDEX] = FALSE;
instance->settings->ColorDepth = 24;
instance->settings->SoftwareGdi = 1;
2013-02-22 06:42:47 +04:00
// setup callbacks
2013-02-22 08:07:35 +04:00
instance->update->BeginPaint = mac_begin_paint;
instance->update->EndPaint = mac_end_paint;
instance->update->SetBounds = mac_set_bounds;
instance->update->BitmapUpdate = mac_bitmap_update;
2013-02-22 06:42:47 +04:00
NSArray *args = [[NSProcessInfo processInfo] arguments];
g_mrdpview->argc = (int) [args count];
g_mrdpview->argv = malloc(sizeof(char *) * g_mrdpview->argc);
if (g_mrdpview->argv == NULL)
return FALSE;
i = 0;
// in RemoteApp (RAIL) mode, we connect to RDP server at max screen resolution;
// in order to achieve this, we need to modify the cmd line args entered by the user;
2013-02-22 07:04:09 +04:00
if (g_mrdpview->isRemoteApp)
{
2013-02-22 06:42:47 +04:00
BOOL gotGeometry = NO;
// get dimensions of screen that has keyboard focus;
// we use these dimensions when connecting to RDP server
2013-02-22 08:07:35 +04:00
instance->settings->DesktopWidth = [[NSScreen mainScreen] frame].size.width;
instance->settings->DesktopHeight = [[NSScreen mainScreen] frame].size.height - g_mrdpview->titleBarHeight;
g_mrdpview->width = instance->settings->DesktopWidth;
g_mrdpview->height = instance->settings->DesktopHeight;
2013-02-22 06:42:47 +04:00
for (NSString * str in args)
{
2013-02-22 07:04:09 +04:00
if (gotGeometry)
{
2013-02-22 06:42:47 +04:00
gotGeometry = NO;
cptr = (char *) malloc(20);
sprintf(cptr, "%dx%d", g_mrdpview->width, g_mrdpview->height);
g_mrdpview->argv[i++] = cptr;
continue;
}
len = (int) ([str length] + 1);
cptr = (char *) malloc(len);
strcpy(cptr, [str UTF8String]);
g_mrdpview->argv[i++] = cptr;
// -g is the cmd line arg to specify screen resolution/geometry
2013-02-22 07:04:09 +04:00
if ([str compare:@"-g"] == NSOrderedSame)
{
2013-02-22 06:42:47 +04:00
gotGeometry = YES;
}
}
}
2013-02-22 07:04:09 +04:00
else
{
2013-02-22 06:42:47 +04:00
for (NSString * str in args)
{
len = (int) ([str length] + 1);
cptr = (char *) malloc(len);
strcpy(cptr, [str UTF8String]);
g_mrdpview->argv[i++] = cptr;
}
}
2012-11-23 00:32:21 +04:00
2013-02-22 08:07:35 +04:00
instance->context->argc = g_mrdpview->argc;
instance->context->argv = g_mrdpview->argv;
2012-11-23 00:32:21 +04:00
2013-02-22 08:07:35 +04:00
status = freerdp_client_parse_command_line_arguments(instance->context->argc, instance->context->argv, instance->settings);
2012-11-23 00:32:21 +04:00
if (status < 0)
{
[NSApp terminate:nil];
return TRUE;
}
2013-02-22 08:07:35 +04:00
freerdp_client_load_addins(instance->context->channels, instance->settings);
2013-02-22 06:42:47 +04:00
2013-02-22 08:07:35 +04:00
[g_mrdpview setViewSize:instance->settings->DesktopWidth :instance->settings->DesktopHeight];
2013-02-22 06:42:47 +04:00
2013-02-22 08:07:35 +04:00
freerdp_channels_pre_connect(instance->context->channels, instance);
2013-02-22 06:42:47 +04:00
return TRUE;
}
/** *********************************************************************
* a callback registered with freerdp_connect() to perform post-connection operations.
2013-02-22 06:42:47 +04:00
* we get called only if the connection was initialized properly, and will continue
* the initialization based on the newly created connection.
*
* @param inst - pointer to a rdp_freerdp struct
*
* @return true on success, false on failure
*
************************************************************************/
2013-02-22 08:07:35 +04:00
BOOL mac_post_connect(freerdp* instance)
{
2013-02-22 08:07:35 +04:00
int index;
int fds[32];
UINT32 flags;
int rd_count = 0;
int wr_count = 0;
void* rd_fds[32];
void* wr_fds[32];
2013-02-22 06:42:47 +04:00
rdpPointer rdp_pointer;
memset(&rdp_pointer, 0, sizeof(rdpPointer));
rdp_pointer.size = sizeof(rdpPointer);
rdp_pointer.New = pointer_new;
rdp_pointer.Free = pointer_free;
rdp_pointer.Set = pointer_set;
rdp_pointer.SetNull = pointer_setNull;
rdp_pointer.SetDefault = pointer_setDefault;
flags = CLRCONV_ALPHA;
flags |= CLRBUF_32BPP;
2013-02-22 08:07:35 +04:00
gdi_init(instance, flags, NULL);
pointer_cache_register_callbacks(instance->update);
graphics_register_pointer(instance->context->graphics, &rdp_pointer);
2013-02-22 06:42:47 +04:00
// register file descriptors with the RunLoop
2013-02-22 08:07:35 +04:00
if (!freerdp_get_fds(instance, rd_fds, &rd_count, 0, 0))
2013-02-22 06:42:47 +04:00
{
printf("mac_post_connect: freerdp_get_fds() failed!\n");
}
for (index = 0; index < rd_count; index++)
{
fds[index] = (int)(long)rd_fds[index];
}
2013-02-22 08:07:35 +04:00
register_fds(fds, rd_count, instance);
2013-02-22 06:42:47 +04:00
// register channel manager file descriptors with the RunLoop
2013-02-22 08:07:35 +04:00
if (!freerdp_channels_get_fds(instance->context->channels, instance, rd_fds, &rd_count, wr_fds, &wr_count))
2013-02-22 06:42:47 +04:00
{
printf("ERROR: freerdp_channels_get_fds() failed\n");
}
for (index = 0; index < rd_count; index++)
{
fds[index] = (int)(long)rd_fds[index];
}
2013-02-22 07:04:09 +04:00
2013-02-22 08:07:35 +04:00
register_channel_fds(fds, rd_count, instance);
freerdp_channels_post_connect(instance->context->channels, instance);
2013-02-22 06:42:47 +04:00
// setup RAIL (remote app)
2013-02-22 08:07:35 +04:00
instance->context->rail = rail_new(instance->settings);
rail_register_update_callbacks(instance->context->rail, instance->update);
mac_rail_register_callbacks(instance, instance->context->rail);
2013-02-22 06:42:47 +04:00
// setup pasteboard (aka clipboard) for copy operations (write only)
g_mrdpview->pasteboard_wr = [NSPasteboard generalPasteboard];
// setup pasteboard for read operations
g_mrdpview->pasteboard_rd = [NSPasteboard generalPasteboard];
g_mrdpview->pasteboard_changecount = (int) [g_mrdpview->pasteboard_rd changeCount];
g_mrdpview->pasteboard_timer = [NSTimer scheduledTimerWithTimeInterval:0.5 target:g_mrdpview selector:@selector(onPasteboardTimerFired:) userInfo:nil repeats:YES];
// we want to be notified when window resizes
[[NSNotificationCenter defaultCenter] addObserver:g_mrdpview selector:@selector(windowDidResize:) name:NSWindowDidResizeNotification object:nil];
return TRUE;
}
/** *********************************************************************
* create a new mouse cursor
*
* @param context our context state
* @param pointer information about the cursor to create
*
************************************************************************/
void pointer_new(rdpContext* context, rdpPointer* pointer)
{
2013-02-22 08:07:35 +04:00
BYTE* cursor_data;
2013-02-22 06:42:47 +04:00
MRDPCursor *mrdpCursor = [[MRDPCursor alloc] init];
NSRect rect;
rect.size.width = pointer->width;
rect.size.height = pointer->height;
rect.origin.x = pointer->xPos;
rect.origin.y = pointer->yPos;
cursor_data = (uint8 *) malloc(rect.size.width * rect.size.height * 4);
mrdpCursor->cursor_data = cursor_data;
freerdp_alpha_cursor_convert(cursor_data, pointer->xorMaskData, pointer->andMaskData,
pointer->width, pointer->height, pointer->xorBpp, context->gdi->clrconv);
// TODO if xorBpp is > 24 need to call freerdp_image_swap_color_order
// see file df_graphics.c
// store cursor bitmap image in representation - required by NSImage
NSBitmapImageRep *bmiRep;
bmiRep = [[NSBitmapImageRep alloc] initWithBitmapDataPlanes:(unsigned char **) &cursor_data
2013-02-22 07:04:09 +04:00
pixelsWide:rect.size.width
2013-02-22 06:42:47 +04:00
pixelsHigh:rect.size.height
bitsPerSample:8
samplesPerPixel:sizeof(struct rgba_data)
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bitmapFormat:0
bytesPerRow:rect.size.width * 4
bitsPerPixel:0];
mrdpCursor->bmiRep = bmiRep;
// create an image using above representation
NSImage *image = [[NSImage alloc] initWithSize:[bmiRep size]];
[image addRepresentation: bmiRep];
[image setFlipped:NO];
mrdpCursor->nsImage = image;
// need hotspot to create cursor
NSPoint hotSpot;
hotSpot.x = pointer->xPos;
hotSpot.y = pointer->yPos;
NSCursor *cursor = [[NSCursor alloc] initWithImage: image hotSpot:hotSpot];
mrdpCursor->nsCursor = cursor;
mrdpCursor->pointer = pointer;
// save cursor for later use in pointer_set()
NSMutableArray *ma = g_mrdpview->cursors;
[ma addObject:mrdpCursor];
}
/** *********************************************************************
* release resources on specified cursor
************************************************************************/
void pointer_free(rdpContext* context, rdpPointer* pointer)
{
2013-02-22 08:07:35 +04:00
NSMutableArray* ma = g_mrdpview->cursors;
2013-02-22 06:42:47 +04:00
2013-02-22 08:07:35 +04:00
for (MRDPCursor* cursor in ma)
2013-02-22 06:42:47 +04:00
{
2013-02-22 07:04:09 +04:00
if (cursor->pointer == pointer)
{
2013-02-22 06:42:47 +04:00
cursor->nsImage = nil;
cursor->nsCursor = nil;
cursor->bmiRep = nil;
free(cursor->cursor_data);
[ma removeObject:cursor];
return;
}
}
}
/** *********************************************************************
* set specified cursor as the current cursor
************************************************************************/
void pointer_set(rdpContext* context, rdpPointer* pointer)
{
2013-02-22 08:07:35 +04:00
NSMutableArray* ma = g_mrdpview->cursors;
2013-02-22 06:42:47 +04:00
if (!g_mrdpview->mouseInClientArea)
2013-02-22 08:07:35 +04:00
return;
2013-02-22 06:42:47 +04:00
2013-02-22 08:07:35 +04:00
for (MRDPCursor* cursor in ma)
2013-02-22 06:42:47 +04:00
{
2013-02-22 07:04:09 +04:00
if (cursor->pointer == pointer)
{
2013-02-22 06:42:47 +04:00
[cursor->nsCursor set];
return;
}
}
}
/** *********************************************************************
* do not display any mouse cursor
***********************************************************************/
void pointer_setNull(rdpContext* context)
{
}
/** *********************************************************************
* display default mouse cursor
***********************************************************************/
void pointer_setDefault(rdpContext* context)
{
}
/** *********************************************************************
* create a new context - but all we really need to do is save state info
***********************************************************************/
2013-02-22 08:07:35 +04:00
void mac_context_new(freerdp* instance, rdpContext* context)
{
2013-02-22 08:07:35 +04:00
[g_mrdpview saveStateInfo:instance :context];
2013-02-22 06:42:47 +04:00
context->channels = freerdp_channels_new();
}
/** *********************************************************************
* we don't do much over here
***********************************************************************/
2013-02-22 08:07:35 +04:00
void mac_context_free(freerdp* instance, rdpContext* context)
{
}
/** *********************************************************************
* clip drawing surface so nothing is drawn outside specified bounds
***********************************************************************/
2013-02-22 08:07:35 +04:00
void mac_set_bounds(rdpContext* context, rdpBounds* bounds)
{
}
/** *********************************************************************
* we don't do much over here
***********************************************************************/
2013-02-22 08:07:35 +04:00
void mac_bitmap_update(rdpContext* context, BITMAP_UPDATE* bitmap)
{
}
/** *********************************************************************
* we don't do much over here
***********************************************************************/
2013-02-22 08:07:35 +04:00
void mac_begin_paint(rdpContext* context)
{
2013-02-22 06:42:47 +04:00
rdpGdi* gdi = context->gdi;
gdi->primary->hdc->hwnd->invalid->null = 1;
}
/** *********************************************************************
* RDP server wants us to draw new data in the view
***********************************************************************/
void mac_end_paint(rdpContext* context)
{
2013-02-22 08:07:35 +04:00
int i;
rdpGdi* gdi;
NSRect drawRect;
2013-02-22 06:42:47 +04:00
if ((context == 0) || (context->gdi == 0))
return;
if (context->gdi->primary->hdc->hwnd->invalid->null)
return;
if (context->gdi->drawing != context->gdi->primary)
return;
gdi = g_mrdpview->rdp_context->gdi;
2013-02-22 07:04:09 +04:00
if (g_mrdpview->isRemoteApp && g_mrdpview->currentWindow)
{
2013-02-22 06:42:47 +04:00
[[g_mrdpview->currentWindow view] updateDisplay];
return;
}
for (i = 0; i < gdi->primary->hdc->hwnd->ninvalid; i++)
{
drawRect.origin.x = gdi->primary->hdc->hwnd->cinvalid[i].x;
drawRect.origin.y = gdi->primary->hdc->hwnd->cinvalid[i].y;
drawRect.size.width = gdi->primary->hdc->hwnd->cinvalid[i].w;
drawRect.size.height = gdi->primary->hdc->hwnd->cinvalid[i].h;
convert_color_space(g_mrdpview->pixel_data, (char *) gdi->primary_buffer, &drawRect, g_mrdpview->width, g_mrdpview->height);
[g_mrdpview setNeedsDisplayInRect:drawRect];
}
2013-02-22 07:04:09 +04:00
2013-02-22 06:42:47 +04:00
gdi->primary->hdc->hwnd->ninvalid = 0;
}
/** *********************************************************************
* called when data is available on a socket
***********************************************************************/
2013-02-22 07:04:09 +04:00
void skt_activity_cb(CFSocketRef s, CFSocketCallBackType callbackType,
CFDataRef address, const void* data, void* info)
{
2013-02-22 07:04:09 +04:00
if (!freerdp_check_fds(info))
{
2013-02-22 06:42:47 +04:00
// lost connection or did not connect
[NSApp terminate:nil];
}
}
/** *********************************************************************
* called when data is available on a virtual channel
***********************************************************************/
2013-02-22 07:04:09 +04:00
void channel_activity_cb(CFSocketRef s, CFSocketCallBackType callbackType,
CFDataRef address, const void* data, void* info)
2013-02-22 06:42:47 +04:00
{
RDP_EVENT* event;
2013-02-22 08:07:35 +04:00
freerdp* instance = (freerdp*) info;
2013-02-22 06:42:47 +04:00
2013-02-22 08:07:35 +04:00
freerdp_channels_check_fds(instance->context->channels, instance);
event = freerdp_channels_pop_event(instance->context->channels);
2013-02-22 07:04:09 +04:00
if (event)
{
2013-02-22 06:42:47 +04:00
switch (event->event_class)
{
case RDP_EVENT_CLASS_RAIL:
2013-02-22 08:07:35 +04:00
mac_process_rail_event(instance, event);
2013-02-22 06:42:47 +04:00
break;
case RDP_EVENT_CLASS_CLIPRDR:
2013-02-22 08:07:35 +04:00
process_cliprdr_event(instance, event);
2013-02-22 06:42:47 +04:00
break;
}
}
}
/** *********************************************************************
* setup callbacks for data availability on sockets
***********************************************************************/
2013-02-22 08:07:35 +04:00
int register_fds(int* fds, int count, void* instance)
{
2013-02-22 06:42:47 +04:00
int i;
CFSocketRef skt_ref;
2013-02-22 08:07:35 +04:00
CFSocketContext skt_context = { 0, instance, NULL, NULL, NULL };
2013-02-22 06:42:47 +04:00
for (i = 0; i < count; i++)
{
skt_ref = CFSocketCreateWithNative(NULL, fds[i], kCFSocketReadCallBack, skt_activity_cb, &skt_context);
g_mrdpview->run_loop_src = CFSocketCreateRunLoopSource(NULL, skt_ref, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), g_mrdpview->run_loop_src, kCFRunLoopDefaultMode);
CFRelease(skt_ref);
}
2013-02-22 07:04:09 +04:00
2013-02-22 06:42:47 +04:00
return 0;
}
/** *********************************************************************
2013-02-22 06:42:47 +04:00
* setup callbacks for data availability on channels
***********************************************************************/
2013-02-22 08:07:35 +04:00
int register_channel_fds(int* fds, int count, void* instance)
{
2013-02-22 06:42:47 +04:00
int i;
CFSocketRef skt_ref;
2013-02-22 08:07:35 +04:00
CFSocketContext skt_context = { 0, instance, NULL, NULL, NULL };
2013-02-22 06:42:47 +04:00
for (i = 0; i < count; i++)
{
skt_ref = CFSocketCreateWithNative(NULL, fds[i], kCFSocketReadCallBack, channel_activity_cb, &skt_context);
g_mrdpview->run_loop_src_channels = CFSocketCreateRunLoopSource(NULL, skt_ref, 0);
CFRunLoopAddSource(CFRunLoopGetCurrent(), g_mrdpview->run_loop_src_channels, kCFRunLoopDefaultMode);
CFRelease(skt_ref);
}
2013-02-22 07:04:09 +04:00
2013-02-22 06:42:47 +04:00
return 0;
}
/** *********************************************************************
* called when channel data is available
***********************************************************************/
2013-02-22 08:07:35 +04:00
int receive_channel_data(freerdp* instance, int chan_id, BYTE* data, int size, int flags, int total_size)
{
2013-02-22 08:07:35 +04:00
return freerdp_channels_data(instance, chan_id, data, size, flags, total_size);
}
/** *********************************************************************
* convert an array containing ARGB data to RGBA
***********************************************************************/
2013-02-22 08:07:35 +04:00
void convert_color_space(char* dest, char* src, NSRect* drawRect, int width, int height)
{
2013-02-22 06:42:47 +04:00
int i;
int j;
int x;
int y;
int cx;
int cy;
int pixel;
int pixel1;
int pixel2;
int* src32;
int* dst32;
2013-02-22 08:07:35 +04:00
if ((!dest) || (!src))
2013-02-22 06:42:47 +04:00
return;
x = drawRect->origin.x;
y = drawRect->origin.y;
cx = drawRect->size.width;
cy = drawRect->size.height;
for (j = 0; j < cy; j++)
{
src32 = (int*)(src + ((y + j) * width + x) * 4);
dst32 = (int*)(dest + ((y + j) * width + x) * 4);
2013-02-22 08:07:35 +04:00
2013-02-22 06:42:47 +04:00
for (i = 0; i < cx; i++)
{
pixel = *src32;
pixel1 = (pixel & 0x00ff0000) >> 16;
pixel2 = (pixel & 0x000000ff) << 16;
pixel = (pixel & 0xff00ff00) | pixel1 | pixel2;
*dst32 = pixel;
src32++;
dst32++;
}
}
drawRect->origin.y = height - drawRect->origin.y - drawRect->size.height;
}
/**
* Used to load plugins based on the commandline parameters.
* This function is provided as a parameter to freerdp_parse_args(), that will call it
* each time a plugin name is found on the command line.
* This function just calls freerdp_channels_load_plugin() for the given plugin, and always returns 1.
2013-02-22 06:42:47 +04:00
*
* @param settings
* @param name
* @param plugin_data
* @param user_data
2013-02-22 06:42:47 +04:00
*
* @return 1
*/
int process_plugin_args(rdpSettings* settings, const char* name, RDP_PLUGIN_DATA* plugin_data, void* user_data)
{
2013-02-22 06:42:47 +04:00
rdpChannels* channels = (rdpChannels*) user_data;
freerdp_channels_load_plugin(channels, settings, name, plugin_data);
2013-02-22 08:07:35 +04:00
2013-02-22 06:42:47 +04:00
return 1;
}
/*
* stuff related to clipboard redirection
*/
/**
* remote system has requested clipboard data from local system
*/
2013-02-22 08:07:35 +04:00
void cliprdr_process_cb_data_request_event(freerdp* instance)
{
2013-02-22 08:07:35 +04:00
int len;
NSArray* types;
RDP_CB_DATA_RESPONSE_EVENT* event;
2013-02-22 06:42:47 +04:00
2013-02-22 07:04:09 +04:00
event = (RDP_CB_DATA_RESPONSE_EVENT*) freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, RDP_EVENT_TYPE_CB_DATA_RESPONSE, NULL, NULL);
2013-02-22 06:42:47 +04:00
types = [NSArray arrayWithObject:NSStringPboardType];
2013-02-22 08:07:35 +04:00
NSString* str = [g_mrdpview->pasteboard_rd availableTypeFromArray:types];
2013-02-22 07:04:09 +04:00
2013-02-22 06:42:47 +04:00
if (str == nil)
{
event->data = NULL;
event->size = 0;
}
else
{
2013-02-22 08:07:35 +04:00
NSString* data = [g_mrdpview->pasteboard_rd stringForType:NSStringPboardType];
2013-02-22 06:42:47 +04:00
len = (int) ([data length] * 2 + 2);
event->data = malloc(len);
[data getCString:(char *) event->data maxLength:len encoding:NSUnicodeStringEncoding];
event->size = len;
}
2013-02-22 07:04:09 +04:00
2013-02-22 08:07:35 +04:00
freerdp_channels_send_event(instance->context->channels, (RDP_EVENT*) event);
}
2013-02-22 08:07:35 +04:00
void cliprdr_send_data_request(freerdp* instance, UINT32 format)
{
2013-02-22 06:42:47 +04:00
RDP_CB_DATA_REQUEST_EVENT* event;
2013-02-22 08:07:35 +04:00
event = (RDP_CB_DATA_REQUEST_EVENT*) freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, RDP_EVENT_TYPE_CB_DATA_REQUEST, NULL, NULL);
2013-02-22 06:42:47 +04:00
event->format = format;
2013-02-22 08:07:35 +04:00
freerdp_channels_send_event(instance->context->channels, (RDP_EVENT*) event);
}
/**
* at the moment, only the following formats are supported
* CB_FORMAT_TEXT
* CB_FORMAT_UNICODETEXT
*/
2013-02-22 08:07:35 +04:00
void cliprdr_process_cb_data_response_event(freerdp* instance, RDP_CB_DATA_RESPONSE_EVENT* event)
{
2013-02-22 08:07:35 +04:00
NSString* str;
NSArray* types;
2013-02-22 06:42:47 +04:00
2013-02-22 07:04:09 +04:00
if (event->size == 0)
2013-02-22 06:42:47 +04:00
return;
2013-02-22 07:04:09 +04:00
if (g_mrdpview->pasteboard_format == CB_FORMAT_TEXT || g_mrdpview->pasteboard_format == CB_FORMAT_UNICODETEXT)
{
2013-02-22 06:42:47 +04:00
str = [[NSString alloc] initWithCharacters:(unichar *) event->data length:event->size / 2];
types = [[NSArray alloc] initWithObjects:NSStringPboardType, nil];
[g_mrdpview->pasteboard_wr declareTypes:types owner:g_mrdpview];
[g_mrdpview->pasteboard_wr setString:str forType:NSStringPboardType];
}
}
2013-02-22 08:07:35 +04:00
void cliprdr_process_cb_monitor_ready_event(freerdp* instance)
{
2013-02-22 06:42:47 +04:00
RDP_EVENT* event;
RDP_CB_FORMAT_LIST_EVENT* format_list_event;
event = freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, RDP_EVENT_TYPE_CB_FORMAT_LIST, NULL, NULL);
format_list_event = (RDP_CB_FORMAT_LIST_EVENT*)event;
format_list_event->num_formats = 0;
2013-02-22 08:07:35 +04:00
freerdp_channels_send_event(instance->context->channels, event);
}
/**
* list of supported clipboard formats; currently only the following are supported
* CB_FORMAT_TEXT
* CB_FORMAT_UNICODETEXT
*/
2013-02-22 08:07:35 +04:00
void cliprdr_process_cb_format_list_event(freerdp* instance, RDP_CB_FORMAT_LIST_EVENT* event)
{
2013-02-22 06:42:47 +04:00
int i;
2013-02-22 08:07:35 +04:00
if (event->num_formats == 0)
2013-02-22 06:42:47 +04:00
return;
for (i = 0; i < event->num_formats; i++)
{
switch (event->formats[i])
{
case CB_FORMAT_RAW:
printf("CB_FORMAT_RAW: not yet supported\n");
break;
case CB_FORMAT_TEXT:
case CB_FORMAT_UNICODETEXT:
g_mrdpview->pasteboard_format = CB_FORMAT_UNICODETEXT;
2013-02-22 08:07:35 +04:00
cliprdr_send_data_request(instance, CB_FORMAT_UNICODETEXT);
2013-02-22 06:42:47 +04:00
return;
break;
case CB_FORMAT_DIB:
printf("CB_FORMAT_DIB: not yet supported\n");
break;
case CB_FORMAT_HTML:
printf("CB_FORMAT_HTML\n");
break;
case CB_FORMAT_PNG:
printf("CB_FORMAT_PNG: not yet supported\n");
break;
case CB_FORMAT_JPEG:
printf("CB_FORMAT_JPEG: not yet supported\n");
break;
case CB_FORMAT_GIF:
printf("CB_FORMAT_GIF: not yet supported\n");
break;
}
}
}
2013-02-22 08:07:35 +04:00
void process_cliprdr_event(freerdp* instance, RDP_EVENT* event)
{
2013-02-22 07:04:09 +04:00
if (event)
{
2013-02-22 06:42:47 +04:00
switch (event->event_type)
{
// Monitor Ready PDU is sent by server to indicate that it has been
// inited and is ready. This PDU is transmitted by the server after it has sent
// Clipboard Capabilities PDU
case RDP_EVENT_TYPE_CB_MONITOR_READY:
2013-02-22 08:07:35 +04:00
cliprdr_process_cb_monitor_ready_event(instance);
2013-02-22 06:42:47 +04:00
break;
// The Format List PDU is sent either by the client or the server when its
// local system clipboard is updated with new clipboard data. This PDU
// contains the Clipboard Format ID and name pairs of the new Clipboard
// Formats on the clipboard
case RDP_EVENT_TYPE_CB_FORMAT_LIST:
2013-02-22 08:07:35 +04:00
cliprdr_process_cb_format_list_event(instance, (RDP_CB_FORMAT_LIST_EVENT*) event);
2013-02-22 06:42:47 +04:00
break;
// The Format Data Request PDU is sent by the receipient of the Format List PDU.
// It is used to request the data for one of the formats that was listed in the
// Format List PDU
case RDP_EVENT_TYPE_CB_DATA_REQUEST:
2013-02-22 08:07:35 +04:00
cliprdr_process_cb_data_request_event(instance);
2013-02-22 06:42:47 +04:00
break;
// The Format Data Response PDU is sent as a reply to the Format Data Request PDU.
// It is used to indicate whether processing of the Format Data Request PDU
// was successful. If the processing was successful, the Format Data Response PDU
// includes the contents of the requested clipboard data
case RDP_EVENT_TYPE_CB_DATA_RESPONSE:
2013-02-22 08:07:35 +04:00
cliprdr_process_cb_data_response_event(instance, (RDP_CB_DATA_RESPONSE_EVENT*) event);
2013-02-22 06:42:47 +04:00
break;
default:
printf("process_cliprdr_event: unknown event type %d\n", event->event_type);
break;
}
2013-02-22 07:04:09 +04:00
2013-02-22 06:42:47 +04:00
freerdp_event_free(event);
}
}
2013-02-22 08:07:35 +04:00
void cliprdr_send_supported_format_list(freerdp* instance)
{
2013-02-22 06:42:47 +04:00
RDP_CB_FORMAT_LIST_EVENT* event;
2013-02-22 07:04:09 +04:00
event = (RDP_CB_FORMAT_LIST_EVENT*) freerdp_event_new(RDP_EVENT_CLASS_CLIPRDR, RDP_EVENT_TYPE_CB_FORMAT_LIST, NULL, NULL);
2013-02-22 06:42:47 +04:00
2013-02-22 08:07:35 +04:00
event->formats = (UINT32*) malloc(sizeof(UINT32) * 1);
2013-02-22 06:42:47 +04:00
event->num_formats = 1;
event->formats[0] = CB_FORMAT_UNICODETEXT;
2013-02-22 08:07:35 +04:00
freerdp_channels_send_event(instance->context->channels, (RDP_EVENT*) event);
}
/****************************************************************************************
* *
* *
* RemoteApp (RAIL) related stuff goes here *
* *
* *
2013-02-22 06:42:47 +04:00
****************************************************************************************/
2013-02-22 08:07:35 +04:00
void mac_process_rail_event(freerdp* instance, RDP_EVENT* event)
{
2013-02-22 06:42:47 +04:00
switch (event->event_type)
{
case RDP_EVENT_TYPE_RAIL_CHANNEL_GET_SYSPARAMS:
2013-02-22 08:07:35 +04:00
mac_process_rail_get_sysparams_event(instance->context->channels, event);
2013-02-22 06:42:47 +04:00
break;
case RDP_EVENT_TYPE_RAIL_CHANNEL_EXEC_RESULTS:
2013-02-22 08:07:35 +04:00
mac_process_rail_exec_result_event(instance->context->channels, event);
2013-02-22 06:42:47 +04:00
break;
case RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_SYSPARAM:
2013-02-22 08:07:35 +04:00
mac_process_rail_server_sysparam_event(instance->context->channels, event);
2013-02-22 06:42:47 +04:00
break;
case RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_MINMAXINFO:
2013-02-22 08:07:35 +04:00
mac_process_rail_server_minmaxinfo_event(instance->context->channels, event);
2013-02-22 06:42:47 +04:00
break;
case RDP_EVENT_TYPE_RAIL_CHANNEL_SERVER_LOCALMOVESIZE:
2013-02-22 08:07:35 +04:00
mac_process_rail_server_localmovesize_event(instance, event);
2013-02-22 06:42:47 +04:00
break;
case RDP_EVENT_TYPE_RAIL_CHANNEL_APPID_RESP:
//xf_process_rail_appid_resp_event(xfi, channels, event);
break;
case RDP_EVENT_TYPE_RAIL_CHANNEL_LANGBARINFO:
//xf_process_rail_langbarinfo_event(xfi, channels, event);
break;
}
}
2013-02-22 08:07:35 +04:00
void mac_rail_CreateWindow(rdpRail* rail, rdpWindow* window)
{
2013-02-22 06:42:47 +04:00
BOOL centerWindow = NO;
BOOL moveWindow = NO;
BOOL displayAsModal = NO;
NSMutableArray * ma = g_mrdpview->windows;
// make sure window fits resolution
if (window->windowWidth > g_mrdpview->width)
window->windowWidth = g_mrdpview->width;
if (window->windowHeight > g_mrdpview->height)
window->windowHeight = g_mrdpview->height;
// center main window, which is the first to be created
2013-02-22 07:04:09 +04:00
if ([ma count] == 0)
{
2013-02-22 06:42:47 +04:00
centerWindow = YES;
moveWindow = YES;
}
2013-02-22 07:04:09 +04:00
if ((window->extendedStyle & WS_EX_TOPMOST) || (window->extendedStyle & WS_EX_TOOLWINDOW))
{
2013-02-22 06:42:47 +04:00
[g_mrdpview->currentWindow view]->skipMoveWindowOnce = TRUE;
moveWindow = YES;
}
2013-02-22 07:04:09 +04:00
else if (window->style & WS_POPUP)
{
2013-02-22 06:42:47 +04:00
centerWindow = YES;
moveWindow = YES;
}
2013-02-22 07:04:09 +04:00
else
{
2013-02-22 06:42:47 +04:00
}
// create NSWindow
NSRect winFrame = NSMakeRect(window->windowOffsetX, window->windowOffsetY,
window->windowWidth, window->windowHeight);
if (centerWindow)
apple_center_window(&winFrame);
MRDPRailWindow * newWindow = [[MRDPRailWindow alloc] initWithContentRect:winFrame
styleMask:NSTitledWindowMask | NSResizableWindowMask
backing:NSBackingStoreBuffered
defer:NO];
// this does not work if specified during window creation in above code
[newWindow setStyleMask:NSBorderlessWindowMask];
if (moveWindow) {
// let RDP server know that window has moved
RAIL_WINDOW_MOVE_ORDER windowMove;
apple_to_windowMove(&winFrame, &windowMove);
windowMove.windowId = window->windowId;
mac_send_rail_client_event(g_mrdpview->rdp_instance->context->channels, RDP_EVENT_TYPE_RAIL_CLIENT_WINDOW_MOVE, &windowMove);
}
// create MRDPRailView and add to above window
NSRect viewFrame = NSMakeRect(window->clientOffsetX, window->clientOffsetY,
window->clientAreaWidth, window->clientAreaHeight);
MRDPRailView * newView = [[MRDPRailView alloc] initWithFrame:viewFrame];
[newView setRdpInstance:g_mrdpview->rdp_instance width:g_mrdpview->width andHeight:g_mrdpview->height windowID: window->windowId];
[newWindow setContentView:newView];
// save new window
MRDPWindow * mrdpWindow = [[MRDPWindow alloc] init];
[mrdpWindow setWindowID:window->windowId];
[mrdpWindow setWindow:newWindow];
[mrdpWindow setView:newView];
// add to list of windows
[ma addObject:mrdpWindow];
// make new window current
g_mrdpview->currentWindow = mrdpWindow;
2013-02-22 07:04:09 +04:00
if (displayAsModal)
{
2013-02-22 06:42:47 +04:00
// display as modal window
NSModalSession session = [NSApp beginModalSessionForWindow:newWindow];
while (1)
{
if ([NSApp runModalSession:session] != NSRunContinuesResponse)
break;
}
[NSApp endModalSession:session];
}
else {
[newWindow makeKeyAndOrderFront:NSApp];
[[g_mrdpview window] resignFirstResponder];
[g_mrdpview resignFirstResponder];
[[g_mrdpview window] setNextResponder:newWindow];
}
return;
}
void mac_rail_MoveWindow(rdpRail *rail, rdpWindow *window)
{
2013-02-22 07:04:09 +04:00
if (g_mrdpview->currentWindow)
{
2013-02-22 06:42:47 +04:00
rail_MoveWindow(rail, window);
return;
}
}
void mac_rail_ShowWindow(rdpRail *rail, rdpWindow *window, uint8 state)
{
}
void mac_rail_SetWindowText(rdpRail *rail, rdpWindow *window)
{
}
void mac_rail_SetWindowIcon(rdpRail *rail, rdpWindow *window, rdpIcon *icon)
{
}
void mac_rail_SetWindowRects(rdpRail *rail, rdpWindow *window)
{
}
void mac_rail_SetWindowVisibilityRects(rdpRail *rail, rdpWindow *window)
{
}
/** *********************************************************************
* destroy window created in mac_rail_CreateWindow()
***********************************************************************/
void mac_rail_DestroyWindow(rdpRail *rail, rdpWindow *window)
{
2013-02-22 06:42:47 +04:00
int count = 0;
for (MRDPWindow * win in g_mrdpview->windows)
{
if ([win windowID] == window->windowId) {
//[[win window] close];
[win setView:nil];
[win setWindow:nil];
[g_mrdpview->windows removeObject:win];
count = [g_mrdpview->windows count];
if (count) {
g_mrdpview->currentWindow = [g_mrdpview->windows objectAtIndex:count - 1];
//[[g_mrdpview window] makeKeyAndOrderFront:[g_mrdpview->currentWindow window]];
[[g_mrdpview->currentWindow window] makeKeyAndOrderFront:NSApp];
}
else {
g_mrdpview->currentWindow = nil;
// RAIL_TODO [[g_mrdpview window] makeKeyAndOrderFront:[g_mrdpview window]];
[NSApp terminate:nil];
}
return;
}
}
}
void mac_rail_register_callbacks(freerdp *inst, rdpRail *rail)
2013-02-22 07:04:09 +04:00
{
rail->extra = (void*) inst;
2013-02-22 06:42:47 +04:00
rail->rail_CreateWindow = mac_rail_CreateWindow;
rail->rail_MoveWindow = mac_rail_MoveWindow;
rail->rail_ShowWindow = mac_rail_ShowWindow;
rail->rail_SetWindowText = mac_rail_SetWindowText;
rail->rail_SetWindowIcon = mac_rail_SetWindowIcon;
rail->rail_SetWindowRects = mac_rail_SetWindowRects;
rail->rail_SetWindowVisibilityRects = mac_rail_SetWindowVisibilityRects;
rail->rail_DestroyWindow = mac_rail_DestroyWindow;
}
/** *********************************************************************
* set work area size, which is the portion of the screen not obscured
* by the system taskbar or by application desktop toolbars
************************************************************************/
2013-02-22 07:04:09 +04:00
void mac_process_rail_get_sysparams_event(rdpChannels* channels, RDP_EVENT* event)
{
2013-02-22 06:42:47 +04:00
RAIL_SYSPARAM_ORDER * sysparam;
2013-02-22 07:04:09 +04:00
sysparam = (RAIL_SYSPARAM_ORDER*) event->user_data;
2013-02-22 06:42:47 +04:00
sysparam->workArea.left = 0;
sysparam->workArea.top = 22;
sysparam->workArea.right = g_mrdpview->width;
sysparam->workArea.bottom = g_mrdpview->height - 22;
sysparam->taskbarPos.left = 0;
sysparam->taskbarPos.top = 0;
sysparam->taskbarPos.right = 0;
sysparam->taskbarPos.bottom = 0;
sysparam->dragFullWindows = FALSE;
mac_send_rail_client_event(channels, RDP_EVENT_TYPE_RAIL_CLIENT_SET_SYSPARAMS, sysparam);
}
void mac_process_rail_server_sysparam_event(rdpChannels* channels, RDP_EVENT* event)
{
2013-02-22 06:42:47 +04:00
RAIL_SYSPARAM_ORDER* sysparam = (RAIL_SYSPARAM_ORDER*) event->user_data;
switch (sysparam->param)
{
case SPI_SET_SCREEN_SAVE_ACTIVE:
break;
case SPI_SET_SCREEN_SAVE_SECURE:
break;
}
}
/** *********************************************************************
* server returned result of exec'ing remote app on server
************************************************************************/
void mac_process_rail_exec_result_event(rdpChannels* channels, RDP_EVENT* event)
{
2013-02-22 06:42:47 +04:00
RAIL_EXEC_RESULT_ORDER* exec_result;
exec_result = (RAIL_EXEC_RESULT_ORDER*) event->user_data;
2013-02-22 07:04:09 +04:00
if (exec_result->execResult != RAIL_EXEC_S_OK)
{
2013-02-22 06:42:47 +04:00
printf("RAIL exec error: execResult=%s NtError=0x%X\n",
error_code_names[exec_result->execResult], exec_result->rawResult);
g_mrdpview->is_connected = FALSE;
[g_mrdpview rdpRemoteAppError];
}
2013-02-22 07:04:09 +04:00
else
{
2013-02-22 06:42:47 +04:00
mac_rail_enable_remoteapp_mode();
}
}
/** *********************************************************************
* sent by server when a window move or resize on the server is being
* initiated. this PDU contains info about the min and max extents
* to which the window can be moved or sized
************************************************************************/
void mac_process_rail_server_minmaxinfo_event(rdpChannels* channels, RDP_EVENT* event)
{
#if 0
2013-02-22 06:42:47 +04:00
RAIL_MINMAXINFO_ORDER * minmax = (RAIL_MINMAXINFO_ORDER*) event->user_data;
printf("minmax_info: maxPosX=%d maxPosY=%d maxWidth=%d maxHeight=%d minTrackWidth=%d minTrackHeight=%d maxTrackWidth=%d maxTrackHeight=%d\n",
minmax->maxPosX, minmax->maxPosY, minmax->maxWidth, minmax->maxHeight,
minmax->minTrackWidth, minmax->minTrackHeight, minmax->maxTrackWidth, minmax->maxTrackHeight);
#endif
}
/** *********************************************************************
* sent by the server when a window on the server is beginning a move or
* resize; use this info to initiate a local move or resize of the
* corresponding local window
************************************************************************/
2013-02-22 08:07:35 +04:00
void mac_process_rail_server_localmovesize_event(freerdp* instance, RDP_EVENT *event)
{
2013-02-22 07:04:09 +04:00
RAIL_LOCALMOVESIZE_ORDER* moveSize = (RAIL_LOCALMOVESIZE_ORDER*) event->user_data;
2013-02-22 06:42:47 +04:00
RAIL_WINDOW_MOVE_ORDER windowMove;
2013-02-22 07:04:09 +04:00
switch (moveSize->moveSizeType)
{
2013-02-22 06:42:47 +04:00
case RAIL_WMSZ_LEFT:
printf("!!!! RAIL_WMSZ_LEFT\n");
break;
case RAIL_WMSZ_RIGHT:
printf("!!!! RAIL_WMSZ_RIGHT\n");
break;
case RAIL_WMSZ_TOP:
printf("!!!! RAIL_WMSZ_TOP\n");
break;
case RAIL_WMSZ_TOPLEFT:
printf("!!!! RAIL_WMSZ_TOPLEFT\n");
break;
case RAIL_WMSZ_TOPRIGHT:
printf("!!!! RAIL_WMSZ_TOPRIGHT\n");
break;
case RAIL_WMSZ_BOTTOM:
printf("!!!! RAIL_WMSZ_BOTTOM\n");
break;
case RAIL_WMSZ_BOTTOMLEFT:
printf("!!!! RAIL_WMSZ_BOTTOMLEFT\n");
break;
case RAIL_WMSZ_BOTTOMRIGHT:
printf("!!!! RAIL_WMSZ_BOTTOMRIGHT\n");
break;
case RAIL_WMSZ_MOVE:
2013-02-22 07:04:09 +04:00
if (moveSize->isMoveSizeStart)
{
2013-02-22 06:42:47 +04:00
// local window move in progress
[g_mrdpview->currentWindow view]->isMoveSizeInProgress = YES;
[g_mrdpview->currentWindow view]->saveInitialDragLoc = YES;
return;
}
// local move has completed
[g_mrdpview->currentWindow view]->isMoveSizeInProgress = NO;
[g_mrdpview->currentWindow view]->saveInitialDragLoc = NO;
// let RDP server know where this window is located
2013-02-22 08:07:35 +04:00
mac_send_rail_client_event(instance->context->channels, RDP_EVENT_TYPE_RAIL_CLIENT_WINDOW_MOVE, &windowMove);
2013-02-22 06:42:47 +04:00
// the event we just sent will cause an extra MoveWindow() to be invoked which we need to ignore
[g_mrdpview->currentWindow view]->skipMoveWindowOnce = YES;
break;
case RAIL_WMSZ_KEYMOVE:
printf("!!!! RAIL_WMSZ_KEYMOVE\n");
break;
case RAIL_WMSZ_KEYSIZE:
printf("!!!! RAIL_WMSZ_KEYSIZE\n");
break;
default:
break;
}
2013-02-22 07:04:09 +04:00
2013-02-22 06:42:47 +04:00
return;
}
2013-02-22 08:07:35 +04:00
void mac_send_rail_client_event(rdpChannels* channels, UINT16 event_type, void* param)
{
2013-02-22 07:04:09 +04:00
RDP_EVENT* out_event = NULL;
void* payload = NULL;
2013-02-22 06:42:47 +04:00
payload = rail_clone_order(event_type, param);
2013-02-22 07:04:09 +04:00
if (payload != NULL)
{
out_event = freerdp_event_new(RDP_EVENT_CLASS_RAIL, event_type, mac_on_free_rail_client_event, payload);
2013-02-22 06:42:47 +04:00
freerdp_channels_send_event(channels, out_event);
}
}
void mac_on_free_rail_client_event(RDP_EVENT* event)
2013-02-22 07:04:09 +04:00
{
2013-02-22 06:42:47 +04:00
if (event->event_class == RDP_EVENT_CLASS_RAIL)
{
rail_free_cloned_order(event->event_type, event->user_data);
}
}
void mac_rail_enable_remoteapp_mode()
2013-02-22 07:04:09 +04:00
{
2013-02-22 06:42:47 +04:00
if (!g_mrdpview->isRemoteApp)
g_mrdpview->isRemoteApp = TRUE;
}
/**
* given a rect with 0,0 at the bottom left (apple cords)
* convert it to a rect with 0,0 at the top left (windows cords)
*/
2013-02-22 08:07:35 +04:00
void apple_to_windows_cords(NSRect* r)
{
2013-02-22 06:42:47 +04:00
r->origin.y = g_mrdpview->height - (r->origin.y + r->size.height);
}
/**
* given a rect with 0,0 at the top left (windows cords)
* convert it to a rect with 0,0 at the bottom left (apple cords)
*/
2013-02-22 08:07:35 +04:00
void windows_to_apple_cords(NSRect* r)
{
2013-02-22 06:42:47 +04:00
r->origin.y = g_mrdpview->height - (r->origin.y + r->size.height);
}
2013-02-22 08:07:35 +04:00
void apple_center_window(NSRect* r)
{
2013-02-22 06:42:47 +04:00
r->origin.x = (g_mrdpview->width - r->size.width) / 2;
r->origin.y = (g_mrdpview->height - r->size.height) / 2;
}
2013-02-22 08:07:35 +04:00
void apple_to_windowMove(NSRect* r, RAIL_WINDOW_MOVE_ORDER* windowMove)
{
2013-02-22 08:07:35 +04:00
windowMove->left = (UINT16) r->origin.x; // x-cord of top left corner
windowMove->top = (UINT16) g_mrdpview->height - (r->origin.y + r->size.height); // y-cord of top left corner
windowMove->right = (UINT16) (windowMove->left + r->size.width); // x-cord of bottom right corner
windowMove->bottom = (UINT16) (windowMove->top + r->size.height); // y-cord of bottom right corner
}
@end