Implement text update events so the spin control works better.
Copyright 2007 Software 2000 Ltd. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@50334 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -51,6 +51,11 @@ public:
|
||||
protected:
|
||||
virtual void Cocoa_didChangeText(void);
|
||||
virtual void CocoaTarget_action(void);
|
||||
public: // We can't make an Objective-C class or method a friend
|
||||
// These are the new (non-virtual for ABI compatibility) messages:
|
||||
void CocoaNotification_controlTextDidChange(WX_NSNotification notification);
|
||||
void CocoaNotification_controlTextDidEndEditing(WX_NSNotification notification);
|
||||
void CocoaNotification_controlTextDidBeginEditing(WX_NSNotification notification);
|
||||
// ------------------------------------------------------------------------
|
||||
// Implementation
|
||||
// ------------------------------------------------------------------------
|
||||
|
@@ -21,6 +21,7 @@
|
||||
#include "wx/cocoa/string.h"
|
||||
|
||||
#include "wx/cocoa/autorelease.h"
|
||||
#include "wx/cocoa/ObjcRef.h"
|
||||
|
||||
#import <Foundation/NSString.h>
|
||||
#import <AppKit/NSTextField.h>
|
||||
@@ -32,8 +33,9 @@
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase)
|
||||
BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase)
|
||||
END_EVENT_TABLE()
|
||||
WX_IMPLEMENT_COCOA_OWNER(wxTextCtrl,NSTextField,NSControl,NSView)
|
||||
|
||||
// Replaced by special 2.8 code:
|
||||
//WX_IMPLEMENT_COCOA_OWNER(wxTextCtrl,NSTextField,NSControl,NSView)
|
||||
bool wxTextCtrl::Create(wxWindow *parent, wxWindowID winid,
|
||||
const wxString& value,
|
||||
const wxPoint& pos,
|
||||
@@ -270,3 +272,67 @@ wxSize wxTextCtrl::DoGetBestSize() const
|
||||
wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxTextCtrl=%p::DoGetBestSize()==(%d,%d)"),this,size.x,size.y);
|
||||
return size;
|
||||
}
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
// Added within the 2.8 release cycle, just after 2.8.7:
|
||||
|
||||
@interface WXNSTextFieldDelegate : NSObject
|
||||
{
|
||||
}
|
||||
|
||||
- (void)controlTextDidChange:(NSNotification*)notification;
|
||||
@end // @interface WXNSTextFieldDelegate : NSObject
|
||||
|
||||
WX_DECLARE_HASH_MAP(WX_NSTextField, wxTextCtrl*, wxPointerHash, wxPointerEqual, wxCocoaNSTextField_wxTextCtrl_Hash);
|
||||
|
||||
static wxCocoaNSTextField_wxTextCtrl_Hash sg_textField_textCtrl_hash;
|
||||
static wxObjcAutoRefFromAlloc<WXNSTextFieldDelegate*> sg_cocoaDelegate([[WXNSTextFieldDelegate alloc] init]);
|
||||
|
||||
static inline wxTextCtrl* GetTextCtrlFromCocoaTextField(WX_NSTextField cocoaObjcClass)
|
||||
{
|
||||
wxCocoaNSTextField_wxTextCtrl_Hash::iterator iter = sg_textField_textCtrl_hash.find(cocoaObjcClass);
|
||||
if(iter != sg_textField_textCtrl_hash.end())
|
||||
return iter->second;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void wxTextCtrl::SetNSTextField(WX_NSTextField cocoaObjcClass)
|
||||
{
|
||||
DisassociateNSTextField((WX_NSTextField)m_cocoaNSView);
|
||||
if(m_cocoaNSView)
|
||||
{
|
||||
sg_textField_textCtrl_hash.erase((WX_NSTextField)m_cocoaNSView);
|
||||
[(WX_NSTextField)m_cocoaNSView setDelegate:nil];
|
||||
}
|
||||
SetNSControl(cocoaObjcClass);
|
||||
AssociateNSTextField((WX_NSTextField)m_cocoaNSView);
|
||||
if(m_cocoaNSView)
|
||||
{
|
||||
sg_textField_textCtrl_hash.insert(wxCocoaNSTextField_wxTextCtrl_Hash::value_type((WX_NSTextField)m_cocoaNSView, this));
|
||||
[(WX_NSTextField)m_cocoaNSView setDelegate:sg_cocoaDelegate];
|
||||
}
|
||||
}
|
||||
|
||||
inline void wxTextCtrl::CocoaNotification_controlTextDidChange(WX_NSNotification notification)
|
||||
{
|
||||
wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
|
||||
|
||||
// See wxTextCtrlBase::SendTextUpdatedEvent for why we don't set the string.
|
||||
//event.SetString(GetValue());
|
||||
|
||||
event.SetEventObject(this);
|
||||
GetEventHandler()->ProcessEvent(event);
|
||||
}
|
||||
|
||||
@implementation WXNSTextFieldDelegate : NSObject
|
||||
|
||||
- (void)controlTextDidChange:(NSNotification*)notification
|
||||
{
|
||||
wxTextCtrl *tc = GetTextCtrlFromCocoaTextField([notification object]);
|
||||
if(tc != NULL)
|
||||
tc->CocoaNotification_controlTextDidChange(notification);
|
||||
}
|
||||
|
||||
|
||||
@end // @implementation WXNSTextFieldDelegate : NSObject
|
||||
|
||||
|
Reference in New Issue
Block a user