From fa7f25306b8089afd278c0b4e8c95201cdb2fc44 Mon Sep 17 00:00:00 2001 From: twanvl Date: Sat, 22 Jan 2011 13:15:05 +0000 Subject: [PATCH] copying messages from console git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1634 0fc631ac-6414-0410-93d0-97cfa31319b6 --- src/gui/set/console_panel.cpp | 46 +++++++++++++++++++++++++++-------- src/gui/set/console_panel.hpp | 5 ---- src/util/window_id.hpp | 1 + 3 files changed, 37 insertions(+), 15 deletions(-) diff --git a/src/gui/set/console_panel.cpp b/src/gui/set/console_panel.cpp index d4d6f690..d4f3c69a 100644 --- a/src/gui/set/console_panel.cpp +++ b/src/gui/set/console_panel.cpp @@ -15,6 +15,7 @@ #include #include #include +#include DECLARE_POINTER_TYPE(ConsoleMessage); DECLARE_TYPEOF_COLLECTION(ScriptParseError); @@ -77,6 +78,27 @@ class MessageCtrl : public wxScrolledWindow { add_message(intrusive(new ConsoleMessage(type,text))); } + bool have_selection() const { + return selection < messages.size(); + } + + bool canCopy() const { + return have_selection(); + } + bool doCopy() { + if (selection >= messages.size()) return false; + ConsoleMessage const& msg = *messages[selection]; + if (!wxTheClipboard->Open()) return false; + bool ok = false; + if (msg.bitmap.Ok()) { + ok = wxTheClipboard->SetData(new wxBitmapDataObject(msg.bitmap)); + } else { + ok = wxTheClipboard->SetData(new wxTextDataObject(msg.text)); + } + wxTheClipboard->Close(); + return ok; + } + private: DECLARE_EVENT_TABLE(); @@ -97,6 +119,7 @@ class MessageCtrl : public wxScrolledWindow { ensure_visible(*messages[selection]); } Refresh(false); + ev.Skip(); // for focus } size_t find_point(int y) { @@ -275,7 +298,7 @@ ConsolePanel::ConsolePanel(Window* parent, int id) { // init controls splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); - messages = new MessageCtrl(splitter, wxID_ANY); + messages = new MessageCtrl(splitter, ID_MESSAGE_LIST); entry_panel = new Panel(splitter, wxID_ANY); entry = new wxTextCtrl(entry_panel, wxID_ANY, _(""), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); wxButton* evaluate = new wxButton(entry_panel, ID_EVALUATE, _BUTTON_("evaluate")); @@ -388,7 +411,7 @@ void ConsolePanel::exec(String const& command) { AColor color = (AColor)*result; wxImage image(30,20); fill_image(image,color); - set_alpha(image, color.alpha); + set_alpha(image, color.alpha / 255.0); message->bitmap = wxBitmap(image); } else { message->text = result->toCode(); @@ -406,14 +429,17 @@ BEGIN_EVENT_TABLE(ConsolePanel, wxPanel) END_EVENT_TABLE () // ----------------------------------------------------------------------------- : Clipboard -/* -bool ConsolePanel::canCut() const { return entry->canCut(); } -bool ConsolePanel::canCopy() const { return entry->canCopy(); } -bool ConsolePanel::canPaste() const { return entry->canPaste(); } -void ConsolePanel::doCut() { entry->doCut(); } -void ConsolePanel::doCopy() { entry->doCopy(); } -void ConsolePanel::doPaste() { entry->doPaste(); } -*/ + +// determine what control to use for clipboard actions +#define CUT_COPY_PASTE(op,return) \ + int id = focused_control(this); \ + if (id == ID_MESSAGE_LIST) { return messages->op(); } \ + else { return false; } + +bool ConsolePanel::canCut() const { return false; } +bool ConsolePanel::canCopy() const { CUT_COPY_PASTE(canCopy, return) } +//void ConsolePanel::doCut() { CUT_COPY_PASTE(doCut, return (void)) } +void ConsolePanel::doCopy() { CUT_COPY_PASTE(doCopy, return (void)) } // ----------------------------------------------------------------------------- : Annoying blinking icon thing diff --git a/src/gui/set/console_panel.hpp b/src/gui/set/console_panel.hpp index b90dbaa8..50d68c46 100644 --- a/src/gui/set/console_panel.hpp +++ b/src/gui/set/console_panel.hpp @@ -33,14 +33,9 @@ class ConsolePanel : public SetWindowPanel { // --------------------------------------------------- : Clipboard - /* virtual bool canCut() const; virtual bool canCopy() const; - virtual bool canPaste() const; - virtual void doCut(); virtual void doCopy(); - virtual void doPaste(); - */ protected: virtual void onChangeSet(); diff --git a/src/util/window_id.hpp b/src/util/window_id.hpp index c4130197..e1b84130 100644 --- a/src/util/window_id.hpp +++ b/src/util/window_id.hpp @@ -244,6 +244,7 @@ enum ControlID { , ID_MATCH , ID_REMINDER , ID_RULES +, ID_MESSAGE_LIST // Card list column select , ID_MOVE_UP , ID_MOVE_DOWN