#include "Platform.h"
#include "wx/stc/stc.h"
+
+#ifdef __WXGTK__
+#include <gtk/gtk.h>
+#endif
+
Point Point::FromLong(long lpoint) {
return Point(lpoint & 0xFFFF, lpoint >> 16);
}
}
PRectangle PRectangleFromwxRect(wxRect rc) {
- return PRectangle(rc.GetLeft(), rc.GetTop(), rc.GetRight(), rc.GetBottom());
+ return PRectangle(rc.GetLeft(), rc.GetTop(),
+ rc.GetRight()+1, rc.GetBottom()+1);
}
Colour::Colour(long lcol) {
}
void Font::Create(const char *faceName, int characterSet, int size, bool bold, bool italic) {
+ // TODO: what to do about the characterSet?
+
Release();
id = new wxFont(size,
wxDEFAULT,
Release();
hdc = new wxMemoryDC();
hdcOwned = true;
- // **** ::SetTextAlign(hdc, TA_BASELINE);
}
void Surface::Init(SurfaceID hdc_) {
Release();
hdc = hdc_;
- // **** ::SetTextAlign(hdc, TA_BASELINE);
}
void Surface::InitPixMap(int width, int height, Surface *surface_) {
Release();
hdc = new wxMemoryDC(surface_->hdc);
hdcOwned = true;
+ if (width < 1) width = 1;
+ if (height < 1) height = 1;
bitmap = new wxBitmap(width, height);
((wxMemoryDC*)hdc)->SelectObject(*bitmap);
- // **** ::SetTextAlign(hdc, TA_BASELINE);
}
void Surface::PenColour(Colour fore) {
int Surface::DeviceHeightFont(int points) {
- return points * LogPixelsY() / 72;
+ return points;
}
}
int Surface::SetPalette(Palette *pal, bool inBackGround) {
- return 0; // **** figure out what to do with palettes...
+ return 0;
}
void Surface::SetClip(PRectangle rc) {
}
+//----------------------------------------------------------------------
+// Helper classes for ListBox
+
+// A wxListBox that gives focus to its parent if it gets it.
+class wxSTCListBox : public wxListBox {
+public:
+ wxSTCListBox(wxWindow* parent, wxWindowID id)
+ : wxListBox(parent, id, wxDefaultPosition, wxDefaultSize,
+ 0, NULL, wxLB_SINGLE | wxSIMPLE_BORDER)
+ {}
+
+ void OnFocus(wxFocusEvent& event) {
+ GetParent()->SetFocus();
+ event.Skip();
+ }
+
+private:
+ DECLARE_EVENT_TABLE()
+};
+
+BEGIN_EVENT_TABLE(wxSTCListBox, wxListBox)
+ EVT_SET_FOCUS(wxSTCListBox::OnFocus)
+END_EVENT_TABLE()
+
+
+
+// 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
+#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
+#endif
+
+class wxSTCListBoxWin : public wxSTCListBoxWinBase {
+public:
+ wxSTCListBoxWin(wxWindow* parent, wxWindowID id)
+ : wxSTCListBoxWinBase(parent, param2) {
+ lb = new wxSTCListBox(this, id);
+ }
+
+ void OnSize(wxSizeEvent& event) {
+ lb->SetSize(GetSize());
+ }
+ void OnFocus(wxFocusEvent& event) {
+ GetParent()->SetFocus();
+ event.Skip();
+ }
+
+ wxListBox* GetLB() { return lb; }
+
+#if wxUSE_POPUPWIN
+ virtual void DoSetSize(int x, int y,
+ int width, int height,
+ int sizeFlags = wxSIZE_AUTO) {
+ if (x != -1)
+ GetParent()->ClientToScreen(&x, NULL);
+ if (y != -1)
+ GetParent()->ClientToScreen(NULL, &y);
+ wxSTCListBoxWinBase::DoSetSize(x, y, width, height, sizeFlags);
+ }
+#endif
+
+private:
+ wxSTCListBox* lb;
+ DECLARE_EVENT_TABLE()
+};
+
+BEGIN_EVENT_TABLE(wxSTCListBoxWin, wxSTCListBoxWinBase)
+ EVT_SIZE (wxSTCListBoxWin::OnSize)
+ EVT_SET_FOCUS (wxSTCListBoxWin::OnFocus)
+END_EVENT_TABLE()
+
+
+#define GETLB(win) (((wxSTCListBoxWin*)win)->GetLB())
+
+//----------------------------------------------------------------------
ListBox::ListBox() {
}
}
void ListBox::Create(Window &parent, int ctrlID) {
- id = new wxListBox(parent.id, ctrlID, wxDefaultPosition, wxDefaultSize,
- 0, NULL, wxLB_SINGLE | wxLB_SORT);
+ id = new wxSTCListBoxWin(parent.id, ctrlID);
+}
+
+void ListBox::SetVisibleRows(int rows) {
+ desiredVisibleRows = rows;
+}
+
+PRectangle ListBox::GetDesiredRect() {
+ wxSize sz = GETLB(id)->GetBestSize();
+ PRectangle rc;
+ rc.top = 0;
+ rc.left = 0;
+ if (sz.x > 400)
+ sz.x = 400;
+ if (sz.y > 160) // TODO: Use desiredVisibleRows??
+ sz.y = 160;
+ rc.right = sz.x;
+ rc.bottom = sz.y;
+ return rc;
+}
+
+void ListBox::SetAverageCharWidth(int width) {
+ aveCharWidth = width;
+}
+
+void ListBox::SetFont(Font &font) {
+ GETLB(id)->SetFont(*font.GetID());
}
void ListBox::Clear() {
- ((wxListBox*)id)->Clear();
+ GETLB(id)->Clear();
}
void ListBox::Append(char *s) {
- ((wxListBox*)id)->Append(s);
+ GETLB(id)->Append(s);
}
int ListBox::Length() {
- return ((wxListBox*)id)->Number();
+ return GETLB(id)->GetCount();
}
void ListBox::Select(int n) {
- ((wxListBox*)id)->SetSelection(n);
+ GETLB(id)->SetSelection(n);
+#ifdef __WXGTK__
+ if (n > 4)
+ n = n - 4;
+ else
+ n = 1;
+ GETLB(id)->SetFirstItem(n);
+#endif
}
int ListBox::GetSelection() {
- return ((wxListBox*)id)->GetSelection();
+ return GETLB(id)->GetSelection();
}
int ListBox::Find(const char *prefix) {
- if (prefix) {
- for (int x=0; x < ((wxListBox*)id)->Number(); x++) {
- wxString text = ((wxListBox*)id)->GetString(x);
- if (text.StartsWith(prefix))
- return x;
- }
- }
+ // No longer used
return -1;
}
void ListBox::GetValue(int n, char *value, int len) {
- wxString text = ((wxListBox*)id)->GetString(n);
+ wxString text = GETLB(id)->GetString(n);
strncpy(value, text.c_str(), len);
value[len-1] = '\0';
}
void ListBox::Sort() {
- // wxWindows keeps sorted so no need to sort
}
Colour Platform::Chrome() {
wxColour c;
- c = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DFACE);
+ c = wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE);
return Colour(c.Red(), c.Green(), c.Blue());
}
Colour Platform::ChromeHighlight() {
wxColour c;
- c = wxSystemSettings::GetSystemColour(wxSYS_COLOUR_3DHIGHLIGHT);
+ c = wxSystemSettings::GetColour(wxSYS_COLOUR_3DHIGHLIGHT);
return Colour(c.Red(), c.Green(), c.Blue());
}
#endif
}
+
+static bool assertionPopUps = true;
+
+bool Platform::ShowAssertionPopUps(bool assertionPopUps_) {
+ bool ret = assertionPopUps;
+ assertionPopUps = assertionPopUps_;
+ return ret;
+}
+
+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(buffer, "Assertion failure",
+ wxICON_HAND | wxOK);
+// if (idButton == IDRETRY) {
+// ::DebugBreak();
+// } else if (idButton == IDIGNORE) {
+// // all OK
+// } else {
+// abort();
+// }
+ } else {
+ strcat(buffer, "\r\n");
+ Platform::DebugDisplay(buffer);
+ abort();
+ }
+}
+
+
int Platform::Clamp(int val, int minVal, int maxVal) {
if (val > maxVal)
val = maxVal;