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., 51 Franklin Street, Fifth Floor, Boston, MA  02111-1301  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 typedef struct _GntEntryKillRing    GntEntryKillRing;
00052 typedef struct _GntEntrySearch      GntEntrySearch;
00053 
00054 typedef enum
00055 {
00056     GNT_ENTRY_FLAG_ALPHA    = 1 << 0,  /* Only alpha */
00057     GNT_ENTRY_FLAG_INT      = 1 << 1,  /* Only integer */
00058     GNT_ENTRY_FLAG_NO_SPACE = 1 << 2,  /* No blank space is allowed */
00059     GNT_ENTRY_FLAG_NO_PUNCT = 1 << 3,  /* No punctuations */
00060     GNT_ENTRY_FLAG_MASK     = 1 << 4,  /* Mask the inputs */
00061 } GntEntryFlag;
00062 
00063 #define GNT_ENTRY_FLAG_ALL    (GNT_ENTRY_FLAG_ALPHA | GNT_ENTRY_FLAG_INT)
00064 
00065 struct _GntEntry
00066 {
00067     GntWidget parent;
00068 
00069     GntEntryFlag flag;
00070 
00071     char *start;
00072     char *end;
00073     char *scroll;   /* Current scrolling position */
00074     char *cursor;   /* Cursor location */
00075                     /* 0 <= cursor - scroll < widget-width */
00076 
00077     size_t buffer;  /* Size of the buffer */
00078 
00079     int max;        /* 0 means infinite */
00080     gboolean masked;
00081 
00082     GList *history; /* History of the strings. User can use this by pressing ctrl+up/down */
00083     int histlength; /* How long can the history be? */
00084 
00085     GList *suggests;    /* List of suggestions */
00086     gboolean word;      /* Are the suggestions for only a word, or for the whole thing? */
00087     gboolean always;    /* Should the list of suggestions show at all times, or only on tab-press? */
00088     GntWidget *ddown;   /* The dropdown with the suggested list */
00089     GntEntryKillRing *killring; 
00090     GntEntrySearch *search;     
00091 };
00092 
00093 struct _GntEntryClass
00094 {
00095     GntWidgetClass parent;
00096 
00097     void (*text_changed)(GntEntry *entry);
00098     void (*gnt_reserved1)(void);
00099     void (*gnt_reserved2)(void);
00100     void (*gnt_reserved3)(void);
00101     void (*gnt_reserved4)(void);
00102 };
00103 
00104 G_BEGIN_DECLS
00105 
00109 GType gnt_entry_get_gtype(void);
00110 
00118 GntWidget * gnt_entry_new(const char *text);
00119 
00126 void gnt_entry_set_max(GntEntry *entry, int max);
00127 
00134 void gnt_entry_set_text(GntEntry *entry, const char *text);
00135 
00142 void gnt_entry_set_flag(GntEntry *entry, GntEntryFlag flag);
00143 
00151 const char *gnt_entry_get_text(GntEntry *entry);
00152 
00158 void gnt_entry_clear(GntEntry *entry);
00159 
00166 void gnt_entry_set_masked(GntEntry *entry, gboolean set);
00167 
00175 void gnt_entry_add_to_history(GntEntry *entry, const char *text);
00176 
00183 void gnt_entry_set_history_length(GntEntry *entry, int num);
00184 
00192 void gnt_entry_set_word_suggest(GntEntry *entry, gboolean word);
00193 
00201 void gnt_entry_set_always_suggest(GntEntry *entry, gboolean always);
00202 
00209 void gnt_entry_add_suggest(GntEntry *entry, const char *text);
00210 
00217 void gnt_entry_remove_suggest(GntEntry *entry, const char *text);
00218 
00219 G_END_DECLS
00220 
00221 #endif /* GNT_ENTRY_H */