4
4
// Author: David Elliott
5
5
// Modified by: Mark Oxenham
6
6
// Created: 2003/03/16
7
// RCS-ID: $Id: textctrl.mm 48754 2007-09-17 16:43:30Z DE $
7
// RCS-ID: $Id: textctrl.mm 50334 2007-11-30 05:08:21Z DE $
8
8
// Copyright: (c) 2003 David Elliott
9
9
// Licence: wxWidgets licence
10
10
/////////////////////////////////////////////////////////////////////////////
21
21
#include "wx/cocoa/string.h"
23
23
#include "wx/cocoa/autorelease.h"
24
#include "wx/cocoa/ObjcRef.h"
25
26
#import <Foundation/NSString.h>
26
27
#import <AppKit/NSTextField.h>
32
33
IMPLEMENT_DYNAMIC_CLASS(wxTextCtrl, wxTextCtrlBase)
33
34
BEGIN_EVENT_TABLE(wxTextCtrl, wxTextCtrlBase)
35
WX_IMPLEMENT_COCOA_OWNER(wxTextCtrl,NSTextField,NSControl,NSView)
37
// Replaced by special 2.8 code:
38
//WX_IMPLEMENT_COCOA_OWNER(wxTextCtrl,NSTextField,NSControl,NSView)
37
39
bool wxTextCtrl::Create(wxWindow *parent, wxWindowID winid,
38
40
const wxString& value,
39
41
const wxPoint& pos,
270
272
wxLogTrace(wxTRACE_COCOA_Window_Size,wxT("wxTextCtrl=%p::DoGetBestSize()==(%d,%d)"),this,size.x,size.y);
276
///////////////////////////////////////////////////////////////////////////
277
// Added within the 2.8 release cycle, just after 2.8.7:
279
@interface WXNSTextFieldDelegate : NSObject
283
- (void)controlTextDidChange:(NSNotification*)notification;
284
@end // @interface WXNSTextFieldDelegate : NSObject
286
WX_DECLARE_HASH_MAP(WX_NSTextField, wxTextCtrl*, wxPointerHash, wxPointerEqual, wxCocoaNSTextField_wxTextCtrl_Hash);
288
static wxCocoaNSTextField_wxTextCtrl_Hash sg_textField_textCtrl_hash;
289
static wxObjcAutoRefFromAlloc<WXNSTextFieldDelegate*> sg_cocoaDelegate([[WXNSTextFieldDelegate alloc] init]);
291
static inline wxTextCtrl* GetTextCtrlFromCocoaTextField(WX_NSTextField cocoaObjcClass)
293
wxCocoaNSTextField_wxTextCtrl_Hash::iterator iter = sg_textField_textCtrl_hash.find(cocoaObjcClass);
294
if(iter != sg_textField_textCtrl_hash.end())
299
void wxTextCtrl::SetNSTextField(WX_NSTextField cocoaObjcClass)
301
DisassociateNSTextField((WX_NSTextField)m_cocoaNSView);
304
sg_textField_textCtrl_hash.erase((WX_NSTextField)m_cocoaNSView);
305
[(WX_NSTextField)m_cocoaNSView setDelegate:nil];
307
SetNSControl(cocoaObjcClass);
308
AssociateNSTextField((WX_NSTextField)m_cocoaNSView);
311
sg_textField_textCtrl_hash.insert(wxCocoaNSTextField_wxTextCtrl_Hash::value_type((WX_NSTextField)m_cocoaNSView, this));
312
[(WX_NSTextField)m_cocoaNSView setDelegate:sg_cocoaDelegate];
316
inline void wxTextCtrl::CocoaNotification_controlTextDidChange(WX_NSNotification notification)
318
wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, GetId());
320
// See wxTextCtrlBase::SendTextUpdatedEvent for why we don't set the string.
321
//event.SetString(GetValue());
323
event.SetEventObject(this);
324
GetEventHandler()->ProcessEvent(event);
327
@implementation WXNSTextFieldDelegate : NSObject
329
- (void)controlTextDidChange:(NSNotification*)notification
331
wxTextCtrl *tc = GetTextCtrlFromCocoaTextField([notification object]);
333
tc->CocoaNotification_controlTextDidChange(notification);
337
@end // @implementation WXNSTextFieldDelegate : NSObject