| 1 /* |
|
| 2 * GNT - The GLib Ncurses Toolkit |
|
| 3 * |
|
| 4 * GNT is the legal property of its developers, whose names are too numerous |
|
| 5 * to list here. Please refer to the COPYRIGHT file distributed with this |
|
| 6 * source distribution. |
|
| 7 * |
|
| 8 * This library is free software; you can redistribute it and/or modify |
|
| 9 * it under the terms of the GNU General Public License as published by |
|
| 10 * the Free Software Foundation; either version 2 of the License, or |
|
| 11 * (at your option) any later version. |
|
| 12 * |
|
| 13 * This program is distributed in the hope that it will be useful, |
|
| 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
| 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
| 16 * GNU General Public License for more details. |
|
| 17 * |
|
| 18 * You should have received a copy of the GNU General Public License |
|
| 19 * along with this program; if not, write to the Free Software |
|
| 20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
| 21 */ |
|
| 22 |
|
| 23 #ifndef GNT_ENTRY_H |
|
| 24 #define GNT_ENTRY_H |
|
| 25 /** |
|
| 26 * SECTION:gntentry |
|
| 27 * @section_id: libgnt-gntentry |
|
| 28 * @short_description: <filename>gntentry.h</filename> |
|
| 29 * @title: Entry |
|
| 30 */ |
|
| 31 |
|
| 32 #include "gntwidget.h" |
|
| 33 #include "gnt.h" |
|
| 34 #include "gntcolors.h" |
|
| 35 #include "gntkeys.h" |
|
| 36 |
|
| 37 #define GNT_TYPE_ENTRY (gnt_entry_get_type()) |
|
| 38 #define GNT_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_ENTRY, GntEntry)) |
|
| 39 #define GNT_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_ENTRY, GntEntryClass)) |
|
| 40 #define GNT_IS_ENTRY(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_ENTRY)) |
|
| 41 #define GNT_IS_ENTRY_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_ENTRY)) |
|
| 42 #define GNT_ENTRY_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_ENTRY, GntEntryClass)) |
|
| 43 |
|
| 44 #define GNT_ENTRY_FLAGS(obj) (GNT_ENTRY(obj)->priv.flags) |
|
| 45 #define GNT_ENTRY_SET_FLAGS(obj, flags) (GNT_ENTRY_FLAGS(obj) |= flags) |
|
| 46 #define GNT_ENTRY_UNSET_FLAGS(obj, flags) (GNT_ENTRY_FLAGS(obj) &= ~(flags)) |
|
| 47 |
|
| 48 #define GNT_ENTRY_CHAR '_' /* The character to use to fill in the blank places */ |
|
| 49 |
|
| 50 typedef struct _GntEntry GntEntry; |
|
| 51 typedef struct _GntEntryPriv GntEntryPriv; |
|
| 52 typedef struct _GntEntryClass GntEntryClass; |
|
| 53 typedef struct _GntEntryKillRing GntEntryKillRing; |
|
| 54 typedef struct _GntEntrySearch GntEntrySearch; |
|
| 55 |
|
| 56 typedef enum |
|
| 57 { |
|
| 58 GNT_ENTRY_FLAG_ALPHA = 1 << 0, /* Only alpha */ |
|
| 59 GNT_ENTRY_FLAG_INT = 1 << 1, /* Only integer */ |
|
| 60 GNT_ENTRY_FLAG_NO_SPACE = 1 << 2, /* No blank space is allowed */ |
|
| 61 GNT_ENTRY_FLAG_NO_PUNCT = 1 << 3, /* No punctuations */ |
|
| 62 GNT_ENTRY_FLAG_MASK = 1 << 4, /* Mask the inputs */ |
|
| 63 } GntEntryFlag; |
|
| 64 |
|
| 65 #define GNT_ENTRY_FLAG_ALL (GNT_ENTRY_FLAG_ALPHA | GNT_ENTRY_FLAG_INT) |
|
| 66 |
|
| 67 struct _GntEntry |
|
| 68 { |
|
| 69 GntWidget parent; |
|
| 70 |
|
| 71 GntEntryFlag flag; |
|
| 72 |
|
| 73 char *start; |
|
| 74 char *end; |
|
| 75 char *scroll; /* Current scrolling position */ |
|
| 76 char *cursor; /* Cursor location */ |
|
| 77 /* 0 <= cursor - scroll < widget-width */ |
|
| 78 |
|
| 79 size_t buffer; /* Size of the buffer */ |
|
| 80 |
|
| 81 int max; /* 0 means infinite */ |
|
| 82 gboolean masked; |
|
| 83 |
|
| 84 GList *history; /* History of the strings. User can use this by pressing ctrl+up/down */ |
|
| 85 int histlength; /* How long can the history be? */ |
|
| 86 |
|
| 87 GList *suggests; /* List of suggestions */ |
|
| 88 gboolean word; /* Are the suggestions for only a word, or for the whole thing? */ |
|
| 89 gboolean always; /* Should the list of suggestions show at all times, or only on tab-press? */ |
|
| 90 GntWidget *ddown; /* The dropdown with the suggested list */ |
|
| 91 GntEntryKillRing *killring; /* Since: 2.3.0 */ |
|
| 92 GntEntrySearch *search; /* Since: 2.7.0 */ |
|
| 93 }; |
|
| 94 |
|
| 95 struct _GntEntryClass |
|
| 96 { |
|
| 97 GntWidgetClass parent; |
|
| 98 |
|
| 99 void (*text_changed)(GntEntry *entry); |
|
| 100 |
|
| 101 /*< private >*/ |
|
| 102 void (*gnt_reserved1)(void); |
|
| 103 void (*gnt_reserved2)(void); |
|
| 104 void (*gnt_reserved3)(void); |
|
| 105 void (*gnt_reserved4)(void); |
|
| 106 }; |
|
| 107 |
|
| 108 G_BEGIN_DECLS |
|
| 109 |
|
| 110 /** |
|
| 111 * gnt_entry_get_type: |
|
| 112 * |
|
| 113 * Returns: GType for GntEntry. |
|
| 114 */ |
|
| 115 GType gnt_entry_get_type(void); |
|
| 116 |
|
| 117 /** |
|
| 118 * gnt_entry_new: |
|
| 119 * @text: The text in the new entry box. |
|
| 120 * |
|
| 121 * Create a new GntEntry. |
|
| 122 * |
|
| 123 * Returns: The newly created entry box. |
|
| 124 */ |
|
| 125 GntWidget * gnt_entry_new(const char *text); |
|
| 126 |
|
| 127 /** |
|
| 128 * gnt_entry_set_max: |
|
| 129 * @entry: The entry box. |
|
| 130 * @max: The maximum length for text. A value of 0 means infinite length. |
|
| 131 * |
|
| 132 * Set the maximum length of the text in the entry box. |
|
| 133 */ |
|
| 134 void gnt_entry_set_max(GntEntry *entry, int max); |
|
| 135 |
|
| 136 /** |
|
| 137 * gnt_entry_set_text: |
|
| 138 * @entry: The entry box. |
|
| 139 * @text: The text to set in the box. |
|
| 140 * |
|
| 141 * Set the text in an entry box. |
|
| 142 */ |
|
| 143 void gnt_entry_set_text(GntEntry *entry, const char *text); |
|
| 144 |
|
| 145 /** |
|
| 146 * gnt_entry_set_flag: |
|
| 147 * @entry: The entry box. |
|
| 148 * @flag: The flags to set for the entry box. |
|
| 149 * |
|
| 150 * Set flags an entry box. |
|
| 151 */ |
|
| 152 void gnt_entry_set_flag(GntEntry *entry, GntEntryFlag flag); |
|
| 153 |
|
| 154 /** |
|
| 155 * gnt_entry_get_text: |
|
| 156 * @entry: The entry box. |
|
| 157 * |
|
| 158 * Get the text in an entry box. |
|
| 159 * |
|
| 160 * Returns: The current text in the entry box. |
|
| 161 */ |
|
| 162 const char *gnt_entry_get_text(GntEntry *entry); |
|
| 163 |
|
| 164 /** |
|
| 165 * gnt_entry_clear: |
|
| 166 * @entry: The entry box. |
|
| 167 * |
|
| 168 * Clear the text in the entry box. |
|
| 169 */ |
|
| 170 void gnt_entry_clear(GntEntry *entry); |
|
| 171 |
|
| 172 /** |
|
| 173 * gnt_entry_set_masked: |
|
| 174 * @entry: The entry box. |
|
| 175 * @set: %TRUE if the text should be masked, %FALSE otherwise. |
|
| 176 * |
|
| 177 * Set whether the text in the entry box should be masked for display. |
|
| 178 */ |
|
| 179 void gnt_entry_set_masked(GntEntry *entry, gboolean set); |
|
| 180 |
|
| 181 /** |
|
| 182 * gnt_entry_add_to_history: |
|
| 183 * @entry: The entry box. |
|
| 184 * @text: A new entry for the history list. |
|
| 185 * |
|
| 186 * Add a text to the history list for the text. The history length for the |
|
| 187 * entry box needs to be set first by gnt_entry_set_history_length. |
|
| 188 */ |
|
| 189 void gnt_entry_add_to_history(GntEntry *entry, const char *text); |
|
| 190 |
|
| 191 /** |
|
| 192 * gnt_entry_set_history_length: |
|
| 193 * @entry: The entry box. |
|
| 194 * @num: The maximum length of the history, -1 for unlimited. |
|
| 195 * |
|
| 196 * Set the length of history for the entry box. |
|
| 197 */ |
|
| 198 void gnt_entry_set_history_length(GntEntry *entry, int num); |
|
| 199 |
|
| 200 /** |
|
| 201 * gnt_entry_set_word_suggest: |
|
| 202 * @entry: The entry box. |
|
| 203 * @word: %TRUE if the suggestions are for individual words, %FALSE otherwise. |
|
| 204 * |
|
| 205 * Set whether the suggestions are for the entire entry box, or for each |
|
| 206 * individual word in the entry box. |
|
| 207 */ |
|
| 208 void gnt_entry_set_word_suggest(GntEntry *entry, gboolean word); |
|
| 209 |
|
| 210 /** |
|
| 211 * gnt_entry_set_always_suggest: |
|
| 212 * @entry: The entry box. |
|
| 213 * @always: %TRUE if the suggestion list should always be displayed. |
|
| 214 * |
|
| 215 * Set whether to always display the suggestions list, or only when the |
|
| 216 * tab-completion key is pressed (the TAB key, by default). |
|
| 217 */ |
|
| 218 void gnt_entry_set_always_suggest(GntEntry *entry, gboolean always); |
|
| 219 |
|
| 220 /** |
|
| 221 * gnt_entry_add_suggest: |
|
| 222 * @entry: The entry box. |
|
| 223 * @text: An item to add to the suggestion list. |
|
| 224 * |
|
| 225 * Add an item to the suggestion list. |
|
| 226 */ |
|
| 227 void gnt_entry_add_suggest(GntEntry *entry, const char *text); |
|
| 228 |
|
| 229 /** |
|
| 230 * gnt_entry_remove_suggest: |
|
| 231 * @entry: The entry box. |
|
| 232 * @text: The item to remove from the suggestion list. |
|
| 233 * |
|
| 234 * Remove an entry from the suggestion list. |
|
| 235 */ |
|
| 236 void gnt_entry_remove_suggest(GntEntry *entry, const char *text); |
|
| 237 |
|
| 238 G_END_DECLS |
|
| 239 |
|
| 240 #endif /* GNT_ENTRY_H */ |
|