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
163 SetLayoutCache (wxSTC_CACHE_PAGE
);
169 //----------------------------------------------------------------------------
170 // common event handlers
171 void Edit::OnSize( wxSizeEvent
& event
) {
172 int x
= GetClientSize().x
+
173 (g_CommonPrefs
.lineNumberEnable
? m_LineNrMargin
: 0) +
174 (g_CommonPrefs
.foldEnable
? m_FoldingMargin
: 0);
175 if (x
> 0) SetScrollWidth (x
);
179 // edit event handlers
180 void Edit::OnEditRedo (wxCommandEvent
&WXUNUSED(event
)) {
181 if (!CanRedo()) return;
185 void Edit::OnEditUndo (wxCommandEvent
&WXUNUSED(event
)) {
186 if (!CanUndo()) return;
190 void Edit::OnEditClear (wxCommandEvent
&WXUNUSED(event
)) {
191 if (GetReadOnly()) return;
195 void Edit::OnEditCut (wxCommandEvent
&WXUNUSED(event
)) {
196 if (GetReadOnly() || (GetSelectionEnd()-GetSelectionStart() <= 0)) return;
200 void Edit::OnEditCopy (wxCommandEvent
&WXUNUSED(event
)) {
201 if (GetSelectionEnd()-GetSelectionStart() <= 0) return;
205 void Edit::OnEditPaste (wxCommandEvent
&WXUNUSED(event
)) {
206 if (!CanPaste()) return;
210 void Edit::OnFind (wxCommandEvent
&WXUNUSED(event
)) {
213 void Edit::OnFindNext (wxCommandEvent
&WXUNUSED(event
)) {
216 void Edit::OnReplace (wxCommandEvent
&WXUNUSED(event
)) {
219 void Edit::OnReplaceNext (wxCommandEvent
&WXUNUSED(event
)) {
222 void Edit::OnBraceMatch (wxCommandEvent
&WXUNUSED(event
)) {
223 int min
= GetCurrentPos ();
224 int max
= BraceMatch (min
);
226 BraceHighlight (min
+1, max
);
227 SetSelection (min
+1, max
);
233 void Edit::OnGoto (wxCommandEvent
&WXUNUSED(event
)) {
236 void Edit::OnEditIndentInc (wxCommandEvent
&WXUNUSED(event
)) {
237 CmdKeyExecute (wxSTC_CMD_TAB
);
240 void Edit::OnEditIndentRed (wxCommandEvent
&WXUNUSED(event
)) {
241 CmdKeyExecute (wxSTC_CMD_DELETEBACK
);
244 void Edit::OnEditSelectAll (wxCommandEvent
&WXUNUSED(event
)) {
245 SetSelection (0, GetTextLength ());
248 void Edit::OnEditSelectLine (wxCommandEvent
&WXUNUSED(event
)) {
249 int lineStart
= PositionFromLine (GetCurrentLine());
250 int lineEnd
= PositionFromLine (GetCurrentLine() + 1);
251 SetSelection (lineStart
, lineEnd
);
254 void Edit::OnHilightLang (wxCommandEvent
&event
) {
255 InitializePrefs (g_LanguagePrefs
[event
.GetId() - myID_HILIGHTFIRST
].name
);
258 void Edit::OnDisplayEOL (wxCommandEvent
&WXUNUSED(event
)) {
259 SetViewEOL (!GetViewEOL());
262 void Edit::OnIndentGuide (wxCommandEvent
&WXUNUSED(event
)) {
263 SetIndentationGuides (!GetIndentationGuides());
266 void Edit::OnLineNumber (wxCommandEvent
&WXUNUSED(event
)) {
267 SetMarginWidth (m_LineNrID
,
268 GetMarginWidth (m_LineNrID
) == 0? m_LineNrMargin
: 0);
271 void Edit::OnLongLineOn (wxCommandEvent
&WXUNUSED(event
)) {
272 SetEdgeMode (GetEdgeMode() == 0? wxSTC_EDGE_LINE
: wxSTC_EDGE_NONE
);
275 void Edit::OnWhiteSpace (wxCommandEvent
&WXUNUSED(event
)) {
276 SetViewWhiteSpace (GetViewWhiteSpace() == 0?
277 wxSTC_WS_VISIBLEALWAYS
: wxSTC_WS_INVISIBLE
);
280 void Edit::OnFoldToggle (wxCommandEvent
&WXUNUSED(event
)) {
281 ToggleFold (GetFoldParent(GetCurrentLine()));
284 void Edit::OnSetOverType (wxCommandEvent
&WXUNUSED(event
)) {
285 SetOvertype (!GetOvertype());
288 void Edit::OnSetReadOnly (wxCommandEvent
&WXUNUSED(event
)) {
289 SetReadOnly (!GetReadOnly());
292 void Edit::OnWrapmodeOn (wxCommandEvent
&WXUNUSED(event
)) {
293 SetWrapMode (GetWrapMode() == 0? wxSTC_WRAP_WORD
: wxSTC_WRAP_NONE
);
296 void Edit::OnUseCharset (wxCommandEvent
&event
) {
298 int charset
= GetCodePage();
299 switch (event
.GetId()) {
300 case myID_CHARSETANSI
: {charset
= wxSTC_CHARSET_ANSI
; break;}
301 case myID_CHARSETMAC
: {charset
= wxSTC_CHARSET_ANSI
; break;}
303 for (Nr
= 0; Nr
< wxSTC_STYLE_LASTPREDEFINED
; Nr
++) {
304 StyleSetCharacterSet (Nr
, charset
);
306 SetCodePage (charset
);
309 void Edit::OnChangeCase (wxCommandEvent
&event
) {
310 switch (event
.GetId()) {
311 case myID_CHANGELOWER
: {
312 CmdKeyExecute (wxSTC_CMD_LOWERCASE
);
315 case myID_CHANGEUPPER
: {
316 CmdKeyExecute (wxSTC_CMD_UPPERCASE
);
322 void Edit::OnConvertEOL (wxCommandEvent
&event
) {
323 int eolMode
= GetEOLMode();
324 switch (event
.GetId()) {
325 case myID_CONVERTCR
: { eolMode
= wxSTC_EOL_CR
; break;}
326 case myID_CONVERTCRLF
: { eolMode
= wxSTC_EOL_CRLF
; break;}
327 case myID_CONVERTLF
: { eolMode
= wxSTC_EOL_LF
; break;}
329 ConvertEOLs (eolMode
);
330 SetEOLMode (eolMode
);
334 void Edit::OnMarginClick (wxStyledTextEvent
&event
) {
335 if (event
.GetMargin() == 2) {
336 int lineClick
= LineFromPosition (event
.GetPosition());
337 int levelClick
= GetFoldLevel (lineClick
);
338 if ((levelClick
& wxSTC_FOLDLEVELHEADERFLAG
) > 0) {
339 ToggleFold (lineClick
);
344 void Edit::OnCharAdded (wxStyledTextEvent
&event
) {
345 char chr
= event
.GetKey();
346 int currentLine
= GetCurrentLine();
347 // Change this if support for mac files with \r is needed
350 if (currentLine
> 0) {
351 lineInd
= GetLineIndentation(currentLine
- 1);
353 if (lineInd
== 0) return;
354 SetLineIndentation (currentLine
, lineInd
);
355 GotoPos(PositionFromLine (currentLine
) + lineInd
);
360 //----------------------------------------------------------------------------
362 wxString
Edit::DeterminePrefs (const wxString
&filename
) {
364 LanguageInfo
const* curInfo
= NULL
;
366 // determine language from filepatterns
368 for (languageNr
= 0; languageNr
< g_LanguagePrefsSize
; languageNr
++) {
369 curInfo
= &g_LanguagePrefs
[languageNr
];
370 wxString filepattern
= curInfo
->filepattern
;
372 while (!filepattern
.IsEmpty()) {
373 wxString cur
= filepattern
.BeforeFirst (';');
374 if ((cur
== filename
) ||
375 (cur
== (filename
.BeforeLast ('.') + _T(".*"))) ||
376 (cur
== (_T("*.") + filename
.AfterLast ('.')))) {
377 return curInfo
->name
;
379 filepattern
= filepattern
.AfterFirst (';');
382 return wxEmptyString
;
386 bool Edit::InitializePrefs (const wxString
&name
) {
390 LanguageInfo
const* curInfo
= NULL
;
392 // determine language
395 for (languageNr
= 0; languageNr
< g_LanguagePrefsSize
; languageNr
++) {
396 curInfo
= &g_LanguagePrefs
[languageNr
];
397 if (curInfo
->name
== name
) {
402 if (!found
) return false;
404 // set lexer and language
405 SetLexer (curInfo
->lexer
);
406 m_language
= curInfo
;
408 // set margin for line numbers
409 SetMarginType (m_LineNrID
, wxSTC_MARGIN_NUMBER
);
410 StyleSetForeground (wxSTC_STYLE_LINENUMBER
, wxColour (_T("DARK GREY")));
411 StyleSetBackground (wxSTC_STYLE_LINENUMBER
, wxColour (_T("WHITE")));
412 SetMarginWidth (m_LineNrID
,
413 g_CommonPrefs
.lineNumberEnable
? m_LineNrMargin
: 0);
415 // default fonts for all styles!
417 for (Nr
= 0; Nr
< wxSTC_STYLE_LASTPREDEFINED
; Nr
++) {
418 wxFont
font (10, wxMODERN
, wxNORMAL
, wxNORMAL
);
419 StyleSetFont (Nr
, font
);
423 StyleSetForeground (wxSTC_STYLE_DEFAULT
, wxColour (_T("DARK GREY")));
424 StyleSetForeground (wxSTC_STYLE_INDENTGUIDE
, wxColour (_T("DARK GREY")));
426 // initialize settings
427 if (g_CommonPrefs
.syntaxEnable
) {
429 for (Nr
= 0; Nr
< STYLE_TYPES_COUNT
; Nr
++) {
430 if (curInfo
->styles
[Nr
].type
== -1) continue;
431 const StyleInfo
&curType
= g_StylePrefs
[curInfo
->styles
[Nr
].type
];
432 wxFont
font (curType
.fontsize
, wxMODERN
, wxNORMAL
, wxNORMAL
, false,
434 StyleSetFont (Nr
, font
);
435 if (curType
.foreground
) {
436 StyleSetForeground (Nr
, wxColour (curType
.foreground
));
438 if (curType
.background
) {
439 StyleSetBackground (Nr
, wxColour (curType
.background
));
441 StyleSetBold (Nr
, (curType
.fontstyle
& mySTC_STYLE_BOLD
) > 0);
442 StyleSetItalic (Nr
, (curType
.fontstyle
& mySTC_STYLE_ITALIC
) > 0);
443 StyleSetUnderline (Nr
, (curType
.fontstyle
& mySTC_STYLE_UNDERL
) > 0);
444 StyleSetVisible (Nr
, (curType
.fontstyle
& mySTC_STYLE_HIDDEN
) == 0);
445 StyleSetCase (Nr
, curType
.lettercase
);
446 const wxChar
*pwords
= curInfo
->styles
[Nr
].words
;
448 SetKeyWords (keywordnr
, pwords
);
454 // set margin as unused
455 SetMarginType (m_DividerID
, wxSTC_MARGIN_SYMBOL
);
456 SetMarginWidth (m_DividerID
, 0);
457 SetMarginSensitive (m_DividerID
, false);
460 SetMarginType (m_FoldingID
, wxSTC_MARGIN_SYMBOL
);
461 SetMarginMask (m_FoldingID
, wxSTC_MASK_FOLDERS
);
462 StyleSetBackground (m_FoldingID
, wxColour (_T("WHITE")));
463 SetMarginWidth (m_FoldingID
, 0);
464 SetMarginSensitive (m_FoldingID
, false);
465 if (g_CommonPrefs
.foldEnable
) {
466 SetMarginWidth (m_FoldingID
, curInfo
->folds
!= 0? m_FoldingMargin
: 0);
467 SetMarginSensitive (m_FoldingID
, curInfo
->folds
!= 0);
468 SetProperty (_T("fold"), curInfo
->folds
!= 0? _T("1"): _T("0"));
469 SetProperty (_T("fold.comment"),
470 (curInfo
->folds
& mySTC_FOLD_COMMENT
) > 0? _T("1"): _T("0"));
471 SetProperty (_T("fold.compact"),
472 (curInfo
->folds
& mySTC_FOLD_COMPACT
) > 0? _T("1"): _T("0"));
473 SetProperty (_T("fold.preprocessor"),
474 (curInfo
->folds
& mySTC_FOLD_PREPROC
) > 0? _T("1"): _T("0"));
475 SetProperty (_T("fold.html"),
476 (curInfo
->folds
& mySTC_FOLD_HTML
) > 0? _T("1"): _T("0"));
477 SetProperty (_T("fold.html.preprocessor"),
478 (curInfo
->folds
& mySTC_FOLD_HTMLPREP
) > 0? _T("1"): _T("0"));
479 SetProperty (_T("fold.comment.python"),
480 (curInfo
->folds
& mySTC_FOLD_COMMENTPY
) > 0? _T("1"): _T("0"));
481 SetProperty (_T("fold.quotes.python"),
482 (curInfo
->folds
& mySTC_FOLD_QUOTESPY
) > 0? _T("1"): _T("0"));
484 SetFoldFlags (wxSTC_FOLDFLAG_LINEBEFORE_CONTRACTED
|
485 wxSTC_FOLDFLAG_LINEAFTER_CONTRACTED
);
487 // set spaces and indention
490 SetTabIndents (true);
491 SetBackSpaceUnIndents (true);
492 SetIndent (g_CommonPrefs
.indentEnable
? 4: 0);
495 SetViewEOL (g_CommonPrefs
.displayEOLEnable
);
496 SetIndentationGuides (g_CommonPrefs
.indentGuideEnable
);
498 SetEdgeMode (g_CommonPrefs
.longLineOnEnable
? wxSTC_EDGE_LINE
: wxSTC_EDGE_NONE
);
499 SetViewWhiteSpace (g_CommonPrefs
.whiteSpaceEnable
?
500 wxSTC_WS_VISIBLEALWAYS
: wxSTC_WS_INVISIBLE
);
501 SetOvertype (g_CommonPrefs
.overTypeInitial
);
502 SetReadOnly (g_CommonPrefs
.readOnlyInitial
);
503 SetWrapMode (g_CommonPrefs
.wrapModeInitial
?
504 wxSTC_WRAP_WORD
: wxSTC_WRAP_NONE
);
509 bool Edit::LoadFile () {
513 wxFileDialog
dlg (this, _T("Open file"), _T(""), _T(""),
514 _T("Any file (*)|*"), wxOPEN
| wxFILE_MUST_EXIST
| wxCHANGE_DIR
);
515 if (dlg
.ShowModal() != wxID_OK
) return false;
516 m_filename
= dlg
.GetPath();
520 return LoadFile (m_filename
);
523 bool Edit::LoadFile (const wxString
&filename
) {
525 // load file in edit and clear undo
526 if (!filename
.IsEmpty()) m_filename
= filename
;
527 // wxFile file (m_filename);
528 // if (!file.IsOpened()) return false;
530 // long lng = file.Length ();
533 // wxChar *buff = buf.GetWriteBuf (lng);
534 // file.Read (buff, lng);
535 // buf.UngetWriteBuf ();
536 // InsertText (0, buf);
540 wxStyledTextCtrl::LoadFile(m_filename
);
544 // determine lexer language
545 wxFileName
fname (m_filename
);
546 InitializePrefs (DeterminePrefs (fname
.GetFullName()));
551 bool Edit::SaveFile () {
553 // return if no change
554 if (!Modified()) return true;
558 wxFileDialog
dlg (this, _T("Save file"), _T(""), _T(""), _T("Any file (*)|*"),
559 wxSAVE
| wxOVERWRITE_PROMPT
);
560 if (dlg
.ShowModal() != wxID_OK
) return false;
561 m_filename
= dlg
.GetPath();
565 return SaveFile (m_filename
);
568 bool Edit::SaveFile (const wxString
&filename
) {
570 // return if no change
571 if (!Modified()) return true;
573 // // save edit in file and clear undo
574 // if (!filename.IsEmpty()) m_filename = filename;
575 // wxFile file (m_filename, wxFile::write);
576 // if (!file.IsOpened()) return false;
577 // wxString buf = GetText();
578 // bool okay = file.Write (buf);
580 // if (!okay) return false;
581 // EmptyUndoBuffer();
586 return wxStyledTextCtrl::SaveFile(filename
);
590 bool Edit::Modified () {
592 // return modified state
593 return (GetModify() && !GetReadOnly());
596 //----------------------------------------------------------------------------
598 //----------------------------------------------------------------------------
600 EditProperties::EditProperties (Edit
*edit
,
602 : wxDialog (edit
, -1, wxEmptyString
,
603 wxDefaultPosition
, wxDefaultSize
,
604 style
| wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
) {
606 // sets the application title
607 SetTitle (_("Properties"));
611 wxBoxSizer
*fullname
= new wxBoxSizer (wxHORIZONTAL
);
612 fullname
->Add (10, 0);
613 fullname
->Add (new wxStaticText (this, -1, _("Full filename"),
614 wxDefaultPosition
, wxSize(80, -1)),
615 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
);
616 fullname
->Add (new wxStaticText (this, -1, edit
->GetFilename()),
617 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
);
620 wxGridSizer
*textinfo
= new wxGridSizer (4, 0, 2);
621 textinfo
->Add (new wxStaticText (this, -1, _("Language"),
622 wxDefaultPosition
, wxSize(80, -1)),
623 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
624 textinfo
->Add (new wxStaticText (this, -1, edit
->m_language
->name
),
625 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
626 textinfo
->Add (new wxStaticText (this, -1, _("Lexer-ID: "),
627 wxDefaultPosition
, wxSize(80, -1)),
628 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
629 text
= wxString::Format (_T("%d"), edit
->GetLexer());
630 textinfo
->Add (new wxStaticText (this, -1, text
),
631 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
632 wxString EOLtype
= _T("");
633 switch (edit
->GetEOLMode()) {
634 case wxSTC_EOL_CR
: {EOLtype
= _T("CR (Unix)"); break; }
635 case wxSTC_EOL_CRLF
: {EOLtype
= _T("CRLF (Windows)"); break; }
636 case wxSTC_EOL_LF
: {EOLtype
= _T("CR (Macintosh)"); break; }
638 textinfo
->Add (new wxStaticText (this, -1, _("Line endings"),
639 wxDefaultPosition
, wxSize(80, -1)),
640 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
641 textinfo
->Add (new wxStaticText (this, -1, EOLtype
),
642 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
645 wxStaticBoxSizer
*textinfos
= new wxStaticBoxSizer (
646 new wxStaticBox (this, -1, _("Informations")),
648 textinfos
->Add (textinfo
, 0, wxEXPAND
);
649 textinfos
->Add (0, 6);
652 wxGridSizer
*statistic
= new wxGridSizer (4, 0, 2);
653 statistic
->Add (new wxStaticText (this, -1, _("Total lines"),
654 wxDefaultPosition
, wxSize(80, -1)),
655 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
656 text
= wxString::Format (_T("%d"), edit
->GetLineCount());
657 statistic
->Add (new wxStaticText (this, -1, text
),
658 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
659 statistic
->Add (new wxStaticText (this, -1, _("Total chars"),
660 wxDefaultPosition
, wxSize(80, -1)),
661 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
662 text
= wxString::Format (_T("%d"), edit
->GetTextLength());
663 statistic
->Add (new wxStaticText (this, -1, text
),
664 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
665 statistic
->Add (new wxStaticText (this, -1, _("Current line"),
666 wxDefaultPosition
, wxSize(80, -1)),
667 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
668 text
= wxString::Format (_T("%d"), edit
->GetCurrentLine());
669 statistic
->Add (new wxStaticText (this, -1, text
),
670 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
671 statistic
->Add (new wxStaticText (this, -1, _("Current pos"),
672 wxDefaultPosition
, wxSize(80, -1)),
673 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
674 text
= wxString::Format (_T("%d"), edit
->GetCurrentPos());
675 statistic
->Add (new wxStaticText (this, -1, text
),
676 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
678 // char/line statistics
679 wxStaticBoxSizer
*statistics
= new wxStaticBoxSizer (
680 new wxStaticBox (this, -1, _("Statistics")),
682 statistics
->Add (statistic
, 0, wxEXPAND
);
683 statistics
->Add (0, 6);
686 wxBoxSizer
*totalpane
= new wxBoxSizer (wxVERTICAL
);
687 totalpane
->Add (fullname
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
| wxTOP
, 10);
688 totalpane
->Add (0, 6);
689 totalpane
->Add (textinfos
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
690 totalpane
->Add (0, 10);
691 totalpane
->Add (statistics
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
692 totalpane
->Add (0, 6);
693 wxButton
*okButton
= new wxButton (this, wxID_OK
, _("OK"));
694 okButton
->SetDefault();
695 totalpane
->Add (okButton
, 0, wxALIGN_CENTER
| wxALL
, 10);
697 SetSizerAndFit (totalpane
);
702 //----------------------------------------------------------------------------
704 //----------------------------------------------------------------------------
706 EditPrint::EditPrint (Edit
*edit
, wxChar
*title
)
707 : wxPrintout(title
) {
713 bool EditPrint::OnPrintPage (int page
) {
716 if (!dc
) return false;
722 if (page
== 1) m_printed
= 0;
723 m_printed
= m_edit
->FormatRange (1, m_printed
, m_edit
->GetLength(),
724 dc
, dc
, m_printRect
, m_pageRect
);
729 bool EditPrint::OnBeginDocument (int startPage
, int endPage
) {
731 if (!wxPrintout::OnBeginDocument (startPage
, endPage
)) {
738 void EditPrint::GetPageInfo (int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
) {
746 // scale DC if possible
751 // get print page informations and convert to printer pixels
753 GetPPIScreen (&ppiScr
.x
, &ppiScr
.y
);
754 wxSize page
= g_pageSetupData
->GetPaperSize();
755 page
.x
= static_cast<int> (page
.x
* ppiScr
.x
/ 25.4);
756 page
.y
= static_cast<int> (page
.y
* ppiScr
.y
/ 25.4);
757 m_pageRect
= wxRect (0,
762 // get margins informations and convert to printer pixels
763 int top
= 25; // default 25
764 int bottom
= 25; // default 25
765 int left
= 20; // default 20
766 int right
= 20; // default 20
767 wxPoint (top
, left
) = g_pageSetupData
->GetMarginTopLeft();
768 wxPoint (bottom
, right
) = g_pageSetupData
->GetMarginBottomRight();
769 top
= static_cast<int> (top
* ppiScr
.y
/ 25.4);
770 bottom
= static_cast<int> (bottom
* ppiScr
.y
/ 25.4);
771 left
= static_cast<int> (left
* ppiScr
.x
/ 25.4);
772 right
= static_cast<int> (right
* ppiScr
.x
/ 25.4);
773 m_printRect
= wxRect (left
,
775 page
.x
- (left
+ right
),
776 page
.y
- (top
+ bottom
));
779 while (HasPage (*maxPage
)) {
780 m_printed
= m_edit
->FormatRange (0, m_printed
, m_edit
->GetLength(),
781 dc
, dc
, m_printRect
, m_pageRect
);
784 if (*maxPage
> 0) *minPage
= 1;
785 *selPageFrom
= *minPage
;
786 *selPageTo
= *maxPage
;
789 bool EditPrint::HasPage (int WXUNUSED(page
)) {
791 return (m_printed
< m_edit
->GetLength());
794 bool EditPrint::PrintScaling (wxDC
*dc
){
796 // check for dc, return if none
797 if (!dc
) return false;
799 // get printer and screen sizing values
801 GetPPIScreen (&ppiScr
.x
, &ppiScr
.y
);
802 if (ppiScr
.x
== 0) { // most possible guess 96 dpi
807 GetPPIPrinter (&ppiPrt
.x
, &ppiPrt
.y
);
808 if (ppiPrt
.x
== 0) { // scaling factor to 1
812 wxSize dcSize
= dc
->GetSize();
814 GetPageSizePixels (&pageSize
.x
, &pageSize
.y
);
817 float scale_x
= (float)(ppiPrt
.x
* dcSize
.x
) /
818 (float)(ppiScr
.x
* pageSize
.x
);
819 float scale_y
= (float)(ppiPrt
.y
* dcSize
.y
) /
820 (float)(ppiScr
.y
* pageSize
.y
);
821 dc
->SetUserScale (scale_x
, scale_y
);