mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-10 04:57:00 -04:00
implemented clipboard handling for cards
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@83 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
+1
-1
@@ -9,7 +9,7 @@
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <util/string.hpp>
|
||||
#include <util/prec.hpp>
|
||||
#include <util/reflect.hpp>
|
||||
|
||||
class Game;
|
||||
|
||||
@@ -50,7 +50,7 @@ class ImageValue : public Value {
|
||||
public:
|
||||
inline ImageValue(const ImageFieldP& field) : Value(field) {}
|
||||
|
||||
String filename; ///< Filename of the image (in the current package), or ""
|
||||
FileName filename; ///< Filename of the image (in the current package), or ""
|
||||
|
||||
virtual String toString() const;
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ class SymbolValue : public Value {
|
||||
inline SymbolValue(const SymbolFieldP& field) : Value(field) {}
|
||||
DECLARE_HAS_FIELD(Symbol)
|
||||
|
||||
String filename; ///< Filename of the symbol (in the current package)
|
||||
FileName filename; ///< Filename of the symbol (in the current package)
|
||||
|
||||
virtual String toString() const;
|
||||
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
|
||||
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||
//+----------------------------------------------------------------------------+
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <data/format/formats.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
@@ -0,0 +1,83 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
|
||||
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||
//+----------------------------------------------------------------------------+
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <data/format/clipboard.hpp>
|
||||
#include <data/card.hpp>
|
||||
#include <data/set.hpp>
|
||||
#include <data/game.hpp>
|
||||
#include <util/io/package.hpp>
|
||||
#include <script/scriptable.hpp>
|
||||
#include <wx/sstream.h>
|
||||
|
||||
// ----------------------------------------------------------------------------- : Clipboard serialization
|
||||
|
||||
template <typename T>
|
||||
String serialize_for_clipboard(Package& package, T& object) {
|
||||
shared_ptr<wxStringOutputStream> stream( new wxStringOutputStream );
|
||||
Writer writer(stream);
|
||||
WITH_DYNAMIC_ARG(clipboard_package, &package);
|
||||
writer.handle(object);
|
||||
return stream->GetString();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void deserialize_from_clipboard(T& object, Package& package, const String& data) {
|
||||
shared_ptr<wxStringInputStream> stream( new wxStringInputStream(data) );
|
||||
Reader reader(stream, _("clipboard"));
|
||||
WITH_DYNAMIC_ARG(clipboard_package, &package);
|
||||
reader.handle(object);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : CardDataObject
|
||||
|
||||
/// A wrapped card for storing on the clipboard
|
||||
struct WrappedCard {
|
||||
String expected_game_name;
|
||||
String game_name;
|
||||
CardP card;
|
||||
|
||||
DECLARE_REFLECTION();
|
||||
};
|
||||
|
||||
IMPLEMENT_REFLECTION(WrappedCard) {
|
||||
if (game_name == expected_game_name) REFLECT(game_name);
|
||||
if (game_name == expected_game_name) REFLECT(card);
|
||||
}
|
||||
|
||||
|
||||
wxDataFormat CardDataObject::format = _("application/x-mse-card");
|
||||
|
||||
CardDataObject::CardDataObject(const SetP& set, const CardP& card) {
|
||||
WrappedCard data = { set->game->name(), set->game->name(), card };
|
||||
SetText(serialize_for_clipboard(*set, data));
|
||||
SetFormat(format);
|
||||
}
|
||||
|
||||
CardDataObject::CardDataObject() {
|
||||
SetFormat(format);
|
||||
}
|
||||
|
||||
CardP CardDataObject::getCard(const SetP& set) {
|
||||
CardP card(new Card(*set->game));
|
||||
WrappedCard data = { set->game->name(), set->game->name(), card};
|
||||
deserialize_from_clipboard(data, *set, GetText());
|
||||
if (data.game_name != set->game->name()) return CardP(); // Card is from a different game
|
||||
else return card;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Card on clipboard
|
||||
|
||||
CardOnClipboard::CardOnClipboard(const SetP& set, const CardP& card) {
|
||||
// Conversion to text format
|
||||
// TODO
|
||||
//Add( new TextDataObject(_("card")))
|
||||
// Conversion to bitmap format
|
||||
// Add(new BitmapDataObject(exportImageBmp(set, card)));
|
||||
// Conversion to serialized card format
|
||||
Add(new CardDataObject(set, card), true);
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
|
||||
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||
//+----------------------------------------------------------------------------+
|
||||
|
||||
#ifndef HEADER_DATA_FORMAT_CLIPBOARD
|
||||
#define HEADER_DATA_FORMAT_CLIPBOARD
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <util/prec.hpp>
|
||||
#include <wx/dataobj.h>
|
||||
|
||||
DECLARE_POINTER_TYPE(Set);
|
||||
DECLARE_POINTER_TYPE(Card);
|
||||
|
||||
// ----------------------------------------------------------------------------- : CardDataObject
|
||||
|
||||
/// The data format for cards on the clipboard
|
||||
class CardDataObject : public wxTextDataObject {
|
||||
public:
|
||||
/// Name of the format of MSE cards
|
||||
static wxDataFormat format;
|
||||
|
||||
CardDataObject();
|
||||
/// Store a card
|
||||
CardDataObject(const SetP& set, const CardP& card);
|
||||
|
||||
/// Retrieve a card, only if it is made with the same game as set
|
||||
CardP getCard(const SetP& set);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : Card on clipboard
|
||||
|
||||
/// A DataObject for putting a card on the clipboard, in multiple formats
|
||||
class CardOnClipboard : public wxDataObjectComposite {
|
||||
public:
|
||||
CardOnClipboard(const SetP& set, const CardP& card);
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
|
||||
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||
//+----------------------------------------------------------------------------+
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <data/format/formats.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
@@ -0,0 +1,11 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
|
||||
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||
//+----------------------------------------------------------------------------+
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <data/format/formats.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
@@ -0,0 +1,11 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
|
||||
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||
//+----------------------------------------------------------------------------+
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <data/format/formats.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
@@ -0,0 +1,11 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
|
||||
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||
//+----------------------------------------------------------------------------+
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <data/format/formats.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
@@ -0,0 +1,11 @@
|
||||
//+----------------------------------------------------------------------------+
|
||||
//| Description: Magic Set Editor - Program to make Magic (tm) cards |
|
||||
//| Copyright: (C) 2001 - 2006 Twan van Laarhoven |
|
||||
//| License: GNU General Public License 2 or later (see file COPYING) |
|
||||
//+----------------------------------------------------------------------------+
|
||||
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <data/format/formats.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- :
|
||||
+1
-1
@@ -63,5 +63,5 @@ void Reader::handle(GameP& game) {
|
||||
game = Game::byName(value);
|
||||
}
|
||||
void Writer::handle(const GameP& game) {
|
||||
handle(game->name());
|
||||
if (game) handle(game->name());
|
||||
}
|
||||
|
||||
@@ -92,5 +92,5 @@ void Reader::handle(StyleSheetP& stylesheet) {
|
||||
stylesheet = StyleSheet::byGameAndName(*game_for_reading(), value);
|
||||
}
|
||||
void Writer::handle(const StyleSheetP& stylesheet) {
|
||||
handle(stylesheet->name());
|
||||
if (stylesheet) handle(stylesheet->name());
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class AboutWindow : public wxDialog {
|
||||
// graphics
|
||||
Bitmap logo, logo2;
|
||||
|
||||
void onPaint(wxPaintEvent& e);
|
||||
void onPaint(wxPaintEvent&);
|
||||
void draw(DC& dc);
|
||||
};
|
||||
|
||||
|
||||
@@ -83,7 +83,7 @@ class DataEditor : public CardViewer {
|
||||
void onChar (wxKeyEvent&);
|
||||
|
||||
void onContextMenu(wxContextMenuEvent&);
|
||||
void onMenu (wxCommandEvent& e);
|
||||
void onMenu (wxCommandEvent&);
|
||||
|
||||
void onFocus (wxFocusEvent&);
|
||||
void onLoseFocus(wxFocusEvent&);
|
||||
@@ -96,7 +96,7 @@ class DataEditor : public CardViewer {
|
||||
// selectField, but don't send events
|
||||
void selectFieldNoEvents(const RealPoint& pos);
|
||||
/// Convert mouse coordinates to internal coordinates
|
||||
RealPoint mousePoint(const wxMouseEvent& e);
|
||||
RealPoint mousePoint(const wxMouseEvent&);
|
||||
|
||||
// Create tab index ordering of the (editable) viewers
|
||||
void createTabIndex();
|
||||
|
||||
@@ -14,8 +14,10 @@
|
||||
#include <data/set.hpp>
|
||||
#include <data/card.hpp>
|
||||
#include <data/settings.hpp>
|
||||
#include <data/format/clipboard.hpp>
|
||||
#include <data/action/set.hpp>
|
||||
#include <util/window_id.hpp>
|
||||
#include <wx/clipbrd.h>
|
||||
|
||||
DECLARE_TYPEOF_COLLECTION(CardP);
|
||||
DECLARE_TYPEOF_COLLECTION(FieldP);
|
||||
@@ -165,6 +167,41 @@ void CardListBase::selectCurrentCard() {
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : CardListBase : Clipboard
|
||||
|
||||
bool CardListBase::canCopy() const { return !!selected_card; }
|
||||
bool CardListBase::canCut() const { return canCopy() && allowModify(); }
|
||||
bool CardListBase::canPaste() const {
|
||||
return wxTheClipboard->IsSupported(CardDataObject::format);
|
||||
}
|
||||
|
||||
void CardListBase::doCopy() {
|
||||
if (!canCopy()) return;
|
||||
if (!wxTheClipboard->Open()) return;
|
||||
wxTheClipboard->SetData(new CardOnClipboard(set, selected_card)); // ignore result
|
||||
wxTheClipboard->Close();
|
||||
}
|
||||
void CardListBase::doCut() {
|
||||
// cut = copy + delete
|
||||
if (!canCut()) return;
|
||||
doCopy();
|
||||
set->actions.add(new RemoveCardAction(*set, selected_card) );
|
||||
}
|
||||
void CardListBase::doPaste() {
|
||||
// get data
|
||||
if (!canPaste()) return;
|
||||
if (!wxTheClipboard->Open()) return;
|
||||
CardDataObject data;
|
||||
bool ok = wxTheClipboard->GetData(data);
|
||||
wxTheClipboard->Close();
|
||||
if (!ok) return;
|
||||
// add card to set
|
||||
CardP card = data.getCard(set);
|
||||
if (card) {
|
||||
set->actions.add(new AddCardAction(*set, card));
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : CardListBase : Building the list
|
||||
|
||||
// Comparison object for comparing cards
|
||||
@@ -356,7 +393,7 @@ void CardListBase::onItemFocus(wxListEvent& ev) {
|
||||
}
|
||||
|
||||
void CardListBase::onChar(wxKeyEvent& ev) {
|
||||
if (ev.GetKeyCode() == WXK_DELETE) {
|
||||
if (ev.GetKeyCode() == WXK_DELETE && allowModify()) {
|
||||
set->actions.add(new RemoveCardAction(*set, selected_card));
|
||||
} else if (ev.GetKeyCode() == WXK_TAB) {
|
||||
// send a navigation event to our parent, to select another control
|
||||
|
||||
@@ -88,6 +88,8 @@ class CardListBase : public wxListView, public SetView {
|
||||
void rebuild();
|
||||
/// Do some additional updating before rebuilding the list
|
||||
virtual void onRebuild() {}
|
||||
/// Can the card list be modified?
|
||||
virtual bool allowModify() const { return true; }
|
||||
|
||||
// --------------------------------------------------- : Item 'events'
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ class FilteredCardList : public CardListBase {
|
||||
/// Rebuild the filtered card list
|
||||
virtual void onRebuild();
|
||||
// /// Don't reorder
|
||||
// virtual void onDrag(wxMouseEvent& e);
|
||||
// virtual void onDrag(wxMouseEvent& ev);
|
||||
|
||||
private:
|
||||
CardListFilterP filter; ///< Filter with which this.cards is made
|
||||
|
||||
@@ -73,8 +73,8 @@ wxSize NativeLookEditor::DoGetBestSize() const {
|
||||
return wxSize(200, 200);
|
||||
}
|
||||
void NativeLookEditor::onSize(wxSizeEvent& ev) {
|
||||
// CardViewre::onSize(ev);
|
||||
resizeViewers();
|
||||
Refresh(false);
|
||||
}
|
||||
|
||||
BEGIN_EVENT_TABLE(NativeLookEditor, DataEditor)
|
||||
|
||||
+36
-21
@@ -10,6 +10,7 @@
|
||||
#include <gui/control/card_list.hpp>
|
||||
#include <gui/control/card_editor.hpp>
|
||||
#include <gui/icon_menu.hpp>
|
||||
#include <gui/util.hpp>
|
||||
#include <data/set.hpp>
|
||||
#include <data/action/set.hpp>
|
||||
#include <data/settings.hpp>
|
||||
@@ -119,25 +120,25 @@ void CardsPanel::destroyUI(wxToolBar* tb, wxMenuBar* mb) {
|
||||
delete mb->Remove(2);
|
||||
}
|
||||
|
||||
void CardsPanel::onUpdateUI(wxUpdateUIEvent& e) {
|
||||
switch (e.GetId()) {
|
||||
case ID_CARD_PREV: e.Enable(card_list->canSelectPrevious()); break;
|
||||
case ID_CARD_NEXT: e.Enable(card_list->canSelectNext()); break;
|
||||
/* case ID_CARD_ROTATE_0: e.Check(editor->rotation.angle == 0); break;
|
||||
case ID_CARD_ROTATE_90: e.Check(editor->rotation.angle == 90); break;
|
||||
case ID_CARD_ROTATE_180: e.Check(editor->rotation.angle == 180); break;
|
||||
case ID_CARD_ROTATE_270: e.Check(editor->rotation.angle == 270); break;
|
||||
case ID_CARD_REMOVE: e.Enable(set->cards.size() > 0); break;
|
||||
case ID_FORMAT_BOLD: case ID_FORMAT_ITALIC: case ID_FORMAT_SYMBOL: {
|
||||
if (focusedControl() == idEditor) {
|
||||
e.Enable(editor->canFormat(e.id));
|
||||
e.Check (editor->hasFormat(e.id));
|
||||
void CardsPanel::onUpdateUI(wxUpdateUIEvent& ev) {
|
||||
switch (ev.GetId()) {
|
||||
case ID_CARD_PREV: ev.Enable(card_list->canSelectPrevious()); break;
|
||||
case ID_CARD_NEXT: ev.Enable(card_list->canSelectNext()); break;
|
||||
/* case ID_CARD_ROTATE_0: ev.Check(editor->rotation.angle == 0); break;
|
||||
case ID_CARD_ROTATE_90: ev.Check(editor->rotation.angle == 90); break;
|
||||
case ID_CARD_ROTATE_180: ev.Check(editor->rotation.angle == 180); break;
|
||||
case ID_CARD_ROTATE_270: ev.Check(editor->rotation.angle == 270); break;*/
|
||||
case ID_CARD_REMOVE: ev.Enable(set->cards.size() > 0); break;
|
||||
case ID_FORMAT_BOLD: case ID_FORMAT_ITALIC: case ID_FORMAT_SYMBOL: case ID_FORMAT_REMINDER: {
|
||||
if (focused_control(this) == ID_EDITOR) {
|
||||
ev.Enable(editor->canFormat(ev.GetId()));
|
||||
ev.Check (editor->hasFormat(ev.GetId()));
|
||||
} else {
|
||||
e.Enable(false);
|
||||
e.Check(false);
|
||||
ev.Enable(false);
|
||||
ev.Check(false);
|
||||
}
|
||||
break;
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -159,35 +160,41 @@ void CardsPanel::onCommand(int id) {
|
||||
StyleSettings& ss = settings.styleSettingsFor(*editor->style);
|
||||
ss.cardAngle = (ss.cardAngle + 90) % 360;
|
||||
onRenderSettingsChange();
|
||||
break;
|
||||
}
|
||||
case idCardRotate0 {
|
||||
StyleSettings& ss = settings.styleSettingsFor(*editor->style);
|
||||
ss.cardAngle = 0;
|
||||
onRenderSettingsChange();
|
||||
break;
|
||||
}
|
||||
case idCardRotate90 {
|
||||
StyleSettings& ss = settings.styleSettingsFor(*editor->style);
|
||||
ss.cardAngle = 90;
|
||||
onRenderSettingsChange();
|
||||
break;
|
||||
}
|
||||
case idCardRotate180 {
|
||||
StyleSettings& ss = settings.styleSettingsFor(*editor->style);
|
||||
ss.cardAngle = 180;
|
||||
onRenderSettingsChange();
|
||||
break;
|
||||
}
|
||||
case idCardRotate270 {
|
||||
StyleSettings& ss = settings.styleSettingsFor(*editor->style);
|
||||
ss.cardAngle = 270;
|
||||
onRenderSettingsChange();
|
||||
break;
|
||||
}
|
||||
case idSelectColumns {
|
||||
cardList->selectColumns();
|
||||
}
|
||||
case idFormatBold, idFormatItalic, idFormatSymbol, idFormatNoAuto {
|
||||
if (focusedControl() == idEditor) {
|
||||
editor->doFormat(id);
|
||||
}
|
||||
}*/
|
||||
case ID_FORMAT_BOLD: case ID_FORMAT_ITALIC: case ID_FORMAT_SYMBOL: case ID_FORMAT_REMINDER: {
|
||||
if (focused_control(this) == ID_EDITOR) {
|
||||
editor->doFormat(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -205,6 +212,14 @@ void CardsPanel::onRenderSettingsChange() {
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Clipboard
|
||||
|
||||
bool CardsPanel::canCut() const { return focused_control(this) == ID_EDITOR ? editor->canCut() : card_list->canCut(); }
|
||||
bool CardsPanel::canCopy() const { return focused_control(this) == ID_EDITOR ? editor->canCopy() : card_list->canCopy(); }
|
||||
bool CardsPanel::canPaste() const { return focused_control(this) == ID_EDITOR ? editor->canPaste() : card_list->canPaste(); }
|
||||
void CardsPanel::doCut() { if (focused_control(this) == ID_EDITOR) editor->doCut(); else card_list->doCut(); }
|
||||
void CardsPanel::doCopy() { if (focused_control(this) == ID_EDITOR) editor->doCopy(); else card_list->doCopy(); }
|
||||
void CardsPanel::doPaste() { if (focused_control(this) == ID_EDITOR) editor->doPaste(); else card_list->doPaste(); }
|
||||
|
||||
// ----------------------------------------------------------------------------- : Searching
|
||||
|
||||
// ----------------------------------------------------------------------------- : Selection
|
||||
|
||||
@@ -30,7 +30,7 @@ class CardsPanel : public SetWindowPanel {
|
||||
|
||||
virtual void initUI (wxToolBar* tb, wxMenuBar* mb);
|
||||
virtual void destroyUI(wxToolBar* tb, wxMenuBar* mb);
|
||||
virtual void onUpdateUI(wxUpdateUIEvent& e);
|
||||
virtual void onUpdateUI(wxUpdateUIEvent&);
|
||||
virtual void onCommand(int id);
|
||||
|
||||
// --------------------------------------------------- : Actions
|
||||
@@ -41,7 +41,7 @@ class CardsPanel : public SetWindowPanel {
|
||||
public:
|
||||
|
||||
// --------------------------------------------------- : Clipboard
|
||||
/* virtual bool canCut() const;
|
||||
virtual bool canCut() const;
|
||||
virtual bool canCopy() const;
|
||||
virtual bool canPaste() const;
|
||||
virtual void doCut();
|
||||
@@ -49,7 +49,7 @@ class CardsPanel : public SetWindowPanel {
|
||||
virtual void doPaste();
|
||||
|
||||
// --------------------------------------------------- : Searching (find/replace)
|
||||
virtual bool canFind() const;
|
||||
/* virtual bool canFind() const;
|
||||
virtual bool canReplace() const;
|
||||
virtual bool doFind(wxFindReplaceData& what);
|
||||
virtual bool doReplace(wxFindReplaceData& what);
|
||||
|
||||
+1
-17
@@ -39,7 +39,7 @@ class SetWindowPanel : public wxPanel, public SetView {
|
||||
/// Update the UI by enabling/disabling items.
|
||||
/** Note: copy/paste and find/replace are not handled here.
|
||||
*/
|
||||
virtual void onUpdateUI(wxUpdateUIEvent& e) {}
|
||||
virtual void onUpdateUI(wxUpdateUIEvent&) {}
|
||||
/// Respond to one of those extra menu/tool items
|
||||
virtual void onCommand(int id) {}
|
||||
|
||||
@@ -69,22 +69,6 @@ class SetWindowPanel : public wxPanel, public SetView {
|
||||
// --------------------------------------------------- : Selection
|
||||
virtual CardP selectedCard() const { return CardP(); } ///< Return the currently selected card, or CardP()
|
||||
virtual void selectCard(const CardP& card) {} ///< Switch the view to another card
|
||||
|
||||
protected:
|
||||
// --------------------------------------------------- : Helper functions for UI
|
||||
/// Enable/disable a tool or menu item
|
||||
// void enable(wxToolBar* tb, wxMenuBar* mb, int id, bool enable);
|
||||
// mb->Enable(id, enable)
|
||||
// tb->EnableTool(id, enable)
|
||||
|
||||
/// Id of the control that has the focus, or -1 if no control has the focus
|
||||
int focusedControl();
|
||||
// Window* focusedWindow = findFocus()
|
||||
// // is this window actually inside this panel?
|
||||
// if focusedWindow && findWindowById(focusedWindow->id, &this) == focusedWindow
|
||||
// return focusedWindow->id
|
||||
// else
|
||||
// return -1 // no window has the focus, or it has a different parent/ancestor
|
||||
};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
|
||||
@@ -55,11 +55,11 @@ void SetInfoPanel::destroyUI(wxToolBar* tb, wxMenuBar* mb) {
|
||||
delete mb->Remove(2);
|
||||
}
|
||||
|
||||
void SetInfoPanel::onUpdateUI(wxUpdateUIEvent& e) {
|
||||
switch (e.GetId()) {
|
||||
void SetInfoPanel::onUpdateUI(wxUpdateUIEvent& ev) {
|
||||
switch (ev.GetId()) {
|
||||
case ID_FORMAT_BOLD: case ID_FORMAT_ITALIC: case ID_FORMAT_SYMBOL: {
|
||||
e.Enable(editor->canFormat(e.GetId()));
|
||||
e.Check (editor->hasFormat(e.GetId()));
|
||||
ev.Enable(editor->canFormat(ev.GetId()));
|
||||
ev.Check (editor->hasFormat(ev.GetId()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -69,6 +69,7 @@ void SetInfoPanel::onCommand(int id) {
|
||||
switch (id) {
|
||||
case ID_FORMAT_BOLD: case ID_FORMAT_ITALIC: case ID_FORMAT_SYMBOL: {
|
||||
editor->doFormat(id);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ class SetInfoPanel : public SetWindowPanel {
|
||||
|
||||
virtual void initUI (wxToolBar* tb, wxMenuBar* mb);
|
||||
virtual void destroyUI(wxToolBar* tb, wxMenuBar* mb);
|
||||
virtual void onUpdateUI(wxUpdateUIEvent& e);
|
||||
virtual void onUpdateUI(wxUpdateUIEvent&);
|
||||
virtual void onCommand(int id);
|
||||
|
||||
// --------------------------------------------------- : Clipboard
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <gui/control/graph.hpp>
|
||||
#include <gui/control/gallery_list.hpp>
|
||||
#include <gui/control/filtered_card_list.hpp>
|
||||
#include <util/window_id.hpp>
|
||||
#include <wx/splitter.h>
|
||||
|
||||
// ----------------------------------------------------------------------------- : StatFieldList
|
||||
@@ -43,7 +44,7 @@ StatsPanel::StatsPanel(Window* parent, int id)
|
||||
{
|
||||
// init controls
|
||||
wxSplitterWindow* splitter;
|
||||
fields = new StatFieldList (this, wxID_ANY);
|
||||
fields = new StatFieldList (this, ID_FIELD_LIST);
|
||||
splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, 0);
|
||||
graph = new GraphControl (splitter, wxID_ANY);
|
||||
card_list = new FilteredCardList(splitter, wxID_ANY);
|
||||
@@ -58,3 +59,25 @@ StatsPanel::StatsPanel(Window* parent, int id)
|
||||
s->SetSizeHints(this);
|
||||
SetSizer(s);
|
||||
}
|
||||
|
||||
void StatsPanel::onChangeSet() {
|
||||
card_list->setSet(set);
|
||||
}
|
||||
|
||||
void StatsPanel::onCommand(int id) {
|
||||
switch (id) {
|
||||
case ID_FIELD_LIST: {
|
||||
// change graph data
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Selection
|
||||
|
||||
CardP StatsPanel::selectedCard() const {
|
||||
return card_list->getCard();
|
||||
}
|
||||
void StatsPanel::selectCard(const CardP& card) {
|
||||
card_list->setCard(card);
|
||||
}
|
||||
|
||||
@@ -22,9 +22,16 @@ class StatsPanel : public SetWindowPanel {
|
||||
public:
|
||||
StatsPanel(Window* parent, int id);
|
||||
|
||||
// virtual void onUpdateUI(wxUpdateUIEvent& e);
|
||||
// virtual void onCommand(int id);
|
||||
// --------------------------------------------------- : UI
|
||||
|
||||
virtual void onChangeSet();
|
||||
virtual void onCommand(int id);
|
||||
|
||||
// --------------------------------------------------- : Selection
|
||||
virtual CardP selectedCard() const;
|
||||
virtual void selectCard(const CardP& card);
|
||||
|
||||
// --------------------------------------------------- : Data
|
||||
private:
|
||||
StatFieldList* fields;
|
||||
GraphControl* graph;
|
||||
|
||||
@@ -29,7 +29,7 @@ class SymbolBasicShapeEditor : public SymbolEditorBase {
|
||||
|
||||
virtual void initUI (wxToolBar* tb, wxMenuBar* mb);
|
||||
virtual void destroyUI(wxToolBar* tb, wxMenuBar* mb);
|
||||
virtual void onUpdateUI(wxUpdateUIEvent& e);
|
||||
virtual void onUpdateUI(wxUpdateUIEvent&);
|
||||
virtual void onCommand(int id);
|
||||
virtual int modeToolId();
|
||||
|
||||
|
||||
@@ -140,7 +140,7 @@ void SymbolControl::draw(DC& dc) {
|
||||
editor->draw(dc);
|
||||
}
|
||||
}
|
||||
void SymbolControl::onPaint(wxPaintEvent& e) {
|
||||
void SymbolControl::onPaint(wxPaintEvent&) {
|
||||
wxBufferedPaintDC dc(this);
|
||||
dc.BeginDrawing();
|
||||
draw(dc);
|
||||
|
||||
@@ -92,7 +92,7 @@ class SymbolControl : public wxControl, public SymbolViewer {
|
||||
void onRightDown (wxMouseEvent& ev);
|
||||
void onMotion (wxMouseEvent& ev);
|
||||
|
||||
void onPaint (wxPaintEvent& e);
|
||||
void onPaint (wxPaintEvent& ev);
|
||||
void onKeyChange(wxKeyEvent& ev);
|
||||
void onChar (wxKeyEvent& ev);
|
||||
void onSize (wxSizeEvent& ev);
|
||||
|
||||
@@ -59,7 +59,7 @@ class SymbolPointEditor : public SymbolEditorBase {
|
||||
|
||||
virtual void initUI (wxToolBar* tb, wxMenuBar* mb);
|
||||
virtual void destroyUI(wxToolBar* tb, wxMenuBar* mb);
|
||||
virtual void onUpdateUI(wxUpdateUIEvent& e);
|
||||
virtual void onUpdateUI(wxUpdateUIEvent&);
|
||||
virtual void onCommand(int id);
|
||||
virtual int modeToolId();
|
||||
|
||||
|
||||
@@ -225,7 +225,7 @@ void SymbolSelectEditor::onLeftDClick(const Vector2D& pos, wxMouseEvent& ev) {
|
||||
}
|
||||
}
|
||||
|
||||
void SymbolSelectEditor::onMouseMove (const Vector2D& from, const Vector2D& to, wxMouseEvent& e) {
|
||||
void SymbolSelectEditor::onMouseMove (const Vector2D& from, const Vector2D& to, wxMouseEvent& ev) {
|
||||
// can we highlight a part?
|
||||
highlightPart = findPart(to);
|
||||
// are we on a handle?
|
||||
|
||||
@@ -42,7 +42,7 @@ class SymbolSelectEditor : public SymbolEditorBase {
|
||||
|
||||
virtual void initUI (wxToolBar* tb, wxMenuBar* mb);
|
||||
virtual void destroyUI(wxToolBar* tb, wxMenuBar* mb);
|
||||
virtual void onUpdateUI(wxUpdateUIEvent& e);
|
||||
virtual void onUpdateUI(wxUpdateUIEvent&);
|
||||
virtual void onCommand(int id);
|
||||
virtual int modeToolId();
|
||||
|
||||
|
||||
@@ -58,7 +58,7 @@ class SymbolWindow : public Frame {
|
||||
void onModeChange(wxCommandEvent&);
|
||||
void onExtraTool (wxCommandEvent&);
|
||||
|
||||
void onUpdateUI(wxUpdateUIEvent& e);
|
||||
void onUpdateUI(wxUpdateUIEvent&);
|
||||
|
||||
/// Changing selected parts in the list
|
||||
void onSelectFromList(wxListEvent& ev);
|
||||
|
||||
@@ -17,6 +17,19 @@
|
||||
#include <shlobj.h>
|
||||
#endif
|
||||
|
||||
// ----------------------------------------------------------------------------- : Window related
|
||||
|
||||
// Id of the control that has the focus, or -1 if no control has the focus
|
||||
int focused_control(const Window* window) {
|
||||
Window* focused_window = wxWindow::FindFocus();
|
||||
// is this window actually inside this panel?
|
||||
if (focused_window && wxWindow::FindWindowById(focused_window->GetId(), window) == focused_window) {
|
||||
return focused_window->GetId();
|
||||
} else {
|
||||
return -1; // no window has the focus, or it has a different parent/ancestor
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : DC related
|
||||
|
||||
/// Fill a DC with a single color
|
||||
|
||||
@@ -18,6 +18,11 @@
|
||||
class RotatedDC;
|
||||
class RealRect;
|
||||
|
||||
// ----------------------------------------------------------------------------- : Window related
|
||||
|
||||
/// Id of the control that has the focus in the given window, or -1 if no control has the focus
|
||||
int focused_control(const Window* window);
|
||||
|
||||
// ----------------------------------------------------------------------------- : DC related
|
||||
|
||||
/// Fill a DC with a single color
|
||||
|
||||
@@ -46,7 +46,7 @@ WelcomeWindow::WelcomeWindow()
|
||||
SetSizer(s1);
|
||||
}
|
||||
|
||||
void WelcomeWindow::onPaint(wxPaintEvent& e) {
|
||||
void WelcomeWindow::onPaint(wxPaintEvent&) {
|
||||
wxBufferedPaintDC dc(this);
|
||||
dc.BeginDrawing();
|
||||
draw(dc);
|
||||
|
||||
@@ -34,7 +34,7 @@ class WelcomeWindow : public Frame {
|
||||
// MSE logos
|
||||
Bitmap logo, logo2;
|
||||
|
||||
void onPaint(wxPaintEvent& e);
|
||||
void onPaint(wxPaintEvent&);
|
||||
void draw(DC& dc);
|
||||
|
||||
void onOpenSet (wxCommandEvent&);
|
||||
|
||||
@@ -955,6 +955,12 @@
|
||||
<File
|
||||
RelativePath=".\data\format\apprentice.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\data\format\clipboard.cpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\data\format\clipboard.hpp">
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\data\format\formats.cpp">
|
||||
</File>
|
||||
|
||||
@@ -60,6 +60,7 @@ Context& DataViewer::getContext() const { return set->getContext(); }
|
||||
// ----------------------------------------------------------------------------- : Setting data
|
||||
|
||||
void DataViewer::setCard(const CardP& card) {
|
||||
if (!card) return; // TODO: clear editor?
|
||||
assert(set);
|
||||
this->card = card;
|
||||
setStyles(set->stylesheet->card_style);
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
|
||||
template <> void GetDefaultMember::handle(const Char* const& v) { value = toScript(v); }
|
||||
template <> void GetDefaultMember::handle(const String& v) { value = toScript(v); }
|
||||
template <> void GetDefaultMember::handle(const FileName& v) { value = toScript(v); }
|
||||
template <> void GetDefaultMember::handle(const int& v) { value = toScript(v); }
|
||||
template <> void GetDefaultMember::handle(const unsigned int& v) { value = toScript((int)v); }
|
||||
template <> void GetDefaultMember::handle(const double& v) { value = toScript(v); }
|
||||
|
||||
@@ -18,6 +18,9 @@ DECLARE_TYPEOF(Package::FileInfos);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Package : outside
|
||||
|
||||
IMPLEMENT_DYNAMIC_ARG(Package*, writing_package, nullptr);
|
||||
IMPLEMENT_DYNAMIC_ARG(Package*, clipboard_package, nullptr);
|
||||
|
||||
Package::Package()
|
||||
: zipStream (nullptr)
|
||||
, fileStream(nullptr)
|
||||
@@ -219,6 +222,13 @@ String Package::newFileName(const String& prefix, const String& suffix) {
|
||||
}
|
||||
}
|
||||
|
||||
void Package::referenceFile(const String& file) {
|
||||
if (file.empty()) return;
|
||||
FileInfos::iterator it = files.find(file);
|
||||
if (it == files.end()) throw InternalError(_("referencing a nonexistant file"));
|
||||
it->second.keep = true;
|
||||
}
|
||||
|
||||
String Package::absoluteName(const String& file) {
|
||||
assert(wxThread::IsMain());
|
||||
FileInfos::iterator it = files.find(toStandardName(file));
|
||||
@@ -236,6 +246,21 @@ String Package::absoluteName(const String& file) {
|
||||
return filename+_("\1")+file;
|
||||
}
|
||||
}
|
||||
// Open a file that is in some package
|
||||
InputStreamP Package::openAbsoluteFile(const String& name) {
|
||||
size_t pos = name.find_first_of(_('\1'));
|
||||
if (pos == String::npos) {
|
||||
// temp or dir file
|
||||
shared_ptr<wxFileInputStream> f = new_shared1<wxFileInputStream>(name);
|
||||
if (!f->IsOk()) throw FileNotFoundError(_("<unknown>"), name);
|
||||
return f;
|
||||
} else {
|
||||
// packaged file, always in zip format
|
||||
Package p;
|
||||
p.open(name.substr(0, pos));
|
||||
return p.openIn( name.substr(pos + 1));
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Package : private
|
||||
|
||||
|
||||
@@ -10,11 +10,18 @@
|
||||
// ----------------------------------------------------------------------------- : Includes
|
||||
|
||||
#include <util/reflect.hpp>
|
||||
#include <util/dynamic_arg.hpp>
|
||||
|
||||
class Package;
|
||||
class wxFileInputStream;
|
||||
class wxZipInputStream;
|
||||
class wxZipEntry;
|
||||
|
||||
/// The package that is currently being written to
|
||||
DECLARE_DYNAMIC_ARG(Package*, writing_package);
|
||||
/// The package that is being put onto/read from the clipboard
|
||||
DECLARE_DYNAMIC_ARG(Package*, clipboard_package);
|
||||
|
||||
// ----------------------------------------------------------------------------- : Package
|
||||
|
||||
/// A package is a container for files. On disk it is either a directory or a zip file.
|
||||
|
||||
+22
-1
@@ -190,7 +190,6 @@ template <> void Reader::handle(double& d) {
|
||||
template <> void Reader::handle(bool& b) {
|
||||
b = (value==_("true") || value==_("1") || value==_("yes"));
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------- : Handling less basic util types
|
||||
|
||||
template <> void Reader::handle(Vector2D& vec) {
|
||||
@@ -205,3 +204,25 @@ template <> void Reader::handle(Color& col) {
|
||||
col.Set(r, g, b);
|
||||
}
|
||||
}
|
||||
|
||||
template <> void Reader::handle(FileName& f) {
|
||||
if (clipboard_package()) {
|
||||
String str; handle(str);
|
||||
if (!str.empty()) {
|
||||
// copy file into current package
|
||||
try {
|
||||
String packaged_name = clipboard_package()->newFileName(_("image"),_("")); // a new unique name in the package, assume it's an image
|
||||
OutputStreamP out = clipboard_package()->openOut(packaged_name);
|
||||
InputStreamP in = Package::openAbsoluteFile(str);
|
||||
out->Write(*in); // copy
|
||||
f.assign(packaged_name);
|
||||
} catch (Error) {
|
||||
// ignore errors
|
||||
}
|
||||
} else {
|
||||
f.assign(str);
|
||||
}
|
||||
} else {
|
||||
handle(static_cast<String&>(f));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <util/vector2d.hpp>
|
||||
#include <util/error.hpp>
|
||||
#include <util/version.hpp>
|
||||
#include <util/io/package.hpp>
|
||||
|
||||
// ----------------------------------------------------------------------------- : Writer
|
||||
|
||||
@@ -115,3 +116,19 @@ template <> void Writer::handle(const Vector2D& vec) {
|
||||
template <> void Writer::handle(const Color& col) {
|
||||
handle(String::Format(_("rgb(%u,%u,%u)"), col.Red(), col.Green(), col.Blue()));
|
||||
}
|
||||
|
||||
template <> void Writer::handle(const FileName& value) {
|
||||
if (clipboard_package() && !value.empty()) {
|
||||
// use absolute names on clipboard
|
||||
try {
|
||||
handle(clipboard_package()->absoluteName(value));
|
||||
} catch (const Error&) {
|
||||
// ignore errors
|
||||
}
|
||||
} else {
|
||||
handle(static_cast<const String&>(value));
|
||||
if (writing_package()) {
|
||||
writing_package()->referenceFile(value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -65,5 +65,8 @@ typedef unsigned int UInt;
|
||||
/// Null pointer
|
||||
#define nullptr 0
|
||||
|
||||
/// A string standing for a filename, has different behaviour when reading/writing
|
||||
class FileName : public String {};
|
||||
|
||||
// ----------------------------------------------------------------------------- : EOF
|
||||
#endif
|
||||
|
||||
@@ -138,6 +138,9 @@ enum ChildMenuID {
|
||||
|
||||
// CardList
|
||||
, ID_SELECT_COLUMNS = 3001
|
||||
|
||||
// Statistics
|
||||
, ID_FIELD_LIST = 3101
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user