~canonical-dx-team/ubuntu/maverick/gtk+2.0/menuproxy

« back to all changes in this revision

Viewing changes to gtk/gtktextmark.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2007-05-04 12:24:25 UTC
  • mfrom: (1.1.21 upstream)
  • Revision ID: james.westby@ubuntu.com-20070504122425-0m8midgzrp40y8w2
Tags: 2.10.12-1ubuntu1
* Sync with Debian
* New upstream version:
  Fixed bugs:
  - 379414 file chooser warnings when changing path in the entry
  - 418585 GtkFileChooserDefault sizing code is not DPI independent
  - 419568 Crash in search if start with special letter
  - 435062 build dies with icon cache validation
  - 379399 Segfault to call gtk_print_operation_run twice.
  - 387889 cups backend has problems when there are too many printers
  - 418531 invalid read to gtkicontheme.c gtk_icon_theme_lookup_icon...
  - 423916 crash in color scheme code
  - 424042 Segmentation fault while quickly pressing Alt+arrows
  - 415260 Protect against negative indices when setting values in G...
  - 419171 XGetVisualInfo() may not set nxvisuals
  - 128852 Gdk cursors don't look good on win32
  - 344657 Ctrl-H doesn't toggle "Show Hidden Files" setting
  - 345345 PrintOperation::paginate is not emitted for class handler
  - 347567 GtkPrintOperation::end-print is not emitted if it's cance...
  - 369112 gtk_ui_manager_add_ui should accept unnamed separator
  - 392015 Selected menu item invisible on Windows Vista
  - 399253 MS-Windows Theme Bottom Tab placement rendering glitches
  - 399425 gtk_input_dialog_fill_axes() adds child to gtkscrolledwin...
  - 403251 [patch] little memory leak in GtkPrintJob
  - 403267 [patch] memory leak in GtkPageSetupUnixDialog
  - 403470 MS-Windows Theme tab placement other than on top leaks a ...
  - 404506 Windows system fonts that have multi-byte font names cann...
  - 405089 Incorrect window placement for GtkEventBox private window
  - 405515 Minor leak in gtkfilesystemmodel.c
  - 405539 gdk_pixbuf_save() for PNG saver can return FALSE without ...
  - 415681 gdk_window_clear_area includes an extra line and column o...
  - 418219 GtkRecentChooser should apply filter before sorting and c...
  - 418403 Scroll to printer after selecting it from settings
  - 421985 _gtk_print_operation_platform_backend_launch_preview
  - 421990 gtk_print_job_get_surface
  - 421993 gtk_print_operation_init
  - 423064 Conditional jump or move depends on uninitialised value(s...
  - 423722 Fix printing header in gtk-demo
  - 424168 gtk_print_operation_run on async preview
  - 425655 Don't install gtk+-unix-print-2.0.pc on non-UNIX platforms
  - 425786 GDK segfaults if XineramaQueryScreens fails
  - 428665 Lpr Backend gets stuck in infinite loop during gtk_enumer...
  - 429902 GtkPrintOperation leaks cairo contextes
  - 431997 First delay of GdkPixbufAnimationIter is wrong
  - 433242 Inconsistent scroll arrow position calculations
  - 433972 Placing gtk.Expander inside a gtk.TextView() changes gtk....
  - 434261 _gtk_toolbar_elide_underscores incorrectly handles some s...
  - 383354 ctrl-L should make 'Location' entry disappear
  - 418673 gtk_recent_manager_add_item
  - 429732 gtk_accel_group_finalize accesses invalid memory
  - 435028 WM_CLIENT_LEADER is wrong on the leader_window
  - 431067 Background of the header window is not updated
  - 338843 add recent files support inside the ui manager
  - 148535 add drop shadow to menus, tooltips, etc. under Windows XP
* debian/control.in:
  - Conflicts on ubuntulooks (<= 0.9.11-1)
* debian/patches/15_default-fallback-icon-theme.patch:
  - patch from Debian, fallback on gnome icon theme

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* gtktextmark.c - mark segments
 
2
 *
 
3
 * Copyright (c) 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
#define GTK_TEXT_USE_INTERNAL_UNSUPPORTED_API
 
51
#include <config.h>
 
52
#include "gtktextbtree.h"
 
53
#include "gtkintl.h"
 
54
#include "gtkalias.h"
 
55
 
 
56
static void gtk_text_mark_finalize (GObject *obj);
 
57
 
 
58
G_DEFINE_TYPE (GtkTextMark, gtk_text_mark, G_TYPE_OBJECT)
 
59
 
 
60
static void
 
61
gtk_text_mark_init (GtkTextMark *mark)
 
62
{
 
63
  mark->segment = NULL;
 
64
}
 
65
 
 
66
static void
 
67
gtk_text_mark_class_init (GtkTextMarkClass *klass)
 
68
{
 
69
  GObjectClass *object_class = G_OBJECT_CLASS (klass);
 
70
 
 
71
  object_class->finalize = gtk_text_mark_finalize;
 
72
}
 
73
 
 
74
static void
 
75
gtk_text_mark_finalize (GObject *obj)
 
76
{
 
77
  GtkTextMark *mark;
 
78
  GtkTextLineSegment *seg;
 
79
 
 
80
  mark = GTK_TEXT_MARK (obj);
 
81
 
 
82
  seg = mark->segment;
 
83
 
 
84
  if (seg)
 
85
    {
 
86
      if (seg->body.mark.tree != NULL)
 
87
        g_warning ("GtkTextMark being finalized while still in the buffer; "
 
88
                   "someone removed a reference they didn't own! Crash "
 
89
                   "impending");
 
90
 
 
91
      g_free (seg->body.mark.name);
 
92
      g_free (seg);
 
93
 
 
94
      mark->segment = NULL;
 
95
    }
 
96
 
 
97
  /* chain parent_class' handler */
 
98
  G_OBJECT_CLASS (gtk_text_mark_parent_class)->finalize (obj);
 
99
}
 
100
 
 
101
/**
 
102
 * gtk_text_mark_get_visible:
 
103
 * @mark: a #GtkTextMark
 
104
 * 
 
105
 * Returns %TRUE if the mark is visible (i.e. a cursor is displayed
 
106
 * for it)
 
107
 * 
 
108
 * Return value: %TRUE if visible
 
109
 **/
 
110
gboolean
 
111
gtk_text_mark_get_visible (GtkTextMark *mark)
 
112
{
 
113
  GtkTextLineSegment *seg;
 
114
 
 
115
  seg = mark->segment;
 
116
 
 
117
  return seg->body.mark.visible;
 
118
}
 
119
 
 
120
/**
 
121
 * gtk_text_mark_get_name:
 
122
 * @mark: a #GtkTextMark
 
123
 * 
 
124
 * Returns the mark name; returns NULL for anonymous marks.
 
125
 * 
 
126
 * Return value: mark name
 
127
 **/
 
128
const char *
 
129
gtk_text_mark_get_name (GtkTextMark *mark)
 
130
{
 
131
  GtkTextLineSegment *seg;
 
132
 
 
133
  seg = mark->segment;
 
134
 
 
135
  return seg->body.mark.name;
 
136
}
 
137
 
 
138
/**
 
139
 * gtk_text_mark_get_deleted:
 
140
 * @mark: a #GtkTextMark
 
141
 * 
 
142
 * Returns %TRUE if the mark has been removed from its buffer
 
143
 * with gtk_text_buffer_delete_mark(). Marks can't be used
 
144
 * once deleted.
 
145
 * 
 
146
 * Return value: whether the mark is deleted
 
147
 **/
 
148
gboolean
 
149
gtk_text_mark_get_deleted (GtkTextMark *mark)
 
150
{
 
151
  GtkTextLineSegment *seg;
 
152
 
 
153
  g_return_val_if_fail (GTK_IS_TEXT_MARK (mark), FALSE);
 
154
 
 
155
  seg = mark->segment;
 
156
 
 
157
  if (seg == NULL)
 
158
    return TRUE;
 
159
 
 
160
  return seg->body.mark.tree == NULL;
 
161
}
 
162
 
 
163
/**
 
164
 * gtk_text_mark_get_buffer:
 
165
 * @mark: a #GtkTextMark
 
166
 * 
 
167
 * Gets the buffer this mark is located inside,
 
168
 * or NULL if the mark is deleted.
 
169
 * 
 
170
 * Return value: the mark's #GtkTextBuffer
 
171
 **/
 
172
GtkTextBuffer*
 
173
gtk_text_mark_get_buffer (GtkTextMark *mark)
 
174
{
 
175
  GtkTextLineSegment *seg;
 
176
 
 
177
  g_return_val_if_fail (GTK_IS_TEXT_MARK (mark), NULL);
 
178
 
 
179
  seg = mark->segment;
 
180
 
 
181
  if (seg->body.mark.tree == NULL)
 
182
    return NULL;
 
183
  else
 
184
    return _gtk_text_btree_get_buffer (seg->body.mark.tree);
 
185
}
 
186
 
 
187
/**
 
188
 * gtk_text_mark_get_left_gravity:
 
189
 * @mark: a #GtkTextMark
 
190
 * 
 
191
 * Determines whether the mark has left gravity.
 
192
 * 
 
193
 * Return value: %TRUE if the mark has left gravity, %FALSE otherwise
 
194
 **/
 
195
gboolean
 
196
gtk_text_mark_get_left_gravity (GtkTextMark *mark)
 
197
{
 
198
  GtkTextLineSegment *seg;
 
199
 
 
200
  g_return_val_if_fail (GTK_IS_TEXT_MARK (mark), FALSE);
 
201
  
 
202
  seg = mark->segment;
 
203
 
 
204
  return seg->type == &gtk_text_left_mark_type;
 
205
}
 
206
 
 
207
/*
 
208
 * Macro that determines the size of a mark segment:
 
209
 */
 
210
 
 
211
#define MSEG_SIZE ((unsigned) (G_STRUCT_OFFSET (GtkTextLineSegment, body) \
 
212
        + sizeof (GtkTextMarkBody)))
 
