Use float-on-parent frames for the popups if wxPopupWindow is not available

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@44266 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Robin Dunn
2007-01-20 03:26:34 +00:00
parent a0232aa520
commit 67879c5b41
4 changed files with 210 additions and 52 deletions

View File

@@ -791,9 +791,10 @@ public:
wxSTCListBoxWin(wxWindow* parent, wxWindowID id, Point WXUNUSED(location)) : wxSTCListBoxWin(wxWindow* parent, wxWindowID id, Point WXUNUSED(location)) :
wxPopupWindow(parent, wxBORDER_NONE) wxPopupWindow(parent, wxBORDER_NONE)
{ {
SetBackgroundColour(*wxBLACK); // for our simple border 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); wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_NO_HEADER | wxBORDER_NONE);
lv->SetCursor(wxCursor(wxCURSOR_ARROW)); lv->SetCursor(wxCursor(wxCURSOR_ARROW));
lv->InsertColumn(0, wxEmptyString); lv->InsertColumn(0, wxEmptyString);
@@ -897,17 +898,27 @@ END_EVENT_TABLE()
#else // wxUSE_POPUPWIN ----------------------------------- #else // !wxUSE_POPUPWIN -----------------------------------
// A normal window to place the wxSTCListBox upon. // A normal window to place the wxSTCListBox upon, but make it behave as much
class wxSTCListBoxWin : public wxWindow { // like a wxPopupWindow as possible
class wxSTCListBoxWin : public wxFrame {
private: private:
wxListView* lv; wxListView* lv;
CallBackAction doubleClickAction; CallBackAction doubleClickAction;
void* doubleClickActionData; void* doubleClickActionData;
public: public:
wxSTCListBoxWin(wxWindow* parent, wxWindowID id, Point location) : 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, lv = new wxSTCListBox(this, id, wxDefaultPosition, wxDefaultSize,
@@ -921,14 +932,15 @@ public:
lv->SetFocus(); lv->SetFocus();
Hide(); Hide();
} }
// On OSX and (possibly others) there can still be pending // On OSX and (possibly others) there can still be pending
// messages/events for the list control when Scintilla wants to // messages/events for the list control when Scintilla wants to
// close it, so do a pending delete of it instead of destroying // close it, so do a pending delete of it instead of destroying
// immediately. // immediately.
bool Destroy() { bool Destroy()
{
#ifdef __WXMAC__ #ifdef __WXMAC__
// The bottom edge of this window is not getting properly // The bottom edge of this window is not getting properly
// refreshed upon deletion, so help it out... // refreshed upon deletion, so help it out...
@@ -943,7 +955,8 @@ public:
} }
int IconWidth() { int IconWidth()
{
wxImageList* il = lv->GetImageList(wxIMAGE_LIST_SMALL); wxImageList* il = lv->GetImageList(wxIMAGE_LIST_SMALL);
if (il != NULL) { if (il != NULL) {
int w, h; int w, h;
@@ -954,18 +967,22 @@ public:
} }
void SetDoubleClickAction(CallBackAction action, void *data) { void SetDoubleClickAction(CallBackAction action, void *data)
{
doubleClickAction = action; doubleClickAction = action;
doubleClickActionData = data; doubleClickActionData = data;
} }
void OnFocus(wxFocusEvent& event) { void OnFocus(wxFocusEvent& event)
{
ActivateParent();
GetParent()->SetFocus(); GetParent()->SetFocus();
event.Skip(); event.Skip();
} }
void OnSize(wxSizeEvent& event) { void OnSize(wxSizeEvent& event)
{
// resize the child // resize the child
wxSize sz = GetClientSize(); wxSize sz = GetClientSize();
lv->SetSize(sz); lv->SetSize(sz);
@@ -976,15 +993,44 @@ public:
event.Skip(); 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__ #ifdef __WXMAC__
virtual bool Show(bool show = true) {
bool rv = wxWindow::Show(show);
GetParent()->Refresh(false); GetParent()->Refresh(false);
#endif
return rv; return rv;
} }
#endif
void OnActivate(wxListEvent& WXUNUSED(event)) { void OnActivate(wxListEvent& WXUNUSED(event))
{
doubleClickAction(doubleClickActionData); doubleClickAction(doubleClickActionData);
} }
@@ -1193,7 +1239,7 @@ void ListBoxImpl::Select(int n) {
n = 0; n = 0;
select = false; select = false;
} }
GETLB(id)->Focus(n); GETLB(id)->EnsureVisible(n);
GETLB(id)->Select(n, select); GETLB(id)->Select(n, select);
} }

View File

@@ -87,7 +87,7 @@ void wxSTCDropTarget::OnLeave() {
#define wxSTCCallTipBase wxPopupWindow #define wxSTCCallTipBase wxPopupWindow
#define param2 wxBORDER_NONE // popup's 2nd param is flags #define param2 wxBORDER_NONE // popup's 2nd param is flags
#else #else
#define wxSTCCallTipBase wxWindow #define wxSTCCallTipBase wxFrame
#define param2 -1 // wxWindow's 2nd param is ID #define param2 -1 // wxWindow's 2nd param is ID
#endif #endif
@@ -95,8 +95,19 @@ void wxSTCDropTarget::OnLeave() {
class wxSTCCallTip : public wxSTCCallTipBase { class wxSTCCallTip : public wxSTCCallTipBase {
public: public:
wxSTCCallTip(wxWindow* parent, CallTip* ct, ScintillaWX* swx) wxSTCCallTip(wxWindow* parent, CallTip* ct, ScintillaWX* swx) :
: wxSTCCallTipBase(parent, param2), #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
wxSTCCallTipBase(parent, wxBORDER_NONE),
#else
wxSTCCallTipBase(parent, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize,
wxFRAME_NO_TASKBAR
| wxFRAME_FLOAT_ON_PARENT
| wxBORDER_NONE
#ifdef __WXMAC__
| wxPOPUP_WINDOW
#endif
),
#endif
m_ct(ct), m_swx(swx), m_cx(wxDefaultCoord), m_cy(wxDefaultCoord) m_ct(ct), m_swx(swx), m_cx(wxDefaultCoord), m_cy(wxDefaultCoord)
{ {
} }
@@ -112,7 +123,8 @@ public:
bool AcceptsFocus() const { return false; } bool AcceptsFocus() const { return false; }
void OnPaint(wxPaintEvent& WXUNUSED(evt)) { void OnPaint(wxPaintEvent& WXUNUSED(evt))
{
wxBufferedPaintDC dc(this); wxBufferedPaintDC dc(this);
Surface* surfaceWindow = Surface::Allocate(); Surface* surfaceWindow = Surface::Allocate();
surfaceWindow->Init(&dc, m_ct->wDraw.GetID()); surfaceWindow->Init(&dc, m_ct->wDraw.GetID());
@@ -121,22 +133,25 @@ public:
delete surfaceWindow; delete surfaceWindow;
} }
void OnFocus(wxFocusEvent& event) { void OnFocus(wxFocusEvent& event)
{
GetParent()->SetFocus(); GetParent()->SetFocus();
event.Skip(); event.Skip();
} }
void OnLeftDown(wxMouseEvent& event) { void OnLeftDown(wxMouseEvent& event)
{
wxPoint pt = event.GetPosition(); wxPoint pt = event.GetPosition();
Point p(pt.x, pt.y); Point p(pt.x, pt.y);
m_ct->MouseClick(p); m_ct->MouseClick(p);
m_swx->CallTipClick(); m_swx->CallTipClick();
} }
#if wxUSE_POPUPWIN && wxSTC_USE_POPUP
virtual void DoSetSize(int x, int y, virtual void DoSetSize(int x, int y,
int width, int height, int width, int height,
int sizeFlags = wxSIZE_AUTO) { int sizeFlags = wxSIZE_AUTO)
{
// convert coords to screen coords since we're a top-level window
if (x != wxDefaultCoord) { if (x != wxDefaultCoord) {
m_cx = x; m_cx = x;
GetParent()->ClientToScreen(&x, NULL); GetParent()->ClientToScreen(&x, NULL);
@@ -147,9 +162,27 @@ public:
} }
wxSTCCallTipBase::DoSetSize(x, y, width, height, sizeFlags); wxSTCCallTipBase::DoSetSize(x, y, width, height, sizeFlags);
} }
#endif
wxPoint GetMyPosition() { #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
#else
virtual bool Show( bool show = true )
{
// Although we're a frame, we always want the parent to be active, so
// raise it whenever we get shown.
bool rv = wxSTCCallTipBase::Show(show);
if (rv && show)
{
wxTopLevelWindow *frame = wxDynamicCast(
wxGetTopLevelParent(GetParent()), wxTopLevelWindow);
if (frame)
frame->Raise();
}
return rv;
}
#endif
wxPoint GetMyPosition()
{
return wxPoint(m_cx, m_cy); return wxPoint(m_cx, m_cy);
} }

View File

@@ -791,9 +791,10 @@ public:
wxSTCListBoxWin(wxWindow* parent, wxWindowID id, Point WXUNUSED(location)) : wxSTCListBoxWin(wxWindow* parent, wxWindowID id, Point WXUNUSED(location)) :
wxPopupWindow(parent, wxBORDER_NONE) wxPopupWindow(parent, wxBORDER_NONE)
{ {
SetBackgroundColour(*wxBLACK); // for our simple border 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); wxLC_REPORT | wxLC_SINGLE_SEL | wxLC_NO_HEADER | wxBORDER_NONE);
lv->SetCursor(wxCursor(wxCURSOR_ARROW)); lv->SetCursor(wxCursor(wxCURSOR_ARROW));
lv->InsertColumn(0, wxEmptyString); lv->InsertColumn(0, wxEmptyString);
@@ -897,17 +898,27 @@ END_EVENT_TABLE()
#else // wxUSE_POPUPWIN ----------------------------------- #else // !wxUSE_POPUPWIN -----------------------------------
// A normal window to place the wxSTCListBox upon. // A normal window to place the wxSTCListBox upon, but make it behave as much
class wxSTCListBoxWin : public wxWindow { // like a wxPopupWindow as possible
class wxSTCListBoxWin : public wxFrame {
private: private:
wxListView* lv; wxListView* lv;
CallBackAction doubleClickAction; CallBackAction doubleClickAction;
void* doubleClickActionData; void* doubleClickActionData;
public: public:
wxSTCListBoxWin(wxWindow* parent, wxWindowID id, Point location) : 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, lv = new wxSTCListBox(this, id, wxDefaultPosition, wxDefaultSize,
@@ -921,14 +932,15 @@ public:
lv->SetFocus(); lv->SetFocus();
Hide(); Hide();
} }
// On OSX and (possibly others) there can still be pending // On OSX and (possibly others) there can still be pending
// messages/events for the list control when Scintilla wants to // messages/events for the list control when Scintilla wants to
// close it, so do a pending delete of it instead of destroying // close it, so do a pending delete of it instead of destroying
// immediately. // immediately.
bool Destroy() { bool Destroy()
{
#ifdef __WXMAC__ #ifdef __WXMAC__
// The bottom edge of this window is not getting properly // The bottom edge of this window is not getting properly
// refreshed upon deletion, so help it out... // refreshed upon deletion, so help it out...
@@ -943,7 +955,8 @@ public:
} }
int IconWidth() { int IconWidth()
{
wxImageList* il = lv->GetImageList(wxIMAGE_LIST_SMALL); wxImageList* il = lv->GetImageList(wxIMAGE_LIST_SMALL);
if (il != NULL) { if (il != NULL) {
int w, h; int w, h;
@@ -954,18 +967,22 @@ public:
} }
void SetDoubleClickAction(CallBackAction action, void *data) { void SetDoubleClickAction(CallBackAction action, void *data)
{
doubleClickAction = action; doubleClickAction = action;
doubleClickActionData = data; doubleClickActionData = data;
} }
void OnFocus(wxFocusEvent& event) { void OnFocus(wxFocusEvent& event)
{
ActivateParent();
GetParent()->SetFocus(); GetParent()->SetFocus();
event.Skip(); event.Skip();
} }
void OnSize(wxSizeEvent& event) { void OnSize(wxSizeEvent& event)
{
// resize the child // resize the child
wxSize sz = GetClientSize(); wxSize sz = GetClientSize();
lv->SetSize(sz); lv->SetSize(sz);
@@ -976,15 +993,44 @@ public:
event.Skip(); 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__ #ifdef __WXMAC__
virtual bool Show(bool show = true) {
bool rv = wxWindow::Show(show);
GetParent()->Refresh(false); GetParent()->Refresh(false);
#endif
return rv; return rv;
} }
#endif
void OnActivate(wxListEvent& WXUNUSED(event)) { void OnActivate(wxListEvent& WXUNUSED(event))
{
doubleClickAction(doubleClickActionData); doubleClickAction(doubleClickActionData);
} }
@@ -1193,7 +1239,7 @@ void ListBoxImpl::Select(int n) {
n = 0; n = 0;
select = false; select = false;
} }
GETLB(id)->Focus(n); GETLB(id)->EnsureVisible(n);
GETLB(id)->Select(n, select); GETLB(id)->Select(n, select);
} }

View File

@@ -87,7 +87,7 @@ void wxSTCDropTarget::OnLeave() {
#define wxSTCCallTipBase wxPopupWindow #define wxSTCCallTipBase wxPopupWindow
#define param2 wxBORDER_NONE // popup's 2nd param is flags #define param2 wxBORDER_NONE // popup's 2nd param is flags
#else #else
#define wxSTCCallTipBase wxWindow #define wxSTCCallTipBase wxFrame
#define param2 -1 // wxWindow's 2nd param is ID #define param2 -1 // wxWindow's 2nd param is ID
#endif #endif
@@ -95,8 +95,19 @@ void wxSTCDropTarget::OnLeave() {
class wxSTCCallTip : public wxSTCCallTipBase { class wxSTCCallTip : public wxSTCCallTipBase {
public: public:
wxSTCCallTip(wxWindow* parent, CallTip* ct, ScintillaWX* swx) wxSTCCallTip(wxWindow* parent, CallTip* ct, ScintillaWX* swx) :
: wxSTCCallTipBase(parent, param2), #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
wxSTCCallTipBase(parent, wxBORDER_NONE),
#else
wxSTCCallTipBase(parent, -1, wxEmptyString, wxDefaultPosition, wxDefaultSize,
wxFRAME_NO_TASKBAR
| wxFRAME_FLOAT_ON_PARENT
| wxBORDER_NONE
#ifdef __WXMAC__
| wxPOPUP_WINDOW
#endif
),
#endif
m_ct(ct), m_swx(swx), m_cx(wxDefaultCoord), m_cy(wxDefaultCoord) m_ct(ct), m_swx(swx), m_cx(wxDefaultCoord), m_cy(wxDefaultCoord)
{ {
} }
@@ -112,7 +123,8 @@ public:
bool AcceptsFocus() const { return false; } bool AcceptsFocus() const { return false; }
void OnPaint(wxPaintEvent& WXUNUSED(evt)) { void OnPaint(wxPaintEvent& WXUNUSED(evt))
{
wxBufferedPaintDC dc(this); wxBufferedPaintDC dc(this);
Surface* surfaceWindow = Surface::Allocate(); Surface* surfaceWindow = Surface::Allocate();
surfaceWindow->Init(&dc, m_ct->wDraw.GetID()); surfaceWindow->Init(&dc, m_ct->wDraw.GetID());
@@ -121,22 +133,25 @@ public:
delete surfaceWindow; delete surfaceWindow;
} }
void OnFocus(wxFocusEvent& event) { void OnFocus(wxFocusEvent& event)
{
GetParent()->SetFocus(); GetParent()->SetFocus();
event.Skip(); event.Skip();
} }
void OnLeftDown(wxMouseEvent& event) { void OnLeftDown(wxMouseEvent& event)
{
wxPoint pt = event.GetPosition(); wxPoint pt = event.GetPosition();
Point p(pt.x, pt.y); Point p(pt.x, pt.y);
m_ct->MouseClick(p); m_ct->MouseClick(p);
m_swx->CallTipClick(); m_swx->CallTipClick();
} }
#if wxUSE_POPUPWIN && wxSTC_USE_POPUP
virtual void DoSetSize(int x, int y, virtual void DoSetSize(int x, int y,
int width, int height, int width, int height,
int sizeFlags = wxSIZE_AUTO) { int sizeFlags = wxSIZE_AUTO)
{
// convert coords to screen coords since we're a top-level window
if (x != wxDefaultCoord) { if (x != wxDefaultCoord) {
m_cx = x; m_cx = x;
GetParent()->ClientToScreen(&x, NULL); GetParent()->ClientToScreen(&x, NULL);
@@ -147,9 +162,27 @@ public:
} }
wxSTCCallTipBase::DoSetSize(x, y, width, height, sizeFlags); wxSTCCallTipBase::DoSetSize(x, y, width, height, sizeFlags);
} }
#endif
wxPoint GetMyPosition() { #if wxUSE_POPUPWIN && wxSTC_USE_POPUP
#else
virtual bool Show( bool show = true )
{
// Although we're a frame, we always want the parent to be active, so
// raise it whenever we get shown.
bool rv = wxSTCCallTipBase::Show(show);
if (rv && show)
{
wxTopLevelWindow *frame = wxDynamicCast(
wxGetTopLevelParent(GetParent()), wxTopLevelWindow);
if (frame)
frame->Raise();
}
return rv;
}
#endif
wxPoint GetMyPosition()
{
return wxPoint(m_cx, m_cy); return wxPoint(m_cx, m_cy);
} }