1998-10-20 01:39:29 +04:00
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// "$Id$"
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
|
|
|
// Input base class header file for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2008-09-16 11:26:22 +04:00
|
|
|
// Copyright 1998-2008 by Bill Spitzak and others.
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
|
|
|
// 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; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
|
|
|
|
// USA.
|
|
|
|
//
|
2005-04-16 04:13:17 +04:00
|
|
|
// Please report all bugs and problems on the following page:
|
|
|
|
//
|
|
|
|
// http://www.fltk.org/str.php
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2008-10-15 17:46:06 +04:00
|
|
|
/* \file
|
2008-09-16 11:26:22 +04:00
|
|
|
Fl_Input_ widget . */
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
#ifndef Fl_Input__H
|
|
|
|
#define Fl_Input__H
|
|
|
|
|
|
|
|
#ifndef Fl_Widget_H
|
|
|
|
#include "Fl_Widget.H"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define FL_NORMAL_INPUT 0
|
|
|
|
#define FL_FLOAT_INPUT 1
|
|
|
|
#define FL_INT_INPUT 2
|
|
|
|
#define FL_HIDDEN_INPUT 3
|
|
|
|
#define FL_MULTILINE_INPUT 4
|
|
|
|
#define FL_SECRET_INPUT 5
|
2002-04-11 15:52:43 +04:00
|
|
|
#define FL_INPUT_TYPE 7
|
|
|
|
#define FL_INPUT_READONLY 8
|
|
|
|
#define FL_NORMAL_OUTPUT (FL_NORMAL_INPUT | FL_INPUT_READONLY)
|
|
|
|
#define FL_MULTILINE_OUTPUT (FL_MULTILINE_INPUT | FL_INPUT_READONLY)
|
2002-07-23 20:28:19 +04:00
|
|
|
#define FL_INPUT_WRAP 16
|
|
|
|
#define FL_MULTILINE_INPUT_WRAP (FL_MULTILINE_INPUT | FL_INPUT_WRAP)
|
|
|
|
#define FL_MULTILINE_OUTPUT_WRAP (FL_MULTILINE_INPUT | FL_INPUT_READONLY | FL_INPUT_WRAP)
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2008-09-15 15:10:51 +04:00
|
|
|
/**
|
|
|
|
This is a virtual base class below Fl_Input. It has all
|
|
|
|
the same interfaces, but lacks the handle() and
|
|
|
|
draw() method. You may want to subclass it if you are
|
|
|
|
one of those people who likes to change how the editing keys
|
|
|
|
work.
|
|
|
|
|
|
|
|
<P>This can act like any of the subclasses of Fl_Input, by
|
|
|
|
setting type() to one of the following values:</P>
|
|
|
|
|
|
|
|
\code
|
|
|
|
#define FL_NORMAL_INPUT 0
|
|
|
|
#define FL_FLOAT_INPUT 1
|
|
|
|
#define FL_INT_INPUT 2
|
|
|
|
#define FL_MULTILINE_INPUT 4
|
|
|
|
#define FL_SECRET_INPUT 5
|
|
|
|
#define FL_INPUT_TYPE 7
|
|
|
|
#define FL_INPUT_READONLY 8
|
|
|
|
#define FL_NORMAL_OUTPUT (FL_NORMAL_INPUT | FL_INPUT_READONLY)
|
|
|
|
#define FL_MULTILINE_OUTPUT (FL_MULTILINE_INPUT | FL_INPUT_READONLY)
|
|
|
|
#define FL_INPUT_WRAP 16
|
|
|
|
#define FL_MULTILINE_INPUT_WRAP (FL_MULTILINE_INPUT | FL_INPUT_WRAP)
|
|
|
|
#define FL_MULTILINE_OUTPUT_WRAP (FL_MULTILINE_INPUT | FL_INPUT_READONLY | FL_INPUT_WRAP)
|
|
|
|
\endcode
|
|
|
|
*/
|
2002-08-14 20:49:38 +04:00
|
|
|
class FL_EXPORT Fl_Input_ : public Fl_Widget {
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
const char* value_;
|
|
|
|
char* buffer;
|
|
|
|
|
|
|
|
int size_;
|
|
|
|
int bufsize;
|
|
|
|
int position_;
|
|
|
|
int mark_;
|
|
|
|
int xscroll_, yscroll_;
|
|
|
|
int mu_p;
|
|
|
|
int maximum_size_;
|
2008-04-23 03:33:17 +04:00
|
|
|
int shortcut_;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2001-10-29 06:44:33 +03:00
|
|
|
uchar erase_cursor_only;
|
2008-04-23 23:09:28 +04:00
|
|
|
Fl_Font textfont_;
|
2008-08-16 01:11:21 +04:00
|
|
|
Fl_Fontsize textsize_;
|
2001-10-29 06:44:33 +03:00
|
|
|
unsigned textcolor_;
|
|
|
|
unsigned cursor_color_;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2002-08-14 20:49:38 +04:00
|
|
|
const char* expand(const char*, char*) const;
|
|
|
|
double expandpos(const char*, const char*, const char*, int*) const;
|
|
|
|
void minimal_update(int, int);
|
|
|
|
void minimal_update(int p);
|
|
|
|
void put_in_buffer(int newsize);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2002-08-14 20:49:38 +04:00
|
|
|
void setfont() const;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2002-08-14 20:49:38 +04:00
|
|
|
int word_start(int i) const;
|
|
|
|
int word_end(int i) const;
|
|
|
|
int line_start(int i) const;
|
|
|
|
int line_end(int i) const;
|
|
|
|
void drawtext(int, int, int, int);
|
|
|
|
int up_down_position(int, int keepmark=0);
|
|
|
|
void handle_mouse(int, int, int, int, int keepmark=0);
|
|
|
|
int handletext(int e, int, int, int, int);
|
|
|
|
void maybe_do_callback();
|
1998-10-06 22:21:25 +04:00
|
|
|
int xscroll() const {return xscroll_;}
|
|
|
|
int yscroll() const {return yscroll_;}
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
2002-08-14 20:49:38 +04:00
|
|
|
void resize(int, int, int, int);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2002-08-14 20:49:38 +04:00
|
|
|
Fl_Input_(int, int, int, int, const char* = 0);
|
|
|
|
~Fl_Input_();
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2002-08-14 20:49:38 +04:00
|
|
|
int value(const char*);
|
|
|
|
int value(const char*, int);
|
|
|
|
int static_value(const char*);
|
|
|
|
int static_value(const char*, int);
|
2008-09-15 15:10:51 +04:00
|
|
|
/**
|
|
|
|
The first form returns the current value, which is a pointer
|
|
|
|
to the internal buffer and is valid only until the next event is
|
|
|
|
handled.
|
|
|
|
|
|
|
|
<P>The second two forms change the text and set the mark and the
|
|
|
|
point to the end of it. The string is copied to the internal
|
2008-09-17 19:44:43 +04:00
|
|
|
buffer. Passing NULL is the same as "".
|
2008-09-15 15:10:51 +04:00
|
|
|
This returns non-zero if the new value is different than the
|
|
|
|
current one. You can use the second version to directly set the
|
|
|
|
length if you know it already or want to put nul's in the
|
|
|
|
text.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
const char* value() const {return value_;}
|
2008-09-15 15:10:51 +04:00
|
|
|
/**
|
|
|
|
Same as value()[n], but may be faster in plausible
|
|
|
|
implementations. No bounds checking is done.
|
|
|
|
*/
|
|
|
|
char index(int i) const {return value_[i];}
|
|
|
|
/**
|
|
|
|
Returns the number of characters in value(). This
|
|
|
|
may be greater than strlen(value()) if there are nul
|
|
|
|
characters in it.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
int size() const {return size_;}
|
2003-06-15 08:47:28 +04:00
|
|
|
void size(int W, int H) { Fl_Widget::size(W, H); }
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Gets the maximum length of the input field. */
|
1998-10-06 22:21:25 +04:00
|
|
|
int maximum_size() const {return maximum_size_;}
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Sets the maximum length of the input field. */
|
1998-10-06 22:21:25 +04:00
|
|
|
void maximum_size(int m) {maximum_size_ = m;}
|
2008-09-15 15:10:51 +04:00
|
|
|
/**
|
|
|
|
The input widget maintains two pointers into the string. The
|
2008-09-17 19:44:43 +04:00
|
|
|
"position" is where the cursor is. The
|
|
|
|
"mark" is the other end of the selected text. If they
|
2008-09-15 15:10:51 +04:00
|
|
|
are equal then there is no selection. Changing this does not
|
|
|
|
affect the clipboard (use copy() to do that).
|
|
|
|
|
|
|
|
<P>Changing these values causes a redraw(). The new
|
|
|
|
values are bounds checked. The return value is non-zero if the
|
|
|
|
new position is different than the old one. position(n)
|
|
|
|
is the same as position(n,n). mark(n) is the
|
|
|
|
same as position(position(),n).
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
int position() const {return position_;}
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Gets the current selection mark. mark(n) is the same as position(position(),n).*/
|
1998-10-06 22:21:25 +04:00
|
|
|
int mark() const {return mark_;}
|
2002-08-14 20:49:38 +04:00
|
|
|
int position(int p, int m);
|
2008-09-15 15:10:51 +04:00
|
|
|
/** See int Fl_Input_::position() const */
|
1998-10-06 22:21:25 +04:00
|
|
|
int position(int p) {return position(p, p);}
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Sets the current selection mark. mark(n) is the same as position(position(),n).*/
|
1998-10-06 22:21:25 +04:00
|
|
|
int mark(int m) {return position(position(), m);}
|
2002-08-14 20:49:38 +04:00
|
|
|
int replace(int, int, const char*, int=0);
|
2008-09-15 15:10:51 +04:00
|
|
|
/**
|
|
|
|
Deletes the current selection.
|
|
|
|
cut(n) deletes n characters after the
|
|
|
|
position(). cut(-n) deletes n
|
|
|
|
characters before the position(). cut(a,b)
|
|
|
|
deletes the characters between offsets a and
|
|
|
|
b. A, b, and n are all
|
|
|
|
clamped to the size of the string. The mark and point are left
|
|
|
|
where the deleted text was.
|
|
|
|
|
|
|
|
<P>If you want the data to go into the clipboard, do
|
|
|
|
Fl_Input_::copy() before calling
|
|
|
|
Fl_Input_::cut(), or do Fl_Input_::copy_cuts()
|
|
|
|
afterwards.
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
int cut() {return replace(position(), mark(), 0);}
|
2008-09-15 15:10:51 +04:00
|
|
|
/** See int Fl_Input_::cut() */
|
1998-10-06 22:21:25 +04:00
|
|
|
int cut(int n) {return replace(position(), position()+n, 0);}
|
2008-09-15 15:10:51 +04:00
|
|
|
/** See int Fl_Input_::cut() */
|
1998-10-06 22:21:25 +04:00
|
|
|
int cut(int a, int b) {return replace(a, b, 0);}
|
2008-09-15 15:10:51 +04:00
|
|
|
/**
|
|
|
|
Insert the string t at the current position, and
|
|
|
|
leave the mark and position after it. If l is not zero
|
|
|
|
then it is assumed to be strlen(t).
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
int insert(const char* t, int l=0){return replace(position_, mark_, t, l);}
|
2002-08-14 20:49:38 +04:00
|
|
|
int copy(int clipboard);
|
|
|
|
int undo();
|
|
|
|
int copy_cuts();
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2008-09-15 15:10:51 +04:00
|
|
|
/**
|
|
|
|
The first form returns the current shortcut key for the Input.
|
|
|
|
<P>The second form sets the shortcut key to key. Setting this
|
|
|
|
overrides the use of '&' in the label(). The value is a bitwise
|
|
|
|
OR of a key and a set of shift flags, for example FL_ALT | 'a'
|
|
|
|
, FL_ALT | (FL_F + 10), or just 'a'. A value
|
|
|
|
of 0 disables the shortcut. </P>
|
|
|
|
<P>The key can be any value returned by
|
|
|
|
Fl::event_key(), but will usually be an ASCII letter. Use
|
|
|
|
a lower-case letter unless you require the shift key to be held down. </P>
|
|
|
|
<P>The shift flags can be any set of values accepted by
|
|
|
|
Fl::event_state(). If the bit is on that shift key must
|
|
|
|
be pushed. Meta, Alt, Ctrl, and Shift must be off if they are not in
|
2008-09-17 19:44:43 +04:00
|
|
|
the shift flags (zero for the other bits indicates a "don't care"
|
2008-09-15 15:10:51 +04:00
|
|
|
setting).
|
|
|
|
*/
|
2008-04-23 03:33:17 +04:00
|
|
|
int shortcut() const {return shortcut_;}
|
2008-09-15 15:10:51 +04:00
|
|
|
/** See int shortcut() const */
|
2008-04-23 03:33:17 +04:00
|
|
|
void shortcut(int s) {shortcut_ = s;}
|
|
|
|
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Gets the font of the text in the input field.*/
|
2008-04-23 23:09:28 +04:00
|
|
|
Fl_Font textfont() const {return textfont_;}
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Sets the font of the text in the input field.*/
|
2008-04-23 23:09:28 +04:00
|
|
|
void textfont(Fl_Font s) {textfont_ = s;}
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Gets the size of the text in the input field.*/
|
2008-08-16 01:11:21 +04:00
|
|
|
Fl_Fontsize textsize() const {return textsize_;}
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Sets the size of the text in the input field.*/
|
2008-08-16 01:11:21 +04:00
|
|
|
void textsize(Fl_Fontsize s) {textsize_ = s;}
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Gets the color of the text in the input field.*/
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_Color textcolor() const {return (Fl_Color)textcolor_;}
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Sets the color of the text in the input field.*/
|
2001-10-29 06:44:33 +03:00
|
|
|
void textcolor(unsigned n) {textcolor_ = n;}
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Gets the color of the cursor. This is black by default.*/
|
1998-10-06 22:21:25 +04:00
|
|
|
Fl_Color cursor_color() const {return (Fl_Color)cursor_color_;}
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Sets the color of the cursor. This is black by default.*/
|
2001-10-29 06:44:33 +03:00
|
|
|
void cursor_color(unsigned n) {cursor_color_ = n;}
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Gets the input field type. */
|
2002-04-11 15:52:43 +04:00
|
|
|
int input_type() const {return type() & FL_INPUT_TYPE; }
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Sets the input field type. */
|
2002-11-19 19:37:36 +03:00
|
|
|
void input_type(int t) { type((uchar)(t | readonly())); }
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Gets the read-only state of the input field. */
|
2002-04-11 15:52:43 +04:00
|
|
|
int readonly() const { return type() & FL_INPUT_READONLY; }
|
2008-09-15 15:10:51 +04:00
|
|
|
/** Sets the read-only state of the input field. */
|
2002-11-19 19:37:36 +03:00
|
|
|
void readonly(int b) { if (b) type((uchar)(type() | FL_INPUT_READONLY));
|
|
|
|
else type((uchar)(type() & ~FL_INPUT_READONLY)); }
|
2008-09-15 15:10:51 +04:00
|
|
|
/**
|
|
|
|
Gets the word wrapping state of the input field. Word
|
|
|
|
wrap is only functional with multi-line input fields.
|
|
|
|
*/
|
2002-07-23 20:28:19 +04:00
|
|
|
int wrap() const { return type() & FL_INPUT_WRAP; }
|
2008-09-15 15:10:51 +04:00
|
|
|
/**
|
|
|
|
Sets the word wrapping state of the input field. Word
|
|
|
|
wrap is only functional with multi-line input fields.
|
|
|
|
*/
|
2002-11-19 19:37:36 +03:00
|
|
|
void wrap(int b) { if (b) type((uchar)(type() | FL_INPUT_WRAP));
|
|
|
|
else type((uchar)(type() & ~FL_INPUT_WRAP)); }
|
1998-10-06 22:21:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|
1998-10-20 01:39:29 +04:00
|
|
|
|
|
|
|
//
|
2005-02-25 00:55:12 +03:00
|
|
|
// End of "$Id$".
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|