aboutsummaryrefslogtreecommitdiffhomepage
path: root/cocoa/ScintillaCocoa.mm
diff options
context:
space:
mode:
authornyamatongwe <nyamatongwe@gmail.com>2013-09-18 10:40:53 +1000
committernyamatongwe <nyamatongwe@gmail.com>2013-09-18 10:40:53 +1000
commit59b95105a1e71ad6b62a1970e88a0390850e5bfe (patch)
treeb2b837ef548ae7550d9e0bafb68ad50dcddd3f3c /cocoa/ScintillaCocoa.mm
parentc7eca832e818dbaa7180822fdea6f3aabcd83a32 (diff)
downloadscintilla-mirror-59b95105a1e71ad6b62a1970e88a0390850e5bfe.tar.gz
Reimplement notifications from ScintillaCocoa to ScintillaView as a delegate relationship
using ScintillaNotificationProtocol. Add optional command:idFrom: method to ScintillaNotificationProtocol for command notifications. In a future version registerNotifyCallback: and ScintillaCocoa::RegisterNotifyCallback will be deprecated.
Diffstat (limited to 'cocoa/ScintillaCocoa.mm')
-rw-r--r--cocoa/ScintillaCocoa.mm34
1 files changed, 30 insertions, 4 deletions
diff --git a/cocoa/ScintillaCocoa.mm b/cocoa/ScintillaCocoa.mm
index 07f29bd8e..ce1042e9b 100644
--- a/cocoa/ScintillaCocoa.mm
+++ b/cocoa/ScintillaCocoa.mm
@@ -384,6 +384,8 @@ ScintillaCocoa::ScintillaCocoa(InnerView* view, MarginView* viewMargin)
wMargin = viewMargin;
timerTarget = [[TimerTarget alloc] init: this];
lastMouseEvent = NULL;
+ delegate = NULL;
+ delegateHasCommand = false;
notifyObj = NULL;
notifyProc = NULL;
capturedMouse = false;
@@ -1652,6 +1654,26 @@ void ScintillaCocoa::UpdateForScroll() {
//--------------------------------------------------------------------------------------------------
/**
+ * Register a delegate that will be called for notifications and commands.
+ * This provides similar functionality to RegisterNotifyCallback but in an
+ * Objective C way.
+ *
+ * @param delegate_ A pointer to an object that implements ScintillaNotificationProtocol.
+ */
+
+void ScintillaCocoa::SetDelegate(id<ScintillaNotificationProtocol> delegate_)
+{
+ delegate = delegate_;
+ delegateHasCommand = false;
+ if (delegate)
+ {
+ delegateHasCommand = [(id)delegate respondsToSelector: @selector(command:ctrlID:)];
+ }
+}
+
+//--------------------------------------------------------------------------------------------------
+
+/**
* Used to register a callback function for a given window. This is used to emulate the way
* Windows notifies other controls (mainly up in the view hierarchy) about certain events.
*
@@ -1673,6 +1695,8 @@ void ScintillaCocoa::NotifyChange()
if (notifyProc != NULL)
notifyProc(notifyObj, WM_COMMAND, Platform::LongFromTwoShorts(GetCtrlID(), SCEN_CHANGE),
(uintptr_t) this);
+ if (delegateHasCommand)
+ [delegate command:SCEN_CHANGE idFrom:GetCtrlID()];
}
//--------------------------------------------------------------------------------------------------
@@ -1682,6 +1706,8 @@ void ScintillaCocoa::NotifyFocus(bool focus)
if (notifyProc != NULL)
notifyProc(notifyObj, WM_COMMAND, Platform::LongFromTwoShorts(GetCtrlID(), (focus ? SCEN_SETFOCUS : SCEN_KILLFOCUS)),
(uintptr_t) this);
+ if (delegateHasCommand)
+ [delegate command:(focus ? SCEN_SETFOCUS : SCEN_KILLFOCUS) idFrom:GetCtrlID()];
}
//--------------------------------------------------------------------------------------------------
@@ -1694,12 +1720,12 @@ void ScintillaCocoa::NotifyFocus(bool focus)
*/
void ScintillaCocoa::NotifyParent(SCNotification scn)
{
+ scn.nmhdr.hwndFrom = (void*) this;
+ scn.nmhdr.idFrom = GetCtrlID();
if (notifyProc != NULL)
- {
- scn.nmhdr.hwndFrom = (void*) this;
- scn.nmhdr.idFrom = GetCtrlID();
notifyProc(notifyObj, WM_NOTIFY, GetCtrlID(), (uintptr_t) &scn);
- }
+ if (delegate)
+ [delegate notification:&scn];
}
//--------------------------------------------------------------------------------------------------