Loading ...
Sorry, an error occurred while loading the content.

[PATCH] Add Basic Mouse Support for MMAtsuiTextView

Expand Messages
  • Jjgod Jiang
    I m kind of hesitate to commit this patch since most of code are the same with MMTextView, which implies there may be a better way to implement this, say, a
    Message 1 of 1 , Jul 26, 2008
    • 0 Attachment
      I'm kind of hesitate to commit this patch since most of code
      are the same with MMTextView, which implies there may be a
      better way to implement this, say, a general MMView class
      inherit by both MMAtsuiTextView and MMTextView, which
      implements the mouse{Down, Up, Move, Dragged} methods with
      a common interface.

      Please note at current stage, mouseDragged is missing
      because I can't figure out why the window is also receiving
      the drag event even I already handled it in MMAtsuiTextview,
      which will cause the window moving while the user is dragging
      around. So I need some help to investigate it further.
      ---
      src/MacVim/MMAtsuiTextView.m | 79 ++++++++++++++++++++++++++++++++++++++----
      1 files changed, 72 insertions(+), 7 deletions(-)

      diff --git a/src/MacVim/MMAtsuiTextView.m b/src/MacVim/MMAtsuiTextView.m
      index 8f5b5a9..13406d4 100644
      --- a/src/MacVim/MMAtsuiTextView.m
      +++ b/src/MacVim/MMAtsuiTextView.m
      @@ -100,7 +100,6 @@ enum {
      fraction:(int)percent color:(NSColor *)color;
      @end

      -
      @implementation MMAtsuiTextView

      - (id)initWithFrame:(NSRect)frame
      @@ -715,11 +714,6 @@ enum {
      int row, col;
      NSPoint pt = [self convertPoint:[event locationInWindow] fromView:nil];

      - // View is not flipped, instead the atsui code draws to a flipped image;
      - // thus we need to 'flip' the coordinate here since the column number
      - // increases in an up-to-down order.
      - pt.y = [self frame].size.height - pt.y;
      -
      if (![self convertPoint:pt toRow:&row column:&col])
      return;

      @@ -735,6 +729,72 @@ enum {
      [[self vimController] sendMessage:ScrollWheelMsgID data:data];
      }

      +- (void)mouseDown:(NSEvent *)event
      +{
      + int row, col;
      + NSPoint pt = [self convertPoint:[event locationInWindow] fromView:nil];
      + if (![self convertPoint:pt toRow:&row column:&col])
      + return;
      +
      + int button = [event buttonNumber];
      + int flags = [event modifierFlags];
      + int count = [event clickCount];
      + NSMutableData *data = [NSMutableData data];
      +
      + // If desired, intepret Ctrl-Click as a right mouse click.
      + if ([[NSUserDefaults standardUserDefaults]
      + boolForKey:MMTranslateCtrlClickKey]
      + && button == 0 && flags & NSControlKeyMask) {
      + button = 1;
      + flags &= ~NSControlKeyMask;
      + }
      +
      + [data appendBytes:&row length:sizeof(int)];
      + [data appendBytes:&col length:sizeof(int)];
      + [data appendBytes:&button length:sizeof(int)];
      + [data appendBytes:&flags length:sizeof(int)];
      + [data appendBytes:&count length:sizeof(int)];
      +
      + [[self vimController] sendMessage:MouseDownMsgID data:data];
      +}
      +
      +- (void)rightMouseDown:(NSEvent *)event
      +{
      + [self mouseDown:event];
      +}
      +
      +- (void)otherMouseDown:(NSEvent *)event
      +{
      + [self mouseDown:event];
      +}
      +
      +- (void)mouseUp:(NSEvent *)event
      +{
      + int row, col;
      + NSPoint pt = [self convertPoint:[event locationInWindow] fromView:nil];
      + if (![self convertPoint:pt toRow:&row column:&col])
      + return;
      +
      + int flags = [event modifierFlags];
      + NSMutableData *data = [NSMutableData data];
      +
      + [data appendBytes:&row length:sizeof(int)];
      + [data appendBytes:&col length:sizeof(int)];
      + [data appendBytes:&flags length:sizeof(int)];
      +
      + [[self vimController] sendMessage:MouseUpMsgID data:data];
      +}
      +
      +- (void)rightMouseUp:(NSEvent *)event
      +{
      + [self mouseUp:event];
      +}
      +
      +- (void)otherMouseUp:(NSEvent *)event
      +{
      + [self mouseUp:event];
      +}
      +
      @end // MMAtsuiTextView


      @@ -746,13 +806,18 @@ enum {
      {
      NSPoint origin = { insetSize.width, insetSize.height };

      + // View is not flipped, instead the atsui code draws to a flipped image;
      + // thus we need to 'flip' the coordinate here since the column number
      + // increases in an up-to-down order.
      + point.y = [self frame].size.height - point.y;
      +
      if (!(cellSize.width > 0 && cellSize.height > 0))
      return NO;

      if (row) *row = floor((point.y-origin.y-1) / cellSize.height);
      if (column) *column = floor((point.x-origin.x-1) / cellSize.width);

      - //NSLog(@"convertPoint:%@ toRow:%d column:%d", NSStringFromPoint(point),
      + // NSLog(@"convertPoint:%@ toRow:%d column:%d", NSStringFromPoint(point),
      // *row, *column);

      return YES;
      --
      1.5.4.3


      --~--~---------~--~----~------------~-------~--~----~
      You received this message from the "vim_mac" maillist.
      For more information, visit http://www.vim.org/maillist.php
      -~----------~----~----~----~------~----~------~--~---
    Your message has been successfully submitted and would be delivered to recipients shortly.