Exemple #1
0
static gboolean
regrab_idle (GtkWidget *image)
{
  GdkPixbuf *magnified;
  GtkAllocation allocation;

  gtk_widget_get_allocation (image, &allocation);

  if (allocation.width != last_grab_allocation.width ||
      allocation.height != last_grab_allocation.height)
    {
      last_grab_width = rint (allocation.width / width_factor);
      last_grab_height = rint (allocation.height / height_factor);
      last_grab_allocation = allocation;

      magnified = get_pixbuf ();

      gtk_image_set_from_pixbuf (GTK_IMAGE (image), magnified);

      g_object_unref (G_OBJECT (magnified));
    }

  regrab_idle_id = 0;

  return FALSE;
}
GdkPixbuf *
ide_ctags_completion_provider_get_proposal_icon (IdeCtagsCompletionProvider *self,
                                                 GtkSourceCompletionContext *context,
                                                 const IdeCtagsIndexEntry   *entry)
{
  g_return_val_if_fail (IDE_IS_CTAGS_COMPLETION_PROVIDER (self), NULL);

  return get_pixbuf (self, context, entry);
}
Exemple #3
0
static void
popup_menu_cb (GtkStatusIcon * icon, guint button, guint activate_time, gpointer data)
{
  GtkWidget *menu;
  GtkWidget *item;
  GSList *m;

  if (!menu_data)
    return;

  menu = gtk_menu_new ();
  for (m = menu_data; m; m = m->next)
    {
      MenuData *d = (MenuData *) m->data;

      if (d->name)
        {
          if (d->icon)
            {
              GdkPixbuf *pb = get_pixbuf (d->icon, YAD_SMALL_ICON);
              item = gtk_image_menu_item_new_with_mnemonic (d->name);
              if (pb)
                {
                  gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (item), gtk_image_new_from_pixbuf (pb));
                  g_object_unref (pb);
                }
            }
          else
            {
              GtkStockItem it;
              if (gtk_stock_lookup (d->name, &it))
                item = gtk_image_menu_item_new_from_stock (d->name, NULL);
              else
                item = gtk_menu_item_new_with_mnemonic (d->name);
            }
          g_signal_connect (GTK_MENU_ITEM (item), "activate",
                            G_CALLBACK (popup_menu_item_activate_cb), (gpointer) d->action);
        }
      else
        item = gtk_separator_menu_item_new ();

      gtk_widget_show (item);
      gtk_menu_shell_append (GTK_MENU_SHELL (menu), item);
    }
  gtk_menu_popup (GTK_MENU (menu), NULL, NULL, gtk_status_icon_position_menu, icon, button, activate_time);
}
Exemple #4
0
static void
grab_area_at_mouse (GtkWidget *invisible,
                    int        x_root,
                    int        y_root)
{
  GdkPixbuf *magnified;
  int width, height;
  GtkWidget *widget;

  width = last_grab_width;
  height = last_grab_height;

  last_grab_x = x_root;
  last_grab_y = y_root;
  last_grab_width = width;
  last_grab_height = height;

  magnified = get_pixbuf ();

  display_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
  gtk_window_set_default_size (GTK_WINDOW (display_window),
                               last_grab_width, last_grab_height);
  widget = gtk_image_new_from_pixbuf (magnified);
  gtk_widget_set_size_request (widget, 40, 40);
  gtk_container_add (GTK_CONTAINER (display_window), widget);
  g_object_unref (G_OBJECT (magnified));

  g_object_add_weak_pointer (G_OBJECT (display_window),
                             (gpointer) &display_window);

  g_signal_connect (G_OBJECT (display_window), "destroy",
                    G_CALLBACK (gtk_main_quit), NULL);

  g_signal_connect_after (G_OBJECT (widget), "size_allocate", G_CALLBACK (image_resized), NULL);

  gtk_widget_show_all (display_window);
}
Exemple #5
0
gint
yad_print_run (void)
{
  GtkWidget *dlg;
  GtkWidget *box, *img, *lbl;
  gchar *uri, *job_name = NULL;
  GtkPrintCapabilities pcap;
  GtkPrintOperationAction act = GTK_PRINT_OPERATION_ACTION_PRINT;
  gint resp, ret = 0;
  GError *err = NULL;

  /* check if file is exists */
  if (options.common_data.uri && options.common_data.uri[0])
    {
      if (!g_file_test (options.common_data.uri, G_FILE_TEST_EXISTS))
        {
          g_printerr (_("File %s not found.\n"), options.common_data.uri);
          return 1;
        }
    }
  else
    {
      g_printerr (_("Filename is not specified.\n"));
      return 1;
    }

  /* create print dialog */
  dlg = gtk_print_unix_dialog_new (options.data.dialog_title, NULL);
  gtk_window_set_type_hint (GTK_WINDOW (dlg), GDK_WINDOW_TYPE_HINT_NORMAL);
  gtk_print_unix_dialog_set_embed_page_setup (GTK_PRINT_UNIX_DIALOG (dlg), TRUE);
  pcap = GTK_PRINT_CAPABILITY_PAGE_SET | GTK_PRINT_CAPABILITY_COPIES |
    GTK_PRINT_CAPABILITY_COLLATE | GTK_PRINT_CAPABILITY_REVERSE |
    GTK_PRINT_CAPABILITY_NUMBER_UP | GTK_PRINT_CAPABILITY_NUMBER_UP_LAYOUT;
  if (options.common_data.preview && options.print_data.type != YAD_PRINT_RAW)
    pcap |= GTK_PRINT_CAPABILITY_PREVIEW;
  gtk_print_unix_dialog_set_manual_capabilities (GTK_PRINT_UNIX_DIALOG (dlg), pcap);

  if (!settings.print_settings)
    settings.print_settings = gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (dlg));

  uri = g_build_filename (g_get_current_dir (), "yad.pdf", NULL);
  gtk_print_settings_set (settings.print_settings, "output-uri", g_filename_to_uri (uri, NULL, NULL));
  g_free (uri);

  gtk_print_unix_dialog_set_settings (GTK_PRINT_UNIX_DIALOG (dlg), settings.print_settings);

  if (settings.page_setup)
    gtk_print_unix_dialog_set_page_setup (GTK_PRINT_UNIX_DIALOG (dlg), settings.page_setup);

  /* set window behavior */
  gtk_widget_set_name (dlg, "yad-dialog-window");
  if (options.data.sticky)
    gtk_window_stick (GTK_WINDOW (dlg));
  gtk_window_set_resizable (GTK_WINDOW (dlg), !options.data.fixed);
  gtk_window_set_keep_above (GTK_WINDOW (dlg), options.data.ontop);
  gtk_window_set_decorated (GTK_WINDOW (dlg), !options.data.undecorated);
  gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dlg), options.data.skip_taskbar);
  gtk_window_set_skip_pager_hint (GTK_WINDOW (dlg), options.data.skip_taskbar);

  /* set window size and position */
  if (!options.data.geometry)
    {
      gtk_window_set_default_size (GTK_WINDOW (dlg), options.data.width, options.data.height);
      if (options.data.center)
        gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_CENTER);
      else if (options.data.mouse)
        gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_MOUSE);
    }
  else
    {
      /* parse geometry, if given. must be after showing widget */
      gtk_widget_realize (dlg);
      gtk_window_parse_geometry (GTK_WINDOW (dlg), options.data.geometry);
    }

  /* create yad's top box */
  if (options.data.dialog_text || options.data.dialog_image)
    {
#if !GTK_CHECK_VERSION(3,0,0)
      box = gtk_hbox_new (FALSE, 0);
#else
      box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
#endif

      if (options.data.dialog_image)
        {
          GdkPixbuf *pb = NULL;

          pb = get_pixbuf (options.data.dialog_image, YAD_BIG_ICON);
          img = gtk_image_new_from_pixbuf (pb);
          if (pb)
            g_object_unref (pb);

          gtk_widget_set_name (img, "yad-dialog-image");
          gtk_box_pack_start (GTK_BOX (box), img, FALSE, FALSE, 2);
        }
      if (options.data.dialog_text)
        {
          gchar *buf = g_strcompress (options.data.dialog_text);

          lbl = gtk_label_new (NULL);
          if (!options.data.no_markup)
            gtk_label_set_markup (GTK_LABEL (lbl), buf);
          else
            gtk_label_set_text (GTK_LABEL (lbl), buf);
          gtk_widget_set_name (lbl, "yad-dialog-label");
          gtk_label_set_selectable (GTK_LABEL (lbl), options.data.selectable_labels);
          gtk_misc_set_alignment (GTK_MISC (lbl), options.data.text_align, 0.5);
          if (options.data.geometry || options.data.width != -1)
            gtk_label_set_line_wrap (GTK_LABEL (lbl), TRUE);
          gtk_box_pack_start (GTK_BOX (box), lbl, TRUE, TRUE, 2);
          g_signal_connect (G_OBJECT (lbl), "size-allocate", G_CALLBACK (size_allocate_cb), NULL);
          g_free (buf);
        }

      /* add tob box to dialog */
      gtk_widget_show_all (box);
      gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), box, TRUE, TRUE, 5);
      gtk_box_reorder_child (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), box, 0);
    }

  do
    {
      resp = gtk_dialog_run (GTK_DIALOG (dlg));
      switch (resp)
        {
        case GTK_RESPONSE_APPLY:   /* ask for preview */
          act = GTK_PRINT_OPERATION_ACTION_PREVIEW;
        case GTK_RESPONSE_OK:      /* run print */
          settings.print_settings = gtk_print_unix_dialog_get_settings (GTK_PRINT_UNIX_DIALOG (dlg));
          settings.page_setup = gtk_print_unix_dialog_get_page_setup (GTK_PRINT_UNIX_DIALOG (dlg));
          job_name = g_strdup_printf ("yad-%s-%d", g_path_get_basename (options.common_data.uri), getpid ());
          if (options.print_data.type != YAD_PRINT_RAW)
            {
              /* print text or image */
              GtkPrintOperation *op = gtk_print_operation_new ();
              gtk_print_operation_set_unit (op, GTK_UNIT_POINTS);
              gtk_print_operation_set_print_settings (op, settings.print_settings);
              gtk_print_operation_set_default_page_setup (op, settings.page_setup);
              gtk_print_operation_set_job_name (op, job_name);

              switch (options.print_data.type)
                {
                case YAD_PRINT_TEXT:
                  g_signal_connect (G_OBJECT (op), "begin-print", G_CALLBACK (begin_print_text), NULL);
                  g_signal_connect (G_OBJECT (op), "draw-page", G_CALLBACK (draw_page_text), NULL);
                  break;
                case YAD_PRINT_IMAGE:
                  gtk_print_operation_set_n_pages (op, 1);
                  g_signal_connect (G_OBJECT (op), "draw-page", G_CALLBACK (draw_page_image), NULL);
                  break;
                default:;
                }

              if (gtk_print_operation_run (op, act, NULL, &err) == GTK_PRINT_OPERATION_RESULT_ERROR)
                {
                  g_printerr (_("Printing failed: %s\n"), err->message);
                  ret = 1;
                }
            }
          else
            {
              /* print raw ps or pdf data */
              GtkPrinter *prnt;
              GtkPrintJob *job;

              prnt = gtk_print_unix_dialog_get_selected_printer (GTK_PRINT_UNIX_DIALOG (dlg));

              if (g_str_has_suffix (options.common_data.uri, ".ps"))
                {
                  if (!gtk_printer_accepts_ps (prnt))
                    {
                      g_printerr (_("Printer doesn't support ps format.\n"));
                      ret = 1;
                    }
                }
              else if (g_str_has_suffix (options.common_data.uri, ".pdf"))
                {
                  if (!gtk_printer_accepts_pdf (prnt))
                    {
                      g_printerr (_("Printer doesn't support pdf format.\n"));
                      ret = 1;
                    }
                }
              else
                {
                  g_printerr (_("This file type is not supported for raw printing.\n"));
                  ret = 1;
                }
              if (ret == 1)
                break;

              job = gtk_print_job_new (job_name, prnt, settings.print_settings, settings.page_setup);
              if (gtk_print_job_set_source_file (job, options.common_data.uri, &err))
                {
                  gtk_print_job_send (job, (GtkPrintJobCompleteFunc) raw_print_done, &ret, NULL);
                  gtk_main ();
                }
              else
                {
                  g_printerr (_("Load source file failed: %s\n"), err->message);
                  ret = 1;
                }
            }
          break;
        default:
          ret = 1;
          break;
        }
    }
  while (resp == GTK_RESPONSE_APPLY);

  gtk_widget_destroy (dlg);
  write_settings ();
  return ret;
}
Exemple #6
0
GtkWidget *
entry_create_widget (GtkWidget * dlg)
{
  GtkWidget *c, *l = NULL, *w = NULL;

#if !GTK_CHECK_VERSION(3,0,0)
  w = gtk_hbox_new (FALSE, 5);
#else
  w = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 5);
