Commit 2b9a06ca authored by Gildas Bazin's avatar Gildas Bazin

* modules/gui/wxwindows/*: modified the auto-generated menus routines to not

delete/re-create parent menus. That makes wxWindows a lot happier.
parent 68904f40
......@@ -355,21 +355,11 @@ void Interface::CreateOurMenuBar()
wxU(_("Stream and Media &info...\tCtrl-I")),
wxU(_(HELP_FILEINFO)) );
/* Create the "Settings" menu */
p_settings_menu = new wxMenu;
b_settings_menu = 1;
/* Create the "Audio" menu */
p_audio_menu = new wxMenu;
b_audio_menu = 1;
/* Create the "Video" menu */
p_video_menu = new wxMenu;
b_video_menu = 1;
/* Create the "Navigation" menu */
p_navig_menu = new wxMenu;
b_navig_menu = 1;
/* Create the "Auto-generated" menus */
p_settings_menu = SettingsMenu( p_intf, this );
p_audio_menu = AudioMenu( p_intf, this );
p_video_menu = VideoMenu( p_intf, this );
p_navig_menu = NavigMenu( p_intf, this );
/* Create the "Help" menu */
wxMenu *help_menu = new wxMenu;
......@@ -751,33 +741,14 @@ void Interface::UpdateAcceleratorTable()
/*****************************************************************************
* Event Handlers.
*****************************************************************************/
/* Work-around helper for buggy wxGTK */
void RecursiveDestroy( wxMenu *menu )
{
wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
for( ; node; )
{
wxMenuItem *item = node->GetData();
node = node->GetNext();
/* Delete the submenus */
wxMenu *submenu = item->GetSubMenu();
if( submenu )
{
RecursiveDestroy( submenu );
}
menu->Delete( item );
}
}
void Interface::OnMenuOpen(wxMenuEvent& event)
{
#if !defined( __WXMSW__ )
if( event.GetEventObject() == p_settings_menu )
#endif
{
if( b_settings_menu )
{
p_settings_menu = SettingsMenu( p_intf, this );
p_settings_menu = SettingsMenu( p_intf, this, p_settings_menu );
/* Add static items */
p_settings_menu->AppendCheckItem( Extended_Event,
......@@ -786,104 +757,28 @@ void Interface::OnMenuOpen(wxMenuEvent& event)
wxU(_("&Bookmarks...") ), wxU(_(HELP_BOOKMARKS)) );
p_settings_menu->Append( Prefs_Event, wxU(_("&Preferences...")),
wxU(_(HELP_PREFS)) );
/* Work-around for buggy wxGTK */
wxMenu *menu = GetMenuBar()->GetMenu( 2 );
RecursiveDestroy( menu );
/* End work-around */
menu = GetMenuBar()->Replace( 2, p_settings_menu,
wxU(_("&Settings")));
if( menu ) delete menu;
b_settings_menu = 0;
}
else b_settings_menu = 1;
}
#if !defined( __WXMSW__ )
else if( event.GetEventObject() == p_audio_menu )
#endif
{
if( b_audio_menu )
{
p_audio_menu = AudioMenu( p_intf, this );
/* Work-around for buggy wxGTK */
wxMenu *menu = GetMenuBar()->GetMenu( 3 );
RecursiveDestroy( menu );
/* End work-around */
menu =
GetMenuBar()->Replace( 3, p_audio_menu, wxU(_("&Audio")) );
if( menu ) delete menu;
b_audio_menu = 0;
}
else b_audio_menu = 1;
p_audio_menu = AudioMenu( p_intf, this, p_audio_menu );
}
#if !defined( __WXMSW__ )
else if( event.GetEventObject() == p_video_menu )
#endif
{
if( b_video_menu )
{
p_video_menu = VideoMenu( p_intf, this );
/* Work-around for buggy wxGTK */
wxMenu *menu = GetMenuBar()->GetMenu( 4 );
RecursiveDestroy( menu );
/* End work-around */
menu =
GetMenuBar()->Replace( 4, p_video_menu, wxU(_("&Video")) );
if( menu ) delete menu;
b_video_menu = 0;
}
else b_video_menu = 1;
p_video_menu = VideoMenu( p_intf, this, p_video_menu );
}
#if !defined( __WXMSW__ )
else if( event.GetEventObject() == p_navig_menu )
#endif
{
if( b_navig_menu )
{
p_navig_menu = NavigMenu( p_intf, this );
/* Work-around for buggy wxGTK */
wxMenu *menu = GetMenuBar()->GetMenu( 5 );
RecursiveDestroy( menu );
/* End work-around */
menu =
GetMenuBar()->Replace( 5, p_navig_menu, wxU(_("&Navigation")));
if( menu ) delete menu;
b_navig_menu = 0;
}
else b_navig_menu = 1;
p_navig_menu = NavigMenu( p_intf, this, p_navig_menu );
}
#else
p_settings_menu = SettingsMenu( p_intf, this );
/* Add static items */
p_settings_menu->AppendCheckItem( Extended_Event, wxU(_("&Extended GUI") ),
wxU(_(HELP_EXTENDED)) );
p_settings_menu->AppendCheckItem( Bookmarks_Event, wxU(_("&Bookmarks") ),
wxU(_(HELP_BOOKMARKS)) );
p_settings_menu->Append( Prefs_Event, wxU(_("&Preferences...")),
wxU(_(HELP_PREFS)) );
wxMenu *menu =
GetMenuBar()->Replace( 2, p_settings_menu, wxU(_("&Settings")) );
if( menu ) delete menu;
p_audio_menu = AudioMenu( p_intf, this );
menu = GetMenuBar()->Replace( 3, p_audio_menu, wxU(_("&Audio")) );
if( menu ) delete menu;
p_video_menu = VideoMenu( p_intf, this );
menu = GetMenuBar()->Replace( 4, p_video_menu, wxU(_("&Video")) );
if( menu ) delete menu;
p_navig_menu = NavigMenu( p_intf, this );
menu = GetMenuBar()->Replace( 5, p_navig_menu, wxU(_("&Navigation")) );
if( menu ) delete menu;
#endif
}
#if defined( __WXMSW__ ) || defined( __WXMAC__ )
......
......@@ -4,7 +4,7 @@
* Copyright (C) 2000-2004 VideoLAN
* $Id$
*
* Authors: Gildas Bazin <gbazin@netcourrier.com>
* Authors: Gildas Bazin <gbazin@videolan.org>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -54,6 +54,34 @@ private:
};
class Menu: public wxMenu
{
public:
/* Constructor */
Menu( intf_thread_t *p_intf, wxWindow *p_parent, int i_start_id );
virtual ~Menu();
void Populate( int i_count, char **ppsz_names, int *pi_objects );
void Clear();
private:
/* Event handlers (these functions should _not_ be virtual) */
void OnClose( wxCommandEvent& event );
void OnShowDialog( wxCommandEvent& event );
void OnEntrySelected( wxCommandEvent& event );
wxMenu *Menu::CreateDummyMenu();
void Menu::CreateMenuItem( wxMenu *, char *, vlc_object_t * );
wxMenu *Menu::CreateChoicesMenu( char *, vlc_object_t *, bool );
DECLARE_EVENT_TABLE();
intf_thread_t *p_intf;
int i_start_id;
int i_item_id;
};
/*****************************************************************************
* Event Table.
*****************************************************************************/
......@@ -214,8 +242,8 @@ void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
}
/* Build menu */
Menu popupmenu( p_intf, p_parent, i,
ppsz_varnames, pi_objects, PopupMenu_Events );
Menu popupmenu( p_intf, p_parent, PopupMenu_Events );
popupmenu.Populate( i, ppsz_varnames, pi_objects );
#if 1
/* Add static entries */
......@@ -229,7 +257,7 @@ void PopupMenu( intf_thread_t *p_intf, wxWindow *p_parent,
p_intf->p_sys->p_popup_menu = NULL;
}
wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent )
wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
{
#define MAX_AUDIO_ITEMS 10
......@@ -264,11 +292,18 @@ wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent )
}
/* Build menu */
return new Menu( _p_intf, p_parent, i,
ppsz_varnames, pi_objects, AudioMenu_Events );
Menu *p_vlc_menu = (Menu *)p_menu;
if( !p_vlc_menu )
p_vlc_menu = new Menu( _p_intf, p_parent, AudioMenu_Events );
else
p_vlc_menu->Clear();
p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
return p_vlc_menu;
}
wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent )
wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
{
#define MAX_VIDEO_ITEMS 15
......@@ -328,11 +363,18 @@ wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent )
}
/* Build menu */
return new Menu( _p_intf, p_parent, i,
ppsz_varnames, pi_objects, VideoMenu_Events );
Menu *p_vlc_menu = (Menu *)p_menu;
if( !p_vlc_menu )
p_vlc_menu = new Menu( _p_intf, p_parent, VideoMenu_Events );
else
p_vlc_menu->Clear();
p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
return p_vlc_menu;
}
wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent )
wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent, wxMenu *p_menu )
{
#define MAX_NAVIG_ITEMS 10
......@@ -374,11 +416,19 @@ wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent )
}
/* Build menu */
return new Menu( _p_intf, p_parent, i,
ppsz_varnames, pi_objects, NavigMenu_Events );
Menu *p_vlc_menu = (Menu *)p_menu;
if( !p_vlc_menu )
p_vlc_menu = new Menu( _p_intf, p_parent, NavigMenu_Events );
else
p_vlc_menu->Clear();
p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
return p_vlc_menu;
}
wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent )
wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
wxMenu *p_menu )
{
#define MAX_SETTINGS_ITEMS 10
......@@ -402,24 +452,41 @@ wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent )
}
/* Build menu */
return new Menu( _p_intf, p_parent, i,
ppsz_varnames, pi_objects, SettingsMenu_Events );
Menu *p_vlc_menu = (Menu *)p_menu;
if( !p_vlc_menu )
p_vlc_menu = new Menu( _p_intf, p_parent, SettingsMenu_Events );
else
p_vlc_menu->Clear();
p_vlc_menu->Populate( i, ppsz_varnames, pi_objects );
return p_vlc_menu;
}
/*****************************************************************************
* Constructor.
*****************************************************************************/
Menu::Menu( intf_thread_t *_p_intf, wxWindow *p_parent,
int i_count, char **ppsz_varnames, int *pi_objects,
int i_start_id ): wxMenu( )
Menu::Menu( intf_thread_t *_p_intf, wxWindow *p_parent, int _i_start_id )
: wxMenu( )
{
/* Initializations */
p_intf = _p_intf;
i_start_id = _i_start_id;
}
Menu::~Menu()
{
}
/*****************************************************************************
* Public methods.
*****************************************************************************/
void Menu::Populate( int i_count, char **ppsz_varnames, int *pi_objects )
{
vlc_object_t *p_object;
vlc_bool_t b_section_empty = VLC_FALSE;
int i;
/* Initializations */
p_intf = _p_intf;
i_item_id = i_start_id;
for( i = 0; i < i_count; i++ )
......@@ -460,8 +527,28 @@ Menu::Menu( intf_thread_t *_p_intf, wxWindow *p_parent,
}
}
Menu::~Menu()
/* Work-around helper for buggy wxGTK */
static void RecursiveDestroy( wxMenu *menu )
{
wxMenuItemList::Node *node = menu->GetMenuItems().GetFirst();
for( ; node; )
{
wxMenuItem *item = node->GetData();
node = node->GetNext();
/* Delete the submenus */
wxMenu *submenu = item->GetSubMenu();
if( submenu )
{
RecursiveDestroy( submenu );
}
menu->Delete( item );
}
}
void Menu::Clear( )
{
RecursiveDestroy( this );
}
/*****************************************************************************
......
......@@ -262,13 +262,9 @@ private:
/* For auto-generated menus */
wxMenu *p_settings_menu;
vlc_bool_t b_settings_menu;
wxMenu *p_audio_menu;
vlc_bool_t b_audio_menu;
wxMenu *p_video_menu;
vlc_bool_t b_video_menu;
wxMenu *p_navig_menu;
vlc_bool_t b_navig_menu;
};
/* Dialogs Provider */
......@@ -949,12 +945,11 @@ private:
} // end of wxvlc namespace
/* Menus */
void PopupMenu( intf_thread_t *_p_intf, wxWindow *p_parent,
const wxPoint& pos );
wxMenu *SettingsMenu( intf_thread_t *_p_intf, wxWindow *p_parent );
wxMenu *AudioMenu( intf_thread_t *_p_intf, wxWindow *p_parent );
wxMenu *VideoMenu( intf_thread_t *_p_intf, wxWindow *p_parent );
wxMenu *NavigMenu( intf_thread_t *_p_intf, wxWindow *p_parent );
void PopupMenu( intf_thread_t *, wxWindow *, const wxPoint& );
wxMenu *SettingsMenu( intf_thread_t *, wxWindow *, wxMenu * = NULL );
wxMenu *AudioMenu( intf_thread_t *, wxWindow *, wxMenu * = NULL );
wxMenu *VideoMenu( intf_thread_t *, wxWindow *, wxMenu * = NULL );
wxMenu *NavigMenu( intf_thread_t *, wxWindow *, wxMenu * = NULL );
namespace wxvlc
{
......@@ -975,31 +970,6 @@ private:
Interface *p_main_interface;
};
class Menu: public wxMenu
{
public:
/* Constructor */
Menu( intf_thread_t *p_intf, wxWindow *p_parent, int i_count,
char **ppsz_names, int *pi_objects, int i_start_id );
virtual ~Menu();
private:
/* Event handlers (these functions should _not_ be virtual) */
void OnClose( wxCommandEvent& event );
void OnShowDialog( wxCommandEvent& event );
void OnEntrySelected( wxCommandEvent& event );
wxMenu *Menu::CreateDummyMenu();
void Menu::CreateMenuItem( wxMenu *, char *, vlc_object_t * );
wxMenu *Menu::CreateChoicesMenu( char *, vlc_object_t *, bool );
DECLARE_EVENT_TABLE();
intf_thread_t *p_intf;
int i_item_id;
};
} // end of wxvlc namespace
using namespace wxvlc;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment