~ubuntu-branches/ubuntu/jaunty/gimp/jaunty-security

« back to all changes in this revision

Viewing changes to app/display/gimpnavigationeditor.c

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Holbach
  • Date: 2007-05-02 16:33:03 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20070502163303-bvzhjzbpw8qglc4y
Tags: 2.3.16-1ubuntu1
* Resynchronized with Debian, remaining Ubuntu changes:
  - debian/rules: i18n magic.
* debian/control.in:
  - Maintainer: Ubuntu Core Developers <ubuntu-devel@lists.ubuntu.com>
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch,
  debian/patches/10_dont_show_wizard.patch: updated.
* debian/patches/04_composite-signedness.patch,
  debian/patches/05_add-letter-spacing.patch: dropped, used upstream.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* The GIMP -- an image manipulation program
 
1
/* GIMP - The GNU Image Manipulation Program
2
2
 * Copyright (C) 1995 Spencer Kimball and Peter Mattis
3
3
 *
4
4
 * gimpnavigationeditor.c
26
26
 
27
27
#include <gtk/gtk.h>
28
28
 
 
29
#include "libgimpmath/gimpmath.h"
29
30
#include "libgimpwidgets/gimpwidgets.h"
30
31
 
31
32
#include "display-types.h"
52
53
#include "gimp-intl.h"
53
54
 
54
55
 
55
 
#define MAX_SCALE_BUF 20
56
 
 
57
 
 
58
 
static void   gimp_navigation_editor_class_init (GimpNavigationEditorClass *klass);
59
 
static void   gimp_navigation_editor_init       (GimpNavigationEditor      *editor);
60
 
 
61
 
static void   gimp_navigation_editor_docked_iface_init (GimpDockedInterface *docked_iface);
62
 
static void   gimp_navigation_editor_set_context       (GimpDocked       *docked,
63
 
                                                        GimpContext      *context);
64
 
 
65
 
static void   gimp_navigation_editor_destroy           (GtkObject          *object);
66
 
 
67
 
static GtkWidget * gimp_navigation_editor_new_private  (GimpMenuFactory    *menu_factory,
68
 
                                                        GimpDisplayShell   *shell);
 
56
static void   gimp_navigation_editor_docked_iface_init (GimpDockedInterface  *iface);
 
57
 
 
58
static void   gimp_navigation_editor_destroy           (GtkObject            *object);
 
59
 
 
60
static void   gimp_navigation_editor_set_context       (GimpDocked           *docked,
 
61
                                                        GimpContext          *context);
 
62
 
 
63
static GtkWidget * gimp_navigation_editor_new_private  (GimpMenuFactory      *menu_factory,
 
64
                                                        GimpDisplayShell     *shell);
69
65
 
70
66
static void     gimp_navigation_editor_set_shell       (GimpNavigationEditor *view,
71
67
                                                        GimpDisplayShell     *shell);
72
 
static gboolean gimp_navigation_editor_button_release  (GtkWidget          *widget,
73
 
                                                        GdkEventButton     *bevent,
74
 
                                                        GimpDisplayShell   *shell);
 
68
static gboolean gimp_navigation_editor_button_release  (GtkWidget            *widget,
 
69
                                                        GdkEventButton       *bevent,
 
70
                                                        GimpDisplayShell     *shell);
75
71
static void   gimp_navigation_editor_marker_changed    (GimpNavigationView   *view,
76
72
                                                        gdouble               x,
77
73
                                                        gdouble               y,
95
91
static void   gimp_navigation_editor_update_marker     (GimpNavigationEditor *editor);
96
92
 
97
93
 
98
 
static GimpEditorClass *parent_class = NULL;
99
 
 
100
 
 
101
 
GType
102
 
gimp_navigation_editor_get_type (void)
103
 
{
104
 
  static GType type = 0;
105
 
 
106
 
  if (! type)
107
 
    {
108
 
      static const GTypeInfo editor_info =
109
 
      {
110
 
        sizeof (GimpNavigationEditorClass),
111
 
        NULL,           /* base_init */
112
 
        NULL,           /* base_finalize */
113
 
        (GClassInitFunc) gimp_navigation_editor_class_init,
