]> git.saurik.com Git - wxWidgets.git/blame - src/osx/cocoa/textctrl.mm
fix MSVC warnings about possibly uninitialized variables; some reindentation
[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
4dd9fdf8
SC
54+ (void)initialize
55{
56 static BOOL initialized = NO;
57 if (!initialized)
58 {
59 initialized = YES;
60 wxOSXCocoaClassAddWXMethods( self );
61 }
62}
dbeddfb9 63
ffad7b0d
SC
64- (id)initWithFrame:(NSRect)frame
65{
66 [super initWithFrame:frame];
ffad7b0d
SC
67 [self setDelegate: self];
68 [self setTarget: self];
69// [self setAction: @selector(enterAction:)];
70 return self;
71}
72
dbeddfb9
SC
73// use our common calls
74- (void) setTitle:(NSString *) title
75{
76 [self setStringValue: title];
77}
ffad7b0d
SC
78/*
79- (void)controlTextDidChange:(NSNotification *)aNotification
80{
81 if ( impl )
82 {
83 wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
84 if ( wxpeer ) {
85 wxCommandEvent event(wxEVT_COMMAND_TEXT_UPDATED, wxpeer->GetId());
86 event.SetEventObject( wxpeer );
87 event.SetString( static_cast<wxTextCtrl*>(wxpeer)->GetValue() );
88 wxpeer->HandleWindowEvent( event );
89 }
90 }
91}
dbeddfb9 92
ffad7b0d
SC
93- (void)controlTextDidEndEditing:(NSNotification *)aNotification
94{
95 if ( impl )
96 {
97 wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
98 if ( wxpeer ) {
99 wxFocusEvent event(wxEVT_KILL_FOCUS, wxpeer->GetId());
100 event.SetEventObject( wxpeer );
101 event.SetWindow( wxpeer );
102 wxpeer->HandleWindowEvent( event );
103 }
104 }
105}
106
107- (void) enterAction: (id) sender
108{
109 if ( impl )
110 {
111 wxWindow* wxpeer = (wxWindow*) impl->GetWXPeer();
112 if ( wxpeer && (wxpeer->GetWindowStyle() & wxTE_PROCESS_ENTER) ) {
113 wxCommandEvent event(wxEVT_COMMAND_TEXT_ENTER, wxpeer->GetId());
114 event.SetEventObject( wxpeer );
115 event.SetString( static_cast<wxTextCtrl*>(wxpeer)->GetValue() );
116 wxpeer->HandleWindowEvent( event );
117 }
118 }
119}
120*/
dbeddfb9
SC
121@end
122
1e181c7a
SC
123wxNSTextFieldControl::wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ) : wxWidgetCocoaImpl(wxPeer, w)
124{
125}
126
127wxNSTextFieldControl::~wxNSTextFieldControl()
128{
129}
130
131wxString wxNSTextFieldControl::GetStringValue() const
132{
133 wxCFStringRef cf( (CFStringRef) [[(wxNSTextField*) m_osxView stringValue] retain] );
134 return cf.AsString(m_wxPeer->GetFont().GetEncoding());
135}
136void wxNSTextFieldControl::SetStringValue( const wxString &str)
137{
138 [(wxNSTextField*) m_osxView setStringValue: wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
139}
140void wxNSTextFieldControl::Copy()
141{
142}
143
144void wxNSTextFieldControl::Cut()
145{
146}
147
148void wxNSTextFieldControl::Paste()
149{
150}
151
152bool wxNSTextFieldControl::CanPaste() const
153{
154 return false;
155}
156
157void wxNSTextFieldControl::SetEditable(bool editable)
158{
0c530e5a 159 [(wxNSTextField*) m_osxView setEditable:editable];
1e181c7a
SC
160}
161
162void wxNSTextFieldControl::GetSelection( long* from, long* to) const
163{
164}
165
166void wxNSTextFieldControl::SetSelection( long from , long to )
167{
168}
169
170void wxNSTextFieldControl::WriteText(const wxString& str)
171{
172 // temp hack to get logging working early
173 wxString former = GetStringValue();
174 SetStringValue( former + str );
175}
dbeddfb9
SC
176
177wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
178 wxWindowMac* parent,
179 wxWindowID id,
180 const wxString& str,
181 const wxPoint& pos,
182 const wxSize& size,
183 long style,
184 long extraStyle)
185{
dbeddfb9
SC
186 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
187 wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
b15f9375
SC
188
189 if ( style & wxNO_BORDER )
190 {
191 [v setBezeled:NO];
192 [v setBordered:NO];
193 }
dbeddfb9
SC
194
195 //[v setBezeled:NO];
196 //[v setEditable:NO];
197 //[v setDrawsBackground:NO];
198
199 wxWidgetCocoaImpl* c = new wxNSTextFieldControl( wxpeer, v );
dbeddfb9
SC
200 return c;
201}
202
203
204#endif // wxUSE_TEXTCTRL