diff options
Diffstat (limited to 'cocoa')
-rw-r--r-- | cocoa/PlatCocoa.mm | 83 |
1 files changed, 61 insertions, 22 deletions
diff --git a/cocoa/PlatCocoa.mm b/cocoa/PlatCocoa.mm index 7a65d3d41..0e311126e 100644 --- a/cocoa/PlatCocoa.mm +++ b/cocoa/PlatCocoa.mm @@ -1385,7 +1385,9 @@ static NSImage* ImageFromXPM(XPM* pxpm) namespace { -// unnamed namespace hides IListBox interface +// Unnamed namespace hides local IListBox interface. +// IListBox is used to cross languages to send events from Objective C++ +// AutoCompletionDelegate and AutoCompletionDataSource to C++ ListBoxImpl. class IListBox { public: @@ -1393,19 +1395,44 @@ public: virtual NSImage* ImageForRow(NSInteger row) = 0; virtual NSString* TextForRow(NSInteger row) = 0; virtual void DoubleClick() = 0; + virtual void SelectionChange() = 0; }; -} // unnamed namespace +} + +//----------------- AutoCompletionDelegate --------------------------------------------------------- + +// AutoCompletionDelegate is an Objective C++ class so it can implement +// NSTableViewDelegate and receive tableViewSelectionDidChange events. + +@interface AutoCompletionDelegate : NSObject <NSTableViewDelegate> { + IListBox *box; +} + +@property IListBox *box; + +@end + +@implementation AutoCompletionDelegate + +@synthesize box; + +- (void) tableViewSelectionDidChange: (NSNotification *) notification { +#pragma unused(notification) + if (box) { + box->SelectionChange(); + } +} + +@end //----------------- AutoCompletionDataSource ------------------------------------------------------- -@interface AutoCompletionDataSource : -NSObject -#if MAC_OS_X_VERSION_MAX_ALLOWED > MAC_OS_X_VERSION_10_5 -<NSTableViewDataSource> -#endif -{ - IListBox* box; +// AutoCompletionDataSource provides data to display in the list box. +// It is also the target of the NSTableView so it receives double clicks. + +@interface AutoCompletionDataSource : NSObject <NSTableViewDataSource> { + IListBox *box; } @property IListBox* box; @@ -1535,10 +1562,10 @@ private: NSTableColumn* colIcon; NSTableColumn* colText; AutoCompletionDataSource* ds; + AutoCompletionDelegate *acd; LinesData ld; - CallBackAction doubleClickAction; - void* doubleClickActionData; + IListBoxDelegate *delegate; public: ListBoxImpl() : @@ -1555,8 +1582,8 @@ public: colIcon(nil), colText(nil), ds(nil), - doubleClickAction(nullptr), - doubleClickActionData(nullptr) + acd(nil), + delegate(nullptr) { images = [[NSMutableDictionary alloc] init]; } @@ -1582,10 +1609,8 @@ public: void RegisterImage(int type, const char* xpm_data) override; void RegisterRGBAImage(int type, int width, int height, const unsigned char *pixelsImage) override; void ClearRegisteredImages() override; - void SetDoubleClickAction(CallBackAction action, void* data) override - { - doubleClickAction = action; - doubleClickActionData = data; + void SetDelegate(IListBoxDelegate *lbDelegate) override { + delegate = lbDelegate; } void SetList(const char* list, char separator, char typesep) override; @@ -1597,6 +1622,7 @@ public: NSImage* ImageForRow(NSInteger row) override; NSString* TextForRow(NSInteger row) override; void DoubleClick() override; + void SelectionChange() override; }; void ListBoxImpl::Create(Window& /*parent*/, int /*ctrlID*/, Scintilla::Point pt, @@ -1634,6 +1660,9 @@ void ListBoxImpl::Create(Window& /*parent*/, int /*ctrlID*/, Scintilla::Point pt ds = [[AutoCompletionDataSource alloc] init]; [ds setBox:this]; [table setDataSource: ds]; // Weak reference + acd = [[AutoCompletionDelegate alloc] init]; + [acd setBox: this]; + [table setDelegate: acd]; [scroller setAutoresizingMask: NSViewWidthSizable | NSViewHeightSizable]; [[winLB contentView] addSubview: scroller]; @@ -1722,6 +1751,8 @@ void ListBoxImpl::ReleaseViews() colIcon = nil; [colText release ]; colText = nil; + [acd release]; + acd = nil; [ds release]; ds = nil; } @@ -1875,11 +1906,17 @@ NSString* ListBoxImpl::TextForRow(NSInteger row) return sTitle; } -void ListBoxImpl::DoubleClick() -{ - if (doubleClickAction) - { - doubleClickAction(doubleClickActionData); +void ListBoxImpl::DoubleClick() { + if (delegate) { + ListBoxEvent event(ListBoxEvent::EventType::doubleClick); + delegate->ListNotify(&event); + } +} + +void ListBoxImpl::SelectionChange() { + if (delegate) { + ListBoxEvent event(ListBoxEvent::EventType::selectionChange); + delegate->ListNotify(&event); } } @@ -1887,6 +1924,8 @@ void ListBoxImpl::DoubleClick() //----------------- ListBox ------------------------------------------------------------------------ +// ListBox is implemented by the ListBoxImpl class. + ListBox::ListBox() { } |