213
 
 
214
 
 
215
GtkTextLineSegment*
 
216
_gtk_mark_segment_new (GtkTextBTree *tree,
 
217
                       gboolean      left_gravity,
 
218
                       const gchar  *name)
 
219
{
 
220
  GtkTextLineSegment *mark;
 
221
 
 
222
  mark = (GtkTextLineSegment *) g_malloc0 (MSEG_SIZE);
 
223
  mark->body.mark.name = g_strdup (name);
 
224
 
 
225
  if (left_gravity)
 
226
    mark->type = &gtk_text_left_mark_type;
 
227
  else
 
228
    mark->type = &gtk_text_right_mark_type;
 
229
 
 
230
  mark->byte_count = 0;
 
231
  mark->char_count = 0;
 
232
 
 
233
  mark->body.mark.obj = g_object_new (GTK_TYPE_TEXT_MARK, NULL);
 
234
  mark->body.mark.obj->segment = mark;
 
235
 
 
236
  mark->body.mark.tree = tree;
 
237
  mark->body.mark.line = NULL;
 
238
  mark->next = NULL;
 
239
 
 
240
  mark->body.mark.visible = FALSE;
 
241
  mark->body.mark.not_deleteable = FALSE;
 
242
 
 
243
  return mark;
 
244
}
 
