mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 21:06:59 -04:00
added scrollbar to NativeLookEditor
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@223 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -228,13 +228,13 @@ ChoiceValueEditor::~ChoiceValueEditor() {
|
||||
thumbnail_thread.abort(this);
|
||||
}
|
||||
|
||||
void ChoiceValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
bool ChoiceValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
//HACK TODO REMOVEME
|
||||
thumbnail_thread.abortAll();
|
||||
drop_down->onMouseInParent(ev, style().popup_style == POPUP_DROPDOWN_IN_PLACE && !nativeLook());
|
||||
return drop_down->onMouseInParent(ev, style().popup_style == POPUP_DROPDOWN_IN_PLACE && !nativeLook());
|
||||
}
|
||||
void ChoiceValueEditor::onChar(wxKeyEvent& ev) {
|
||||
drop_down->onCharInParent(ev);
|
||||
bool ChoiceValueEditor::onChar(wxKeyEvent& ev) {
|
||||
return drop_down->onCharInParent(ev);
|
||||
}
|
||||
void ChoiceValueEditor::onLoseFocus() {
|
||||
drop_down->hide(false);
|
||||
@@ -243,7 +243,7 @@ void ChoiceValueEditor::onLoseFocus() {
|
||||
void ChoiceValueEditor::draw(RotatedDC& dc) {
|
||||
ChoiceValueViewer::draw(dc);
|
||||
if (nativeLook()) {
|
||||
draw_drop_down_arrow(&editor(), dc.getDC(), style().getRect().grow(1), drop_down->IsShown());
|
||||
draw_drop_down_arrow(&editor(), dc.getDC(), dc.tr(style().getRect().grow(1)), drop_down->IsShown());
|
||||
}
|
||||
}
|
||||
void ChoiceValueEditor::determineSize(bool) {
|
||||
|
||||
@@ -25,8 +25,8 @@ class ChoiceValueEditor : public ChoiceValueViewer, public ValueEditor {
|
||||
~ChoiceValueEditor();
|
||||
|
||||
// --------------------------------------------------- : Events
|
||||
virtual void onLeftDown(const RealPoint& pos, wxMouseEvent& ev);
|
||||
virtual void onChar(wxKeyEvent& ev);
|
||||
virtual bool onLeftDown(const RealPoint& pos, wxMouseEvent& ev);
|
||||
virtual bool onChar(wxKeyEvent& ev);
|
||||
virtual void onLoseFocus();
|
||||
|
||||
virtual void draw(RotatedDC& dc);
|
||||
|
||||
@@ -128,11 +128,11 @@ IMPLEMENT_VALUE_EDITOR(Color)
|
||||
, drop_down(new DropDownColorList(&editor(), *this))
|
||||
{}
|
||||
|
||||
void ColorValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
drop_down->onMouseInParent(ev, !nativeLook());
|
||||
bool ColorValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
return drop_down->onMouseInParent(ev, !nativeLook());
|
||||
}
|
||||
void ColorValueEditor::onChar(wxKeyEvent& ev) {
|
||||
drop_down->onCharInParent(ev);
|
||||
bool ColorValueEditor::onChar(wxKeyEvent& ev) {
|
||||
return drop_down->onCharInParent(ev);
|
||||
}
|
||||
void ColorValueEditor::onLoseFocus() {
|
||||
drop_down->hide(false);
|
||||
@@ -141,7 +141,7 @@ void ColorValueEditor::onLoseFocus() {
|
||||
void ColorValueEditor::draw(RotatedDC& dc) {
|
||||
ColorValueViewer::draw(dc);
|
||||
if (nativeLook()) {
|
||||
draw_drop_down_arrow(&editor(), dc.getDC(), style().getRect().grow(1), drop_down->IsShown());
|
||||
draw_drop_down_arrow(&editor(), dc.getDC(), dc.tr(style().getRect().grow(1)), drop_down->IsShown());
|
||||
}
|
||||
}
|
||||
void ColorValueEditor::determineSize(bool) {
|
||||
|
||||
@@ -23,8 +23,8 @@ class ColorValueEditor : public ColorValueViewer, public ValueEditor {
|
||||
DECLARE_VALUE_EDITOR(Color);
|
||||
|
||||
// --------------------------------------------------- : Events
|
||||
virtual void onLeftDown(const RealPoint& pos, wxMouseEvent& ev);
|
||||
virtual void onChar(wxKeyEvent& ev);
|
||||
virtual bool onLeftDown(const RealPoint& pos, wxMouseEvent& ev);
|
||||
virtual bool onChar(wxKeyEvent& ev);
|
||||
virtual void onLoseFocus();
|
||||
|
||||
virtual void draw(RotatedDC& dc);
|
||||
|
||||
@@ -39,16 +39,16 @@ class ValueEditor {
|
||||
/// This editor loses focus
|
||||
virtual void onLoseFocus() {}
|
||||
|
||||
/// Handle mouse events
|
||||
virtual void onLeftDown (const RealPoint& pos, wxMouseEvent& ev) {}
|
||||
virtual void onLeftUp (const RealPoint& pos, wxMouseEvent& ev) {}
|
||||
virtual void onLeftDClick (const RealPoint& pos, wxMouseEvent& ev) {}
|
||||
virtual void onRightDown (const RealPoint& pos, wxMouseEvent& ev) {}
|
||||
virtual void onMotion (const RealPoint& pos, wxMouseEvent& ev) {}
|
||||
virtual void onMouseWheel (const RealPoint& pos, wxMouseEvent& ev) {}
|
||||
/// Handle mouse events, return true if the event is used
|
||||
virtual bool onLeftDown (const RealPoint& pos, wxMouseEvent& ev) { return false; }
|
||||
virtual bool onLeftUp (const RealPoint& pos, wxMouseEvent& ev) { return false; }
|
||||
virtual bool onLeftDClick (const RealPoint& pos, wxMouseEvent& ev) { return false; }
|
||||
virtual bool onRightDown (const RealPoint& pos, wxMouseEvent& ev) { return false; }
|
||||
virtual bool onMotion (const RealPoint& pos, wxMouseEvent& ev) { return false; }
|
||||
virtual bool onMouseWheel (const RealPoint& pos, wxMouseEvent& ev) { return false; }
|
||||
|
||||
/// Key events
|
||||
virtual void onChar(wxKeyEvent& ev) {}
|
||||
virtual bool onChar(wxKeyEvent& ev) { return false; }
|
||||
|
||||
/// a context menu is requested, add extra items to the menu m
|
||||
/** return false to suppress menu */
|
||||
|
||||
@@ -16,15 +16,14 @@
|
||||
|
||||
IMPLEMENT_VALUE_EDITOR(Image) {}
|
||||
|
||||
void ImageValueEditor::onLeftDClick(const RealPoint&, wxMouseEvent&) {
|
||||
bool ImageValueEditor::onLeftDClick(const RealPoint&, wxMouseEvent&) {
|
||||
String filename = wxFileSelector(_("Open image file"), _(""), _(""), _(""),
|
||||
_("All images|*.bmp;*.jpg;*.png;*.gif|Windows bitmaps (*.bmp)|*.bmp|JPEG images (*.jpg;*.jpeg)|*.jpg;*.jpeg|PNG images (*.png)|*.png|GIF images (*.gif)|*.gif|TIFF images (*.tif;*.tiff)|*.tif;*.tiff"),
|
||||
wxOPEN);
|
||||
if (filename.empty()) {
|
||||
return;
|
||||
} else {
|
||||
if (!filename.empty()) {
|
||||
sliceImage(wxImage(filename));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void ImageValueEditor::sliceImage(const Image& image) {
|
||||
|
||||
@@ -20,7 +20,7 @@ class ImageValueEditor : public ImageValueViewer, public ValueEditor {
|
||||
public:
|
||||
DECLARE_VALUE_EDITOR(Image);
|
||||
|
||||
virtual void onLeftDClick(const RealPoint&, wxMouseEvent&);
|
||||
virtual bool onLeftDClick(const RealPoint&, wxMouseEvent&);
|
||||
|
||||
// --------------------------------------------------- : Clipboard
|
||||
|
||||
|
||||
@@ -13,10 +13,11 @@
|
||||
|
||||
IMPLEMENT_VALUE_EDITOR(Symbol) {}
|
||||
|
||||
void SymbolValueEditor::onLeftDClick(const RealPoint& pos, wxMouseEvent&) {
|
||||
bool SymbolValueEditor::onLeftDClick(const RealPoint& pos, wxMouseEvent&) {
|
||||
// TODO : use SetWindow as parent? Maybe not, the symbol editor will stay open when mainwindow closes
|
||||
SymbolWindow* wnd = new SymbolWindow(nullptr, valueP(), viewer.getSet());
|
||||
wnd->Show();
|
||||
return true;
|
||||
}
|
||||
|
||||
void SymbolValueEditor::determineSize(bool) {
|
||||
|
||||
@@ -20,7 +20,7 @@ class SymbolValueEditor : public SymbolValueViewer, public ValueEditor {
|
||||
public:
|
||||
DECLARE_VALUE_EDITOR(Symbol);
|
||||
|
||||
virtual void onLeftDClick(const RealPoint& pos, wxMouseEvent&);
|
||||
virtual bool onLeftDClick(const RealPoint& pos, wxMouseEvent&);
|
||||
virtual void determineSize(bool);
|
||||
};
|
||||
|
||||
|
||||
+22
-12
@@ -71,15 +71,17 @@ TextValueEditor::~TextValueEditor() {
|
||||
|
||||
// ----------------------------------------------------------------------------- : Mouse
|
||||
|
||||
void TextValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
bool TextValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
select_words = false;
|
||||
moveSelection(TYPE_INDEX, v.indexAt(style().getRotation().trInv(pos)), !ev.ShiftDown(), MOVE_MID);
|
||||
return true;
|
||||
}
|
||||
void TextValueEditor::onLeftUp(const RealPoint& pos, wxMouseEvent&) {
|
||||
bool TextValueEditor::onLeftUp(const RealPoint& pos, wxMouseEvent&) {
|
||||
// TODO: lookup position of click?
|
||||
return false;
|
||||
}
|
||||
|
||||
void TextValueEditor::onMotion(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
bool TextValueEditor::onMotion(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
if (ev.LeftIsDown()) {
|
||||
size_t index = v.indexAt(style().getRotation().trInv(pos));
|
||||
if (select_words) {
|
||||
@@ -98,27 +100,30 @@ void TextValueEditor::onMotion(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
moveSelection(TYPE_INDEX, index, false, MOVE_MID);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextValueEditor::onLeftDClick(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
bool TextValueEditor::onLeftDClick(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
select_words = true;
|
||||
size_t index = v.indexAt(style().getRotation().trInv(pos));
|
||||
moveSelection(TYPE_INDEX, prevWordBoundry(index), true, MOVE_MID);
|
||||
moveSelection(TYPE_INDEX, nextWordBoundry(index), false, MOVE_MID);
|
||||
return true;
|
||||
}
|
||||
|
||||
void TextValueEditor::onRightDown(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
bool TextValueEditor::onRightDown(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
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)) {
|
||||
// only move cursor when outside selection
|
||||
moveSelection(TYPE_INDEX, index, !ev.ShiftDown(), MOVE_MID);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Keyboard
|
||||
|
||||
void TextValueEditor::onChar(wxKeyEvent& ev) {
|
||||
bool TextValueEditor::onChar(wxKeyEvent& ev) {
|
||||
fixSelection();
|
||||
switch (ev.GetKeyCode()) {
|
||||
case WXK_LEFT:
|
||||
@@ -166,7 +171,7 @@ void TextValueEditor::onChar(wxKeyEvent& ev) {
|
||||
if (selection_start == selection_end) {
|
||||
// Walk over a <sep> as if we are the LEFT key
|
||||
moveSelection(TYPE_CURSOR, prevCharBoundry(selection_end), true, MOVE_LEFT);
|
||||
return;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
replaceSelection(wxEmptyString, _("Backspace"));
|
||||
@@ -195,6 +200,7 @@ void TextValueEditor::onChar(wxKeyEvent& ev) {
|
||||
replaceSelection(escape(String(ev.GetUnicodeKey(), 1)), _("Typing"));
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Other events
|
||||
@@ -629,13 +635,15 @@ void TextValueEditor::determineSize(bool force_fit) {
|
||||
style().angle = 0; // no rotation in nativeLook
|
||||
if (scrollbar) {
|
||||
// muliline, determine scrollbar size
|
||||
Rotation rot = viewer.getRotation();
|
||||
if (!force_fit) style().height = 100;
|
||||
int sbw = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
|
||||
RealPoint pos = rot.tr(style().getPos());
|
||||
scrollbar->SetSize(
|
||||
int(style().left + style().width - sbw + 1),
|
||||
int(style().top - 1),
|
||||
int(sbw),
|
||||
int(style().height + 2));
|
||||
(int)pos.x + rot.trS(style().width) + 1 - sbw,
|
||||
(int)pos.y - 1,
|
||||
(int)sbw,
|
||||
(int)rot.trS(style().height) + 2);
|
||||
v.reset();
|
||||
} else {
|
||||
// Height depends on font
|
||||
@@ -654,13 +662,15 @@ void TextValueEditor::onShow(bool showing) {
|
||||
}
|
||||
}
|
||||
|
||||
void TextValueEditor::onMouseWheel(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
bool TextValueEditor::onMouseWheel(const RealPoint& pos, wxMouseEvent& ev) {
|
||||
if (scrollbar) {
|
||||
int toScroll = ev.GetWheelRotation() * ev.GetLinesPerAction() / ev.GetWheelDelta(); // note: up is positive
|
||||
int target = min(max(scrollbar->GetScrollPos(wxVERTICAL) - toScroll, 0),
|
||||
scrollbar->GetScrollRange(wxVERTICAL) - scrollbar->GetScrollThumb(wxVERTICAL));
|
||||
scrollTo(target);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void TextValueEditor::scrollTo(int pos) {
|
||||
|
||||
@@ -36,18 +36,18 @@ class TextValueEditor : public TextValueViewer, public ValueEditor {
|
||||
virtual void onFocus();
|
||||
virtual void onLoseFocus();
|
||||
|
||||
virtual void onLeftDown (const RealPoint& pos, wxMouseEvent&);
|
||||
virtual void onLeftUp (const RealPoint& pos, wxMouseEvent&);
|
||||
virtual void onLeftDClick(const RealPoint& pos, wxMouseEvent&);
|
||||
virtual void onRightDown (const RealPoint& pos, wxMouseEvent&);
|
||||
virtual void onMotion (const RealPoint& pos, wxMouseEvent&);
|
||||
virtual void onMouseWheel(const RealPoint& pos, wxMouseEvent& ev);
|
||||
virtual bool onLeftDown (const RealPoint& pos, wxMouseEvent&);
|
||||
virtual bool onLeftUp (const RealPoint& pos, wxMouseEvent&);
|
||||
virtual bool onLeftDClick(const RealPoint& pos, wxMouseEvent&);
|
||||
virtual bool onRightDown (const RealPoint& pos, wxMouseEvent&);
|
||||
virtual bool onMotion (const RealPoint& pos, wxMouseEvent&);
|
||||
virtual bool onMouseWheel(const RealPoint& pos, wxMouseEvent& ev);
|
||||
|
||||
virtual bool onContextMenu(wxMenu& m, wxContextMenuEvent&);
|
||||
virtual wxMenu* getMenu(int type) const;
|
||||
virtual bool onCommand(int);
|
||||
|
||||
virtual void onChar(wxKeyEvent&);
|
||||
virtual bool onChar(wxKeyEvent&);
|
||||
|
||||
// --------------------------------------------------- : Actions
|
||||
|
||||
|
||||
Reference in New Issue
Block a user