Commit d98d23d2 authored by twanvl's avatar twanvl

copying messages from console

parent 8b698c47
...@@ -15,6 +15,7 @@ ...@@ -15,6 +15,7 @@
#include <data/stylesheet.hpp> #include <data/stylesheet.hpp>
#include <wx/splitter.h> #include <wx/splitter.h>
#include <wx/dcbuffer.h> #include <wx/dcbuffer.h>
#include <wx/clipbrd.h>
DECLARE_POINTER_TYPE(ConsoleMessage); DECLARE_POINTER_TYPE(ConsoleMessage);
DECLARE_TYPEOF_COLLECTION(ScriptParseError); DECLARE_TYPEOF_COLLECTION(ScriptParseError);
...@@ -77,6 +78,27 @@ class MessageCtrl : public wxScrolledWindow { ...@@ -77,6 +78,27 @@ class MessageCtrl : public wxScrolledWindow {
add_message(intrusive(new ConsoleMessage(type,text))); 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: private:
DECLARE_EVENT_TABLE(); DECLARE_EVENT_TABLE();
...@@ -97,6 +119,7 @@ class MessageCtrl : public wxScrolledWindow { ...@@ -97,6 +119,7 @@ class MessageCtrl : public wxScrolledWindow {
ensure_visible(*messages[selection]); ensure_visible(*messages[selection]);
} }
Refresh(false); Refresh(false);
ev.Skip(); // for focus
} }
size_t find_point(int y) { size_t find_point(int y) {
...@@ -275,7 +298,7 @@ ConsolePanel::ConsolePanel(Window* parent, int id) ...@@ -275,7 +298,7 @@ ConsolePanel::ConsolePanel(Window* parent, int id)
{ {
// init controls // init controls
splitter = new wxSplitterWindow(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL); 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_panel = new Panel(splitter, wxID_ANY);
entry = new wxTextCtrl(entry_panel, wxID_ANY, _(""), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER); entry = new wxTextCtrl(entry_panel, wxID_ANY, _(""), wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER);
wxButton* evaluate = new wxButton(entry_panel, ID_EVALUATE, _BUTTON_("evaluate")); wxButton* evaluate = new wxButton(entry_panel, ID_EVALUATE, _BUTTON_("evaluate"));
...@@ -388,7 +411,7 @@ void ConsolePanel::exec(String const& command) { ...@@ -388,7 +411,7 @@ void ConsolePanel::exec(String const& command) {
AColor color = (AColor)*result; AColor color = (AColor)*result;
wxImage image(30,20); wxImage image(30,20);
fill_image(image,color); fill_image(image,color);
set_alpha(image, color.alpha); set_alpha(image, color.alpha / 255.0);
message->bitmap = wxBitmap(image); message->bitmap = wxBitmap(image);
} else { } else {
message->text = result->toCode(); message->text = result->toCode();
...@@ -406,14 +429,17 @@ BEGIN_EVENT_TABLE(ConsolePanel, wxPanel) ...@@ -406,14 +429,17 @@ BEGIN_EVENT_TABLE(ConsolePanel, wxPanel)
END_EVENT_TABLE () END_EVENT_TABLE ()
// ----------------------------------------------------------------------------- : Clipboard // ----------------------------------------------------------------------------- : Clipboard
/*
bool ConsolePanel::canCut() const { return entry->canCut(); } // determine what control to use for clipboard actions
bool ConsolePanel::canCopy() const { return entry->canCopy(); } #define CUT_COPY_PASTE(op,return) \
bool ConsolePanel::canPaste() const { return entry->canPaste(); } int id = focused_control(this); \
void ConsolePanel::doCut() { entry->doCut(); } if (id == ID_MESSAGE_LIST) { return messages->op(); } \
void ConsolePanel::doCopy() { entry->doCopy(); } else { return false; }
void ConsolePanel::doPaste() { entry->doPaste(); }
*/ 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 // ----------------------------------------------------------------------------- : Annoying blinking icon thing
......
...@@ -33,14 +33,9 @@ class ConsolePanel : public SetWindowPanel { ...@@ -33,14 +33,9 @@ class ConsolePanel : public SetWindowPanel {
// --------------------------------------------------- : Clipboard // --------------------------------------------------- : Clipboard
/*
virtual bool canCut() const; virtual bool canCut() const;
virtual bool canCopy() const; virtual bool canCopy() const;
virtual bool canPaste() const;
virtual void doCut();
virtual void doCopy(); virtual void doCopy();
virtual void doPaste();
*/
protected: protected:
virtual void onChangeSet(); virtual void onChangeSet();
......
...@@ -244,6 +244,7 @@ enum ControlID { ...@@ -244,6 +244,7 @@ enum ControlID {
, ID_MATCH , ID_MATCH
, ID_REMINDER , ID_REMINDER
, ID_RULES , ID_RULES
, ID_MESSAGE_LIST
// Card list column select // Card list column select
, ID_MOVE_UP , ID_MOVE_UP
, ID_MOVE_DOWN , ID_MOVE_DOWN
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment