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:
twanvl
2006-11-20 18:51:11 +00:00
parent 3cbf2577c1
commit 23abbedcbd
46 changed files with 433 additions and 70 deletions
+1 -1
View File
@@ -24,7 +24,7 @@ class AboutWindow : public wxDialog {
// graphics
Bitmap logo, logo2;
void onPaint(wxPaintEvent& e);
void onPaint(wxPaintEvent&);
void draw(DC& dc);
};
+2 -2
View File
@@ -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();
+38 -1
View File
@@ -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
+2
View File
@@ -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'
+1 -1
View File
@@ -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
+1 -1
View File
@@ -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
View File
@@ -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
+3 -3
View File
@@ -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
View File
@@ -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
+5 -4
View File
@@ -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;
}
}
}
+1 -1
View File
@@ -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
+24 -1
View File
@@ -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);
}
+9 -2
View File
@@ -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;
+1 -1
View File
@@ -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();
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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);
+1 -1
View File
@@ -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();
+1 -1
View File
@@ -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?
+1 -1
View File
@@ -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();
+1 -1
View File
@@ -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);
+13
View File
@@ -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
+5
View File
@@ -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
+1 -1
View File
@@ -46,7 +46,7 @@ WelcomeWindow::WelcomeWindow()
SetSizer(s1);
}
void WelcomeWindow::onPaint(wxPaintEvent& e) {
void WelcomeWindow::onPaint(wxPaintEvent&) {
wxBufferedPaintDC dc(this);
dc.BeginDrawing();
draw(dc);
+1 -1
View File
@@ -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&);