114
 
        NULL,           /* class_finalize */
115
 
        NULL,           /* class_navigation */
116
 
        sizeof (GimpNavigationEditor),
117
 
        0,              /* n_preallocs */
118
 
        (GInstanceInitFunc) gimp_navigation_editor_init,
119
 
      };
120
 
      static const GInterfaceInfo docked_iface_info =
121
 
      {
122
 
        (GInterfaceInitFunc) gimp_navigation_editor_docked_iface_init,
123
 
        NULL,           /* iface_finalize */
124
 
        NULL            /* iface_data     */
125
 
      };
126
 
 
127
 
      type = g_type_register_static (GIMP_TYPE_EDITOR,
128
 
                                     "GimpNavigationEditor",
129
 
                                     &editor_info, 0);
130
 
 
131
 
      g_type_add_interface_static (type, GIMP_TYPE_DOCKED,
132
 
                                   &docked_iface_info);
133
 
    }
134
 
 
135
 
  return type;
136
 
}
 
94
G_DEFINE_TYPE_WITH_CODE (GimpNavigationEditor, gimp_navigation_editor,
 
95
                         GIMP_TYPE_EDITOR,
 
96
                         G_IMPLEMENT_INTERFACE (GIMP_TYPE_DOCKED,
 
97
                                                gimp_navigation_editor_docked_iface_init))
 
98
 
 
99
#define parent_class gimp_navigation_editor_parent_class
 
100
 
137
101
 
138
102
static void
139
103
gimp_navigation_editor_class_init (GimpNavigationEditorClass *klass)
140
104
{
141
105
  GtkObjectClass *gtk_object_class = GTK_OBJECT_CLASS (klass);
142
106
 
143
 
  parent_class = g_type_class_peek_parent (klass);
144
 
 
145
107
  gtk_object_class->destroy = gimp_navigation_editor_destroy;
146
108
}
147
109
 
148
110
static void
 
111
gimp_navigation_editor_docked_iface_init (GimpDockedInterface *iface)
 
112
{
 
113
  iface->set_context = gimp_navigation_editor_set_context;
 
114
}
 