245
 
 
246
static int                 mark_segment_delete_func  (GtkTextLineSegment *segPtr,
 
247
                                                      GtkTextLine        *line,
 
248
                                                      int                 treeGone);
 
249
static GtkTextLineSegment *mark_segment_cleanup_func (GtkTextLineSegment *segPtr,
 
250
                                                      GtkTextLine        *line);
 
251
static void                mark_segment_check_func   (GtkTextLineSegment *segPtr,
 
252
                                                      GtkTextLine        *line);
 
253
 
 
254
 
 
255
/*
 
256
 * The following structures declare the "mark" segment types.
 
257
 * There are actually two types for marks, one with left gravity
 
258
 * and one with right gravity.  They are identical except for
 
259
 * their gravity property.
 
260
 */
 
261
 
 
262
const GtkTextLineSegmentClass gtk_text_right_mark_type = {
 
263
  "mark",                                               /* name */
 
264
  FALSE,                                                /* leftGravity */
 
265
  NULL,                                         /* splitFunc */
 
266
  mark_segment_delete_func,                             /* deleteFunc */
 
267
  mark_segment_cleanup_func,                            /* cleanupFunc */
 
268
  NULL,                                         /* lineChangeFunc */
 
269
  mark_segment_check_func                               /* checkFunc */
 
270
};
 
