From e2f3bc41106f177e3d4ab717961c1a2469abdbef Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Mon, 12 Nov 2007 00:25:09 +0000 Subject: [PATCH] some Hildon integration work: use HildonProgram (for integration with the OS), HildonWindow (which has native appearance) and more native-like menus git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49841 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/gtk/app.h | 12 ++++++++++++ src/common/menucmn.cpp | 1 - src/gtk/app.cpp | 13 +++++++++++++ src/gtk/frame.cpp | 13 +++++++++++++ src/gtk/menu.cpp | 8 +++++++- src/gtk/toplevel.cpp | 19 +++++++++++++++++++ 6 files changed, 64 insertions(+), 2 deletions(-) diff --git a/include/wx/gtk/app.h b/include/wx/gtk/app.h index d9a34eee80..b258ea5a99 100644 --- a/include/wx/gtk/app.h +++ b/include/wx/gtk/app.h @@ -18,6 +18,10 @@ class WXDLLIMPEXP_FWD_BASE wxMutex; #endif +#if wxUSE_LIBHILDON +typedef struct _HildonProgram HildonProgram; +#endif // wxUSE_LIBHILDON + //----------------------------------------------------------------------------- // wxApp //----------------------------------------------------------------------------- @@ -58,6 +62,10 @@ public: // must return XVisualInfo pointer (it is not freed by caller) virtual void *GetXVisualInfo() { return NULL; } +#if wxUSE_LIBHILDON + // Maemo-specific method: get the main program object + HildonProgram *GetHildonProgram() const { return m_hildonProgram; } +#endif // wxUSE_LIBHILDON // implementation only from now on // ------------------------------- @@ -80,6 +88,10 @@ private: #endif guint m_idleSourceId; +#if wxUSE_LIBHILDON + HildonProgram *m_hildonProgram; +#endif // wxUSE_LIBHILDON + DECLARE_DYNAMIC_CLASS(wxApp) }; diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index 884fa75167..d7ae6c33d2 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -852,5 +852,4 @@ wxString wxMenuBarBase::GetLabelTop(size_t pos) const } #endif - #endif // wxUSE_MENUS diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index 62cf72b0be..12b3f4dfdd 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -29,6 +29,10 @@ #include "wx/gtk/private.h" #include "wx/apptrait.h" +#if wxUSE_LIBHILDON + #include +#endif // wxUSE_LIBHILDON + #include //----------------------------------------------------------------------------- @@ -317,6 +321,15 @@ bool wxApp::OnInitGui() } } +#if wxUSE_LIBHILDON + m_hildonProgram = hildon_program_get_instance(); + if ( !m_hildonProgram ) + { + wxLogError(_("Unable to initialize Hildon program")); + return false; + } +#endif // wxUSE_LIBHILDON + return true; } diff --git a/src/gtk/frame.cpp b/src/gtk/frame.cpp index 3c1c9f91c3..118148b185 100644 --- a/src/gtk/frame.cpp +++ b/src/gtk/frame.cpp @@ -20,6 +20,10 @@ #include +#if wxUSE_LIBHILDON + #include +#endif // wxUSE_LIBHILDON + // ---------------------------------------------------------------------------- // event tables // ---------------------------------------------------------------------------- @@ -267,11 +271,15 @@ void wxFrame::DetachMenuBar() if ( m_frameMenuBar ) { +#if wxUSE_LIBHILDON + hildon_window_set_menu(HILDON_WINDOW(m_widget), NULL); +#else // !wxUSE_LIBHILDON m_frameMenuBar->UnsetInvokingWindow( this ); gtk_widget_ref( m_frameMenuBar->m_widget ); gtk_container_remove( GTK_CONTAINER(m_mainWidget), m_frameMenuBar->m_widget ); +#endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON } wxFrameBase::DetachMenuBar(); @@ -286,6 +294,10 @@ void wxFrame::AttachMenuBar( wxMenuBar *menuBar ) if (m_frameMenuBar) { +#if wxUSE_LIBHILDON + hildon_window_set_menu(HILDON_WINDOW(m_widget), + GTK_MENU(m_frameMenuBar->m_menubar)); +#else // !wxUSE_LIBHILDON m_frameMenuBar->SetInvokingWindow( this ); m_frameMenuBar->SetParent(this); @@ -309,6 +321,7 @@ void wxFrame::AttachMenuBar( wxMenuBar *menuBar ) gtk_widget_set_size_request(menuBar->m_widget, -1, -1); gtk_widget_show( m_frameMenuBar->m_widget ); +#endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON } // make sure next size_allocate causes a wxSizeEvent m_oldClientWidth = 0; diff --git a/src/gtk/menu.cpp b/src/gtk/menu.cpp index bfea8d8999..6e1d23f4c3 100644 --- a/src/gtk/menu.cpp +++ b/src/gtk/menu.cpp @@ -174,6 +174,12 @@ void wxMenuBar::Init(size_t n, wxMenu *menus[], const wxString titles[], long st m_style = style; m_invokingWindow = NULL; +#if wxUSE_LIBHILDON + // Hildon window uses a single menu instead of a menu bar, so wxMenuBar is + // the same as menu in this case + m_widget = + m_menubar = gtk_menu_new(); +#else // !wxUSE_LIBHILDON if (!PreCreation( NULL, wxDefaultPosition, wxDefaultSize ) || !CreateBase( NULL, -1, wxDefaultPosition, wxDefaultSize, style, wxDefaultValidator, wxT("menubar") )) { @@ -197,6 +203,7 @@ void wxMenuBar::Init(size_t n, wxMenu *menus[], const wxString titles[], long st PostCreation(); ApplyWidgetStyle(); +#endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON for (size_t i = 0; i < n; ++i ) Append(menus[i], titles[i]); @@ -207,7 +214,6 @@ void wxMenuBar::Init(size_t n, wxMenu *menus[], const wxString titles[], long st // can't pass the menu which was closed in wxMenuEvent object g_signal_connect (m_menubar, "deactivate", G_CALLBACK (gtk_menu_close_callback), this); - } wxMenuBar::wxMenuBar(size_t n, wxMenu *menus[], const wxString titles[], long style) diff --git a/src/gtk/toplevel.cpp b/src/gtk/toplevel.cpp index 2aa4cc4e5a..caca06176d 100644 --- a/src/gtk/toplevel.cpp +++ b/src/gtk/toplevel.cpp @@ -45,6 +45,11 @@ // XA_CARDINAL #include +#if wxUSE_LIBHILDON + #include + #include +#endif // wxUSE_LIBHILDON + // ---------------------------------------------------------------------------- // data // ---------------------------------------------------------------------------- @@ -503,6 +508,14 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent, // e.g. in wxTaskBarIconAreaGTK if (m_widget == NULL) { +#if wxUSE_LIBHILDON + // we must create HildonWindow and not a normal GtkWindow as the latter + // doesn't look correctly in Maemo environment and it must also be + // registered with the main program object + m_widget = hildon_window_new(); + hildon_program_add_window(wxTheApp->GetHildonProgram(), + HILDON_WINDOW(m_widget)); +#else // !wxUSE_LIBHILDON m_widget = gtk_window_new(GTK_WINDOW_TOPLEVEL); if (GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) { @@ -529,6 +542,7 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent, style |= wxFRAME_NO_TASKBAR; } } +#endif // wxUSE_LIBHILDON/!wxUSE_LIBHILDON } wxWindow *topParent = wxGetTopLevelParent(m_parent); @@ -665,6 +679,11 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent, wxTopLevelWindowGTK::~wxTopLevelWindowGTK() { +#if wxUSE_LIBHILDON + hildon_program_remove_window(wxTheApp->GetHildonProgram(), + HILDON_WINDOW(m_widget)); +#endif // wxUSE_LIBHILDON + if (m_grabbed) { wxFAIL_MSG(_T("Window still grabbed")); -- 2.47.2