]> git.saurik.com Git - wxWidgets.git/blame - utils/wxPython/modules/lseditor/lseditorpl.cpp
Prep for wxPython 2.1b3 release
[wxWidgets.git] / utils / wxPython / modules / lseditor / lseditorpl.cpp
CommitLineData
4b123bb9
HH
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
45wxsLSEditorPlugin::wxsLSEditorPlugin()
46
47 : mpModel( NULL ),
48 mpView( NULL )
49{}
50
51wxsLSEditorPlugin::~wxsLSEditorPlugin()
52{
53 // view is destroyed by wxWindows along
54 // with it's owned model
55}
56
57void 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
71void wxsLSEditorPlugin::OnOpen( const string& fname )
72{
73 mpModel->LoadTextFromFile( fname );
74
75 SetFileName( fname );
76}
77
78void wxsLSEditorPlugin::OnSave( const string& fname )
79{
80 mpModel->SaveTextToFile( fname );
81}
82
83void wxsLSEditorPlugin::OnCopy()
84{
85 mpModel->OnCopy();
86}
87
88void wxsLSEditorPlugin::OnCut()
89{
90 mpModel->OnCut();
91}
92
93void wxsLSEditorPlugin::OnPaste()
94{
95 mpModel->OnPaste();
96}
97
98void wxsLSEditorPlugin::OnDelete()
99{
100 mpModel->OnDelete();
101}
102
103void wxsLSEditorPlugin::OnUndo()
104{
105 mpModel->OnUndo();
106}
107
108void wxsLSEditorPlugin::OnRedo()
109{
110 mpModel->OnRedo();
111}
112
113void wxsLSEditorPlugin::SelectAll()
114{
115 mpModel->OnSelectAll();
116}
117
118void wxsLSEditorPlugin::OnGotoLine()
119{
120 mpModel->OnGotoLine();
121}
122
123void wxsLSEditorPlugin::OnGotoLine( int lineNo, int column )
124{
125 mpModel->ResetSelection();
126 mpModel->OnGotoLine( lineNo, column );
127}
128
129void wxsLSEditorPlugin::OnProperties()
130{
131 // not impl.
132}
133
134void wxsLSEditorPlugin::OnFind()
135{
136 mpModel->OnFind();
137}
138
139void wxsLSEditorPlugin::OnFindNext()
140{
141 mpModel->OnFindNext();
142}
143
144void wxsLSEditorPlugin::OnFindPrevious()
145{
146 mpModel->OnFindPrevious();
147}
148
149void wxsLSEditorPlugin::OnReplace()
150{
151 // not impl.
152}
153
154void wxsLSEditorPlugin::OnToggleBookmark()
155{
156 mpModel->OnToggleBookmark();
157}
158
159void wxsLSEditorPlugin::OnNextBookmark()
160{
161 mpModel->OnNextBookmark();
162}
163
164void wxsLSEditorPlugin::OnPreviousBookmark()
165{
166 mpModel->OnPreviousBookmark();
167}
168
169void wxsLSEditorPlugin::OnShowBookmarks()
170{
171 // not impl.
172}
173
174void wxsLSEditorPlugin::SetCheckpoint()
175{
176 mpModel->SetCheckpoint();
177}
178
179bool wxsLSEditorPlugin::CheckpointModified()
180{
181 return mpModel->CheckpointModified();
182}
183
184// UI-updates
185
186bool wxsLSEditorPlugin::CanCopy()
187{
188 return mpModel->CanCopy();
189}
190
191bool wxsLSEditorPlugin::CanCut()
192{
193 return mpModel->CanCopy();
194}
195
196bool wxsLSEditorPlugin::CanPaste()
197{
198 return mpModel->CanPaste();
199}
200
201bool wxsLSEditorPlugin::CanUndo()
202{
203 return mpModel->CanUndo();
204}
205
206bool wxsLSEditorPlugin::CanRedo()
207{
208 return mpModel->CanRedo();
209}
210
211// accesed by framework
212
213bool wxsLSEditorPlugin::IsModified()
214{
215 return mpModel->IsModified();
216}
217
218wxWindow* wxsLSEditorPlugin::GetWindow()
219{
220 return mpView;
221}
222
223void wxsLSEditorPlugin::GetAllText( char** ppBuf, size_t* length )
224{
225 mpModel->GetAllText( ppBuf, *length );
226}
227
228void wxsLSEditorPlugin::SetFileName( const string& fname )
229{
230 mFileName = fname;
231
232 if ( mpView )
233
234 mpView->SetName( fname );
235}
236
237void wxsLSEditorPlugin::HoldCursor( bool hold )
238{
239 mpView->HoldCursor( hold );
240}
241
242string 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
260void 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
268void wxsLSEditorPlugin::SetCursorPos( int line, int column )
269{
270 mpModel->OnGotoLine( line, column );
271}
272
273void wxsLSEditorPlugin::GetPagePos( int* line, int* column )
274{
275 TPosition pos = mpView->GetPagePos();
276
277 *line = pos.mRow;
278 *column = pos.mCol;
279}
280
281void 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
290void wxsLSEditorPlugin::InsertText( int line, int column,
291 char* text, size_t lenght )
292{
293 mpModel->InsertText( TPosition( line, column ),
294 text, lenght );
295}
296
297void wxsLSEditorPlugin::DeleteText( int fromLine, int fromColumn,
298 int tillLine, int tillColumn )
299{
300 mpModel->DeleteRange( TPosition( fromLine, fromColumn ),
301 TPosition( tillLine, tillColumn ) );
302}
303
304void 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
314void 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
326wxSize wxsLSEditorPlugin::GetCharacterSize()
327{
328 return mpView->GetCharacterSize();
329}
330
331bool wxsLSEditorPlugin::IsUnixText()
332{
333 return mpModel->IsUnixText();
334}
335
336wxTextEditorModel& wxsLSEditorPlugin::GetModel()
337{
338 return *mpModel;
339}
340
341wxTextEditorView& wxsLSEditorPlugin::GetView()
342{
343 return *mpView;
344}