#endif

  if (options.entry_data.entry_label)
    {
      l = gtk_label_new (NULL);
      if (options.data.no_markup)
        gtk_label_set_text_with_mnemonic (GTK_LABEL (l), options.entry_data.entry_label);
      else
        gtk_label_set_markup_with_mnemonic (GTK_LABEL (l), options.entry_data.entry_label);
      gtk_widget_set_name (l, "yad-entry-label");
      gtk_box_pack_start (GTK_BOX (w), l, FALSE, FALSE, 1);
    }

  if (options.entry_data.numeric)
    {
      gdouble min, max, step, val;
      guint prec;

      min = 0.0;
      max = 65535.0;
      step = 1.0;
      prec = 0;

      if (options.extra_data && options.extra_data[0])
        {
          min = g_ascii_strtod (options.extra_data[0], NULL);
          if (options.extra_data[1])
            max = g_ascii_strtod (options.extra_data[1], NULL);
          if (options.extra_data[2])
            step = g_ascii_strtod (options.extra_data[2], NULL);
          if (options.extra_data[3])
            {
              prec = (guint) g_ascii_strtoull (options.extra_data[3], NULL, 0);
              if (prec > 20)
                prec = 20;
            }
        }

      c = entry = gtk_spin_button_new_with_range (min, max, step);
      gtk_entry_set_alignment (GTK_ENTRY (c), 1.0);
      gtk_spin_button_set_digits (GTK_SPIN_BUTTON (c), prec);
      gtk_widget_set_name (entry, "yad-entry-spin");

      if (options.entry_data.entry_text)
        {
          val = g_ascii_strtod (options.entry_data.entry_text, NULL);

          if (min >= max)
            {
              g_printerr (_("Maximum value must be greater than minimum value.\n"));
              min = 0.0;
              max = 65535.0;
            }

          if (val < min)
            {
              g_printerr (_("Initial value less than minimal.\n"));
              val = min;
            }
          else if (val > max)
            {
              g_printerr (_("Initial value greater than maximum.\n"));
              val = max;
            }

          gtk_spin_button_set_value (GTK_SPIN_BUTTON (c), val);
        }
    }
  else if (!options.entry_data.completion && options.extra_data && *options.extra_data)
    {
      gint active, i;

      if (options.common_data.editable || settings.combo_always_editable)
        {
#if GTK_CHECK_VERSION(2,24,0)
          c = gtk_combo_box_text_new_with_entry ();
#else
          c = gtk_combo_box_entry_new_text ();
#endif
          gtk_widget_set_name (c, "yad-entry-edit-combo");
          entry = gtk_bin_get_child (GTK_BIN (c));
          if (options.entry_data.licon)
            {
              GdkPixbuf *pb = get_pixbuf (options.entry_data.licon, YAD_SMALL_ICON);

              if (pb)
                gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, pb);
            }
          if (options.entry_data.ricon)
            {
              GdkPixbuf *pb = get_pixbuf (options.entry_data.ricon, YAD_SMALL_ICON);

              if (pb)
                gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY, pb);
            }
        }
      else
        {
#if GTK_CHECK_VERSION(2,24,0)
          c = entry = gtk_combo_box_text_new ();
#else
          c = entry = gtk_combo_box_new_text ();
#endif
          gtk_widget_set_name (c, "yad-entry-combo");
          is_combo = TRUE;
        }

      i = 0;
      active = -1;
      while (options.extra_data[i] != NULL)
        {
          if (options.entry_data.entry_text &&
              g_ascii_strcasecmp (options.extra_data[i], options.entry_data.entry_text) == 0)
            active = i;
#if GTK_CHECK_VERSION(2,24,0)
          gtk_combo_box_text_append_text (GTK_COMBO_BOX_TEXT (c), options.extra_data[i]);
#else
          gtk_combo_box_append_text (GTK_COMBO_BOX (c), options.extra_data[i]);
#endif
          i++;
        }

      if (options.entry_data.entry_text && active == -1)
        {
#if GTK_CHECK_VERSION(2,24,0)
          gtk_combo_box_text_prepend_text (GTK_COMBO_BOX_TEXT (c), options.entry_data.entry_text);
#else
          gtk_combo_box_prepend_text (GTK_COMBO_BOX (c), options.entry_data.entry_text);
#endif
        }

      /* set first iter active */
      if (!options.common_data.editable)
        gtk_combo_box_set_active (GTK_COMBO_BOX (c), (active != -1 ? active : 0));
    }
  else
    {
      c = entry = gtk_entry_new ();
      gtk_widget_set_name (c, "yad-entry-widget");

      gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE);

      if (options.entry_data.entry_text)
        gtk_entry_set_text (GTK_ENTRY (entry), options.entry_data.entry_text);

      if (options.entry_data.hide_text)
        g_object_set (G_OBJECT (entry), "visibility", FALSE, NULL);

      if (options.entry_data.completion)
        {
          GtkEntryCompletion *completion;
          GtkTreeModel *completion_model;

          completion = gtk_entry_completion_new ();
          gtk_entry_set_completion (GTK_ENTRY (entry), completion);

          completion_model = create_completion_model ();
          gtk_entry_completion_set_model (completion, completion_model);
          g_object_unref (completion_model);

          gtk_entry_completion_set_text_column (completion, 0);
          g_object_unref (completion);
        }

      if (options.entry_data.licon)
        {
          GdkPixbuf *pb = get_pixbuf (options.entry_data.licon, YAD_SMALL_ICON);

          if (pb)
            gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (entry), GTK_ENTRY_ICON_PRIMARY, pb);
        }
      if (options.entry_data.ricon)
        {
          GdkPixbuf *pb = get_pixbuf (options.entry_data.ricon, YAD_SMALL_ICON);

          if (pb)
            gtk_entry_set_icon_from_pixbuf (GTK_ENTRY (entry), GTK_ENTRY_ICON_SECONDARY, pb);
        }
    }

  if (l)
    gtk_label_set_mnemonic_widget (GTK_LABEL (l), entry);

  if (!is_combo)
    g_signal_connect (G_OBJECT (entry), "activate", G_CALLBACK (entry_activate_cb), dlg);
  else
    g_signal_connect (G_OBJECT (entry), "key-press-event", G_CALLBACK (combo_activate_cb), dlg);

  if (options.entry_data.licon || options.entry_data.ricon)
    g_signal_connect (G_OBJECT (entry), "icon-press", G_CALLBACK (icon_cb), NULL);

  gtk_box_pack_start (GTK_BOX (w), c, TRUE, TRUE, 1);

  return w;
}
Exemple #7
0
GtkWidget *
create_dialog (void)
{
    GtkWidget *dlg;
    GtkWidget *hbox, *vbox, *hbox2, *bbox;
    GtkWidget *image;
    GtkWidget *text;
    GtkWidget *main_widget = NULL;
    GtkWidget *topb = NULL;

    /* create dialog window */
    dlg = gtk_dialog_new ();
    if (options.data.splash)
        gtk_window_set_type_hint (GTK_WINDOW (dlg), GDK_WINDOW_TYPE_HINT_SPLASHSCREEN);
    else
        gtk_window_set_type_hint (GTK_WINDOW (dlg), GDK_WINDOW_TYPE_HINT_NORMAL);
    gtk_window_set_title (GTK_WINDOW (dlg), options.data.dialog_title);
    gtk_widget_set_name (dlg, "yad-dialog-window");

#ifndef  G_OS_WIN32
    if (options.parent)
    {
        gdk_window_set_transient_for (gtk_widget_get_window (dlg),
                                      gdk_x11_window_foreign_new_for_display (gdk_display_get_default (),
                                              options.parent));
    }
#endif

    if (options.data.no_escape)
        g_signal_connect (G_OBJECT (dlg), "close", G_CALLBACK (ignore_close_cb) , NULL);

    /* get buttons container */
    bbox = gtk_dialog_get_action_area (GTK_DIALOG (dlg));

    /* set window icon */
    if (options.data.window_icon)
    {
        if (g_file_test (options.data.window_icon, G_FILE_TEST_EXISTS))
            gtk_window_set_icon_from_file (GTK_WINDOW (dlg), options.data.window_icon, NULL);
        else
            gtk_window_set_icon_name (GTK_WINDOW (dlg), options.data.window_icon);
    }

    /* set window borders */
    if (options.data.borders == -1)
        options.data.borders = (gint) gtk_container_get_border_width (GTK_CONTAINER (dlg));
    gtk_container_set_border_width (GTK_CONTAINER (dlg), (guint) options.data.borders);

    /* set window size and position */
    if (!options.data.geometry && !options.data.maximized && !options.data.fullscreen)
    {
        gtk_window_set_default_size (GTK_WINDOW (dlg), options.data.width, options.data.height);
        if (options.data.center)
            gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_CENTER);
        else if (options.data.mouse)
            gtk_window_set_position (GTK_WINDOW (dlg), GTK_WIN_POS_MOUSE);
    }

    /* set window behavior */
    if (options.data.sticky)
        gtk_window_stick (GTK_WINDOW (dlg));
    gtk_window_set_keep_above (GTK_WINDOW (dlg), options.data.ontop);
    gtk_window_set_decorated (GTK_WINDOW (dlg), !options.data.undecorated);
    gtk_window_set_skip_taskbar_hint (GTK_WINDOW (dlg), options.data.skip_taskbar);
    gtk_window_set_skip_pager_hint (GTK_WINDOW (dlg), options.data.skip_taskbar);

    /* create timeout indicator widget */
    if (options.data.timeout)
    {
        if (G_LIKELY (options.data.to_indicator) && g_ascii_strcasecmp (options.data.to_indicator, "none"))
        {
            topb = gtk_progress_bar_new ();
            gtk_progress_bar_set_fraction (GTK_PROGRESS_BAR (topb), 1.0);
            gtk_widget_set_name (topb, "yad-timeout-indicator");
        }
    }

    /* add top label widgets */
