dialog enhancements




Hi,

Trying to make GtkDialog a little less useless than it currently is,
while retaining backward compatibility.

Here's what I added:
 - changed the action_area to be a button box
 - buttons can be referred to by position in the box, as with 
   GnomeDialog
 - can auto-create buttons by passing a NULL-terminated varargs 
   list of button labels; as with GnomeDialog, eventually these
   labels could also be stock button IDs
 - gtk_dialog_run() function to block waiting for modal dialog
 - button_clicked signal on the dialog so you don't have to 
   connect to each button separately

Then I did a GtkMessageDialog subclass, which simply packs a label,
sets the dialog title, and eventually adds one of those little pixmaps
representing the dialog type. Pretty much identical to Motif, Qt, and
GNOME message boxes.

Headers appended, I have implementation too though.

Havoc


typedef struct _GtkDialog        GtkDialog;
typedef struct _GtkDialogClass   GtkDialogClass;

struct _GtkDialog
{
  GtkWindow window;

  /*< public >*/
  
  GtkWidget *vbox;
  GtkWidget *action_area;

  /*< private >*/
  guint action_area_add_handler;
  guint action_area_remove_handler;
};

struct _GtkDialogClass
{
  GtkWindowClass parent_class;

  void (* button_clicked) (GtkDialog *dialog, gint button_position);
};

GtkType    gtk_dialog_get_type                   (void);
GtkWidget* gtk_dialog_new                        (void);
/* Think of a better name ;-) */
GtkWidget* gtk_dialog_new_improved               (const gchar *title,
                                                  GtkWindow   *parent,
                                                  const gchar *first_button_name,
                                                  ...);
void       gtk_dialog_append_button              (GtkDialog   *dialog,
                                                  const gchar *button_name);
void       gtk_dialog_append_buttons             (GtkDialog   *dialog,
                                                  const gchar *first_button_name,
                                                  ...);
void       gtk_dialog_append_buttons_valist      (GtkDialog   *dialog,
                                                  const gchar *first,
                                                  va_list      list);
void       gtk_dialog_append_button_widget       (GtkDialog   *dialog,
                                                  GtkWidget   *button);
GtkWidget* gtk_dialog_get_button_widget          (GtkDialog   *dialog,
                                                  gint         position);
gint       gtk_dialog_get_button_widget_position (GtkDialog   *dialog,
                                                  GtkWidget   *button);
gint       gtk_dialog_run                        (GtkDialog   *dialog);

/* emit button_clicked signal */
void       gtk_dialog_button_clicked             (GtkDialog   *dialog,
                                                  gint         button);



/* Message dialog */

/* FIXME move to gtkenums.h */

typedef enum
{
  GTK_MESSAGE_INFO,
  GTK_MESSAGE_WARNING,
  GTK_MESSAGE_QUESTION,
  GTK_MESSAGE_ERROR
} GtkMessageType;

typedef enum
{
  GTK_BUTTONS_NONE,
  GTK_BUTTONS_OK,
  GTK_BUTTONS_CLOSE,
  GTK_BUTTONS_CANCEL,
  GTK_BUTTONS_YES_NO,
  GTK_BUTTONS_OK_CANCEL
} GtkButtonsType;

/* FIXME move stock #defines to a separate header */

#define GTK_STOCK_BUTTON_OK              "OK"
#define GTK_STOCK_BUTTON_CANCEL          "Cancel"
#define GTK_STOCK_BUTTON_CLOSE           "Close"
#define GTK_STOCK_BUTTON_YES             "Yes"
#define GTK_STOCK_BUTTON_NO              "No"

typedef struct _GtkMessageDialog        GtkMessageDialog;
typedef struct _GtkMessageDialogClass   GtkMessageDialogClass;

struct _GtkMessageDialog
{
  GtkDialog dialog;

  /*< public >*/
  
  GtkWidget *label;
};

struct _GtkMessageDialogClass
{
  GtkDialogClass parent_class;
};

GtkType    gtk_message_dialog_get_type (void);

GtkWidget* gtk_message_dialog_new      (GtkMessageType    type,
                                        GtkButtonsType    buttons,
                                        GtkWindow        *parent,
                                        const gchar      *message_format,
                                        ...) G_GNUC_PRINTF(3, 4);

GtkWidget* gtk_message_dialog_new_with_buttons (GtkMessageType  type,
                                                GtkWindow      *parent,
                                                const gchar    *message,
                                                const gchar    *first_button,
                                                ...);



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]