~ubuntu-branches/ubuntu/karmic/gimp/karmic-security

« back to all changes in this revision

Viewing changes to plug-ins/common/screenshot.c

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2008-10-06 13:30:41 UTC
  • mfrom: (1.1.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20081006133041-axco233xt49jobn7
Tags: 2.6.0-1ubuntu1
* Sync on debian and new version (lp: #276839)
* debian/patches/02_help-message.patch,
  debian/patches/03_gimp.desktop.in.in.patch:
  - updated some strings for ubuntu
* debian/rules:
  - updated translation templates

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
 
40
40
#ifdef HAVE_X11_EXTENSIONS_SHAPE_H
41
41
#include <X11/extensions/shape.h>
42
 
#endif /* HAVE_X11_EXTENSIONS_SHAPE_H */
 
42
#endif
43
43
 
44
44
#ifdef HAVE_X11_XMU_WINUTIL_H
45
45
#include <X11/Xmu/WinUtil.h>
46
 
#endif /* HAVE_X11_XMU_WINUTIL_H */
 
46
#endif
 
47
 
 
48
#ifdef HAVE_XFIXES
 
49
#include <X11/extensions/Xfixes.h>
 
50
#endif
47
51
 
48
52
#elif defined(GDK_WINDOWING_WIN32)
49
53
#include <windows.h>
163
167
  gint       y1;
164
168
  gint       x2;
165
169
  gint       y2;
 
170
  gboolean   show_cursor;
166
171
} ScreenshotValues;
167
172
 
168
173
static ScreenshotValues shootvals =
174
179
  0,            /* coords of region dragged out by pointer */
175
180
  0,
176
181
  0,
177
 
  0
 
182
  0,
 
183
  FALSE
178
184
};
179
185
 
180
186
 
242
248
                          "of the region to be grabbed.",
243
249
                          "Sven Neumann <sven@gimp.org>, "
244
250
                          "Henrik Brix Andersen <brix@gimp.org>",
245
 
                          "1998 - 2007",
246
 
                          "v1.0 (2007/05)",
 
251
                          "1998 - 2008",
 
252
                          "v1.1 (2008/04)",
247
253
                          N_("_Screenshot..."),
248
254
                          NULL,
249
255
                          GIMP_PLUGIN,
251
257
                          G_N_ELEMENTS (return_vals),
252
258
                          args, return_vals);
253
259
 
254
 
  gimp_plugin_menu_register (PLUG_IN_PROC, "<Toolbox>/File/Acquire");
255
 
  gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/File/Acquire");
 
260
  gimp_plugin_menu_register (PLUG_IN_PROC, "<Image>/File/Create/Acquire");
256
261
  gimp_plugin_icon_register (PLUG_IN_PROC, GIMP_ICON_TYPE_INLINE_PIXBUF,
257
262
                             screenshot_icon);
258
263
}
384
389
  gint          x_scr       = GDK_SCREEN_XNUMBER (screen);
385
390
  Window        x_root      = RootWindow (x_dpy, x_scr);
386
391
  Window        x_win       = None;
387
 
  GC            x_gc          = None;
 
392
  GC            x_gc        = NULL;
388
393
  Cursor        x_cursor    = XCreateFontCursor (x_dpy, GDK_CROSSHAIR);
389
394
  GdkKeymapKey *keys        = NULL;
390
395
  gint          status;
588
593
 
589
594
  XFreeCursor (x_dpy, x_cursor);
590
595
 
591
 
  if (x_gc != None)
 
596
  if (x_gc != NULL)
592
597
    XFreeGC (x_dpy, x_gc);
593
598
 
594
599
  return x_win;
818
823
  return image;
819
824
}
820
825
 
 
826
static void
 
827
add_cursor_image (gint32      image,
 
828
                  GdkDisplay *display)
 
829
{
 
830
#ifdef HAVE_XFIXES
 
831
  XFixesCursorImage *cursor;
 
832
  GimpDrawable      *drawable;
 
833
  GimpPixelRgn       rgn;
 
834
  gpointer           pr;
 
835
  gint32             layer;
 
836
  gint32             active;
 
837
 
 
838
  cursor = XFixesGetCursorImage (GDK_DISPLAY_XDISPLAY (display));
 
839
 
 
840
  if (!cursor)
 
841
    return;
 
842
 
 
843
  active = gimp_image_get_active_layer (image);
 
844
 
 
845
  layer = gimp_layer_new (image, _("Mouse Pointer"),
 
846
                          cursor->width, cursor->height,
 
847
                          GIMP_RGBA_IMAGE, 100.0, GIMP_NORMAL_MODE);
 
848
 
 
849
  drawable = gimp_drawable_get (layer);
 
850
 
 
851
  gimp_pixel_rgn_init (&rgn, drawable,
 
852
                       0, 0, drawable->width, drawable->height, TRUE, FALSE);
 
853
 
 
854
  for (pr = gimp_pixel_rgns_register (1, &rgn);
 
855
       pr != NULL;
 
856
       pr = gimp_pixel_rgns_process (pr))
 
857
    {
 
858
      const gulong *src  = cursor->pixels + rgn.y * cursor->width + rgn.x;
 
859
      guchar       *dest = rgn.data;
 
860
      gint          x, y;
 
861
 
 
862
      for (y = 0; y < rgn.h; y++)
 
863
        {
 
864
          const gulong *s = src;
 
865
          guchar       *d = dest;
 
866
 
 
867
          for (x = 0; x < rgn.w; x++)
 
868
            {
 
869
              /*  the cursor pixels are pre-multiplied ARGB  */
 
870
              guint a = (*s >> 24) & 0xff;
 
871
              guint r = (*s >> 16) & 0xff;
 
872
              guint g = (*s >> 8)  & 0xff;
 
873
              guint b = (*s >> 0)  & 0xff;
 
874
 
 
875
              d[0] = a ? (r * 255) / a : r;
 
876
              d[1] = a ? (g * 255) / a : g;
 
877
              d[2] = a ? (b * 255) / a : b;
 
878
              d[3] = a;
 
879
 
 
880
              s++;
 
881
              d += 4;
 
882
            }
 
883
 
 
884
          src  += cursor->width;
 
885
          dest += rgn.rowstride;
 
886
        }
 
887
    }
 
888
 
 
889
  gimp_drawable_detach (drawable);
 
890
 
 
891
  gimp_image_add_layer (image, layer, -1);
 
892
  gimp_layer_set_offsets (layer,
 
893
                          cursor->x - cursor->xhot, cursor->y - cursor->yhot);
 
894
 
 
895
  gimp_image_set_active_layer (image, active);
 
896
#endif
 
897
}
 
