00001
00002
00003
00004
00005
00006
00007
00008
00009
00011
00012
00013
00014 #include "wx/wxprec.h"
00015
00016 #ifdef __BORLANDC__
00017 #pragma hdrstop
00018 #endif
00019
00020
00021
00022 #ifndef WX_PRECOMP
00023 #include "wx/wx.h"
00024 #endif
00025
00026 #include "wx/filename.h"
00027 #include "guipkg/sourceeditctrl.h"
00028
00029
00030
00031
00032
00033
00034
00035 BEGIN_EVENT_TABLE(wxPackageSourceEditCtrl, wxStyledTextCtrl)
00036 #if ENABLE_EDIT_MODE
00037
00038 EVT_MENU(wxID_CLEAR, wxPackageSourceEditCtrl::OnEditClear)
00039 EVT_MENU(wxID_CUT, wxPackageSourceEditCtrl::OnEditCut)
00040 EVT_MENU(wxID_COPY, wxPackageSourceEditCtrl::OnEditCopy)
00041 EVT_MENU(wxID_PASTE, wxPackageSourceEditCtrl::OnEditPaste)
00042 EVT_MENU(ID_SEC_INDENTINC, wxPackageSourceEditCtrl::OnEditIndentInc)
00043 EVT_MENU(ID_SEC_INDENTRED, wxPackageSourceEditCtrl::OnEditIndentRed)
00044 EVT_MENU(wxID_SELECTALL, wxPackageSourceEditCtrl::OnEditSelectAll)
00045 EVT_MENU(wxID_REDO, wxPackageSourceEditCtrl::OnEditRedo)
00046 EVT_MENU(wxID_UNDO, wxPackageSourceEditCtrl::OnEditUndo)
00047
00048
00049 EVT_MENU(wxID_FIND, wxPackageSourceEditCtrl::OnFind)
00050 EVT_MENU(ID_SEC_FINDNEXT, wxPackageSourceEditCtrl::OnFindNext)
00051 EVT_MENU(ID_SEC_REPLACE, wxPackageSourceEditCtrl::OnReplace)
00052 EVT_MENU(ID_SEC_REPLACENEXT, wxPackageSourceEditCtrl::OnReplaceNext)
00053
00054
00055 EVT_MENU(ID_SEC_DISPLAYEOL, wxPackageSourceEditCtrl::OnDisplayEOL)
00056 EVT_MENU(ID_SEC_LINENUMBER, wxPackageSourceEditCtrl::OnLineNumber)
00057 EVT_MENU(ID_SEC_LONGLINEON, wxPackageSourceEditCtrl::OnLongLineOn)
00058 EVT_MENU(ID_SEC_WHITESPACE, wxPackageSourceEditCtrl::OnWhiteSpace)
00059 EVT_MENU(ID_SEC_WRAPMODEON, wxPackageSourceEditCtrl::OnWrapmodeOn)
00060
00061
00062 EVT_STC_MARGINCLICK(wxID_ANY, wxPackageSourceEditCtrl::OnMarginClick)
00063 EVT_STC_CHARADDED(wxID_ANY, wxPackageSourceEditCtrl::OnCharAdded)
00064 #endif
00065 END_EVENT_TABLE()
00066
00067
00068 bool wxPackageSourceEditCtrl::Create(wxWindow *parent, wxWindowID id,
00069 const wxPoint &pos, const wxSize &size,
00070 long style)
00071 {
00072 if (!wxStyledTextCtrl::Create(parent, id, pos, size, style))
00073 return false;
00074
00075
00076 SetLexer(wxSTC_LEX_XML);
00077
00078
00079 SetEdgeColumn(80);
00080 EnableWrapMode(false);
00081
00082
00083 SetDefaultStyle();
00084 UpdateScrollWidth();
00085
00086 return true;
00087 }
00088
00089 void wxPackageSourceEditCtrl::SetDefaultStyle()
00090 {
00091
00092 m_font = wxFont(9, wxMODERN, wxNORMAL, wxNORMAL);
00093 StyleSetFont(wxSTC_STYLE_DEFAULT, m_font);
00094
00095
00096 StyleSetForeground(wxSTC_H_TAG, wxColour(0,0,128));
00097 StyleSetForeground(wxSTC_H_ATTRIBUTE, wxColour(0,128,128));
00098 StyleSetForeground(wxSTC_H_COMMENT, wxColour(128,128,0));
00099 StyleSetForeground(wxSTC_H_TAGUNKNOWN, wxColour(255,0,0));
00100 StyleSetForeground(wxSTC_H_ATTRIBUTEUNKNOWN, wxColour(255,0,0));
00101 StyleSetForeground(wxSTC_H_DOUBLESTRING, wxColour(127,0,127));
00102 StyleSetForeground(wxSTC_H_SINGLESTRING, wxColour(127,0,127));
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117 }
00118
00119 void wxPackageSourceEditCtrl::UpdateScrollWidth()
00120 {
00121 if (GetWrapMode() == wxSTC_WRAP_WORD)
00122 return;
00123
00124
00125
00126
00127 size_t max = 0;
00128 for (int i=0; i<GetLineCount(); i++)
00129 {
00130 size_t len = LineLength(i);
00131 max = wxMax(len, max);
00132 }
00133
00134
00135 wxWindowDC dc(this);
00136 dc.SetFont(m_font);
00137 SetScrollWidth(dc.GetCharWidth() * (max+1));
00138 }
00139
00140 void wxPackageSourceEditCtrl::EnableWrapMode(bool enable)
00141 {
00142 SetWrapMode(enable ? wxSTC_WRAP_WORD : wxSTC_WRAP_NONE);
00143 SetEdgeMode(!enable ? wxSTC_EDGE_LINE : wxSTC_EDGE_NONE);
00144 }
00145
00146
00147
00148
00149
00150
00151