neoGFX
Cross-platform C++ app/game engine
Loading...
Searching...
No Matches
i_clipboard.hpp
Go to the documentation of this file.
1// i_clipboard.hpp
2/*
3 neogfx C++ App/Game Engine
4 Copyright (c) 2015, 2020 Leigh Johnston. All Rights Reserved.
5
6 This program is free software: you can redistribute it and / or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
18*/
19
20#pragma once
21
22#include <neogfx/neogfx.hpp>
23#include <neogfx/core/event.hpp>
24#include <neogfx/gfx/image.hpp>
25
26namespace neogfx
27{
28 class i_clipboard;
29
31 {
32 public:
33 virtual bool can_undo() const = 0;
34 virtual bool can_redo() const = 0;
35 virtual bool can_cut() const = 0;
36 virtual bool can_copy() const = 0;
37 virtual bool can_paste() const = 0;
38 virtual bool can_delete_selected() const = 0;
39 virtual bool can_select_all() const = 0;
40 virtual void undo(i_clipboard& aClipboard) = 0;
41 virtual void redo(i_clipboard& aClipboard) = 0;
42 virtual void cut(i_clipboard& aClipboard) = 0;
43 virtual void copy(i_clipboard& aClipboard) = 0;
44 virtual void paste(i_clipboard& aClipboard) = 0;
45 virtual void delete_selected() = 0;
46 virtual void select_all() = 0;
47 };
48
50 {
51 public:
52 bool can_undo() const override { return false; }
53 bool can_redo() const override { return false; }
54 bool can_cut() const override { return false; }
55 bool can_copy() const override { return false; }
56 bool can_paste() const override { return false; }
57 bool can_delete_selected() const override { return false; }
58 bool can_select_all() const override { return false; }
59 void undo(i_clipboard& aClipboard) override {}
60 void redo(i_clipboard& aClipboard) override {}
61 void cut(i_clipboard& aClipboard) override {}
62 void copy(i_clipboard& aClipboard) override {}
63 void paste(i_clipboard& aClipboard) override {}
64 void delete_selected() override {}
65 void select_all() override {}
66 };
67
68 class i_clipboard : public i_service
69 {
70 public:
71 declare_event(updated)
72 declare_event(sink_activated)
73 declare_event(sink_deactivated)
74 public:
75 struct no_active_sink : std::logic_error { no_active_sink() : std::logic_error("neogfx::i_clipboard::no_active_sink") {} };
76 struct sink_not_active : std::logic_error { sink_not_active() : std::logic_error("neogfx::i_clipboard::sink_not_active") {} };
77 public:
78 virtual bool sink_active() const = 0;
80 virtual void activate(i_clipboard_sink& aSink) = 0;
81 virtual void deactivate(i_clipboard_sink& aSink) = 0;
82 public:
83 virtual bool has_text() const = 0;
84 virtual const i_string& text() const = 0;
85 virtual void set_text(i_string const& aText) = 0;
86 virtual bool has_image() const = 0;
87 virtual neogfx::image image() const = 0;
88 virtual void set_image(const neogfx::image& aImage) = 0;
89 public:
90 virtual void cut() = 0;
91 virtual void copy() = 0;
92 virtual void paste() = 0;
93 virtual void delete_selected() = 0;
94 virtual void select_all() = 0;
95 public:
96 static uuid const& iid() { static uuid const sIid{ 0x441eee78, 0x6c80, 0x464b, 0xb733, { 0x18, 0x91, 0x90, 0xa8, 0x39, 0xb9 } }; return sIid; }
97 };
98
100 {
101 public:
103 iPreviousSink{ service<i_clipboard>().sink_active() ? &service<i_clipboard>().active_sink() : nullptr }
104 {
105 service<i_clipboard>().activate(aSink);
106 }
108 {
109 if (iPreviousSink != nullptr)
110 {
111 service<i_clipboard>().activate(*iPreviousSink);
112 }
113 }
114 private:
115 i_clipboard_sink* iPreviousSink;
116 };
117}
bool can_copy() const override
bool can_cut() const override
bool can_delete_selected() const override
void paste(i_clipboard &aClipboard) override
bool can_paste() const override
bool can_undo() const override
bool can_select_all() const override
void redo(i_clipboard &aClipboard) override
bool can_redo() const override
void cut(i_clipboard &aClipboard) override
void undo(i_clipboard &aClipboard) override
void copy(i_clipboard &aClipboard) override
virtual void paste(i_clipboard &aClipboard)=0
virtual void delete_selected()=0
virtual bool can_select_all() const =0
virtual void cut(i_clipboard &aClipboard)=0
virtual void copy(i_clipboard &aClipboard)=0
virtual bool can_paste() const =0
virtual void undo(i_clipboard &aClipboard)=0
virtual bool can_copy() const =0
virtual bool can_undo() const =0
virtual bool can_delete_selected() const =0
virtual bool can_cut() const =0
virtual void select_all()=0
virtual void redo(i_clipboard &aClipboard)=0
virtual bool can_redo() const =0
virtual i_clipboard_sink & active_sink()=0
virtual bool has_text() const =0
virtual void cut()=0
virtual void set_image(const neogfx::image &aImage)=0
virtual void activate(i_clipboard_sink &aSink)=0
virtual void copy()=0
virtual neogfx::image image() const =0
virtual void set_text(i_string const &aText)=0
virtual void delete_selected()=0
virtual void deactivate(i_clipboard_sink &aSink)=0
virtual void paste()=0
virtual void select_all()=0
virtual const i_string & text() const =0
virtual bool has_image() const =0
virtual bool sink_active() const =0
static uuid const & iid()
scoped_clipboard_sink(i_clipboard_sink &aSink)
Service & service()
Definition services.hpp:113
#define declare_event(declName,...)
Definition i_event.hpp:305