gtktexttag.h 9.39 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
/* gtktexttag.c - text tag object
 *
 * Copyright (c) 1992-1994 The Regents of the University of California.
 * Copyright (c) 1994-1997 Sun Microsystems, Inc.
 * Copyright (c) 2000      Red Hat, Inc.
 * Tk -> Gtk port by Havoc Pennington <hp@redhat.com>
 *
 * This software is copyrighted by the Regents of the University of
 * California, Sun Microsystems, Inc., and other parties.  The
 * following terms apply to all files associated with the software
 * unless explicitly disclaimed in individual files.
 *
 * The authors hereby grant permission to use, copy, modify,
 * distribute, and license this software and its documentation for any
 * purpose, provided that existing copyright notices are retained in
 * all copies and that this notice is included verbatim in any
 * distributions. No written agreement, license, or royalty fee is
 * required for any of the authorized uses.  Modifications to this
 * software may be copyrighted by their authors and need not follow
 * the licensing terms described here, provided that the new terms are
 * clearly indicated on the first page of each file where they apply.
 *
 * IN NO EVENT SHALL THE AUTHORS OR DISTRIBUTORS BE LIABLE TO ANY
 * PARTY FOR DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL
 * DAMAGES ARISING OUT OF THE USE OF THIS SOFTWARE, ITS DOCUMENTATION,
 * OR ANY DERIVATIVES THEREOF, EVEN IF THE AUTHORS HAVE BEEN ADVISED
 * OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * THE AUTHORS AND DISTRIBUTORS SPECIFICALLY DISCLAIM ANY WARRANTIES,
 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, AND
 * NON-INFRINGEMENT.  THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS,
 * AND THE AUTHORS AND DISTRIBUTORS HAVE NO OBLIGATION TO PROVIDE
 * MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 *
 * GOVERNMENT USE: If you are acquiring this software on behalf of the
 * U.S. government, the Government shall have only "Restricted Rights"
 * in the software and related documentation as defined in the Federal
 * Acquisition Regulations (FARs) in Clause 52.227.19 (c) (2).  If you
 * are acquiring the software on behalf of the Department of Defense,
 * the software shall be classified as "Commercial Computer Software"
 * and the Government shall have only "Restricted Rights" as defined
 * in Clause 252.227-7013 (c) (1) of DFARs.  Notwithstanding the
 * foregoing, the authors grant the U.S. Government and others acting
 * in its behalf permission to use and distribute the software in
 * accordance with the terms specified in this license.
 *
 */

50
#if !defined (__GTK_H_INSIDE__) && !defined (GTK_COMPILATION)
51 52 53
#error "Only <gtk/gtk.h> can be included directly."
#endif

54 55
#ifndef __GTK_TEXT_TAG_H__
#define __GTK_TEXT_TAG_H__
56

57

58
#include <gdk/gdk.h>
Manish Singh's avatar
Manish Singh committed
59 60 61 62
#include <gtk/gtkenums.h>

/* Not needed, retained for compatibility -Yosh */
#include <gtk/gtkobject.h>
63

64

65
G_BEGIN_DECLS
66 67 68 69

typedef struct _GtkTextIter GtkTextIter;
typedef struct _GtkTextTagTable GtkTextTagTable;

70
typedef struct _GtkTextAttributes GtkTextAttributes;
71

72
#define GTK_TYPE_TEXT_TAG            (gtk_text_tag_get_type ())
73 74 75 76 77
#define GTK_TEXT_TAG(obj)            (G_TYPE_CHECK_INSTANCE_CAST ((obj), GTK_TYPE_TEXT_TAG, GtkTextTag))
#define GTK_TEXT_TAG_CLASS(klass)    (G_TYPE_CHECK_CLASS_CAST ((klass), GTK_TYPE_TEXT_TAG, GtkTextTagClass))
#define GTK_IS_TEXT_TAG(obj)         (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GTK_TYPE_TEXT_TAG))
#define GTK_IS_TEXT_TAG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GTK_TYPE_TEXT_TAG))
#define GTK_TEXT_TAG_GET_CLASS(obj)  (G_TYPE_INSTANCE_GET_CLASS ((obj), GTK_TYPE_TEXT_TAG, GtkTextTagClass))
78

