Improvements to keyboard handling (TAB)

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@660 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-09-02 01:03:37 +00:00
parent 4840ba824c
commit 100d48b5a7
19 changed files with 105 additions and 54 deletions
+32 -10
View File
@@ -22,7 +22,7 @@ DECLARE_TYPEOF_COLLECTION(ValueViewer*);
// ----------------------------------------------------------------------------- : DataEditor
DataEditor::DataEditor(Window* parent, int id, long style)
: CardViewer(parent, id, style)
: CardViewer(parent, id, style | wxWANTS_CHARS)
, current_viewer(nullptr)
, current_editor(nullptr)
, hovered_viewer(nullptr)
@@ -59,6 +59,10 @@ ValueViewer* DataEditor::focusedViewer() const {
// ----------------------------------------------------------------------------- : Selection
bool DataEditor::AcceptsFocus() const {
return wxControl::AcceptsFocus();
}
void DataEditor::select(ValueViewer* v) {
ValueEditor* old_editor = current_editor;
current_viewer = v;
@@ -125,7 +129,8 @@ struct CompareTabIndex {
void DataEditor::createTabIndex() {
by_tab_index.clear();
FOR_EACH(v, viewers) {
if (v->getField()->editable && v->getStyle()->visible) {
ValueEditor* e = v->getEditor();
if (e && v->getField()->editable && v->getStyle()->visible) {
by_tab_index.push_back(v.get());
}
}
@@ -136,6 +141,9 @@ void DataEditor::onInit() {
current_viewer = nullptr;
current_editor = nullptr;
hovered_viewer = nullptr;
// hide caret if it is shown
wxCaret* caret = GetCaret();
if (caret->IsVisible()) caret->Hide();
}
// ----------------------------------------------------------------------------- : Search / replace
@@ -195,10 +203,16 @@ void DataEditor::onLeftDown(wxMouseEvent& ev) {
}
void DataEditor::onLeftUp(wxMouseEvent& ev) {
if (HasCapture()) ReleaseMouse();
if (current_editor) current_editor->onLeftUp(mousePoint(ev), ev);
RealPoint pos = mousePoint(ev);
if (current_editor && current_viewer && current_viewer->containsPoint(pos)) {
current_editor->onLeftUp(pos, ev);
}
}
void DataEditor::onLeftDClick(wxMouseEvent& ev) {
if (current_editor) current_editor->onLeftDClick(mousePoint(ev), ev);
RealPoint pos = mousePoint(ev);
if (current_editor && current_viewer && current_viewer->containsPoint(pos)) {
current_editor->onLeftDClick(pos, ev);
}
}
void DataEditor::onRightDown(wxMouseEvent& ev) {
ev.Skip(); // for context menu
@@ -206,8 +220,11 @@ void DataEditor::onRightDown(wxMouseEvent& ev) {
selectField(ev, &ValueEditor::onRightDown);
}
void DataEditor::onMouseWheel(wxMouseEvent& ev) {
if (current_editor && current_editor->onMouseWheel(mousePoint(ev), ev));
else ev.Skip();
RealPoint pos = mousePoint(ev);
if (current_editor && current_viewer && current_viewer->containsPoint(pos)) {
if (current_editor->onMouseWheel(pos, ev)) return;
}
ev.Skip();
}
void DataEditor::onMotion(wxMouseEvent& ev) {
@@ -269,7 +286,9 @@ void DataEditor::selectField(wxMouseEvent& ev, bool (ValueEditor::*event)(const
if (current_editor) current_editor->onFocus();
}
// pass event
if (current_editor) (current_editor->*event)(pos, ev);
if (current_editor && current_viewer && current_viewer->containsPoint(pos)) {
(current_editor->*event)(pos, ev);
}
// refresh?
if (old_editor != current_editor) {
// selection has changed, refresh viewers
@@ -279,14 +298,15 @@ void DataEditor::selectField(wxMouseEvent& ev, bool (ValueEditor::*event)(const
}
void DataEditor::selectFieldNoEvents(const RealPoint& p) {
FOR_EACH_EDITOR_REVERSE { // find high z index fields first
if (v->containsPoint(p) && v->getField()->editable) {
if (v->getField()->editable && (v->containsPoint(p) ||
(nativeLook() && p.y >= v->getStyle()->top && p.y < v->getStyle()->bottom) )) {
current_viewer = v.get();
current_editor = e;
return;
}
}
current_viewer = nullptr;
current_editor = nullptr;
//% current_viewer = nullptr;
//% current_editor = nullptr;
}
RealPoint DataEditor::mousePoint(const wxMouseEvent& ev) {
@@ -348,6 +368,8 @@ void DataEditor::onFocus(wxFocusEvent& ev) {
if (current_editor) {
current_editor->onFocus();
onChange();
} else {
selectFirst();
}
}
void DataEditor::onLoseFocus(wxFocusEvent& ev) {
+2
View File
@@ -41,6 +41,8 @@ class DataEditor : public CardViewer {
/// Select the previous editable editor, returns false if the current editor is the first one
bool selectPrevious();
virtual bool AcceptsFocus() const;
// --------------------------------------------------- : Clipboard
bool canCut() const;
+2
View File
@@ -38,6 +38,8 @@ class CardViewer : public wxControl, public DataViewer {
/// The rotation to use
virtual Rotation getRotation() const;
virtual bool AcceptsFocus() const { return false; }
protected:
/// Return the desired size of control
virtual wxSize DoGetBestSize() const;
+16 -4
View File
@@ -21,11 +21,12 @@ const int MARGIN = 1; // margin between items (excluding border)
const int BORDER = 1; // border aroung items
const int SPACING = MARGIN + 2*BORDER; // distance between items
GalleryList::GalleryList(Window* parent, int id, int direction)
: wxScrolledWindow(parent, id, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER | (direction == wxHORIZONTAL ? wxHSCROLL : wxVSCROLL) )
GalleryList::GalleryList(Window* parent, int id, int direction, bool always_focused)
: wxScrolledWindow(parent, id, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER | wxWANTS_CHARS | (direction == wxHORIZONTAL ? wxHSCROLL : wxVSCROLL) )
, selection(NO_SELECTION)
, direction(direction)
, scroll_increment(10)
, always_focused(always_focused)
{}
void GalleryList::update() {
@@ -117,7 +118,7 @@ void GalleryList::onChar(wxKeyEvent& ev) {
} break;
case WXK_TAB: {
// send a navigation event to our parent, to select another control
// we need this because tabs are not handled on the set window panels
// we need this because tabs of wxWANTS_CHARS
wxNavigationKeyEvent nev;
nev.SetDirection(!ev.ShiftDown());
GetParent()->ProcessEvent(nev);
@@ -168,7 +169,12 @@ void GalleryList::OnDraw(DC& dc) {
for (size_t i = start ; i < end ; ++i) {
// draw selection rectangle
bool selected = i == selection;
Color c = selected ? wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT) : unselected;
Color c = selected ? ( always_focused || FindFocus() == this
? wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT)
: lerp(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW),
wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT), 0.7)
)
: unselected;
dc.SetPen(c);
dc.SetBrush(saturate(lerp(background, c, 0.3), selected ? 0.5 : 0));
wxPoint pos = itemPos(i);
@@ -178,6 +184,10 @@ void GalleryList::OnDraw(DC& dc) {
}
}
void GalleryList::onFocus(wxFocusEvent&) {
if (!always_focused) Refresh(false);
}
void GalleryList::onSize(wxSizeEvent&) {
update();
}
@@ -193,6 +203,8 @@ BEGIN_EVENT_TABLE(GalleryList, wxScrolledWindow)
EVT_LEFT_DOWN (GalleryList::onLeftDown)
EVT_LEFT_DCLICK (GalleryList::onLeftDClick)
EVT_CHAR (GalleryList::onChar)
EVT_SET_FOCUS (GalleryList::onFocus)
EVT_KILL_FOCUS (GalleryList::onFocus)
EVT_PAINT (GalleryList::onPaint)
EVT_SIZE (GalleryList::onSize)
END_EVENT_TABLE ()
+7 -5
View File
@@ -29,17 +29,18 @@ DECLARE_EVENT_TYPE(EVENT_GALLERY_ACTIVATE, <not used>)
*/
class GalleryList : public wxScrolledWindow {
public:
GalleryList(Window* parent, int id, int direction = wxHORIZONTAL);
GalleryList(Window* parent, int id, int direction = wxHORIZONTAL, bool always_focused = true);
/// Is there an item selected?
inline bool hasSelection() const { return selection < itemCount(); }
protected:
static const size_t NO_SELECTION = (size_t)-1;
size_t selection; ///< The selected item, or NO_SELECTION if there is no selection
wxSize item_size; ///< The size of a single item
int direction; ///< Direction of the list, can be wxHORIZONTAL or wxVERTICAL
int scroll_increment; ///< How large are the scroll steps?
size_t selection; ///< The selected item, or NO_SELECTION if there is no selection
wxSize item_size; ///< The size of a single item
int direction; ///< Direction of the list, can be wxHORIZONTAL or wxVERTICAL
int scroll_increment; ///< How large are the scroll steps?
bool always_focused; ///< Always draw as if focused
/// Redraw the list after changing the selection or the number of items
void update();
@@ -58,6 +59,7 @@ class GalleryList : public wxScrolledWindow {
void onLeftDown (wxMouseEvent& ev);
void onLeftDClick(wxMouseEvent& ev);
void onChar(wxKeyEvent& ev);
void onFocus(wxFocusEvent&);
void onPaint(wxPaintEvent&);
void onSize(wxSizeEvent&);
void OnDraw(DC& dc);
+8 -1
View File
@@ -798,7 +798,7 @@ void GraphContainer::add(const GraphP& graph) {
// ----------------------------------------------------------------------------- : GraphControl
GraphControl::GraphControl(Window* parent, int id)
: wxControl(parent, id)
: wxControl(parent, id, wxDefaultPosition, wxDefaultSize, wxWANTS_CHARS)
{}
void GraphControl::setLayout(GraphType type) {
@@ -912,6 +912,13 @@ void GraphControl::onChar(wxKeyEvent& ev) {
onSelectionChange();
}
break;
case WXK_TAB: {
// send a navigation event to our parent, to select another control
// we need this because of wxWANTS_CHARS
wxNavigationKeyEvent nev;
nev.SetDirection(!ev.ShiftDown());
GetParent()->ProcessEvent(nev);
} break;
}
}
+2 -2
View File
@@ -14,8 +14,8 @@ DECLARE_TYPEOF_COLLECTION(PackagedP);
// ----------------------------------------------------------------------------- : PackageList
PackageList::PackageList(Window* parent, int id, int direction)
: GalleryList(parent, id, direction)
PackageList::PackageList(Window* parent, int id, int direction, bool always_focused)
: GalleryList(parent, id, direction, always_focused)
{
item_size = wxSize(108, 150);
SetThemeEnabled(true);
+1 -1
View File
@@ -20,7 +20,7 @@ DECLARE_POINTER_TYPE(Packaged);
/// A list of Packages of a specific type
class PackageList : public GalleryList {
public:
PackageList(Window* parent, int id, int direction = wxHORIZONTAL);
PackageList(Window* parent, int id, int direction = wxHORIZONTAL, bool always_focused = true);
/// Shows packages that match a specific patern, and that are of the given type
template <typename T>