#if !GTK_CHECK_VERSION(3,0,0)
    hbox = hbox2 = gtk_hbox_new (FALSE, 0);
#else
    hbox = hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
#endif
    gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), hbox, TRUE, TRUE, 5);
#if !GTK_CHECK_VERSION(3,0,0)
    vbox = gtk_vbox_new (FALSE, 0);
#else
    vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 0);
#endif

    /* add timeout indicator */
    if (topb)
    {
        if (g_ascii_strcasecmp (options.data.to_indicator, "top") == 0)
        {
#if !GTK_CHECK_VERSION(3,0,0)
            gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (topb), GTK_PROGRESS_LEFT_TO_RIGHT);
#endif
            gtk_box_pack_start (GTK_BOX (vbox), topb, FALSE, FALSE, 2);
        }
        else if (g_ascii_strcasecmp (options.data.to_indicator, "bottom") == 0)
        {
#if !GTK_CHECK_VERSION(3,0,0)
            gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (topb), GTK_PROGRESS_LEFT_TO_RIGHT);
#endif
            gtk_box_pack_end (GTK_BOX (vbox), topb, FALSE, FALSE, 2);
        }
        else if (g_ascii_strcasecmp (options.data.to_indicator, "left") == 0)
        {
#if !GTK_CHECK_VERSION(3,0,0)
            gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (topb), GTK_PROGRESS_BOTTOM_TO_TOP);
