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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
|
/* This file is part of the KDE project
Copyright 1999-2006 The KSpread Team <koffice-devel@kde.org>
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public License
along with this library; see the file COPYING.LIB. If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#ifndef __kspread_editors_h__
#define __kspread_editors_h__
#include <vector>
#include <tqsyntaxhighlighter.h>
#include <tqwidget.h>
#include <kcombobox.h>
#include <klineedit.h>
#include <ksharedptr.h>
class KTextEdit;
class TQFont;
class TQButton;
class TQTextCursor;
namespace KSpread
{
class Canvas;
class Cell;
class CellEditor;
class LocationEditWidget;
class Region;
class Sheet;
class Tokens;
class View;
/**
* Colours cell references in formulas. Installed by CellEditor instances in
* the constructor.
*/
class FormulaEditorHighlighter : public TQSyntaxHighlighter
{
public:
/**
* Constructs a FormulaHighlighter to colour-code cell references in a TQTextEdit.
*
* @param textEdit The TQTextEdit widget which the highlighter should operate on
* @param canvas The Canvas object
*/
FormulaEditorHighlighter(TQTextEdit* textEdit, Canvas* canvas);
virtual ~FormulaEditorHighlighter();
/**
* Called automatically by KTextEditor to highlight text when modified.
*/
virtual int highlightParagraph(const TQString& text, int endStateOfLastPara);
/**
*
*/
const Tokens& formulaTokens() const;
/**
*
*/
uint rangeCount() const;
/**
* Returns true if any of the ranges or cells in the formula have changed since the
* last call to @ref FormulaEditorHighlighter::rangeChanged()
*/
bool rangeChanged() const;
/**
* Sets the highlighter's range changed flag to false.
*/
void resetRangeChanged();
protected:
/**
* Returns the position of the brace matching the one found at position pos
*/
int findMatchingBrace(int pos);
/**
* Examines the brace (Token::LeftPar or Token::RightPar) operator token at the given index in the token vector
* ( as returned by formulaTokens() ) and if the cursor is next to it, the token plus any matching brace will be highlighted
*/
void handleBrace(uint index);
private:
class Private;
Private* d;
};
/**
* Provides autocompletition facilities in formula editors.
* When the user types in the first few characters of a
* function name in a CellEditor which has a FunctionCompletion
* object installed on it, the FunctionCompletion object
* creates and displays a list of possible names which the user
* can select from. If the user selects a function name from the list,
* the @ref FunctionCompletion::selectedCompletion() signal is emitted
*/
class FunctionCompletion : public TQObject
{
Q_OBJECT
public:
FunctionCompletion( CellEditor* editor );
~FunctionCompletion();
/**
* Handles various keyboard and mouse actions which may occur on the autocompletion popup list
*/
bool eventFilter( TQObject *o, TQEvent *e );
/**
* Hides the autocompletion list box if it is visible and emits the @ref selectedCompletion signal.
*/
void doneCompletion();
/**
* Populates the autocompletion list box with the specified choices and shows it so that the user can view and select a function name.
* @param choices A list of possible function names which match the characters that the user has already entered.
*/
void showCompletion( const TQStringList &choices );
private slots:
void itemSelected( const TQString& item );
signals:
/**
* Emitted, if the user selects a function name from the list.
*/
void selectedCompletion( const TQString& item );
private:
class Private;
Private* d;
FunctionCompletion( const FunctionCompletion& );
FunctionCompletion& operator=( const FunctionCompletion& );
};
/**
* class CellEditor
*/
class CellEditor : public TQWidget
{
Q_OBJECT
public:
/**
* Creates a new CellEditor.
* @param cell The spreadsheet cell to associate the cell text editor with
* @param _parent The @ref Canvas object to associate this cell text editor with
* @param captureAllKeyEvents Controls whether or not the text editor swallows arrow key events or sends them to the parent canvas instead. If this is set to true, pressing the arrow keys will navigate backwards and forwards through the text in the editor. If it is false, the key events will be sent to the parent canvas which will change the cell being edited (depending on the direction of the arrow pressed). Generally this should be set to true if the user double clicks on the cell to edit it, and false if the user initiates editing by typing whilst the cell is selected.
* @param _name This parameter is sent to the TQObject constructor
*/
CellEditor( Cell* cell, Canvas* _parent = 0, bool captureAllKeyEvents = false, const char* _name = 0 );
~CellEditor();
Cell* cell() const;
Canvas* canvas() const;
void handleKeyPressEvent( TQKeyEvent* _ev );
void handleIMEvent( TQIMEvent * _ev );
void setEditorFont(TQFont const & font, bool updateSize);
int cursorPosition() const;
void setCursorPosition(int pos);
void setText(TQString text);
/** wrapper to KTextEdit::text() */
TQString text() const;
/** wrapper to KTextEdit::cut() */
void cut();
/** wrapper to KTextEdit::paste() */
void paste();
/** wrapper to KTextEdit::copy() */
void copy();
TQPoint globalCursorPosition() const;
bool checkChoice();
void setCheckChoice(bool b);
void updateChoice();
void setUpdateChoice(bool);
void setCursorToRange(uint);
private slots:
void slotTextChanged();
void slotCompletionModeChanged(TDEGlobalSettings::Completion _completion);
void slotCursorPositionChanged(int para,int pos);
void slotTextCursorChanged(TQTextCursor*);
protected:
void resizeEvent( TQResizeEvent* );
/**
* Steals some key events from the TQLineEdit and sends
* it to the @ref Canvas ( its parent ) instead.
*/
bool eventFilter( TQObject* o, TQEvent* e );
protected slots:
void checkFunctionAutoComplete();
void triggerFunctionAutoComplete();
void functionAutoComplete( const TQString& item );
private:
class Private;
Private* d;
};
/**
* ComboboxLocationEditWidget
*/
class ComboboxLocationEditWidget : public KComboBox
{
Q_OBJECT
public:
ComboboxLocationEditWidget( TQWidget *_parent, View * _canvas );
public slots:
void slotAddAreaName( const TQString & );
void slotRemoveAreaName( const TQString & );
private:
LocationEditWidget *m_locationWidget;
};
/**
* A widget that allows the user to enter an arbitrary
* cell location to goto or cell selection to highlight
*/
class LocationEditWidget : public KLineEdit
{
Q_OBJECT
public:
LocationEditWidget( TQWidget *_parent, View * _canvas );
View * view() const { return m_pView;}
void addCompletionItem( const TQString &_item );
void removeCompletionItem( const TQString &_item );
private slots:
void slotActivateItem();
protected:
virtual void keyPressEvent( TQKeyEvent * _ev );
private:
View * m_pView;
TDECompletion completionList;
bool activateItem();
};
/**
* The widget that appears above the sheet and allows to
* edit the cells content.
*/
class EditWidget : public TQLineEdit
{
Q_OBJECT
public:
EditWidget( TQWidget *parent, Canvas *canvas,
TQButton *cancelButton, TQButton *okButton);
virtual void setText( const TQString& t );
// Go into edit mode (enable the buttons)
void setEditMode( bool mode );
void showEditWidget(bool _show);
public slots:
void slotAbortEdit();
void slotDoneEdit();
protected:
virtual void keyPressEvent ( TQKeyEvent* _ev );
virtual void focusOutEvent( TQFocusEvent* ev );
private:
TQButton* m_pCancelButton;
TQButton* m_pOkButton;
Canvas* m_pCanvas;
bool isArray;
};
} // namespace KSpread
#endif
|