Generated packs can now be selected for printing.

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1107 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2008-08-08 21:35:38 +00:00
parent 5cde673976
commit 2d2c434bd8
18 changed files with 322 additions and 64 deletions
+27 -16
View File
@@ -36,6 +36,18 @@ DECLARE_TYPEOF_COLLECTION(CardListBase*);
DEFINE_EVENT_TYPE(EVENT_CARD_SELECT);
DEFINE_EVENT_TYPE(EVENT_CARD_ACTIVATE);
CardP CardSelectEvent::getCard() const {
return getTheCardList()->getCard();
}
void CardSelectEvent::getSelection(vector<CardP>& out) const {
getTheCardList()->getSelection(out);
}
CardListBase* CardSelectEvent::getTheCardList() const {
return static_cast<CardListBase*>(GetEventObject());
}
// ----------------------------------------------------------------------------- : CardListBase
vector<CardListBase*> CardListBase::card_lists;
@@ -116,11 +128,21 @@ void CardListBase::getItems(vector<VoidP>& out) const {
out.push_back(c);
}
}
void CardListBase::sendEvent() {
CardSelectEvent ev(getCard());
void CardListBase::sendEvent(int type) {
CardSelectEvent ev(type);
ev.SetEventObject(this);
ProcessEvent(ev);
}
void CardListBase::getSelection(vector<CardP>& out) const {
long count = GetItemCount();
for (long pos = 0 ; pos < count ; ++pos) {
if (const_cast<CardListBase*>(this)->IsSelected(pos)) {
out.push_back(getCard(pos));
}
}
}
// ----------------------------------------------------------------------------- : CardListBase : Clipboard
bool CardListBase::canCut() const { return canDelete(); }
@@ -136,12 +158,7 @@ bool CardListBase::doCopy() {
if (!canCopy()) return false;
// cards to copy
vector<CardP> cards_to_copy;
long count = GetItemCount();
for (long pos = 0 ; pos < count ; ++pos) {
if (IsSelected(pos)) {
cards_to_copy.push_back(getCard(pos));
}
}
getSelection(cards_to_copy);
if (cards_to_copy.empty()) return false;
// put on clipboard
if (!wxTheClipboard->Open()) return false;
@@ -168,12 +185,7 @@ bool CardListBase::doPaste() {
bool CardListBase::doDelete() {
// cards to delete
vector<CardP> cards_to_delete;
long count = GetItemCount();
for (long pos = 0 ; pos < count ; ++pos) {
if (IsSelected(pos)) {
cards_to_delete.push_back(getCard(pos));
}
}
getSelection(cards_to_delete);
if (cards_to_delete.empty()) return false;
// delete cards
set->actions.addAction(new AddCardAction(REMOVE, *set, cards_to_delete));
@@ -372,8 +384,7 @@ void CardListBase::onContextMenu(wxContextMenuEvent&) {
void CardListBase::onItemActivate(wxListEvent& ev) {
selectItemPos(ev.GetIndex(), false);
CardSelectEvent event(getCard(), EVENT_CARD_ACTIVATE);
ProcessEvent(event);
sendEvent(EVENT_CARD_ACTIVATE);
}
// ----------------------------------------------------------------------------- : CardListBase : Event table
+13 -4
View File
@@ -16,6 +16,7 @@
DECLARE_POINTER_TYPE(ChoiceField);
DECLARE_POINTER_TYPE(Field);
class CardListBase;
// ----------------------------------------------------------------------------- : Events
@@ -36,11 +37,16 @@ DECLARE_EVENT_TYPE(EVENT_CARD_ACTIVATE, <not used>)
/// The event of selecting a card
struct CardSelectEvent : public wxCommandEvent {
inline CardSelectEvent(const CardP& card, int type = EVENT_CARD_SELECT)
: wxCommandEvent(type), card(card)
inline CardSelectEvent(int type = EVENT_CARD_SELECT)
: wxCommandEvent(type)
{}
CardP card; ///< The selected card
/// The selected card
CardP getCard() const;
/// All focused cards
void getSelection(vector<CardP>& out) const;
private:
CardListBase* getTheCardList() const;
};
// ----------------------------------------------------------------------------- : CardListBase
@@ -83,6 +89,8 @@ class CardListBase : public ItemList, public SetView {
public:
/// Return the card at the given position in the sorted card list
inline CardP getCard(long pos) const { return static_pointer_cast<Card>(getItem(pos)); }
/// Get a list of all focused cards
void getSelection(vector<CardP>& out) const;
protected:
/// Get a list of all cards
virtual void getItems(vector<VoidP>& out) const;
@@ -97,7 +105,8 @@ class CardListBase : public ItemList, public SetView {
virtual void sortBy(long column, bool ascending);
/// Send an 'item selected' event for the currently selected item (selected_item)
virtual void sendEvent();
virtual void sendEvent() { sendEvent(EVENT_CARD_SELECT); }
void sendEvent(int type = EVENT_CARD_SELECT);
/// Compare cards
virtual bool compareItems(void* a, void* b) const;
+1
View File
@@ -21,6 +21,7 @@
* Terminology:
* selected item = a single item in the variable selected_item
* focused items = items that are drawn as selected in the control
* TODO: This is reverse of normal
*/
class ItemList : public wxListView {
public:
+12
View File
@@ -43,6 +43,18 @@ bool SelectCardList::isSelected(const CardP& card) const {
return selected.find(card) != selected.end();
}
void SelectCardList::getSelection(vector<CardP>& out) const {
FOR_EACH_CONST(card, set->cards) {
if (isSelected(card)) out.push_back(card);
}
}
void SelectCardList::setSelection(const vector<CardP>& cards) {
selected.clear();
copy(cards.begin(), cards.end(), inserter(selected, selected.begin()));
}
void SelectCardList::onChangeSet() {
CardListBase::onChangeSet();
// init selected list: select all
+5
View File
@@ -26,6 +26,11 @@ class SelectCardList : public CardListBase {
void selectNone();
/// Is the given card selected?
bool isSelected(const CardP& card) const;
/// Get a list of all selected cards
void getSelection(vector<CardP>& out) const;
/// Change which cards are selected
void setSelection(const vector<CardP>& cards);
protected:
virtual int OnGetItemImage(long pos) const;
virtual void onChangeSet();