sourceeditctrl.cpp

00001 
00002 // File:        sourceeditctrl.cpp
00003 // Purpose:     wxPackageSourceEditCtrl
00004 // Author:      Francesco Montorsi
00005 // Modified by:
00006 // Created:     2006-06-08
00007 // RCS-ID:      $Id: sourceeditctrl.cpp,v 1.1.1.1 2006/12/12 09:38:27 frm Exp $
00008 // Copyright:   (c) Francesco Montorsi
00009 // Licence:     wxWidgets licence
00011 
00012 
00013 // For compilers that support precompilation, includes "wx/wx.h".
00014 #include "wx/wxprec.h"
00015 
00016 #ifdef __BORLANDC__
00017     #pragma hdrstop
00018 #endif
00019 
00020 // for all others, include the necessary headers (this file is usually all you
00021 // need because it includes almost all 'standard' wxWidgets headers)
00022 #ifndef WX_PRECOMP
00023     #include "wx/wx.h"
00024 #endif
00025 
00026 #include "wx/filename.h"
00027 #include "guipkg/sourceeditctrl.h"        // edit module
00028 
00029 
00030 
00031 //----------------------------------------------------------------------------
00032 // wxPackageSourceEditCtrl
00033 //----------------------------------------------------------------------------
00034 
00035 BEGIN_EVENT_TABLE(wxPackageSourceEditCtrl, wxStyledTextCtrl)
00036 #if ENABLE_EDIT_MODE
00037     // edit
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     // find
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     // view
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     // stc
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     // the lexer is fixed to XML
00076     SetLexer(wxSTC_LEX_XML);
00077 
00078     // when wrapping is off, a line will be drawn at 80-th column
00079     SetEdgeColumn(80);
00080     EnableWrapMode(false);
00081 
00082     // some defaults
00083     SetDefaultStyle();
00084     UpdateScrollWidth();
00085 
00086     return true;
00087 }
00088 
00089 void wxPackageSourceEditCtrl::SetDefaultStyle()
00090 {
00091     // as font use a monospaced font
00092     m_font = wxFont(9, wxMODERN, wxNORMAL, wxNORMAL);
00093     StyleSetFont(wxSTC_STYLE_DEFAULT, m_font);
00094 
00095     // set some nice colours for the XML lexer
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 #define wxSTC_H_DEFAULT 0
00106 #define wxSTC_H_TAG 1
00107 #define wxSTC_H_TAGUNKNOWN 2
00108 #define wxSTC_H_ATTRIBUTE 3
00109 #define wxSTC_H_ATTRIBUTEUNKNOWN 4
00110 #define wxSTC_H_NUMBER 5
00111 #define wxSTC_H_DOUBLESTRING 6
00112 #define wxSTC_H_SINGLESTRING 7
00113 #define wxSTC_H_OTHER 8
00114 #define wxSTC_H_COMMENT 9
00115 #define wxSTC_H_ENTITY 10
00116 */
00117 }
00118 
00119 void wxPackageSourceEditCtrl::UpdateScrollWidth()
00120 {
00121     if (GetWrapMode() == wxSTC_WRAP_WORD)
00122         return;       // we have no scrollbars to update
00123 
00124     // compute the width of the longest line of text we contain
00125     // NOTE: this is more optimized than using wxDC::GetMultiLineTextExtent
00126     //       which also computes the height of the given block
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     // get the lenght in pixels
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 // wxPackageSourceEditCtrl - event handlers
00150 // ----------------------------------------------------------------------------
00151 

Generated on Thu Feb 1 22:14:31 2007 for wxWidgets Package Manager by  doxygen 1.5.1-p1