コード例 #1
0
ファイル: colordlg.cpp プロジェクト: iokto/newton-dynamics
void wxColourDialog::DialogToColourData()
{
#if wxUSE_LIBHILDON
    HildonColorSelector * const sel = HILDON_COLOR_SELECTOR(m_widget);
    const GdkColor * const clr = hildon_color_selector_get_color(sel);
    if ( clr )
        m_data.SetColour(*clr);
#elif wxUSE_LIBHILDON2 // !wxUSE_LIBHILDON
    const GdkColor * const
    col = m_data.GetColour().IsOk() ? m_data.GetColour().GetColor() : NULL;

    GdkColor clr;
    if (col)
        clr = *col;
    else {
        clr.pixel = 0;
        clr.red = 32768;
        clr.green = 32768;
        clr.blue = 32768;
    }
    GdkColor new_color = clr;
    hildon_color_chooser_dialog_get_color((HildonColorChooserDialog *)m_widget, &new_color);

    m_data.SetColour(new_color);
#else // !wxUSE_LIBHILDON2

    GtkColorSelection* sel = GTK_COLOR_SELECTION(
        gtk_color_selection_dialog_get_color_selection(
        GTK_COLOR_SELECTION_DIALOG(m_widget)));

#ifdef __WXGTK3__
    GdkRGBA clr;
    gtk_color_selection_get_current_rgba(sel, &clr);
#else
    GdkColor clr;
    gtk_color_selection_get_current_color(sel, &clr);
#endif
    m_data.SetColour(clr);

    // Extract custom palette:

    GtkSettings *settings = gtk_widget_get_settings(GTK_WIDGET(sel));
    gchar *pal;
    g_object_get(settings, "gtk-color-palette", &pal, NULL);

    GdkColor *colors;
    gint n_colors;
    if (gtk_color_selection_palette_from_string(pal, &colors, &n_colors))
    {
        for (int i = 0; i < n_colors && i < wxColourData::NUM_CUSTOM; i++)
        {
            m_data.SetCustomColour(i, wxColour(colors[i]));
        }
        g_free(colors);
    }

    g_free(pal);
#endif // wxUSE_LIBHILDON / wxUSE_LIBHILDON2 /!wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
}
コード例 #2
0
/* Popup a color selector dialog on button click */
static void
hildon_color_button_clicked                     (GtkButton *button)
{
    HildonColorButton *cb = HILDON_COLOR_BUTTON (button);
    HildonColorButtonPrivate *priv = HILDON_COLOR_BUTTON_GET_PRIVATE (button);
    HildonColorChooserDialog *cs_dialog;
    
    g_assert (priv);
    
    cs_dialog = (HildonColorChooserDialog *) priv->dialog;

    /* Popup the color selector dialog */
    if (! cs_dialog)
    {
        /* The dialog hasn't been created yet, do it */
        GtkWidget *parent = gtk_widget_get_toplevel (GTK_WIDGET(cb));
        priv->dialog = hildon_color_chooser_dialog_new ();
        cs_dialog = HILDON_COLOR_CHOOSER_DIALOG (priv->dialog);
        if (parent)
            gtk_window_set_transient_for (GTK_WINDOW (cs_dialog), GTK_WINDOW (parent));

        g_signal_emit (button, signals[SETUP_DIALOG], 0, priv->dialog);
    }

    /* Set the initial color for the color selector dialog */
    hildon_color_chooser_dialog_set_color (cs_dialog, &priv->color);

    /* Update the color for color button if selection was made */
    priv->popped = TRUE;
    if (gtk_dialog_run (GTK_DIALOG (cs_dialog)) == GTK_RESPONSE_OK)
    {
        hildon_color_chooser_dialog_get_color (cs_dialog, &priv->color);
        hildon_color_button_set_color (HILDON_COLOR_BUTTON (button), &priv->color);
        // FIXME A queue-draw should be enough here (not set needed)
    } 

    gtk_widget_hide (GTK_WIDGET(cs_dialog));
    priv->popped = FALSE;
}