79 80
#define GTK_TYPE_TEXT_ATTRIBUTES     (gtk_text_attributes_get_type ())

81 82 83
typedef struct _GtkTextTag GtkTextTag;
typedef struct _GtkTextTagClass GtkTextTagClass;

Havoc Pennington's avatar
Havoc Pennington committed
84 85
struct _GtkTextTag
{
86
  GObject parent_instance;
87

Cody Russell's avatar
Cody Russell committed
88
  GtkTextTagTable *GSEAL (table);
89

Cody Russell's avatar
Cody Russell committed
90
  char *GSEAL (name);           /* Name of this tag.  This field is actually
91 92 93
                                 * a pointer to the key from the entry in
                                 * tkxt->tagTable, so it needn't be freed
                                 * explicitly. */
Cody Russell's avatar
Cody Russell committed
94
  int GSEAL (priority);  /* Priority of this tag within widget.  0
95 96 97 98 99 100 101 102 103 104 105
                         * means lowest priority.  Exactly one tag
                         * has each integer value between 0 and
                         * numTags-1. */
  /*
   * Information for displaying text with this tag.  The information
   * belows acts as an override on information specified by lower-priority
   * tags.  If no value is specified, then the next-lower-priority tag
   * on the text determins the value.  The text widget itself provides
   * defaults if no tag specifies an override.
   */

Cody Russell's avatar
Cody Russell committed
106
  GtkTextAttributes *GSEAL (values);
107
  
108 109 110
  /* Flags for whether a given value is set; if a value is unset, then
   * this tag does not affect it.
   */
Cody Russell's avatar
Cody Russell committed
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130
  guint GSEAL (bg_color_set) : 1;
  guint GSEAL (fg_color_set) : 1;
  guint GSEAL (scale_set) : 1;
  guint GSEAL (justification_set) : 1;
  guint GSEAL (left_margin_set) : 1;
  guint GSEAL (indent_set) : 1;
  guint GSEAL (rise_set) : 1;
  guint GSEAL (strikethrough_set) : 1;
  guint GSEAL (right_margin_set) : 1;
  guint GSEAL (pixels_above_lines_set) : 1;
  guint GSEAL (pixels_below_lines_set) : 1;
  guint GSEAL (pixels_inside_wrap_set) : 1;
  guint GSEAL (tabs_set) : 1;
  guint GSEAL (underline_set) : 1;
  guint GSEAL (wrap_mode_set) : 1;
  guint GSEAL (bg_full_height_set) : 1;
  guint GSEAL (invisible_set) : 1;
  guint GSEAL (editable_set) : 1;
  guint GSEAL (language_set) : 1;
  guint GSEAL (pg_bg_color_set) : 1;
131 132

  /* Whether these margins accumulate or override */
Cody Russell's avatar
Cody Russell committed
133
  guint GSEAL (accumulative_margin) : 1;
134

Cody Russell's avatar
Cody Russell committed
135
  guint GSEAL (pad1) : 1;
136 137
};

138
struct _GtkTextTagClass
139
{
140
  GObjectClass parent_class;
141

142 143 144 145
  gboolean (* event) (GtkTextTag        *tag,
                      GObject           *event_object, /* widget, canvas item, whatever */
                      GdkEvent          *event,        /* the event itself */
                      const GtkTextIter *iter);        /* location of event in buffer */
146

147 148 149 150 151
  /* Padding for future expansion */
  void (*_gtk_reserved1) (void);
  void (*_gtk_reserved2) (void);
  void (*_gtk_reserved3) (void);
  void (*_gtk_reserved4) (void);
152 153
};

154
GType        gtk_text_tag_get_type     (void) G_GNUC_CONST;
155
GtkTextTag  *gtk_text_tag_new          (const gchar       *name);
156
gint         gtk_text_tag_get_priority (GtkTextTag        *tag);
157
void         gtk_text_tag_set_priority (GtkTextTag        *tag,
158
                                        gint               priority);
159
gboolean     gtk_text_tag_event        (GtkTextTag        *tag,
160
                                        GObject           *event_object,
161 162
                                        GdkEvent          *event,
                                        const GtkTextIter *iter);
163

164 165 166 167 168 169 170 171
/*
 * Style object created by folding a set of tags together
 */

