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 
00053 typedef enum
00054 {
00055     GNT_ENTRY_FLAG_ALPHA    = 1 << 0,  /* Only alpha */
00056     GNT_ENTRY_FLAG_INT      = 1 << 1,  /* Only integer */
00057     GNT_ENTRY_FLAG_NO_SPACE = 1 << 2,  /* No blank space is allowed */
00058     GNT_ENTRY_FLAG_NO_PUNCT = 1 << 3,  /* No punctuations */
00059     GNT_ENTRY_FLAG_MASK     = 1 << 4,  /* Mask the inputs */
00060 } GntEntryFlag;
00061 
00062 #define GNT_ENTRY_FLAG_ALL    (GNT_ENTRY_FLAG_ALPHA | GNT_ENTRY_FLAG_INT)
00063 
00064 struct _GntEntry
00065 {
00066     GntWidget parent;
00067 
00068     GntEntryFlag flag;
00069 
00070     char *start;
00071     char *end;
00072     char *scroll;   /* Current scrolling position */
00073     char *cursor;   /* Cursor location */
00074                     /* 0 <= cursor - scroll < widget-width */
00075 
00076     size_t buffer;  /* Size of the buffer */
00077 
00078     int max;        /* 0 means infinite */
00079     gboolean masked;
00080 
00081     GList *history; /* History of the strings. User can use this by pressing ctrl+up/down */
00082     int histlength; /* How long can the history be? */
00083 
00084     GList *suggests;    /* List of suggestions */
00085     gboolean word;      /* Are the suggestions for only a word, or for the whole thing? */
00086     gboolean always;    /* Should the list of suggestions show at all times, or only on tab-press? */
00087     GntWidget *ddown;   /* The dropdown with the suggested list */
00088     GntEntryKillRing *killring; 
00089 };
00090 
00091 struct _GntEntryClass
00092 {
00093     GntWidgetClass parent;
00094 
00095     void (*text_changed)(GntEntry *entry);
00096     void (*gnt_reserved1)(void);
00097     void (*gnt_reserved2)(void);
00098     void (*gnt_reserved3)(void);
00099     void (*gnt_reserved4)(void);
00100 };
00101 
00102 G_BEGIN_DECLS
00103 
00107 GType gnt_entry_get_gtype(void);
00108 
00116 GntWidget * gnt_entry_new(const char *text);
00117 
00124 void gnt_entry_set_max(GntEntry *entry, int max);
00125 
00132 void gnt_entry_set_text(GntEntry *entry, const char *text);
00133 
00140 void gnt_entry_set_flag(GntEntry *entry, GntEntryFlag flag);
00141 
00149 const char *gnt_entry_get_text(GntEntry *entry);
00150 
00156 void gnt_entry_clear(GntEntry *entry);
00157 
00164 void gnt_entry_set_masked(GntEntry *entry, gboolean set);
00165 
00173 void gnt_entry_add_to_history(GntEntry *entry, const char *text);
00174 
00181 void gnt_entry_set_history_length(GntEntry *entry, int num);
00182 
00190 void gnt_entry_set_word_suggest(GntEntry *entry, gboolean word);
00191 
00199 void gnt_entry_set_always_suggest(GntEntry *entry, gboolean always);
00200 
00207 void gnt_entry_add_suggest(GntEntry *entry, const char *text);
00208 
00215 void gnt_entry_remove_suggest(GntEntry *entry, const char *text);
00216 
00217 G_END_DECLS
00218 
00219 #endif /* GNT_ENTRY_H */