X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/74e1efddbc1c76b5888e51ac83e10a161e62e141..29fbbf8967e4c4b3174a4bc45a9007b92ecb0de7:/src/stc/PlatWX.cpp diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 0e92b30e8a..6a5cc02735 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -4,9 +4,27 @@ // Robin Dunn // The License.txt file describes the conditions under which this software may be distributed. +// For compilers that support precompilation, includes "wx.h". +#include "wx/wxprec.h" + +#ifdef __BORLANDC__ + #pragma hdrstop +#endif + +#if wxUSE_STC + +#ifndef WX_PRECOMP + #include "wx/menu.h" + #include "wx/dcmemory.h" + #include "wx/settings.h" +#endif // WX_PRECOMP + #include -#include "wx/wx.h" +#if wxUSE_DISPLAY +#include "wx/display.h" +#endif + #include "wx/encconv.h" #include "wx/listctrl.h" #include "wx/mstream.h" @@ -21,6 +39,7 @@ #include "Platform.h" #include "PlatWX.h" #include "wx/stc/stc.h" +#include "wx/stc/private.h" @@ -119,8 +138,9 @@ Font::Font() { Font::~Font() { } -void Font::Create(const char *faceName, int characterSet, int size, bool bold, bool italic, bool extraFontFlag) { - +void Font::Create(const char *faceName, int characterSet, + int size, bool bold, bool italic, + bool extraFontFlag) { Release(); // The minus one is done because since Scintilla uses SC_SHARSET_DEFAULT @@ -352,12 +372,11 @@ void SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, // TODO: do something with cornerSize wxUnusedVar(cornerSize); - + int x, y; wxRect r = wxRectFromPRectangle(rc); wxBitmap bmp(r.width, r.height, 32); wxAlphaPixelData pixData(bmp); - pixData.UseAlpha(); // Set the fill pixels ColourDesired cdf(fill.AsLong()); @@ -373,7 +392,7 @@ void SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, p.Green() = wxPy_premultiply(green, alphaFill); p.Blue() = wxPy_premultiply(blue, alphaFill); p.Alpha() = alphaFill; - ++p; + ++p; } } @@ -387,12 +406,12 @@ void SurfaceImpl::AlphaRectangle(PRectangle rc, int cornerSize, p.Red() = wxPy_premultiply(red, alphaOutline); p.Green() = wxPy_premultiply(green, alphaOutline); p.Blue() = wxPy_premultiply(blue, alphaOutline); - p.Alpha() = alphaOutline; + p.Alpha() = alphaOutline; p.MoveTo(pixData, x, r.height-1); p.Red() = wxPy_premultiply(red, alphaOutline); p.Green() = wxPy_premultiply(green, alphaOutline); p.Blue() = wxPy_premultiply(blue, alphaOutline); - p.Alpha() = alphaOutline; + p.Alpha() = alphaOutline; } for (y=0; yDrawBitmap(bmp, r.x, r.y, true); @@ -707,6 +726,19 @@ void Window::SetTitle(const char *s) { } +// Returns rectangle of monitor pt is on +PRectangle Window::GetMonitorRect(Point pt) { + wxRect rect; + if (! id) return PRectangle(); +#if wxUSE_DISPLAY + // Get the display the point is found on + int n = wxDisplay::GetFromPoint(wxPoint(pt.x, pt.y)); + wxDisplay dpy(n == wxNOT_FOUND ? 0 : n); + rect = dpy.GetGeometry(); +#endif + return PRectangleFromwxRect(rect); +} + //---------------------------------------------------------------------- // Helper classes for ListBox @@ -769,7 +801,7 @@ END_EVENT_TABLE() #if wxUSE_POPUPWIN //----------------------------------- -#include +#include "wx/popupwin.h" // @@ -791,9 +823,10 @@ public: wxSTCListBoxWin(wxWindow* parent, wxWindowID id, Point WXUNUSED(location)) : wxPopupWindow(parent, wxBORDER_NONE) { + SetBackgroundColour(*wxBLACK); // for our simple border - lv = new wxSTCListBox(parent, id, wxDefaultPosition, wxDefaultSize, + lv = new wxSTCListBox(parent, id, wxPoint(-50,-50), wxDefaultSize, wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_NO_HEADER | wxBORDER_NONE); lv->SetCursor(wxCursor(wxCURSOR_ARROW)); lv->InsertColumn(0, wxEmptyString); @@ -897,17 +930,28 @@ END_EVENT_TABLE() -#else // wxUSE_POPUPWIN ----------------------------------- +#else // !wxUSE_POPUPWIN ----------------------------------- +#include "wx/frame.h" -// A normal window to place the wxSTCListBox upon. -class wxSTCListBoxWin : public wxWindow { +// A normal window to place the wxSTCListBox upon, but make it behave as much +// like a wxPopupWindow as possible +class wxSTCListBoxWin : public wxFrame { private: wxListView* lv; CallBackAction doubleClickAction; void* doubleClickActionData; public: wxSTCListBoxWin(wxWindow* parent, wxWindowID id, Point location) : - wxWindow(parent, id, wxPoint(location.x, location.y), wxSize(0,0), wxSIMPLE_BORDER ) + wxFrame(parent, id, wxEmptyString, wxPoint(location.x, location.y), wxSize(0,0), + wxFRAME_NO_TASKBAR + | wxFRAME_FLOAT_ON_PARENT +#ifdef __WXMAC__ + | wxPOPUP_WINDOW + | wxNO_BORDER +#else + | wxSIMPLE_BORDER +#endif + ) { lv = new wxSTCListBox(this, id, wxDefaultPosition, wxDefaultSize, @@ -928,7 +972,8 @@ public: // messages/events for the list control when Scintilla wants to // close it, so do a pending delete of it instead of destroying // immediately. - bool Destroy() { + bool Destroy() + { #ifdef __WXMAC__ // The bottom edge of this window is not getting properly // refreshed upon deletion, so help it out... @@ -943,7 +988,8 @@ public: } - int IconWidth() { + int IconWidth() + { wxImageList* il = lv->GetImageList(wxIMAGE_LIST_SMALL); if (il != NULL) { int w, h; @@ -954,18 +1000,22 @@ public: } - void SetDoubleClickAction(CallBackAction action, void *data) { + void SetDoubleClickAction(CallBackAction action, void *data) + { doubleClickAction = action; doubleClickActionData = data; } - void OnFocus(wxFocusEvent& event) { + void OnFocus(wxFocusEvent& event) + { + ActivateParent(); GetParent()->SetFocus(); event.Skip(); } - void OnSize(wxSizeEvent& event) { + void OnSize(wxSizeEvent& event) + { // resize the child wxSize sz = GetClientSize(); lv->SetSize(sz); @@ -976,15 +1026,44 @@ public: event.Skip(); } + void ActivateParent() + { + // Although we're a frame, we always want the parent to be active, so + // raise it whenever we get shown, focused, etc. + wxTopLevelWindow *frame = wxDynamicCast( + wxGetTopLevelParent(GetParent()), wxTopLevelWindow); + if (frame) + frame->Raise(); + } + + + virtual void DoSetSize(int x, int y, + int width, int height, + int sizeFlags = wxSIZE_AUTO) + { + // convert coords to screen coords since we're a top-level window + if (x != wxDefaultCoord) { + GetParent()->ClientToScreen(&x, NULL); + } + if (y != wxDefaultCoord) { + GetParent()->ClientToScreen(NULL, &y); + } + wxFrame::DoSetSize(x, y, width, height, sizeFlags); + } + + virtual bool Show(bool show = true) + { + bool rv = wxFrame::Show(show); + if (rv && show) + ActivateParent(); #ifdef __WXMAC__ - virtual bool Show(bool show = true) { - bool rv = wxWindow::Show(show); GetParent()->Refresh(false); +#endif return rv; } -#endif - void OnActivate(wxListEvent& WXUNUSED(event)) { + void OnActivate(wxListEvent& WXUNUSED(event)) + { doubleClickAction(doubleClickActionData); } @@ -1155,13 +1234,14 @@ void ListBoxImpl::Append(char *s, int type) { void ListBoxImpl::Append(const wxString& text, int type) { long count = GETLB(id)->GetItemCount(); long itemID = GETLB(id)->InsertItem(count, wxEmptyString); + long idx = -1; GETLB(id)->SetItem(itemID, 1, text); maxStrWidth = wxMax(maxStrWidth, text.length()); if (type != -1) { wxCHECK_RET(imgTypeMap, wxT("Unexpected NULL imgTypeMap")); - long idx = imgTypeMap->Item(type); - GETLB(id)->SetItemImage(itemID, idx, idx); + idx = imgTypeMap->Item(type); } + GETLB(id)->SetItemImage(itemID, idx, idx); } void ListBoxImpl::SetList(const char* list, char separator, char typesep) { @@ -1193,7 +1273,7 @@ void ListBoxImpl::Select(int n) { n = 0; select = false; } - GETLB(id)->Focus(n); + GETLB(id)->EnsureVisible(n); GETLB(id)->Select(n, select); } @@ -1388,6 +1468,8 @@ void Platform::DebugPrintf(const char *format, ...) { vsprintf(buffer,format,pArguments); va_end(pArguments); Platform::DebugDisplay(buffer); +#else + wxUnusedVar(format); #endif } @@ -1480,10 +1562,10 @@ wxString stc2wx(const char* str, size_t len) if (!len) return wxEmptyString; - size_t wclen = UCS2Length(str, len); + size_t wclen = UTF16Length(str, len); wxWCharBuffer buffer(wclen+1); - size_t actualLen = UCS2FromUTF8(str, len, buffer.data(), wclen+1); + size_t actualLen = UTF16FromUTF8(str, len, buffer.data(), wclen+1); return wxString(buffer.data(), actualLen); } @@ -1502,7 +1584,7 @@ const wxWX2MBbuf wx2stc(const wxString& str) size_t len = UTF8Length(wcstr, wclen); wxCharBuffer buffer(len+1); - UTF8FromUCS2(wcstr, wclen, buffer.data(), len); + UTF8FromUTF16(wcstr, wclen, buffer.data(), len); // TODO check NULL termination!! @@ -1510,3 +1592,5 @@ const wxWX2MBbuf wx2stc(const wxString& str) } #endif + +#endif // wxUSE_STC