115
 
 
116
static void
149
117
gimp_navigation_editor_init (GimpNavigationEditor *editor)
150
118
{
151
119
  GtkWidget *frame;
152
120
 
153
 
  editor->shell = NULL;
 
121
  editor->context = NULL;
 
122
  editor->shell   = NULL;
154
123
 
155
124
  frame = gtk_frame_new (NULL);
156
125
  gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
157
126
  gtk_box_pack_start (GTK_BOX (editor), frame, TRUE, TRUE, 0);
158
127
  gtk_widget_show (frame);
159
128
 
160
 
  editor->view = gimp_view_new_by_types (GIMP_TYPE_NAVIGATION_VIEW,
 
129
  editor->view = gimp_view_new_by_types (NULL,
 
130
                                         GIMP_TYPE_NAVIGATION_VIEW,
161
131
                                         GIMP_TYPE_IMAGE,
162
132
                                         GIMP_VIEW_SIZE_MEDIUM, 0, TRUE);
163
133
  gtk_container_add (GTK_CONTAINER (frame), editor->view);
164
134
  gtk_widget_show (editor->view);
165
135
 
166
 
  g_signal_connect (editor->view, "marker_changed",
 
136
  g_signal_connect (editor->view, "marker-changed",
167
137
                    G_CALLBACK (gimp_navigation_editor_marker_changed),
168
138
                    editor);
169
139
  g_signal_connect (editor->view, "zoom",
177
147
}
178
148
 
179
149
static void
180
 
gimp_navigation_editor_docked_iface_init (GimpDockedInterface *docked_iface)
 
150
gimp_navigation_editor_destroy (GtkObject *object)
181
151
{
182
 
  docked_iface->set_context = gimp_navigation_editor_set_context;
 
152
  GimpNavigationEditor *editor = GIMP_NAVIGATION_EDITOR (object);
 
153
 
 
154
  if (editor->shell)
 
155
    gimp_navigation_editor_set_shell (editor, NULL);
 
156
 
 
157
  GTK_OBJECT_CLASS (parent_class)->destroy (object);
183
158
}
184
159
 
185
160
static void
186
161
gimp_navigation_editor_context_changed (GimpContext          *context,
187
 
                                        GimpDisplay          *gdisp,
 
162
                                        GimpDisplay          *display,
188
163
                                        GimpNavigationEditor *editor)
189
164
{
190
165
  GimpDisplayShell *shell = NULL;
191
166
 
192
 
  if (gdisp)
193
 
    shell = GIMP_DISPLAY_SHELL (gdisp->shell);
 
167
  if (display)
 
168
    shell = GIMP_DISPLAY_SHELL (display->shell);
194
169
 
195
170
  gimp_navigation_editor_set_shell (editor, shell);
196
171
}
200
175
                                    GimpContext *context)
201
176
{
202
177
  GimpNavigationEditor *editor  = GIMP_NAVIGATION_EDITOR (docked);
203
 
  GimpDisplay          *gdisp = NULL;
204
 
  GimpDisplayShell     *shell = NULL;
 
178
  GimpDisplay          *display = NULL;
 
179
  GimpDisplayShell     *shell   = NULL;
205
180
 
206
181
  if (editor->context)
207
182
    {
214
189
 
215
190
  if (context)
216
191
    {
217
 
      g_signal_connect (context, "display_changed",
 
192
      g_signal_connect (context, "display-changed",
218
193
                        G_CALLBACK (gimp_navigation_editor_context_changed),
219
194
                        editor);
220
195
 
221
 
      gdisp = gimp_context_get_display (context);
 
196
      display = gimp_context_get_display (context);
222
197
    }
223
198
 
224
 
  if (gdisp)
225
 
    shell = GIMP_DISPLAY_SHELL (gdisp->shell);
 
199
  gimp_view_renderer_set_context (GIMP_VIEW (editor->view)->renderer,
 
200
                                  context);
 
201
 
 
202
  if (display)
 
203
    shell = GIMP_DISPLAY_SHELL (display->shell);
226
204
 
227
205
  gimp_navigation_editor_set_shell (editor, shell);
228
206
}
229
207
 
230
 
static void
231
 
gimp_navigation_editor_destroy (GtkObject *object)
232
 
{
233
 
  GimpNavigationEditor *editor = GIMP_NAVIGATION_EDITOR (object);
234
 
 
235
 
  if (editor->shell)
236
 
    gimp_navigation_editor_set_shell (editor, NULL);
237
 
 
238
 
  GTK_OBJECT_CLASS (parent_class)->destroy (object);
239
 
}
240
 
 
241
208
 
242
209
/*  public functions  */
243
210
 
279
246
      gtk_container_add (GTK_CONTAINER (frame), GTK_WIDGET (editor));
280
247
      gtk_widget_show (GTK_WIDGET (editor));
281
248
 
282
 
      g_signal_connect (editor->view, "button_release_event",
 
249
      g_signal_connect (editor->view, "button-release-event",
283
250
                        G_CALLBACK (gimp_navigation_editor_button_release),
284
251
                        shell);
285
252
    }
356
323
 
357
324
  if (shell)
358
325
    {
359
 
      GimpDisplayConfig *config;
 
326
      Gimp              *gimp   = shell->display->image->gimp;
 
327
      GimpDisplayConfig *config = GIMP_DISPLAY_CONFIG (gimp->config);
360
328
      GimpView          *view;
361
329
 
362
330
      editor = g_object_new (GIMP_TYPE_NAVIGATION_EDITOR, NULL);
363
331
 
364
 
      config = GIMP_DISPLAY_CONFIG (shell->gdisp->gimage->gimp->config);
365
 
      view   = GIMP_VIEW (editor->view);
 
332
      view = GIMP_VIEW (editor->view);
366
333
 
367
334
      gimp_view_renderer_set_size (view->renderer,
368
335
                                   config->nav_preview_size * 3,
369
336
                                   view->renderer->border_width);
 
337
      gimp_view_renderer_set_context (view->renderer,
 
338
                                      gimp_get_user_context (gimp));
370
339
 
371
340
      gimp_navigation_editor_set_shell (editor, shell);
 
341
 
372
342
    }
373
343
  else
374
344
    {
375
345
      GtkWidget *hscale;
 
346
      GtkWidget *hbox;
376
347
 
377
348
      editor = g_object_new (GIMP_TYPE_NAVIGATION_EDITOR,
378
349
                             "menu-factory",    menu_factory,
412
383
 
413
384
      /* the zoom scale */
414
385
 
 
386
      hbox = gtk_hbox_new (FALSE, 6);
 
387
      gtk_box_pack_end (GTK_BOX (editor), hbox, FALSE, FALSE, 0);
 
388
      gtk_widget_show (hbox);
 
389
 
415
390
      editor->zoom_adjustment =
416
391
        GTK_ADJUSTMENT (gtk_adjustment_new (0.0, -8.0, 8.0, 0.5, 1.0, 0.0));
417
392
 
418
 
      g_signal_connect (editor->zoom_adjustment, "value_changed",
 
393
      g_signal_connect (editor->zoom_adjustment, "value-changed",
419
394
                        G_CALLBACK (gimp_navigation_editor_zoom_adj_changed),
420
395
                        editor);
421
396
 
422
397
      hscale = gtk_hscale_new (GTK_ADJUSTMENT (editor->zoom_adjustment));
423
398
      gtk_range_set_update_policy (GTK_RANGE (hscale), GTK_UPDATE_DELAYED);
424
399
      gtk_scale_set_draw_value (GTK_SCALE (hscale), FALSE);
425
 
      gtk_scale_set_digits (GTK_SCALE (hscale), 2);
426
 
      gtk_box_pack_end (GTK_BOX (editor), hscale, FALSE, FALSE, 0);
 
400
      gtk_box_pack_start (GTK_BOX (hbox), hscale, TRUE, TRUE, 0);
427
401
      gtk_widget_show (hscale);
428
402
 
429
403
      /* the zoom label */
430
404
 
431
405
      editor->zoom_label = gtk_label_new ("100%");
432
 
      gtk_box_pack_end (GTK_BOX (editor), editor->zoom_label, FALSE, FALSE, 0);
 
406
      gtk_label_set_width_chars (GTK_LABEL (editor->zoom_label), 7);
 
407
      gtk_box_pack_start (GTK_BOX (hbox), editor->zoom_label, FALSE, FALSE, 0);
433
408
      gtk_widget_show (editor->zoom_label);
434
 
 
435
 
      /* eek */
436
 
      {
437
 
        GtkRequisition requisition;
438
 
 
439
 
        gtk_widget_size_request (editor->zoom_label, &requisition);
440
 
        gtk_widget_set_size_request (editor->zoom_label,
441
 
                                     4 * requisition.width,
442
 
                                     requisition.height);
443
 
      }
444
409
    }
445
410
 
446
411
  gimp_view_renderer_set_background (GIMP_VIEW (editor->view)->renderer,
481
446
  if (editor->shell)
482
447
    {
483
448
      gimp_view_set_viewable (GIMP_VIEW (editor->view),
484
 
                              GIMP_VIEWABLE (shell->gdisp->gimage));
 
449
                              GIMP_VIEWABLE (shell->display->image));
485
450
 
486
451
      g_signal_connect (editor->shell, "scaled",
487
452
                        G_CALLBACK (gimp_navigation_editor_shell_scaled),
527
492
{
528
493
  if (editor->shell)
529
494
    {
530
 
      gdouble xratio;
531
 
      gdouble yratio;
532
 
      gint    xoffset;
533
 
      gint    yoffset;
534
 
 
535
 
      xratio = SCALEFACTOR_X (editor->shell);
536
 
      yratio = SCALEFACTOR_Y (editor->shell);
537
 
 
538
 
      xoffset = RINT (x * xratio - editor->shell->offset_x);
539
 
      yoffset = RINT (y * yratio - editor->shell->offset_y);
540
 
 
541
 
      gimp_display_shell_scroll (editor->shell, xoffset, yoffset);
 
495
      GimpDisplayShell *shell = editor->shell;
 
496
 
 
497
      gimp_display_shell_scroll (shell,
 
498
                                 RINT (x * shell->scale_x - shell->offset_x),
 
499
                                 RINT (y * shell->scale_y - shell->offset_y));
542
500
    }
543
501
}
544
502
 
605
563
gimp_navigation_editor_zoom_adj_changed (GtkAdjustment        *adj,
606
564
                                         GimpNavigationEditor *editor)
607
565
{
608
 
  gimp_display_shell_scale (editor->shell, GIMP_ZOOM_TO,
609
 
                            pow (2.0, adj->value));
 
566
  gimp_display_shell_scale (editor->shell, GIMP_ZOOM_TO, pow (2.0, adj->value));
610
567
}
611
568
 
612
569
static void
615
572
{
616
573
  if (editor->zoom_label)
617
574
    {
618
 
      gchar scale_str[MAX_SCALE_BUF];
619
 
 
620
 
      /* Update the zoom scale string */
621
 
      g_snprintf (scale_str, sizeof (scale_str),
622
 
                  shell->scale >= 0.15 ? "%.0f%%" : "%.2f%%",
623
 
                  editor->shell->scale * 100);
624
 
 
625
 
      gtk_label_set_text (GTK_LABEL (editor->zoom_label), scale_str);
 
575
      gchar *str;
 
576
 
 
577
      g_object_get (shell->zoom,
 
578
                    "percentage", &str,
 
579
                    NULL);
 
580
      gtk_label_set_text (GTK_LABEL (editor->zoom_label), str);
 
581
      g_free (str);
626
582
    }
627
583
 
628
584
  if (editor->zoom_adjustment)
629
585
    {
630
586
      gdouble val;
631
587
 
632
 
      val = log (CLAMP (editor->shell->scale, 1.0 / 256, 256.0) ) / G_LN2;
 
588
      val = log (gimp_zoom_model_get_factor (shell->zoom)) / G_LN2;
633
589
 
634
590
      g_signal_handlers_block_by_func (editor->zoom_adjustment,
635
591
                                       gimp_navigation_editor_zoom_adj_changed,
665
621
                                        GimpNavigationEditor *editor)
666
622
{
667
623
  gimp_view_set_viewable (GIMP_VIEW (editor->view),
668
 
                          GIMP_VIEWABLE (shell->gdisp->gimage));
 
624
                          GIMP_VIEWABLE (shell->display->image));
669
625
 
670
626
  if (GIMP_EDITOR (editor)->ui_manager)
671
627
    gimp_ui_manager_update (GIMP_EDITOR (editor)->ui_manager,
675
631
static void
676
632
gimp_navigation_editor_update_marker (GimpNavigationEditor *editor)
677
633
{
678
 
  GimpViewRenderer *renderer;
679
 
  gdouble           xratio;
680
 
  gdouble           yratio;
681
 
 
682
 
  renderer = GIMP_VIEW (editor->view)->renderer;
683
 
 
684
 
  xratio = SCALEFACTOR_X (editor->shell);
685
 
  yratio = SCALEFACTOR_Y (editor->shell);
686
 
 
687
 
  if (renderer->dot_for_dot != editor->shell->dot_for_dot)
688
 
    gimp_view_renderer_set_dot_for_dot (renderer,
689
 
                                        editor->shell->dot_for_dot);
 
634
  GimpViewRenderer *renderer = GIMP_VIEW (editor->view)->renderer;
 
635
  GimpDisplayShell *shell    = editor->shell;
 
636
 
 
637
  if (renderer->dot_for_dot != shell->dot_for_dot)
 
638
    gimp_view_renderer_set_dot_for_dot (renderer, shell->dot_for_dot);
690
639
 
691
640
  gimp_navigation_view_set_marker (GIMP_NAVIGATION_VIEW (editor->view),
692
 
                                   editor->shell->offset_x    / xratio,
693
 
                                   editor->shell->offset_y    / yratio,
694
 
                                   editor->shell->disp_width  / xratio,
695
 
                                   editor->shell->disp_height / yratio);
 
641
                                   shell->offset_x    / shell->scale_x,
 
642
                                   shell->offset_y    / shell->scale_y,
 
643
                                   shell->disp_width  / shell->scale_x,
 
644
                                   shell->disp_height / shell->scale_y);
696
645
}