//+----------------------------------------------------------------------------+ //| Description: Magic Set Editor - Program to make Magic (tm) cards | //| Copyright: (C) Twan van Laarhoven and the other MSE developers | //| License: GNU General Public License 2 or later (see file COPYING) | //+----------------------------------------------------------------------------+ #pragma once // ----------------------------------------------------------------------------- : Includes #include #include #include #include #include typedef intrusive_ptr > KeywordListFilterP; // ----------------------------------------------------------------------------- : Events DECLARE_LOCAL_EVENT_TYPE(EVENT_KEYWORD_SELECT, ) /// Handle KeywordSelectEvents #define EVT_KEYWORD_SELECT(id, handler) \ DECLARE_EVENT_TABLE_ENTRY(EVENT_KEYWORD_SELECT, id, -1, \ (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) \ (void (wxEvtHandler::*)(KeywordSelectEvent&)) (&handler), (wxObject*) NULL), /// The event of selecting a keyword struct KeywordSelectEvent : public wxCommandEvent { KeywordP keyword; ///< The selected keyword inline KeywordSelectEvent(const KeywordP& keyword) : wxCommandEvent(EVENT_KEYWORD_SELECT), keyword(keyword) {} }; // ----------------------------------------------------------------------------- : KeywordList /// A control that lists the keywords in a set and its game class KeywordList : public ItemList, public SetView { public: KeywordList(Window* parent, int id, long additional_style = 0); ~KeywordList(); // --------------------------------------------------- : Set stuff virtual void onBeforeChangeSet(); virtual void onChangeSet(); virtual void onAction(const Action&, bool); void updateUsageStatistics(); // --------------------------------------------------- : Selection inline KeywordP getKeyword() const { return static_pointer_cast(selected_item); } inline void setKeyword(const KeywordP& kw) { selectItem(kw, true, false); } /// Change the filter to use, can be null void setFilter(const KeywordListFilterP& filter); // --------------------------------------------------- : Clipboard bool canDelete() const; bool canCopy() const; bool canPaste() const; // Try to perform a clipboard operation, return success bool doCut(); bool doCopy(); bool doPaste(); bool doDelete(); // --------------------------------------------------- : The keywords protected: /// Get a list of all keywords virtual void getItems(vector& out) const; /// Return the keyword at the given position in the sorted keyword list inline KeywordP getKeyword(long pos) const { return static_pointer_cast(getItem(pos)); } /// Send an 'item selected' event for the currently selected item (selected_item) virtual void sendEvent(); /// Compare keywords virtual bool compareItems(void* a, void* b) const; /// Get the text of an item in a specific column /** Overrides a function from wxListCtrl */ virtual String OnGetItemText (long pos, long col) const; /// Get the image of an item, by default no image is used /** Overrides a function from wxListCtrl */ virtual int OnGetItemImage(long pos) const; /// Get the color for an item virtual wxListItemAttr* OnGetItemAttr(long pos) const; private: void storeColumns(); mutable wxListItemAttr item_attr; // for OnGetItemAttr KeywordListFilterP filter; ///< Which keywords to show? /// How often is a keyword used in the set? int usage(const Keyword&) const; map usage_statistics; // --------------------------------------------------- : Window events DECLARE_EVENT_TABLE(); void onContextMenu (wxContextMenuEvent&); };