Commit 8667020f authored by twanvl's avatar twanvl

added scrollbar to NativeLookEditor

parent 4f1f254c
...@@ -303,7 +303,7 @@ void SymbolFont::getCharInfo(RotatedDC& dc, Context& ctx, double font_size, cons ...@@ -303,7 +303,7 @@ void SymbolFont::getCharInfo(RotatedDC& dc, Context& ctx, double font_size, cons
RealSize SymbolFont::symbolSize(Context& ctx, double font_size, const DrawableSymbol& sym) { RealSize SymbolFont::symbolSize(Context& ctx, double font_size, const DrawableSymbol& sym) {
if (sym.symbol) { if (sym.symbol) {
return addDiagonal(sym.symbol->size(ctx, *this, font_size), spacing); return add_diagonal(sym.symbol->size(ctx, *this, font_size), spacing);
} else { } else {
return defaultSymbolSize(ctx, font_size); return defaultSymbolSize(ctx, font_size);
} }
...@@ -312,9 +312,9 @@ RealSize SymbolFont::symbolSize(Context& ctx, double font_size, const DrawableSy ...@@ -312,9 +312,9 @@ RealSize SymbolFont::symbolSize(Context& ctx, double font_size, const DrawableSy
RealSize SymbolFont::defaultSymbolSize(Context& ctx, double font_size) { RealSize SymbolFont::defaultSymbolSize(Context& ctx, double font_size) {
SymbolInFont* def = defaultSymbol(); SymbolInFont* def = defaultSymbol();
if (def) { if (def) {
return addDiagonal(def->size(ctx, *this, font_size), spacing); return add_diagonal(def->size(ctx, *this, font_size), spacing);
} else { } else {
return addDiagonal(RealSize(1,1), spacing); return add_diagonal(RealSize(1,1), spacing);
} }
} }
......
...@@ -210,7 +210,7 @@ void DataEditor::onMouseLeave(wxMouseEvent& ev) { ...@@ -210,7 +210,7 @@ void DataEditor::onMouseLeave(wxMouseEvent& ev) {
if (frame) frame->SetStatusText(wxEmptyString); if (frame) frame->SetStatusText(wxEmptyString);
} }
void DataEditor::selectField(wxMouseEvent& ev, void (ValueEditor::*event)(const RealPoint&, wxMouseEvent&)) { void DataEditor::selectField(wxMouseEvent& ev, bool (ValueEditor::*event)(const RealPoint&, wxMouseEvent&)) {
RealPoint pos = mousePoint(ev); RealPoint pos = mousePoint(ev);
// change viewer/editor // change viewer/editor
ValueEditor* old_editor = current_editor; ValueEditor* old_editor = current_editor;
...@@ -242,10 +242,7 @@ void DataEditor::selectFieldNoEvents(const RealPoint& p) { ...@@ -242,10 +242,7 @@ void DataEditor::selectFieldNoEvents(const RealPoint& p) {
} }
RealPoint DataEditor::mousePoint(const wxMouseEvent& ev) { RealPoint DataEditor::mousePoint(const wxMouseEvent& ev) {
StyleSheetP stylesheet = set->stylesheetFor(card); return getRotation().trInv(RealPoint(ev.GetX(), ev.GetY()));
StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet);
Rotation rot(ss.card_angle(), stylesheet->getCardRect(), ss.card_zoom());
return rot.trInv(RealPoint(ev.GetX(), ev.GetY()));
} }
// ----------------------------------------------------------------------------- : Keyboard events // ----------------------------------------------------------------------------- : Keyboard events
......
...@@ -67,14 +67,14 @@ class DataEditor : public CardViewer { ...@@ -67,14 +67,14 @@ class DataEditor : public CardViewer {
virtual void onInit(); virtual void onInit();
// --------------------------------------------------- : Data // --------------------------------------------------- : Data
private:
DECLARE_EVENT_TABLE();
ValueViewer* current_viewer; ///< The currently selected viewer ValueViewer* current_viewer; ///< The currently selected viewer
ValueEditor* current_editor; ///< The currently selected editor, corresponding to the viewer ValueEditor* current_editor; ///< The currently selected editor, corresponding to the viewer
vector<ValueViewer*> by_tab_index; ///< The editable viewers, sorted by tab index vector<ValueViewer*> by_tab_index; ///< The editable viewers, sorted by tab index
private:
// --------------------------------------------------- : Events // --------------------------------------------------- : Events
DECLARE_EVENT_TABLE();
void onLeftDown (wxMouseEvent&); void onLeftDown (wxMouseEvent&);
void onLeftUp (wxMouseEvent&); void onLeftUp (wxMouseEvent&);
...@@ -96,7 +96,7 @@ class DataEditor : public CardViewer { ...@@ -96,7 +96,7 @@ class DataEditor : public CardViewer {
/// Changes the selection to the field at the specified coordinates /// Changes the selection to the field at the specified coordinates
/** Sends an event to the event function of the current viewer */ /** Sends an event to the event function of the current viewer */
void selectField(wxMouseEvent& ev, void (ValueEditor::*event)(const RealPoint&, wxMouseEvent&)); void selectField(wxMouseEvent& ev, bool (ValueEditor::*event)(const RealPoint&, wxMouseEvent&));
// selectField, but don't send events // selectField, but don't send events
void selectFieldNoEvents(const RealPoint& pos); void selectFieldNoEvents(const RealPoint& pos);
/// Convert mouse coordinates to internal coordinates /// Convert mouse coordinates to internal coordinates
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <gui/control/card_viewer.hpp> #include <gui/control/card_viewer.hpp>
#include <data/stylesheet.hpp> #include <data/stylesheet.hpp>
#include <data/settings.hpp>
#include <render/value/viewer.hpp> #include <render/value/viewer.hpp>
#include <wx/dcbuffer.h> #include <wx/dcbuffer.h>
...@@ -32,7 +33,7 @@ wxSize CardViewer::DoGetBestSize() const { ...@@ -32,7 +33,7 @@ wxSize CardViewer::DoGetBestSize() const {
void CardViewer::redraw(const ValueViewer& v) { void CardViewer::redraw(const ValueViewer& v) {
up_to_date = false; up_to_date = false;
RefreshRect(v.boundingBox(), false); RefreshRect(getRotation().tr(v.boundingBox()), false);
} }
void CardViewer::onChange() { void CardViewer::onChange() {
...@@ -66,12 +67,16 @@ void CardViewer::onPaint(wxPaintEvent&) { ...@@ -66,12 +67,16 @@ void CardViewer::onPaint(wxPaintEvent&) {
up_to_date = false; up_to_date = false;
} }
wxBufferedPaintDC dc(this, buffer); wxBufferedPaintDC dc(this, buffer);
dc.SetClippingRegion(GetUpdateRegion()); // scrolling
// int dx = GetScrollPos(wxHORIZONTAL), dy = GetScrollPos(wxVERTICAL);
// dc.SetDeviceOrigin(-dx, -dy);
wxRegion clip = GetUpdateRegion();
// clip.Offset(dx, dy);
dc.SetClippingRegion(clip);
// draw
if (!up_to_date) { if (!up_to_date) {
up_to_date = true; up_to_date = true;
dc.BeginDrawing();
draw(dc); draw(dc);
dc.EndDrawing();
} }
} }
...@@ -80,7 +85,10 @@ void CardViewer::drawViewer(RotatedDC& dc, ValueViewer& v) { ...@@ -80,7 +85,10 @@ void CardViewer::drawViewer(RotatedDC& dc, ValueViewer& v) {
} }
bool CardViewer::shouldDraw(const ValueViewer& v) const { bool CardViewer::shouldDraw(const ValueViewer& v) const {
return GetUpdateRegion().Contains(v.boundingBox().toRect()) != wxOutRegion; // int dx = GetScrollPos(wxHORIZONTAL), dy = GetScrollPos(wxVERTICAL);
// wxRegion clip = GetUpdateRegion();
// clip.Offset(dx, dy);
return GetUpdateRegion().Contains(getRotation().tr(v.boundingBox().toRect()).toRect()) != wxOutRegion;
} }
// helper class for overdrawDC() // helper class for overdrawDC()
...@@ -102,7 +110,15 @@ shared_ptr<DC> CardViewer::overdrawDC() { ...@@ -102,7 +110,15 @@ shared_ptr<DC> CardViewer::overdrawDC() {
// don't call from onPaint // don't call from onPaint
assert(!inOnPaint()); assert(!inOnPaint());
#endif #endif
return shared_ptr<DC>((wxBufferedDC*)(new OverdrawDC(this))); return shared_ptr<DC>((wxBufferedDC*)new OverdrawDC(this));
}
Rotation CardViewer::getRotation() const {
// Same as DataViewer::getRotation, only taking into account scrolling
if (!stylesheet) stylesheet = set->stylesheet;
StyleSheetSettings& ss = settings.stylesheetSettingsFor(*stylesheet);
int dx = GetScrollPos(wxHORIZONTAL), dy = GetScrollPos(wxVERTICAL);
return Rotation(ss.card_angle(), stylesheet->getCardRect().move(-dx,-dy,0,0), ss.card_zoom(), true);
} }
// ----------------------------------------------------------------------------- : Event table // ----------------------------------------------------------------------------- : Event table
......
...@@ -33,6 +33,9 @@ class CardViewer : public wxControl, public DataViewer { ...@@ -33,6 +33,9 @@ class CardViewer : public wxControl, public DataViewer {
/// Invalidate and redraw (the area of) a single value viewer /// Invalidate and redraw (the area of) a single value viewer
void redraw(const ValueViewer&); void redraw(const ValueViewer&);
/// The rotation to use
virtual Rotation getRotation() const;
protected: protected:
/// Return the desired size of control /// Return the desired size of control
virtual wxSize DoGetBestSize() const; virtual wxSize DoGetBestSize() const;
......
...@@ -21,7 +21,8 @@ NativeLookEditor::NativeLookEditor(Window* parent, int id, long style) ...@@ -21,7 +21,8 @@ NativeLookEditor::NativeLookEditor(Window* parent, int id, long style)
{} {}
Rotation NativeLookEditor::getRotation() const { Rotation NativeLookEditor::getRotation() const {
return Rotation(0, RealRect(RealPoint(0,0),GetClientSize())); int dx = GetScrollPos(wxHORIZONTAL), dy = GetScrollPos(wxVERTICAL);
return Rotation(0, RealRect(RealPoint(-dx,-dy),GetClientSize()));
} }
void NativeLookEditor::draw(DC& dc) { void NativeLookEditor::draw(DC& dc) {
...@@ -43,7 +44,7 @@ void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) { ...@@ -43,7 +44,7 @@ void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) {
dc.DrawText(tr(*set->game, s.fieldP->name, capitalize_sentence(s.fieldP->name)), dc.DrawText(tr(*set->game, s.fieldP->name, capitalize_sentence(s.fieldP->name)),
RealPoint(margin_left, s.top + 1)); RealPoint(margin_left, s.top + 1));
// draw 3D border // draw 3D border
draw_control_border(this, dc.getDC(), RealRect(s.left - 1, s.top - 1, s.width + 2, s.height + 2)); draw_control_border(this, dc.getDC(), dc.tr(RealRect(s.left - 1, s.top - 1, s.width + 2, s.height + 2)));
} }
// draw viewer // draw viewer
v.draw(dc); v.draw(dc);
...@@ -52,8 +53,8 @@ void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) { ...@@ -52,8 +53,8 @@ void NativeLookEditor::drawViewer(RotatedDC& dc, ValueViewer& v) {
void NativeLookEditor::resizeViewers() { void NativeLookEditor::resizeViewers() {
// size stuff // size stuff
double y = margin; double y = margin;
int w; int w, h;
GetClientSize(&w, 0); GetClientSize(&w, &h);
const int default_height = 17; const int default_height = 17;
// Set editor sizes // Set editor sizes
FOR_EACH(v, viewers) { FOR_EACH(v, viewers) {
...@@ -70,6 +71,23 @@ void NativeLookEditor::resizeViewers() { ...@@ -70,6 +71,23 @@ void NativeLookEditor::resizeViewers() {
if (e) e->determineSize(); if (e) e->determineSize();
y += s->height + vspace; y += s->height + vspace;
} }
SetVirtualSize(w,y);
SetScrollbar(wxVERTICAL, 0, h, y);
if (y >= h) {
// Doesn't fit vertically, add scrollbar and resize
/*
y = margin;
FOR_EACH(v, viewers) {
StyleP s = v->getStyle();
ValueEditor* e = v->getEditor();
s->top = y;
s->width = s->width - wxSystemSettings::GetMetric(wxSYS_VSCROLL_X, this);
if (e) e->determineSize();
y += s->height + vspace;
}
*/
// create scrollbar
}
} }
void NativeLookEditor::onInit() { void NativeLookEditor::onInit() {
...@@ -87,9 +105,65 @@ void NativeLookEditor::onSize(wxSizeEvent& ev) { ...@@ -87,9 +105,65 @@ void NativeLookEditor::onSize(wxSizeEvent& ev) {
resizeViewers(); resizeViewers();
Refresh(false); Refresh(false);
} }
void NativeLookEditor::onScroll(wxScrollWinEvent& ev) {
if (ev.GetOrientation() == wxVERTICAL) {
int y = GetScrollPos(wxVERTICAL);
int page = GetClientSize().y; // view size
// determine new y offset
// NOTE: can't use case, these are not constants
if (ev.GetEventType() == wxEVT_SCROLLWIN_TOP) {
y = 0;
} else if (ev.GetEventType() == wxEVT_SCROLLWIN_BOTTOM) {
y = numeric_limits<int>::max();
} else if (ev.GetEventType() == wxEVT_SCROLLWIN_LINEUP) {
y = y - 10;
} else if (ev.GetEventType() == wxEVT_SCROLLWIN_LINEDOWN) {
y = y + 10;
} else if (ev.GetEventType() == wxEVT_SCROLLWIN_PAGEUP) {
y = y - page;
} else if (ev.GetEventType() == wxEVT_SCROLLWIN_PAGEDOWN) {
y = y + page;
} else if (ev.GetEventType() == wxEVT_SCROLLWIN_THUMBTRACK ||
ev.GetEventType() == wxEVT_SCROLLWIN_THUMBRELEASE) {
y = ev.GetPosition();
}
scrollTo(wxVERTICAL, y);
}
}
void NativeLookEditor::onMouseWheel(wxMouseEvent& ev) {
if (current_editor) {
bool scrolled = current_editor->onMouseWheel(mousePoint(ev), ev);
if (scrolled) return;
}
int toScroll = 10 * ev.GetWheelRotation() * ev.GetLinesPerAction() / ev.GetWheelDelta(); // note: up is positive
int y = GetScrollPos(wxVERTICAL);
scrollTo(wxVERTICAL, y - toScroll);
}
void NativeLookEditor::scrollTo(int direction, int pos) {
if (direction == wxVERTICAL) {
int y = GetScrollPos(wxVERTICAL);
int height = GetVirtualSize().y; // height
int page = GetClientSize().y; // view size
int bottom = max(0, height - page);
pos = max(0, min(bottom, pos));
if (pos != y) {
SetScrollPos(wxVERTICAL, pos);
// move child controls
FOR_EACH(v, viewers) {
ValueEditor* e = v->getEditor();
if (e) e->determineSize();
}
// redraw
onChange();
}
}
}
BEGIN_EVENT_TABLE(NativeLookEditor, DataEditor) BEGIN_EVENT_TABLE(NativeLookEditor, DataEditor)
EVT_SIZE (NativeLookEditor::onSize) EVT_SIZE (NativeLookEditor::onSize)
EVT_SCROLLWIN (NativeLookEditor::onScroll)
EVT_MOUSEWHEEL (NativeLookEditor::onMouseWheel)
END_EVENT_TABLE() END_EVENT_TABLE()
......
...@@ -41,6 +41,9 @@ class NativeLookEditor : public DataEditor { ...@@ -41,6 +41,9 @@ class NativeLookEditor : public DataEditor {
DECLARE_EVENT_TABLE(); DECLARE_EVENT_TABLE();
void onSize(wxSizeEvent&); void onSize(wxSizeEvent&);
void onScroll(wxScrollWinEvent&);
void onMouseWheel(wxMouseEvent&);
void scrollTo(int direction, int pos);
/// Resize the viewers so they match with this control /// Resize the viewers so they match with this control
void resizeViewers(); void resizeViewers();
}; };
......
...@@ -307,18 +307,19 @@ void DropDownList::onMotion(wxMouseEvent& ev) { ...@@ -307,18 +307,19 @@ void DropDownList::onMotion(wxMouseEvent& ev) {
// ----------------------------------------------------------------------------- : DropDownList : Parent events // ----------------------------------------------------------------------------- : DropDownList : Parent events
void DropDownList::onMouseInParent(wxMouseEvent& ev, bool open_in_place) { bool DropDownList::onMouseInParent(wxMouseEvent& ev, bool open_in_place) {
if (IsShown()) hide(false); if (IsShown()) hide(false);
else show(open_in_place, wxPoint(ev.GetX(), ev.GetY())); else show(open_in_place, wxPoint(ev.GetX(), ev.GetY()));
return true;
} }
void DropDownList::onCharInParent(wxKeyEvent& ev) { bool DropDownList::onCharInParent(wxKeyEvent& ev) {
// keyboard codes // keyboard codes
int k = ev.GetKeyCode(); int k = ev.GetKeyCode();
if (IsShown()) { if (IsShown()) {
if (open_sub_menu) { if (open_sub_menu) {
// sub menu always takes keys // sub menu always takes keys
open_sub_menu->onCharInParent(ev); return open_sub_menu->onCharInParent(ev);
} else { } else {
switch (k) { switch (k) {
case WXK_UP: case WXK_UP:
...@@ -356,15 +357,18 @@ void DropDownList::onCharInParent(wxKeyEvent& ev) { ...@@ -356,15 +357,18 @@ void DropDownList::onCharInParent(wxKeyEvent& ev) {
selected_item = index; selected_item = index;
showSubMenu(); showSubMenu();
Refresh(false); Refresh(false);
return; return true;
} }
} }
} }
} }
return true;
} else if (k==WXK_SPACE || k==WXK_RETURN || k==WXK_DOWN) { } else if (k==WXK_SPACE || k==WXK_RETURN || k==WXK_DOWN) {
// drop down list is not shown yet, show it now // drop down list is not shown yet, show it now
show(false, wxPoint(0,0)); show(false, wxPoint(0,0));
return true;
} }
return false;
} }
// ----------------------------------------------------------------------------- : DropDownList : Event table // ----------------------------------------------------------------------------- : DropDownList : Event table
......
...@@ -35,9 +35,9 @@ class DropDownList : public wxPopupWindow { ...@@ -35,9 +35,9 @@ class DropDownList : public wxPopupWindow {
// --------------------------------------------------- : Parent control // --------------------------------------------------- : Parent control
/// Takes all keyboard events from a FieldEditor /// Takes all keyboard events from a FieldEditor
void onCharInParent(wxKeyEvent&); bool onCharInParent(wxKeyEvent&);
/// Takes a mouse event from the parent, show/hide as appropriate /// Takes a mouse event from the parent, show/hide as appropriate
void onMouseInParent(wxMouseEvent&, bool open_in_place); bool onMouseInParent(wxMouseEvent&, bool open_in_place);
protected: protected:
// --------------------------------------------------- : Selection // --------------------------------------------------- : Selection
......
...@@ -37,9 +37,10 @@ int focused_control(const Window* window) { ...@@ -37,9 +37,10 @@ int focused_control(const Window* window) {
/// Fill a DC with a single color /// Fill a DC with a single color
void clearDC(DC& dc, const wxBrush& brush) { void clearDC(DC& dc, const wxBrush& brush) {
wxSize size = dc.GetSize(); wxSize size = dc.GetSize();
wxPoint pos = dc.GetDeviceOrigin(); // don't you love undocumented methods?
dc.SetPen(*wxTRANSPARENT_PEN); dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(brush); dc.SetBrush(brush);
dc.DrawRectangle(0, 0, size.GetWidth(), size.GetHeight()); dc.DrawRectangle(-pos.x, -pos.y, size.GetWidth(), size.GetHeight());
} }
void clearDC_black(DC& dc) { void clearDC_black(DC& dc) {
......
...@@ -228,13 +228,13 @@ ChoiceValueEditor::~ChoiceValueEditor() { ...@@ -228,13 +228,13 @@ ChoiceValueEditor::~ChoiceValueEditor() {
thumbnail_thread.abort(this); thumbnail_thread.abort(this);
} }
void ChoiceValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) { bool ChoiceValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
//HACK TODO REMOVEME //HACK TODO REMOVEME
thumbnail_thread.abortAll(); 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) { bool ChoiceValueEditor::onChar(wxKeyEvent& ev) {
drop_down->onCharInParent(ev); return drop_down->onCharInParent(ev);
} }
void ChoiceValueEditor::onLoseFocus() { void ChoiceValueEditor::onLoseFocus() {
drop_down->hide(false); drop_down->hide(false);
...@@ -243,7 +243,7 @@ void ChoiceValueEditor::onLoseFocus() { ...@@ -243,7 +243,7 @@ void ChoiceValueEditor::onLoseFocus() {
void ChoiceValueEditor::draw(RotatedDC& dc) { void ChoiceValueEditor::draw(RotatedDC& dc) {
ChoiceValueViewer::draw(dc); ChoiceValueViewer::draw(dc);
if (nativeLook()) { 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) { void ChoiceValueEditor::determineSize(bool) {
......
...@@ -25,8 +25,8 @@ class ChoiceValueEditor : public ChoiceValueViewer, public ValueEditor { ...@@ -25,8 +25,8 @@ class ChoiceValueEditor : public ChoiceValueViewer, public ValueEditor {
~ChoiceValueEditor(); ~ChoiceValueEditor();
// --------------------------------------------------- : Events // --------------------------------------------------- : Events
virtual void onLeftDown(const RealPoint& pos, wxMouseEvent& ev); virtual bool onLeftDown(const RealPoint& pos, wxMouseEvent& ev);
virtual void onChar(wxKeyEvent& ev); virtual bool onChar(wxKeyEvent& ev);
virtual void onLoseFocus(); virtual void onLoseFocus();
virtual void draw(RotatedDC& dc); virtual void draw(RotatedDC& dc);
......
...@@ -128,11 +128,11 @@ IMPLEMENT_VALUE_EDITOR(Color) ...@@ -128,11 +128,11 @@ IMPLEMENT_VALUE_EDITOR(Color)
, drop_down(new DropDownColorList(&editor(), *this)) , drop_down(new DropDownColorList(&editor(), *this))
{} {}
void ColorValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) { bool ColorValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
drop_down->onMouseInParent(ev, !nativeLook()); return drop_down->onMouseInParent(ev, !nativeLook());
} }
void ColorValueEditor::onChar(wxKeyEvent& ev) { bool ColorValueEditor::onChar(wxKeyEvent& ev) {
drop_down->onCharInParent(ev); return drop_down->onCharInParent(ev);
} }
void ColorValueEditor::onLoseFocus() { void ColorValueEditor::onLoseFocus() {
drop_down->hide(false); drop_down->hide(false);
...@@ -141,7 +141,7 @@ void ColorValueEditor::onLoseFocus() { ...@@ -141,7 +141,7 @@ void ColorValueEditor::onLoseFocus() {
void ColorValueEditor::draw(RotatedDC& dc) { void ColorValueEditor::draw(RotatedDC& dc) {
ColorValueViewer::draw(dc); ColorValueViewer::draw(dc);
if (nativeLook()) { 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) { void ColorValueEditor::determineSize(bool) {
......
...@@ -23,8 +23,8 @@ class ColorValueEditor : public ColorValueViewer, public ValueEditor { ...@@ -23,8 +23,8 @@ class ColorValueEditor : public ColorValueViewer, public ValueEditor {
DECLARE_VALUE_EDITOR(Color); DECLARE_VALUE_EDITOR(Color);
// --------------------------------------------------- : Events // --------------------------------------------------- : Events
virtual void onLeftDown(const RealPoint& pos, wxMouseEvent& ev); virtual bool onLeftDown(const RealPoint& pos, wxMouseEvent& ev);
virtual void onChar(wxKeyEvent& ev); virtual bool onChar(wxKeyEvent& ev);
virtual void onLoseFocus(); virtual void onLoseFocus();
virtual void draw(RotatedDC& dc); virtual void draw(RotatedDC& dc);
......
...@@ -39,16 +39,16 @@ class ValueEditor { ...@@ -39,16 +39,16 @@ class ValueEditor {
/// This editor loses focus /// This editor loses focus
virtual void onLoseFocus() {} virtual void onLoseFocus() {}
/// Handle mouse events /// Handle mouse events, return true if the event is used
virtual void onLeftDown (const RealPoint& pos, wxMouseEvent& ev) {} virtual bool onLeftDown (const RealPoint& pos, wxMouseEvent& ev) { return false; }
virtual void onLeftUp (const RealPoint& pos, wxMouseEvent& ev) {} virtual bool onLeftUp (const RealPoint& pos, wxMouseEvent& ev) { return false; }
virtual void onLeftDClick (const RealPoint& pos, wxMouseEvent& ev) {} virtual bool onLeftDClick (const RealPoint& pos, wxMouseEvent& ev) { return false; }
virtual void onRightDown (const RealPoint& pos, wxMouseEvent& ev) {} virtual bool onRightDown (const RealPoint& pos, wxMouseEvent& ev) { return false; }
virtual void onMotion (const RealPoint& pos, wxMouseEvent& ev) {} virtual bool onMotion (const RealPoint& pos, wxMouseEvent& ev) { return false; }
virtual void onMouseWheel (const RealPoint& pos, wxMouseEvent& ev) {} virtual bool onMouseWheel (const RealPoint& pos, wxMouseEvent& ev) { return false; }
/// Key events /// 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 /// a context menu is requested, add extra items to the menu m
/** return false to suppress menu */ /** return false to suppress menu */
......
...@@ -16,15 +16,14 @@ ...@@ -16,15 +16,14 @@
IMPLEMENT_VALUE_EDITOR(Image) {} IMPLEMENT_VALUE_EDITOR(Image) {}
void ImageValueEditor::onLeftDClick(const RealPoint&, wxMouseEvent&) { bool ImageValueEditor::onLeftDClick(const RealPoint&, wxMouseEvent&) {
String filename = wxFileSelector(_("Open image file"), _(""), _(""), _(""), 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"), _("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); wxOPEN);
if (filename.empty()) { if (!filename.empty()) {
return;
} else {
sliceImage(wxImage(filename)); sliceImage(wxImage(filename));
} }
return true;
} }
void ImageValueEditor::sliceImage(const Image& image) { void ImageValueEditor::sliceImage(const Image& image) {
......
...@@ -20,7 +20,7 @@ class ImageValueEditor : public ImageValueViewer, public ValueEditor { ...@@ -20,7 +20,7 @@ class ImageValueEditor : public ImageValueViewer, public ValueEditor {
public: public:
DECLARE_VALUE_EDITOR(Image); DECLARE_VALUE_EDITOR(Image);
virtual void onLeftDClick(const RealPoint&, wxMouseEvent&); virtual bool onLeftDClick(const RealPoint&, wxMouseEvent&);
// --------------------------------------------------- : Clipboard // --------------------------------------------------- : Clipboard
......
...@@ -13,10 +13,11 @@ ...@@ -13,10 +13,11 @@
IMPLEMENT_VALUE_EDITOR(Symbol) {} 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 // TODO : use SetWindow as parent? Maybe not, the symbol editor will stay open when mainwindow closes
SymbolWindow* wnd = new SymbolWindow(nullptr, valueP(), viewer.getSet()); SymbolWindow* wnd = new SymbolWindow(nullptr, valueP(), viewer.getSet());
wnd->Show(); wnd->Show();
return true;
} }
void SymbolValueEditor::determineSize(bool) { void SymbolValueEditor::determineSize(bool) {
......
...@@ -20,7 +20,7 @@ class SymbolValueEditor : public SymbolValueViewer, public ValueEditor { ...@@ -20,7 +20,7 @@ class SymbolValueEditor : public SymbolValueViewer, public ValueEditor {
public: public:
DECLARE_VALUE_EDITOR(Symbol); DECLARE_VALUE_EDITOR(Symbol);
virtual void onLeftDClick(const RealPoint& pos, wxMouseEvent&); virtual bool onLeftDClick(const RealPoint& pos, wxMouseEvent&);
virtual void determineSize(bool); virtual void determineSize(bool);
}; };
......
...@@ -71,15 +71,17 @@ TextValueEditor::~TextValueEditor() { ...@@ -71,15 +71,17 @@ TextValueEditor::~TextValueEditor() {
// ----------------------------------------------------------------------------- : Mouse // ----------------------------------------------------------------------------- : Mouse
void TextValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) { bool TextValueEditor::onLeftDown(const RealPoint& pos, wxMouseEvent& ev) {
select_words = false; select_words = false;
moveSelection(TYPE_INDEX, v.indexAt(style().getRotation().trInv(pos)), !ev.ShiftDown(), MOVE_MID); 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? // 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()) { if (ev.LeftIsDown()) {
size_t index = v.indexAt(style().getRotation().trInv(pos)); size_t index = v.indexAt(style().getRotation().trInv(pos));
if (select_words) { if (select_words) {
...@@ -98,27 +100,30 @@ void TextValueEditor::onMotion(const RealPoint& pos, wxMouseEvent& ev) { ...@@ -98,27 +100,30 @@ void TextValueEditor::onMotion(const RealPoint& pos, wxMouseEvent& ev) {
moveSelection(TYPE_INDEX, index, false, MOVE_MID); 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; select_words = true;
size_t index = v.indexAt(style().getRotation().trInv(pos)); size_t index = v.indexAt(style().getRotation().trInv(pos));
moveSelection(TYPE_INDEX, prevWordBoundry(index), true, MOVE_MID); moveSelection(TYPE_INDEX, prevWordBoundry(index), true, MOVE_MID);
moveSelection(TYPE_INDEX, nextWordBoundry(index), false, 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)); size_t index = v.indexAt(style().getRotation().trInv(pos));
if (index < min(selection_start_i, selection_end_i) || if (index < min(selection_start_i, selection_end_i) ||
index > max(selection_start_i, selection_end_i)) { index > max(selection_start_i, selection_end_i)) {
// only move cursor when outside selection // only move cursor when outside selection
moveSelection(TYPE_INDEX, index, !ev.ShiftDown(), MOVE_MID); moveSelection(TYPE_INDEX, index, !ev.ShiftDown(), MOVE_MID);
} }
return true;
} }
// ----------------------------------------------------------------------------- : Keyboard // ----------------------------------------------------------------------------- : Keyboard
void TextValueEditor::onChar(wxKeyEvent& ev) { bool TextValueEditor::onChar(wxKeyEvent& ev) {
fixSelection(); fixSelection();
switch (ev.GetKeyCode()) { switch (ev.GetKeyCode()) {
case WXK_LEFT: case WXK_LEFT:
...@@ -166,7 +171,7 @@ void TextValueEditor::onChar(wxKeyEvent& ev) { ...@@ -166,7 +171,7 @@ void TextValueEditor::onChar(wxKeyEvent& ev) {
if (selection_start == selection_end) { if (selection_start == selection_end) {
// Walk over a <sep> as if we are the LEFT key // Walk over a <sep> as if we are the LEFT key
moveSelection(TYPE_CURSOR, prevCharBoundry(selection_end), true, MOVE_LEFT); moveSelection(TYPE_CURSOR, prevCharBoundry(selection_end), true, MOVE_LEFT);
return; return true;
} }
} }
replaceSelection(wxEmptyString, _("Backspace")); replaceSelection(wxEmptyString, _("Backspace"));
...@@ -195,6 +200,7 @@ void TextValueEditor::onChar(wxKeyEvent& ev) { ...@@ -195,6 +200,7 @@ void TextValueEditor::onChar(wxKeyEvent& ev) {
replaceSelection(escape(String(ev.GetUnicodeKey(), 1)), _("Typing")); replaceSelection(escape(String(ev.GetUnicodeKey(), 1)), _("Typing"));
} }
} }
return true;
} }
// ----------------------------------------------------------------------------- : Other events // ----------------------------------------------------------------------------- : Other events
...@@ -629,13 +635,15 @@ void TextValueEditor::determineSize(bool force_fit) { ...@@ -629,13 +635,15 @@ void TextValueEditor::determineSize(bool force_fit) {
style().angle = 0; // no rotation in nativeLook style().angle = 0; // no rotation in nativeLook
if (scrollbar) { if (scrollbar) {
// muliline, determine scrollbar size // muliline, determine scrollbar size
Rotation rot = viewer.getRotation();
if (!force_fit) style().height = 100; if (!force_fit) style().height = 100;
int sbw = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X); int sbw = wxSystemSettings::GetMetric(wxSYS_VSCROLL_X);
RealPoint pos = rot.tr(style().getPos());
scrollbar->SetSize( scrollbar->SetSize(
int(style().left + style().width - sbw + 1), (int)pos.x + rot.trS(style().width) + 1 - sbw,
int(style().top - 1), (int)pos.y - 1,
int(sbw), (int)sbw,
int(style().height + 2)); (int)rot.trS(style().height) + 2);
v.reset(); v.reset();
} else { } else {
// Height depends on font // Height depends on font
...@@ -654,13 +662,15 @@ void TextValueEditor::onShow(bool showing) { ...@@ -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) { if (scrollbar) {
int toScroll = ev.GetWheelRotation() * ev.GetLinesPerAction() / ev.GetWheelDelta(); // note: up is positive int toScroll = ev.GetWheelRotation() * ev.GetLinesPerAction() / ev.GetWheelDelta(); // note: up is positive
int target = min(max(scrollbar->GetScrollPos(wxVERTICAL) - toScroll, 0), int target = min(max(scrollbar->GetScrollPos(wxVERTICAL) - toScroll, 0),
scrollbar->GetScrollRange(wxVERTICAL) - scrollbar->GetScrollThumb(wxVERTICAL)); scrollbar->GetScrollRange(wxVERTICAL) - scrollbar->GetScrollThumb(wxVERTICAL));
scrollTo(target); scrollTo(target);
return true;
} }
return false;
} }
void TextValueEditor::scrollTo(int pos) { void TextValueEditor::scrollTo(int pos) {
......
...@@ -36,18 +36,18 @@ class TextValueEditor : public TextValueViewer, public ValueEditor { ...@@ -36,18 +36,18 @@ class TextValueEditor : public TextValueViewer, public ValueEditor {
virtual void onFocus(); virtual void onFocus();
virtual void onLoseFocus(); virtual void onLoseFocus();
virtual void onLeftDown (const RealPoint& pos, wxMouseEvent&); virtual bool onLeftDown (const RealPoint& pos, wxMouseEvent&);
virtual void onLeftUp (const RealPoint& pos, wxMouseEvent&); virtual bool onLeftUp (const RealPoint& pos, wxMouseEvent&);
virtual void onLeftDClick(const RealPoint& pos, wxMouseEvent&); virtual bool onLeftDClick(const RealPoint& pos, wxMouseEvent&);
virtual void onRightDown (const RealPoint& pos, wxMouseEvent&); virtual bool onRightDown (const RealPoint& pos, wxMouseEvent&);
virtual void onMotion (const RealPoint& pos, wxMouseEvent&); virtual bool onMotion (const RealPoint& pos, wxMouseEvent&);
virtual void onMouseWheel(const RealPoint& pos, wxMouseEvent& ev); virtual bool onMouseWheel(const RealPoint& pos, wxMouseEvent& ev);
virtual bool onContextMenu(wxMenu& m, wxContextMenuEvent&); virtual bool onContextMenu(wxMenu& m, wxContextMenuEvent&);
virtual wxMenu* getMenu(int type) const; virtual wxMenu* getMenu(int type) const;
virtual bool onCommand(int); virtual bool onCommand(int);
virtual void onChar(wxKeyEvent&); virtual bool onChar(wxKeyEvent&);
// --------------------------------------------------- : Actions // --------------------------------------------------- : Actions
......
...@@ -382,7 +382,7 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars, ...@@ -382,7 +382,7 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars,
accept_word = true; accept_word = true;
} }
// Add size of the character // Add size of the character
word_size = addHorizontal(word_size, c.size); word_size = add_horizontal(word_size, c.size);
positions_word.push_back(word_size.width); positions_word.push_back(word_size.width);
// Did the word become too long? // Did the word become too long?
if (style.field().multi_line && !break_now) { if (style.field().multi_line && !break_now) {
...@@ -411,7 +411,7 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars, ...@@ -411,7 +411,7 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars,
line.positions.push_back(line_size.width + p); line.positions.push_back(line_size.width + p);
} }
// add size; next word // add size; next word
line_size = addHorizontal(line_size, word_size); line_size = add_horizontal(line_size, word_size);
word_size = RealSize(0, 0); word_size = RealSize(0, 0);
word_start = i + 1; word_start = i + 1;
positions_word.clear(); positions_word.clear();
...@@ -445,7 +445,7 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars, ...@@ -445,7 +445,7 @@ bool TextViewer::prepareLinesScale(RotatedDC& dc, const vector<CharInfo>& chars,
FOR_EACH(p, positions_word) { FOR_EACH(p, positions_word) {
line.positions.push_back(line_size.width + p); line.positions.push_back(line_size.width + p);
} }
line_size = addHorizontal(line_size, word_size); line_size = add_horizontal(line_size, word_size);
// the last line // the last line
if (line_size.height < 0.01 && !lines.empty()) { if (line_size.height < 0.01 && !lines.empty()) {
// if a line has 0 height, use the height of the line above it, but at most once // if a line has 0 height, use the height of the line above it, but at most once
...@@ -477,7 +477,7 @@ void TextViewer::alignLines(RotatedDC& dc, const vector<CharInfo>& chars, const ...@@ -477,7 +477,7 @@ void TextViewer::alignLines(RotatedDC& dc, const vector<CharInfo>& chars, const
if (l.line_height) break; // not an empty line if (l.line_height) break; // not an empty line
} }
// amount to shift all lines vertically // amount to shift all lines vertically
RealSize s = addDiagonal( RealSize s = add_diagonal(
dc.getInternalSize(), dc.getInternalSize(),
-RealSize(style.padding_left+style.padding_right, style.padding_top + style.padding_bottom)); -RealSize(style.padding_left+style.padding_right, style.padding_top + style.padding_bottom));
double vdelta = align_delta_y(style.alignment, s.height, height); double vdelta = align_delta_y(style.alignment, s.height, height);
......
...@@ -41,12 +41,11 @@ void MultipleChoiceValueViewer::draw(RotatedDC& dc) { ...@@ -41,12 +41,11 @@ void MultipleChoiceValueViewer::draw(RotatedDC& dc) {
} }
void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const String& choice, bool active) { void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const String& choice, bool active) {
double margin = 0, height = 0; RealSize size;
if (nativeLook() && (style().render_style & RENDER_CHECKLIST)) { if (nativeLook() && (style().render_style & RENDER_CHECKLIST)) {
height = 10; wxRect rect = dc.tr(RealRect(pos + RealSize(1,1), RealSize(12,12)));
margin = 11;
wxRect rect = dc.tr(RealRect(pos,RealSize(10,10)));
draw_checkbox(nullptr, dc.getDC(), rect, active); // TODO draw_checkbox(nullptr, dc.getDC(), rect, active); // TODO
size = add_horizontal(size, RealSize(14,16));
} }
if (style().render_style & RENDER_IMAGE) { if (style().render_style & RENDER_IMAGE) {
map<String,ScriptableImage>::iterator it = style().choice_images.find(cannocial_name_form(choice)); map<String,ScriptableImage>::iterator it = style().choice_images.find(cannocial_name_form(choice));
...@@ -54,21 +53,22 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const ...@@ -54,21 +53,22 @@ void MultipleChoiceValueViewer::drawChoice(RotatedDC& dc, RealPoint& pos, const
ScriptImageP i = it->second.update(viewer.getContext(), *viewer.stylesheet, 0, 0); ScriptImageP i = it->second.update(viewer.getContext(), *viewer.stylesheet, 0, 0);
if (i) { if (i) {
// TODO : alignment? // TODO : alignment?
dc.DrawImage(i->image, pos, i->combine == COMBINE_NORMAL ? style().combine : i->combine); dc.DrawImage(i->image, pos + RealSize(size.width, 0), i->combine == COMBINE_NORMAL ? style().combine : i->combine);
margin += dc.trInvS(i->image.GetWidth()) + 1; size = add_horizontal(size, dc.trInv(RealSize(i->image.GetWidth() + 1, i->image.GetHeight())));
height = max(height, dc.trInvS(i->image.GetHeight()));
} }
} }
} }
if (style().render_style & RENDER_TEXT) { if (style().render_style & RENDER_TEXT) {
// draw text // draw text
// TODO: alignment String text = tr(*viewer.stylesheet, choice, capitalize(choice));
dc.DrawText(tr(*viewer.stylesheet, choice, capitalize(choice)), pos + RealSize(margin, 0)); RealSize text_size = dc.GetTextExtent(text);
// TODO: determine size dc.DrawText(text, align_in_rect(ALIGN_MIDDLE_LEFT, text_size,
RealRect(pos + RealSize(size.width + 1, 0), RealSize(0,size.height))));
size = add_horizontal(size, text_size);
} }
if (style().direction == HORIZONTAL) { if (style().direction == HORIZONTAL) {
pos.x += margin + style().spacing; pos.x += size.width + style().spacing;
} else { } else {
pos.y += height + style().spacing; pos.y += size.height + style().spacing;
} }
} }
...@@ -70,7 +70,7 @@ class RealSize { ...@@ -70,7 +70,7 @@ class RealSize {
* #### + $$$ = ####$$$ * #### + $$$ = ####$$$
* #### ####... * #### ####...
*/ */
inline RealSize addHorizontal(const RealSize& a, const RealSize& b) { inline RealSize add_horizontal(const RealSize& a, const RealSize& b) {
return RealSize(a.width + b.width, max(a.height, b.height)); return RealSize(a.width + b.width, max(a.height, b.height));
} }
...@@ -81,7 +81,7 @@ inline RealSize addHorizontal(const RealSize& a, const RealSize& b) { ...@@ -81,7 +81,7 @@ inline RealSize addHorizontal(const RealSize& a, const RealSize& b) {
* $$$. * $$$.
* $$$. * $$$.
*/ */
inline RealSize addVertical(const RealSize& a, const RealSize& b) { inline RealSize add_vertical(const RealSize& a, const RealSize& b) {
return RealSize(max(a.width, b.width), a.height + b.height); return RealSize(max(a.width, b.width), a.height + b.height);
} }
...@@ -92,7 +92,7 @@ inline RealSize addVertical(const RealSize& a, const RealSize& b) { ...@@ -92,7 +92,7 @@ inline RealSize addVertical(const RealSize& a, const RealSize& b) {
* ....$$$ * ....$$$
* ....$$$ * ....$$$
*/ */
inline RealSize addDiagonal(const RealSize& a, const RealSize& b) { inline RealSize add_diagonal(const RealSize& a, const RealSize& b) {
return RealSize(a.width + b.width, a.height + b.height); return RealSize(a.width + b.width, a.height + b.height);
} }
......
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