summaryrefslogtreecommitdiff
path: root/inputmethods/dasher/DashEdit.h
blob: dc14d15c7f95e475c9c943f0a53edb12d26633f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
//! Class definition for an edit box
// DashEdit.h
//
/////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2002 Iain Murray
//
/////////////////////////////////////////////////////////////////////////////

/*
An abstract DashEditbox class is described here.
An implementation will handle interaction between Dasher and an actual Edit control.
e.g. - output characters to the edit control
     - tapping on the edit box updates the Dasher display
*/

#ifndef __DashEdit_h__
#define __DashEdit_h__

#include "DasherWidgetInterface.h"

namespace Dasher {class CDashEditbox;}
class Dasher::CDashEditbox
{
public:
	CDashEditbox() : m_iFlushed(0), m_DasherInterface(0), m_dirty(false) {}

	//! Provide the Editbox with a widget interface
	virtual void SetInterface(CDasherWidgetInterface* DasherInterface) {m_DasherInterface = DasherInterface;}
	
	//! Write some buffered output to a file
	virtual void write_to_file()=0;
	
	//! Set the number of flushed characters
	//
	//! Set the number of flushed characters to an arbitrary number.
	//! Usually used to reset it to 0 after unflushing
	void set_flushed(int i) {m_iFlushed=i;}
	
	//! Provide context from the editbox for the core
	//
	//! Provide the context at the current position within the editbox to 
	//! the core. Set str to up to max characters before 
	//! the cursor position within the editbox.
	virtual void get_new_context(std::string& str, int max)=0;
	
	//! Delete flushed text from the editbox
	virtual inline void unflush()=0;
	
	//! Enter a the character Symbol into the text box
	virtual void output(symbol Symbol)=0;

	//! Delete the previous symbol from the text box
	virtual void deletetext()=0;
	
	//! Enter a character into the text box and remember that it is flushed
	//
	//! Output the character and increment m_iFlushed. When unflush is
	//! called, remove the previous m_iFlushed characters
	virtual void flush(symbol Symbol)=0;
	
	// File I/O (optional)

	//! If Value is true, timestamp all new files (optional)
	//
	//! If switched on, all new files should be timestamped, either in the
	//! filename or in file metadata
	virtual void TimeStampNewFiles(bool Value) {}

	//! Return true if any text has been modified since the last save (optional)
	bool IsDirty() {return m_dirty;}

	//! Generate a new file (optional)
	//
	//! New file - provide a file save dialogue and return the filename in
	//! filename, or provide a blank filename and present a file 
	//! save dialogue when Save() is called
	virtual void New(const std::string& filename) {}; // filename can be "", but you cannot call Save() without having set a filename.
	
	//! Open a file (optional)
	//
	//! Provide a file open dialogue and set filename to the 
	//! filename. Return true if a file is chosen and opened successfully,
	//! false otherwise
	virtual bool Open(const std::string& filename) {return false;};

	//! Open a file and append to it (optional)
	// 
	//! Provide a file open dialogue and set filename to the 
	//! filename. The file will then have any new text appended to it. 
	//! Return true if a file is chosen and opened successfully, false 
	//! otherwise
	virtual bool OpenAppendMode(const std::string& filename) {return false;};
	//! Save a file as a provided filename (optional)
	// 
	//! Provide a file save dialogue and set filename to the 
	//! filename. Return true if a file is chosen and saved successfully,
	//! false otherwise
	virtual bool SaveAs(const std::string& filename) {return false;};

	//! Save the current file (optional)
	//
	//! Save file to the current filename. If there is no current filename,
	//! or if saving fails, return false
	virtual bool Save() {return false;}; // returns false if there is no filename set, or if saving fails
	
	// Clipboard (optional)
	//! Cut selected text (optional)
	//
	//! Copy the selected text to the clipboard and remove it from the
	//! editbox
	virtual void Cut() {};

	//! Copy selected text (optional)
	//
	//! Copy the selected text to the clipboard
	virtual void Copy() {};

	//! Copy all text (optional)
	//
	//! Copy all text in the editbox to the clipboard
	virtual void CopyAll() {};

	//! Paste text from clipboard (optional)
	//
	//! Paste text from the clipboard into the editbox at the current
	//! position
	virtual void Paste() {};

	//! Select all text in the editbox (optional)
	virtual void SelectAll() {};

	//! Clear all text from the editbox (REQUIRED)
	virtual void Clear()=0; // Must at least be able to clear edit box

	//! Set the file encoding
	//
	//! Set the file encoding to the provided encoding Encoding. 
	//! The editbox is responsible for saving the file in the encoding 
	//! desired by the user. As Dasher is internally UTF8, it may well be 
	//! necessary to save in an alternative format based on locale and OS.
	virtual void SetEncoding(Opts::FileEncodingFormats Encoding)=0;

	//! Set the font used in the editbox
	//
	//! Set the font used in the editbox to Name and size 
	//! Size (in points)
	virtual void SetFont(std::string Name, long Size)=0;
	
// TODO sort relationship between CDashEditbox and derived classes
protected:
	//! Have the contents of the editbox been altered since the last save?
	bool m_dirty;

	//! Record the number of characters that have been flushed
	int m_iFlushed; // how many characters have been flushed

	//! Pointer to a DasherWidgetInterface for communication with the core
	CDasherWidgetInterface* m_DasherInterface;
};


#endif /* #ifndef __DashEdit_h__ */