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_TEXT_VIEW_H 24 #define GNT_TEXT_VIEW_H 25 /** 26 * SECTION:gnttextview 27 * @section_id: libgnt-gnttextview 28 * @title: GntTextView 29 * @short_description: A widget for displaying larger bodies of formatted text 30 */ 31 32 #include "gnt.h" 33 #include "gntcolors.h" 34 #include "gntkeys.h" 35 #include "gntwidget.h" 36 37 #define GNT_TYPE_TEXT_VIEW (gnt_text_view_get_gtype()) 38 #define GNT_TEXT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GNT_TYPE_TEXT_VIEW, GntTextView)) 39 #define GNT_TEXT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), GNT_TYPE_TEXT_VIEW, GntTextViewClass)) 40 #define GNT_IS_TEXT_VIEW(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GNT_TYPE_TEXT_VIEW)) 41 #define GNT_IS_TEXT_VIEW_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), GNT_TYPE_TEXT_VIEW)) 42 #define GNT_TEXT_VIEW_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), GNT_TYPE_TEXT_VIEW, GntTextViewClass)) 43 44 #ifndef GNT_DISABLE_DEPRECATED 45 /** 46 * GNT_TEXT_VIEW_FLAGS: 47 * 48 * Deprecated: 2.14.0: This is an internal implementation detail. 49 */ 50 #define GNT_TEXT_VIEW_FLAGS(obj) (GNT_TEXT_VIEW(obj)->priv.flags) 51 /** 52 * GNT_TEXT_VIEW_SET_FLAGS: 53 * 54 * Deprecated: 2.14.0: This is an internal implementation detail. 55 */ 56 #define GNT_TEXT_VIEW_SET_FLAGS(obj, flags) (GNT_TEXT_VIEW_FLAGS(obj) |= flags) 57 /** 58 * GNT_TEXT_VIEW_UNSET_FLAGS: 59 * 60 * Deprecated: 2.14.0: This is an internal implementation detail. 61 */ 62 #define GNT_TEXT_VIEW_UNSET_FLAGS(obj, flags) (GNT_TEXT_VIEW_FLAGS(obj) &= ~(flags)) 63 #endif 64 65 typedef struct _GntTextView GntTextView; 66 typedef struct _GntTextViewClass GntTextViewClass; 67 #ifndef GNT_DISABLE_DEPRECATED 68 /** 69 * GntTextViewPriv: 70 * 71 * Deprecated: 2.14.0: This is an internal implementation detail. 72 */ 73 typedef struct _GntTextViewPriv GntTextViewPriv; 74 #endif 75 76 /** 77 * GntTextViewFlag: 78 * 79 * Since: 2.1.0 80 */ 81 typedef enum 82 { 83 GNT_TEXT_VIEW_NO_SCROLL = 1 << 0, 84 GNT_TEXT_VIEW_WRAP_CHAR = 1 << 1, 85 GNT_TEXT_VIEW_TOP_ALIGN = 1 << 2, /* Since: 2.1.1 */ 86 } GntTextViewFlag; 87 88 /** 89 * GntTextView: 90 * 91 * Access to any fields is deprecated. See inline comments for replacements. 92 */ 93 struct _GntTextView 94 { 95 GntWidget parent; 96 97 GString *GNTSEAL(string); /* Deprecated. Use gnt_text_view_get_text. */ 98 GList *GNTSEAL(list); /* List of GntTextLine */ 99 100 GList *GNTSEAL(tags); /* A list of tags */ 101 GntTextViewFlag GNTSEAL(flags); 102 }; 103 104 typedef enum 105 { 106 GNT_TEXT_FLAG_NORMAL = 0, 107 GNT_TEXT_FLAG_BOLD = 1 << 0, 108 GNT_TEXT_FLAG_UNDERLINE = 1 << 1, 109 GNT_TEXT_FLAG_BLINK = 1 << 2, 110 GNT_TEXT_FLAG_DIM = 1 << 3, 111 GNT_TEXT_FLAG_HIGHLIGHT = 1 << 4, 112 } GntTextFormatFlags; 113 114 struct _GntTextViewClass 115 { 116 GntWidgetClass parent; 117 118 /*< private >*/ 119 void (*gnt_reserved1)(void); 120 void (*gnt_reserved2)(void); 121 void (*gnt_reserved3)(void); 122 void (*gnt_reserved4)(void); 123 }; 124 125 G_BEGIN_DECLS 126 127 /** 128 * gnt_text_view_get_gtype: 129 * 130 * Returns: GType for GntTextView. 131 */ 132 GType gnt_text_view_get_gtype(void); 133 134 /** 135 * gnt_text_view_new: 136 * 137 * Create a new textview. 138 * 139 * Returns: The newly created textview. 140 */ 141 GntWidget * gnt_text_view_new(void); 142 143 /** 144 * gnt_text_view_scroll: 145 * @view: The textview to scroll. 146 * @scroll: scroll > 0 means scroll up, < 0 means scroll down, == 0 means scroll to the end. 147 * 148 * Scroll the textview. 149 */ 150 void gnt_text_view_scroll(GntTextView *view, int scroll); 151 152 /** 153 * gnt_text_view_append_text_with_flags: 154 * @view: The textview. 155 * @text: The text to append to the textview. 156 * @flags: The text-flags to apply to the new text. 157 * 158 * Append new text in a textview. 159 */ 160 void gnt_text_view_append_text_with_flags(GntTextView *view, const char *text, GntTextFormatFlags flags); 161 162 /** 163 * gnt_text_view_append_text_with_tag: 164 * @view: The textview. 165 * @text: The text to append. 166 * @flags: The text-flags to apply to the new text. 167 * @tag: The tag for the appended text, so it can be changed later (see gnt_text_view_tag_change()) 168 * 169 * Append text in the textview, with some identifier (tag) for the added text. 170 */ 171 void gnt_text_view_append_text_with_tag(GntTextView *view, const char *text, GntTextFormatFlags flags, const char *tag); 172 173 /** 174 * gnt_text_view_get_text: 175 * @view: The textview. 176 * 177 * Get the text of the textview. 178 * 179 * Returns: The text. 180 * 181 * Since: 2.14.0 182 */ 183 const gchar *gnt_text_view_get_text(GntTextView *view); 184 185 /** 186 * gnt_text_view_next_line: 187 * @view: The textview. 188 * 189 * Move the cursor to the beginning of the next line and resets text-attributes. 190 * It first completes the current line with the current text-attributes. 191 */ 192 void gnt_text_view_next_line(GntTextView *view); 193 194 #ifndef GNT_DISABLE_DEPRECATED 195 /** 196 * gnt_text_format_flag_to_chtype: 197 * @flags: The GNT text format. 198 * 199 * Convert GNT-text formats to ncurses-text attributes. 200 * 201 * Returns: Nucrses text attribute. 202 * 203 * Deprecated: 2.14.1: This is an internal implementation detail. 204 */ 205 chtype gnt_text_format_flag_to_chtype(GntTextFormatFlags flags); 206 #endif 207 208 /** 209 * gnt_text_view_clear: 210 * @view: The textview. 211 * 212 * Clear the contents of the textview. 213 */ 214 void gnt_text_view_clear(GntTextView *view); 215 216 /** 217 * gnt_text_view_get_lines_below: 218 * @view: The textview. 219 * 220 * The number of lines below the bottom-most visible line. 221 * 222 * Returns: Number of lines below the bottom-most visible line. 223 */ 224 int gnt_text_view_get_lines_below(GntTextView *view); 225 226 /** 227 * gnt_text_view_get_lines_above: 228 * @view: The textview. 229 * 230 * The number of lines above the topmost visible line. 231 * 232 * Returns: Number of lines above the topmost visible line. 233 */ 234 int gnt_text_view_get_lines_above(GntTextView *view); 235 236 /** 237 * gnt_text_view_tag_change: 238 * @view: The textview. 239 * @name: The name of the tag. 240 * @text: The new text for the text. If 'text' is %NULL, the tag is removed. 241 * @all: %TRUE if all of the instancess of the tag should be changed, %FALSE if 242 * only the first instance should be changed. 243 * 244 * Change the text of a tag. 245 * 246 * Returns: The number of instances changed. 247 */ 248 int gnt_text_view_tag_change(GntTextView *view, const char *name, const char *text, gboolean all); 249 250 /** 251 * gnt_text_view_attach_scroll_widget: 252 * @view: The textview. 253 * @widget: The trigger widget. 254 * 255 * Setup hooks so that pressing up/down/page-up/page-down keys when 'widget' is 256 * in focus scrolls the textview. 257 */ 258 void gnt_text_view_attach_scroll_widget(GntTextView *view, GntWidget *widget); 259 260 /** 261 * gnt_text_view_attach_pager_widget: 262 * @view: The textview. 263 * @pager: The widget to trigger the PAGER. 264 * 265 * Setup appropriate hooks so that pressing some keys when the 'pager' widget 266 * is in focus triggers the PAGER to popup with the contents of the textview 267 * in it. 268 * 269 * The default key-combination to trigger the pager is a-v, and the default 270 * PAGER application is $PAGER. Both can be changed in ~/.gntrc like this: 271 * 272 * <programlisting> 273 * [pager] 274 * key = a-v 275 * path = /path/to/pager 276 * </programlisting> 277 */ 278 void gnt_text_view_attach_pager_widget(GntTextView *view, GntWidget *pager); 279 280 /** 281 * gnt_text_view_attach_editor_widget: 282 * @view: The textview. 283 * @widget: The widget to trigger the EDITOR. 284 * 285 * Setup appropriate hooks so that pressing some keys when 'widget' 286 * is in focus triggers the EDITOR to popup with the contents of the textview 287 * in it. 288 * 289 * The default key-combination to trigger the pager is a-e, and the default 290 * EDITOR application is $EDITOR. Both can be changed in ~/.gntrc like this: 291 * 292 * <programlisting> 293 * [editor] 294 * key = a-e 295 * path = /path/to/editor 296 * </programlisting> 297 */ 298 void gnt_text_view_attach_editor_widget(GntTextView *view, GntWidget *widget); 299 300 /** 301 * gnt_text_view_set_flag: 302 * @view: The textview widget 303 * @flag: The flag to set 304 * 305 * Set a GntTextViewFlag for the textview widget. 306 * 307 * Since: 2.1.0 308 */ 309 void gnt_text_view_set_flag(GntTextView *view, GntTextViewFlag flag); 310 311 G_END_DECLS 312 313 #endif /* GNT_TEXT_VIEW_H */ 314