Reader now warns about invalid UTF-8 files;

Fixed possible hang when reading multiline strings with incorrect indentation;
Warnings from reading are shown also in NewSetWindow;
Script parse errors get reported with the correct line number;

Added support for showing multiple choice fields as a single image;
Added 'line_below' to ChoiceField::Choice, for putting a line below menu items.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@420 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2007-06-12 19:35:24 +00:00
parent 27833003c8
commit 8b11433cbd
20 changed files with 318 additions and 86 deletions
+23 -7
View File
@@ -84,6 +84,7 @@ DropDownList::~DropDownList() {
void DropDownList::show(bool in_place, wxPoint pos) {
if (IsShown()) return;
onShow();
// find selection
selected_item = selection();
// width
@@ -248,6 +249,9 @@ void DropDownList::drawItem(DC& dc, int y, size_t item) {
dc.SetBrush (wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT));
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHTTEXT));
dc.DrawRectangle(marginW, y, (int)item_size.width, (int)item_size.height);
} else if (!itemEnabled(item)) {
// mix between foreground and background
dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_GRAYTEXT));
} else if (highlightItem(item)) {
// mix a color between selection and window
dc.SetBrush (lerp(wxSystemSettings::GetColour(wxSYS_COLOUR_HIGHLIGHT),
@@ -266,7 +270,7 @@ void DropDownList::drawItem(DC& dc, int y, size_t item) {
}
// draw line below
if (lineBelow(item)) {
dc.SetPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW));
dc.SetPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
dc.DrawLine(marginW, y + (int)item_size.height, marginW + (int)item_size.width, y + (int)item_size.height);
}
}
@@ -295,8 +299,10 @@ void DropDownList::onMotion(wxMouseEvent& ev) {
for (size_t i = 0 ; i < count ; ++i) {
int endY = startY + (int)item_size.height;
if (ev.GetY() >= startY && ev.GetY() < endY) {
selected_item = i;
showSubMenu(i, startY);
if (itemEnabled(i)) {
selected_item = i;
showSubMenu(i, startY);
}
Refresh(false);
return;
}
@@ -321,18 +327,27 @@ bool DropDownList::onCharInParent(wxKeyEvent& ev) {
// sub menu always takes keys
return open_sub_menu->onCharInParent(ev);
} else {
size_t old_sel = selected_item;
switch (k) {
case WXK_UP:
if (selected_item > 0) {
while (selected_item > 0) {
selected_item -= 1;
Refresh(false);
if (itemEnabled(selected_item)) {
Refresh(false);
return true;
}
}
selected_item = old_sel;
break;
case WXK_DOWN:
if (selected_item + 1 < itemCount()) {
while (selected_item + 1 < itemCount()) {
selected_item += 1;
Refresh(false);
if (itemEnabled(selected_item)) {
Refresh(false);
return true;
}
}
selected_item = old_sel;
break;
case WXK_RETURN:
if (!showSubMenu()) {
@@ -351,6 +366,7 @@ bool DropDownList::onCharInParent(wxKeyEvent& ev) {
size_t count = itemCount();
for (size_t i = 0 ; i < count ; ++i) {
size_t index = (si + i) % count;
if (!itemEnabled(index)) continue;
String c = itemText(index);
#ifdef UNICODE
if (!c.empty() && toUpper(c.GetChar(0)) == toUpper(ev.GetUnicodeKey())) {
+6
View File
@@ -40,6 +40,10 @@ class DropDownList : public wxPopupWindow {
bool onMouseInParent(wxMouseEvent&, bool open_in_place);
protected:
/// Prepare for showing the list
virtual void onShow() {}
// --------------------------------------------------- : Selection
static const size_t NO_SELECTION = (size_t)-1;
@@ -59,6 +63,8 @@ class DropDownList : public wxPopupWindow {
virtual bool lineBelow(size_t item) const { return false; }
/// Should the item be highlighted?
virtual bool highlightItem(size_t item) const { return false; }
/// Is the item enabled?
virtual bool itemEnabled(size_t item) const { return true; }
// An extra submenu that pops up from an item, or null if there is no popup menu
virtual DropDownList* submenu(size_t item) const { return nullptr; }
+8
View File
@@ -60,6 +60,7 @@ NewSetWindow::NewSetWindow(Window* parent)
void NewSetWindow::onGameSelect(wxCommandEvent&) {
wxBusyCursor wait;
GameP game = game_list->getSelection<Game>();
handle_pending_errors();
settings.default_game = game->name();
GameSettings& gs = settings.gameSettingsFor(*game);
stylesheet_list->showData<StyleSheet>(game->name() + _("-*"));
@@ -78,6 +79,7 @@ void NewSetWindow::onStyleSheetSelect(wxCommandEvent&) {
// store this as default selection
GameP game = game_list ->getSelection<Game>();
StyleSheetP stylesheet = stylesheet_list->getSelection<StyleSheet>();
handle_pending_errors();
GameSettings& gs = settings.gameSettingsFor(*game);
gs.default_stylesheet = stylesheet->name();
UpdateWindowUI(wxUPDATE_UI_RECURSE);
@@ -113,10 +115,16 @@ void NewSetWindow::onUpdateUI(wxUpdateUIEvent& ev) {
}
}
void NewSetWindow::onIdle(wxIdleEvent& ev) {
// Stuff that must be done in the main thread
handle_pending_errors();
}
BEGIN_EVENT_TABLE(NewSetWindow, wxDialog)
EVT_GALLERY_SELECT (ID_GAME_LIST, NewSetWindow::onGameSelect)
EVT_GALLERY_SELECT (ID_STYLESHEET_LIST, NewSetWindow::onStyleSheetSelect)
EVT_GALLERY_ACTIVATE(ID_STYLESHEET_LIST, NewSetWindow::onStyleSheetActivate)
EVT_BUTTON (wxID_OK, NewSetWindow::OnOK)
EVT_UPDATE_UI (wxID_ANY, NewSetWindow::onUpdateUI)
EVT_IDLE ( NewSetWindow::onIdle)
END_EVENT_TABLE ()
+2 -1
View File
@@ -42,10 +42,11 @@ class NewSetWindow : public wxDialog {
void onStyleSheetSelect (wxCommandEvent&);
void onStyleSheetActivate(wxCommandEvent&);
virtual void OnOK(wxCommandEvent&);
void onUpdateUI(wxUpdateUIEvent&);
void onIdle(wxIdleEvent&);
// we are done, close the window
void done();
+2 -2
View File
@@ -202,7 +202,7 @@ void draw_drop_down_arrow(Window* win, DC& dc, const wxRect& rect, bool active)
, active ? wxCONTROL_PRESSED : 0);
}
void draw_checkbox(Window* win, DC& dc, const wxRect& rect, bool checked) {
void draw_checkbox(Window* win, DC& dc, const wxRect& rect, bool checked, bool enabled) {
#if wxUSE_UXTHEME && defined(__WXMSW__)
// TODO: Windows version?
#endif
@@ -210,7 +210,7 @@ void draw_checkbox(Window* win, DC& dc, const wxRect& rect, bool checked) {
if (checked) {
dc.DrawCheckMark(wxRect(rect.x-1,rect.y-1,rect.width+2,rect.height+2));
}
dc.SetPen(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
dc.SetPen(wxSystemSettings::GetColour(enabled ? wxSYS_COLOUR_WINDOWTEXT: wxSYS_COLOUR_GRAYTEXT));
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(rect.x, rect.y, rect.width, rect.height);
}
+1 -1
View File
@@ -61,7 +61,7 @@ void draw_menu_arrow(Window* win, DC& dc, const wxRect& rect, bool active);
void draw_drop_down_arrow(Window* win, DC& dc, const wxRect& rect, bool active);
/// Draws a check box
void draw_checkbox(Window* win, DC& dc, const wxRect& rect, bool checked);
void draw_checkbox(Window* win, DC& dc, const wxRect& rect, bool checked, bool enabled = true);
// ----------------------------------------------------------------------------- : EOF
#endif
+19 -4
View File
@@ -106,6 +106,14 @@ DropDownChoiceListBase::DropDownChoiceListBase
item_size.height = max(16., item_size.height);
}
void DropDownChoiceListBase::onShow() {
// update 'enabled'
Context& ctx = cve.viewer.getContext();
FOR_EACH(c, group->choices) {
c->enabled.update(ctx);
}
}
size_t DropDownChoiceListBase::itemCount() const {
return group->choices.size() + hasDefault();
}
@@ -129,7 +137,10 @@ String DropDownChoiceListBase::itemText(size_t item) const {
}
}
bool DropDownChoiceListBase::lineBelow(size_t item) const {
return isDefault(item);
return isDefault(item) || getChoice(item)->line_below;
}
bool DropDownChoiceListBase::itemEnabled(size_t item) const {
return isDefault(item) || getChoice(item)->enabled;
}
DropDownList* DropDownChoiceListBase::submenu(size_t item) const {
if (isDefault(item)) return nullptr;
@@ -157,7 +168,7 @@ void DropDownChoiceListBase::drawIcon(DC& dc, int x, int y, size_t item, bool se
}
// draw image
if (image_id < il->GetImageCount()) {
il->Draw(image_id, dc, x, y);
il->Draw(image_id, dc, x, y, itemEnabled(item) ? wxIMAGELIST_DRAW_NORMAL : wxIMAGELIST_DRAW_TRANSPARENT);
}
}
@@ -196,6 +207,12 @@ DropDownChoiceList::DropDownChoiceList(Window* parent, bool is_submenu, ValueVie
: DropDownChoiceListBase(parent, is_submenu, cve, group)
{}
void DropDownChoiceList::onShow() {
DropDownChoiceListBase::onShow();
// we need thumbnail images soon
generateThumbnailImages();
}
void DropDownChoiceList::select(size_t item) {
if (isFieldDefault(item)) {
dynamic_cast<ChoiceValueEditor&>(cve).change( Defaultable<String>() );
@@ -206,8 +223,6 @@ void DropDownChoiceList::select(size_t item) {
}
size_t DropDownChoiceList::selection() const {
// we need thumbnail images soon
const_cast<DropDownChoiceList*>(this)->generateThumbnailImages();
// selected item
const Defaultable<String>& value = dynamic_cast<ChoiceValueEditor&>(cve).value().value();
int id = field().choices->choiceId(value);
+4 -1
View File
@@ -48,9 +48,11 @@ class DropDownChoiceListBase : public DropDownList {
public:
DropDownChoiceListBase(Window* parent, bool is_submenu, ValueViewer& cve, ChoiceField::ChoiceP group);
protected:
protected:
virtual void onShow();
virtual size_t itemCount() const;
virtual bool lineBelow(size_t item) const;
virtual bool itemEnabled(size_t item) const;
virtual String itemText(size_t item) const;
virtual void drawIcon(DC& dc, int x, int y, size_t item, bool selected) const;
virtual DropDownList* submenu(size_t item) const;
@@ -92,6 +94,7 @@ class DropDownChoiceList : public DropDownChoiceListBase {
DropDownChoiceList(Window* parent, bool is_submenu, ValueViewer& cve, ChoiceField::ChoiceP group);
protected:
virtual void onShow();
virtual void select(size_t item);
virtual size_t selection() const;
virtual DropDownList* createSubMenu(ChoiceField::ChoiceP group) const;
+8 -4
View File
@@ -33,27 +33,31 @@ DropDownMultipleChoiceList::DropDownMultipleChoiceList
}
void DropDownMultipleChoiceList::select(size_t item) {
MultipleChoiceValueEditor& mcve = dynamic_cast<MultipleChoiceValueEditor&>(cve);
if (isFieldDefault(item)) {
// should not happen
// make default
mcve.getSet().actions.add(value_action(mcve.valueP(), Defaultable<String>()));
} else {
ChoiceField::ChoiceP choice = getChoice(item);
dynamic_cast<MultipleChoiceValueEditor&>(cve).toggle(choice->first_id);
mcve.toggle(choice->first_id);
}
}
void DropDownMultipleChoiceList::drawIcon(DC& dc, int x, int y, size_t item, bool selected) const {
// is this item active?
// is this item active/checked?
bool active = false;
if (!isFieldDefault(item)) {
ChoiceField::ChoiceP choice = getChoice(item);
active = dynamic_cast<MultipleChoiceValueEditor&>(cve).active[choice->first_id];
} else {
active = dynamic_cast<MultipleChoiceValueEditor&>(cve).value().value.isDefault();
}
// draw checkbox
dc.SetPen(*wxTRANSPARENT_PEN);
dc.SetBrush(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW));
dc.DrawRectangle(x,y,16,16);
wxRect rect = RealRect(x+2,y+2,12,12);
draw_checkbox(nullptr, dc, rect, active);
draw_checkbox(nullptr, dc, rect, active, itemEnabled(item));
// draw icon
DropDownChoiceListBase::drawIcon(dc, x + 16, y, item, selected);
}