- free( entry );
- }
-
- /*
- * Remove the menu from the menus list
- */
- fgListRemove( &fgStructure.Menus, &menu->Node );
-
- /*
- * If that menu was the current one...
- */
- if( fgStructure.Menu == menu )
- fgStructure.Menu = NULL;
-
- /*
- * Have the menu structure freed
- */
- free( menu );
+ for( from = ( SFG_Menu * )fgStructure.Menus.First;
+ from;
+ from = ( SFG_Menu * )from->Node.Next )
+ fghRemoveMenuFromMenu( from, menu );
+
+ /*
+ * If the programmer defined a destroy callback, call it
+ * A. Donev: But first make this the active menu
+ */
+ if( menu->Destroy )
+ {
+ SFG_Menu *activeMenu=fgStructure.Menu;
+ fgStructure.Menu = menu;
+ menu->Destroy( );
+ fgStructure.Menu = activeMenu;
+ }
+
+ /*
+ * Now we are pretty sure the menu is not used anywhere
+ * and that we can remove all of its entries
+ */
+ while( menu->Entries.First )
+ {
+ SFG_MenuEntry *entry = ( SFG_MenuEntry * ) menu->Entries.First;
+
+ fgListRemove( &menu->Entries, &entry->Node );
+
+ if( entry->Text )
+ free( entry->Text );
+ entry->Text = NULL;
+
+ free( entry );
+ }
+
+ if( fgStructure.Window == menu->Window )
+ fgSetWindow( menu->ParentWindow );
+ fgDestroyWindow( menu->Window );
+ fgListRemove( &fgStructure.Menus, &menu->Node );
+ if( fgStructure.Menu == menu )
+ fgStructure.Menu = NULL;
+
+ free( menu );