11#import "AdvancedKeyboardView.h" 
   12#include <freerdp/locale/keyboard.h> 
   21@interface AdvancedKeyboardView (Private)
 
   22- (UIView *)keyboardViewForItems:(struct ButtonItem *)items columns:(
int)columns rows:(
int)rows;
 
   27@synthesize delegate = _delegate;
 
   30#define KEY_SHOW_FUNCVIEW 0x1000 
   31#define KEY_SHOW_CURSORVIEW 0x1001 
   32#define KEY_SHOW_NUMPADVIEW 0x1002 
   33#define KEY_SKIP 0x8000 
   34#define KEY_MERGE_COLUMN 0x8001 
   36#define KEYCODE_UNICODE 0x80000000 
   38struct ButtonItem functionKeysItems[24] = { { 
@"F1", VK_F1 },
 
   51                                          { 
@"img:icon_key_arrows", KEY_SHOW_CURSORVIEW },
 
   53                                          { 
@"Ins", VK_INSERT | KBDEXT },
 
   54                                          { 
@"Home", VK_HOME | KBDEXT },
 
   55                                          { 
@"PgUp", VK_PRIOR | KBDEXT },
 
   56                                          { 
@"img:icon_key_win", VK_LWIN | KBDEXT },
 
   58                                          { 
@"123", KEY_SHOW_NUMPADVIEW },
 
   59                                          { 
@"Print", VK_PRINT },
 
   60                                          { 
@"Del", VK_DELETE | KBDEXT },
 
   61                                          { 
@"End", VK_END | KBDEXT },
 
   62                                          { 
@"PgDn", VK_NEXT | KBDEXT },
 
   63                                          { 
@"img:icon_key_menu", VK_APPS | KBDEXT } };
 
   65struct ButtonItem numPadKeysItems[24] = { { 
@"(", KEYCODE_UNICODE | 40 },
 
   66                                        { 
@")", KEYCODE_UNICODE | 41 },
 
   70                                        { 
@"-", VK_SUBTRACT },
 
   72                                        { 
@"/", VK_DIVIDE | KBDEXT },
 
   73                                        { 
@"*", VK_MULTIPLY },
 
   79                                        { 
@"Fn", KEY_SHOW_FUNCVIEW },
 
   80                                        { 
@"Num", VK_NUMLOCK },
 
   84                                        { 
@"img:icon_key_backspace", VK_BACK },
 
   86                                        { 
@"img:icon_key_arrows", KEY_SHOW_CURSORVIEW },
 
   87                                        { 
@"=", KEYCODE_UNICODE | 61 },
 
   88                                        { 
@"", KEY_MERGE_COLUMN },
 
   91                                        { 
@"img:icon_key_return", VK_RETURN | KBDEXT } };
 
   93struct ButtonItem cursorKeysItems[24] = { { 
@"", KEY_SKIP },
 
  103                                        { 
@"img:icon_key_arrow_up", VK_UP | KBDEXT },
 
  107                                        { 
@"Fn", KEY_SHOW_FUNCVIEW },
 
  109                                        { 
@"img:icon_key_arrow_left", VK_LEFT | KBDEXT },
 
  111                                        { 
@"img:icon_key_arrow_right", VK_RIGHT | KBDEXT },
 
  112                                        { 
@"img:icon_key_backspace", VK_BACK },
 
  114                                        { 
@"123", KEY_SHOW_NUMPADVIEW },
 
  117                                        { 
@"img:icon_key_arrow_down", VK_DOWN | KBDEXT },
 
  119                                        { 
@"img:icon_key_return", VK_RETURN | KBDEXT } };
 
  121- (void)initFunctionKeysView
 
  123  _function_keys_view = [[
self keyboardViewForItems:functionKeysItems columns:6 rows:4] retain];
 
  124  [
self addSubview:_function_keys_view];
 
  127- (void)initNumPadKeysView
 
  129  _numpad_keys_view = [[
self keyboardViewForItems:numPadKeysItems columns:6 rows:4] retain];
 
  130  [
self addSubview:_numpad_keys_view];
 
  133- (void)initCursorKeysView
 
  135  _cursor_keys_view = [[
self keyboardViewForItems:cursorKeysItems columns:6 rows:4] retain];
 
  136  [
self addSubview:_cursor_keys_view];
 
  139- (id)initWithFrame:(CGRect)frame delegate:(NSObject<AdvancedKeyboardDelegate> *)delegate
 
  141  self = [
super initWithFrame:frame];
 
  144    _delegate = delegate;
 
  146    self.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
 
  147    self.backgroundColor = [UIColor blackColor];
 
  150    [
self initCursorKeysView];
 
  151    [
self initNumPadKeysView];
 
  152    [
self initFunctionKeysView];
 
  155    _cur_view = _function_keys_view;
 
  156    [_numpad_keys_view setHidden:YES];
 
  157    [_cursor_keys_view setHidden:YES];
 
  171- (void)drawRect:(CGRect)rect
 
  174  CGContextRef currentContext = UIGraphicsGetCurrentContext();
 
  176  CGGradientRef glossGradient;
 
  177  CGColorSpaceRef rgbColorspace;
 
  178  size_t num_locations = 2;
 
  179  CGFloat locations[2] = { 0.0, 1.0 };
 
  180  CGFloat components[8] = { 1.0, 1.0, 1.0, 0.35,   
 
  181                          1.0, 1.0, 1.0, 0.06 }; 
 
  183  rgbColorspace = CGColorSpaceCreateDeviceRGB();
 
  185      CGGradientCreateWithColorComponents(rgbColorspace, components, locations, num_locations);
 
  187  CGRect currentBounds = 