898
 
821
899
 
822
900
/* The main Screenshot function */
823
901
 
891
969
                                             0, 0, rect.width, rect.height);
892
970
 
893
971
  gdk_display_beep (display);
894
 
  gdk_flush ();
895
972
 
896
973
  if (! screenshot)
897
974
    {
918
995
 
919
996
  g_free (name);
920
997
 
 
998
  /* FIXME: Some time might have passed until we get here.
 
999
   *        The cursor image should be grabbed together with the screenshot.
 
1000
   */
 
1001
  if (shootvals.shoot_type == SHOOT_ROOT && shootvals.show_cursor)
 
1002
    add_cursor_image (image, display);
 
1003
 
921
1004
  return image;
922
1005
}
923
1006
 
1038
1121
                                               _("Take a screenshot of "
1039
1122
                                                 "a single _window"));
1040
1123
  radio_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
1041
 
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
1042
 
                                shootvals.shoot_type == SHOOT_WINDOW);
1043
1124
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
1044
1125
  gtk_widget_show (button);
1045
1126
 
1051
1132
                    notebook);
1052
1133
 
1053
1134
#ifdef HAVE_X11_XMU_WINUTIL_H
1054
 
 
 
1135
  /*  window decorations  */
1055
1136
  hbox = gtk_hbox_new (FALSE, 12);
1056
1137
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
1057
1138
  gtk_widget_show (hbox);
1069
1150
 
1070
1151
#endif /* HAVE_X11_XMU_WINUTIL_H */
1071
1152
 
 
1153
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
 
1154
                                shootvals.shoot_type == SHOOT_WINDOW);
1072
1155
 
1073
1156
  /*  whole screen  */
1074
1157
  button = gtk_radio_button_new_with_mnemonic (radio_group,
1075
1158
                                               _("Take a screenshot of "
1076
1159
                                                 "the entire _screen"));
1077
1160
  radio_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (button));
 
1161
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
 
1162
  gtk_widget_show (button);
 
1163
 
 
1164
  g_object_set_data (G_OBJECT (button), "gimp-item-data",
 
1165
                     GINT_TO_POINTER (SHOOT_ROOT));
 
1166
 
 
1167
  g_signal_connect (button, "toggled",
 
1168
                    G_CALLBACK (shoot_radio_button_toggled),
 
1169
                    notebook);
 
1170
 
 
1171
#ifdef HAVE_XFIXES
 
1172
  /*  mouse pointer  */
 
1173
  hbox = gtk_hbox_new (FALSE, 12);
 
1174
  gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
 
1175
  gtk_widget_show (hbox);
 
1176
 
 
1177
  toggle = gtk_check_button_new_with_mnemonic (_("Include _mouse pointer"));
 
1178
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (toggle),
 
1179
                                shootvals.show_cursor);
 
1180
  gtk_box_pack_start (GTK_BOX (hbox), toggle, TRUE, TRUE, 24);
 
1181
  gtk_widget_show (toggle);
 
1182
 
 
1183
  gtk_widget_set_sensitive (toggle, FALSE);
 
1184
  g_object_set_data (G_OBJECT (button), "set_sensitive", toggle);
 
1185
 
 
1186
  g_signal_connect (toggle, "toggled",
 
1187
                    G_CALLBACK (gimp_toggle_button_update),
 
1188
                    &shootvals.show_cursor);
 
1189
 
 
1190
#endif
 
1191
 
1078
1192
  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
1079
1193
                                shootvals.shoot_type == SHOOT_ROOT);
1080
 
  gtk_box_pack_start (GTK_BOX (vbox), button, FALSE, FALSE, 0);
1081
 
  gtk_widget_show (button);
1082
 
 
1083
 
  g_object_set_data (G_OBJECT (button), "gimp-item-data",
1084
 
                     GINT_TO_POINTER (SHOOT_ROOT));
1085
 
 
1086
 
  g_signal_connect (button, "toggled",
1087
 
                    G_CALLBACK (shoot_radio_button_toggled),
1088
 
                    notebook);
1089
1194
 
1090
1195
  /*  dragged region  */
1091
1196
  button = gtk_radio_button_new_with_mnemonic (radio_group,