Ejemplo n.º 1
0
bool wxColourDialog::Create(wxWindow *parent, wxColourData *data)
{
    if (data)
        m_data = *data;

    m_parent = GetParentForModalDialog(parent, 0);
    GtkWindow * const parentGTK = m_parent ? GTK_WINDOW(m_parent->m_widget)
                                           : NULL;

#if wxUSE_LIBHILDON
    m_widget = hildon_color_selector_new(parentGTK);
#elif wxUSE_LIBHILDON2 // !wxUSE_LIBHILDON
    m_widget = hildon_color_chooser_dialog_new();
#else // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
    wxString title(_("Choose colour"));
    m_widget = gtk_color_selection_dialog_new(wxGTK_CONV(title));
#endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON

    g_object_ref(m_widget);

    if ( parentGTK )
    {
        gtk_window_set_transient_for(GTK_WINDOW(m_widget), parentGTK);
    }

#if !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2
    GtkColorSelection* sel = GTK_COLOR_SELECTION(
        gtk_color_selection_dialog_get_color_selection(
        GTK_COLOR_SELECTION_DIALOG(m_widget)));
    gtk_color_selection_set_has_palette(sel, true);
#endif // !wxUSE_LIBHILDON && !wxUSE_LIBHILDON2

    return true;
}
/* 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;
}