self.bounds;
 
  188  CGPoint topCenter = CGPointMake(CGRectGetMidX(currentBounds), 0.0f);
 
  189  CGPoint midCenter = CGPointMake(CGRectGetMidX(currentBounds), currentBounds.size.height);
 
  190  CGContextDrawLinearGradient(currentContext, glossGradient, topCenter, midCenter, 0);
 
  192  CGGradientRelease(glossGradient);
 
  193  CGColorSpaceRelease(rgbColorspace);
 
  198  [_function_keys_view autorelease];
 
  199  [_numpad_keys_view autorelease];
 
  200  [_cursor_keys_view autorelease];
 
  205#pragma mark button events 
  207- (IBAction)keyPressed:(
id)sender
 
  209  UIButton *btn = (UIButton *)sender;
 
  212    case KEY_SHOW_CURSORVIEW:
 
  214      [_cur_view setHidden:YES];
 
  215      [_cursor_keys_view setHidden:NO];
 
  216      _cur_view = _cursor_keys_view;
 
  219    case KEY_SHOW_NUMPADVIEW:
 
  221      [_cur_view setHidden:YES];
 
  222      [_numpad_keys_view setHidden:NO];
 
  223      _cur_view = _numpad_keys_view;
 
  226    case KEY_SHOW_FUNCVIEW:
 
  228      [_cur_view setHidden:YES];
 
  229      [_function_keys_view setHidden:NO];
 
  230      _cur_view = _function_keys_view;
 
  234      if ([btn tag] & KEYCODE_UNICODE)
 
  236        if ([[
self delegate] respondsToSelector:@selector(advancedKeyPressedUnicode:)])
 
  237          [[self delegate] advancedKeyPressedUnicode:([btn tag] & ~KEYCODE_UNICODE)];
 
  241        if ([[
self delegate] respondsToSelector:@selector(advancedKeyPressedVKey:)])
 
  242          [[self delegate] advancedKeyPressedVKey:[btn tag]];
 
  251@implementation AdvancedKeyboardView (Private)
 
  253- (UIView *)keyboardViewForItems:(struct ButtonItem *)items columns:(
int)columns rows:(
int)rows
 
  255  UIView *result_view = [[[UIView alloc] initWithFrame:self.bounds] autorelease];
 
  256  result_view.autoresizingMask =
 
  257      UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
 
  260  int max_btn_width = result_view.bounds.size.width / ((columns * 2) + 1);
 
  261  int max_btn_height = result_view.bounds.size.height / ((rows * 2) + 1);
 
  264  CGSize btn_size = CGSizeMake(45, 30);
 
  265  if (btn_size.width < max_btn_width)
 
  266    btn_size.width = max_btn_width;
 
  267  if (btn_size.height < max_btn_height)
 
  268    btn_size.height = max_btn_height;
 
  271  int dist_width = (result_view.bounds.size.width - (columns * btn_size.width)) / (columns + 1);
 
  272  int dist_height = (result_view.bounds.size.height - (rows * btn_size.height)) / (rows + 1);
 
  274  UIImage *btn_background_img = [UIImage
 
  275      imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"keyboard_button_background"
 
  277  for (
int j = 0; j < rows; j++)
 
  279    for (
int i = 0; i < columns; i++)
 
  281      struct ButtonItem *curItem = &items[j * columns + i];
 
  284      if (curItem->tag == KEY_SKIP)
 
  288      UIButton *btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
 
  289      [btn setAutoresizingMask:(UIViewAutoresizingFlexibleLeftMargin |
 
  290                                UIViewAutoresizingFlexibleRightMargin |
 
  291                                UIViewAutoresizingFlexibleTopMargin |
 
  292                                UIViewAutoresizingFlexibleBottomMargin |
 
  293                                UIViewAutoresizingFlexibleWidth |
 
  294                                UIViewAutoresizingFlexibleHeight)];
 
  296                    action:@selector(keyPressed:)
 
  297          forControlEvents:UIControlEventTouchUpInside];
 
  300      if (curItem->tag == KEY_MERGE_COLUMN)
 
  303        [btn setFrame:CGRectMake(dist_width + (i * dist_width) + (i * btn_size.width),
 
  304                                 dist_height + (j * dist_height) + (j * btn_size.height),
 
  305                                 btn_size.width * 2 + dist_width, btn_size.height)];
 
  309        curItem = &items[j * columns + i];
 
  313        [btn setFrame:CGRectMake(dist_width + (i * dist_width) + (i * btn_size.width),
 
  314                                 dist_height + (j * dist_height) + (j * btn_size.height),
 
  315                                 btn_size.width, btn_size.height)];
 
  319      if ([curItem->title hasPrefix:
@"img:"] == YES)
 
  322            [UIImage imageWithContentsOfFile:[[NSBundle mainBundle]
 
  323                                                 pathForResource:[curItem->title
 
  324                                                                     substringFromIndex:4]
 
  326        [btn setImage:btn_image forState:UIControlStateNormal];
 
  330        [btn setTitle:curItem->title forState:UIControlStateNormal];
 
  331        [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
 
  334      [btn setBackgroundImage:btn_background_img forState:UIControlStateNormal];
 
  335      [btn setTag:curItem->tag];
 
  338      [result_view addSubview:btn];