callback and menu item
- From: "Jerome Le Saux" <sidcpc gmail com>
- To: gtk-app-devel-list gnome org
- Subject: callback and menu item
- Date: Thu, 30 Mar 2006 12:15:12 +0200
Hi,
I know that I asked you several questions about the same problem, but I am
lost.
I prefer to paste here the interface code, which be better to understand
what I try to do.
#include <stdlib.h>
#include <gtk/gtk.h>
#include <glib.h>
#include <string.h>
#include <stdio.h>
#include "GestDsk.h"
#define EXIT_SUCESS 1
#define VERSION "ManageDsk 0.14"
#define OPENDSK "Lire DSK"
#define CLOSEDSK "Fermer DSK"
#define CREATEDSK "Creer DSK"
#define RENFILE "Renommer Fichier"
#define ADDFILE "Ajouter Fichier"
#define RMFILE "Enlever Fichier"
#define CLOSEAPPLI "Fermer"
#define MEM_FAILED -2
void OnDestroy (GtkWidget *pWidget , gpointer pData);
void OnQuitter(GtkWidget* widget, gpointer data);
void OnAbout(GtkWidget* widget, gpointer data);
void OnOpenDskFile(GtkContainer * contain, GtkWidget* data);
char* copy_file_path( char* d, char *s);
char * DskPath;
int main (int argc , char ** argv)
{
// declaration du widget, fenetre principale //
GtkWidget *pWindow;
// declaration des boutons ouverture DSK, ajout fichier, sauvegarde DSK,
EXIT//
// GtkWidget *pButton[4];
// GtkWidget *separator;
// declaration de la barre de menu
GtkWidget *pMenuBar;
GtkWidget *pMenu;
GtkWidget *pMenuItem;
GtkWidget *pVbox;
//GtkWidget *frame;
// declarations des choix pour les entetes //
GtkWidget *hbox;
//GSList *group;
//GtkWidget *button;
GtkWidget *scrolled_window;
// GtkWidget *gtklist;
GtkWidget *DirList;
gchar *DirTitles[3] = { "Nom du fichier", "Taille","User"};
// boutons du bas
GtkWidget *button_rename, *button_remove, *button_exporter, *button_view;
gtk_init (&argc, &argv);
// Creation de la fenetre principale //
pWindow = gtk_window_new (GTK_WINDOW_TOPLEVEL);
// definition de la position //
gtk_window_set_position(GTK_WINDOW(pWindow), GTK_WIN_POS_CENTER);
// definition de la taille de la fenetre //
gtk_window_set_default_size(GTK_WINDOW(pWindow), 600 ,600);
// Titre de la fenetre //
gtk_window_set_title(GTK_WINDOW(pWindow), VERSION);
// Connexion du signal "destroy" //
g_signal_connect(G_OBJECT(pWindow), "destroy" , G_CALLBACK(OnDestroy),
NULL);
// creation de la GtkVbox verticale //
pVbox= gtk_vbox_new(FALSE,0);
// ajout de cette box dans la fenetre //
gtk_container_add(GTK_CONTAINER(pWindow),pVbox);
//=============== creation du menu ==================//
pMenuBar = gtk_menu_bar_new();
// sous menu //
pMenu = gtk_menu_new();
// choix dans le menu //
// Action: ouverture d'un menu pour choix de l'image disque DSK //
// remplit la list DirList, DirList utilisé par la fenêtre principale //
pMenuItem = gtk_menu_item_new_with_label(OPENDSK);
DirList = gtk_clist_new_with_titles (3, DirTitles);
g_signal_connect(G_OBJECT(pMenuItem), "activate",
G_CALLBACK(OnOpenDskFile), pWindow); // Here I want to fill the Dirlist
widget, and I would like to return in the scrolled_window above
gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem);
// Action: fermeture de l'image disque DSK. //
// attention a bien fermer la disquette et enregistrer tout avant de
partir //
pMenuItem = gtk_menu_item_new_with_label(CLOSEDSK);
// g_signal_connect(G_OBJECT(pMenuItem), "activate",
G_CALLBACK(OnQuitter), (GtkWidget*) pWindow);
gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem);
// ferme l'application //
pMenuItem = gtk_menu_item_new_with_label("Fermer");
g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(OnQuitter),
(GtkWidget*) pWindow);
gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem);
// menu DSK //
pMenuItem = gtk_menu_item_new_with_label("DSK");
gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pMenu);
gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem);
// menu fichier //
pMenu = gtk_menu_new();
// ajout d'un fichier dans l'image DSK actuelle //
pMenuItem = gtk_menu_item_new_with_label(ADDFILE);
g_signal_connect(G_OBJECT(pMenuItem), "activate",
G_CALLBACK(OnOpenDskFile), (GtkWidget*) pWindow );
gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem);
// Renomme un fichier dans l'image DSK actuelle //
pMenuItem = gtk_menu_item_new_with_label(RENFILE);
gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem);
// enleve un fichier de l'image DSK actuelle //
pMenuItem = gtk_menu_item_new_with_label(RMFILE);
gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem);
pMenuItem = gtk_menu_item_new_with_label("Fichier");
gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pMenu);
gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem);
// apropos de //
pMenu = gtk_menu_new();
pMenuItem = gtk_menu_item_new_with_label("A propos de...");
g_signal_connect(G_OBJECT(pMenuItem), "activate", G_CALLBACK(OnAbout),
(GtkWidget*) pWindow);
gtk_menu_shell_append(GTK_MENU_SHELL(pMenu), pMenuItem);
// apropos de dans le menu //
pMenuItem = gtk_menu_item_new_with_label("?");
gtk_menu_item_set_submenu(GTK_MENU_ITEM(pMenuItem), pMenu);
gtk_menu_shell_append(GTK_MENU_SHELL(pMenuBar), pMenuItem);
// ajout du menu a la fenetre //
gtk_box_pack_start(GTK_BOX(pVbox), pMenuBar, FALSE, FALSE, 0);
/* Fenêtre à défilement pour placer le widget GtkList à l'intérieur. */
scrolled_window=gtk_scrolled_window_new(NULL, NULL);
//g_signal_connect (G_OBJECT (DirList), "select_row", NULL, NULL);
gtk_container_add (GTK_CONTAINER (scrolled_window), DirList);
gtk_container_add(GTK_CONTAINER(pVbox), scrolled_window);
// gtklist=gtk_list_new();
//gtk_container_add(GTK_CONTAINER(scrolled_window), gtklist);
//g_signal_connect_swapped(GTK_OBJECT(gtklist),"selection_changed",NULL,NULL);
//DirList = gtk_clist_new_with_titles (3, DirTitles);
//g_signal_connect (G_OBJECT (DirList), "select_row", NULL, NULL);
//gtk_container_add (GTK_CONTAINER (scrolled_window), DirList);
/* bouton pour import export et visionnage des fichiers */
hbox = gtk_hbox_new (FALSE, 0);
gtk_box_pack_start (GTK_BOX (pVbox), hbox, FALSE, TRUE, 0);
// bouton de manipulation rapide des fichiers //
button_rename = gtk_button_new_with_label ("Renommer");
button_exporter = gtk_button_new_with_label ("Exporter");
button_view = gtk_button_new_with_label ("Lister");
button_remove = gtk_button_new_with_label ("Effacer");
gtk_box_pack_start (GTK_BOX (hbox), button_rename, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), button_exporter, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), button_view, TRUE, TRUE, 0);
gtk_box_pack_start (GTK_BOX (hbox), button_remove, TRUE, TRUE, 0);
// affichage de la fenetre //
gtk_widget_show_all(pWindow);
// demarrage de la boucle evenement //
gtk_main();
return EXIT_SUCESS;
}
void OnDestroy (GtkWidget *pWidget , gpointer pData)
{
// arret de la boucle evenement //
gtk_main_quit();
}
void OnQuitter(GtkWidget* widget, gpointer data)
{
GtkWidget *pQuestion;
pQuestion = gtk_message_dialog_new(GTK_WINDOW(data),
GTK_DIALOG_MODAL,
GTK_MESSAGE_QUESTION,
GTK_BUTTONS_YES_NO,
"Voulez vous vraiment\n"
"quitter le programme?");
switch(gtk_dialog_run(GTK_DIALOG(pQuestion)))
{
case GTK_RESPONSE_YES:
gtk_main_quit();
break;
case GTK_RESPONSE_NONE:
case GTK_RESPONSE_NO:
gtk_widget_destroy(pQuestion);
break;
}
}
void OnAbout(GtkWidget* widget, gpointer data)
{
GtkWidget *pAbout;
pAbout = gtk_message_dialog_new (GTK_WINDOW(data),
GTK_DIALOG_MODAL,
GTK_MESSAGE_INFO,
GTK_BUTTONS_OK,
"Portage Clone Unix de ManageDsk\n"
"Auteur Demoniak, Portage : SiD\n"
"Contact:SiD cpcscene com");
gtk_dialog_run(GTK_DIALOG(pAbout));
gtk_widget_destroy(pAbout);
}
void OnOpenDskFile( GtkContainer * list, GtkWidget* data)
{
GtkWidget *pFileSelection;
// GtkWidget *pDialog;
GtkWidget *pParent;
gchar *sChemin;
int IsDskValid=FALSE, i;
StDirEntry TabDir[ 64 ];
gchar * file;
pParent = GTK_WIDGET(data);
/* Creation de la fenetre de selection */
pFileSelection = gtk_file_chooser_dialog_new("Ouvrir...",
GTK_WINDOW(pParent),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_OK,
NULL);
/* On limite les actions a cette fenetre */
gtk_window_set_modal(GTK_WINDOW(pFileSelection), TRUE);
/* Affichage fenetre */
switch(gtk_dialog_run(GTK_DIALOG(pFileSelection)))
{
case GTK_RESPONSE_OK:
/* Recuperation du chemin */
sChemin =
gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(pFileSelection));
// copie chemin du fichier
DskPath=copy_file_path(DskPath,sChemin);
g_free(sChemin);
break;
default:
break;
}
gtk_widget_destroy(pFileSelection);
// test si dsk reconnu //
if (ReadDsk(DskPath ) )
{
IsDskValid = CheckDsk();
if ( IsDskValid ) // test si entete dsk bonne //
{
g_print("Entete dsk valide\n");
for ( i = 0; i < 64; i++ )
memcpy( &TabDir[ i ] , GetInfoDirEntry( i ), sizeof( StDirEntry ));
for (i =0 ; i< 64; i++)
{
SetInfoDirEntry( i, &TabDir[ i ] );
if ( TabDir[ i ].User != USER_DELETED && ! TabDir[ i ].NumPage )
{
printf("%s.%s\n",TabDir[i].Nom,TabDir[i].Ext);
file = g_strdup(TabDir[i].Nom);
g_print("%s\n",file);
gtk_clist_append(GTK_CLIST(list),&file);
}
}
return;
}
else
{
g_print("Entete dsk non valide\n");
}
}
free(DskPath);
return;
}
I want to fill the DirList Widget in the OnOpenDskFile function and to be
displayed in the scrolled_window.
What's wrong ?
Sincerely
Jerome
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]