#include <ctype.h>
#include <wx/wx.h>
+#include <wx/encconv.h>
+
#include "Platform.h"
#include "PlatWX.h"
break;
}
- // TODO: Use wxFontMapper and wxEncodingConverter if encoding not available.
+ wxFontEncodingArray ea = wxEncodingConverter::GetPlatformEquivalents(encoding);
+ if (ea.GetCount())
+ encoding = ea[0];
id = new wxFont(size,
wxDEFAULT,
italic ? wxITALIC : wxNORMAL,
bold ? wxBOLD : wxNORMAL,
false,
- faceName,
+ stc2wx(faceName),
encoding);
+#ifdef __WXMAC__
+ ((wxFont*)id)->SetNoAntiAliasing( true ) ;
+#endif
}
}
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_) {
int SurfaceImpl::DeviceHeightFont(int points) {
return points;
-// int logPix = LogPixelsY();
-// return (points * logPix + logPix / 2) / 72;
}
void SurfaceImpl::MoveTo(int x_, int y_) {
hdc->SetTextBackground(wxColourFromCA(back));
FillRectangle(rc, back);
-#if wxUSE_UNICODE
-#error fix this... Convert s from UTF-8.
-#else
- wxString str = wxString(s, len);
-#endif
-
// 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,
FillRectangle(rc, back);
hdc->SetClippingRegion(wxRectFromPRectangle(rc));
-#if wxUSE_UNICODE
-#error fix this... Convert s from UTF-8.
-#else
- wxString str = wxString(s, len);
-#endif
-
// see comments above
- hdc->DrawText(str, rc.left, ybase - font.ascent);
+ hdc->DrawText(stc2wx(s, len), rc.left, ybase - font.ascent);
hdc->DestroyClippingRegion();
}
int w;
int h;
-#if wxUSE_UNICODE
-#error fix this... Convert s from UTF-8.
-#else
- wxString str = wxString(s, len);
-#endif
-
- 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) {
-#if wxUSE_UNICODE
-#error fix this... Convert s from UTF-8.
-#else
- wxString str = wxString(s, len);
-#endif
+void SurfaceImpl::MeasureWidths(Font &font, const char *s, int len, int *positions) {
+ wxString str = stc2wx(s, len);
SetFont(font);
+
+ // Calculate the position of each character based on the widths of
+ // the previous characters
+ int* tpos = new int[len];
int totalWidth = 0;
- for (size_t i=0; i<(size_t)len; i++) {
- int w;
- int h;
+ size_t i;
+ for (i=0; i<str.Length(); i++) {
+ int w, h;
hdc->GetTextExtent(str[i], &w, &h);
totalWidth += w;
- positions[i] = totalWidth;
+ tpos[i] = totalWidth;
}
+
+#if wxUSE_UNICODE
+ // Map the widths for UCS-2 characters back to the UTF-8 input string
+ i = 0;
+ size_t ui = 0;
+ while (i < len) {
+ unsigned char uch = (unsigned char)s[i];
+ positions[i++] = tpos[ui];
+ if (uch >= 0x80) {
+ if (uch < (0x80 + 0x40 + 0x20)) {
+ positions[i++] = tpos[ui];
+ } else {
+ positions[i++] = tpos[ui];
+ positions[i++] = tpos[ui];
+ }
+ }
+ ui++;
+ }
+#else
+
+ // If not unicode then just use the widths we have
+ memcpy(positions, tpos, len * sizeof(*tpos));
+#endif
+
+ delete [] tpos;
}
+
int SurfaceImpl::WidthChar(Font &font, char ch) {
SetFont(font);
int w;
int h;
-#if wxUSE_UNICODE
-#error fix this... Convert s from UTF-8.
-#else
- hdc->GetTextExtent(ch, &w, &h);
-#endif
+ char s[2] = { ch, 0 };
+
+ hdc->GetTextExtent(stc2wx(s, 1), &w, &h);
return w;
}
}
void SurfaceImpl::SetUnicodeMode(bool unicodeMode_) {
- // TODO: Make this jive with wxUSE_UNICODE
unicodeMode=unicodeMode_;
+#if wxUSE_UNICODE
+ wxASSERT_MSG(unicodeMode == wxUSE_UNICODE,
+ wxT("Only unicode may be used when wxUSE_UNICODE is on."));
+#else
+ wxASSERT_MSG(unicodeMode == wxUSE_UNICODE,
+ wxT("Only non-unicode may be used when wxUSE_UNICODE is off."));
+#endif
}
Surface *Surface::Allocate() {
void Window::InvalidateAll() {
GETWIN(id)->Refresh(false);
+ wxWakeUpIdle();
}
void Window::InvalidateRectangle(PRectangle rc) {
wxRect r = wxRectFromPRectangle(rc);
GETWIN(id)->Refresh(false, &r);
+ wxWakeUpIdle();
}
void Window::SetFont(Font &font) {
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) {
-#if wxUSE_UNICODE
-#error Fix this...
-#else
- GETWIN(id)->SetTitle(s);
-#endif
+ 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:
};
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 // 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.
-
-#if wxUSE_POPUPWIN
+#if wxUSE_POPUPWIN && wxSTC_USE_POPUP
#include <wx/popupwin.h>
#define wxSTCListBoxWinBase wxPopupWindow
#define param2 wxBORDER_NONE // popup's 2nd param is flags
#else
#define wxSTCListBoxWinBase wxWindow
-#define param2 -1 // wxWindows 2nd param is ID
+#define param2 -1 // wxWindow's 2nd param is ID
#endif
class wxSTCListBoxWin : public wxSTCListBoxWinBase {
wxSTCListBoxWin(wxWindow* parent, wxWindowID id)
: 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; }
-#if wxUSE_POPUPWIN
+#if wxUSE_POPUPWIN && wxSTC_USE_POPUP
virtual void DoSetSize(int x, int y,
int width, int height,
int sizeFlags = wxSIZE_AUTO) {
};
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());
rc.left = 0;
if (sz.x > 400)
sz.x = 400;
- if (sz.y > 160) // TODO: Use desiredVisibleRows??
- sz.y = 160;
+ if (sz.y > 140) // TODO: Use desiredVisibleRows??
+ sz.y = 140;
rc.right = sz.x;
rc.bottom = sz.y;
return rc;
}
void ListBox::Append(char *s) {
- GETLB(id)->Append(s);
+ GETLB(id)->Append(stc2wx(s));
}
int ListBox::Length() {
if (n > 4)
n = n - 4;
else
- n = 1;
+ n = 0;
GETLB(id)->SetFirstItem(n);
#endif
}
}
void ListBox::GetValue(int n, char *value, int len) {
-#if wxUSE_UNICODE
-#error fix this...
wxString text = GETLB(id)->GetString(n);
- strncpy(value, text.c_str(), len);
+ strncpy(value, wx2stc(text), len);
value[len-1] = '\0';
-#endif
}
void ListBox::Sort() {
}
const char *Platform::DefaultFont() {
- return wxNORMAL_FONT->GetFaceName();
+ static char buf[128];
+ strcpy(buf, wxNORMAL_FONT->GetFaceName().mbc_str());
+ return buf;
}
int Platform::DefaultFontSize() {
}
void Platform::DebugDisplay(const char *s) {
- wxLogDebug(s);
+ wxLogDebug(stc2wx(s));
}
bool Platform::IsKeyDown(int key) {
return stc->SendMsg(msg, wParam, lParam);
}
+long Platform::SendScintillaPointer(WindowID w,
+ unsigned int msg,
+ unsigned long wParam,
+ void *lParam) {
+
+ wxStyledTextCtrl* stc = (wxStyledTextCtrl*)w;
+ return stc->SendMsg(msg, wParam, (long)lParam);
+}
+
// These are utility functions not really tied to a platform
char buffer[2000];
sprintf(buffer, "Assertion [%s] failed at %s %d", c, file, line);
if (assertionPopUps) {
- int idButton = wxMessageBox(buffer, "Assertion failure",
- wxICON_HAND | wxOK);
+ /*int idButton = */
+ wxMessageBox(stc2wx(buffer),
+ wxT("Assertion failure"),
+ wxICON_HAND | wxOK);
// if (idButton == IDRETRY) {
// ::DebugBreak();
// } else if (idButton == IDIGNORE) {