typedef struct _GtkTextAppearance GtkTextAppearance;

struct _GtkTextAppearance
{
Soren Sandmann's avatar
Soren Sandmann committed
172
  /*< public >*/
173 174 175
  GdkColor bg_color;
  GdkColor fg_color;

176 177
  /* super/subscript rise, can be negative */
  gint rise;
178

Soren Sandmann's avatar
Soren Sandmann committed
179
  /*< private >*/
180 181 182 183
  /* I'm not sure this can really be used without breaking some things
   * an app might do :-/
   */
  gpointer padding1;
Soren Sandmann's avatar
Soren Sandmann committed
184 185

  /*< public >*/
186
  guint underline : 4;          /* PangoUnderline */
187
  guint strikethrough : 1;
188 189 190 191

  /* Whether to use background-related values; this is irrelevant for
   * the values struct when in a tag, but is used for the composite
   * values struct; it's true if any of the tags being composited
192 193
   * had background stuff set.
   */
194
  guint draw_bg : 1;
195 196
  
  /* These are only used when we are actually laying out and rendering
197
   * a paragraph; not when a GtkTextAppearance is part of a
198
   * GtkTextAttributes.
199 200
   */
  guint inside_selection : 1;
201
  guint is_text : 1;
202

Soren Sandmann's avatar
Soren Sandmann committed
203
  /*< private >*/
204 205 206 207
  guint pad1 : 1;
  guint pad2 : 1;
  guint pad3 : 1;
  guint pad4 : 1;
208 209
};

210
struct _GtkTextAttributes
211
{
Soren Sandmann's avatar
Soren Sandmann committed
212
  /*< private >*/
213 214
  guint refcount;

Soren Sandmann's avatar
Soren Sandmann committed
215
  /*< public >*/
216
  GtkTextAppearance appearance;
217

218
  GtkJustification justification;
219
  GtkTextDirection direction;
220

221
  /* Individual chunks of this can be set/unset as a group */
222
  PangoFontDescription *font;
223

Havoc Pennington's avatar
Havoc Pennington committed
224 225
  gdouble font_scale;
  
226
  gint left_margin;
227

228
  gint indent;  
229

230 231 232 233 234 235 236 237
  gint right_margin;

  gint pixels_above_lines;

  gint pixels_below_lines;

  gint pixels_inside_wrap;

238
  PangoTabArray *tabs;
239 240 241 242

  GtkWrapMode wrap_mode;        /* How to handle wrap-around for this tag.
                                 * Must be GTK_WRAPMODE_CHAR,
                                 * GTK_WRAPMODE_NONE, GTK_WRAPMODE_WORD
243 244
                                 */

245
  PangoLanguage *language;
246

Soren Sandmann's avatar
Soren Sandmann committed
247
  /*< private >*/
248
  GdkColor *pg_bg_color;
Soren Sandmann's avatar
Soren Sandmann committed
249 250

  /*< public >*/
251 252 253 254
  /* hide the text  */
  guint invisible : 1;

  /* Background is fit to full line height rather than
255 256
   * baseline +/- ascent/descent (font height)
   */
257
  guint bg_full_height : 1;
258

259 260 261
  /* can edit this text */
  guint editable : 1;

Soren Sandmann's avatar
Soren Sandmann committed
262
  /*< private >*/
263 264 265 266 267 268
  guint pad1 : 1;
  guint pad2 : 1;
  guint pad3 : 1;
  guint pad4 : 1;
};

269 270 271 272 273
GtkTextAttributes* gtk_text_attributes_new         (void);
GtkTextAttributes* gtk_text_attributes_copy        (GtkTextAttributes *src);
void               gtk_text_attributes_copy_values (GtkTextAttributes *src,
                                                    GtkTextAttributes *dest);
void               gtk_text_attributes_unref       (GtkTextAttributes *values);
Matthias Clasen's avatar
Matthias Clasen committed
274
GtkTextAttributes *gtk_text_attributes_ref         (GtkTextAttributes *values);
275

Matthias Clasen's avatar
Matthias Clasen committed
276
GType              gtk_text_attributes_get_type    (void) G_GNUC_CONST;
277

278

279
G_END_DECLS
280 281 282

#endif