Re: Destroying file selection
- From: Raymond Wan <rwan cs mu oz au>
- To: Owen Taylor <otaylor redhat com>
- Cc: gtk-list gnome org
- Subject: Re: Destroying file selection
- Date: Mon, 3 Feb 2003 11:44:40 +1100 (EST)
Hi Owen,
On 2 Feb 2003, Owen Taylor wrote:
> I suspect you probably got something slightly wrong in your first
> attempt, and then wandered off into more and more complex variants.
> Most straightforward thing would be along the lines of:
That's an accurate assessment. :) Unfortunately, I tried what
you said and it still doesn't work. I forgot to mention, but I'm still
using version 2.0 -- I hope this isn't a problem in that version.
If you or someone else has the time to look over my code that
would be great -- I'm getting quite confused. I've stripped away as much
as I could so that I have the main window, a menu, and the fileselector
that replicates the problem. I figured if I just have the fileselector,
then I would have the tutorial code. I'm guessing I must have made a
mistake elsewhere in the code or overlooked something obvious.
Any help would be appreciated, thanks!
Ray
-----
#include <stdio.h>
#include <stdlib.h>
#include "include_gdk.h"
#include "include_gtk.h"
#define MAX_WINDOWS 2
typedef struct info_struct {
/* Main window only */
GtkWidget *main_vbox;
/* Main and sum-windows */
GtkWidget *window[MAX_WINDOWS];
GtkWidget *scroll_window[MAX_WINDOWS];
GtkWidget *view[MAX_WINDOWS];
unsigned int current_window;
} INFODEF;
INFODEF *info = NULL;
/**********************************************************************
Callback functions
**********************************************************************/
static void programExit (GtkWidget *w, gpointer data) {
fprintf (stderr, "Exiting...\n");
gtk_main_quit ();
}
static void fileselCancel (GtkWidget *w, GtkWidget *filesel) {
gtk_widget_destroy (filesel);
}
static void menuFileOpen (GtkWidget *w, gpointer data) {
createOpenFile ();
}
/**********************************************************************
Menu structure
**********************************************************************/
static GtkItemFactoryEntry menu_items[] = {
{"/_File", "<ALT>F", NULL, 0, "<Branch>" },
{"/File/_Open", "<CTRL>O", menuFileOpen, 0, "<Item>" },
};
/**********************************************************************
Functions
**********************************************************************/
void createOpenFile () {
GtkWidget *filesel;
filesel = gtk_file_selection_new ("Open");
g_signal_connect (GTK_FILE_SELECTION (filesel)->ok_button, "destroy",
G_CALLBACK (gtk_main_quit), NULL);
g_signal_connect (GTK_FILE_SELECTION (filesel)->ok_button,
"clicked", G_CALLBACK (fileselCancel), filesel);
g_signal_connect (GTK_FILE_SELECTION (filesel)->cancel_button,
"clicked", G_CALLBACK (fileselCancel), filesel);
gtk_widget_show (filesel);
gtk_grab_add (filesel);
}
/* Returns a menubar widget made from the above menu */
GtkWidget *getMainMenu (GtkWidget *window) {
GtkItemFactory *item_factory;
GtkAccelGroup *accel_group;
unsigned int nmenu_items;
nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]);
accel_group = gtk_accel_group_new ();
item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "<main>",
accel_group);
gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL);
gtk_window_add_accel_group (GTK_WINDOW (window), accel_group);
gtk_accel_group_lock (accel_group);
return (gtk_item_factory_get_widget (item_factory, "<main>"));
}
static void createMainWindow (unsigned int curr) {
GtkWidget *menubar;
info -> window[curr] = gtk_window_new (GTK_WINDOW_TOPLEVEL);
g_signal_connect (G_OBJECT (info -> window[curr]), "destroy",
G_CALLBACK (programExit), NULL);
gtk_window_set_title (GTK_WINDOW (info -> window[curr]), "Main window");
gtk_widget_set_size_request (GTK_WIDGET (info -> window[curr]), 400, 400);
info -> main_vbox = gtk_vbox_new (FALSE, 0);
gtk_container_add (GTK_CONTAINER (info -> window[curr]), info -> main_vbox);
menubar = getMainMenu (info -> window[curr]);
gtk_box_pack_start (GTK_BOX (info -> main_vbox), menubar, FALSE, TRUE, 0);
info -> scroll_window[curr] = gtk_scrolled_window_new (NULL, NULL);
gtk_box_pack_start (GTK_BOX (info -> main_vbox),
info -> scroll_window[curr], TRUE, TRUE, 0);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW
(info -> scroll_window[curr]), GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_container_border_width (GTK_CONTAINER (info -> window[curr]), 0);
return;
}
int main (int argc, char *argv[]) {
unsigned int current_window = 0;
gtk_init (&argc, &argv);
info = malloc (sizeof (INFODEF));
createMainWindow (current_window);
gtk_widget_show_all (info -> window[current_window]);
gtk_main ();
free (info);
return (EXIT_SUCCESS);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]