1
//////////////////////////////////////////////////////////////////////////////
3
// Purpose: wxScintilla test module
4
// Maintainer: Otto Wyss
6
// RCS-ID: $Id: edit.cpp 1960 2006-02-07 13:36:51Z thomasdenk $
7
// Copyright: (c) 2004wxCode
9
//////////////////////////////////////////////////////////////////////////////
11
//----------------------------------------------------------------------------
13
//----------------------------------------------------------------------------
16
//----------------------------------------------------------------------------
18
//----------------------------------------------------------------------------
20
// For compilers that support precompilation, includes <wx/wx.h>.
21
#include <wx/wxprec.h>
27
// for all others, include the necessary headers (this file is usually all you
28
// need because it includes almost all 'standard' wxWindows headers)
34
#include <wx/file.h> // raw file io support
35
#include <wx/filename.h> // filename support
37
//! application headers
38
#include "defsext.h" // additional definitions
40
#include "edit.h" // edit module
43
//----------------------------------------------------------------------------
45
//----------------------------------------------------------------------------
48
//============================================================================
50
//============================================================================
53
//============================================================================
55
//============================================================================
57
//----------------------------------------------------------------------------
59
//----------------------------------------------------------------------------
61
BEGIN_EVENT_TABLE (Edit, wxScintilla)
63
EVT_SIZE ( Edit::OnSize)
65
EVT_MENU (wxID_CLEAR, Edit::OnEditClear)
66
EVT_MENU (wxID_CUT, Edit::OnEditCut)
67
EVT_MENU (wxID_COPY, Edit::OnEditCopy)
68
EVT_MENU (wxID_PASTE, Edit::OnEditPaste)
69
EVT_MENU (myID_INDENTINC, Edit::OnEditIndentInc)
70
EVT_MENU (myID_INDENTRED, Edit::OnEditIndentRed)
71
EVT_MENU (wxID_SELECTALL, Edit::OnEditSelectAll)
72
EVT_MENU (myID_SELECTLINE, Edit::OnEditSelectLine)
73
EVT_MENU (wxID_REDO, Edit::OnEditRedo)
74
EVT_MENU (wxID_UNDO, Edit::OnEditUndo)
76
EVT_MENU (wxID_FIND, Edit::OnFind)
77
EVT_MENU (myID_FINDNEXT, Edit::OnFindNext)
78
EVT_MENU (myID_REPLACE, Edit::OnReplace)
79
EVT_MENU (myID_REPLACENEXT, Edit::OnReplaceNext)
80
EVT_MENU (myID_BRACEMATCH, Edit::OnBraceMatch)
81
EVT_MENU (myID_GOTO, Edit::OnGoto)
83
EVT_MENU_RANGE (myID_HILIGHTFIRST, myID_HILIGHTLAST,
85
EVT_MENU (myID_DISPLAYEOL, Edit::OnDisplayEOL)
86
EVT_MENU (myID_INDENTGUIDE, Edit::OnIndentGuide)
87
EVT_MENU (myID_LINENUMBER, Edit::OnLineNumber)
88
EVT_MENU (myID_LONGLINEON, Edit::OnLongLineOn)
89
EVT_MENU (myID_WHITESPACE, Edit::OnWhiteSpace)
90
EVT_MENU (myID_FOLDTOGGLE, Edit::OnFoldToggle)
91
EVT_MENU (myID_OVERTYPE, Edit::OnSetOverType)
92
EVT_MENU (myID_READONLY, Edit::OnSetReadOnly)
93
EVT_MENU (myID_WRAPMODEON, Edit::OnWrapmodeOn)
94
EVT_MENU (myID_CHARSETANSI, Edit::OnUseCharset)
95
EVT_MENU (myID_CHARSETMAC, Edit::OnUseCharset)
97
EVT_MENU (myID_CHANGELOWER, Edit::OnChangeCase)
98
EVT_MENU (myID_CHANGEUPPER, Edit::OnChangeCase)
99
EVT_MENU (myID_CONVERTCR, Edit::OnConvertEOL)
100
EVT_MENU (myID_CONVERTCRLF, Edit::OnConvertEOL)
101
EVT_MENU (myID_CONVERTLF, Edit::OnConvertEOL)
103
EVT_SCI_MARGINCLICK (-1, Edit::OnMarginClick)
104
EVT_SCI_CHARADDED (-1, Edit::OnCharAdded)
107
Edit::Edit (wxWindow *parent, wxWindowID id,
111
: wxScintilla (parent, id, pos, size, style) {
117
m_LineNrMargin = TextWidth (wxSCI_STYLE_LINENUMBER, _T("_999999"));
119
m_FoldingMargin = 16;
122
// default font for all styles
123
SetViewEOL (g_CommonPrefs.displayEOLEnable);
124
SetIndentationGuides (g_CommonPrefs.indentGuideEnable);
125
SetMarginWidth (m_LineNrID,
126
g_CommonPrefs.lineNumberEnable? m_LineNrMargin: 0);
127
SetEdgeMode (g_CommonPrefs.longLineOnEnable?
128
wxSCI_EDGE_LINE: wxSCI_EDGE_NONE);
129
SetViewWhiteSpace (g_CommonPrefs.whiteSpaceEnable?
130
wxSCI_WS_VISIBLEALWAYS: wxSCI_WS_INVISIBLE);
131
SetOvertype (g_CommonPrefs.overTypeInitial);
132
SetReadOnly (g_CommonPrefs.readOnlyInitial);
133
SetWrapMode (g_CommonPrefs.wrapModeInitial?
134
wxSCI_WRAP_WORD: wxSCI_WRAP_NONE);
135
wxFont font (10, wxTELETYPE, wxNORMAL, wxNORMAL);
136
StyleSetFont (wxSCI_STYLE_DEFAULT, font);
137
StyleSetForeground (wxSCI_STYLE_DEFAULT, wxColour (_T("BLACK")));
138
StyleSetBackground (wxSCI_STYLE_DEFAULT, wxColour (_T("WHITE")));
139
StyleSetForeground (wxSCI_STYLE_LINENUMBER, wxColour (_T("DARK GREY")));
140
StyleSetBackground (wxSCI_STYLE_LINENUMBER, wxColour (_T("WHITE")));
141
StyleSetForeground(wxSCI_STYLE_INDENTGUIDE, wxColour (_T("DARK GREY")));
142
InitializePrefs (DEFAULT_LANGUAGE);
145
SetVisiblePolicy (wxSCI_VISIBLE_STRICT|wxSCI_VISIBLE_SLOP, 1);
146
SetXCaretPolicy (wxSCI_CARET_EVEN|wxSCI_VISIBLE_STRICT|wxSCI_CARET_SLOP, 1);
147
SetYCaretPolicy (wxSCI_CARET_EVEN|wxSCI_VISIBLE_STRICT|wxSCI_CARET_SLOP, 1);
150
MarkerDefine (wxSCI_MARKNUM_FOLDER, wxSCI_MARK_BOXPLUS);
151
MarkerSetBackground (wxSCI_MARKNUM_FOLDER, wxColour (_T("BLACK")));
152
MarkerSetForeground (wxSCI_MARKNUM_FOLDER, wxColour (_T("WHITE")));
153
MarkerDefine (wxSCI_MARKNUM_FOLDEROPEN, wxSCI_MARK_BOXMINUS);
154
MarkerSetBackground (wxSCI_MARKNUM_FOLDEROPEN, wxColour (_T("BLACK")));
155
MarkerSetForeground (wxSCI_MARKNUM_FOLDEROPEN, wxColour (_T("WHITE")));
156
MarkerDefine (wxSCI_MARKNUM_FOLDERSUB, wxSCI_MARK_EMPTY);
157
MarkerDefine (wxSCI_MARKNUM_FOLDEREND, wxSCI_MARK_SHORTARROW);
158
MarkerDefine (wxSCI_MARKNUM_FOLDEROPENMID, wxSCI_MARK_ARROWDOWN);
159
MarkerDefine (wxSCI_MARKNUM_FOLDERMIDTAIL, wxSCI_MARK_EMPTY);
160
MarkerDefine (wxSCI_MARKNUM_FOLDERTAIL, wxSCI_MARK_EMPTY);
162
// clear wrong default keys
163
#if !defined(__WXGTK__)
164
CmdKeyClear (wxSCI_KEY_TAB, 0);
165
CmdKeyClear (wxSCI_KEY_TAB, wxSCI_SCMOD_SHIFT);
167
CmdKeyClear ('A', wxSCI_SCMOD_CTRL);
168
#if !defined(__WXGTK__)
169
CmdKeyClear ('C', wxSCI_SCMOD_CTRL);
171
CmdKeyClear ('D', wxSCI_SCMOD_CTRL);
172
CmdKeyClear ('D', wxSCI_SCMOD_SHIFT | wxSCI_SCMOD_CTRL);
173
CmdKeyClear ('F', wxSCI_SCMOD_ALT | wxSCI_SCMOD_CTRL);
174
CmdKeyClear ('L', wxSCI_SCMOD_CTRL);
175
CmdKeyClear ('L', wxSCI_SCMOD_SHIFT | wxSCI_SCMOD_CTRL);
176
CmdKeyClear ('T', wxSCI_SCMOD_CTRL);
177
CmdKeyClear ('T', wxSCI_SCMOD_SHIFT | wxSCI_SCMOD_CTRL);
178
CmdKeyClear ('U', wxSCI_SCMOD_CTRL);
179
CmdKeyClear ('U', wxSCI_SCMOD_SHIFT | wxSCI_SCMOD_CTRL);
180
#if !defined(__WXGTK__)
181
CmdKeyClear ('V', wxSCI_SCMOD_CTRL);
182
CmdKeyClear ('X', wxSCI_SCMOD_CTRL);
184
CmdKeyClear ('Y', wxSCI_SCMOD_CTRL);
185
#if !defined(__WXGTK__)
186
CmdKeyClear ('Z', wxSCI_SCMOD_CTRL);
191
SetLayoutCache (wxSCI_CACHE_PAGE);
198
//----------------------------------------------------------------------------
199
// common event handlers
200
void Edit::OnSize( wxSizeEvent& event ) {
201
int x = GetClientSize().x +
202
(g_CommonPrefs.lineNumberEnable? m_LineNrMargin: 0) +
203
(g_CommonPrefs.foldEnable? m_FoldingMargin: 0);
204
if (x > 0) SetScrollWidth (x);
208
// edit event handlers
209
void Edit::OnEditRedo (wxCommandEvent &WXUNUSED(event)) {
210
if (!CanRedo()) return;
214
void Edit::OnEditUndo (wxCommandEvent &WXUNUSED(event)) {
215
if (!CanUndo()) return;
219
void Edit::OnEditClear (wxCommandEvent &WXUNUSED(event)) {
220
if (GetReadOnly()) return;
224
void Edit::OnEditCut (wxCommandEvent &WXUNUSED(event)) {
225
if (GetReadOnly() || (GetSelectionEnd()-GetSelectionStart() <= 0)) return;
229
void Edit::OnEditCopy (wxCommandEvent &WXUNUSED(event)) {
230
if (GetSelectionEnd()-GetSelectionStart() <= 0) return;
234
void Edit::OnEditPaste (wxCommandEvent &WXUNUSED(event)) {
235
if (!CanPaste()) return;
239
void Edit::OnFind (wxCommandEvent &WXUNUSED(event)) {
242
void Edit::OnFindNext (wxCommandEvent &WXUNUSED(event)) {
245
void Edit::OnReplace (wxCommandEvent &WXUNUSED(event)) {
248
void Edit::OnReplaceNext (wxCommandEvent &WXUNUSED(event)) {
251
void Edit::OnBraceMatch (wxCommandEvent &WXUNUSED(event)) {
252
int min = GetCurrentPos ();
253
int max = BraceMatch (min);
255
BraceHighlight (min+1, max);
256
SetSelection (min+1, max);
262
void Edit::OnGoto (wxCommandEvent &WXUNUSED(event)) {
265
void Edit::OnEditIndentInc (wxCommandEvent &WXUNUSED(event)) {
266
CmdKeyExecute (wxSCI_CMD_TAB);
269
void Edit::OnEditIndentRed (wxCommandEvent &WXUNUSED(event)) {
270
CmdKeyExecute (wxSCI_CMD_DELETEBACK);
273
void Edit::OnEditSelectAll (wxCommandEvent &WXUNUSED(event)) {
274
SetSelection (0, GetLength());
277
void Edit::OnEditSelectLine (wxCommandEvent &WXUNUSED(event)) {
278
int lineStart = PositionFromLine (GetCurrentLine());
279
int lineEnd = PositionFromLine (GetCurrentLine() + 1);
280
SetSelection (lineStart, lineEnd);
283
void Edit::OnHilightLang (wxCommandEvent &event) {
284
InitializePrefs (g_LanguagePrefs [event.GetId() - myID_HILIGHTFIRST].name);
287
void Edit::OnDisplayEOL (wxCommandEvent &WXUNUSED(event)) {
288
SetViewEOL (!GetViewEOL());
291
void Edit::OnIndentGuide (wxCommandEvent &WXUNUSED(event)) {
292
SetIndentationGuides (!GetIndentationGuides());
295
void Edit::OnLineNumber (wxCommandEvent &WXUNUSED(event)) {
296
SetMarginWidth (m_LineNrID,
297
GetMarginWidth (m_LineNrID) == 0? m_LineNrMargin: 0);
300
void Edit::OnLongLineOn (wxCommandEvent &WXUNUSED(event)) {
301
SetEdgeMode (GetEdgeMode() == 0? wxSCI_EDGE_LINE: wxSCI_EDGE_NONE);
304
void Edit::OnWhiteSpace (wxCommandEvent &WXUNUSED(event)) {
305
SetViewWhiteSpace (GetViewWhiteSpace() == 0?
306
wxSCI_WS_VISIBLEALWAYS: wxSCI_WS_INVISIBLE);
309
void Edit::OnFoldToggle (wxCommandEvent &WXUNUSED(event)) {
310
ToggleFold (GetFoldParent(GetCurrentLine()));
313
void Edit::OnSetOverType (wxCommandEvent &WXUNUSED(event)) {
314
SetOvertype (!GetOvertype());
317
void Edit::OnSetReadOnly (wxCommandEvent &WXUNUSED(event)) {
318
SetReadOnly (!GetReadOnly());
321
void Edit::OnWrapmodeOn (wxCommandEvent &WXUNUSED(event)) {
322
SetWrapMode (GetWrapMode() == 0? wxSCI_WRAP_WORD: wxSCI_WRAP_NONE);
325
void Edit::OnUseCharset (wxCommandEvent &event) {
327
int charset = GetCodePage();
328
switch (event.GetId()) {
329
case myID_CHARSETANSI: {charset = wxSCI_CHARSET_ANSI; break;}
330
case myID_CHARSETMAC: {charset = wxSCI_CHARSET_ANSI; break;}
332
for (Nr = 0; Nr < wxSCI_STYLE_LASTPREDEFINED; Nr++) {
333
StyleSetCharacterSet (Nr, charset);
335
SetCodePage (charset);
338
void Edit::OnChangeCase (wxCommandEvent &event) {
339
switch (event.GetId()) {
340
case myID_CHANGELOWER: {
341
CmdKeyExecute (wxSCI_CMD_LOWERCASE);
344
case myID_CHANGEUPPER: {
345
CmdKeyExecute (wxSCI_CMD_UPPERCASE);
351
void Edit::OnConvertEOL (wxCommandEvent &event) {
352
int eolMode = GetEOLMode();
353
switch (event.GetId()) {
354
case myID_CONVERTCR: { eolMode = wxSCI_EOL_CR; break;}
355
case myID_CONVERTCRLF: { eolMode = wxSCI_EOL_CRLF; break;}
356
case myID_CONVERTLF: { eolMode = wxSCI_EOL_LF; break;}
358
ConvertEOLs (eolMode);
359
SetEOLMode (eolMode);
363
void Edit::OnMarginClick (wxScintillaEvent &event) {
364
if (event.GetMargin() == 2) {
365
int lineClick = LineFromPosition (event.GetPosition());
366
int levelClick = GetFoldLevel (lineClick);
367
if ((levelClick & wxSCI_FOLDLEVELHEADERFLAG) > 0) {
368
ToggleFold (lineClick);
373
void Edit::OnCharAdded (wxScintillaEvent &event) {
374
char chr = event.GetKey();
375
int currentLine = GetCurrentLine();
376
// Change this if support for mac files with \r is needed
379
if (currentLine > 0) {
380
lineInd = GetLineIndentation(currentLine - 1);
382
if (lineInd == 0) return;
383
SetLineIndentation (currentLine, lineInd);
384
GotoPos(PositionFromLine (currentLine) + lineInd);
389
//----------------------------------------------------------------------------
391
wxString Edit::DeterminePrefs (const wxString &filename) {
393
LanguageInfo const* curInfo;
395
// determine language from filepatterns
397
for (languageNr = 0; languageNr < g_LanguagePrefsSize; languageNr++) {
398
curInfo = &g_LanguagePrefs [languageNr];
399
wxString filepattern = curInfo->filepattern;
401
while (!filepattern.IsEmpty()) {
402
wxString cur = filepattern.BeforeFirst (';');
403
if ((cur == filename) ||
404
(cur == (filename.BeforeLast ('.') + _T(".*"))) ||
405
(cur == (_T("*.") + filename.AfterLast ('.')))) {
406
return curInfo->name;
408
filepattern = filepattern.AfterFirst (';');
411
return wxEmptyString;
415
bool Edit::InitializePrefs (const wxString &name) {
419
LanguageInfo const* curInfo = NULL;
421
// determine language
424
for (languageNr = 0; languageNr < g_LanguagePrefsSize; languageNr++) {
425
curInfo = &g_LanguagePrefs [languageNr];
426
if (curInfo->name == name) {
431
if (!found) return false;
433
// set lexer and language
434
SetLexer (curInfo->lexer);
435
m_language = curInfo;
437
// set margin for line numbers
438
SetMarginType (m_LineNrID, wxSCI_MARGIN_NUMBER);
439
StyleSetForeground (wxSCI_STYLE_LINENUMBER, wxColour (_T("DARK GREY")));
440
StyleSetBackground (wxSCI_STYLE_LINENUMBER, wxColour (_T("WHITE")));
441
SetMarginWidth (m_LineNrID,
442
g_CommonPrefs.lineNumberEnable? m_LineNrMargin: 0);
445
StyleSetForeground (wxSCI_STYLE_DEFAULT, wxColour (_T("DARK GREY")));
446
StyleSetForeground (wxSCI_STYLE_INDENTGUIDE, wxColour (_T("DARK GREY")));
448
// initialize settings
449
if (g_CommonPrefs.syntaxEnable) {
452
for (Nr = 0; Nr < STYLE_TYPES_COUNT; Nr++) {
453
if (curInfo->styles[Nr].type == -1) continue;
454
const StyleInfo &curType = g_StylePrefs [curInfo->styles[Nr].type];
455
wxFont font (curType.fontsize, wxTELETYPE, wxNORMAL, wxNORMAL, false,
457
StyleSetFont (Nr, font);
458
if (curType.foreground) {
459
StyleSetForeground (Nr, wxColour (curType.foreground));
461
if (curType.background) {
462
StyleSetBackground (Nr, wxColour (curType.background));
464
StyleSetBold (Nr, (curType.fontstyle & TOKEN_STYLE_BOLD) > 0);
465
StyleSetItalic (Nr, (curType.fontstyle & TOKEN_STYLE_ITALIC) > 0);
466
StyleSetUnderline (Nr, (curType.fontstyle & TOKEN_STYLE_UNDERL) > 0);
467
StyleSetVisible (Nr, (curType.fontstyle & TOKEN_STYLE_HIDDEN) == 0);
468
StyleSetCase (Nr, curType.lettercase);
469
const wxChar *pwords = curInfo->styles[Nr].words;
471
SetKeyWords (keywordnr, pwords);
477
// set margin as unused
478
SetMarginType (m_DividerID, wxSCI_MARGIN_SYMBOL);
479
SetMarginWidth (m_DividerID, 8);
480
SetMarginSensitive (m_DividerID, false);
483
SetMarginType (m_FoldingID, wxSCI_MARGIN_SYMBOL);
484
SetMarginMask (m_FoldingID, wxSCI_MASK_FOLDERS);
485
StyleSetBackground (m_FoldingID, wxColour (_T("WHITE")));
486
SetMarginWidth (m_FoldingID, 0);
487
SetMarginSensitive (m_FoldingID, false);
488
if (g_CommonPrefs.foldEnable) {
489
SetMarginWidth (m_FoldingID, curInfo->folds != 0? m_FoldingMargin: 0);
490
SetMarginSensitive (m_FoldingID, curInfo->folds != 0);
491
SetProperty (_T("fold"), curInfo->folds != 0? _T("1"): _T("0"));
492
SetProperty (_T("fold.comment"),
493
(curInfo->folds & FOLD_TYPE_COMMENT) > 0? _T("1"): _T("0"));
494
SetProperty (_T("fold.compact"),
495
(curInfo->folds & FOLD_TYPE_COMPACT) > 0? _T("1"): _T("0"));
496
SetProperty (_T("fold.preprocessor"),
497
(curInfo->folds & FOLD_TYPE_PREPROC) > 0? _T("1"): _T("0"));
498
SetProperty (_T("fold.html"),
499
(curInfo->folds & FOLD_TYPE_HTML) > 0? _T("1"): _T("0"));
500
SetProperty (_T("fold.html.preprocessor"),
501
(curInfo->folds & FOLD_TYPE_HTMLPREP) > 0? _T("1"): _T("0"));
502
SetProperty (_T("fold.comment.python"),
503
(curInfo->folds & FOLD_TYPE_COMMENTPY) > 0? _T("1"): _T("0"));
504
SetProperty (_T("fold.quotes.python"),
505
(curInfo->folds & FOLD_TYPE_QUOTESPY) > 0? _T("1"): _T("0"));
507
SetFoldFlags (wxSCI_FOLDFLAG_LINEBEFORE_CONTRACTED |
508
wxSCI_FOLDFLAG_LINEAFTER_CONTRACTED);
510
// set spaces and indention
513
SetTabIndents (true);
514
SetBackSpaceUnIndents (true);
515
SetIndent (g_CommonPrefs.indentEnable? 4: 0);
518
SetViewEOL (g_CommonPrefs.displayEOLEnable);
519
SetIndentationGuides (g_CommonPrefs.indentGuideEnable);
521
SetEdgeMode (g_CommonPrefs.longLineOnEnable? wxSCI_EDGE_LINE: wxSCI_EDGE_NONE);
522
SetViewWhiteSpace (g_CommonPrefs.whiteSpaceEnable?
523
wxSCI_WS_VISIBLEALWAYS: wxSCI_WS_INVISIBLE);
524
SetOvertype (g_CommonPrefs.overTypeInitial);
525
SetReadOnly (g_CommonPrefs.readOnlyInitial);
526
SetWrapMode (g_CommonPrefs.wrapModeInitial?
527
wxSCI_WRAP_WORD: wxSCI_WRAP_NONE);
532
bool Edit::LoadFile () {
536
wxFileDialog dlg (this, _T("Open file"), _T(""), _T(""),
537
_T("Any file (*)|*"), wxOPEN | wxFILE_MUST_EXIST | wxCHANGE_DIR);
538
if (dlg.ShowModal() != wxID_OK) return false;
539
m_filename = dlg.GetPath();
543
return LoadFile (m_filename);
546
bool Edit::LoadFile (const wxString &filename) {
548
// load file in edit and clear undo
549
if (!filename.IsEmpty()) m_filename = filename;
550
if (!wxScintilla::LoadFile (m_filename)) return false;
552
// determine lexer language
553
wxFileName fname (m_filename);
554
InitializePrefs (DeterminePrefs (fname.GetFullName()));
559
bool Edit::SaveFile () {
561
// return if no change
562
if (!Modified()) return true;
566
wxFileDialog dlg (this, _T("Save file"), _T(""), _T(""), _T("Any file (*)|*"),
567
wxSAVE | wxOVERWRITE_PROMPT);
568
if (dlg.ShowModal() != wxID_OK) return false;
569
m_filename = dlg.GetPath();
573
return SaveFile (m_filename);
576
bool Edit::SaveFile (const wxString &filename) {
578
// return if no change
579
if (!Modified()) return true;
581
return wxScintilla::SaveFile(filename);
585
bool Edit::Modified () {
587
// return modified state
588
return (GetModify() && !GetReadOnly());
591
//----------------------------------------------------------------------------
593
//----------------------------------------------------------------------------
595
EditProperties::EditProperties (Edit *edit,
597
: wxDialog (edit, -1, wxEmptyString,
598
wxDefaultPosition, wxDefaultSize,
599
style | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
601
// sets the application title
602
SetTitle (_("Properties"));
606
wxBoxSizer *fullname = new wxBoxSizer (wxHORIZONTAL);
607
fullname->Add (10, 0);
608
fullname->Add (new wxStaticText (this, -1, _("Full filename"),
609
wxDefaultPosition, wxSize(80, -1)),
610
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL);
611
fullname->Add (new wxStaticText (this, -1, edit->GetFilename()),
612
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL);
615
wxGridSizer *textinfo = new wxGridSizer (4, 0, 2);
616
textinfo->Add (new wxStaticText (this, -1, _("Language"),
617
wxDefaultPosition, wxSize(80, -1)),
618
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
619
textinfo->Add (new wxStaticText (this, -1, edit->m_language->name),
620
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
621
textinfo->Add (new wxStaticText (this, -1, _("Lexer-ID: "),
622
wxDefaultPosition, wxSize(80, -1)),
623
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
624
text = wxString::Format (_T("%d"), edit->GetLexer());
625
textinfo->Add (new wxStaticText (this, -1, text),
626
0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
627
wxString EOLtype = _T("");
628
switch (edit->GetEOLMode()) {
629
case wxSCI_EOL_CR: {EOLtype = _T("CR (Unix)"); break; }
630
case wxSCI_EOL_CRLF: {EOLtype = _T("CRLF (Windows)"); break; }
631
case wxSCI_EOL_LF: {EOLtype = _T("CR (Macintosh)"); break; }
633
textinfo->Add (new wxStaticText (this, -1, _("Line endings"),
634
wxDefaultPosition, wxSize(80, -1)),
635
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
636
textinfo->Add (new wxStaticText (this, -1, EOLtype),
637
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
640
wxStaticBoxSizer *textinfos = new wxStaticBoxSizer (
641
new wxStaticBox (this, -1, _("Informations")),
643
textinfos->Add (textinfo, 0, wxEXPAND);
644
textinfos->Add (0, 6);
647
wxGridSizer *statistic = new wxGridSizer (4, 0, 2);
648
statistic->Add (new wxStaticText (this, -1, _("Total lines"),
649
wxDefaultPosition, wxSize(80, -1)),
650
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
651
text = wxString::Format (_T("%d"), edit->GetLineCount());
652
statistic->Add (new wxStaticText (this, -1, text),
653
0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
654
statistic->Add (new wxStaticText (this, -1, _("Total chars"),
655
wxDefaultPosition, wxSize(80, -1)),
656
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
657
text = wxString::Format (_T("%d"), edit->GetTextLength());
658
statistic->Add (new wxStaticText (this, -1, text),
659
0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
660
statistic->Add (new wxStaticText (this, -1, _("Current line"),
661
wxDefaultPosition, wxSize(80, -1)),
662
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
663
text = wxString::Format (_T("%d"), edit->GetCurrentLine());
664
statistic->Add (new wxStaticText (this, -1, text),
665
0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
666
statistic->Add (new wxStaticText (this, -1, _("Current pos"),
667
wxDefaultPosition, wxSize(80, -1)),
668
0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
669
text = wxString::Format (_T("%d"), edit->GetCurrentPos());
670
statistic->Add (new wxStaticText (this, -1, text),
671
0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
673
// char/line statistics
674
wxStaticBoxSizer *statistics = new wxStaticBoxSizer (
675
new wxStaticBox (this, -1, _("Statistics")),
677
statistics->Add (statistic, 0, wxEXPAND);
678
statistics->Add (0, 6);
681
wxBoxSizer *totalpane = new wxBoxSizer (wxVERTICAL);
682
totalpane->Add (fullname, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 10);
683
totalpane->Add (0, 6);
684
totalpane->Add (textinfos, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
685
totalpane->Add (0, 10);
686
totalpane->Add (statistics, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
687
totalpane->Add (0, 6);
688
wxButton *okButton = new wxButton (this, wxID_OK, _("OK"));
689
okButton->SetDefault();
690
totalpane->Add (okButton, 0, wxALIGN_CENTER | wxALL, 10);
692
SetSizerAndFit (totalpane);
697
//----------------------------------------------------------------------------
699
//----------------------------------------------------------------------------
701
EditPrint::EditPrint (Edit *edit, wxChar *title)
702
: wxPrintout(title) {
708
bool EditPrint::OnPrintPage (int page) {
711
if (!dc) return false;
717
if (page == 1) m_printed = 0;
718
m_printed = m_edit->FormatRange (1, m_printed, m_edit->GetLength(),
719
dc, dc, m_printRect, m_pageRect);
724
bool EditPrint::OnBeginDocument (int startPage, int endPage) {
726
if (!wxPrintout::OnBeginDocument (startPage, endPage)) {
733
void EditPrint::GetPageInfo (int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) {
741
// scale DC if possible
746
// get print page informations and convert to printer pixels
748
GetPPIScreen (&ppiScr.x, &ppiScr.y);
749
wxSize page = g_pageSetupData->GetPaperSize();
750
page.x = static_cast<int> (page.x * ppiScr.x / 25.4);
751
page.y = static_cast<int> (page.y * ppiScr.y / 25.4);
752
m_pageRect = wxRect (0,
757
// get margins informations and convert to printer pixels
758
int top = 25; // default 25
759
int bottom = 25; // default 25
760
int left = 20; // default 20
761
int right = 20; // default 20
762
wxPoint (top, left) = g_pageSetupData->GetMarginTopLeft();
763
wxPoint (bottom, right) = g_pageSetupData->GetMarginBottomRight();
764
top = static_cast<int> (top * ppiScr.y / 25.4);
765
bottom = static_cast<int> (bottom * ppiScr.y / 25.4);
766
left = static_cast<int> (left * ppiScr.x / 25.4);
767
right = static_cast<int> (right * ppiScr.x / 25.4);
768
m_printRect = wxRect (left,
770
page.x - (left + right),
771
page.y - (top + bottom));
774
while (HasPage (*maxPage)) {
775
m_printed = m_edit->FormatRange (0, m_printed, m_edit->GetLength(),
776
dc, dc, m_printRect, m_pageRect);
779
if (*maxPage > 0) *minPage = 1;
780
*selPageFrom = *minPage;
781
*selPageTo = *maxPage;
785
bool EditPrint::HasPage (int WXUNUSED(page)) {
787
return (m_printed < m_edit->GetLength());
790
bool EditPrint::PrintScaling (wxDC *dc){
792
// check for dc, return if none
793
if (!dc) return false;
795
// get printer and screen sizing values
797
GetPPIScreen (&ppiScr.x, &ppiScr.y);
798
if (ppiScr.x == 0) { // most possible guess 96 dpi
803
GetPPIPrinter (&ppiPrt.x, &ppiPrt.y);
804
if (ppiPrt.x == 0) { // scaling factor to 1
808
wxSize dcSize = dc->GetSize();
810
GetPageSizePixels (&pageSize.x, &pageSize.y);
813
float scale_x = (float)(ppiPrt.x * dcSize.x) /
814
(float)(ppiScr.x * pageSize.x);
815
float scale_y = (float)(ppiPrt.y * dcSize.y) /
816
(float)(ppiScr.y * pageSize.y);
817
dc->SetUserScale (scale_x, scale_y);