]> git.saurik.com Git - wxWidgets.git/blob - utils/wxPython/modules/lseditor/lseditorpl.cpp
wizard.h added to the list of headers
[wxWidgets.git] / utils / wxPython / modules / lseditor / lseditorpl.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: lseditorpl.cpp
3 // Purpose: Language-sensative editor plugin for wxStudio
4 // Copyright: (c) Aleksandars Gluchovas
5 // Modified by:
6 // Created: 11/04/1999
7 // RCS-ID: $Id$
8 // Copyright: (c) Aleskandars Gluchovas
9 // Licence: GNU General Public License
10 /////////////////////////////////////////////////////////////////////////////
11 //
12 // This program is free software; you can redistribute it and/or modify
13 // it under the terms of the GNU General Public License as published by
14 // the Free Software Foundation; either version 2 of the License, or
15 // (at your option) any later version.
16 //
17 // This program is distributed in the hope that it will be useful,
18 // but WITHOUT ANY WARRANTY; without even the implied warranty of
19 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 // GNU General Public License for more details.
21 //
22 // You should have received a copy of the GNU General Public License
23 // along with this program; if not, write to the Free Software
24 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 /////////////////////////////////////////////////////////////////////////////
26
27
28 // For compilers that support precompilation, includes "wx/wx.h".
29 #include "wx/wxprec.h"
30
31 #ifdef __BORLANDC__
32 #pragma hdrstop
33 #endif
34
35 #ifndef WX_PRECOMP
36 #include "wx/wx.h"
37 #endif
38
39
40 #include "lseditorpl.h"
41 #include "tdefs.h"
42
43 /***** Impelmentation for class wxsLSEditorPlugin *****/
44
45 wxsLSEditorPlugin::wxsLSEditorPlugin()
46
47 : mpModel( NULL ),
48 mpView( NULL )
49 {}
50
51 wxsLSEditorPlugin::~wxsLSEditorPlugin()
52 {
53 // view is destroyed by wxWindows along
54 // with it's owned model
55 }
56
57 void wxsLSEditorPlugin::Create( wxWindow* parent, wxWindowID id )
58 {
59 mpModel = new wxTextEditorModel();
60
61 mpView = new wxTextEditorView( parent, id, mpModel );
62
63 mpModel->AddView( mpView );
64 mpView->Activate();
65
66 mpView->AddPinPainter( new TBreakpointPainter() );
67
68 mpView->SyncScrollbars();
69 }
70
71 void wxsLSEditorPlugin::OnOpen( const string& fname )
72 {
73 mpModel->LoadTextFromFile( fname );
74
75 SetFileName( fname );
76 }
77
78 void wxsLSEditorPlugin::OnSave( const string& fname )
79 {
80 mpModel->SaveTextToFile( fname );
81 }
82
83 void wxsLSEditorPlugin::OnCopy()
84 {
85 mpModel->OnCopy();
86 }
87
88 void wxsLSEditorPlugin::OnCut()
89 {
90 mpModel->OnCut();
91 }
92
93 void wxsLSEditorPlugin::OnPaste()
94 {
95 mpModel->OnPaste();
96 }
97
98 void wxsLSEditorPlugin::OnDelete()
99 {
100 mpModel->OnDelete();
101 }
102
103 void wxsLSEditorPlugin::OnUndo()
104 {
105 mpModel->OnUndo();
106 }
107
108 void wxsLSEditorPlugin::OnRedo()
109 {
110 mpModel->OnRedo();
111 }
112
113 void wxsLSEditorPlugin::SelectAll()
114 {
115 mpModel->OnSelectAll();
116 }
117
118 void wxsLSEditorPlugin::OnGotoLine()
119 {
120 mpModel->OnGotoLine();
121 }
122
123 void wxsLSEditorPlugin::OnGotoLine( int lineNo, int column )
124 {
125 mpModel->ResetSelection();
126 mpModel->OnGotoLine( lineNo, column );
127 }
128
129 void wxsLSEditorPlugin::OnProperties()
130 {
131 // not impl.
132 }
133
134 void wxsLSEditorPlugin::OnFind()
135 {
136 mpModel->OnFind();
137 }
138
139 void wxsLSEditorPlugin::OnFindNext()
140 {
141 mpModel->OnFindNext();
142 }
143
144 void wxsLSEditorPlugin::OnFindPrevious()
145 {
146 mpModel->OnFindPrevious();
147 }
148
149 void wxsLSEditorPlugin::OnReplace()
150 {
151 // not impl.
152 }
153
154 void wxsLSEditorPlugin::OnToggleBookmark()
155 {
156 mpModel->OnToggleBookmark();
157 }
158
159 void wxsLSEditorPlugin::OnNextBookmark()
160 {
161 mpModel->OnNextBookmark();
162 }
163
164 void wxsLSEditorPlugin::OnPreviousBookmark()
165 {
166 mpModel->OnPreviousBookmark();
167 }
168
169 void wxsLSEditorPlugin::OnShowBookmarks()
170 {
171 // not impl.
172 }
173
174 void wxsLSEditorPlugin::SetCheckpoint()
175 {
176 mpModel->SetCheckpoint();
177 }
178
179 bool wxsLSEditorPlugin::CheckpointModified()
180 {
181 return mpModel->CheckpointModified();
182 }
183
184 // UI-updates
185
186 bool wxsLSEditorPlugin::CanCopy()
187 {
188 return mpModel->CanCopy();
189 }
190
191 bool wxsLSEditorPlugin::CanCut()
192 {
193 return mpModel->CanCopy();
194 }
195
196 bool wxsLSEditorPlugin::CanPaste()
197 {
198 return mpModel->CanPaste();
199 }
200
201 bool wxsLSEditorPlugin::CanUndo()
202 {
203 return mpModel->CanUndo();
204 }
205
206 bool wxsLSEditorPlugin::CanRedo()
207 {
208 return mpModel->CanRedo();
209 }
210
211 // accesed by framework
212
213 bool wxsLSEditorPlugin::IsModified()
214 {
215 return mpModel->IsModified();
216 }
217
218 wxWindow* wxsLSEditorPlugin::GetWindow()
219 {
220 return mpView;
221 }
222
223 void wxsLSEditorPlugin::GetAllText( char** ppBuf, size_t* length )
224 {
225 mpModel->GetAllText( ppBuf, *length );
226 }
227
228 void wxsLSEditorPlugin::SetFileName( const string& fname )
229 {
230 mFileName = fname;
231
232 if ( mpView )
233
234 mpView->SetName( fname );
235 }
236
237 void wxsLSEditorPlugin::HoldCursor( bool hold )
238 {
239 mpView->HoldCursor( hold );
240 }
241
242 string wxsLSEditorPlugin::FindWordAtCursor()
243 {
244 mpModel->OnSelectWord();
245
246 char* buf = NULL; size_t len = 0;
247
248 mpModel->GetSelection( &buf, len );
249
250 if ( buf )
251 {
252 string word = string( buf, 0, len );
253 delete [] buf;
254 return word;
255 }
256 else
257 return "";
258 }
259
260 void wxsLSEditorPlugin::GetCursorPos( int* line, int* column )
261 {
262 TPosition pos = mpModel->GetCursor();
263
264 *line = (int)pos.mRow;
265 *column = (int)pos.mCol;
266 }
267
268 void wxsLSEditorPlugin::SetCursorPos( int line, int column )
269 {
270 mpModel->OnGotoLine( line, column );
271 }
272
273 void wxsLSEditorPlugin::GetPagePos( int* line, int* column )
274 {
275 TPosition pos = mpView->GetPagePos();
276
277 *line = pos.mRow;
278 *column = pos.mCol;
279 }
280
281 void wxsLSEditorPlugin::GetText( int fromLine, int fromColumn,
282 int tillLine, int tillColumn,
283 char** ppBuf, size_t* length )
284 {
285 mpModel->GetTextFromRange( TPosition( fromLine, fromColumn ),
286 TPosition( tillLine, tillColumn ),
287 ppBuf, *length );
288 }
289
290 void wxsLSEditorPlugin::InsertText( int line, int column,
291 char* text, size_t lenght )
292 {
293 mpModel->InsertText( TPosition( line, column ),
294 text, lenght );
295 }
296
297 void wxsLSEditorPlugin::DeleteText( int fromLine, int fromColumn,
298 int tillLine, int tillColumn )
299 {
300 mpModel->DeleteRange( TPosition( fromLine, fromColumn ),
301 TPosition( tillLine, tillColumn ) );
302 }
303
304 void wxsLSEditorPlugin::PositionToXY( int line, int column, int* x, int* y )
305 {
306 TPosition scrPos;
307
308 mpView->TextPosToScreenPos( TPosition( line, column ), scrPos );
309 mpView->ScreenPosToPixels( scrPos, *x, *y );
310
311 *y += mpView->mCharDim.y; // lower-right corner
312 }
313
314 void wxsLSEditorPlugin::GetSelectionRange( int* fromLine, int* fromColumn,
315 int* tillLine, int* tillColumn )
316 {
317 TPosition start = mpModel->GetStartOfSelection();
318 TPosition end = mpModel->GetEndOfSelection();
319
320 *fromLine = (int)start.mRow;
321 *fromColumn = (int)start.mCol;
322 *tillLine = (int)end.mRow;
323 *tillColumn = (int)end.mCol;
324 }
325
326 wxSize wxsLSEditorPlugin::GetCharacterSize()
327 {
328 return mpView->GetCharacterSize();
329 }
330
331 bool wxsLSEditorPlugin::IsUnixText()
332 {
333 return mpModel->IsUnixText();
334 }
335
336 wxTextEditorModel& wxsLSEditorPlugin::GetModel()
337 {
338 return *mpModel;
339 }
340
341 wxTextEditorView& wxsLSEditorPlugin::GetView()
342 {
343 return *mpView;
344 }