1 //////////////////////////////////////////////////////////////////////////////
3 // Purpose: STC test module
7 // Copyright: (c) wxGuide
8 // Licence: wxWindows licence
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
, wxStyledTextCtrl
)
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_STC_MARGINCLICK (-1, Edit::OnMarginClick
)
104 EVT_STC_CHARADDED (-1, Edit::OnCharAdded
)
107 Edit::Edit (wxWindow
*parent
, wxWindowID id
,
111 : wxStyledTextCtrl (parent
, id
, pos
, size
, style
) {
119 // initialize language
122 // default font for all styles
123 SetViewEOL (g_CommonPrefs
.displayEOLEnable
);
124 SetIndentationGuides (g_CommonPrefs
.indentGuideEnable
);
125 SetEdgeMode (g_CommonPrefs
.longLineOnEnable
?
126 wxSTC_EDGE_LINE
: wxSTC_EDGE_NONE
);
127 SetViewWhiteSpace (g_CommonPrefs
.whiteSpaceEnable
?
128 wxSTC_WS_VISIBLEALWAYS
: wxSTC_WS_INVISIBLE
);
129 SetOvertype (g_CommonPrefs
.overTypeInitial
);
130 SetReadOnly (g_CommonPrefs
.readOnlyInitial
);
131 SetWrapMode (g_CommonPrefs
.wrapModeInitial
?
132 wxSTC_WRAP_WORD
: wxSTC_WRAP_NONE
);
133 wxFont
font (10, wxMODERN
, wxNORMAL
, wxNORMAL
);
134 StyleSetFont (wxSTC_STYLE_DEFAULT
, font
);
135 StyleSetForeground (wxSTC_STYLE_DEFAULT
, wxColour (_T("BLACK")));
136 StyleSetBackground (wxSTC_STYLE_DEFAULT
, wxColour (_T("WHITE")));
137 StyleSetForeground (wxSTC_STYLE_LINENUMBER
, wxColour (_T("DARK GREY")));
138 StyleSetBackground (wxSTC_STYLE_LINENUMBER
, wxColour (_T("WHITE")));
139 StyleSetForeground(wxSTC_STYLE_INDENTGUIDE
, wxColour (_T("DARK GREY")));
140 InitializePrefs (DEFAULT_LANGUAGE
);
143 SetVisiblePolicy (wxSTC_VISIBLE_STRICT
|wxSTC_VISIBLE_SLOP
, 1);
144 SetXCaretPolicy (wxSTC_CARET_EVEN
|wxSTC_VISIBLE_STRICT
|wxSTC_CARET_SLOP
, 1);
145 SetYCaretPolicy (wxSTC_CARET_EVEN
|wxSTC_VISIBLE_STRICT
|wxSTC_CARET_SLOP
, 1);
148 MarkerDefine (wxSTC_MARKNUM_FOLDER
, wxSTC_MARK_DOTDOTDOT
, _T("BLACK"), _T("BLACK"));
149 MarkerDefine (wxSTC_MARKNUM_FOLDEROPEN
, wxSTC_MARK_ARROWDOWN
, _T("BLACK"), _T("BLACK"));
150 MarkerDefine (wxSTC_MARKNUM_FOLDERSUB
, wxSTC_MARK_EMPTY
, _T("BLACK"), _T("BLACK"));
151 MarkerDefine (wxSTC_MARKNUM_FOLDEREND
, wxSTC_MARK_DOTDOTDOT
, _T("BLACK"), _T("WHITE"));
152 MarkerDefine (wxSTC_MARKNUM_FOLDEROPENMID
, wxSTC_MARK_ARROWDOWN
, _T("BLACK"), _T("WHITE"));
153 MarkerDefine (wxSTC_MARKNUM_FOLDERMIDTAIL
, wxSTC_MARK_EMPTY
, _T("BLACK"), _T("BLACK"));
154 MarkerDefine (wxSTC_MARKNUM_FOLDERTAIL
, wxSTC_MARK_EMPTY
, _T("BLACK"), _T("BLACK"));
157 m_LineNrMargin
= TextWidth (wxSTC_STYLE_LINENUMBER
, _T("_999999"));
158 m_FoldingMargin
= 16;
159 SetMarginWidth (m_LineNrID
,
160 g_CommonPrefs
.lineNumberEnable
? m_LineNrMargin
: 0);
161 CmdKeyClear (wxSTC_KEY_TAB
, 0); // this is done by the menu accelerator key
162 SetLayoutCache (wxSTC_CACHE_PAGE
);
168 //----------------------------------------------------------------------------
169 // common event handlers
170 void Edit::OnSize( wxSizeEvent
& event
) {
171 int x
= GetClientSize().x
+
172 (g_CommonPrefs
.lineNumberEnable
? m_LineNrMargin
: 0) +
173 (g_CommonPrefs
.foldEnable
? m_FoldingMargin
: 0);
174 if (x
> 0) SetScrollWidth (x
);
178 // edit event handlers
179 void Edit::OnEditRedo (wxCommandEvent
&WXUNUSED(event
)) {
180 if (!CanRedo()) return;
184 void Edit::OnEditUndo (wxCommandEvent
&WXUNUSED(event
)) {
185 if (!CanUndo()) return;
189 void Edit::OnEditClear (wxCommandEvent
&WXUNUSED(event
)) {
190 if (GetReadOnly()) return;
194 void Edit::OnEditCut (wxCommandEvent
&WXUNUSED(event
)) {
195 if (GetReadOnly() || (GetSelectionEnd()-GetSelectionStart() <= 0)) return;
199 void Edit::OnEditCopy (wxCommandEvent
&WXUNUSED(event
)) {
200 if (GetSelectionEnd()-GetSelectionStart() <= 0) return;
204 void Edit::OnEditPaste (wxCommandEvent
&WXUNUSED(event
)) {
205 if (!CanPaste()) return;
209 void Edit::OnFind (wxCommandEvent
&WXUNUSED(event
)) {
212 void Edit::OnFindNext (wxCommandEvent
&WXUNUSED(event
)) {
215 void Edit::OnReplace (wxCommandEvent
&WXUNUSED(event
)) {
218 void Edit::OnReplaceNext (wxCommandEvent
&WXUNUSED(event
)) {
221 void Edit::OnBraceMatch (wxCommandEvent
&WXUNUSED(event
)) {
222 int min
= GetCurrentPos ();
223 int max
= BraceMatch (min
);
225 BraceHighlight (min
+1, max
);
226 SetSelection (min
+1, max
);
232 void Edit::OnGoto (wxCommandEvent
&WXUNUSED(event
)) {
235 void Edit::OnEditIndentInc (wxCommandEvent
&WXUNUSED(event
)) {
236 CmdKeyExecute (wxSTC_CMD_TAB
);
239 void Edit::OnEditIndentRed (wxCommandEvent
&WXUNUSED(event
)) {
240 CmdKeyExecute (wxSTC_CMD_DELETEBACK
);
243 void Edit::OnEditSelectAll (wxCommandEvent
&WXUNUSED(event
)) {
244 SetSelection (0, GetTextLength ());
247 void Edit::OnEditSelectLine (wxCommandEvent
&WXUNUSED(event
)) {
248 int lineStart
= PositionFromLine (GetCurrentLine());
249 int lineEnd
= PositionFromLine (GetCurrentLine() + 1);
250 SetSelection (lineStart
, lineEnd
);
253 void Edit::OnHilightLang (wxCommandEvent
&event
) {
254 InitializePrefs (g_LanguagePrefs
[event
.GetId() - myID_HILIGHTFIRST
].name
);
257 void Edit::OnDisplayEOL (wxCommandEvent
&WXUNUSED(event
)) {
258 SetViewEOL (!GetViewEOL());
261 void Edit::OnIndentGuide (wxCommandEvent
&WXUNUSED(event
)) {
262 SetIndentationGuides (!GetIndentationGuides());
265 void Edit::OnLineNumber (wxCommandEvent
&WXUNUSED(event
)) {
266 SetMarginWidth (m_LineNrID
,
267 GetMarginWidth (m_LineNrID
) == 0? m_LineNrMargin
: 0);
270 void Edit::OnLongLineOn (wxCommandEvent
&WXUNUSED(event
)) {
271 SetEdgeMode (GetEdgeMode() == 0? wxSTC_EDGE_LINE
: wxSTC_EDGE_NONE
);
274 void Edit::OnWhiteSpace (wxCommandEvent
&WXUNUSED(event
)) {
275 SetViewWhiteSpace (GetViewWhiteSpace() == 0?
276 wxSTC_WS_VISIBLEALWAYS
: wxSTC_WS_INVISIBLE
);
279 void Edit::OnFoldToggle (wxCommandEvent
&WXUNUSED(event
)) {
280 ToggleFold (GetFoldParent(GetCurrentLine()));
283 void Edit::OnSetOverType (wxCommandEvent
&WXUNUSED(event
)) {
284 SetOvertype (!GetOvertype());
287 void Edit::OnSetReadOnly (wxCommandEvent
&WXUNUSED(event
)) {
288 SetReadOnly (!GetReadOnly());
291 void Edit::OnWrapmodeOn (wxCommandEvent
&WXUNUSED(event
)) {
292 SetWrapMode (GetWrapMode() == 0? wxSTC_WRAP_WORD
: wxSTC_WRAP_NONE
);
295 void Edit::OnUseCharset (wxCommandEvent
&event
) {
297 int charset
= GetCodePage();
298 switch (event
.GetId()) {
299 case myID_CHARSETANSI
: {charset
= wxSTC_CHARSET_ANSI
; break;}
300 case myID_CHARSETMAC
: {charset
= wxSTC_CHARSET_ANSI
; break;}
302 for (Nr
= 0; Nr
< wxSTC_STYLE_LASTPREDEFINED
; Nr
++) {
303 StyleSetCharacterSet (Nr
, charset
);
305 SetCodePage (charset
);
308 void Edit::OnChangeCase (wxCommandEvent
&event
) {
309 switch (event
.GetId()) {
310 case myID_CHANGELOWER
: {
311 CmdKeyExecute (wxSTC_CMD_LOWERCASE
);
314 case myID_CHANGEUPPER
: {
315 CmdKeyExecute (wxSTC_CMD_UPPERCASE
);
321 void Edit::OnConvertEOL (wxCommandEvent
&event
) {
322 int eolMode
= GetEOLMode();
323 switch (event
.GetId()) {
324 case myID_CONVERTCR
: { eolMode
= wxSTC_EOL_CR
; break;}
325 case myID_CONVERTCRLF
: { eolMode
= wxSTC_EOL_CRLF
; break;}
326 case myID_CONVERTLF
: { eolMode
= wxSTC_EOL_LF
; break;}
328 ConvertEOLs (eolMode
);
329 SetEOLMode (eolMode
);
333 void Edit::OnMarginClick (wxStyledTextEvent
&event
) {
334 if (event
.GetMargin() == 2) {
335 int lineClick
= LineFromPosition (event
.GetPosition());
336 int levelClick
= GetFoldLevel (lineClick
);
337 if ((levelClick
& wxSTC_FOLDLEVELHEADERFLAG
) > 0) {
338 ToggleFold (lineClick
);
343 void Edit::OnCharAdded (wxStyledTextEvent
&event
) {
344 char chr
= event
.GetKey();
345 int currentLine
= GetCurrentLine();
346 // Change this if support for mac files with \r is needed
349 if (currentLine
> 0) {
350 lineInd
= GetLineIndentation(currentLine
- 1);
352 if (lineInd
== 0) return;
353 SetLineIndentation (currentLine
, lineInd
);
354 GotoPos(PositionFromLine (currentLine
) + lineInd
);
359 //----------------------------------------------------------------------------
361 wxString
Edit::DeterminePrefs (const wxString
&filename
) {
363 LanguageInfo
const* curInfo
;
365 // determine language from filepatterns
367 for (languageNr
= 0; languageNr
< g_LanguagePrefsSize
; languageNr
++) {
368 curInfo
= &g_LanguagePrefs
[languageNr
];
369 wxString filepattern
= curInfo
->filepattern
;
371 while (!filepattern
.IsEmpty()) {
372 wxString cur
= filepattern
.BeforeFirst (';');
373 if ((cur
== filename
) ||
374 (cur
== (filename
.BeforeLast ('.') + _T(".*"))) ||
375 (cur
== (_T("*.") + filename
.AfterLast ('.')))) {
376 return curInfo
->name
;
378 filepattern
= filepattern
.AfterFirst (';');
381 return wxEmptyString
;
385 bool Edit::InitializePrefs (const wxString
&name
) {
389 LanguageInfo
const* curInfo
= NULL
;
391 // determine language
394 for (languageNr
= 0; languageNr
< g_LanguagePrefsSize
; languageNr
++) {
395 curInfo
= &g_LanguagePrefs
[languageNr
];
396 if (curInfo
->name
== name
) {
401 if (!found
) return false;
403 // set lexer and language
404 SetLexer (curInfo
->lexer
);
405 m_language
= curInfo
;
407 // set margin for line numbers
408 SetMarginType (m_LineNrID
, wxSTC_MARGIN_NUMBER
);
409 StyleSetForeground (wxSTC_STYLE_LINENUMBER
, wxColour (_T("DARK GREY")));
410 StyleSetBackground (wxSTC_STYLE_LINENUMBER
, wxColour (_T("WHITE")));
411 SetMarginWidth (m_LineNrID
,
412 g_CommonPrefs
.lineNumberEnable
? m_LineNrMargin
: 0);
414 // default fonts for all styles!
416 for (Nr
= 0; Nr
< wxSTC_STYLE_LASTPREDEFINED
; Nr
++) {
417 wxFont
font (10, wxMODERN
, wxNORMAL
, wxNORMAL
);
418 StyleSetFont (Nr
, font
);
422 StyleSetForeground (wxSTC_STYLE_DEFAULT
, wxColour (_T("DARK GREY")));
423 StyleSetForeground (wxSTC_STYLE_INDENTGUIDE
, wxColour (_T("DARK GREY")));
425 // initialize settings
426 if (g_CommonPrefs
.syntaxEnable
) {
428 for (Nr
= 0; Nr
< STYLE_TYPES_COUNT
; Nr
++) {
429 if (curInfo
->styles
[Nr
].type
== -1) continue;
430 const StyleInfo
&curType
= g_StylePrefs
[curInfo
->styles
[Nr
].type
];
431 wxFont
font (curType
.fontsize
, wxMODERN
, wxNORMAL
, wxNORMAL
, false,
433 StyleSetFont (Nr
, font
);
434 if (curType
.foreground
) {
435 StyleSetForeground (Nr
, wxColour (curType
.foreground
));
437 if (curType
.background
) {
438 StyleSetBackground (Nr
, wxColour (curType
.background
));
440 StyleSetBold (Nr
, (curType
.fontstyle
& mySTC_STYLE_BOLD
) > 0);
441 StyleSetItalic (Nr
, (curType
.fontstyle
& mySTC_STYLE_ITALIC
) > 0);
442 StyleSetUnderline (Nr
, (curType
.fontstyle
& mySTC_STYLE_UNDERL
) > 0);
443 StyleSetVisible (Nr
, (curType
.fontstyle
& mySTC_STYLE_HIDDEN
) == 0);
444 StyleSetCase (Nr
, curType
.lettercase
);
445 const wxChar
*pwords
= curInfo
->styles
[Nr
].words
;
447 SetKeyWords (keywordnr
, pwords
);
453 // set margin as unused
454 SetMarginType (m_DividerID
, wxSTC_MARGIN_SYMBOL
);
455 SetMarginWidth (m_DividerID
, 0);
456 SetMarginSensitive (m_DividerID
, false);
459 SetMarginType (m_FoldingID
, wxSTC_MARGIN_SYMBOL
);
460 SetMarginMask (m_FoldingID
, wxSTC_MASK_FOLDERS
);
461 StyleSetBackground (m_FoldingID
, wxColour (_T("WHITE")));
462 SetMarginWidth (m_FoldingID
, 0);
463 SetMarginSensitive (m_FoldingID
, false);
464 if (g_CommonPrefs
.foldEnable
) {
465 SetMarginWidth (m_FoldingID
, curInfo
->folds
!= 0? m_FoldingMargin
: 0);
466 SetMarginSensitive (m_FoldingID
, curInfo
->folds
!= 0);
467 SetProperty (_T("fold"), curInfo
->folds
!= 0? _T("1"): _T("0"));
468 SetProperty (_T("fold.comment"),
469 (curInfo
->folds
& mySTC_FOLD_COMMENT
) > 0? _T("1"): _T("0"));
470 SetProperty (_T("fold.compact"),
471 (curInfo
->folds
& mySTC_FOLD_COMPACT
) > 0? _T("1"): _T("0"));
472 SetProperty (_T("fold.preprocessor"),
473 (curInfo
->folds
& mySTC_FOLD_PREPROC
) > 0? _T("1"): _T("0"));
474 SetProperty (_T("fold.html"),
475 (curInfo
->folds
& mySTC_FOLD_HTML
) > 0? _T("1"): _T("0"));
476 SetProperty (_T("fold.html.preprocessor"),
477 (curInfo
->folds
& mySTC_FOLD_HTMLPREP
) > 0? _T("1"): _T("0"));
478 SetProperty (_T("fold.comment.python"),
479 (curInfo
->folds
& mySTC_FOLD_COMMENTPY
) > 0? _T("1"): _T("0"));
480 SetProperty (_T("fold.quotes.python"),
481 (curInfo
->folds
& mySTC_FOLD_QUOTESPY
) > 0? _T("1"): _T("0"));
483 SetFoldFlags (wxSTC_FOLDFLAG_LINEBEFORE_CONTRACTED
|
484 wxSTC_FOLDFLAG_LINEAFTER_CONTRACTED
);
486 // set spaces and indention
489 SetTabIndents (true);
490 SetBackSpaceUnIndents (true);
491 SetIndent (g_CommonPrefs
.indentEnable
? 4: 0);
494 SetViewEOL (g_CommonPrefs
.displayEOLEnable
);
495 SetIndentationGuides (g_CommonPrefs
.indentGuideEnable
);
497 SetEdgeMode (g_CommonPrefs
.longLineOnEnable
? wxSTC_EDGE_LINE
: wxSTC_EDGE_NONE
);
498 SetViewWhiteSpace (g_CommonPrefs
.whiteSpaceEnable
?
499 wxSTC_WS_VISIBLEALWAYS
: wxSTC_WS_INVISIBLE
);
500 SetOvertype (g_CommonPrefs
.overTypeInitial
);
501 SetReadOnly (g_CommonPrefs
.readOnlyInitial
);
502 SetWrapMode (g_CommonPrefs
.wrapModeInitial
?
503 wxSTC_WRAP_WORD
: wxSTC_WRAP_NONE
);
508 bool Edit::LoadFile () {
512 wxFileDialog
dlg (this, _T("Open file"), _T(""), _T(""),
513 _T("Any file (*)|*"), wxOPEN
| wxFILE_MUST_EXIST
| wxCHANGE_DIR
);
514 if (dlg
.ShowModal() != wxID_OK
) return false;
515 m_filename
= dlg
.GetPath();
519 return LoadFile (m_filename
);
522 bool Edit::LoadFile (const wxString
&filename
) {
524 // load file in edit and clear undo
525 if (!filename
.IsEmpty()) m_filename
= filename
;
526 // wxFile file (m_filename);
527 // if (!file.IsOpened()) return false;
529 // long lng = file.Length ();
532 // wxChar *buff = buf.GetWriteBuf (lng);
533 // file.Read (buff, lng);
534 // buf.UngetWriteBuf ();
535 // InsertText (0, buf);
539 wxStyledTextCtrl::LoadFile(m_filename
);
543 // determine lexer language
544 wxFileName
fname (m_filename
);
545 InitializePrefs (DeterminePrefs (fname
.GetFullName()));
550 bool Edit::SaveFile () {
552 // return if no change
553 if (!Modified()) return true;
557 wxFileDialog
dlg (this, _T("Save file"), _T(""), _T(""), _T("Any file (*)|*"),
558 wxSAVE
| wxOVERWRITE_PROMPT
);
559 if (dlg
.ShowModal() != wxID_OK
) return false;
560 m_filename
= dlg
.GetPath();
564 return SaveFile (m_filename
);
567 bool Edit::SaveFile (const wxString
&filename
) {
569 // return if no change
570 if (!Modified()) return true;
572 // // save edit in file and clear undo
573 // if (!filename.IsEmpty()) m_filename = filename;
574 // wxFile file (m_filename, wxFile::write);
575 // if (!file.IsOpened()) return false;
576 // wxString buf = GetText();
577 // bool okay = file.Write (buf);
579 // if (!okay) return false;
580 // EmptyUndoBuffer();
585 return wxStyledTextCtrl::SaveFile(filename
);
589 bool Edit::Modified () {
591 // return modified state
592 return (GetModify() && !GetReadOnly());
595 //----------------------------------------------------------------------------
597 //----------------------------------------------------------------------------
599 EditProperties::EditProperties (Edit
*edit
,
601 : wxDialog (edit
, -1, wxEmptyString
,
602 wxDefaultPosition
, wxDefaultSize
,
603 style
| wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
) {
605 // sets the application title
606 SetTitle (_("Properties"));
610 wxBoxSizer
*fullname
= new wxBoxSizer (wxHORIZONTAL
);
611 fullname
->Add (10, 0);
612 fullname
->Add (new wxStaticText (this, -1, _("Full filename"),
613 wxDefaultPosition
, wxSize(80, -1)),
614 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
);
615 fullname
->Add (new wxStaticText (this, -1, edit
->GetFilename()),
616 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
);
619 wxGridSizer
*textinfo
= new wxGridSizer (4, 0, 2);
620 textinfo
->Add (new wxStaticText (this, -1, _("Language"),
621 wxDefaultPosition
, wxSize(80, -1)),
622 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
623 textinfo
->Add (new wxStaticText (this, -1, edit
->m_language
->name
),
624 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
625 textinfo
->Add (new wxStaticText (this, -1, _("Lexer-ID: "),
626 wxDefaultPosition
, wxSize(80, -1)),
627 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
628 text
= wxString::Format (_T("%d"), edit
->GetLexer());
629 textinfo
->Add (new wxStaticText (this, -1, text
),
630 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
631 wxString EOLtype
= _T("");
632 switch (edit
->GetEOLMode()) {
633 case wxSTC_EOL_CR
: {EOLtype
= _T("CR (Unix)"); break; }
634 case wxSTC_EOL_CRLF
: {EOLtype
= _T("CRLF (Windows)"); break; }
635 case wxSTC_EOL_LF
: {EOLtype
= _T("CR (Macintosh)"); break; }
637 textinfo
->Add (new wxStaticText (this, -1, _("Line endings"),
638 wxDefaultPosition
, wxSize(80, -1)),
639 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
640 textinfo
->Add (new wxStaticText (this, -1, EOLtype
),
641 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
644 wxStaticBoxSizer
*textinfos
= new wxStaticBoxSizer (
645 new wxStaticBox (this, -1, _("Informations")),
647 textinfos
->Add (textinfo
, 0, wxEXPAND
);
648 textinfos
->Add (0, 6);
651 wxGridSizer
*statistic
= new wxGridSizer (4, 0, 2);
652 statistic
->Add (new wxStaticText (this, -1, _("Total lines"),
653 wxDefaultPosition
, wxSize(80, -1)),
654 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
655 text
= wxString::Format (_T("%d"), edit
->GetLineCount());
656 statistic
->Add (new wxStaticText (this, -1, text
),
657 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
658 statistic
->Add (new wxStaticText (this, -1, _("Total chars"),
659 wxDefaultPosition
, wxSize(80, -1)),
660 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
661 text
= wxString::Format (_T("%d"), edit
->GetTextLength());
662 statistic
->Add (new wxStaticText (this, -1, text
),
663 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
664 statistic
->Add (new wxStaticText (this, -1, _("Current line"),
665 wxDefaultPosition
, wxSize(80, -1)),
666 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
667 text
= wxString::Format (_T("%d"), edit
->GetCurrentLine());
668 statistic
->Add (new wxStaticText (this, -1, text
),
669 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
670 statistic
->Add (new wxStaticText (this, -1, _("Current pos"),
671 wxDefaultPosition
, wxSize(80, -1)),
672 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
673 text
= wxString::Format (_T("%d"), edit
->GetCurrentPos());
674 statistic
->Add (new wxStaticText (this, -1, text
),
675 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
677 // char/line statistics
678 wxStaticBoxSizer
*statistics
= new wxStaticBoxSizer (
679 new wxStaticBox (this, -1, _("Statistics")),
681 statistics
->Add (statistic
, 0, wxEXPAND
);
682 statistics
->Add (0, 6);
685 wxBoxSizer
*totalpane
= new wxBoxSizer (wxVERTICAL
);
686 totalpane
->Add (fullname
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
| wxTOP
, 10);
687 totalpane
->Add (0, 6);
688 totalpane
->Add (textinfos
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
689 totalpane
->Add (0, 10);
690 totalpane
->Add (statistics
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
691 totalpane
->Add (0, 6);
692 wxButton
*okButton
= new wxButton (this, wxID_OK
, _("OK"));
693 okButton
->SetDefault();
694 totalpane
->Add (okButton
, 0, wxALIGN_CENTER
| wxALL
, 10);
696 SetSizerAndFit (totalpane
);
701 //----------------------------------------------------------------------------
703 //----------------------------------------------------------------------------
705 EditPrint::EditPrint (Edit
*edit
, wxChar
*title
)
706 : wxPrintout(title
) {
712 bool EditPrint::OnPrintPage (int page
) {
715 if (!dc
) return false;
721 if (page
== 1) m_printed
= 0;
722 m_printed
= m_edit
->FormatRange (1, m_printed
, m_edit
->GetLength(),
723 dc
, dc
, m_printRect
, m_pageRect
);
728 bool EditPrint::OnBeginDocument (int startPage
, int endPage
) {
730 if (!wxPrintout::OnBeginDocument (startPage
, endPage
)) {
737 void EditPrint::GetPageInfo (int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
) {
745 // scale DC if possible
750 // get print page informations and convert to printer pixels
752 GetPPIScreen (&ppiScr
.x
, &ppiScr
.y
);
753 wxSize page
= g_pageSetupData
->GetPaperSize();
754 page
.x
= static_cast<int> (page
.x
* ppiScr
.x
/ 25.4);
755 page
.y
= static_cast<int> (page
.y
* ppiScr
.y
/ 25.4);
756 m_pageRect
= wxRect (0,
761 // get margins informations and convert to printer pixels
762 int top
= 25; // default 25
763 int bottom
= 25; // default 25
764 int left
= 20; // default 20
765 int right
= 20; // default 20
766 wxPoint (top
, left
) = g_pageSetupData
->GetMarginTopLeft();
767 wxPoint (bottom
, right
) = g_pageSetupData
->GetMarginBottomRight();
768 top
= static_cast<int> (top
* ppiScr
.y
/ 25.4);
769 bottom
= static_cast<int> (bottom
* ppiScr
.y
/ 25.4);
770 left
= static_cast<int> (left
* ppiScr
.x
/ 25.4);
771 right
= static_cast<int> (right
* ppiScr
.x
/ 25.4);
772 m_printRect
= wxRect (left
,
774 page
.x
- (left
+ right
),
775 page
.y
- (top
+ bottom
));
778 while (HasPage (*maxPage
)) {
779 m_printed
= m_edit
->FormatRange (0, m_printed
, m_edit
->GetLength(),
780 dc
, dc
, m_printRect
, m_pageRect
);
783 if (*maxPage
> 0) *minPage
= 1;
784 *selPageFrom
= *minPage
;
785 *selPageTo
= *maxPage
;
788 bool EditPrint::HasPage (int WXUNUSED(page
)) {
790 return (m_printed
< m_edit
->GetLength());
793 bool EditPrint::PrintScaling (wxDC
*dc
){
795 // check for dc, return if none
796 if (!dc
) return false;
798 // get printer and screen sizing values
800 GetPPIScreen (&ppiScr
.x
, &ppiScr
.y
);
801 if (ppiScr
.x
== 0) { // most possible guess 96 dpi
806 GetPPIPrinter (&ppiPrt
.x
, &ppiPrt
.y
);
807 if (ppiPrt
.x
== 0) { // scaling factor to 1
811 wxSize dcSize
= dc
->GetSize();
813 GetPageSizePixels (&pageSize
.x
, &pageSize
.y
);
816 float scale_x
= (float)(ppiPrt
.x
* dcSize
.x
) /
817 (float)(ppiScr
.x
* pageSize
.x
);
818 float scale_y
= (float)(ppiPrt
.y
* dcSize
.y
) /
819 (float)(ppiScr
.y
* pageSize
.y
);
820 dc
->SetUserScale (scale_x
, scale_y
);