mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 21:47:00 -04:00
Use wxPopupTransientWindow for drop down lists
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1522 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -16,47 +16,10 @@
|
|||||||
#include <gfx/gfx.hpp>
|
#include <gfx/gfx.hpp>
|
||||||
#include <wx/dcbuffer.h>
|
#include <wx/dcbuffer.h>
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : DropDownHider
|
|
||||||
|
|
||||||
// Class that intercepts all events not directed to a DropDownList, and closes the list
|
|
||||||
class DropDownHider : public wxEvtHandler {
|
|
||||||
public:
|
|
||||||
DropDownHider(DropDownList& list) : list(list) {}
|
|
||||||
|
|
||||||
private:
|
|
||||||
DropDownList& list;
|
|
||||||
|
|
||||||
virtual bool ProcessEvent(wxEvent& ev) {
|
|
||||||
int t = ev.GetEventType();
|
|
||||||
if ( t == wxEVT_LEFT_DOWN || t == wxEVT_RIGHT_DOWN
|
|
||||||
|| t == wxEVT_MOVE || t == wxEVT_SIZE
|
|
||||||
|| t == wxEVT_MENU_HIGHLIGHT || t == wxEVT_MENU_OPEN || t == wxEVT_MENU_OPEN
|
|
||||||
|| t == wxEVT_ACTIVATE || t == wxEVT_CLOSE_WINDOW || t == wxEVT_KILL_FOCUS
|
|
||||||
|| t == wxEVT_COMMAND_TOOL_CLICKED)
|
|
||||||
{
|
|
||||||
// close the list, and pass on the event
|
|
||||||
// don't just use ev.Skip(), because this event handler will be removed by hiding,
|
|
||||||
// so there will be no next handler to skip to
|
|
||||||
wxEvtHandler* nh = GetNextHandler();
|
|
||||||
if (nh) nh->ProcessEvent(ev);
|
|
||||||
list.hide(false);
|
|
||||||
return false;
|
|
||||||
} else {
|
|
||||||
// if (t !=10093 && t !=10098 && t !=10097 && t !=10099 && t !=10004 && t !=10062
|
|
||||||
// && t !=10025 && t !=10035 && t !=10034 && t !=10036 && t !=10042 && t !=10119)
|
|
||||||
// {
|
|
||||||
// t=t;//DEBUG
|
|
||||||
// }
|
|
||||||
return wxEvtHandler::ProcessEvent(ev);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : DropDownList : Show/Hide
|
// ----------------------------------------------------------------------------- : DropDownList : Show/Hide
|
||||||
|
|
||||||
DropDownList::DropDownList(Window* parent, bool is_submenu, ValueViewer* viewer)
|
DropDownList::DropDownList(Window* parent, bool is_submenu, ValueViewer* viewer)
|
||||||
: wxPopupWindow(parent, wxSIMPLE_BORDER)
|
: wxPopupTransientWindow(parent, wxSIMPLE_BORDER)//wxPopupWindow(parent, wxSIMPLE_BORDER)
|
||||||
, text_offset(1)
|
, text_offset(1)
|
||||||
, item_size(100,1)
|
, item_size(100,1)
|
||||||
, icon_size(0,0)
|
, icon_size(0,0)
|
||||||
@@ -65,8 +28,6 @@ DropDownList::DropDownList(Window* parent, bool is_submenu, ValueViewer* viewer)
|
|||||||
, open_sub_menu(nullptr)
|
, open_sub_menu(nullptr)
|
||||||
, parent_menu(nullptr)
|
, parent_menu(nullptr)
|
||||||
, viewer(viewer)
|
, viewer(viewer)
|
||||||
, hider (is_submenu ? nullptr : new DropDownHider(*this))
|
|
||||||
, hider2(is_submenu ? nullptr : new DropDownHider(*this))
|
|
||||||
, close_on_mouse_out(false)
|
, close_on_mouse_out(false)
|
||||||
{
|
{
|
||||||
if (is_submenu) {
|
if (is_submenu) {
|
||||||
@@ -82,8 +43,6 @@ DropDownList::DropDownList(Window* parent, bool is_submenu, ValueViewer* viewer)
|
|||||||
|
|
||||||
DropDownList::~DropDownList() {
|
DropDownList::~DropDownList() {
|
||||||
realHide(); // restore event handler before deleting it
|
realHide(); // restore event handler before deleting it
|
||||||
delete hider;
|
|
||||||
delete hider2;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void DropDownList::show(bool in_place, wxPoint pos, RealRect* rect) {
|
void DropDownList::show(bool in_place, wxPoint pos, RealRect* rect) {
|
||||||
@@ -149,17 +108,11 @@ void DropDownList::show(bool in_place, wxPoint pos, RealRect* rect) {
|
|||||||
// visible item
|
// visible item
|
||||||
visible_start = 0;
|
visible_start = 0;
|
||||||
ensureSelectedItemVisible();
|
ensureSelectedItemVisible();
|
||||||
// set event handler
|
|
||||||
if (hider) {
|
|
||||||
assert(hider2);
|
|
||||||
wxGetTopLevelParent(GetParent())->PushEventHandler(hider);
|
|
||||||
GetParent() ->PushEventHandler(hider2);
|
|
||||||
}
|
|
||||||
// show
|
// show
|
||||||
if (selected_item == NO_SELECTION && itemCount() > 0) selected_item = 0; // select first item by default
|
if (selected_item == NO_SELECTION && itemCount() > 0) selected_item = 0; // select first item by default
|
||||||
mouse_down = false;
|
mouse_down = false;
|
||||||
close_on_mouse_out = false;
|
close_on_mouse_out = false;
|
||||||
Window::Show();
|
Popup();
|
||||||
if (isRoot() && GetParent()->HasCapture()) {
|
if (isRoot() && GetParent()->HasCapture()) {
|
||||||
// release capture on parent
|
// release capture on parent
|
||||||
GetParent()->ReleaseMouse();
|
GetParent()->ReleaseMouse();
|
||||||
@@ -197,9 +150,6 @@ void DropDownList::realHide() {
|
|||||||
parent_menu->open_sub_menu = nullptr;
|
parent_menu->open_sub_menu = nullptr;
|
||||||
} else {
|
} else {
|
||||||
redrawArrowOnParent();
|
redrawArrowOnParent();
|
||||||
// disconnect event handler
|
|
||||||
GetParent() ->RemoveEventHandler(hider2);
|
|
||||||
wxGetTopLevelParent(GetParent())->RemoveEventHandler(hider);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -14,13 +14,12 @@
|
|||||||
#include <wx/popupwin.h> // undocumented: wxPopupWindow
|
#include <wx/popupwin.h> // undocumented: wxPopupWindow
|
||||||
|
|
||||||
class ValueViewer;
|
class ValueViewer;
|
||||||
class DropDownHider;
|
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------- : DropDownList
|
// ----------------------------------------------------------------------------- : DropDownList
|
||||||
|
|
||||||
/// A popup/drop down window displaying a list of items
|
/// A popup/drop down window displaying a list of items
|
||||||
/** This class is an abstract base for various drop down lists */
|
/** This class is an abstract base for various drop down lists */
|
||||||
class DropDownList : public wxPopupWindow {
|
class DropDownList : public wxPopupTransientWindow {
|
||||||
public:
|
public:
|
||||||
~DropDownList();
|
~DropDownList();
|
||||||
/// Create a drop down list, possibly a sub menu
|
/// Create a drop down list, possibly a sub menu
|
||||||
@@ -94,7 +93,6 @@ class DropDownList : public wxPopupWindow {
|
|||||||
DropDownList* open_sub_menu; ///< The sub menu that is currently shown, if any
|
DropDownList* open_sub_menu; ///< The sub menu that is currently shown, if any
|
||||||
DropDownList* parent_menu; ///< The parent menu, only applies to sub menus
|
DropDownList* parent_menu; ///< The parent menu, only applies to sub menus
|
||||||
ValueViewer* viewer; ///< The parent viewer object (optional)
|
ValueViewer* viewer; ///< The parent viewer object (optional)
|
||||||
DropDownHider* hider, *hider2; ///< Class to hide this window when we lose focus
|
|
||||||
bool close_on_mouse_out; ///< Was the list kept open after selecting a choice, if so, be eager to close it
|
bool close_on_mouse_out; ///< Was the list kept open after selecting a choice, if so, be eager to close it
|
||||||
int visible_start; ///< First visible pixel
|
int visible_start; ///< First visible pixel
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user