1 //////////////////////////////////////////////////////////////////////////////
2 // File: contrib/samples/stc/edit.cpp
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' wxWidgets 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 (wxID_ANY
, Edit::OnMarginClick
)
104 EVT_STC_CHARADDED (wxID_ANY
, Edit::OnCharAdded
)
105 EVT_STC_KEY( wxID_ANY
, Edit::OnKey
)
108 Edit::Edit (wxWindow
*parent
, wxWindowID id
,
112 : wxStyledTextCtrl (parent
, id
, pos
, size
, style
) {
114 m_filename
= wxEmptyString
;
120 // initialize language
123 // default font for all styles
124 SetViewEOL (g_CommonPrefs
.displayEOLEnable
);
125 SetIndentationGuides (g_CommonPrefs
.indentGuideEnable
);
126 SetEdgeMode (g_CommonPrefs
.longLineOnEnable
?
127 wxSTC_EDGE_LINE
: wxSTC_EDGE_NONE
);
128 SetViewWhiteSpace (g_CommonPrefs
.whiteSpaceEnable
?
129 wxSTC_WS_VISIBLEALWAYS
: wxSTC_WS_INVISIBLE
);
130 SetOvertype (g_CommonPrefs
.overTypeInitial
);
131 SetReadOnly (g_CommonPrefs
.readOnlyInitial
);
132 SetWrapMode (g_CommonPrefs
.wrapModeInitial
?
133 wxSTC_WRAP_WORD
: wxSTC_WRAP_NONE
);
134 wxFont
font (10, wxMODERN
, wxNORMAL
, wxNORMAL
);
135 StyleSetFont (wxSTC_STYLE_DEFAULT
, font
);
136 StyleSetForeground (wxSTC_STYLE_DEFAULT
, *wxBLACK
);
137 StyleSetBackground (wxSTC_STYLE_DEFAULT
, *wxWHITE
);
138 StyleSetForeground (wxSTC_STYLE_LINENUMBER
, wxColour (wxT("DARK GREY")));
139 StyleSetBackground (wxSTC_STYLE_LINENUMBER
, *wxWHITE
);
140 StyleSetForeground(wxSTC_STYLE_INDENTGUIDE
, wxColour (wxT("DARK GREY")));
141 InitializePrefs (DEFAULT_LANGUAGE
);
144 SetVisiblePolicy (wxSTC_VISIBLE_STRICT
|wxSTC_VISIBLE_SLOP
, 1);
145 SetXCaretPolicy (wxSTC_CARET_EVEN
|wxSTC_VISIBLE_STRICT
|wxSTC_CARET_SLOP
, 1);
146 SetYCaretPolicy (wxSTC_CARET_EVEN
|wxSTC_VISIBLE_STRICT
|wxSTC_CARET_SLOP
, 1);
149 MarkerDefine (wxSTC_MARKNUM_FOLDER
, wxSTC_MARK_DOTDOTDOT
, wxT("BLACK"), wxT("BLACK"));
150 MarkerDefine (wxSTC_MARKNUM_FOLDEROPEN
, wxSTC_MARK_ARROWDOWN
, wxT("BLACK"), wxT("BLACK"));
151 MarkerDefine (wxSTC_MARKNUM_FOLDERSUB
, wxSTC_MARK_EMPTY
, wxT("BLACK"), wxT("BLACK"));
152 MarkerDefine (wxSTC_MARKNUM_FOLDEREND
, wxSTC_MARK_DOTDOTDOT
, wxT("BLACK"), wxT("WHITE"));
153 MarkerDefine (wxSTC_MARKNUM_FOLDEROPENMID
, wxSTC_MARK_ARROWDOWN
, wxT("BLACK"), wxT("WHITE"));
154 MarkerDefine (wxSTC_MARKNUM_FOLDERMIDTAIL
, wxSTC_MARK_EMPTY
, wxT("BLACK"), wxT("BLACK"));
155 MarkerDefine (wxSTC_MARKNUM_FOLDERTAIL
, wxSTC_MARK_EMPTY
, wxT("BLACK"), wxT("BLACK"));
158 m_LineNrMargin
= TextWidth (wxSTC_STYLE_LINENUMBER
, wxT("_999999"));
159 m_FoldingMargin
= 16;
160 CmdKeyClear (wxSTC_KEY_TAB
, 0); // this is done by the menu accelerator key
161 SetLayoutCache (wxSTC_CACHE_PAGE
);
167 //----------------------------------------------------------------------------
168 // common event handlers
169 void Edit::OnSize( wxSizeEvent
& event
) {
170 int x
= GetClientSize().x
+
171 (g_CommonPrefs
.lineNumberEnable
? m_LineNrMargin
: 0) +
172 (g_CommonPrefs
.foldEnable
? m_FoldingMargin
: 0);
173 if (x
> 0) SetScrollWidth (x
);
177 // edit event handlers
178 void Edit::OnEditRedo (wxCommandEvent
&WXUNUSED(event
)) {
179 if (!CanRedo()) return;
183 void Edit::OnEditUndo (wxCommandEvent
&WXUNUSED(event
)) {
184 if (!CanUndo()) return;
188 void Edit::OnEditClear (wxCommandEvent
&WXUNUSED(event
)) {
189 if (GetReadOnly()) return;
193 void Edit::OnKey (wxStyledTextEvent
&WXUNUSED(event
))
195 wxMessageBox("OnKey");
198 void Edit::OnEditCut (wxCommandEvent
&WXUNUSED(event
)) {
199 if (GetReadOnly() || (GetSelectionEnd()-GetSelectionStart() <= 0)) return;
203 void Edit::OnEditCopy (wxCommandEvent
&WXUNUSED(event
)) {
204 if (GetSelectionEnd()-GetSelectionStart() <= 0) return;
208 void Edit::OnEditPaste (wxCommandEvent
&WXUNUSED(event
)) {
209 if (!CanPaste()) return;
213 void Edit::OnFind (wxCommandEvent
&WXUNUSED(event
)) {
216 void Edit::OnFindNext (wxCommandEvent
&WXUNUSED(event
)) {
219 void Edit::OnReplace (wxCommandEvent
&WXUNUSED(event
)) {
222 void Edit::OnReplaceNext (wxCommandEvent
&WXUNUSED(event
)) {
225 void Edit::OnBraceMatch (wxCommandEvent
&WXUNUSED(event
)) {
226 int min
= GetCurrentPos ();
227 int max
= BraceMatch (min
);
229 BraceHighlight (min
+1, max
);
230 SetSelection (min
+1, max
);
236 void Edit::OnGoto (wxCommandEvent
&WXUNUSED(event
)) {
239 void Edit::OnEditIndentInc (wxCommandEvent
&WXUNUSED(event
)) {
240 CmdKeyExecute (wxSTC_CMD_TAB
);
243 void Edit::OnEditIndentRed (wxCommandEvent
&WXUNUSED(event
)) {
244 CmdKeyExecute (wxSTC_CMD_DELETEBACK
);
247 void Edit::OnEditSelectAll (wxCommandEvent
&WXUNUSED(event
)) {
248 SetSelection (0, GetTextLength ());
251 void Edit::OnEditSelectLine (wxCommandEvent
&WXUNUSED(event
)) {
252 int lineStart
= PositionFromLine (GetCurrentLine());
253 int lineEnd
= PositionFromLine (GetCurrentLine() + 1);
254 SetSelection (lineStart
, lineEnd
);
257 void Edit::OnHilightLang (wxCommandEvent
&event
) {
258 InitializePrefs (g_LanguagePrefs
[event
.GetId() - myID_HILIGHTFIRST
].name
);
261 void Edit::OnDisplayEOL (wxCommandEvent
&WXUNUSED(event
)) {
262 SetViewEOL (!GetViewEOL());
265 void Edit::OnIndentGuide (wxCommandEvent
&WXUNUSED(event
)) {
266 SetIndentationGuides (!GetIndentationGuides());
269 void Edit::OnLineNumber (wxCommandEvent
&WXUNUSED(event
)) {
270 SetMarginWidth (m_LineNrID
,
271 GetMarginWidth (m_LineNrID
) == 0? m_LineNrMargin
: 0);
274 void Edit::OnLongLineOn (wxCommandEvent
&WXUNUSED(event
)) {
275 SetEdgeMode (GetEdgeMode() == 0? wxSTC_EDGE_LINE
: wxSTC_EDGE_NONE
);
278 void Edit::OnWhiteSpace (wxCommandEvent
&WXUNUSED(event
)) {
279 SetViewWhiteSpace (GetViewWhiteSpace() == 0?
280 wxSTC_WS_VISIBLEALWAYS
: wxSTC_WS_INVISIBLE
);
283 void Edit::OnFoldToggle (wxCommandEvent
&WXUNUSED(event
)) {
284 ToggleFold (GetFoldParent(GetCurrentLine()));
287 void Edit::OnSetOverType (wxCommandEvent
&WXUNUSED(event
)) {
288 SetOvertype (!GetOvertype());
291 void Edit::OnSetReadOnly (wxCommandEvent
&WXUNUSED(event
)) {
292 SetReadOnly (!GetReadOnly());
295 void Edit::OnWrapmodeOn (wxCommandEvent
&WXUNUSED(event
)) {
296 SetWrapMode (GetWrapMode() == 0? wxSTC_WRAP_WORD
: wxSTC_WRAP_NONE
);
299 void Edit::OnUseCharset (wxCommandEvent
&event
) {
301 int charset
= GetCodePage();
302 switch (event
.GetId()) {
303 case myID_CHARSETANSI
: {charset
= wxSTC_CHARSET_ANSI
; break;}
304 case myID_CHARSETMAC
: {charset
= wxSTC_CHARSET_ANSI
; break;}
306 for (Nr
= 0; Nr
< wxSTC_STYLE_LASTPREDEFINED
; Nr
++) {
307 StyleSetCharacterSet (Nr
, charset
);
309 SetCodePage (charset
);
312 void Edit::OnChangeCase (wxCommandEvent
&event
) {
313 switch (event
.GetId()) {
314 case myID_CHANGELOWER
: {
315 CmdKeyExecute (wxSTC_CMD_LOWERCASE
);
318 case myID_CHANGEUPPER
: {
319 CmdKeyExecute (wxSTC_CMD_UPPERCASE
);
325 void Edit::OnConvertEOL (wxCommandEvent
&event
) {
326 int eolMode
= GetEOLMode();
327 switch (event
.GetId()) {
328 case myID_CONVERTCR
: { eolMode
= wxSTC_EOL_CR
; break;}
329 case myID_CONVERTCRLF
: { eolMode
= wxSTC_EOL_CRLF
; break;}
330 case myID_CONVERTLF
: { eolMode
= wxSTC_EOL_LF
; break;}
332 ConvertEOLs (eolMode
);
333 SetEOLMode (eolMode
);
337 void Edit::OnMarginClick (wxStyledTextEvent
&event
) {
338 if (event
.GetMargin() == 2) {
339 int lineClick
= LineFromPosition (event
.GetPosition());
340 int levelClick
= GetFoldLevel (lineClick
);
341 if ((levelClick
& wxSTC_FOLDLEVELHEADERFLAG
) > 0) {
342 ToggleFold (lineClick
);
347 void Edit::OnCharAdded (wxStyledTextEvent
&event
) {
348 char chr
= (char)event
.GetKey();
349 int currentLine
= GetCurrentLine();
350 // Change this if support for mac files with \r is needed
353 if (currentLine
> 0) {
354 lineInd
= GetLineIndentation(currentLine
- 1);
356 if (lineInd
== 0) return;
357 SetLineIndentation (currentLine
, lineInd
);
358 GotoPos(PositionFromLine (currentLine
) + lineInd
);
363 //----------------------------------------------------------------------------
365 wxString
Edit::DeterminePrefs (const wxString
&filename
) {
367 LanguageInfo
const* curInfo
;
369 // determine language from filepatterns
371 for (languageNr
= 0; languageNr
< g_LanguagePrefsSize
; languageNr
++) {
372 curInfo
= &g_LanguagePrefs
[languageNr
];
373 wxString filepattern
= curInfo
->filepattern
;
375 while (!filepattern
.empty()) {
376 wxString cur
= filepattern
.BeforeFirst (';');
377 if ((cur
== filename
) ||
378 (cur
== (filename
.BeforeLast ('.') + wxT(".*"))) ||
379 (cur
== (wxT("*.") + filename
.AfterLast ('.')))) {
380 return curInfo
->name
;
382 filepattern
= filepattern
.AfterFirst (';');
385 return wxEmptyString
;
389 bool Edit::InitializePrefs (const wxString
&name
) {
393 LanguageInfo
const* curInfo
= NULL
;
395 // determine language
398 for (languageNr
= 0; languageNr
< g_LanguagePrefsSize
; languageNr
++) {
399 curInfo
= &g_LanguagePrefs
[languageNr
];
400 if (curInfo
->name
== name
) {
405 if (!found
) return false;
407 // set lexer and language
408 SetLexer (curInfo
->lexer
);
409 m_language
= curInfo
;
411 // set margin for line numbers
412 SetMarginType (m_LineNrID
, wxSTC_MARGIN_NUMBER
);
413 StyleSetForeground (wxSTC_STYLE_LINENUMBER
, wxColour (wxT("DARK GREY")));
414 StyleSetBackground (wxSTC_STYLE_LINENUMBER
, *wxWHITE
);
415 SetMarginWidth (m_LineNrID
, 0); // start out not visible
417 // default fonts for all styles!
419 for (Nr
= 0; Nr
< wxSTC_STYLE_LASTPREDEFINED
; Nr
++) {
420 wxFont
font (10, wxMODERN
, wxNORMAL
, wxNORMAL
);
421 StyleSetFont (Nr
, font
);
425 StyleSetForeground (wxSTC_STYLE_DEFAULT
, wxColour (wxT("DARK GREY")));
426 StyleSetForeground (wxSTC_STYLE_INDENTGUIDE
, wxColour (wxT("DARK GREY")));
428 // initialize settings
429 if (g_CommonPrefs
.syntaxEnable
) {
431 for (Nr
= 0; Nr
< STYLE_TYPES_COUNT
; Nr
++) {
432 if (curInfo
->styles
[Nr
].type
== -1) continue;
433 const StyleInfo
&curType
= g_StylePrefs
[curInfo
->styles
[Nr
].type
];
434 wxFont
font (curType
.fontsize
, wxMODERN
, wxNORMAL
, wxNORMAL
, false,
436 StyleSetFont (Nr
, font
);
437 if (curType
.foreground
) {
438 StyleSetForeground (Nr
, wxColour (curType
.foreground
));
440 if (curType
.background
) {
441 StyleSetBackground (Nr
, wxColour (curType
.background
));
443 StyleSetBold (Nr
, (curType
.fontstyle
& mySTC_STYLE_BOLD
) > 0);
444 StyleSetItalic (Nr
, (curType
.fontstyle
& mySTC_STYLE_ITALIC
) > 0);
445 StyleSetUnderline (Nr
, (curType
.fontstyle
& mySTC_STYLE_UNDERL
) > 0);
446 StyleSetVisible (Nr
, (curType
.fontstyle
& mySTC_STYLE_HIDDEN
) == 0);
447 StyleSetCase (Nr
, curType
.lettercase
);
448 const char *pwords
= curInfo
->styles
[Nr
].words
;
450 SetKeyWords (keywordnr
, pwords
);
456 // set margin as unused
457 SetMarginType (m_DividerID
, wxSTC_MARGIN_SYMBOL
);
458 SetMarginWidth (m_DividerID
, 0);
459 SetMarginSensitive (m_DividerID
, false);
462 SetMarginType (m_FoldingID
, wxSTC_MARGIN_SYMBOL
);
463 SetMarginMask (m_FoldingID
, wxSTC_MASK_FOLDERS
);
464 StyleSetBackground (m_FoldingID
, *wxWHITE
);
465 SetMarginWidth (m_FoldingID
, 0);
466 SetMarginSensitive (m_FoldingID
, false);
467 if (g_CommonPrefs
.foldEnable
) {
468 SetMarginWidth (m_FoldingID
, curInfo
->folds
!= 0? m_FoldingMargin
: 0);
469 SetMarginSensitive (m_FoldingID
, curInfo
->folds
!= 0);
470 SetProperty (wxT("fold"), curInfo
->folds
!= 0? wxT("1"): wxT("0"));
471 SetProperty (wxT("fold.comment"),
472 (curInfo
->folds
& mySTC_FOLD_COMMENT
) > 0? wxT("1"): wxT("0"));
473 SetProperty (wxT("fold.compact"),
474 (curInfo
->folds
& mySTC_FOLD_COMPACT
) > 0? wxT("1"): wxT("0"));
475 SetProperty (wxT("fold.preprocessor"),
476 (curInfo
->folds
& mySTC_FOLD_PREPROC
) > 0? wxT("1"): wxT("0"));
477 SetProperty (wxT("fold.html"),
478 (curInfo
->folds
& mySTC_FOLD_HTML
) > 0? wxT("1"): wxT("0"));
479 SetProperty (wxT("fold.html.preprocessor"),
480 (curInfo
->folds
& mySTC_FOLD_HTMLPREP
) > 0? wxT("1"): wxT("0"));
481 SetProperty (wxT("fold.comment.python"),
482 (curInfo
->folds
& mySTC_FOLD_COMMENTPY
) > 0? wxT("1"): wxT("0"));
483 SetProperty (wxT("fold.quotes.python"),
484 (curInfo
->folds
& mySTC_FOLD_QUOTESPY
) > 0? wxT("1"): wxT("0"));
486 SetFoldFlags (wxSTC_FOLDFLAG_LINEBEFORE_CONTRACTED
|
487 wxSTC_FOLDFLAG_LINEAFTER_CONTRACTED
);
489 // set spaces and indention
492 SetTabIndents (true);
493 SetBackSpaceUnIndents (true);
494 SetIndent (g_CommonPrefs
.indentEnable
? 4: 0);
497 SetViewEOL (g_CommonPrefs
.displayEOLEnable
);
498 SetIndentationGuides (g_CommonPrefs
.indentGuideEnable
);
500 SetEdgeMode (g_CommonPrefs
.longLineOnEnable
? wxSTC_EDGE_LINE
: wxSTC_EDGE_NONE
);
501 SetViewWhiteSpace (g_CommonPrefs
.whiteSpaceEnable
?
502 wxSTC_WS_VISIBLEALWAYS
: wxSTC_WS_INVISIBLE
);
503 SetOvertype (g_CommonPrefs
.overTypeInitial
);
504 SetReadOnly (g_CommonPrefs
.readOnlyInitial
);
505 SetWrapMode (g_CommonPrefs
.wrapModeInitial
?
506 wxSTC_WRAP_WORD
: wxSTC_WRAP_NONE
);
511 bool Edit::LoadFile ()
516 wxFileDialog
dlg (this, wxT("Open file"), wxEmptyString
, wxEmptyString
,
517 wxT("Any file (*)|*"), wxFD_OPEN
| wxFD_FILE_MUST_EXIST
| wxFD_CHANGE_DIR
);
518 if (dlg
.ShowModal() != wxID_OK
) return false;
519 m_filename
= dlg
.GetPath();
523 return LoadFile (m_filename
);
526 #endif // wxUSE_FILEDLG
529 bool Edit::LoadFile (const wxString
&filename
) {
531 // load file in edit and clear undo
532 if (!filename
.empty()) m_filename
= filename
;
533 // wxFile file (m_filename);
534 // if (!file.IsOpened()) return false;
536 // long lng = file.Length ();
539 // wxChar *buff = buf.GetWriteBuf (lng);
540 // file.Read (buff, lng);
541 // buf.UngetWriteBuf ();
542 // InsertText (0, buf);
546 wxStyledTextCtrl::LoadFile(m_filename
);
550 // determine lexer language
551 wxFileName
fname (m_filename
);
552 InitializePrefs (DeterminePrefs (fname
.GetFullName()));
557 bool Edit::SaveFile ()
560 // return if no change
561 if (!Modified()) return true;
565 wxFileDialog
dlg (this, wxT("Save file"), wxEmptyString
, wxEmptyString
, wxT("Any file (*)|*"),
566 wxFD_SAVE
| wxFD_OVERWRITE_PROMPT
);
567 if (dlg
.ShowModal() != wxID_OK
) return false;
568 m_filename
= dlg
.GetPath();
572 return SaveFile (m_filename
);
575 #endif // wxUSE_FILEDLG
578 bool Edit::SaveFile (const wxString
&filename
) {
580 // return if no change
581 if (!Modified()) return true;
583 // // save edit in file and clear undo
584 // if (!filename.empty()) m_filename = filename;
585 // wxFile file (m_filename, wxFile::write);
586 // if (!file.IsOpened()) return false;
587 // wxString buf = GetText();
588 // bool okay = file.Write (buf);
590 // if (!okay) return false;
591 // EmptyUndoBuffer();
596 return wxStyledTextCtrl::SaveFile(filename
);
600 bool Edit::Modified () {
602 // return modified state
603 return (GetModify() && !GetReadOnly());
606 //----------------------------------------------------------------------------
608 //----------------------------------------------------------------------------
610 EditProperties::EditProperties (Edit
*edit
,
612 : wxDialog (edit
, wxID_ANY
, wxEmptyString
,
613 wxDefaultPosition
, wxDefaultSize
,
614 style
| wxDEFAULT_DIALOG_STYLE
| wxRESIZE_BORDER
) {
616 // sets the application title
617 SetTitle (_("Properties"));
621 wxBoxSizer
*fullname
= new wxBoxSizer (wxHORIZONTAL
);
622 fullname
->Add (10, 0);
623 fullname
->Add (new wxStaticText (this, wxID_ANY
, _("Full filename"),
624 wxDefaultPosition
, wxSize(80, wxDefaultCoord
)),
625 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
);
626 fullname
->Add (new wxStaticText (this, wxID_ANY
, edit
->GetFilename()),
627 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
);
630 wxGridSizer
*textinfo
= new wxGridSizer (4, 0, 2);
631 textinfo
->Add (new wxStaticText (this, wxID_ANY
, _("Language"),
632 wxDefaultPosition
, wxSize(80, wxDefaultCoord
)),
633 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
634 textinfo
->Add (new wxStaticText (this, wxID_ANY
, edit
->m_language
->name
),
635 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
636 textinfo
->Add (new wxStaticText (this, wxID_ANY
, _("Lexer-ID: "),
637 wxDefaultPosition
, wxSize(80, wxDefaultCoord
)),
638 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
639 text
= wxString::Format (wxT("%d"), edit
->GetLexer());
640 textinfo
->Add (new wxStaticText (this, wxID_ANY
, text
),
641 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
642 wxString EOLtype
= wxEmptyString
;
643 switch (edit
->GetEOLMode()) {
644 case wxSTC_EOL_CR
: {EOLtype
= wxT("CR (Unix)"); break; }
645 case wxSTC_EOL_CRLF
: {EOLtype
= wxT("CRLF (Windows)"); break; }
646 case wxSTC_EOL_LF
: {EOLtype
= wxT("CR (Macintosh)"); break; }
648 textinfo
->Add (new wxStaticText (this, wxID_ANY
, _("Line endings"),
649 wxDefaultPosition
, wxSize(80, wxDefaultCoord
)),
650 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
651 textinfo
->Add (new wxStaticText (this, wxID_ANY
, EOLtype
),
652 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
655 wxStaticBoxSizer
*textinfos
= new wxStaticBoxSizer (
656 new wxStaticBox (this, wxID_ANY
, _("Informations")),
658 textinfos
->Add (textinfo
, 0, wxEXPAND
);
659 textinfos
->Add (0, 6);
662 wxGridSizer
*statistic
= new wxGridSizer (4, 0, 2);
663 statistic
->Add (new wxStaticText (this, wxID_ANY
, _("Total lines"),
664 wxDefaultPosition
, wxSize(80, wxDefaultCoord
)),
665 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
666 text
= wxString::Format (wxT("%d"), edit
->GetLineCount());
667 statistic
->Add (new wxStaticText (this, wxID_ANY
, text
),
668 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
669 statistic
->Add (new wxStaticText (this, wxID_ANY
, _("Total chars"),
670 wxDefaultPosition
, wxSize(80, wxDefaultCoord
)),
671 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
672 text
= wxString::Format (wxT("%d"), edit
->GetTextLength());
673 statistic
->Add (new wxStaticText (this, wxID_ANY
, text
),
674 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
675 statistic
->Add (new wxStaticText (this, wxID_ANY
, _("Current line"),
676 wxDefaultPosition
, wxSize(80, wxDefaultCoord
)),
677 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
678 text
= wxString::Format (wxT("%d"), edit
->GetCurrentLine());
679 statistic
->Add (new wxStaticText (this, wxID_ANY
, text
),
680 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
681 statistic
->Add (new wxStaticText (this, wxID_ANY
, _("Current pos"),
682 wxDefaultPosition
, wxSize(80, wxDefaultCoord
)),
683 0, wxALIGN_LEFT
|wxALIGN_CENTER_VERTICAL
|wxLEFT
, 4);
684 text
= wxString::Format (wxT("%d"), edit
->GetCurrentPos());
685 statistic
->Add (new wxStaticText (this, wxID_ANY
, text
),
686 0, wxALIGN_RIGHT
|wxALIGN_CENTER_VERTICAL
|wxRIGHT
, 4);
688 // char/line statistics
689 wxStaticBoxSizer
*statistics
= new wxStaticBoxSizer (
690 new wxStaticBox (this, wxID_ANY
, _("Statistics")),
692 statistics
->Add (statistic
, 0, wxEXPAND
);
693 statistics
->Add (0, 6);
696 wxBoxSizer
*totalpane
= new wxBoxSizer (wxVERTICAL
);
697 totalpane
->Add (fullname
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
| wxTOP
, 10);
698 totalpane
->Add (0, 6);
699 totalpane
->Add (textinfos
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
700 totalpane
->Add (0, 10);
701 totalpane
->Add (statistics
, 0, wxEXPAND
| wxLEFT
| wxRIGHT
, 10);
702 totalpane
->Add (0, 6);
703 wxButton
*okButton
= new wxButton (this, wxID_OK
, _("OK"));
704 okButton
->SetDefault();
705 totalpane
->Add (okButton
, 0, wxALIGN_CENTER
| wxALL
, 10);
707 SetSizerAndFit (totalpane
);
712 #if wxUSE_PRINTING_ARCHITECTURE
714 //----------------------------------------------------------------------------
716 //----------------------------------------------------------------------------
718 EditPrint::EditPrint (Edit
*edit
, const wxChar
*title
)
719 : wxPrintout(title
) {
725 bool EditPrint::OnPrintPage (int page
) {
728 if (!dc
) return false;
734 if (page
== 1) m_printed
= 0;
735 m_printed
= m_edit
->FormatRange (1, m_printed
, m_edit
->GetLength(),
736 dc
, dc
, m_printRect
, m_pageRect
);
741 bool EditPrint::OnBeginDocument (int startPage
, int endPage
) {
743 if (!wxPrintout::OnBeginDocument (startPage
, endPage
)) {
750 void EditPrint::GetPageInfo (int *minPage
, int *maxPage
, int *selPageFrom
, int *selPageTo
) {
758 // scale DC if possible
763 // get print page informations and convert to printer pixels
765 GetPPIScreen (&ppiScr
.x
, &ppiScr
.y
);
766 wxSize page
= g_pageSetupData
->GetPaperSize();
767 page
.x
= static_cast<int> (page
.x
* ppiScr
.x
/ 25.4);
768 page
.y
= static_cast<int> (page
.y
* ppiScr
.y
/ 25.4);
769 m_pageRect
= wxRect (0,
774 // get margins informations and convert to printer pixels
775 wxPoint pt
= g_pageSetupData
->GetMarginTopLeft();
778 pt
= g_pageSetupData
->GetMarginBottomRight();
782 top
= static_cast<int> (top
* ppiScr
.y
/ 25.4);
783 bottom
= static_cast<int> (bottom
* ppiScr
.y
/ 25.4);
784 left
= static_cast<int> (left
* ppiScr
.x
/ 25.4);
785 right
= static_cast<int> (right
* ppiScr
.x
/ 25.4);
787 m_printRect
= wxRect (left
,
789 page
.x
- (left
+ right
),
790 page
.y
- (top
+ bottom
));
793 while (HasPage (*maxPage
)) {
794 m_printed
= m_edit
->FormatRange (0, m_printed
, m_edit
->GetLength(),
795 dc
, dc
, m_printRect
, m_pageRect
);
798 if (*maxPage
> 0) *minPage
= 1;
799 *selPageFrom
= *minPage
;
800 *selPageTo
= *maxPage
;
803 bool EditPrint::HasPage (int WXUNUSED(page
)) {
805 return (m_printed
< m_edit
->GetLength());
808 bool EditPrint::PrintScaling (wxDC
*dc
){
810 // check for dc, return if none
811 if (!dc
) return false;
813 // get printer and screen sizing values
815 GetPPIScreen (&ppiScr
.x
, &ppiScr
.y
);
816 if (ppiScr
.x
== 0) { // most possible guess 96 dpi
821 GetPPIPrinter (&ppiPrt
.x
, &ppiPrt
.y
);
822 if (ppiPrt
.x
== 0) { // scaling factor to 1
826 wxSize dcSize
= dc
->GetSize();
828 GetPageSizePixels (&pageSize
.x
, &pageSize
.y
);
831 float scale_x
= (float)(ppiPrt
.x
* dcSize
.x
) /
832 (float)(ppiScr
.x
* pageSize
.x
);
833 float scale_y
= (float)(ppiPrt
.y
* dcSize
.y
) /
834 (float)(ppiScr
.y
* pageSize
.y
);
835 dc
->SetUserScale (scale_x
, scale_y
);
840 #endif // wxUSE_PRINTING_ARCHITECTURE