X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/9c46ea66472d59fe5fe623c456e540e47d922fcf..585a7f9db315c3ef39cf09ff5e65b14cdcea04bf:/src/stc/PlatWX.cpp?ds=sidebyside diff --git a/src/stc/PlatWX.cpp b/src/stc/PlatWX.cpp index 23dd10d5bd..8edc3bf5e7 100644 --- a/src/stc/PlatWX.cpp +++ b/src/stc/PlatWX.cpp @@ -187,7 +187,7 @@ void Font::Create(const char *faceName, int characterSet, int size, bool bold, b italic ? wxITALIC : wxNORMAL, bold ? wxBOLD : wxNORMAL, false, - wxString(faceName, wxConvUTF8), + stc2wx(faceName), encoding); } @@ -284,9 +284,16 @@ bool SurfaceImpl::Initialised() { } void SurfaceImpl::Init() { +#if 0 Release(); hdc = new wxMemoryDC(); hdcOwned = true; +#else + // On Mac and GTK the DC is not really valid until it has a bitmap + // selected into it. So instead of just creating the DC with no bitmap, + // go ahead and give it one. + InitPixMap(1,1,NULL); +#endif } void SurfaceImpl::Init(SurfaceID hdc_) { @@ -393,12 +400,9 @@ void SurfaceImpl::DrawTextNoClip(PRectangle rc, Font &font, int ybase, hdc->SetTextBackground(wxColourFromCA(back)); FillRectangle(rc, back); - // will convert from UTF-8 in unicode mode - wxString str(s, wxConvUTF8, len); - // ybase is where the baseline should be, but wxWin uses the upper left // corner, so I need to calculate the real position for the text... - hdc->DrawText(str, rc.left, ybase - font.ascent); + hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); } void SurfaceImpl::DrawTextClipped(PRectangle rc, Font &font, int ybase, @@ -410,11 +414,8 @@ void SurfaceImpl::DrawTextClipped(PRectangle rc, Font &font, int ybase, FillRectangle(rc, back); hdc->SetClippingRegion(wxRectFromPRectangle(rc)); - // will convert from UTF-8 in unicode mode - wxString str(s, wxConvUTF8, len); - // see comments above - hdc->DrawText(str, rc.left, ybase - font.ascent); + hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent); hdc->DestroyClippingRegion(); } @@ -423,17 +424,13 @@ int SurfaceImpl::WidthText(Font &font, const char *s, int len) { int w; int h; - // will convert from UTF-8 in unicode mode - wxString str(s, wxConvUTF8, len); - - hdc->GetTextExtent(str, &w, &h); + hdc->GetTextExtent(stc2wx(s, len), &w, &h); return w; } void SurfaceImpl::MeasureWidths(Font &font, const char *s, int len, int *positions) { - // will convert from UTF-8 in unicode mode - wxString str(s, wxConvUTF8, len); + wxString str = stc2wx(s, len); SetFont(font); // Calculate the position of each character based on the widths of @@ -481,9 +478,7 @@ int SurfaceImpl::WidthChar(Font &font, char ch) { int h; char s[2] = { ch, 0 }; - // will convert from UTF-8 in unicode mode - wxString str(s, wxConvUTF8, 1); - hdc->GetTextExtent(str, &w, &h); + hdc->GetTextExtent(stc2wx(s, 1), &w, &h); return w; } @@ -637,32 +632,66 @@ void Window::SetCursor(Cursor curs) { cursorId = wxCURSOR_ARROW; break; } - - GETWIN(id)->SetCursor(wxCursor(cursorId)); +#ifdef __WXMOTIF__ + wxCursor wc = wxStockCursor(cursorId) ; +#else + wxCursor wc = wxCursor(cursorId) ; +#endif + GETWIN(id)->SetCursor(wc); } void Window::SetTitle(const char *s) { - // will convert from UTF-8 in unicode mode - wxString str(s, wxConvUTF8); - GETWIN(id)->SetTitle(str); + GETWIN(id)->SetTitle(stc2wx(s)); } //---------------------------------------------------------------------- // Helper classes for ListBox -// A wxListBox that gives focus back to its parent if it gets it. + +#if 1 // defined(__WXMAC__) +class wxSTCListBoxWin : public wxListBox { +public: + wxSTCListBoxWin(wxWindow* parent, wxWindowID id) + : wxListBox(parent, id, wxDefaultPosition, wxSize(0,0), + 0, NULL, wxLB_SINGLE | wxSIMPLE_BORDER) { + SetCursor(wxCursor(wxCURSOR_ARROW)); + Hide(); + } + + void OnFocus(wxFocusEvent& event) { + GetParent()->SetFocus(); + event.Skip(); + } + + wxListBox* GetLB() { return this; } + +private: + DECLARE_EVENT_TABLE() +}; + + +BEGIN_EVENT_TABLE(wxSTCListBoxWin, wxListBox) + EVT_SET_FOCUS(wxSTCListBoxWin::OnFocus) +END_EVENT_TABLE() + + + +#else + + class wxSTCListBox : public wxListBox { public: wxSTCListBox(wxWindow* parent, wxWindowID id) : wxListBox(parent, id, wxDefaultPosition, wxDefaultSize, - 0, NULL, wxLB_SINGLE | wxSIMPLE_BORDER) + 0, NULL, wxLB_SINGLE | wxSIMPLE_BORDER | wxWANTS_CHARS) {} - void OnFocus(wxFocusEvent& event) { - GetParent()->SetFocus(); - event.Skip(); + void OnKeyDown(wxKeyEvent& event) { + // Give the key events to the STC. It will then update + // the listbox as needed. + GetGrandParent()->GetEventHandler()->ProcessEvent(event); } private: @@ -670,13 +699,15 @@ private: }; BEGIN_EVENT_TABLE(wxSTCListBox, wxListBox) - EVT_SET_FOCUS(wxSTCListBox::OnFocus) + EVT_KEY_DOWN(wxSTCListBox::OnKeyDown) + EVT_CHAR(wxSTCListBox::OnKeyDown) END_EVENT_TABLE() -#undef wxSTC_USE_POPUP -#define wxSTC_USE_POPUP 0 // Leave it off for this one... +#undef wxSTC_USE_POPUP +#define wxSTC_USE_POPUP 0 // wxPopupWindow just doesn't work well in this case... + // A window to place the listbox upon. If wxPopupWindow is supported then // that will be used so the listbox can extend beyond the client area of the // wxSTC if needed. @@ -695,17 +726,14 @@ public: : wxSTCListBoxWinBase(parent, param2) { lb = new wxSTCListBox(this, id); lb->SetCursor(wxCursor(wxCURSOR_ARROW)); - } + lb->SetFocus(); + } void OnSize(wxSizeEvent& event) { lb->SetSize(GetSize()); } - void OnFocus(wxFocusEvent& event) { - GetParent()->SetFocus(); - event.Skip(); - } - wxListBox* GetLB() { return lb; } + wxListBox* GetLB() { return lb; } #if wxUSE_POPUPWIN && wxSTC_USE_POPUP virtual void DoSetSize(int x, int y, @@ -725,10 +753,9 @@ private: }; BEGIN_EVENT_TABLE(wxSTCListBoxWin, wxSTCListBoxWinBase) - EVT_SIZE (wxSTCListBoxWin::OnSize) - EVT_SET_FOCUS (wxSTCListBoxWin::OnFocus) + EVT_SIZE(wxSTCListBoxWin::OnSize) END_EVENT_TABLE() - +#endif inline wxListBox* GETLB(WindowID win) { return (((wxSTCListBoxWin*)win)->GetLB()); @@ -806,7 +833,7 @@ int ListBox::Find(const char *prefix) { void ListBox::GetValue(int n, char *value, int len) { wxString text = GETLB(id)->GetString(n); - strncpy(value, text.mb_str(wxConvUTF8), len); + strncpy(value, wx2stc(text), len); value[len-1] = '\0'; } @@ -863,7 +890,7 @@ unsigned int Platform::DoubleClickTime() { } void Platform::DebugDisplay(const char *s) { - wxLogDebug(wxString(s, *wxConvCurrent)); + wxLogDebug(stc2wx(s)); } bool Platform::IsKeyDown(int key) { @@ -922,9 +949,10 @@ void Platform::Assert(const char *c, const char *file, int line) { char buffer[2000]; sprintf(buffer, "Assertion [%s] failed at %s %d", c, file, line); if (assertionPopUps) { - int idButton = wxMessageBox(wxString(buffer, *wxConvCurrent), - wxT("Assertion failure"), - wxICON_HAND | wxOK); + /*int idButton = */ + wxMessageBox(stc2wx(buffer), + wxT("Assertion failure"), + wxICON_HAND | wxOK); // if (idButton == IDRETRY) { // ::DebugBreak(); // } else if (idButton == IDIGNORE) {