271
 
 
272
const GtkTextLineSegmentClass gtk_text_left_mark_type = {
 
273
  "mark",                                               /* name */
 
274
  TRUE,                                         /* leftGravity */
 
275
  NULL,                                         /* splitFunc */
 
276
  mark_segment_delete_func,                             /* deleteFunc */
 
277
  mark_segment_cleanup_func,                            /* cleanupFunc */
 
278
  NULL,                                         /* lineChangeFunc */
 
279
  mark_segment_check_func                               /* checkFunc */
 
280
};
 
281
 
 
282
/*
 
283
 *--------------------------------------------------------------
 
284
 *
 
285
 * mark_segment_delete_func --
 
286
 *
 
287
 *      This procedure is invoked by the text B-tree code whenever
 
288
 *      a mark lies in a range of characters being deleted.
 
289
 *
 
290
 * Results:
 
291
 *      Returns 1 to indicate that deletion has been rejected,
 
292
 *      or 0 otherwise
 
293
 *
 
294
 * Side effects:
 
295
 *      Frees mark if tree is going away
 
296
 *
 
297
 *--------------------------------------------------------------
 
298
 */
 
299
 
 
300
static gboolean
 
301
mark_segment_delete_func (GtkTextLineSegment *seg,
 
302
                          GtkTextLine        *line,
 
303
                          gboolean            tree_gone)
 
304
{
 
305
  if (tree_gone)
 
306
    {
 
307
      _gtk_text_btree_release_mark_segment (seg->body.mark.tree, seg);
 
308
      return FALSE;
 
309
    }
 
310
  else
 
311
    return TRUE;
 
312
}
 
313
 
 
314
/*
 
315
 *--------------------------------------------------------------
 
316
 *
 
317
 * mark_segment_cleanup_func --
 
318
 *
 
319
 *      This procedure is invoked by the B-tree code whenever a
 
320
 *      mark segment is moved from one line to another.
 
321
 *
 
322
 * Results:
 
323
 *      None.
 
324
 *
 
325
 * Side effects:
 
326
 *      The line field of the segment gets updated.
 
327
 *
 
328
 *--------------------------------------------------------------
 
329
 */
 
330
 
 
331
static GtkTextLineSegment *
 
332
mark_segment_cleanup_func (GtkTextLineSegment *seg,
 
333
                           GtkTextLine        *line)
 
334
{
 
335
  /* not sure why Tk did this here and not in LineChangeFunc */
 
336
  seg->body.mark.line = line;
 
337
  return seg;
 
338
}
 
339
 
 
340
/*
 
341
 *--------------------------------------------------------------
 
342
 *
 
343
 * mark_segment_check_func --
 
344
 *
 
345
 *      This procedure is invoked by the B-tree code to perform
 
346
 *      consistency checks on mark segments.
 
347
 *
 
348
 * Results:
 
349
 *      None.
 
350
 *
 
351
 * Side effects:
 
352
 *      The procedure panics if it detects anything wrong with
 
353
 *      the mark.
 
354
 *
 
355
 *--------------------------------------------------------------
 
356
 */
 
357
 
 
358
static void
 
359
mark_segment_check_func (GtkTextLineSegment *seg,
 
360
                         GtkTextLine        *line)
 
361
{
 
362
  if (seg->body.mark.line != line)
 
363
    g_error ("mark_segment_check_func: seg->body.mark.line bogus");
 
364
}
 
365
 
 
366
#define __GTK_TEXT_MARK_C__
 
367
#include "gtkaliasdef.c"