1 //------------------------------------------------------------------------------
2 // emClipboard.h
3 //
4 // Copyright (C) 2005-2008,2010-2011,2018 Oliver Hamann.
5 //
6 // Homepage: http://eaglemode.sourceforge.net/
7 //
8 // This program is free software: you can redistribute it and/or modify it under
9 // the terms of the GNU General Public License version 3 as published by the
10 // Free Software Foundation.
11 //
12 // This program is distributed in the hope that it will be useful, but WITHOUT
13 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14 // FOR A PARTICULAR PURPOSE. See the GNU General Public License version 3 for
15 // more details.
16 //
17 // You should have received a copy of the GNU General Public License version 3
18 // along with this program. If not, see <http://www.gnu.org/licenses/>.
19 //------------------------------------------------------------------------------
20 
21 #ifndef emClipboard_h
22 #define emClipboard_h
23 
24 #ifndef emModel_h
25 #include <emCore/emModel.h>
26 #endif
27 
28 
29 //==============================================================================
30 //================================ emClipboard =================================
31 //==============================================================================
32 
33 class emClipboard : public emModel {
34 
35 public:
36 
37 	// This model class acts as an interface to the common clipboard and the
38 	// common selection. It is an abstract base class for an interface
39 	// implementation. Such an implementation should also define a public
40 	// method like this:
41 	//
42 	//   static void Install(emContext & context);
43 	//
44 	// That method should find or create an instance of the interface
45 	// implementation within the given context, and it should call the
46 	// protected method Install for registering it as the interface to be
47 	// returned by LookupInherited. The main program or the emGUIFramework
48 	// implementation should call the public Install method on the root
49 	// context at program start.
50 
51 	static emRef<emClipboard> LookupInherited(emContext & context);
52 		// Get a reference to the clipboard interface.
53 		// Arguments:
54 		//   context - The context where the clipboard interface has
55 		//             been installed, or any descendant context.
56 		//             Typically, it should have been installed in the
57 		//             root context, so you can give any context here.
58 		// Returns:
59 		//   The reference to the interface, or a NULL reference if not
60 		//   found.
61 
62 	virtual emInt64 PutText(const emString & str, bool selection=false) = 0;
63 		// Put a text to the clipboard or selection.
64 		// Arguments:
65 		//   str       - The text.
66 		//   selection - Whether to put the text to the clipboard
67 		//               (false) or to the selection (true).
68 		// Returns:
69 		//   An identification number for the new selection (see Clear).
70 		//   If the text is put to the clipboard, the return value has
71 		//   no meaning.
72 
73 	virtual void Clear(bool selection=false, emInt64 selectionId=0) = 0;
74 		// Clear the clipboard or selection.
75 		// Arguments:
76 		//   selection   - Whether to clear the clipboard (false) or the
77 		//                 selection (true).
78 		//   selectionId - If the selection is to be cleared:
79 		//                 Identification number retrieved with PutText.
80 		//                 If anyone else has modified the selection in
81 		//                 between, the call is ignored and the
82 		//                 selection is not cleared.
83 
84 	virtual emString GetText(bool selection=false) = 0;
85 		// Get the text from the clipboard or selection.
86 		// Arguments:
87 		//   selection - Whether to ask the clipboard (false) or the
88 		//               selection (true).
89 		// Returns:
90 		//   The text, or an empty string if cleared.
91 
92 protected:
93 
94 	emClipboard(emContext & context, const emString & name);
95 		// See emModel.
96 
97 	virtual ~emClipboard();
98 		// Destructor.
99 
100 	void Install();
101 		// Register this interface so that it can be found by
102 		// LookupInherited.
103 };
104 
105 
106 //==============================================================================
107 //============================= emPrivateClipboard =============================
108 //==============================================================================
109 
110 class emPrivateClipboard : public emClipboard {
111 
112 public:
113 
114 	// This is a simple implementation for a clipboard which is not shared
115 	// with anything.
116 
117 	static void Install(emContext & context);
118 
119 	virtual emInt64 PutText(const emString & str, bool selection=false);
120 
121 	virtual void Clear(bool selection=false, emInt64 selectionId=0);
122 
123 	virtual emString GetText(bool selection=false);
124 
125 private:
126 
127 	emPrivateClipboard(emContext & context, const emString & name);
128 	virtual ~emPrivateClipboard();
129 
130 	emString ClipText;
131 	emString SelText;
132 	emInt64 SelId;
133 };
134 
135 
136 #endif
137