]> git.saurik.com Git - wxWidgets.git/blob - src/osx/cocoa/textctrl.mm
Compilo for wxMac
[wxWidgets.git] / src / osx / cocoa / textctrl.mm
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"
50 #include "wx/osx/carbon/private/mactext.h"
51
52
53 @implementation wxNSTextField
54
55 - (void)setImplementation: (wxWidgetImpl *) theImplementation
56 {
57 impl = theImplementation;
58 }
59
60 - (wxWidgetImpl*) implementation
61 {
62 return impl;
63 }
64
65 - (BOOL) isFlipped
66 {
67 return YES;
68 }
69
70 // use our common calls
71 - (void) setTitle:(NSString *) title
72 {
73 [self setStringValue: title];
74 }
75
76 @end
77
78 class wxNSTextFieldControl : public wxMacTextControl
79 {
80 public :
81 wxNSTextFieldControl( wxTextCtrl *wxPeer, WXWidget w ) : wxMacTextControl(wxPeer, w)
82 {
83 }
84 virtual ~wxNSTextFieldControl()
85 {
86 }
87
88 virtual void VisibilityChanged(bool shown){}
89 virtual wxString GetStringValue() const
90 {
91 wxCFStringRef cf( (CFStringRef) [[(wxNSTextField*) m_osxView stringValue] retain] );
92 return cf.AsString(m_wxPeer->GetFont().GetEncoding());
93 }
94 virtual void SetStringValue( const wxString &str)
95 {
96 [(wxNSTextField*) m_osxView setStringValue: wxCFStringRef( str , m_wxPeer->GetFont().GetEncoding() ).AsNSString()];
97 }
98 virtual void Copy() {}
99 virtual void Cut() {}
100 virtual void Paste() {}
101 virtual bool CanPaste() const { return false;}
102 virtual void SetEditable(bool editable) {}
103 virtual void GetSelection( long* from, long* to) const {}
104 virtual void SetSelection( long from , long to ){}
105 virtual void WriteText(const wxString& str)
106 {
107 // temp hack to get logging working early
108 wxString former = GetStringValue();
109 SetStringValue( former + str );
110 }
111 };
112
113 wxWidgetImplType* wxWidgetImpl::CreateTextControl( wxTextCtrl* wxpeer,
114 wxWindowMac* parent,
115 wxWindowID id,
116 const wxString& str,
117 const wxPoint& pos,
118 const wxSize& size,
119 long style,
120 long extraStyle)
121 {
122 NSView* sv = (wxpeer->GetParent()->GetHandle() );
123
124 NSRect r = wxOSXGetFrameForControl( wxpeer, pos , size ) ;
125 wxNSTextField* v = [[wxNSTextField alloc] initWithFrame:r];
126 [sv addSubview:v];
127
128 //[v setBezeled:NO];
129 //[v setEditable:NO];
130 //[v setDrawsBackground:NO];
131
132 wxWidgetCocoaImpl* c = new wxNSTextFieldControl( wxpeer, v );
133 [v setImplementation:c];
134 return c;
135 }
136
137
138 #endif // wxUSE_TEXTCTRL