From dc9f08b3115e68e2f4f1eb4680fbed23034fbe3a Mon Sep 17 00:00:00 2001 From: twanvl Date: Thu, 23 Aug 2007 17:37:44 +0000 Subject: [PATCH] Some tweaks to word drop down list git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@619 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/gui/drop_down_list.cpp | 4 +-- src/gui/drop_down_list.hpp | 6 ++-- src/gui/value/text.cpp | 63 +++++++++++++++++++++++++-------- src/gui/value/text.hpp | 6 ++-- src/script/functions/editor.cpp | 3 +- 5 files changed, 61 insertions(+), 21 deletions(-) diff --git a/src/gui/drop_down_list.cpp b/src/gui/drop_down_list.cpp index 78802073..8af5973b 100644 --- a/src/gui/drop_down_list.cpp +++ b/src/gui/drop_down_list.cpp @@ -84,7 +84,7 @@ DropDownList::~DropDownList() { delete hider2; } -void DropDownList::show(bool in_place, wxPoint pos) { +void DropDownList::show(bool in_place, wxPoint pos, RealRect* rect) { if (IsShown()) return; onShow(); // find selection @@ -111,7 +111,7 @@ void DropDownList::show(bool in_place, wxPoint pos) { int parent_height = 0; if (!in_place && viewer) { // Position the drop down list below the editor control (based on the style) - RealRect r = viewer->viewer.getRotation().trNoNeg(viewer->getStyle()->getRect()); + RealRect r = viewer->viewer.getRotation().trNoNeg(rect ? *rect : viewer->getStyle()->getRect()); if (viewer->viewer.nativeLook()) { pos = RealPoint(r.x - 3, r.y - 3); size.width = max(size.width, r.width + 6); diff --git a/src/gui/drop_down_list.hpp b/src/gui/drop_down_list.hpp index d1894666..bdda6287 100644 --- a/src/gui/drop_down_list.hpp +++ b/src/gui/drop_down_list.hpp @@ -28,8 +28,10 @@ class DropDownList : public wxPopupWindow { DropDownList(Window* parent, bool is_submenu = false, ValueViewer* viewer = nullptr); /// Show the editor - /** if in_place, then shows the list at the position pos */ - void show(bool in_place, wxPoint pos); + /** if in_place, then shows the list at the position pos. + * Otherwise around the rect or the viewer rectangle + */ + void show(bool in_place, wxPoint pos, RealRect* rect = nullptr); /// Close the list, optionally send an onSelect event void hide(bool event, bool allow_veto = true); diff --git a/src/gui/value/text.cpp b/src/gui/value/text.cpp index 7466ea66..7d899a18 100644 --- a/src/gui/value/text.cpp +++ b/src/gui/value/text.cpp @@ -21,6 +21,7 @@ DECLARE_SHARED_POINTER_TYPE(DropDownList); DECLARE_TYPEOF_COLLECTION(WordListP); +DECLARE_TYPEOF_COLLECTION(WordListWordP); DECLARE_TYPEOF_COLLECTION(WordListPosP); // ----------------------------------------------------------------------------- : TextValueEditorScrollBar @@ -134,7 +135,14 @@ DropDownList* DropDownWordList::submenu(size_t item) const { size_t DropDownWordList::selection() const { - // TODO: find selection + // current selection + String current = untag(tve.value().value().substr(pos->start, pos->end - pos->start)); + // find selection + size_t i = 0; + FOR_EACH(w, words->words) { + if (current == w->name) return i; + ++i; + } return NO_SELECTION; } @@ -143,7 +151,8 @@ void DropDownWordList::select(size_t item) { tve.selection_start_i = pos->start; tve.selection_end_i = pos->end; tve.fixSelection(TYPE_INDEX); - tve.replaceSelection(words->words[item]->name, _ACTION_("?????")); + tve.replaceSelection(escape(words->words[item]->name), + format_string(_ACTION_("change"), tve.field().name)); } // ----------------------------------------------------------------------------- : TextValueEditor @@ -171,13 +180,7 @@ bool TextValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) { // on word list dropdown button? WordListPosP wl_pos = findWordList(pos2); if (wl_pos) { - // show dropdown - if (drop_down) { - drop_down->setWords(wl_pos); - } else { - drop_down.reset(new DropDownWordList(&editor(), false, *this, wl_pos, wl_pos->word_list)); - } - drop_down->show(false, wxPoint(0,0)); // TODO: position? + wordListDropDown(wl_pos); } else { // no, select text selecting = true; @@ -215,6 +218,7 @@ bool TextValueEditor::onMotion(const RealPoint& pos, wxMouseEvent& ev) { } bool TextValueEditor::onLeftDClick(const RealPoint& pos, wxMouseEvent& ev) { + if (dropDownShown()) return false; select_words = true; size_t index = v.indexAt(style().getRotation().trInv(pos)); moveSelection(TYPE_INDEX, prevWordBoundry(index), true, MOVE_MID); @@ -223,6 +227,7 @@ bool TextValueEditor::onLeftDClick(const RealPoint& pos, wxMouseEvent& ev) { } bool TextValueEditor::onRightDown(const RealPoint& pos, wxMouseEvent& ev) { + if (dropDownShown()) return false; size_t index = v.indexAt(style().getRotation().trInv(pos)); if (index < min(selection_start_i, selection_end_i) || index > max(selection_start_i, selection_end_i)) { @@ -259,10 +264,18 @@ bool TextValueEditor::onChar(wxKeyEvent& ev) { } break; case WXK_UP: - moveSelection(TYPE_INDEX, v.moveLine(selection_end_i, -1), !ev.ShiftDown(), MOVE_LEFT_OPT); + if (field().multi_line) { + moveSelection(TYPE_INDEX, v.moveLine(selection_end_i, -1), !ev.ShiftDown(), MOVE_LEFT_OPT); + } else { + wordListDropDown(findWordList(selection_end_i)); + } break; case WXK_DOWN: - moveSelection(TYPE_INDEX, v.moveLine(selection_end_i, +1), !ev.ShiftDown(), MOVE_RIGHT_OPT); + if (field().multi_line) { + moveSelection(TYPE_INDEX, v.moveLine(selection_end_i, +1), !ev.ShiftDown(), MOVE_RIGHT_OPT); + } else { + wordListDropDown(findWordList(selection_end_i)); + } break; case WXK_HOME: // move to begining of line / all (if control) @@ -1016,6 +1029,7 @@ void TextValueEditor::findWordLists() { } void TextValueEditor::drawWordListIndicators(RotatedDC& dc) { + Rotater rot(dc, style().getRotation()); bool current = isCurrent(); FOR_EACH(wl, word_lists) { RealRect& r = wl->rect; @@ -1039,16 +1053,16 @@ void TextValueEditor::drawWordListIndicators(RotatedDC& dc) { dc.SetPen (Color(128,128,128)); dc.SetBrush(Color(192,192,192)); } - dc.DrawRectangle(RealRect(style().left + r.right(), style().top + r.top(), 9, r.height)); + dc.DrawRectangle(RealRect(r.right(), r.top(), 9, r.height)); // draw foreground /* dc.SetPen (*wxTRANSPARENT_PEN); dc.SetBrush(*wxBLACK_BRUSH); wxPoint poly[] = {dc.tr(RealPoint(0,0)), dc.tr(RealPoint(5,0)), dc.tr(RealPoint(3,2))}; - dc.getDC().DrawPolygon(3, poly, style().left + r.right() + 2, style().top + r.bottom() - 5); + dc.getDC().DrawPolygon(3, poly, r.right() + 2, r.bottom() - 5); */ dc.SetPen (*wxBLACK_PEN); - double x = style().left + r.right(), y = style().top + r.bottom(); + double x = r.right(), y = r.bottom(); dc.DrawLine(RealPoint(x + 4, y - 3), RealPoint(x + 5, y - 3)); dc.DrawLine(RealPoint(x + 3, y - 4), RealPoint(x + 6, y - 4)); dc.DrawLine(RealPoint(x + 2, y - 5), RealPoint(x + 7, y - 5)); @@ -1065,3 +1079,24 @@ WordListPosP TextValueEditor::findWordList(const RealPoint& pos) const { } return WordListPosP(); } +WordListPosP TextValueEditor::findWordList(size_t index) const { + FOR_EACH_CONST(wl, word_lists) { + if (index >= wl->start && index <= wl->end) { + return wl; + } + } + return WordListPosP(); +} + +bool TextValueEditor::wordListDropDown(const WordListPosP& wl) { + if (!wl) return false; + // show dropdown + if (drop_down) { + drop_down->setWords(wl); + } else { + drop_down.reset(new DropDownWordList(&editor(), false, *this, wl, wl->word_list)); + } + RealRect rect = wl->rect.move(style().left, style().top, 0, 0); + drop_down->show(false, wxPoint(0,0), &rect); + return true; +} diff --git a/src/gui/value/text.hpp b/src/gui/value/text.hpp index c6108d85..2a95f8d6 100644 --- a/src/gui/value/text.hpp +++ b/src/gui/value/text.hpp @@ -164,8 +164,10 @@ class TextValueEditor : public TextValueViewer, public ValueEditor { void drawWordListIndicators(RotatedDC& dc); /// Find a WordListPos under the mouse cursor (if any), pos is in internal coordinates WordListPosP findWordList(const RealPoint& pos) const; - /// Show a word list drop down menu - void wordListDropDown(const WordListPosP& pos); + /// Find a WordListPos for a index position + WordListPosP findWordList(size_t index) const; + /// Show a word list drop down menu, if wl + bool wordListDropDown(const WordListPosP& wl); }; diff --git a/src/script/functions/editor.cpp b/src/script/functions/editor.cpp index da514dfd..a9cfb338 100644 --- a/src/script/functions/editor.cpp +++ b/src/script/functions/editor.cpp @@ -67,7 +67,8 @@ SCRIPT_FUNCTION_WITH_DEP(combined_editor) { // update the values if our input value is newer? Age new_value_update = last_update_age(); FOR_EACH_2(v, values, nv, value_parts) { - if (v->value() != nv.first && v->last_update < new_value_update) { + //if (v->value() != nv.first && v->last_update < new_value_update) { + if (v->last_update < new_value_update) { v->value.assign(nv.first); v->update(ctx); }