#endif
            gtk_box_pack_start (GTK_BOX (hbox), topb, FALSE, FALSE, 2);
        }
        else if (g_ascii_strcasecmp (options.data.to_indicator, "right") == 0)
        {
#if !GTK_CHECK_VERSION(3,0,0)
            gtk_progress_bar_set_orientation (GTK_PROGRESS_BAR (topb), GTK_PROGRESS_BOTTOM_TO_TOP);
#endif
            gtk_box_pack_end (GTK_BOX (hbox), topb, FALSE, FALSE, 2);
        }
        if (settings.show_remain)
        {
            gchar *lbl = g_strdup_printf (_("%d sec"), options.data.timeout);
#if GTK_CHECK_VERSION(3,0,0)
            gtk_progress_bar_set_show_text (GTK_PROGRESS_BAR (topb), TRUE);
#endif
            gtk_progress_bar_set_text (GTK_PROGRESS_BAR (topb), lbl);
            g_free (lbl);
        }
    }

    /* must be after indicator! */
    gtk_box_pack_end (GTK_BOX (hbox), vbox, TRUE, TRUE, 0);

    if (options.data.image_on_top)
    {
#if !GTK_CHECK_VERSION(3,0,0)
        hbox2 = gtk_hbox_new (FALSE, 0);
#else
        hbox2 = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
#endif
        gtk_box_pack_start (GTK_BOX (vbox), hbox2, FALSE, FALSE, 0);
    }

    if (options.data.dialog_image)
    {
        GdkPixbuf *pb = NULL;

        pb = get_pixbuf (options.data.dialog_image, YAD_BIG_ICON);
        image = gtk_image_new_from_pixbuf (pb);
        if (pb)
            g_object_unref (pb);

        gtk_widget_set_name (image, "yad-dialog-image");
        gtk_misc_set_alignment (GTK_MISC (image), 0.5, 0.0);
        gtk_box_pack_start (GTK_BOX (hbox2), image, FALSE, FALSE, 2);
    }
    if (options.data.dialog_text)
    {
        /* for dnd's tooltip we don't need text label */
        if (options.mode != YAD_MODE_DND || !options.dnd_data.tooltip)
        {
            gchar *buf = g_strcompress (options.data.dialog_text);

            text = gtk_label_new (NULL);
            if (!options.data.no_markup)
                gtk_label_set_markup (GTK_LABEL (text), buf);
            else
                gtk_label_set_text (GTK_LABEL (text), buf);
            g_free (buf);

            gtk_widget_set_name (text, "yad-dialog-label");
            gtk_label_set_line_wrap (GTK_LABEL (text), TRUE);
            gtk_label_set_selectable (GTK_LABEL (text), options.data.selectable_labels);
            gtk_label_set_justify (GTK_LABEL (text), options.data.text_align);
            switch (options.data.text_align)
            {
            case GTK_JUSTIFY_LEFT:
            case GTK_JUSTIFY_FILL:
                gtk_misc_set_alignment (GTK_MISC (text), 0.0, 0.5);
                break;
            case GTK_JUSTIFY_CENTER:
                gtk_misc_set_alignment (GTK_MISC (text), 0.5, 0.5);
                break;
            case GTK_JUSTIFY_RIGHT:
                gtk_misc_set_alignment (GTK_MISC (text), 1.0, 0.5);
                break;
            }
            if (options.data.image_on_top)
                gtk_box_pack_start (GTK_BOX (hbox2), text, TRUE, TRUE, 2);
            else
                gtk_box_pack_start (GTK_BOX (vbox), text, FALSE, FALSE, 2);
#if !GTK_CHECK_VERSION(3,0,0)
            if (!options.data.fixed)
                g_signal_connect (G_OBJECT (text), "size-allocate", G_CALLBACK (text_size_allocate_cb), NULL);
#endif
        }
    }

    /* add main widget */
    switch (options.mode)
    {
    case YAD_MODE_CALENDAR:
        main_widget = calendar_create_widget (dlg);
        break;
    case YAD_MODE_COLOR:
        main_widget = color_create_widget (dlg);
        break;
    case YAD_MODE_DND:
        dnd_init (dlg);
        break;
    case YAD_MODE_ENTRY:
        main_widget = entry_create_widget (dlg);
        break;
    case YAD_MODE_FILE:
        main_widget = file_create_widget (dlg);
        break;
    case YAD_MODE_FONT:
        main_widget = font_create_widget (dlg);
        break;
    case YAD_MODE_FORM:
        main_widget = form_create_widget (dlg);
        break;
#ifdef HAVE_HTML
    case YAD_MODE_HTML:
        main_widget = html_create_widget (dlg);
        break;
#endif
    case YAD_MODE_ICONS:
        main_widget = icons_create_widget (dlg);
        break;
    case YAD_MODE_LIST:
        main_widget = list_create_widget (dlg);
        break;
    case YAD_MODE_MULTI_PROGRESS:
        main_widget = multi_progress_create_widget (dlg);
        break;
    case YAD_MODE_NOTEBOOK:
        main_widget = notebook_create_widget (dlg);
        break;
    case YAD_MODE_PANED:
        main_widget = paned_create_widget (dlg);
        break;
    case YAD_MODE_PROGRESS:
        main_widget = progress_create_widget (dlg);
        break;
    case YAD_MODE_SCALE:
        main_widget = scale_create_widget (dlg);
        break;
    case YAD_MODE_TEXTINFO:
        main_widget = text_create_widget (dlg);
        break;
    default:
        ;
    }

    if (main_widget)
    {
        if (options.data.expander)
        {
            GtkWidget *exp;

            exp = gtk_expander_new_with_mnemonic (options.data.expander);
            gtk_expander_set_expanded (GTK_EXPANDER (exp), FALSE);
            gtk_container_add (GTK_CONTAINER (exp), main_widget);
            gtk_box_pack_start (GTK_BOX (vbox), exp, TRUE, TRUE, 2);
        }
        else
            gtk_box_pack_start (GTK_BOX (vbox), main_widget, TRUE, TRUE, 2);
    }

    /* add buttons */
    if (!options.data.no_buttons)
    {
        if (options.data.buttons)
        {
            GSList *tmp = options.data.buttons;
            do
            {
                GtkWidget *btn;
                YadButton *b = (YadButton *) tmp->data;

                btn = gtk_button_new ();
                gtk_container_add (GTK_CONTAINER (btn), get_label (b->name, 2));
                gtk_button_set_alignment (GTK_BUTTON (btn), 0.5, 0.5);
                g_object_set_data (G_OBJECT (btn), "resp", GINT_TO_POINTER (b->response));
                g_signal_connect (G_OBJECT (btn), "clicked", G_CALLBACK (btn_cb), b->cmd);
                gtk_box_pack_start (GTK_BOX (bbox), btn, FALSE, FALSE, 0);

                tmp = tmp->next;
            }
            while (tmp != NULL);
        }
        else
        {
            if (options.mode == YAD_MODE_PROGRESS || options.mode == YAD_MODE_MULTI_PROGRESS)
                gtk_dialog_add_buttons (GTK_DIALOG (dlg), GTK_STOCK_CLOSE, YAD_RESPONSE_OK, NULL);
            else
            {
                if (gtk_alternative_dialog_button_order (NULL))
                    gtk_dialog_add_buttons (GTK_DIALOG (dlg),
                                            GTK_STOCK_OK, YAD_RESPONSE_OK, GTK_STOCK_CANCEL, YAD_RESPONSE_CANCEL, NULL);
                else
                    gtk_dialog_add_buttons (GTK_DIALOG (dlg),
                                            GTK_STOCK_CANCEL, YAD_RESPONSE_CANCEL, GTK_STOCK_OK, YAD_RESPONSE_OK, NULL);
            }
            gtk_dialog_set_default_response (GTK_DIALOG (dlg), YAD_RESPONSE_OK);
        }
        gtk_button_box_set_layout (GTK_BUTTON_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))),
                                   options.data.buttons_layout);
    }

    /* show widgets */
    gtk_widget_show_all (gtk_dialog_get_content_area (GTK_DIALOG (dlg)));
    if (options.data.no_buttons)
        gtk_widget_hide (bbox);

    /* parse geometry, if given. must be after showing widget */
    if (options.data.geometry && !options.data.maximized && !options.data.fullscreen)
    {
        gtk_widget_realize (dlg);
        gtk_window_parse_geometry (GTK_WINDOW (dlg), options.data.geometry);
    }
    gtk_widget_show (dlg);

    /* set maximized or fixed size after showing widget */
    if (options.data.maximized)
        gtk_window_maximize (GTK_WINDOW (dlg));
    else if (options.data.fullscreen)
        gtk_window_fullscreen (GTK_WINDOW (dlg));
    else
    {
        gtk_window_set_resizable (GTK_WINDOW (dlg), !options.data.fixed);
        if (options.data.fixed)
            gtk_widget_set_size_request (dlg, options.data.width, options.data.height);
    }
    /* set timeout */
    if (options.data.timeout)
    {
        g_timeout_add_seconds (options.data.timeout, timeout_cb, dlg);
        g_timeout_add_seconds (1, timeout_indicator_cb, topb);
    }

