X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7475e8146203b9f75ea01247eb456209ed7b7c13..bcbd69875f4e9149eb22d922f94d99e307fdd280:/src/stc/stc.cpp.in?ds=sidebyside diff --git a/src/stc/stc.cpp.in b/src/stc/stc.cpp.in index c339d40d8f..a859ec1a47 100644 --- a/src/stc/stc.cpp.in +++ b/src/stc/stc.cpp.in @@ -136,11 +136,27 @@ wxStyledTextCtrl::wxStyledTextCtrl(wxWindow *parent, const wxPoint& pos, const wxSize& size, long style, - const wxString& name) : - wxControl(parent, id, pos, size, - style | wxVSCROLL | wxHSCROLL | wxWANTS_CHARS | wxCLIP_CHILDREN, - wxDefaultValidator, name) + const wxString& name) { + m_swx = NULL; + Create(parent, id, pos, size, style, name); +} + + +void wxStyledTextCtrl::Create(wxWindow *parent, + wxWindowID id, + const wxPoint& pos, + const wxSize& size, + long style, + const wxString& name) +{ +#ifdef __WXMAC__ + style |= wxVSCROLL | wxHSCROLL; +#endif + wxControl::Create(parent, id, pos, size, + style | wxWANTS_CHARS | wxCLIP_CHILDREN, + wxDefaultValidator, name); + #ifdef LINK_LEXERS Scintilla_LinkLexers(); #endif @@ -320,7 +336,7 @@ bool wxStyledTextCtrl::SaveFile(const wxString& filename) if (!file.IsOpened()) return FALSE; - bool success = file.Write(GetText()); + bool success = file.Write(GetText(), *wxConvCurrent); if (success) SetSavePoint(); @@ -337,12 +353,20 @@ bool wxStyledTextCtrl::LoadFile(const wxString& filename) { wxString contents; off_t len = file.Length(); - if (len > 0) { - wxChar *buf = contents.GetWriteBuf(len); - success = (file.Read(buf, len) == len); - contents.UngetWriteBuf(); +#if wxUSE_UNICODE + wxMemoryBuffer buffer(len+1); + success = (file.Read(buffer.GetData(), len) == len); + if (success) { + ((char*)buffer.GetData())[len] = 0; + contents = wxString(buffer, *wxConvCurrent, len); + } +#else + wxString buffer; + success = (file.Read(wxStringBuffer(buffer, len), len) == len); + contents = buffer; +#endif } else success = true; // empty file is ok @@ -359,10 +383,30 @@ bool wxStyledTextCtrl::LoadFile(const wxString& filename) } +#if wxUSE_DRAG_AND_DROP +wxDragResult wxStyledTextCtrl::DoDragOver(wxCoord x, wxCoord y, wxDragResult def) { + return m_swx->DoDragOver(x, y, def); +} + + +bool wxStyledTextCtrl::DoDropText(long x, long y, const wxString& data) { + return m_swx->DoDropText(x, y, data); +} +#endif + + +void wxStyledTextCtrl::SetUseAntiAliasing(bool useAA) { + m_swx->SetUseAntiAliasing(useAA); +} + +bool wxStyledTextCtrl::GetUseAntiAliasing() { + return m_swx->GetUseAntiAliasing(); +} + //---------------------------------------------------------------------- // Event handlers -void wxStyledTextCtrl::OnPaint(wxPaintEvent& evt) { +void wxStyledTextCtrl::OnPaint(wxPaintEvent& WXUNUSED(evt)) { wxPaintDC dc(this); m_swx->DoPaint(&dc, GetUpdateRegion().GetBox()); } @@ -384,9 +428,11 @@ void wxStyledTextCtrl::OnScroll(wxScrollEvent& evt) { } } -void wxStyledTextCtrl::OnSize(wxSizeEvent& evt) { - wxSize sz = GetClientSize(); - m_swx->DoSize(sz.x, sz.y); +void wxStyledTextCtrl::OnSize(wxSizeEvent& WXUNUSED(evt)) { + if (m_swx) { + wxSize sz = GetClientSize(); + m_swx->DoSize(sz.x, sz.y); + } } void wxStyledTextCtrl::OnMouseLeftDown(wxMouseEvent& evt) { @@ -422,6 +468,14 @@ void wxStyledTextCtrl::OnMouseMiddleUp(wxMouseEvent& evt) { void wxStyledTextCtrl::OnContextMenu(wxContextMenuEvent& evt) { wxPoint pt = evt.GetPosition(); ScreenToClient(&pt.x, &pt.y); + /* + Show context menu at event point if it's within the window, + or at caret location if not + */ + wxHitTest ht = this->HitTest(pt); + if (ht != wxHT_WINDOW_INSIDE) { + pt = this->PointFromPosition(this->GetCurrentPos()); + } m_swx->DoContextMenu(Point(pt.x, pt.y)); } @@ -449,7 +503,7 @@ void wxStyledTextCtrl::OnChar(wxKeyEvent& evt) { // printf("OnChar key:%%d consumed:%%d ctrl:%%d alt:%%d skip:%%d\n", // key, m_lastKeyDownConsumed, ctrl, alt, skip); - if ( (key <= WXK_START || key > WXK_NUMPAD_DIVIDE) && + if ( (key <= WXK_START || key > WXK_COMMAND) && !m_lastKeyDownConsumed && !skip) { m_swx->DoAddChar(key); return; @@ -462,9 +516,10 @@ void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) { int key = evt.GetKeyCode(); bool shift = evt.ShiftDown(), ctrl = evt.ControlDown(), - alt = evt.AltDown(); + alt = evt.AltDown(), + meta = evt.MetaDown(); - int processed = m_swx->DoKeyDown(key, shift, ctrl, alt, &m_lastKeyDownConsumed); + int processed = m_swx->DoKeyDown(key, shift, ctrl, alt, meta, &m_lastKeyDownConsumed); // printf("KeyDn key:%%d shift:%%d ctrl:%%d alt:%%d processed:%%d consumed:%%d\n", // key, shift, ctrl, alt, processed, m_lastKeyDownConsumed); @@ -476,20 +531,22 @@ void wxStyledTextCtrl::OnKeyDown(wxKeyEvent& evt) { void wxStyledTextCtrl::OnLoseFocus(wxFocusEvent& evt) { m_swx->DoLoseFocus(); + evt.Skip(); } void wxStyledTextCtrl::OnGainFocus(wxFocusEvent& evt) { m_swx->DoGainFocus(); + evt.Skip(); } -void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& evt) { +void wxStyledTextCtrl::OnSysColourChanged(wxSysColourChangedEvent& WXUNUSED(evt)) { m_swx->DoSysColourChange(); } -void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent& evt) { +void wxStyledTextCtrl::OnEraseBackground(wxEraseEvent& WXUNUSED(evt)) { // do nothing to help avoid flashing } @@ -500,11 +557,16 @@ void wxStyledTextCtrl::OnMenu(wxCommandEvent& evt) { } -void wxStyledTextCtrl::OnListBox(wxCommandEvent& evt) { +void wxStyledTextCtrl::OnListBox(wxCommandEvent& WXUNUSED(evt)) { m_swx->DoOnListBox(); } +void wxStyledTextCtrl::OnIdle(wxIdleEvent& evt) { + m_swx->DoOnIdle(evt); +} + + //---------------------------------------------------------------------- // Turn notifications from Scintilla into events