#include "wx/frame.h"
#ifndef WX_PRECOMP
+ #include "wx/app.h"
#include "wx/menu.h"
#include "wx/menuitem.h"
#include "wx/dcclient.h"
#include "wx/statusbr.h"
#endif // WX_PRECOMP
+extern WXDLLEXPORT_DATA(const char) wxFrameNameStr[] = "frame";
+extern WXDLLEXPORT_DATA(const char) wxStatusLineNameStr[] = "status_line";
+
// ----------------------------------------------------------------------------
// event table
// ----------------------------------------------------------------------------
#if wxUSE_MENUS && wxUSE_STATUSBAR
-
BEGIN_EVENT_TABLE(wxFrameBase, wxTopLevelWindow)
EVT_MENU_OPEN(wxFrameBase::OnMenuOpen)
EVT_MENU_CLOSE(wxFrameBase::OnMenuClose)
EVT_MENU_HIGHLIGHT_ALL(wxFrameBase::OnMenuHighlight)
END_EVENT_TABLE()
-#endif // wxUSE_MENUS && wxUSE_STATUSBAR
+#endif // wxUSE_MENUS && wxUSE_IDLEMENUUPDATES
+
+/* static */
+bool wxFrameBase::ShouldUpdateMenuFromIdle()
+{
+ // Usually this is determined at compile time and is determined by whether
+ // the platform supports wxEVT_MENU_OPEN, however in wxGTK we need to also
+ // check if we're using the global menu bar as we don't get EVT_MENU_OPEN
+ // for it and need to fall back to idle time updating even if normally
+ // wxUSE_IDLEMENUUPDATES is set to 0 for wxGTK.
+#ifdef __WXGTK20__
+ if ( wxApp::GTKIsUsingGlobalMenu() )
+ return true;
+#endif // !__WXGTK__
+
+ return wxUSE_IDLEMENUUPDATES != 0;
+}
// ============================================================================
// implementation
// ============================================================================
+// ----------------------------------------------------------------------------
+// XTI
+// ----------------------------------------------------------------------------
+
+wxDEFINE_FLAGS( wxFrameStyle )
+wxBEGIN_FLAGS( wxFrameStyle )
+// new style border flags, we put them first to
+// use them for streaming out
+wxFLAGS_MEMBER(wxBORDER_SIMPLE)
+wxFLAGS_MEMBER(wxBORDER_SUNKEN)
+wxFLAGS_MEMBER(wxBORDER_DOUBLE)
+wxFLAGS_MEMBER(wxBORDER_RAISED)
+wxFLAGS_MEMBER(wxBORDER_STATIC)
+wxFLAGS_MEMBER(wxBORDER_NONE)
+
+// old style border flags
+wxFLAGS_MEMBER(wxSIMPLE_BORDER)
+wxFLAGS_MEMBER(wxSUNKEN_BORDER)
+wxFLAGS_MEMBER(wxDOUBLE_BORDER)
+wxFLAGS_MEMBER(wxRAISED_BORDER)
+wxFLAGS_MEMBER(wxSTATIC_BORDER)
+wxFLAGS_MEMBER(wxBORDER)
+
+// standard window styles
+wxFLAGS_MEMBER(wxTAB_TRAVERSAL)
+wxFLAGS_MEMBER(wxCLIP_CHILDREN)
+wxFLAGS_MEMBER(wxTRANSPARENT_WINDOW)
+wxFLAGS_MEMBER(wxWANTS_CHARS)
+wxFLAGS_MEMBER(wxFULL_REPAINT_ON_RESIZE)
+wxFLAGS_MEMBER(wxALWAYS_SHOW_SB )
+wxFLAGS_MEMBER(wxVSCROLL)
+wxFLAGS_MEMBER(wxHSCROLL)
+
+// frame styles
+wxFLAGS_MEMBER(wxSTAY_ON_TOP)
+wxFLAGS_MEMBER(wxCAPTION)
+#if WXWIN_COMPATIBILITY_2_6
+wxFLAGS_MEMBER(wxTHICK_FRAME)
+#endif // WXWIN_COMPATIBILITY_2_6
+wxFLAGS_MEMBER(wxSYSTEM_MENU)
+wxFLAGS_MEMBER(wxRESIZE_BORDER)
+#if WXWIN_COMPATIBILITY_2_6
+wxFLAGS_MEMBER(wxRESIZE_BOX)
+#endif // WXWIN_COMPATIBILITY_2_6
+wxFLAGS_MEMBER(wxCLOSE_BOX)
+wxFLAGS_MEMBER(wxMAXIMIZE_BOX)
+wxFLAGS_MEMBER(wxMINIMIZE_BOX)
+
+wxFLAGS_MEMBER(wxFRAME_TOOL_WINDOW)
+wxFLAGS_MEMBER(wxFRAME_FLOAT_ON_PARENT)
+
+wxFLAGS_MEMBER(wxFRAME_SHAPED)
+wxEND_FLAGS( wxFrameStyle )
+
+wxIMPLEMENT_DYNAMIC_CLASS_XTI(wxFrame, wxTopLevelWindow, "wx/frame.h")
+
+wxBEGIN_PROPERTIES_TABLE(wxFrame)
+wxEVENT_PROPERTY( Menu, wxEVT_COMMAND_MENU_SELECTED, wxCommandEvent)
+
+wxPROPERTY( Title,wxString, SetTitle, GetTitle, wxString(), 0 /*flags*/, \
+ wxT("Helpstring"), wxT("group"))
+wxPROPERTY_FLAGS( WindowStyle, wxFrameStyle, long, SetWindowStyleFlag, \
+ GetWindowStyleFlag, wxEMPTY_PARAMETER_VALUE, 0 /*flags*/, \
+ wxT("Helpstring"), wxT("group")) // style
+#if wxUSE_MENUS
+wxPROPERTY( MenuBar, wxMenuBar *, SetMenuBar, GetMenuBar, wxEMPTY_PARAMETER_VALUE, \
+ 0 /*flags*/, wxT("Helpstring"), wxT("group"))
+#endif
+wxEND_PROPERTIES_TABLE()
+
+wxEMPTY_HANDLERS_TABLE(wxFrame)
+
+wxCONSTRUCTOR_6( wxFrame, wxWindow*, Parent, wxWindowID, Id, wxString, Title, \
+ wxPoint, Position, wxSize, Size, long, WindowStyle)
+
// ----------------------------------------------------------------------------
// construction/destruction
// ----------------------------------------------------------------------------
bool wxFrameBase::ProcessCommand(int id)
{
- wxMenuBar *bar = GetMenuBar();
- if ( !bar )
- return false;
-
- wxMenuItem *item = bar->FindItem(id);
+ wxMenuItem* const item = FindItemInMenuBar(id);
if ( !item )
return false;
bool wxFrameBase::ProcessCommand(wxMenuItem *item)
{
- wxCommandEvent commandEvent(wxEVT_COMMAND_MENU_SELECTED, item->GetId());
- commandEvent.SetEventObject(this);
+ wxCHECK_MSG( item, false, wxS("Menu item can't be NULL") );
if (!item->IsEnabled())
return true;
if ((item->GetKind() == wxITEM_RADIO) && item->IsChecked() )
return true;
+ int checked;
if (item->IsCheckable())
{
item->Toggle();
// use the new value
- commandEvent.SetInt(item->IsChecked());
+ checked = item->IsChecked();
}
+ else // Uncheckable item.
+ {
+ checked = -1;
+ }
+
+ wxMenu* const menu = item->GetMenu();
+ wxCHECK_MSG( menu, false, wxS("Menu item should be attached to a menu") );
- return HandleWindowEvent(commandEvent);
+ return menu->SendEvent(item->GetId(), checked);
}
#endif // wxUSE_MENUS
// If coming from an idle event, we only want to update the menus if
// we're in the wxUSE_IDLEMENUUPDATES configuration, otherwise they
// will be update when the menu is opened later
-#if !wxUSE_IDLEMENUUPDATES
- if ( !(flags & wxUPDATE_UI_FROMIDLE) )
-#endif // wxUSE_IDLEMENUUPDATES
+ if ( !(flags & wxUPDATE_UI_FROMIDLE) || ShouldUpdateMenuFromIdle() )
DoMenuUpdates();
}
#endif // wxUSE_MENUS
void wxFrameBase::OnMenuOpen(wxMenuEvent& event)
{
-#if wxUSE_IDLEMENUUPDATES
- wxUnusedVar(event);
-#else // !wxUSE_IDLEMENUUPDATES
- // as we didn't update the menus from idle time, do it now
- DoMenuUpdates(event.GetMenu());
-#endif // wxUSE_IDLEMENUUPDATES/!wxUSE_IDLEMENUUPDATES
+ if ( !ShouldUpdateMenuFromIdle() )
+ {
+ // as we didn't update the menus from idle time, do it now
+ DoMenuUpdates(event.GetMenu());
+ }
}
void wxFrameBase::OnMenuClose(wxMenuEvent& WXUNUSED(event))
{
wxTopLevelWindow::OnInternalIdle();
-#if wxUSE_MENUS && wxUSE_IDLEMENUUPDATES
- if (wxUpdateUIEvent::CanUpdate(this))
+#if wxUSE_MENUS
+ if ( ShouldUpdateMenuFromIdle() && wxUpdateUIEvent::CanUpdate(this) )
DoMenuUpdates();
#endif
}