diff options
Diffstat (limited to 'cocoa')
-rw-r--r-- | cocoa/ScintillaCocoa.h | 3 | ||||
-rw-r--r-- | cocoa/ScintillaCocoa.mm | 21 | ||||
-rw-r--r-- | cocoa/ScintillaView.mm | 32 |
3 files changed, 53 insertions, 3 deletions
diff --git a/cocoa/ScintillaCocoa.h b/cocoa/ScintillaCocoa.h index 23c84e616..4d5d5c023 100644 --- a/cocoa/ScintillaCocoa.h +++ b/cocoa/ScintillaCocoa.h @@ -213,6 +213,7 @@ public: bool KeyboardInput(NSEvent* event); void MouseDown(NSEvent* event); + void RightMouseDown(NSEvent* event); void MouseMove(NSEvent* event); void MouseUp(NSEvent* event); void MouseEntered(NSEvent* event); @@ -235,6 +236,8 @@ public: virtual void Undo(); virtual void Redo(); + virtual bool ShouldDisplayPopupOnMargin(); + virtual bool ShouldDisplayPopupOnText(); virtual NSMenu* CreateContextMenu(NSEvent* event); void HandleCommand(NSInteger command); diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm index 076d6fcde..c283e4e98 100644 --- a/cocoa/ScintillaCocoa.mm +++ b/cocoa/ScintillaCocoa.mm @@ -2455,6 +2455,17 @@ void ScintillaCocoa::MouseDown(NSEvent* event) ButtonDown(Point(location.x, location.y), (int) (time * 1000), shift, command, alt); } +void ScintillaCocoa::RightMouseDown(NSEvent *event) +{ + Point location = ConvertPoint([event locationInWindow]); + NSTimeInterval time = [event timestamp]; + bool command = ([event modifierFlags] & NSCommandKeyMask) != 0; + bool shift = ([event modifierFlags] & NSShiftKeyMask) != 0; + bool alt = ([event modifierFlags] & NSAlternateKeyMask) != 0; + + RightButtonDownWithModifiers(Point(location.x, location.y), (int) (time * 1000), ModifierFlags(shift, command, alt)); +} + //-------------------------------------------------------------------------------------------------- void ScintillaCocoa::MouseMove(NSEvent* event) @@ -2533,6 +2544,16 @@ void ScintillaCocoa::Redo() //-------------------------------------------------------------------------------------------------- +bool ScintillaCocoa::ShouldDisplayPopupOnMargin() +{ + return displayPopupMenu == SC_POPUP_ALL; +} + +bool ScintillaCocoa::ShouldDisplayPopupOnText() +{ + return displayPopupMenu == SC_POPUP_ALL || displayPopupMenu == SC_POPUP_TEXT; +} + /** * Creates and returns a popup menu, which is then displayed by the Cocoa framework. */ diff --git a/cocoa/ScintillaView.mm b/cocoa/ScintillaView.mm index 7000d96e3..ab0c4375b 100644 --- a/cocoa/ScintillaView.mm +++ b/cocoa/ScintillaView.mm @@ -116,6 +116,21 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) } } +/** + * Called by the framework if it wants to show a context menu for the margin. + */ +- (NSMenu*) menuForEvent: (NSEvent*) theEvent +{ + NSMenu *menu = [owner menuForEvent: theEvent]; + if (menu) { + return menu; + } else if (owner.backend->ShouldDisplayPopupOnMargin()) { + return owner.backend->CreateContextMenu(theEvent); + } else { + return nil; + } +} + - (void) mouseDown: (NSEvent *) theEvent { NSClipView *textView = [[self scrollView] contentView]; @@ -123,6 +138,13 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) owner.backend->MouseDown(theEvent); } +- (void) rightMouseDown: (NSEvent *) theEvent +{ + [NSMenu popUpContextMenu:[self menuForEvent: theEvent] withEvent:theEvent forView:self]; + + owner.backend->RightMouseDown(theEvent); +} + - (void) mouseDragged: (NSEvent *) theEvent { owner.backend->MouseMove(theEvent); @@ -380,10 +402,14 @@ static NSCursor *cursorFromEnum(Window::Cursor cursor) */ - (NSMenu*) menuForEvent: (NSEvent*) theEvent { - if (![mOwner respondsToSelector: @selector(menuForEvent:)]) + NSMenu *menu = [mOwner menuForEvent: theEvent]; + if (menu) { + return menu; + } else if (mOwner.backend->ShouldDisplayPopupOnText()) { return mOwner.backend->CreateContextMenu(theEvent); - else - return [mOwner menuForEvent: theEvent]; + } else { + return nil; + } } //-------------------------------------------------------------------------------------------------- |