gntentry.h

Go to the documentation of this file.
00001 
00005 /*
00006  * GNT - The GLib Ncurses Toolkit
00007  *
00008  * GNT is the legal property of its developers, whose names are too numerous
00009  * to list here.  Please refer to the COPYRIGHT file distributed with this
00010  * source distribution.
00011  *
00012  * This library is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 2 of the License, or
00015  * (at your option) any later version.
00016  *
00017  * This program is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with this program; if not, write to the Free Software
00024  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025  */
00026 
00027 #ifndef GNT_ENTRY_H
00028 #define GNT_ENTRY_H
00029 
00030 #include "gntwidget.h"
00031 #include "gnt.h"
00032 #include "gntcolors.h"
00033 #include "gntkeys.h"
00034 
00035 #define GNT_TYPE_ENTRY              (gnt_entry_get_gtype())
00036 #define GNT_ENTRY(obj)              (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_ENTRY, GntEntry))
00037 #define GNT_ENTRY_CLASS(klass)      (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_ENTRY, GntEntryClass))
00038 #define GNT_IS_ENTRY(obj)           (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_ENTRY))
00039 #define GNT_IS_ENTRY_CLASS(klass)   (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_ENTRY))
00040 #define GNT_ENTRY_GET_CLASS(obj)    (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_ENTRY, GntEntryClass))
00041 
00042 #define GNT_ENTRY_FLAGS(obj)                (GNT_ENTRY(obj)->priv.flags)
00043 #define GNT_ENTRY_SET_FLAGS(obj, flags)     (GNT_ENTRY_FLAGS(obj) |= flags)
00044 #define GNT_ENTRY_UNSET_FLAGS(obj, flags)   (GNT_ENTRY_FLAGS(obj) &= ~(flags))
00045 
00046 #define ENTRY_CHAR      '_'         /* The character to use to fill in the blank places */
00047 
00048 typedef struct _GntEntry            GntEntry;
00049 typedef struct _GntEntryPriv        GntEntryPriv;
00050 typedef struct _GntEntryClass   GntEntryClass;
00051 
00052 typedef enum
00053 {
00054     GNT_ENTRY_FLAG_ALPHA    = 1 << 0,  /* Only alpha */
00055     GNT_ENTRY_FLAG_INT      = 1 << 1,  /* Only integer */
00056     GNT_ENTRY_FLAG_NO_SPACE = 1 << 2,  /* No blank space is allowed */
00057     GNT_ENTRY_FLAG_NO_PUNCT = 1 << 3,  /* No punctuations */
00058     GNT_ENTRY_FLAG_MASK     = 1 << 4,  /* Mask the inputs */
00059 } GntEntryFlag;
00060 
00061 #define GNT_ENTRY_FLAG_ALL    (GNT_ENTRY_FLAG_ALPHA | GNT_ENTRY_FLAG_INT)
00062 
00063 struct _GntEntry
00064 {
00065     GntWidget parent;
00066 
00067     GntEntryFlag flag;
00068 
00069     char *start;
00070     char *end;
00071     char *scroll;   /* Current scrolling position */
00072     char *cursor;   /* Cursor location */
00073                     /* 0 <= cursor - scroll < widget-width */
00074     
00075     size_t buffer;  /* Size of the buffer */
00076     
00077     int max;        /* 0 means infinite */
00078     gboolean masked;
00079 
00080     GList *history; /* History of the strings. User can use this by pressing ctrl+up/down */
00081     int histlength; /* How long can the history be? */
00082 
00083     GList *suggests;    /* List of suggestions */
00084     gboolean word;      /* Are the suggestions for only a word, or for the whole thing? */
00085     gboolean always;    /* Should the list of suggestions show at all times, or only on tab-press? */
00086     GntWidget *ddown;   /* The dropdown with the suggested list */
00087 };
00088 
00089 struct _GntEntryClass
00090 {
00091     GntWidgetClass parent;
00092 
00093     void (*text_changed)(GntEntry *entry);
00094     void (*gnt_reserved1)(void);
00095     void (*gnt_reserved2)(void);
00096     void (*gnt_reserved3)(void);
00097     void (*gnt_reserved4)(void);
00098 };
00099 
00100 G_BEGIN_DECLS
00101 
00107 GType gnt_entry_get_gtype(void);
00108 
00115 GntWidget * gnt_entry_new(const char *text);
00116 
00122 void gnt_entry_set_max(GntEntry *entry, int max);
00123 
00129 void gnt_entry_set_text(GntEntry *entry, const char *text);
00130 
00136 void gnt_entry_set_flag(GntEntry *entry, GntEntryFlag flag);
00137 
00138 const char *gnt_entry_get_text(GntEntry *entry);
00139 
00144 void gnt_entry_clear(GntEntry *entry);
00145 
00151 void gnt_entry_set_masked(GntEntry *entry, gboolean set);
00152 
00158 void gnt_entry_add_to_history(GntEntry *entry, const char *text);
00159 
00165 void gnt_entry_set_history_length(GntEntry *entry, int num);
00166 
00172 void gnt_entry_set_word_suggest(GntEntry *entry, gboolean word);
00173 
00179 void gnt_entry_set_always_suggest(GntEntry *entry, gboolean always);
00180 
00186 void gnt_entry_add_suggest(GntEntry *entry, const char *text);
00187 
00193 void gnt_entry_remove_suggest(GntEntry *entry, const char *text);
00194 
00195 G_END_DECLS
00196 
00197 #endif /* GNT_ENTRY_H */