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
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/*
 * Copyright (C) 2011  Red Hat, Inc.
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License as published by the Free Software Foundation; either
 * version 2 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Library General Public License for more details.
 *
 * You should have received a copy of the GNU Library General Public
 * License along with this library. If not, see <http://www.gnu.org/licenses/>.
 */

#include <ctk/ctk.h>

CtkClipboard *clipboard;
CtkWidget *image;
CtkWidget *label;

#define SIZE 256.

static void
image_request_cb (CtkClipboard *clipboard,
                  GdkPixbuf *pixbuf,
                  gpointer data)
{
  gdouble factor;
  char *str;

  if (pixbuf != NULL)
    {
      GdkPixbuf *copy;
      int height;
      int width;

      height = gdk_pixbuf_get_height (pixbuf);
      width = gdk_pixbuf_get_width (pixbuf);

      factor = MAX ((SIZE / height), (SIZE / width));

      copy = gdk_pixbuf_scale_simple (pixbuf, width * factor, height * factor, GDK_INTERP_BILINEAR);
      ctk_image_set_from_pixbuf (CTK_IMAGE (image), copy);
      g_object_unref (copy);
      str = g_strdup_printf ("<b>Image</b> %d \342\234\225 %d", width, height);
    }
  else
    {
      str = g_strdup ("<b>No image data</b>");
    }
  ctk_label_set_markup (CTK_LABEL (label), str);
  g_free (str);
}

static void
update_display (void)
{
  ctk_clipboard_request_image (clipboard, image_request_cb, NULL);
}

static void
on_owner_change (CtkClipboard *clipboard,<--- Parameter 'clipboard' can be declared as pointer to const
                 CdkEvent     *event,<--- Parameter 'event' can be declared as pointer to const
                 gpointer      user_data)
{
  update_display ();
}

static void
on_response (CtkDialog *dialog,
             gint       response_id,
             gpointer   user_data)
{
  switch (response_id)
    {
    case 0:
      /* copy large */
      {
        CtkIconTheme *theme;
        GdkPixbuf *pixbuf;
        theme = ctk_icon_theme_get_default ();
        pixbuf = ctk_icon_theme_load_icon (theme, "utilities-terminal", 1600, 0, NULL);
        g_assert_nonnull (pixbuf);
        ctk_clipboard_set_image (clipboard, pixbuf);
      }
      break;
    case 1:
      /* copy small */
      {
        CtkIconTheme *theme;
        GdkPixbuf *pixbuf;
        theme = ctk_icon_theme_get_default ();
        pixbuf = ctk_icon_theme_load_icon (theme, "utilities-terminal", 48, 0, NULL);
        g_assert_nonnull (pixbuf);
        ctk_clipboard_set_image (clipboard, pixbuf);
      }
      break;
    case CTK_RESPONSE_CLOSE:
    default:
      ctk_main_quit ();
      break;
    }
}

int
main (int argc, char **argv)
{
  CtkWidget *window;

  ctk_init (&argc, &argv);

  window = ctk_dialog_new_with_buttons ("Clipboard",
                                        NULL,
                                        0,
                                        "Copy Large", 0,
                                        "Copy Small", 1,
                                        "_Close", CTK_RESPONSE_CLOSE,
                                        NULL);

  image = ctk_image_new ();
  ctk_box_pack_start (CTK_BOX (ctk_dialog_get_content_area (CTK_DIALOG (window))), image, FALSE, FALSE, 0);
  label = ctk_label_new ("No data found");
  ctk_box_pack_start (CTK_BOX (ctk_dialog_get_content_area (CTK_DIALOG (window))), label, FALSE, FALSE, 0);

  g_signal_connect (window, "response", G_CALLBACK (on_response), NULL);

  clipboard = ctk_clipboard_get_for_display (ctk_widget_get_display (window),
                                             CDK_SELECTION_CLIPBOARD);
  g_signal_connect (clipboard, "owner-change", G_CALLBACK (on_owner_change), NULL);<--- You might need to cast the function pointer here<--- You might need to cast the function pointer here

  update_display ();

  ctk_widget_show_all (window);

  ctk_main ();

  return 0;
}