00001
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044 #include "Defs.h"
00045 #include "mhDefs.h"
00046
00047 #include <iostream>
00048
00049 #include "wx/wxprec.h"
00050 #include "wx/ffile.h"
00051
00052 #ifdef __BORLANDC__
00053 #pragma hdrstop
00054 #endif
00055
00056 #ifndef WX_PRECOMP
00057 #include "wx/wx.h"
00058 #include "wx/mdi.h"
00059 #include "wx/filename.h"
00060 #include "wx/textfile.h"
00061 #endif
00062
00063 #include "wx/toolbar.h"
00064
00065
00066 #ifdef __WXMSW__
00067 #include "wx/msw/private.h"
00068
00069 #if wxUSE_RICHEDIT
00070
00071 #if wxUSE_INKEDIT
00072 #include "wx/dynlib.h"
00073 #endif
00074
00075
00076
00077 #if !defined(__GNUWIN32_OLD__) || defined(__CYGWIN10__)
00078 #include <richedit.h>
00079 #endif
00080
00081 #endif // wxUSE_RICHEDIT
00082 #endif // __WXMSW__
00083
00084
00085
00086 #include "MutFrame.h"
00087 #include "MutEditFile.h"
00088 #include "CompDlg.h"
00089 #include "Runtime.h"
00090 #include "MutView.h"
00091 #include "stclanguage.h"
00092
00093 CompDlg *CompDia = NULL;
00094
00095
00096
00097
00098 using mutaborGUI::MutEditFile;
00099 BEGIN_EVENT_TABLE(MutEditFile, wxStyledTextCtrl)
00100
00101
00102
00103 EVT_MENU(CM_COMPILE, MutEditFile::CmCompile)
00104 EVT_MENU(CM_COMPACT, MutEditFile::CmCompAct)
00105 EVT_MENU(CM_ACTIVATE, MutEditFile::CmCompAct)
00106 EVT_MENU(CM_GETLINE, MutEditFile::CmGetLine)
00107 EVT_MENU(CM_HELPCONTEXT, MutEditFile::CmHelpContext)
00108
00109 EVT_SIZE ( MutEditFile::OnSize)
00110
00111 EVT_MENU (wxID_CLEAR, MutEditFile::OnEditClear)
00112 EVT_MENU (wxID_CUT, MutEditFile::OnEditCut)
00113 EVT_MENU (wxID_COPY, MutEditFile::OnEditCopy)
00114 EVT_MENU (wxID_PASTE, MutEditFile::OnEditPaste)
00115 EVT_MENU (CM_INDENTINC, MutEditFile::OnEditIndentInc)
00116 EVT_MENU (CM_INDENTRED, MutEditFile::OnEditIndentRed)
00117 EVT_MENU (wxID_SELECTALL, MutEditFile::OnEditSelectAll)
00118 EVT_MENU (CM_SELECTLINE, MutEditFile::OnEditSelectLine)
00119 EVT_MENU (wxID_REDO, MutEditFile::OnEditRedo)
00120 EVT_MENU (wxID_UNDO, MutEditFile::OnEditUndo)
00121
00122 EVT_MENU (wxID_FIND, MutEditFile::OnFind)
00123 EVT_MENU (CM_FINDNEXT, MutEditFile::OnFindNext)
00124 EVT_MENU (CM_REPLACE, MutEditFile::OnReplace)
00125 EVT_MENU (CM_REPLACENEXT, MutEditFile::OnReplaceNext)
00126 EVT_MENU (CM_BRACEMATCH, MutEditFile::OnBraceMatch)
00127 EVT_MENU (CM_GOTO, MutEditFile::OnGoto)
00128
00129 EVT_MENU_RANGE (CM_HILIGHTFIRST, CM_HILIGHTLAST,
00130 MutEditFile::OnHilightLang)
00131 EVT_MENU (CM_DISPLAYEOL, MutEditFile::OnDisplayEOL)
00132 EVT_MENU (CM_INDENTGUIDE, MutEditFile::OnIndentGuide)
00133 EVT_MENU (CM_LINENUMBER, MutEditFile::OnLineNumber)
00134 EVT_MENU (CM_LONGLINEON, MutEditFile::OnLongLineOn)
00135 EVT_MENU (CM_WHITESPACE, MutEditFile::OnWhiteSpace)
00136 EVT_MENU (CM_FOLDTOGGLE, MutEditFile::OnFoldToggle)
00137 EVT_MENU (CM_OVERTYPE, MutEditFile::OnSetOverType)
00138 EVT_MENU (CM_READONLY, MutEditFile::OnSetReadOnly)
00139 EVT_MENU (CM_WRAPMODEON, MutEditFile::OnWrapmodeOn)
00140 EVT_MENU (CM_CHARSETANSI, MutEditFile::OnUseCharset)
00141 EVT_MENU (CM_CHARSETMAC, MutEditFile::OnUseCharset)
00142
00143 EVT_MENU (CM_CHANGELOWER, MutEditFile::OnChangeCase)
00144 EVT_MENU (CM_CHANGEUPPER, MutEditFile::OnChangeCase)
00145 EVT_MENU (CM_CONVERTCR, MutEditFile::OnConvertEOL)
00146 EVT_MENU (CM_CONVERTCRLF, MutEditFile::OnConvertEOL)
00147 EVT_MENU (CM_CONVERTLF, MutEditFile::OnConvertEOL)
00148
00149 EVT_STC_MARGINCLICK (wxID_ANY, MutEditFile::OnMarginClick)
00150 EVT_STC_CHARADDED (wxID_ANY, MutEditFile::OnCharAdded)
00151 END_EVENT_TABLE()
00152
00153 namespace mutaborGUI {
00154
00155
00156
00157
00158
00159
00160 MutEditFile::MutEditFile(wxWindow* parent,
00161 const wxPoint& pos,
00162 const wxSize& size,
00163 const wxString& value,
00164 const wxString& name)
00165 : wxStyledTextCtrl(parent,
00166 wxID_ANY,
00167 pos,
00168 size,
00169 wxTE_PROCESS_TAB | wxTE_MULTILINE | wxTE_RICH | wxTE_RICH2
00170 | wxTE_NOHIDESEL | wxHSCROLL | wxVSCROLL | wxBORDER_SUNKEN,
00171 name)
00172 {
00173 Init();
00174 }
00175
00176 MutEditFile::MutEditFile(MutView * v,
00177 wxWindow* parent,
00178 const wxPoint& pos,
00179 const wxSize& size,
00180 const wxString& value,
00181 const wxString& name)
00182 : wxStyledTextCtrl(parent,
00183 wxID_ANY,
00184 pos,
00185 size,
00186 wxTE_PROCESS_TAB |
00187 wxTE_MULTILINE | wxTE_RICH | wxTE_RICH2
00188 | wxTE_NOHIDESEL | wxHSCROLL | wxVSCROLL | wxBORDER_SUNKEN ,
00189 name),
00190 view(v)
00191 {
00192 Init();
00193 }
00194
00195
00196 MutEditFile::~MutEditFile()
00197 {
00198 if (view) {
00199 view->SetTextsw(NULL);
00200 }
00201 }
00202
00203
00204 bool MutEditFile::Compile(bool activate)
00205 {
00206 wxString TmpFile = wxFileName::CreateTempFileName(wxT(PACKAGE));
00207
00208 if ( SaveEditor )
00209 SaveFile(m_filename);
00210
00211 bool result=true;
00212
00213 if ( LogicOn ) {
00214 wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED, CM_STOP);
00215 GetParent()->GetEventHandler()->ProcessEvent(event);
00216 }
00217
00218 wxFile file(TmpFile,wxFile::write);
00219 if (!file.IsOpened() || !file.Write(GetText(), *wxConvCurrent) ) {
00220 wxMessageBox(_("Can't write temporary file."),
00221 _("Error"), wxOK | wxICON_HAND);
00222 CompiledFile = wxEmptyString;
00223 return false;
00224 }
00225
00226 CompDia = new CompDlg(this);
00227
00228 if (!CompDia->Show()) {
00229 wxLogError(_("The compile dialog could not be loaded."));
00230 };
00231
00232 CompDia->SetFileName(GetName());
00233
00234 if ( ::Compile(CompDia, TmpFile.c_str()) ) {
00235 CompiledFile = m_filename;
00236
00237 if (activate) {
00238 wxCommandEvent event(wxEVT_COMMAND_MENU_SELECTED,
00239 CM_DOACTIVATE);
00240 GetParent()->GetEventHandler()->ProcessEvent(event);
00241 CompDia->Destroy();
00242 } else
00243 CompDia->EnableButton(true);
00244
00245 } else {
00246 CompiledFile = wxEmptyString;
00247 CompDia->EnableButton(true);
00248 GoErrorLine();
00249 result = false;
00250 }
00251
00252 wxRemoveFile(TmpFile);
00253
00254 return result;
00255
00256 }
00257
00258 bool MutEditFile::DoLoadFile(const wxString &filename,
00259 int WXUNUSED(fileType))
00260 {
00261 DEBUGLOG(mutparser,_T(""));
00262 STUBC;
00263 #if 0
00264 wxFFile file(filename);
00265
00266 if ( file.IsOpened() ) {
00267 wxString text;
00268
00269 if ( file.ReadAll(&text, autoConverter) ) {
00270 DEBUGLOG(mutparser,_T("%s"),text.c_str());
00271
00272 SetValue(text);
00273 DiscardEdits();
00274 m_filename = filename;
00275 file.Close();
00276 return true;
00277 }
00278
00279 #ifdef DEBUG
00280 else
00281 DEBUGLOG (mutparser,
00282 _T("File opened, but couldn't be loaded."));
00283
00284 #endif
00285 }
00286
00287 wxLogError(_("File couldn't be loaded."));
00288 #endif
00289 return false;
00290 }
00291
00292 bool MutEditFile::DoSaveFile(const wxString& filename, int WXUNUSED(fileType))
00293
00294 {
00295 STUBC;
00296 #if 0
00297 #if wxUSE_FFILE
00298 #ifdef DEBUG
00299 std::cerr << "MutEditFile::DoSaveFile" << std::endl
00300 << (GetValue().fn_str()) << std::endl;
00301 #endif
00302 wxFFile file(filename, _T("w"));
00303
00304 if ( file.IsOpened() && file.Write(GetValue(), autoConverter) ) {
00305
00306 m_filename = filename;
00307
00308
00309 SetSavePoint();
00310
00311 file.Close();
00312
00313 return true;
00314 }
00315
00316 #endif // wxUSE_FFILE
00317 #endif
00318 wxLogError(_("The text couldn't be saved."));
00319
00320 return false;
00321 }
00322
00323
00324 void MutEditFile::CmFileSave(wxCommandEvent& WXUNUSED(event))
00325
00326 {
00327 SaveFile(m_filename);
00328 }
00329
00330 void MutEditFile::CmFileSaveAs(wxCommandEvent& event)
00331 {
00332 wxString newname = FileNameDialog(GetParent(), event.GetId(), m_filename);
00333
00334 if (newname.IsEmpty()) return;
00335
00336 m_filename = newname;
00337 CmFileSave(event);
00338
00339
00340 wxCommandEvent e(wxEVT_COMMAND_MENU_SELECTED,CM_SETTITLE);
00341
00342
00343 wxFileName s(m_filename);
00344
00345 e.SetString(s.GetFullName());
00346
00347 AddPendingEvent(e);
00348 }
00349
00350
00351 void MutEditFile::CmCompile(wxCommandEvent& event)
00352 {
00353
00354 DEBUGLOG (other,
00355 _T("MutEditFile::CmCompile(Event(%d)); filename = %s"),
00356 event.GetId(),m_filename.c_str());
00357 Compile(false);
00358 event.Skip(false);
00359 }
00360
00361 void MutEditFile::CmCompAct(wxCommandEvent& event)
00362 {
00363 Compile(true);
00364 event.Skip(false);
00365 }
00366
00367 void MutEditFile::CmGetLine(wxCommandEvent& WXUNUSED(event))
00368 {
00369 STUBC;
00370
00371
00372
00373
00374
00375 }
00376
00377 void MutEditFile::GoErrorLine()
00378 {
00379 int Line = GetErrorLine();
00380 if ( Line == -1 ) return;
00381 GotoLine(Line);
00382 }
00383
00384 void MutEditFile::CmHelpContext(wxCommandEvent& WXUNUSED(event))
00385 {
00386 STUBC;
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418 }
00419
00420 #if defined(__WXMSW__) && !(wxUSE_UNICODE || wxUSE_WCHAR_T)
00421
00422 wxString MutEditFile::GetValue() const
00423 {
00424 std::cout << "MutEditFile::GetValue()" << std::endl;
00425
00426 return GetRange(0, -1);
00427 }
00428
00429 #endif
00430
00431
00432 void MutEditFile::Init()
00433 {
00434 m_filename = wxEmptyString;
00435
00436 m_LineNrID = 0;
00437 m_DividerID = 1;
00438 m_FoldingID = 2;
00439
00440
00441 m_language = NULL;
00442
00443
00444 SetViewEOL (g_CommonPrefs.displayEOLEnable);
00445 SetIndentationGuides (g_CommonPrefs.indentGuideEnable);
00446 SetEdgeMode (g_CommonPrefs.longLineOnEnable?
00447 wxSTC_EDGE_LINE: wxSTC_EDGE_NONE);
00448 SetViewWhiteSpace (g_CommonPrefs.whiteSpaceEnable?
00449 wxSTC_WS_VISIBLEALWAYS: wxSTC_WS_INVISIBLE);
00450 SetOvertype (g_CommonPrefs.overTypeInitial);
00451 SetReadOnly (g_CommonPrefs.readOnlyInitial);
00452 SetWrapMode (g_CommonPrefs.wrapModeInitial?
00453 wxSTC_WRAP_WORD: wxSTC_WRAP_NONE);
00454 wxFont font (10, wxMODERN, wxNORMAL, wxNORMAL);
00455 StyleSetFont (wxSTC_STYLE_DEFAULT, font);
00456 StyleSetForeground (wxSTC_STYLE_DEFAULT, *wxBLACK);
00457 StyleSetBackground (wxSTC_STYLE_DEFAULT, *wxWHITE);
00458 StyleSetForeground (wxSTC_STYLE_LINENUMBER, wxColour (_T("DARK GREY")));
00459 StyleSetBackground (wxSTC_STYLE_LINENUMBER, *wxWHITE);
00460 StyleSetForeground(wxSTC_STYLE_INDENTGUIDE, wxColour (_T("DARK GREY")));
00461 InitializePrefs (DEFAULT_LANGUAGE);
00462
00463
00464 SetVisiblePolicy (wxSTC_VISIBLE_STRICT|wxSTC_VISIBLE_SLOP, 1);
00465 SetXCaretPolicy (wxSTC_CARET_EVEN|wxSTC_VISIBLE_STRICT|wxSTC_CARET_SLOP, 1);
00466 SetYCaretPolicy (wxSTC_CARET_EVEN|wxSTC_VISIBLE_STRICT|wxSTC_CARET_SLOP, 1);
00467
00468
00469 MarkerDefine (wxSTC_MARKNUM_FOLDER, wxSTC_MARK_DOTDOTDOT, _T("BLACK"), _T("BLACK"));
00470 MarkerDefine (wxSTC_MARKNUM_FOLDEROPEN, wxSTC_MARK_ARROWDOWN, _T("BLACK"), _T("BLACK"));
00471 MarkerDefine (wxSTC_MARKNUM_FOLDERSUB, wxSTC_MARK_EMPTY, _T("BLACK"), _T("BLACK"));
00472 MarkerDefine (wxSTC_MARKNUM_FOLDEREND, wxSTC_MARK_DOTDOTDOT, _T("BLACK"), _T("WHITE"));
00473 MarkerDefine (wxSTC_MARKNUM_FOLDEROPENMID, wxSTC_MARK_ARROWDOWN, _T("BLACK"), _T("WHITE"));
00474 MarkerDefine (wxSTC_MARKNUM_FOLDERMIDTAIL, wxSTC_MARK_EMPTY, _T("BLACK"), _T("BLACK"));
00475 MarkerDefine (wxSTC_MARKNUM_FOLDERTAIL, wxSTC_MARK_EMPTY, _T("BLACK"), _T("BLACK"));
00476
00477
00478 m_LineNrMargin = TextWidth (wxSTC_STYLE_LINENUMBER, _T("_999999"));
00479 m_FoldingMargin = 16;
00480 CmdKeyClear (wxSTC_KEY_TAB, 0);
00481 SetLayoutCache (wxSTC_CACHE_PAGE);
00482 }
00483
00484
00485
00486
00487 void MutEditFile::OnSize( wxSizeEvent& event ) {
00488 int x = GetClientSize().x +
00489 (g_CommonPrefs.lineNumberEnable? m_LineNrMargin: 0) +
00490 (g_CommonPrefs.foldEnable? m_FoldingMargin: 0);
00491 if (x > 0) SetScrollWidth (x);
00492 event.Skip();
00493 }
00494
00495
00496 void MutEditFile::OnEditRedo (wxCommandEvent &WXUNUSED(event)) {
00497 if (!CanRedo()) return;
00498 Redo ();
00499 }
00500
00501 void MutEditFile::OnEditUndo (wxCommandEvent &WXUNUSED(event)) {
00502 if (!CanUndo()) return;
00503 Undo ();
00504 }
00505
00506 void MutEditFile::OnEditClear (wxCommandEvent &WXUNUSED(event)) {
00507 if (GetReadOnly()) return;
00508 Clear ();
00509 }
00510
00511 void MutEditFile::OnEditCut (wxCommandEvent &WXUNUSED(event)) {
00512 if (GetReadOnly() || (GetSelectionEnd()-GetSelectionStart() <= 0)) return;
00513 Cut ();
00514 }
00515
00516 void MutEditFile::OnEditCopy (wxCommandEvent &WXUNUSED(event)) {
00517 if (GetSelectionEnd()-GetSelectionStart() <= 0) return;
00518 Copy ();
00519 }
00520
00521 void MutEditFile::OnEditPaste (wxCommandEvent &WXUNUSED(event)) {
00522 if (!CanPaste()) return;
00523 Paste ();
00524 }
00525
00526 void MutEditFile::OnFind (wxCommandEvent &WXUNUSED(event)) {
00527 }
00528
00529 void MutEditFile::OnFindNext (wxCommandEvent &WXUNUSED(event)) {
00530 }
00531
00532 void MutEditFile::OnReplace (wxCommandEvent &WXUNUSED(event)) {
00533 }
00534
00535 void MutEditFile::OnReplaceNext (wxCommandEvent &WXUNUSED(event)) {
00536 }
00537
00538 void MutEditFile::OnBraceMatch (wxCommandEvent &WXUNUSED(event)) {
00539 int min = GetCurrentPos ();
00540 int max = BraceMatch (min);
00541 if (max > (min+1)) {
00542 BraceHighlight (min+1, max);
00543 SetSelection (min+1, max);
00544 }else{
00545 BraceBadLight (min);
00546 }
00547 }
00548
00549 void MutEditFile::OnGoto (wxCommandEvent &WXUNUSED(event)) {
00550 }
00551
00552 void MutEditFile::OnEditIndentInc (wxCommandEvent &WXUNUSED(event)) {
00553 CmdKeyExecute (wxSTC_CMD_TAB);
00554 }
00555
00556 void MutEditFile::OnEditIndentRed (wxCommandEvent &WXUNUSED(event)) {
00557 CmdKeyExecute (wxSTC_CMD_DELETEBACK);
00558 }
00559
00560 void MutEditFile::OnEditSelectAll (wxCommandEvent &WXUNUSED(event)) {
00561 SetSelection (0, GetTextLength ());
00562 }
00563
00564 void MutEditFile::OnEditSelectLine (wxCommandEvent &WXUNUSED(event)) {
00565 int lineStart = PositionFromLine (GetCurrentLine());
00566 int lineEnd = PositionFromLine (GetCurrentLine() + 1);
00567 SetSelection (lineStart, lineEnd);
00568 }
00569
00570 void MutEditFile::OnHilightLang (wxCommandEvent &event) {
00571 InitializePrefs (g_LanguagePrefs [event.GetId() - CM_HILIGHTFIRST].name);
00572 }
00573
00574 void MutEditFile::OnDisplayEOL (wxCommandEvent &WXUNUSED(event)) {
00575 SetViewEOL (!GetViewEOL());
00576 }
00577
00578 void MutEditFile::OnIndentGuide (wxCommandEvent &WXUNUSED(event)) {
00579 SetIndentationGuides (!GetIndentationGuides());
00580 }
00581
00582 void MutEditFile::OnLineNumber (wxCommandEvent &WXUNUSED(event)) {
00583 SetMarginWidth (m_LineNrID,
00584 GetMarginWidth (m_LineNrID) == 0? m_LineNrMargin: 0);
00585 }
00586
00587 void MutEditFile::OnLongLineOn (wxCommandEvent &WXUNUSED(event)) {
00588 SetEdgeMode (GetEdgeMode() == 0? wxSTC_EDGE_LINE: wxSTC_EDGE_NONE);
00589 }
00590
00591 void MutEditFile::OnWhiteSpace (wxCommandEvent &WXUNUSED(event)) {
00592 SetViewWhiteSpace (GetViewWhiteSpace() == 0?
00593 wxSTC_WS_VISIBLEALWAYS: wxSTC_WS_INVISIBLE);
00594 }
00595
00596 void MutEditFile::OnFoldToggle (wxCommandEvent &WXUNUSED(event)) {
00597 ToggleFold (GetFoldParent(GetCurrentLine()));
00598 }
00599
00600 void MutEditFile::OnSetOverType (wxCommandEvent &WXUNUSED(event)) {
00601 SetOvertype (!GetOvertype());
00602 }
00603
00604 void MutEditFile::OnSetReadOnly (wxCommandEvent &WXUNUSED(event)) {
00605 SetReadOnly (!GetReadOnly());
00606 }
00607
00608 void MutEditFile::OnWrapmodeOn (wxCommandEvent &WXUNUSED(event)) {
00609 SetWrapMode (GetWrapMode() == 0? wxSTC_WRAP_WORD: wxSTC_WRAP_NONE);
00610 }
00611
00612 void MutEditFile::OnUseCharset (wxCommandEvent &event) {
00613 int Nr;
00614 int charset = GetCodePage();
00615 switch (event.GetId()) {
00616 case CM_CHARSETANSI: {charset = wxSTC_CHARSET_ANSI; break;}
00617 case CM_CHARSETMAC: {charset = wxSTC_CHARSET_ANSI; break;}
00618 }
00619 for (Nr = 0; Nr < wxSTC_STYLE_LASTPREDEFINED; Nr++) {
00620 StyleSetCharacterSet (Nr, charset);
00621 }
00622 SetCodePage (charset);
00623 }
00624
00625 void MutEditFile::OnChangeCase (wxCommandEvent &event) {
00626 switch (event.GetId()) {
00627 case CM_CHANGELOWER: {
00628 CmdKeyExecute (wxSTC_CMD_LOWERCASE);
00629 break;
00630 }
00631 case CM_CHANGEUPPER: {
00632 CmdKeyExecute (wxSTC_CMD_UPPERCASE);
00633 break;
00634 }
00635 }
00636 }
00637
00638 void MutEditFile::OnConvertEOL (wxCommandEvent &event) {
00639 int eolMode = GetEOLMode();
00640 switch (event.GetId()) {
00641 case CM_CONVERTCR: { eolMode = wxSTC_EOL_CR; break;}
00642 case CM_CONVERTCRLF: { eolMode = wxSTC_EOL_CRLF; break;}
00643 case CM_CONVERTLF: { eolMode = wxSTC_EOL_LF; break;}
00644 }
00645 ConvertEOLs (eolMode);
00646 SetEOLMode (eolMode);
00647 }
00648
00650 void MutEditFile::OnMarginClick (wxStyledTextEvent &event) {
00651 if (event.GetMargin() == 2) {
00652 int lineClick = LineFromPosition (event.GetPosition());
00653 int levelClick = GetFoldLevel (lineClick);
00654 if ((levelClick & wxSTC_FOLDLEVELHEADERFLAG) > 0) {
00655 ToggleFold (lineClick);
00656 }
00657 }
00658 }
00659
00660 void MutEditFile::OnCharAdded (wxStyledTextEvent &event) {
00661 char chr = (char)event.GetKey();
00662 int currentLine = GetCurrentLine();
00663
00664 if (chr == '\n') {
00665 int lineInd = 0;
00666 if (currentLine > 0) {
00667 lineInd = GetLineIndentation(currentLine - 1);
00668 }
00669 if (lineInd == 0) return;
00670 SetLineIndentation (currentLine, lineInd);
00671 GotoPos(PositionFromLine (currentLine) + lineInd);
00672 }
00673 }
00674
00675
00676
00677
00678 wxString MutEditFile::DeterminePrefs (const wxString &filename) {
00679
00680 LanguageInfo const* curInfo;
00681
00682
00683 int languageNr;
00684 for (languageNr = 0; languageNr < g_LanguagePrefsSize; languageNr++) {
00685 curInfo = &g_LanguagePrefs [languageNr];
00686 wxString filepattern = curInfo->filepattern;
00687 filepattern.Lower();
00688 while (!filepattern.empty()) {
00689 wxString cur = filepattern.BeforeFirst (';');
00690 if ((cur == filename) ||
00691 (cur == (filename.BeforeLast ('.') + _T(".*"))) ||
00692 (cur == (_T("*.") + filename.AfterLast ('.')))) {
00693 return curInfo->name;
00694 }
00695 filepattern = filepattern.AfterFirst (';');
00696 }
00697 }
00698 return wxEmptyString;
00699
00700 }
00701
00702 bool MutEditFile::InitializePrefs (const wxString &name) {
00703
00704
00705 StyleClearAll();
00706 LanguageInfo const* curInfo = NULL;
00707
00708
00709 bool found = false;
00710 int languageNr;
00711 for (languageNr = 0; languageNr < g_LanguagePrefsSize; languageNr++) {
00712 curInfo = &g_LanguagePrefs [languageNr];
00713 if (curInfo->name == name) {
00714 found = true;
00715 break;
00716 }
00717 }
00718 if (!found) return false;
00719
00720
00721 SetLexer (curInfo->lexer);
00722 m_language = curInfo;
00723
00724
00725 SetMarginType (m_LineNrID, wxSTC_MARGIN_NUMBER);
00726 StyleSetForeground (wxSTC_STYLE_LINENUMBER, wxColour (_T("DARK GREY")));
00727 StyleSetBackground (wxSTC_STYLE_LINENUMBER, *wxWHITE);
00728 SetMarginWidth (m_LineNrID, 0);
00729
00730
00731 int Nr;
00732 for (Nr = 0; Nr < wxSTC_STYLE_LASTPREDEFINED; Nr++) {
00733 wxFont font (10, wxMODERN, wxNORMAL, wxNORMAL);
00734 StyleSetFont (Nr, font);
00735 }
00736
00737
00738 StyleSetForeground (wxSTC_STYLE_DEFAULT, wxColour (_T("DARK GREY")));
00739 StyleSetForeground (wxSTC_STYLE_INDENTGUIDE, wxColour (_T("DARK GREY")));
00740
00741
00742 if (g_CommonPrefs.syntaxEnable) {
00743 int keywordnr = 0;
00744 for (Nr = 0; Nr < STYLE_TYPES_COUNT; Nr++) {
00745 if (curInfo->styles[Nr].type == -1) continue;
00746 const StyleInfo &curType = g_StylePrefs [curInfo->styles[Nr].type];
00747 wxFont font (curType.fontsize, wxMODERN, wxNORMAL, wxNORMAL, false,
00748 curType.fontname);
00749 StyleSetFont (Nr, font);
00750 if (curType.foreground) {
00751 StyleSetForeground (Nr, wxColour (curType.foreground));
00752 }
00753 if (curType.background) {
00754 StyleSetBackground (Nr, wxColour (curType.background));
00755 }
00756 StyleSetBold (Nr, (curType.fontstyle & MutSTC_STYLE_BOLD) > 0);
00757 StyleSetItalic (Nr, (curType.fontstyle & MutSTC_STYLE_ITALIC) > 0);
00758 StyleSetUnderline (Nr, (curType.fontstyle & MutSTC_STYLE_UNDERL) > 0);
00759 StyleSetVisible (Nr, (curType.fontstyle & MutSTC_STYLE_HIDDEN) == 0);
00760 StyleSetCase (Nr, curType.lettercase);
00761 const wxChar *pwords = curInfo->styles[Nr].words;
00762 if (pwords) {
00763 SetKeyWords (keywordnr, pwords);
00764 keywordnr += 1;
00765 }
00766 }
00767 }
00768
00769
00770 SetMarginType (m_DividerID, wxSTC_MARGIN_SYMBOL);
00771 SetMarginWidth (m_DividerID, 0);
00772 SetMarginSensitive (m_DividerID, false);
00773
00774
00775 SetMarginType (m_FoldingID, wxSTC_MARGIN_SYMBOL);
00776 SetMarginMask (m_FoldingID, wxSTC_MASK_FOLDERS);
00777 StyleSetBackground (m_FoldingID, *wxWHITE);
00778 SetMarginWidth (m_FoldingID, 0);
00779 SetMarginSensitive (m_FoldingID, false);
00780 if (g_CommonPrefs.foldEnable) {
00781 SetMarginWidth (m_FoldingID, curInfo->folds != 0? m_FoldingMargin: 0);
00782 SetMarginSensitive (m_FoldingID, curInfo->folds != 0);
00783 SetProperty (_T("fold"), curInfo->folds != 0? _T("1"): _T("0"));
00784 SetProperty (_T("fold.comment"),
00785 (curInfo->folds & MutSTC_FOLD_COMMENT) > 0? _T("1"): _T("0"));
00786 SetProperty (_T("fold.compact"),
00787 (curInfo->folds & MutSTC_FOLD_COMPACT) > 0? _T("1"): _T("0"));
00788 SetProperty (_T("fold.preprocessor"),
00789 (curInfo->folds & MutSTC_FOLD_PREPROC) > 0? _T("1"): _T("0"));
00790 SetProperty (_T("fold.html"),
00791 (curInfo->folds & MutSTC_FOLD_HTML) > 0? _T("1"): _T("0"));
00792 SetProperty (_T("fold.html.preprocessor"),
00793 (curInfo->folds & MutSTC_FOLD_HTMLPREP) > 0? _T("1"): _T("0"));
00794 SetProperty (_T("fold.comment.python"),
00795 (curInfo->folds & MutSTC_FOLD_COMMENTPY) > 0? _T("1"): _T("0"));
00796 SetProperty (_T("fold.quotes.python"),
00797 (curInfo->folds & MutSTC_FOLD_QUOTESPY) > 0? _T("1"): _T("0"));
00798 }
00799 SetFoldFlags (wxSTC_FOLDFLAG_LINEBEFORE_CONTRACTED |
00800 wxSTC_FOLDFLAG_LINEAFTER_CONTRACTED);
00801
00802
00803 SetTabWidth (4);
00804 SetUseTabs (false);
00805 SetTabIndents (true);
00806 SetBackSpaceUnIndents (true);
00807 SetIndent (g_CommonPrefs.indentEnable? 4: 0);
00808
00809
00810 SetViewEOL (g_CommonPrefs.displayEOLEnable);
00811 SetIndentationGuides (g_CommonPrefs.indentGuideEnable);
00812 SetEdgeColumn (80);
00813 SetEdgeMode (g_CommonPrefs.longLineOnEnable? wxSTC_EDGE_LINE: wxSTC_EDGE_NONE);
00814 SetViewWhiteSpace (g_CommonPrefs.whiteSpaceEnable?
00815 wxSTC_WS_VISIBLEALWAYS: wxSTC_WS_INVISIBLE);
00816 SetOvertype (g_CommonPrefs.overTypeInitial);
00817 SetReadOnly (g_CommonPrefs.readOnlyInitial);
00818 SetWrapMode (g_CommonPrefs.wrapModeInitial?
00819 wxSTC_WRAP_WORD: wxSTC_WRAP_NONE);
00820
00821 return true;
00822 }
00823
00824 bool MutEditFile::LoadFile ()
00825 {
00826 #if wxUSE_FILEDLG
00827
00828 if (!m_filename) {
00829 wxFileDialog dlg (this, _T("Open file"), wxEmptyString, wxEmptyString,
00830 _T("Any file (*)|*"), wxFD_OPEN | wxFD_FILE_MUST_EXIST | wxFD_CHANGE_DIR);
00831 if (dlg.ShowModal() != wxID_OK) return false;
00832 m_filename = dlg.GetPath();
00833 }
00834
00835
00836 return LoadFile (m_filename);
00837 #else
00838 return false;
00839 #endif // wxUSE_FILEDLG
00840 }
00841
00842 bool MutEditFile::LoadFile (const wxString &filename) {
00843
00844
00845 if (!filename.empty()) m_filename = filename;
00846
00847
00848 ClearAll ();
00849
00850
00851
00852
00853
00854
00855
00856
00857
00858
00859 wxStyledTextCtrl::LoadFile(m_filename);
00860
00861 EmptyUndoBuffer();
00862
00863
00864 wxFileName fname (m_filename);
00865 InitializePrefs (DeterminePrefs (fname.GetFullName()));
00866
00867 return true;
00868 }
00869
00870 bool MutEditFile::SaveFile ()
00871 {
00872 #if wxUSE_FILEDLG
00873
00874 if (!IsModified()) return true;
00875
00876
00877 if (!m_filename) {
00878 wxFileDialog dlg (this, _T("Save file"), wxEmptyString, wxEmptyString, _T("Any file (*)|*"),
00879 wxFD_SAVE | wxFD_OVERWRITE_PROMPT);
00880 if (dlg.ShowModal() != wxID_OK) return false;
00881 m_filename = dlg.GetPath();
00882 }
00883
00884
00885 return SaveFile (m_filename);
00886 #else
00887 return false;
00888 #endif // wxUSE_FILEDLG
00889 }
00890
00891 bool MutEditFile::SaveFile (const wxString &filename) {
00892
00893
00894 if (!IsModified()) return true;
00895
00896
00897
00898
00899
00900
00901
00902
00903
00904
00905
00906
00907
00908
00909 return wxStyledTextCtrl::SaveFile(filename);
00910
00911 }
00912
00913 bool MutEditFile::IsModified () {
00914
00915
00916 return (GetModify() && !GetReadOnly());
00917 }
00918
00919
00920
00921
00922
00923 MutEditProperties::MutEditProperties (MutEditFile *edit,
00924 long style)
00925 : wxDialog (edit, wxID_ANY, wxEmptyString,
00926 wxDefaultPosition, wxDefaultSize,
00927 style | wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) {
00928
00929
00930 SetTitle (_("Properties"));
00931 wxString text;
00932
00933
00934 wxBoxSizer *fullname = new wxBoxSizer (wxHORIZONTAL);
00935 fullname->Add (10, 0);
00936 fullname->Add (new wxStaticText (this, wxID_ANY, _("Full filename"),
00937 wxDefaultPosition, wxSize(80, wxDefaultCoord)),
00938 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL);
00939 fullname->Add (new wxStaticText (this, wxID_ANY, edit->GetFilename()),
00940 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL);
00941
00942
00943 wxGridSizer *textinfo = new wxGridSizer (4, 0, 2);
00944 textinfo->Add (new wxStaticText (this, wxID_ANY, _("Language"),
00945 wxDefaultPosition, wxSize(80, wxDefaultCoord)),
00946 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
00947 textinfo->Add (new wxStaticText (this, wxID_ANY, edit->m_language->name),
00948 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
00949 textinfo->Add (new wxStaticText (this, wxID_ANY, _("Lexer-ID: "),
00950 wxDefaultPosition, wxSize(80, wxDefaultCoord)),
00951 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
00952 text = wxString::Format (_T("%d"), edit->GetLexer());
00953 textinfo->Add (new wxStaticText (this, wxID_ANY, text),
00954 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
00955 wxString EOLtype = wxEmptyString;
00956 switch (edit->GetEOLMode()) {
00957 case wxSTC_EOL_CR: {EOLtype = _T("CR (Unix)"); break; }
00958 case wxSTC_EOL_CRLF: {EOLtype = _T("CRLF (Windows)"); break; }
00959 case wxSTC_EOL_LF: {EOLtype = _T("CR (Macintosh)"); break; }
00960 }
00961 textinfo->Add (new wxStaticText (this, wxID_ANY, _("Line endings"),
00962 wxDefaultPosition, wxSize(80, wxDefaultCoord)),
00963 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
00964 textinfo->Add (new wxStaticText (this, wxID_ANY, EOLtype),
00965 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
00966
00967
00968 wxStaticBoxSizer *textinfos = new wxStaticBoxSizer (
00969 new wxStaticBox (this, wxID_ANY, _("Informations")),
00970 wxVERTICAL);
00971 textinfos->Add (textinfo, 0, wxEXPAND);
00972 textinfos->Add (0, 6);
00973
00974
00975 wxGridSizer *statistic = new wxGridSizer (4, 0, 2);
00976 statistic->Add (new wxStaticText (this, wxID_ANY, _("Total lines"),
00977 wxDefaultPosition, wxSize(80, wxDefaultCoord)),
00978 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
00979 text = wxString::Format (_T("%d"), edit->GetLineCount());
00980 statistic->Add (new wxStaticText (this, wxID_ANY, text),
00981 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
00982 statistic->Add (new wxStaticText (this, wxID_ANY, _("Total chars"),
00983 wxDefaultPosition, wxSize(80, wxDefaultCoord)),
00984 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
00985 text = wxString::Format (_T("%d"), edit->GetTextLength());
00986 statistic->Add (new wxStaticText (this, wxID_ANY, text),
00987 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
00988 statistic->Add (new wxStaticText (this, wxID_ANY, _("Current line"),
00989 wxDefaultPosition, wxSize(80, wxDefaultCoord)),
00990 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
00991 text = wxString::Format (_T("%d"), edit->GetCurrentLine());
00992 statistic->Add (new wxStaticText (this, wxID_ANY, text),
00993 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
00994 statistic->Add (new wxStaticText (this, wxID_ANY, _("Current pos"),
00995 wxDefaultPosition, wxSize(80, wxDefaultCoord)),
00996 0, wxALIGN_LEFT|wxALIGN_CENTER_VERTICAL|wxLEFT, 4);
00997 text = wxString::Format (_T("%d"), edit->GetCurrentPos());
00998 statistic->Add (new wxStaticText (this, wxID_ANY, text),
00999 0, wxALIGN_RIGHT|wxALIGN_CENTER_VERTICAL|wxRIGHT, 4);
01000
01001
01002 wxStaticBoxSizer *statistics = new wxStaticBoxSizer (
01003 new wxStaticBox (this, wxID_ANY, _("Statistics")),
01004 wxVERTICAL);
01005 statistics->Add (statistic, 0, wxEXPAND);
01006 statistics->Add (0, 6);
01007
01008
01009 wxBoxSizer *totalpane = new wxBoxSizer (wxVERTICAL);
01010 totalpane->Add (fullname, 0, wxEXPAND | wxLEFT | wxRIGHT | wxTOP, 10);
01011 totalpane->Add (0, 6);
01012 totalpane->Add (textinfos, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
01013 totalpane->Add (0, 10);
01014 totalpane->Add (statistics, 0, wxEXPAND | wxLEFT | wxRIGHT, 10);
01015 totalpane->Add (0, 6);
01016 wxButton *okButton = new wxButton (this, wxID_OK, _("OK"));
01017 okButton->SetDefault();
01018 totalpane->Add (okButton, 0, wxALIGN_CENTER | wxALL, 10);
01019
01020 SetSizerAndFit (totalpane);
01021
01022 ShowModal();
01023 }
01024
01025 #if wxUSE_PRINTING_ARCHITECTURE
01026
01027
01028
01029
01030
01031 MutEditPrint::MutEditPrint (MutEditFile *edit, wxChar *title)
01032 : wxPrintout(title) {
01033 m_edit = edit;
01034 m_printed = 0;
01035
01036 }
01037
01038 bool MutEditPrint::OnPrintPage (int page) {
01039
01040 wxDC *dc = GetDC();
01041 if (!dc) return false;
01042
01043
01044 PrintScaling (dc);
01045
01046
01047 if (page == 1) m_printed = 0;
01048 m_printed = m_edit->FormatRange (1, m_printed, m_edit->GetLength(),
01049 dc, dc, m_printRect, m_pageRect);
01050
01051 return true;
01052 }
01053
01054 bool MutEditPrint::OnBeginDocument (int startPage, int endPage) {
01055
01056 if (!wxPrintout::OnBeginDocument (startPage, endPage)) {
01057 return false;
01058 }
01059
01060 return true;
01061 }
01062
01063 void MutEditPrint::GetPageInfo (int *minPage, int *maxPage, int *selPageFrom, int *selPageTo) {
01064
01065
01066 *minPage = 0;
01067 *maxPage = 0;
01068 *selPageFrom = 0;
01069 *selPageTo = 0;
01070
01071
01072 wxDC *dc = GetDC();
01073 if (!dc) return;
01074 PrintScaling (dc);
01075
01076
01077 wxSize ppiScr;
01078 GetPPIScreen (&ppiScr.x, &ppiScr.y);
01079 wxSize page = g_pageSetupData->GetPaperSize();
01080 page.x = static_cast<int> (page.x * ppiScr.x / 25.4);
01081 page.y = static_cast<int> (page.y * ppiScr.y / 25.4);
01082 m_pageRect = wxRect (0,
01083 0,
01084 page.x,
01085 page.y);
01086
01087
01088 wxPoint pt = g_pageSetupData->GetMarginTopLeft();
01089 int left = pt.x;
01090 int top = pt.y;
01091 pt = g_pageSetupData->GetMarginBottomRight();
01092 int right = pt.x;
01093 int bottom = pt.y;
01094
01095 top = static_cast<int> (top * ppiScr.y / 25.4);
01096 bottom = static_cast<int> (bottom * ppiScr.y / 25.4);
01097 left = static_cast<int> (left * ppiScr.x / 25.4);
01098 right = static_cast<int> (right * ppiScr.x / 25.4);
01099
01100 m_printRect = wxRect (left,
01101 top,
01102 page.x - (left + right),
01103 page.y - (top + bottom));
01104
01105
01106 while (HasPage (*maxPage)) {
01107 m_printed = m_edit->FormatRange (0, m_printed, m_edit->GetLength(),
01108 dc, dc, m_printRect, m_pageRect);
01109 *maxPage += 1;
01110 }
01111 if (*maxPage > 0) *minPage = 1;
01112 *selPageFrom = *minPage;
01113 *selPageTo = *maxPage;
01114 }
01115
01116 bool MutEditPrint::HasPage (int WXUNUSED(page)) {
01117
01118 return (m_printed < m_edit->GetLength());
01119 }
01120
01121 bool MutEditPrint::PrintScaling (wxDC *dc){
01122
01123
01124 if (!dc) return false;
01125
01126
01127 wxSize ppiScr;
01128 GetPPIScreen (&ppiScr.x, &ppiScr.y);
01129 if (ppiScr.x == 0) {
01130 ppiScr.x = 96;
01131 ppiScr.y = 96;
01132 }
01133 wxSize ppiPrt;
01134 GetPPIPrinter (&ppiPrt.x, &ppiPrt.y);
01135 if (ppiPrt.x == 0) {
01136 ppiPrt.x = ppiScr.x;
01137 ppiPrt.y = ppiScr.y;
01138 }
01139 wxSize dcSize = dc->GetSize();
01140 wxSize pageSize;
01141 GetPageSizePixels (&pageSize.x, &pageSize.y);
01142
01143
01144 float scale_x = (float)(ppiPrt.x * dcSize.x) /
01145 (float)(ppiScr.x * pageSize.x);
01146 float scale_y = (float)(ppiPrt.y * dcSize.y) /
01147 (float)(ppiScr.y * pageSize.y);
01148 dc->SetUserScale (scale_x, scale_y);
01149
01150 return true;
01151 }
01152
01153 #endif
01154
01155
01156
01157 #if 0
01158 wxString MutEditFile::GetRange(long from, long to) const
01159
01160 {
01161 std::cout << "MutEditFile::GetRange ("<< from << ", " << to << ")" << std::endl;
01162 wxString str;
01163
01164 if ( from >= to && to != -1 ) {
01165
01166 return str;
01167 }
01168
01169 #if wxUSE_RICHEDIT
01170 if ( IsRich() ) {
01171 int len = GetWindowTextLength(GetHwnd());
01172 std::cout << "MutEditFile::GetRange: len = "<< len << std::endl;
01173
01174 if ( len > from ) {
01175 if ( to == -1 )
01176 to = len;
01177
01178 std::cout << "MutEditFile::GetRange: to = "<< to << std::endl;
01179
01180 #if !(wxUSE_UNICODE || wxUSE_WCHAR_T)
01181
01182
01183
01184 if ( GetRichVersion() > 1 ) {
01185
01186
01187 wxFontEncoding encoding = wxFONTENCODING_SYSTEM;
01188
01189 wxFont font = m_defaultStyle.GetFont();
01190
01191 if ( !font.Ok() )
01192 font = GetFont();
01193
01194 if ( font.Ok() ) {
01195 encoding = font.GetEncoding();
01196 }
01197
01198 if ( encoding == wxFONTENCODING_SYSTEM ) {
01199 encoding = wxLocale::GetSystemEncoding();
01200 }
01201
01202 if ( encoding == wxFONTENCODING_SYSTEM ) {
01203 encoding = wxFONTENCODING_ISO8859_1;
01204 }
01205
01206 str = StreamOut(encoding);
01207
01208 std::cout << "str = StreamOut(encoding);" << std::endl;
01209
01210 std::cout << "MutEditFile::GetRange: str.Len = "<< (str.Len()) << std::endl;
01211
01212 if ( !str.empty() ) {
01213
01214
01215
01216 str = str.Mid(from, to - from);
01217 std::cout << "MutEditFile::GetRange: str.Len = "<< (str.Len()) << std::endl;
01218 }
01219 }
01220
01221
01222 if ( str.empty() )
01223 #endif
01224 {
01225
01226 wxStringBuffer tmp(str, ++len);
01227 wxChar *p = tmp;
01228
01229 TEXTRANGE textRange;
01230 textRange.chrg.cpMin = from;
01231 textRange.chrg.cpMax = to;
01232 textRange.lpstrText = p;
01233
01234 (void)::SendMessage(GetHwnd(), EM_GETTEXTRANGE,
01235 0, (LPARAM)&textRange);
01236
01237 if ( m_verRichEdit > 1 )
01238 {
01239
01240
01241
01242
01243 for ( ; *p; p++ ) {
01244 if ( *p == _T('\r') )
01245 *p = _T('\n');
01246 }
01247 }
01248 }
01249
01250 if ( m_verRichEdit == 1 ) {
01251
01252 str = wxTextFile::Translate(str, wxTextFileType_Unix);
01253 }
01254 }
01255
01256
01257 } else
01258 #endif // wxUSE_RICHEDIT {
01259
01260 str = wxGetWindowText(GetHWND());
01261
01262 std::cout << "str = wxGetWindowText(GetHWND());" << std::endl;
01263
01264 std::cout << "MutEditFile::GetRange: str.Len = "<< (str.Len()) << std::endl;
01265
01266
01267 if ( from < to ) {
01268 str = str.Mid(from, to - from);
01269 std::cout << "MutEditFile::GetRange: str.Len = "<< (str.Len()) << std::endl;
01270 }
01271
01272
01273
01274
01275 str = wxTextFile::Translate(str, wxTextFileType_Unix);
01276
01277 std::cout << "MutEditFile::GetRange: str.Len = "<< (str.Len()) << std::endl;
01278 }
01279
01280 return str;
01281 }
01282
01283
01284 #if wxUSE_RICHEDIT && (!(wxUSE_UNICODE || wxUSE_WCHAR_T) || wxUSE_UNICODE_MSLU)
01285
01286
01287
01288
01289 class UpdatesCountFilter
01290 {
01291
01292 public:
01293 UpdatesCountFilter(int& count)
01294 : m_count(count)
01295 {
01296 wxASSERT_MSG( m_count == -1 || m_count == -2,
01297 _T("wrong initial m_updatesCount value") );
01298
01299 if (m_count != -2)
01300 m_count = 0;
01301
01302
01303
01304 }
01305
01306 ~UpdatesCountFilter()
01307 {
01308 m_count = -1;
01309 }
01310
01311
01312
01313 bool GotUpdate() const
01314 {
01315 return m_count == 1;
01316 }
01317
01318 private:
01319
01320 int& m_count;
01321
01322 DECLARE_NO_COPY_CLASS(UpdatesCountFilter)
01323 };
01324
01325
01326
01327
01328
01329 DWORD CALLBACK
01330 mutRichEditStreamIn(DWORD dwCookie, BYTE *buf, LONG cb, LONG *pcb)
01331 {
01332 *pcb = 0;
01333
01334 const wchar_t ** const ppws = (const wchar_t **)dwCookie;
01335
01336 wchar_t *wbuf = (wchar_t *)buf;
01337
01338 const wchar_t *wpc = *ppws;
01339
01340 while ( cb && *wpc ) {
01341 *wbuf++ = *wpc++;
01342
01343 cb -= sizeof(wchar_t);
01344 (*pcb) += sizeof(wchar_t);
01345 }
01346
01347 *ppws = wpc;
01348
01349 return 0;
01350 }
01351
01352
01353
01354 struct wxStreamOutData
01355 {
01356 wchar_t *wpc;
01357 size_t len;
01358 };
01359
01360 DWORD CALLBACK
01361 mutRichEditStreamOut(DWORD_PTR dwCookie, BYTE *buf, LONG cb, LONG *pcb)
01362 {
01363 std::cout << "::mutRichEditStreamOut: dwCookie = " << dwCookie <<
01364 " buf = " << buf <<
01365 " cb = " << cb << " pcb = " << pcb << std::endl;
01366 *pcb = 0;
01367
01368 wxStreamOutData *data = (wxStreamOutData *)dwCookie;
01369
01370 const wchar_t *wbuf = (const wchar_t *)buf;
01371
01372 wchar_t *wpc = data->wpc;
01373
01374 std::cout << "::mutRichEditStreamOut: wpc = " << wpc << std::endl;
01375
01376 while ( cb ) {
01377 wchar_t wch = *wbuf++;
01378 char string[sizeof(wchar_t)+1];
01379 string[sizeof(wchar_t)] = 0;
01380 (wchar_t &)*string = wch;
01381
01382 std::cout << string;
01383
01384
01385
01386 *wpc++ = wch;
01387
01388
01389
01390 cb -= sizeof(wchar_t);
01391 (*pcb) += sizeof(wchar_t);
01392 }
01393
01394 data->wpc = wpc;
01395
01396 std::cout << "::mutRichEditStreamOut: wpc = " << wpc << std::endl;
01397
01398 return 0;
01399 }
01400
01401
01402 #if wxUSE_UNICODE_MSLU
01403 #define UNUSED_IF_MSLU(param)
01404 #else
01405 #define UNUSED_IF_MSLU(param) param
01406 #endif
01407
01408 bool
01409
01410 MutEditFile::StreamIn(const wxString& value,
01411 wxFontEncoding UNUSED_IF_MSLU(encoding),
01412 bool selectionOnly)
01413 {
01414 #if wxUSE_UNICODE_MSLU
01415
01416 const wchar_t *wpc = value.c_str();
01417
01418 #else // !wxUSE_UNICODE_MSLU
01419 wxCSConv conv(encoding);
01420
01421 const size_t len = conv.MB2WC(NULL, value, value.length());
01422
01423 #if wxUSE_WCHAR_T
01424 wxWCharBuffer wchBuf(len);
01425
01426 wchar_t *wpc = wchBuf.data();
01427
01428 #else
01429 wchar_t *wchBuf = (wchar_t *)malloc((len + 1)*sizeof(wchar_t));
01430
01431 wchar_t *wpc = wchBuf;
01432
01433 #endif
01434
01435 conv.MB2WC(wpc, value, value.length());
01436
01437 #endif // wxUSE_UNICODE_MSLU
01438
01439
01440 EDITSTREAM eds;
01441
01442 wxZeroMemory(eds);
01443
01444 eds.dwCookie = (DWORD)&wpc;
01445
01446
01447 eds.pfnCallback = (EDITSTREAMCALLBACK)mutRichEditStreamIn;
01448
01449
01450 UpdatesCountFilter ucf(m_updatesCount);
01451
01452 ::SendMessage(GetHwnd(), EM_STREAMIN,
01453 SF_TEXT |
01454 SF_UNICODE |
01455 (selectionOnly ? SFF_SELECTION : 0),
01456 (LPARAM)&eds);
01457
01458
01459
01460 wxASSERT_MSG( ucf.GotUpdate() || ( !HasSelection() && value.empty() ),
01461 _T("EM_STREAMIN didn't send EN_UPDATE?") );
01462
01463 if ( eds.dwError ) {
01464 wxLogLastError(_T("EM_STREAMIN"));
01465 }
01466
01467 #if !wxUSE_WCHAR_T
01468 free(wchBuf);
01469
01470 #endif // !wxUSE_WCHAR_T
01471
01472 return true;
01473 }
01474
01475 #if !wxUSE_UNICODE_MSLU
01476
01477 wxString
01478 MutEditFile::StreamOut(wxFontEncoding encoding, bool selectionOnly) const
01479 {
01480 wxString out;
01481
01482 const int len = GetWindowTextLength(GetHwnd());
01483
01484 std::cout << "MutEditFile::StreamOut: len = " << len << std::endl;
01485
01486
01487
01488
01489
01490 wchar_t *wchBuf = (wchar_t *)malloc((len + 2)*sizeof(wchar_t));
01491
01492 wchar_t *wpc = wchBuf;
01493
01494
01495
01496 wxStreamOutData data;
01497
01498 data.wpc = wpc;
01499
01500 data.len = len+1;
01501
01502 EDITSTREAM eds;
01503
01504 wxZeroMemory(eds);
01505
01506 eds.dwCookie = (DWORD)&data;
01507
01508 eds.pfnCallback = mutRichEditStreamOut;
01509
01510 ::SendMessage
01511 (
01512 GetHwnd(),
01513 EM_STREAMOUT,
01514 SF_TEXT | SF_UNICODE | (selectionOnly ? SFF_SELECTION : 0),
01515 (LPARAM)&eds
01516 );
01517
01518 if ( eds.dwError ) {
01519 wxLogLastError(_T("EM_STREAMOUT"));
01520 } else
01521 {
01522
01523
01524
01525
01526
01527 wchBuf[data.len] = 0;
01528
01529 std::cout << "MutEditFile::StreamOut: data.len = " << (data.len) << std::endl;
01530 wxString test("test");
01531
01532
01533
01534 wxCSConv conv(encoding);
01535 size_t lenNeeded = conv.WC2MB(NULL, wchBuf, 0);
01536
01537 std::cout << "MutEditFile::StreamOut: lenNeeded = " << lenNeeded << std::endl;
01538 std::cout << wchBuf[len] << " " << std:: endl;
01539 std::cout << wchBuf[lenNeeded] << " " << std::endl;
01540
01541 std::cout << "MutEditFile::StreamOut: len = " << len << std::endl;
01542 out.Alloc(lenNeeded+1);
01543
01544
01545 if ( lenNeeded++ ) {
01546 char string[sizeof(wchar_t)+1];
01547 string[sizeof(wchar_t)] = 0;
01548
01549 for (int i=0; i<= len; i++) {
01550 (wchar_t &)*string = wchBuf[i];
01551
01552 std::cout << i << ": " << string << std::endl;
01553 out[i] = *string;
01554 std::cout<< out<<std::endl;
01555 }
01556
01557
01558
01559 }
01560
01561 std::cout << "MutEditFile::StreamOut: lenNeeded = " << lenNeeded << std::endl;
01562
01563
01564
01565
01566 }
01567
01568
01569
01570 free(wchBuf);
01571
01572
01573
01574 return out;
01575 }
01576
01577 #endif // !wxUSE_UNICODE_MSLU
01578
01579 #endif // wxUSE_RICHEDIT
01580 #endif
01581
01582 }