示例#1
0
文件: colorsel.c 项目: BYC/gtk
static void
change_color_callback (GtkWidget *button,
                       gpointer   data)
{
  GtkWidget *dialog;
  GtkColorSelection *colorsel;
  GtkColorSelectionDialog *selection_dialog;
  gint response;

  dialog = gtk_color_selection_dialog_new ("Changing color");

  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));

  selection_dialog = GTK_COLOR_SELECTION_DIALOG (dialog);
  colorsel = GTK_COLOR_SELECTION (gtk_color_selection_dialog_get_color_selection (selection_dialog));

  gtk_color_selection_set_previous_rgba (colorsel, &color);
  gtk_color_selection_set_current_rgba (colorsel, &color);
  gtk_color_selection_set_has_palette (colorsel, TRUE);

  response = gtk_dialog_run (GTK_DIALOG (dialog));

  if (response == GTK_RESPONSE_OK)
    {
      gtk_color_selection_get_current_rgba (colorsel, &color);

      gtk_widget_override_background_color (da, 0, &color);
    }

  gtk_widget_destroy (dialog);
}
示例#2
0
void wxColourDialog::ColourDataToDialog()
{
    GtkColorSelection* sel = GTK_COLOR_SELECTION(
        gtk_color_selection_dialog_get_color_selection(
        GTK_COLOR_SELECTION_DIALOG(m_widget)));

    const wxColour& color = m_data.GetColour();
    if (color.IsOk())
    {
#ifdef __WXGTK3__
        gtk_color_selection_set_current_rgba(sel, color);
#else
        gtk_color_selection_set_current_color(sel, color.GetColor());
#endif
    }

    // setup the palette:

    GdkColor colors[wxColourData::NUM_CUSTOM];
    gint n_colors = 0;
    for (unsigned i = 0; i < WXSIZEOF(colors); i++)
    {
        wxColour c = m_data.GetCustomColour(i);
        if (c.IsOk())
        {
            colors[n_colors] = *c.GetColor();
            n_colors++;
        }
    }

    wxGtkString pal(gtk_color_selection_palette_to_string(colors, n_colors));

    GtkSettings *settings = gtk_widget_get_settings(GTK_WIDGET(sel));
    g_object_set(settings, "gtk-color-palette", pal.c_str(), NULL);
}
示例#3
0
void wxColourDialog::ColourDataToDialog()
{
#if wxUSE_LIBHILDON || wxUSE_LIBHILDON2
    const GdkColor * const
        col = m_data.GetColour().IsOk() ? m_data.GetColour().GetColor()
                                      : NULL;
#endif
#if wxUSE_LIBHILDON
    HildonColorSelector * const sel = HILDON_COLOR_SELECTOR(m_widget);
    hildon_color_selector_set_color(sel, const_cast<GdkColor *>(col));
#elif wxUSE_LIBHILDON2
    GdkColor clr;
    if (col)
        clr = *col;
    else {
        clr.pixel = 0;
        clr.red = 32768;
        clr.green = 32768;
        clr.blue = 32768;
    }

    hildon_color_chooser_dialog_set_color((HildonColorChooserDialog *)m_widget, &clr);
#else // !wxUSE_LIBHILDON2/!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
    GtkColorSelection* sel = GTK_COLOR_SELECTION(
        gtk_color_selection_dialog_get_color_selection(
        GTK_COLOR_SELECTION_DIALOG(m_widget)));

    const wxColour& c = m_data.GetColour();
    if (c.IsOk())
    {
#ifdef __WXGTK3__
        gtk_color_selection_set_current_rgba(sel, c);
#else
        gtk_color_selection_set_current_color(sel, c.GetColor());
#endif
    }

    // setup the palette:

    GdkColor colors[wxColourData::NUM_CUSTOM];
    gint n_colors = 0;
    for (unsigned i = 0; i < WXSIZEOF(colors); i++)
    {
        wxColour c = m_data.GetCustomColour(i);
        if (c.IsOk())
        {
            colors[n_colors] = *c.GetColor();
            n_colors++;
        }
    }

    wxGtkString pal(gtk_color_selection_palette_to_string(colors, n_colors));

    GtkSettings *settings = gtk_widget_get_settings(GTK_WIDGET(sel));
    g_object_set(settings, "gtk-color-palette", pal.c_str(), NULL);
#endif // wxUSE_LIBHILDON / wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
}
示例#4
0
static GtkWidget *
create_color_sel (GObject *action_proxy, GOColor c, GCallback handler, gboolean allow_alpha)
{
	char *title = g_object_get_data (G_OBJECT (action_proxy), "title");
	GtkWidget *w = gtk_color_selection_dialog_new (title), *hb;
	GtkColorSelectionDialog *dialog = GTK_COLOR_SELECTION_DIALOG (w);
	GtkColorSelection *colorsel = GTK_COLOR_SELECTION (gtk_color_selection_dialog_get_color_selection (dialog));
	GdkRGBA gdk;

	g_object_get (G_OBJECT (w), "help-button", &hb, NULL);
	gtk_widget_hide (hb);
	gtk_color_selection_set_has_opacity_control (colorsel, allow_alpha);
	gtk_color_selection_set_current_rgba (colorsel,
		go_color_to_gdk_rgba (c, &gdk));

	g_signal_connect_object (dialog,
		"response", handler, action_proxy, 0);

	/* require an explicit show _after_ the custom-dialog signal fires */
	return w;
}