1 /* gtktexttag.c - text tag object 2 * 3 * Copyright (c) 1992-1994 The Regents of the University of California. 4 * Copyright (c) 1994-1997 Sun Microsystems, Inc. 5 * Copyright (c) 2000 Red Hat, Inc. 6 * Tk -> Gtk port by Havoc Pennington <hp@redhat.com> 7 * 8 * This software is copyrighted by the Regents of the University of 9 * California, Sun Microsystems, Inc., and other parties. The 10 * following terms apply to all files associated with the software 11 * unless explicitly disclaimed in individual files. 12 * 13 * The authors hereby grant permission to use, copy, modify, 14 * distribute, and license this software and its documentation for any 15 * purpose, provided that existing copyright notices are retained in 16 * all copies and that this notice is included verbatim in any 17 * distributions. No written agreement, license, or royalty fee is 18 * required for any of the authorized uses. Modifications to this 19 * software may be copyrighted by their authors and need not follow 20 * the licensing terms described here, provided that the new terms are 21 * clearly indicated on the first page of each file where they apply. 22 * 23 * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY 24 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL 25 * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION, 26 * OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED 27 * OF THE POSSIBILITY OF SUCH DAMAGE. 28 * 29 * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES, 30 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 31 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND 32 * NON-INFRINGEMENT. THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, 33 * AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE 34 * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. 35 * 36 * GOVERNMENT USE: If you are acquiring this software on behalf of the 37 * U.S. government, the Government shall have only "Restricted Rights" 38 * in the software and related documentation as defined in the Federal 39 * Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2). If you 40 * are acquiring the software on behalf of the Department of Defense, 41 * the software shall be classified as "Commercial Computer Software" 42 * and the Government shall have only "Restricted Rights" as defined 43 * in Clause 252.227-7013 (c) (1) of DFARs. Notwithstanding the 44 * foregoing, the authors grant the U.S. Government and others acting 45 * in its behalf permission to use and distribute the software in 46 * accordance with the terms specified in this license. 47 * 48 */ 49 50 #ifndef __GTK_TEXT_TAG_H__ 51 #define __GTK_TEXT_TAG_H__ 52 53 54 #if defined(GTK_DISABLE_SINGLE_INCLUDES) && !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION) 55 #error "Only <gtk/gtk.h> can be included directly." 56 #endif 57 58 #include <gdk/gdk.h> 59 #include <gtk/gtkenums.h> 60 61 /* Not needed, retained for compatibility -Yosh */ 62 #include <gtk/gtkobject.h> 63 64 65 G_BEGIN_DECLS 66 67 typedef struct _GtkTextIter GtkTextIter; 68 typedef struct _GtkTextTagTable GtkTextTagTable; 69 70 typedef struct _GtkTextAttributes GtkTextAttributes; 71 72 #define GTK_TYPE_TEXT_TAG (gtk_text_tag_get_type ()) 73 #define GTK_TEXT_TAG(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TEXT_TAG, GtkTextTag)) 74 #define GTK_TEXT_TAG_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_TAG, GtkTextTagClass)) 75 #define GTK_IS_TEXT_TAG(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TEXT_TAG)) 76 #define GTK_IS_TEXT_TAG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_TAG)) 77 #define GTK_TEXT_TAG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TEXT_TAG, GtkTextTagClass)) 78 79 #define GTK_TYPE_TEXT_ATTRIBUTES (gtk_text_attributes_get_type ()) 80 81 typedef struct _GtkTextTag GtkTextTag; 82 typedef struct _GtkTextTagClass GtkTextTagClass; 83 84 struct _GtkTextTag 85 { 86 GObject parent_instance; 87 88 GtkTextTagTable *GSEAL (table); 89 90 char *GSEAL (name); /* Name of this tag. This field is actually 91 * a pointer to the key from the entry in 92 * tkxt->tagTable, so it needn't be freed 93 * explicitly. */ 94 int GSEAL (priority); /* Priority of this tag within widget. 0 95 * means lowest priority. Exactly one tag 96 * has each integer value between 0 and 97 * numTags-1. */ 98 /* 99 * Information for displaying text with this tag. The information 100 * belows acts as an override on information specified by lower-priority 101 * tags. If no value is specified, then the next-lower-priority tag 102 * on the text determins the value. The text widget itself provides 103 * defaults if no tag specifies an override. 104 */ 105 106 GtkTextAttributes *GSEAL (values); 107 108 /* Flags for whether a given value is set; if a value is unset, then 109 * this tag does not affect it. 110 */ 111 guint GSEAL (bg_color_set) : 1; 112 guint GSEAL (bg_stipple_set) : 1; 113 guint GSEAL (fg_color_set) : 1; 114 guint GSEAL (scale_set) : 1; 115 guint GSEAL (fg_stipple_set) : 1; 116 guint GSEAL (justification_set) : 1; 117 guint GSEAL (left_margin_set) : 1; 118 guint GSEAL (indent_set) : 1; 119 guint GSEAL (rise_set) : 1; 120 guint GSEAL (strikethrough_set) : 1; 121 guint GSEAL (right_margin_set) : 1; 122 guint GSEAL (pixels_above_lines_set) : 1; 123 guint GSEAL (pixels_below_lines_set) : 1; 124 guint GSEAL (pixels_inside_wrap_set) : 1; 125 guint GSEAL (tabs_set) : 1; 126 guint GSEAL (underline_set) : 1; 127 guint GSEAL (wrap_mode_set) : 1; 128 guint GSEAL (bg_full_height_set) : 1; 129 guint GSEAL (invisible_set) : 1; 130 guint GSEAL (editable_set) : 1; 131 guint GSEAL (language_set) : 1; 132 guint GSEAL (pg_bg_color_set) : 1; 133 134 /* Whether these margins accumulate or override */ 135 guint GSEAL (accumulative_margin) : 1; 136 137 guint GSEAL (pad1) : 1; 138 }; 139 140 struct _GtkTextTagClass 141 { 142 GObjectClass parent_class; 143 144 gboolean (* event) (GtkTextTag *tag, 145 GObject *event_object, /* widget, canvas item, whatever */ 146 GdkEvent *event, /* the event itself */ 147 const GtkTextIter *iter); /* location of event in buffer */ 148 149 /* Padding for future expansion */ 150 void (*_gtk_reserved1) (void); 151 void (*_gtk_reserved2) (void); 152 void (*_gtk_reserved3) (void); 153 void (*_gtk_reserved4) (void); 154 }; 155 156 GType gtk_text_tag_get_type (void) G_GNUC_CONST; 157 GtkTextTag *gtk_text_tag_new (const gchar *name); 158 gint gtk_text_tag_get_priority (GtkTextTag *tag); 159 void gtk_text_tag_set_priority (GtkTextTag *tag, 160 gint priority); 161 gboolean gtk_text_tag_event (GtkTextTag *tag, 162 GObject *event_object, 163 GdkEvent *event, 164 const GtkTextIter *iter); 165 166 /* 167 * Style object created by folding a set of tags together 168 */ 169 170 typedef struct _GtkTextAppearance GtkTextAppearance; 171 172 struct _GtkTextAppearance 173 { 174 /*< public >*/ 175 GdkColor bg_color; 176 GdkColor fg_color; 177 GdkBitmap *bg_stipple; 178 GdkBitmap *fg_stipple; 179 180 /* super/subscript rise, can be negative */ 181 gint rise; 182 183 /*< private >*/ 184 /* I'm not sure this can really be used without breaking some things 185 * an app might do :-/ 186 */ 187 gpointer padding1; 188 189 /*< public >*/ 190 guint underline : 4; /* PangoUnderline */ 191 guint strikethrough : 1; 192 193 /* Whether to use background-related values; this is irrelevant for 194 * the values struct when in a tag, but is used for the composite 195 * values struct; it's true if any of the tags being composited 196 * had background stuff set. 197 */ 198 guint draw_bg : 1; 199 200 /* These are only used when we are actually laying out and rendering 201 * a paragraph; not when a GtkTextAppearance is part of a 202 * GtkTextAttributes. 203 */ 204 guint inside_selection : 1; 205 guint is_text : 1; 206 207 /*< private >*/ 208 guint pad1 : 1; 209 guint pad2 : 1; 210 guint pad3 : 1; 211 guint pad4 : 1; 212 }; 213 214 struct _GtkTextAttributes 215 { 216 /*< private >*/ 217 guint refcount; 218 219 /*< public >*/ 220 GtkTextAppearance appearance; 221 222 GtkJustification justification; 223 GtkTextDirection direction; 224 225 /* Individual chunks of this can be set/unset as a group */ 226 PangoFontDescription *font; 227 228 gdouble font_scale; 229 230 gint left_margin; 231 232 gint indent; 233 234 gint right_margin; 235 236 gint pixels_above_lines; 237 238 gint pixels_below_lines; 239 240 gint pixels_inside_wrap; 241 242 PangoTabArray *tabs; 243 244 GtkWrapMode wrap_mode; /* How to handle wrap-around for this tag. 245 * Must be GTK_WRAPMODE_CHAR, 246 * GTK_WRAPMODE_NONE, GTK_WRAPMODE_WORD 247 */ 248 249 PangoLanguage *language; 250 251 /*< private >*/ 252 GdkColor *pg_bg_color; 253 254 /*< public >*/ 255 /* hide the text */ 256 guint invisible : 1; 257 258 /* Background is fit to full line height rather than 259 * baseline +/- ascent/descent (font height) 260 */ 261 guint bg_full_height : 1; 262 263 /* can edit this text */ 264 guint editable : 1; 265 266 /* colors are allocated etc. */ 267 guint realized : 1; 268 269 /*< private >*/ 270 guint pad1 : 1; 271 guint pad2 : 1; 272 guint pad3 : 1; 273 guint pad4 : 1; 274 }; 275 276 GtkTextAttributes* gtk_text_attributes_new (void); 277 GtkTextAttributes* gtk_text_attributes_copy (GtkTextAttributes *src); 278 void gtk_text_attributes_copy_values (GtkTextAttributes *src, 279 GtkTextAttributes *dest); 280 void gtk_text_attributes_unref (GtkTextAttributes *values); 281 GtkTextAttributes *gtk_text_attributes_ref (GtkTextAttributes *values); 282 283 GType gtk_text_attributes_get_type (void) G_GNUC_CONST; 284 285 286 G_END_DECLS 287 288 #endif 289 290