📄 platwx.cpp
字号:
int SurfaceImpl::Ascent(Font &font) {
SetFont(font);
int w, h, d, e;
hdc->GetTextExtent(EXTENT_TEST, &w, &h, &d, &e);
font.ascent = h - d;
return font.ascent;
}
int SurfaceImpl::Descent(Font &font) {
SetFont(font);
int w, h, d, e;
hdc->GetTextExtent(EXTENT_TEST, &w, &h, &d, &e);
return d;
}
int SurfaceImpl::InternalLeading(Font &WXUNUSED(font)) {
return 0;
}
int SurfaceImpl::ExternalLeading(Font &font) {
SetFont(font);
int w, h, d, e;
hdc->GetTextExtent(EXTENT_TEST, &w, &h, &d, &e);
return e;
}
int SurfaceImpl::Height(Font &font) {
SetFont(font);
return hdc->GetCharHeight() + 1;
}
int SurfaceImpl::AverageCharWidth(Font &font) {
SetFont(font);
return hdc->GetCharWidth();
}
int SurfaceImpl::SetPalette(Palette *WXUNUSED(pal), bool WXUNUSED(inBackGround)) {
return 0;
}
void SurfaceImpl::SetClip(PRectangle rc) {
hdc->SetClippingRegion(wxRectFromPRectangle(rc));
}
void SurfaceImpl::FlushCachedState() {
}
void SurfaceImpl::SetUnicodeMode(bool unicodeMode_) {
unicodeMode=unicodeMode_;
}
void SurfaceImpl::SetDBCSMode(int WXUNUSED(codePage)) {
// dbcsMode = codePage == SC_CP_DBCS;
}
Surface *Surface::Allocate() {
return new SurfaceImpl;
}
//----------------------------------------------------------------------
inline wxWindow* GETWIN(WindowID id) { return (wxWindow*)id; }
Window::~Window() {
}
void Window::Destroy() {
if (id) {
Show(FALSE);
GETWIN(id)->Destroy();
}
id = 0;
}
bool Window::HasFocus() {
return wxWindow::FindFocus() == GETWIN(id);
}
PRectangle Window::GetPosition() {
if (! id) return PRectangle();
wxRect rc(GETWIN(id)->GetPosition(), GETWIN(id)->GetSize());
return PRectangleFromwxRect(rc);
}
void Window::SetPosition(PRectangle rc) {
wxRect r = wxRectFromPRectangle(rc);
GETWIN(id)->SetSize(r);
}
void Window::SetPositionRelative(PRectangle rc, Window) {
SetPosition(rc); // ????
}
PRectangle Window::GetClientPosition() {
if (! id) return PRectangle();
wxSize sz = GETWIN(id)->GetClientSize();
return PRectangle(0, 0, sz.x, sz.y);
}
void Window::Show(bool show) {
GETWIN(id)->Show(show);
}
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) {
GETWIN(id)->SetFont(*((wxFont*)font.GetID()));
}
void Window::SetCursor(Cursor curs) {
int cursorId;
switch (curs) {
case cursorText:
cursorId = wxCURSOR_IBEAM;
break;
case cursorArrow:
cursorId = wxCURSOR_ARROW;
break;
case cursorUp:
cursorId = wxCURSOR_ARROW; // ** no up arrow... wxCURSOR_UPARROW;
break;
case cursorWait:
cursorId = wxCURSOR_WAIT;
break;
case cursorHoriz:
cursorId = wxCURSOR_SIZEWE;
break;
case cursorVert:
cursorId = wxCURSOR_SIZENS;
break;
case cursorReverseArrow:
cursorId = wxCURSOR_RIGHT_ARROW;
break;
case cursorHand:
cursorId = wxCURSOR_HAND;
break;
default:
cursorId = wxCURSOR_ARROW;
break;
}
#ifdef __WXMOTIF__
wxCursor wc = wxStockCursor(cursorId) ;
#else
wxCursor wc = wxCursor(cursorId) ;
#endif
GETWIN(id)->SetCursor(wc);
}
void Window::SetTitle(const char *s) {
GETWIN(id)->SetTitle(sci2wx(s));
}
//----------------------------------------------------------------------
// Helper classes for ListBox
// This is a simple subclass of wxListView that just resets focus to the
// parent when it gets it.
class wxSCIListBox : public wxListView {
public:
wxSCIListBox (wxWindow* parent, wxWindowID id,
const wxPoint& pos, const wxSize& size,
long style) : wxListView() {
#ifdef __WXMSW__
Hide(); // don't flicker as we move it around...
#endif
Create(parent, id, pos, size, style);
}
void OnFocus(wxFocusEvent& event) {
GetParent()->SetFocus();
event.Skip();
}
void OnKillFocus(wxFocusEvent& WXUNUSED(event)) {
// Do nothing. Prevents base class from resetting the colors...
}
#ifdef __WXMAC__
// For some reason I don't understand yet the focus doesn't really leave
// the listbox like it should, so if we get any events feed them back to
// the wxSintilla
void OnKeyDown(wxKeyEvent& event) {
GetGrandParent()->GetEventHandler()->ProcessEvent(event);
}
void OnChar(wxKeyEvent& event) {
GetGrandParent()->GetEventHandler()->ProcessEvent(event);
}
// And we need to force the focus back when being destroyed
~wxSCIListBox() {
GetGrandParent()->SetFocus();
}
#endif
private:
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(wxSCIListBox, wxListView)
EVT_SET_FOCUS( wxSCIListBox::OnFocus)
EVT_KILL_FOCUS(wxSCIListBox::OnKillFocus)
#ifdef __WXMAC__
EVT_KEY_DOWN( wxSCIListBox::OnKeyDown)
EVT_CHAR( wxSCIListBox::OnChar)
#endif
END_EVENT_TABLE()
#if wxUSE_POPUPWIN //-----------------------------------
#include <wx/popupwin.h>
// TODO: Refactor these two classes to have a common base (or a mix-in) to get
// rid of the code duplication. (Either that or convince somebody to
// implement wxPopupWindow for the Mac!!)
//
// In the meantime, be careful to duplicate any changes as needed...
// A popup window to place the wxSCIListBox upon
class wxSCIListBoxWin : public wxPopupWindow
{
private:
wxListView* lv;
CallBackAction doubleClickAction;
void* doubleClickActionData;
public:
wxSCIListBoxWin(wxWindow* parent, wxWindowID id) :
wxPopupWindow(parent, wxBORDER_NONE)
{
SetBackgroundColour(*wxBLACK); // for our simple border
lv = new wxSCIListBox(parent, id, wxDefaultPosition, wxDefaultSize,
wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_NO_HEADER | wxBORDER_NONE);
lv->SetCursor(wxCursor(wxCURSOR_ARROW));
lv->InsertColumn(0, wxEmptyString);
lv->InsertColumn(1, wxEmptyString);
// NOTE: We need to fool the wxListView into thinking that it has the
// focus so it will use the normal selection colour and will look
// "right" to the user. But since the wxPopupWindow or its children
// can't receive focus then we have to pull a fast one and temporarily
// parent the listctrl on the STC window and then call SetFocus and
// then reparent it back to the popup.
lv->SetFocus();
lv->Reparent(this);
#ifdef __WXMSW__
lv->Show();
#endif
}
// Set position in client coords
virtual void DoSetSize(int x, int y,
int width, int height,
int sizeFlags = wxSIZE_AUTO) {
#if !wxCHECK_VERSION(2, 5, 0)
if (x != -1) {
#else
if (x != wxDefaultCoord) {
#endif
GetParent()->ClientToScreen(&x, NULL);
}
#if !wxCHECK_VERSION(2, 5, 0)
if (y != -1) {
#else
if (y != wxDefaultCoord) {
#endif
GetParent()->ClientToScreen(NULL, &y);
}
wxPopupWindow::DoSetSize(x, y, width, height, sizeFlags);
}
// return position as if it were in client coords
virtual void DoGetPosition( int *x, int *y ) const {
int sx, sy;
wxPopupWindow::DoGetPosition(&sx, &sy);
GetParent()->ScreenToClient(&sx, &sy);
if (x) *x = sx;
if (y) *y = sy;
}
bool Destroy() {
if ( !wxPendingDelete.Member(this) )
wxPendingDelete.Append(this);
return true;
}
int IconWidth() {
wxImageList* il = lv->GetImageList(wxIMAGE_LIST_SMALL);
if (il != NULL) {
int w, h;
il->GetSize(0, w, h);
return w;
}
return 0;
}
void SetDoubleClickAction(CallBackAction action, void *data) {
doubleClickAction = action;
doubleClickActionData = data;
}
void OnFocus(wxFocusEvent& event) {
GetParent()->SetFocus();
event.Skip();
}
void OnSize(wxSizeEvent& event) {
// resize the child
wxSize sz = GetSize();
sz.x -= 2;
sz.y -= 2;
lv->SetSize(1, 1, sz.x, sz.y);
// reset the column widths
lv->SetColumnWidth(0, IconWidth()+4);
lv->SetColumnWidth(1, sz.x - 2 - lv->GetColumnWidth(0) -
wxSystemSettings::GetMetric(wxSYS_VSCROLL_X));
event.Skip();
}
void OnActivate(wxListEvent& WXUNUSED(event)) {
doubleClickAction(doubleClickActionData);
}
wxListView* GetLB() { return lv; }
private:
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(wxSCIListBoxWin, wxPopupWindow)
EVT_SET_FOCUS ( wxSCIListBoxWin::OnFocus)
EVT_SIZE ( wxSCIListBoxWin::OnSize)
EVT_LIST_ITEM_ACTIVATED(wxID_ANY, wxSCIListBoxWin::OnActivate)
END_EVENT_TABLE()
#else // wxUSE_POPUPWIN -----------------------------------
// A normal window to place the wxSCIListBox upon.
class wxSCIListBoxWin : public wxWindow {
private:
wxListView* lv;
CallBackAction doubleClickAction;
void* doubleClickActionData;
public:
wxSCIListBoxWin(wxWindow* parent, wxWindowID id) :
wxWindow(parent, id, wxDefaultPosition, wxSize(0,0), wxSIMPLE_BORDER )
{
lv = new wxSCIListBox(this, id, wxDefaultPosition, wxDefaultSize,
wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_NO_HEADER | wxNO_BORDER);
lv->SetCursor(wxCursor(wxCURSOR_ARROW));
lv->InsertColumn(0, wxEmptyString);
lv->InsertColumn(1, wxEmptyString);
// Eventhough we immediately reset the focus to the parent, this helps
// things to look right...
lv->SetFocus();
Hide();
}
// On OSX and (possibly others) there can still be pending
// 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() {
#ifdef __WXMAC__
// The bottom edge of this window is not getting properly
// refreshed upon deletion, so help it out...
wxWindow* p = GetParent();
wxRect r(GetPosition(), GetSize());
r.SetHeight(r.GetHeight()+1);
p->Refresh(false, &r);
#endif
if ( !wxPendingDelete.Member(this) )
wxPendingDelete.Append(this);
return TRUE;
}
int IconWidth() {
wxImageList* il = lv->GetImageList(wxIMAGE_LIST_SMALL);
if (il != NULL) {
int w, h;
il->GetSize(0, w, h);
return w;
}
return 0;
}
void SetDoubleClickAction(CallBackAction action, void *data) {
doubleClickAction = action;
doubleClickActionData = data;
}
void OnFocus(wxFocusEvent& event) {
GetParent()->SetFocus();
event.Skip();
}
void OnSize(wxSizeEvent& event) {
// resize the child
wxSize sz = GetClientSize();
lv->SetSize(sz);
// reset the column widths
lv->SetColumnWidth(0, IconWidth()+4);
lv->SetColumnWidth(1, sz.x - 2 - lv->GetColumnWidth(0) -
wxSystemSettings::GetMetric(wxSYS_VSCROLL_X));
event.Skip();
}
#ifdef __WXMAC__
virtual bool Show(bool show = true) {
bool rv = wxWindow::Show(show);
GetParent()->Refresh(false);
return rv;
}
#endif
void OnActivate(wxListEvent& WXUNUSED(event)) {
doubleClickAction(doubleClickActionData);
}
wxListView* GetLB() { return lv; }
private:
DECLARE_EVENT_TABLE()
};
BEGIN_EVENT_TABLE(wxSCIListBoxWin, wxWindow)
EVT_SET_FOCUS ( wxSCIListBoxWin::OnFocus)
EVT_SIZE ( wxSCIListBoxWin::OnSize)
EVT_LIST_ITEM_ACTIVATED(wxID_ANY, wxSCIListBoxWin::OnActivate)
END_EVENT_TABLE()
#endif // wxUSE_POPUPWIN -----------------------------------
inline wxSCIListBoxWin* GETLBW(WindowID win) {
return ((wxSCIListBoxWin*)win);
}
inline wxListView* GETLB(WindowID win) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -