]> git.saurik.com Git - wxWidgets.git/blame - src/osx/cocoa/textctrl.mm
bring in the definition of wxSizer, making non-precomp builds working again after...
[wxWidgets.git] / src / osx / cocoa / textctrl.mm
CommitLineData
dbeddfb9
SC
1/////////////////////////////////////////////////////////////////////////////
2// Name: src/osx/cocoa/textctrl.mm
3// Purpose: wxTextCtrl
4// Author: Stefan Csomor
5// Modified by: Ryan Norton (MLTE GetLineLength and GetLineText)
6// Created: 1998-01-01
7// RCS-ID: $Id: textctrl.cpp 54820 2008-07-29 20:04:11Z SC $
8// Copyright: (c) Stefan Csomor
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#include "wx/wxprec.h"
13
14#if wxUSE_TEXTCTRL
15
16#include "wx/textctrl.h"
17
18#ifndef WX_PRECOMP
19 #include "wx/intl.h"
20 #include "wx/app.h"
21 #include "wx/utils.h"
22 #include "wx/dc.h"
23 #include "wx/button.h"
24 #include "wx/menu.h"
25 #include "wx/settings.h"
26 #include "wx/msgdlg.h"
27 #include "wx/toplevel.h"
28#endif
29
30#ifdef __DARWIN__
31 #include <sys/types.h>
32 #include <sys/stat.h>
33#else
34 #include <stat.h>
35#endif
36
37#if wxUSE_STD_IOSTREAM
38 #if wxUSE_IOSTREAMH
39 #include <fstream.h>
40 #else
41 #include <fstream>
42 #endif
43#endif
44
45#include "wx/filefn.h"
46#include "wx/sysopt.h"
47#include "wx/thread.h"
48
49#include "wx/osx/private.h"
1e181c7a 50#include "wx/osx/cocoa/private/textimpl.h"
dbeddfb9
SC
51
52@implementation wxNSTextField
53
b466e85a 54WXCOCOAIMPL_COMMON_IMPLEMENTATION
dbeddfb9 55
ffad7b0d
SC
56- (id)initWithFrame:(NSRect)frame
57{
58 [super initWithFrame:frame];
59 impl = NULL;
60 [self setDelegate: self];
61 [self setTarget: self];
62// [self setAction: @selector(enterAction:)];
63 return self;
64}
65
dbeddfb9
SC
66// use our common calls
67- (void) setTitle:(NSString *) title
68{
69 [self setStringValue: title];
70}
ffad7b0d
SC
71/*
72- (void)controlTextDidChange:(NSNotification *)aNotification
73{
74 if ( impl )
75 {
76 wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
77 if ( wxpeer ) {
78 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, wxpeer->GetId());
79 event.SetEventObject( wxpeer );
80 event.SetString( static_cast<wxTextCtrl*>(wxpeer)->GetValue() );
81 wxpeer->HandleWindowEvent( event );
82 }
83 }
84}
dbeddfb9 85
ffad7b0d
SC
86- (void)controlTextDidEndEditing:(NSNotification *)aNotification
87{
88 if ( impl )
89 {
90 wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
91 if ( wxpeer ) {
92 wxFocusEvent event(wxEVT_KILL_FOCUS, wxpeer->GetId());
93 event.SetEventObject( wxpeer );
94 event.SetWindow( wxpeer );
95 wxpeer->HandleWindowEvent( event );
96 }
97 }
98}
99
100- (void) enterAction: (id) sender
101{
102 if ( impl )
103 {
104 wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
105 if ( wxpeer && (wxpeer->GetWindowStyle() & wxTE_PROCESS_ENTER) ) {
106 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, wxpeer->GetId());
107 event.SetEventObject( wxpeer );
108 event.SetString( static_cast<wxTextCtrl*>(wxpeer)->GetValue() );
109 wxpeer->HandleWindowEvent( event );
110 }
111 }
112}
113*/
dbeddfb9
SC
114@end
115
1e181c7a
SC
116wxNSTextFieldControl::wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w)
117{
118}
119
120wxNSTextFieldControl::~wxNSTextFieldControl()
121{
122}
123
124wxString wxNSTextFieldControl::GetStringValue() const
125{
126 wxCFStringRef cf( (CFStringRef) [[(wxNSTextField*) m_osxView stringValue] retain] );
127 return cf.AsString(m_wxPeer->GetFont().GetEncoding());
128}
129void wxNSTextFieldControl::SetStringValue( const wxString &str)
130{
131 [(wxNSTextField*) m_osxView setStringValue: wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
132}
133void wxNSTextFieldControl::Copy()
134{
135}
136
137void wxNSTextFieldControl::Cut()
138{
139}
140
141void wxNSTextFieldControl::Paste()
142{
143}
144
145bool wxNSTextFieldControl::CanPaste() const
146{
147 return false;
148}
149
150void wxNSTextFieldControl::SetEditable(bool editable)
151{
0c530e5a 152 [(wxNSTextField*) m_osxView setEditable:editable];
1e181c7a
SC
153}
154
155void wxNSTextFieldControl::GetSelection( long* from, long* to) const
156{
157}
158
159void wxNSTextFieldControl::SetSelection( long from , long to )
160{
161}
162
163void wxNSTextFieldControl::WriteText(const wxString& str)
164{
165 // temp hack to get logging working early
166 wxString former = GetStringValue();
167 SetStringValue( former + str );
168}
dbeddfb9
SC
169
170wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
171 wxWindowMac* parent,
172 wxWindowID id,
173 const wxString& str,
174 const wxPoint& pos,
175 const wxSize& size,
176 long style,
177 long extraStyle)
178{
dbeddfb9
SC
179 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
180 wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
b15f9375
SC
181
182 if ( style & wxNO_BORDER )
183 {
184 [v setBezeled:NO];
185 [v setBordered:NO];
186 }
dbeddfb9
SC
187
188 //[v setBezeled:NO];
189 //[v setEditable:NO];
190 //[v setDrawsBackground:NO];
191
192 wxWidgetCocoaImpl* c = new wxNSTextFieldControl( wxpeer, v );
193 [v setImplementation:c];
194 return c;
195}
196
197
198#endif // wxUSE_TEXTCTRL