#ifndef G_OS_WIN32
    /* print xid */
    if (options.print_xid)
    {
        fprintf (stderr, "0x%lX", GDK_WINDOW_XID (gtk_widget_get_window (dlg)));
        fflush (stderr);
    }
#endif

    return dlg;
}
Exemple #8
0
static void
fill_data (gint n_columns)
{
  GtkTreeIter iter;
  GtkListStore *model = GTK_LIST_STORE (gtk_tree_view_get_model (GTK_TREE_VIEW (list_view)));
  GIOChannel *channel;

  if (options.extra_data && *options.extra_data)
    {
      gchar **args = options.extra_data;
      gint i = 0;

      gtk_widget_freeze_child_notify (list_view);

      while (args[i] != NULL)
        {
          gint j;

          gtk_list_store_append (model, &iter);
          for (j = 0; j < n_columns; j++, i++)
            {
              YadColumn *col = (YadColumn *) g_slist_nth_data (options.list_data.columns, j);
              GdkPixbuf *pb;

              if (args[i] == NULL)
                break;

              switch (col->type)
                {
                case YAD_COLUMN_CHECK:
                case YAD_COLUMN_RADIO:
                  if (strcasecmp ((gchar *) args[i], "true") == 0)
                    gtk_list_store_set (GTK_LIST_STORE (model), &iter, j, TRUE, -1);
                  else
                    gtk_list_store_set (GTK_LIST_STORE (model), &iter, j, FALSE, -1);
                  break;
                case YAD_COLUMN_NUM:
                  gtk_list_store_set (GTK_LIST_STORE (model), &iter, j, g_ascii_strtoll (args[i], NULL, 10), -1);
                  break;
                case YAD_COLUMN_FLOAT:
                  gtk_list_store_set (GTK_LIST_STORE (model), &iter, j, g_ascii_strtod (args[i], NULL), -1);
                  break;
                case YAD_COLUMN_IMAGE:
                  pb = get_pixbuf (args[i], YAD_SMALL_ICON);
                  if (pb)
                    {
                      gtk_list_store_set (GTK_LIST_STORE (model), &iter, j, pb, -1);
                      g_object_unref (pb);
                    }
                  break;
                default:
                  gtk_list_store_set (GTK_LIST_STORE (model), &iter, j, args[i], -1);
                  break;
                }
            }
        }

      gtk_widget_thaw_child_notify (list_view);

      if (settings.always_selected)
        {
          GtkTreeIter it;
          GtkTreeSelection *sel = gtk_tree_view_get_selection (GTK_TREE_VIEW (list_view));
          GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (list_view));

          gtk_tree_model_get_iter_first (model, &it);
          gtk_tree_selection_select_iter (sel, &it);
        }
    }

  if (options.common_data.listen || !(options.extra_data && *options.extra_data))
    {
      channel = g_io_channel_unix_new (0);
      g_io_channel_set_encoding (channel, NULL, NULL);
      g_io_channel_set_flags (channel, G_IO_FLAG_NONBLOCK, NULL);
      g_io_add_watch (channel, G_IO_IN | G_IO_HUP, handle_stdin, GINT_TO_POINTER (n_columns));
    }
}
Exemple #9
0
static gboolean
handle_stdin (GIOChannel * channel, GIOCondition condition, gpointer data)
{
  static GtkTreeIter iter;
  static gint column_count = 0;
  static gint row_count = 0;
  gint n_columns = GPOINTER_TO_INT (data);
  GtkTreeModel *model = gtk_tree_view_get_model (GTK_TREE_VIEW (list_view));

  if ((condition == G_IO_IN) || (condition == G_IO_IN + G_IO_HUP))
    {
      GError *err = NULL;
      GString *string = g_string_new (NULL);

      while (channel->is_readable != TRUE);

      do
        {
          YadColumn *col;
          GdkPixbuf *pb;
          gint status;

          do
            {
              status = g_io_channel_read_line_string (channel, string, NULL, &err);

              while (gtk_events_pending ())
                gtk_main_iteration ();
            }
          while (status == G_IO_STATUS_AGAIN);

          if (status != G_IO_STATUS_NORMAL)
            {
              if (err)
                {
                  g_printerr ("yad_list_handle_stdin(): %s\n", err->message);
                  g_error_free (err);
                  err = NULL;
                }
              /* stop handling */
              g_io_channel_shutdown (channel, TRUE, NULL);
              return FALSE;
            }

          strip_new_line (string->str);
          if (string->str[0] == '\014')
            {
              /* clear list if ^L received */
              gtk_list_store_clear (GTK_LIST_STORE (model));
              row_count = column_count = 0;
              continue;
            }

          if (row_count == 0 && column_count == 0)
            gtk_list_store_append (GTK_LIST_STORE (model), &iter);
          else if (column_count == n_columns)
            {
              /* We're starting a new row */
              column_count = 0;
              row_count++;
              if (options.list_data.limit && row_count >= options.list_data.limit)
                {
                  gtk_tree_model_get_iter_first (model, &iter);
                  gtk_list_store_remove (GTK_LIST_STORE (model), &iter);
                }
              gtk_list_store_append (GTK_LIST_STORE (model), &iter);
            }

          col = (YadColumn *) g_slist_nth_data (options.list_data.columns, column_count);

          switch (col->type)
            {
            case YAD_COLUMN_CHECK:
            case YAD_COLUMN_RADIO:
              if (strcasecmp (string->str, "true") == 0)
                gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, TRUE, -1);
              else
                gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, FALSE, -1);
              break;
            case YAD_COLUMN_NUM:
              gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count,
                                  g_ascii_strtoll (string->str, NULL, 10), -1);
              break;
            case YAD_COLUMN_FLOAT:
              gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count,
                                  g_ascii_strtod (string->str, NULL), -1);
              break;
            case YAD_COLUMN_IMAGE:
              pb = get_pixbuf (string->str, YAD_SMALL_ICON);
              if (pb)
                {
                  gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, pb, -1);
                  g_object_unref (pb);
                }
              break;
            default:
              gtk_list_store_set (GTK_LIST_STORE (model), &iter, column_count, string->str, -1);
              break;
            }

          column_count++;
        }
      while (g_io_channel_get_buffer_condition (channel) == G_IO_IN);
      g_string_free (string, TRUE);
    }

  if ((condition != G_IO_IN) && (condition != G_IO_IN + G_IO_HUP))
    {
      g_io_channel_shutdown (channel, TRUE, NULL);
      return FALSE;
    }

  return TRUE;
}