The menu you are talking about is a property of the unity desktop. It is known as the 'Unity Global Menu'.
Each application implements it own the main menu, but the desktop environment places them where it sees fit. The Unity desktop environment, developed by Canonical as a replacement of Gnome, chooses to place these menus in the top panel.
If you run the same applications in a xfce environment (for example), then the menu will appear in the window.
This applies to all applications that define their menu using the gtk library. For those that don't, including Firefox and LibreOffice, special patches have been made to make the menus work in the global menu. Otherwise applications that don't will have their menu in the window.
Another exception, that I know of, are Java applications. These always have their menu's in the java window. I think this is because Java bypasses the desktop environment to create java app windows, not defining their menus in gtk.