Commit edd8649d authored by twanvl's avatar twanvl

Improvements to keyboard handling (TAB)

parent 0baab644
......@@ -26,7 +26,7 @@ DECLARE_POINTER_TYPE(InfoValue);
*/
class InfoField : public Field {
public:
InfoField() {}
InfoField() { editable = false; }
DECLARE_FIELD_TYPE(Text);
OptionalScript script; ///< Script to apply to all values
......
......@@ -62,10 +62,11 @@ END_EVENT_TABLE ()
// ----------------------------------------------------------------------------- : Button with image and hover effect
HoverButton::HoverButton(Window* parent, int id, const String& name, const Color& background)
HoverButton::HoverButton(Window* parent, int id, const String& name, const Color& background, bool accepts_focus)
: wxControl(parent, id, wxDefaultPosition, wxDefaultSize, wxNO_BORDER )
, hover(false), focus(false), mouse_down(false), key_down(false)
, background(background)
, accepts_focus(accepts_focus)
, last_drawn(nullptr)
{
loadBitmaps(name);
......@@ -136,6 +137,9 @@ void HoverButton::onKeyUp(wxKeyEvent& ev) {
wxSize HoverButton::DoGetBestSize() const {
return wxSize(bg_normal.GetWidth(), bg_normal.GetHeight());
}
bool HoverButton::AcceptsFocus() const {
return wxControl::AcceptsFocus() && accepts_focus;
}
const Bitmap* HoverButton::toDraw() const {
return (mouse_down && hover) || key_down ? &bg_down
......
......@@ -37,11 +37,13 @@ class HoverButton : public wxControl {
/** name+"_normal", name+"_hover", name+"_focus", name+"_down"
* are the resource names of the images used.
*/
HoverButton(Window* parent, int id, const String& name, const Color& background = Color(240,247,255));
HoverButton(Window* parent, int id, const String& name, const Color& background = Color(240,247,255), bool accepts_focus = true);
/// Load different bitmaps for this button
void loadBitmaps(const String& name);
virtual bool AcceptsFocus() const;
private:
DECLARE_EVENT_TABLE();
......@@ -49,6 +51,7 @@ class HoverButton : public wxControl {
Bitmap bg_normal, bg_hover, bg_focus, bg_down; ///< Bitmaps for the states of the button
bool hover, focus, mouse_down, key_down;
Color background;
const bool accepts_focus;
void onMouseEnter(wxMouseEvent&);
void onMouseLeave(wxMouseEvent&);
......
......@@ -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) {
......
......@@ -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;
......
......@@ -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;
......
......@@ -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 ()
......@@ -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);
......
......@@ -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;
}
}
......
......@@ -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);
......
......@@ -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>
......
......@@ -29,8 +29,8 @@ NewSetWindow::NewSetWindow(Window* parent)
{
wxBusyCursor wait;
// init controls
game_list = new PackageList (this, ID_GAME_LIST);
stylesheet_list = new PackageList (this, ID_STYLESHEET_LIST);
game_list = new PackageList (this, ID_GAME_LIST, wxHORIZONTAL, false);
stylesheet_list = new PackageList (this, ID_STYLESHEET_LIST, wxHORIZONTAL, false);
wxStaticText* game_text = new wxStaticText(this, ID_GAME_LIST, _LABEL_("game type"));
wxStaticText* stylesheet_text = new wxStaticText(this, ID_STYLESHEET_LIST, _LABEL_("style type"));
// init sizer
......@@ -43,10 +43,9 @@ NewSetWindow::NewSetWindow(Window* parent)
s->SetSizeHints(this);
SetSizer(s);
// Resize
SetSize(630,-1);
Layout();
GetSizer()->SetSizeHints(this);
SetSize(630,-1);
wxSize min_size = GetSizer()->GetMinSize() + GetSize() - GetClientSize();
SetSize(630,min_size.y);
// init lists
game_list->showData<Game>();
try {
......@@ -66,12 +65,9 @@ void NewSetWindow::onGameSelect(wxCommandEvent&) {
stylesheet_list->select(settings.gameSettingsFor(*game).default_stylesheet);
UpdateWindowUI(wxUPDATE_UI_RECURSE);
// resize (yuck)
SetSize(630,-1);
Layout();
GetSizer()->SetSizeHints(this);
Layout();
GetSizer()->SetSizeHints(this);
SetSize(630,-1);
wxSize min_size = GetSizer()->GetMinSize() + GetSize() - GetClientSize();
SetSize(630,min_size.y);
}
void NewSetWindow::onStyleSheetSelect(wxCommandEvent&) {
......@@ -157,10 +153,9 @@ SelectStyleSheetWindow::SelectStyleSheetWindow(Window* parent, const Game& game,
stylesheet_list->showData<StyleSheet>(game.name() + _("-*"));
stylesheet_list->select(settings.gameSettingsFor(game).default_stylesheet);
// Resize
SetSize(630,-1);
Layout();
GetSizer()->SetSizeHints(this);
SetSize(630,-1);
wxSize min_size = GetSizer()->GetMinSize() + GetSize() - GetClientSize();
SetSize(630,min_size.y);
UpdateWindowUI(wxUPDATE_UI_RECURSE);
}
......
......@@ -26,16 +26,16 @@
// ----------------------------------------------------------------------------- : CardsPanel
CardsPanel::CardsPanel(Window* parent, int id)
: SetWindowPanel(parent, id, false)
: SetWindowPanel(parent, id)
{
// init controls
wxPanel* notesP;
editor = new CardEditor(this, ID_EDITOR);
splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
card_list = new ImageCardList(splitter, ID_CARD_LIST);
notesP = new Panel(splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 /* no tab traversal*/);
notesP = new Panel(splitter, wxID_ANY);
notes = new TextCtrl(notesP, ID_NOTES, true);
collapse_notes = new HoverButton(notesP, ID_COLLAPSE_NOTES, _("btn_collapse"), wxNullColour);
collapse_notes = new HoverButton(notesP, ID_COLLAPSE_NOTES, _("btn_collapse"), wxNullColour, false);
collapse_notes->SetExtraStyle(wxWS_EX_PROCESS_UI_UPDATES);
// init sizer for notes panel
wxSizer* sn = new wxBoxSizer(wxVERTICAL);
......
......@@ -32,18 +32,18 @@ KeywordsPanel::KeywordsPanel(Window* parent, int id)
: SetWindowPanel(parent, id)
{
// init controls
splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
list = new KeywordList(splitter, ID_KEYWORD_LIST);
panel = new Panel(splitter, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0 /* no tab traversal*/);
panel = new Panel(splitter, wxID_ANY);
keyword = new TextCtrl(panel, ID_KEYWORD, false);
mode = new wxChoice(panel, ID_KEYWORD_MODE, wxDefaultPosition, wxDefaultSize, 0, nullptr);
match = new TextCtrl(panel, ID_MATCH, false);
add_param = new wxButton(panel, ID_KEYWORD_ADD_PARAM, _BUTTON_("insert parameter"));
ref_param = new wxButton(panel, ID_KEYWORD_REF_PARAM, _BUTTON_("refer parameter"));
reminder = new TextCtrl(panel, ID_REMINDER, true); // allow multiline for wordwrap
rules = new TextCtrl(panel, ID_RULES, true);
errors = new wxStaticText(panel, wxID_ANY, _(""));
errors->SetForegroundColour(*wxRED);
mode = new wxChoice(panel, ID_KEYWORD_MODE, wxDefaultPosition, wxDefaultSize, 0, nullptr);
add_param = new wxButton(panel, ID_KEYWORD_ADD_PARAM, _BUTTON_("insert parameter"));
ref_param = new wxButton(panel, ID_KEYWORD_REF_PARAM, _BUTTON_("refer parameter"));
// warning about fixed keywords
fixedL = new wxStaticText(panel, wxID_ANY, _(""));
wxStaticBitmap* fixedI = new wxStaticBitmap(panel, wxID_ANY, wxArtProvider::GetBitmap(wxART_WARNING));
......
......@@ -21,7 +21,7 @@ class wxFindReplaceData;
*/
class SetWindowPanel : public wxPanel, public SetView {
public:
SetWindowPanel(Window* parent, int id, bool autoTabbing = false);
SetWindowPanel(Window* parent, int id, bool autoTabbing = true);
/// We will probably want to respond to set changes
virtual void onSetChange() {}
......
......@@ -97,13 +97,13 @@ void StatCategoryList::drawItem(DC& dc, int x, int y, size_t item, bool selected
// ----------------------------------------------------------------------------- : StatsPanel
StatsPanel::StatsPanel(Window* parent, int id)
: SetWindowPanel(parent, id, true)
: SetWindowPanel(parent, id)
, up_to_date(true), active(false)
{
// init controls
wxSplitterWindow* splitter;
categories = new StatCategoryList(this, ID_FIELD_LIST);
splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL);
graph = new GraphControl (splitter, wxID_ANY);
card_list = new FilteredCardList(splitter, wxID_ANY);
// init splitter
......
......@@ -27,10 +27,10 @@ StylePanel::StylePanel(Window* parent, int id)
{
// init controls
preview = new CardViewer (this, wxID_ANY);
editor = new StylingEditor(this, wxID_ANY, wxNO_BORDER);
list = new PackageList (this, wxID_ANY);
use_for_all = new wxButton (this, ID_STYLE_USE_FOR_ALL, _BUTTON_("use for all cards"));
use_custom_options = new wxCheckBox(this, ID_STYLE_USE_CUSTOM, _BUTTON_("use custom styling options"));
editor = new StylingEditor(this, wxID_ANY, wxNO_BORDER);
// init sizer
wxSizer* s = new wxBoxSizer(wxHORIZONTAL);
s->Add(preview, 0, wxRIGHT, 2);
......
......@@ -228,6 +228,8 @@ void SetWindow::selectPanel(int id) {
}
// fix sizer stuff
fixMinWindowSize();
// select something
current_panel->SetFocus();
}
// ----------------------------------------------------------------------------- : Window managment
......
# This file contains the keys expected to be in MSE locales
# It was automatically generated by tools/locale/locale.pl
# Generated on Sat Sep 1 23:06:46 2007
# Generated on Sun Sep 2 02:25:24 2007
action:
add control point: 0
......@@ -377,7 +377,7 @@ title:
untitled: 0
update check: 0
updates: 0
updates availible: 0
updates available: 0
tool:
add symmetry: 0
basic shapes: 0
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment