]> git.saurik.com Git - wxWidgets.git/blobdiff - src/gtk/toplevel.cpp
Made device to logical and vv conversion methods
[wxWidgets.git] / src / gtk / toplevel.cpp
index 3d4a155fc78828e730baa08ae9e4dbccae7e6484..cf9cca1cb21a4b5aea4cf9d8e0f25b780ff5c144 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "wx/gtk/private.h"
 #include "wx/evtloop.h"
+#include "wx/sysopt.h"
 
 #include <gtk/gtk.h>
 #include <gdk/gdkx.h>
@@ -111,8 +112,6 @@ static gboolean gtk_frame_focus_in_callback( GtkWidget *widget,
                                          GdkEvent *WXUNUSED(event),
                                          wxTopLevelWindowGTK *win )
 {
-    // don't need to install idle handler, its done from "event" signal
-
     switch ( g_sendActivateEvent )
     {
         case -1:
@@ -172,8 +171,6 @@ static gboolean gtk_frame_focus_out_callback( GtkWidget *widget,
                                           GdkEventFocus *WXUNUSED(gdk_event),
                                           wxTopLevelWindowGTK *win )
 {
-    // don't need to install idle handler, its done from "event" signal
-
     // if the focus goes out of our app alltogether, OnIdle() will send
     // wxActivateEvent, otherwise gtk_window_focus_in_callback() will reset
     // g_sendActivateEvent to -1
@@ -197,23 +194,6 @@ static gboolean gtk_frame_focus_out_callback( GtkWidget *widget,
 }
 }
 
-//-----------------------------------------------------------------------------
-// "focus" from m_window
-//-----------------------------------------------------------------------------
-
-extern "C" {
-static gboolean gtk_frame_focus_callback( GtkWidget *WXUNUSED(widget),
-                                          GtkDirectionType WXUNUSED(d),
-                                          wxWindow *WXUNUSED(win) )
-{
-    if (g_isIdle)
-        wxapp_install_idle_handler();
-
-    // This disables GTK's tab traversal
-    return TRUE;
-}
-}
-
 //-----------------------------------------------------------------------------
 // "size_allocate"
 //-----------------------------------------------------------------------------
@@ -221,9 +201,6 @@ static gboolean gtk_frame_focus_callback( GtkWidget *WXUNUSED(widget),
 extern "C" {
 static void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation* alloc, wxTopLevelWindowGTK *win )
 {
-    if (g_isIdle)
-        wxapp_install_idle_handler();
-
     if (!win->m_hasVMT)
         return;
 
@@ -248,6 +225,24 @@ static void gtk_frame_size_callback( GtkWidget *WXUNUSED(widget), GtkAllocation*
 }
 }
 
+// ----------------------------------------------------------------------------
+// "size_request"
+// ----------------------------------------------------------------------------
+
+extern "C" {
+void wxgtk_tlw_size_request_callback(GtkWidget * WXUNUSED(widget),
+                                     GtkRequisition *requisition,
+                                     wxTopLevelWindowGTK *win)
+{
+    // we must return the size of the window without WM decorations, otherwise
+    // GTK+ gets confused, so don't call just GetSize() here
+    int w, h;
+    win->GTKDoGetSize(&w, &h);
+
+    requisition->height = h;
+    requisition->width = w;
+}
+}
 //-----------------------------------------------------------------------------
 // "delete_event"
 //-----------------------------------------------------------------------------
@@ -258,8 +253,6 @@ gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget),
                            GdkEvent *WXUNUSED(event),
                            wxTopLevelWindowGTK *win )
 {
-    // don't need to install idle handler, its done from "event" signal
-
     if (win->IsEnabled() &&
         (g_openDialogs == 0 || (win->GetExtraStyle() & wxTOPLEVEL_EX_DIALOG) ||
          win->IsGrabbed()))
@@ -276,23 +269,19 @@ gtk_frame_delete_callback( GtkWidget *WXUNUSED(widget),
 
 extern "C" {
 static gboolean
-gtk_frame_configure_callback( GtkWidget *WXUNUSED(widget),
+gtk_frame_configure_callback( GtkWidget* widget,
                               GdkEventConfigure *WXUNUSED(event),
                               wxTopLevelWindowGTK *win )
 {
-    // don't need to install idle handler, its done from "event" signal
-
     if (!win->m_hasVMT || !win->IsShown())
         return FALSE;
 
+    wxPoint point;
+    gtk_window_get_position((GtkWindow*)widget, &point.x, &point.y);
 
-    int x = 0;
-    int y = 0;
-    gdk_window_get_root_origin( win->m_widget->window, &x, &y );
-    win->m_x = x;
-    win->m_y = y;
-
-    wxMoveEvent mevent( wxPoint(win->m_x,win->m_y), win->GetId() );
+    win->m_x = point.x;
+    win->m_y = point.y;
+    wxMoveEvent mevent(point, win->GetId());
     mevent.SetEventObject( win );
     win->GetEventHandler()->ProcessEvent( mevent );
 
@@ -312,9 +301,6 @@ static void
 gtk_frame_realized_callback( GtkWidget * WXUNUSED(widget),
                              wxTopLevelWindowGTK *win )
 {
-    if (g_isIdle)
-        wxapp_install_idle_handler();
-
     // All this is for Motif Window Manager "hints" and is supposed to be
     // recognized by other WM as well. Not tested.
     gdk_window_set_decorations(win->m_widget->window,
@@ -330,7 +316,7 @@ gtk_frame_realized_callback( GtkWidget * WXUNUSED(widget),
 
     // reset the icon
     wxIconBundle iconsOld = win->GetIcons();
-    if ( iconsOld.GetIcon(-1).Ok() )
+    if ( !iconsOld.IsEmpty() )
     {
         win->SetIcon( wxNullIcon );
         win->SetIcons( iconsOld );
@@ -343,12 +329,13 @@ gtk_frame_realized_callback( GtkWidget * WXUNUSED(widget),
 //-----------------------------------------------------------------------------
 
 extern "C" {
-static void
+static gboolean
 gtk_frame_map_callback( GtkWidget * WXUNUSED(widget),
                         GdkEvent * WXUNUSED(event),
                         wxTopLevelWindow *win )
 {
     win->SetIconizeState(false);
+    return false;
 }
 }
 
@@ -357,12 +344,13 @@ gtk_frame_map_callback( GtkWidget * WXUNUSED(widget),
 //-----------------------------------------------------------------------------
 
 extern "C" {
-static void
+static gboolean
 gtk_frame_unmap_callback( GtkWidget * WXUNUSED(widget),
                           GdkEvent * WXUNUSED(event),
                           wxTopLevelWindow *win )
 {
     win->SetIconizeState(true);
+    return false;
 }
 }
 
@@ -412,7 +400,7 @@ static void wxInsertChildInTopLevelWindow( wxTopLevelWindowGTK* parent, wxWindow
         // these are outside the client area
         wxTopLevelWindowGTK* frame = (wxTopLevelWindowGTK*) parent;
         gtk_pizza_put( GTK_PIZZA(frame->m_mainWidget),
-                         GTK_WIDGET(child->m_widget),
+                         child->m_widget,
                          child->m_x,
                          child->m_y,
                          child->m_width,
@@ -422,7 +410,7 @@ static void wxInsertChildInTopLevelWindow( wxTopLevelWindowGTK* parent, wxWindow
     {
         // these are inside the client area
         gtk_pizza_put( GTK_PIZZA(parent->m_wxwindow),
-                         GTK_WIDGET(child->m_widget),
+                         child->m_widget,
                          child->m_x,
                          child->m_y,
                          child->m_width,
@@ -467,8 +455,6 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
 
     wxTopLevelWindows.Append( this );
 
-    m_needParent = false;
-
     if (!PreCreation( parent, pos, size ) ||
         !CreateBase( parent, id, pos, size, style, wxDefaultValidator, name ))
     {
@@ -586,6 +572,8 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
     g_signal_connect (m_widget, "size_allocate",
                       G_CALLBACK (gtk_frame_size_callback), this);
 
+    g_signal_connect (m_widget, "size_request",
+                      G_CALLBACK (wxgtk_tlw_size_request_callback), this);
     PostCreation();
 
     if ((m_x != -1) || (m_y != -1))
@@ -604,14 +592,10 @@ bool wxTopLevelWindowGTK::Create( wxWindow *parent,
     g_signal_connect (m_widget, "unmap_event",
                       G_CALLBACK (gtk_frame_unmap_callback), this);
 
-    // the only way to get the window size is to connect to this event
+    // for wxMoveEvent
     g_signal_connect (m_widget, "configure_event",
                       G_CALLBACK (gtk_frame_configure_callback), this);
 
-    // disable native tab traversal
-    g_signal_connect (m_widget, "focus",
-                      G_CALLBACK (gtk_frame_focus_callback), this);
-
     // activation
     g_signal_connect_after (m_widget, "focus_in_event",
                       G_CALLBACK (gtk_frame_focus_in_callback), this);
@@ -814,7 +798,7 @@ bool wxTopLevelWindowGTK::Show( bool show )
     wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
 
     if (show == IsShown())
-        return true;
+        return false;
 
     if (show && !m_sizeSet)
     {
@@ -826,13 +810,17 @@ bool wxTopLevelWindowGTK::Show( bool show )
         GtkOnSize();
     }
 
-    // This seems no longer to be needed and the call
-    // itself is deprecated.
-    //
-    //if (show)
-    //    gtk_widget_set_uposition( m_widget, m_x, m_y );
+    wxTopLevelWindowBase::Show(show);
 
-    return wxWindow::Show( show );
+    if (!show)
+    {
+        // make sure window has a non-default position, so when it is shown
+        // again, it won't be repositioned by WM as if it were a new window
+        // Note that this must be done _after_ the window is hidden.
+        gtk_window_move((GtkWindow*)m_widget, m_x, m_y);
+    }
+
+    return true;
 }
 
 void wxTopLevelWindowGTK::Raise()
@@ -849,6 +837,11 @@ void wxTopLevelWindowGTK::DoMoveWindow(int WXUNUSED(x), int WXUNUSED(y), int WXU
 // window geometry
 // ----------------------------------------------------------------------------
 
+void wxTopLevelWindowGTK::GTKDoGetSize(int *width, int *height) const
+{
+    return wxTopLevelWindowBase::DoGetSize(width, height);
+}
+
 void wxTopLevelWindowGTK::GTKDoSetSize(int width, int height)
 {
     // avoid recursions
@@ -864,23 +857,7 @@ void wxTopLevelWindowGTK::GTKDoSetSize(int width, int height)
     if ( height != -1 )
         m_height = height;
 
-    // GPE's window manager doesn't like size hints at all, esp. when the user
-    // has to use the virtual keyboard, so don't constrain size there
-#ifndef __WXGPE__
-    int minWidth = GetMinWidth(),
-        minHeight = GetMinHeight(),
-        maxWidth = GetMaxWidth(),
-        maxHeight = GetMaxHeight();
-
-    if ( minWidth != -1 && m_width < minWidth )
-        m_width = minWidth;
-    if ( minHeight != -1 && m_height < minHeight )
-        m_height = minHeight;
-    if ( maxWidth != -1 && m_width > maxWidth )
-        m_width = maxWidth;
-    if ( maxHeight != -1 && m_height > maxHeight )
-        m_height = maxHeight;
-#endif // __WXGPE__
+    ConstrainSize();
 
     if ( m_width != old_width || m_height != old_height )
     {
@@ -938,7 +915,7 @@ void wxTopLevelWindowGTK::DoSetSize( int x, int y, int width, int height, int si
 
         int wUndec,
             hUndec;
-        wxTopLevelWindowBase::DoGetSize(&wUndec, &hUndec);
+        GTKDoGetSize(&wUndec, &hUndec);
 
         if ( width != -1 )
             width -= wTotal - wUndec;
@@ -957,7 +934,7 @@ void wxTopLevelWindowGTK::DoGetSize(int *width, int *height) const
     {
         // this can happen if we're called before the window is realized, so
         // don't assert but just return the stored values
-        wxTopLevelWindowBase::DoGetSize(width, height);
+        GTKDoGetSize(width, height);
         return;
     }
 
@@ -972,6 +949,18 @@ void wxTopLevelWindowGTK::DoGetSize(int *width, int *height) const
 
 void wxTopLevelWindowGTK::DoGetClientSize( int *width, int *height ) const
 {
+    if ( IsIconized() )
+    {
+        // for consistency with wxMSW, client area is supposed to be empty for
+        // the iconized windows
+        if ( width )
+            *width = 0;
+        if ( height )
+            *height = 0;
+
+        return;
+    }
+
     wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
 
     if (height)
@@ -1041,25 +1030,7 @@ void wxTopLevelWindowGTK::GtkOnSize()
        skip the part which handles m_frameMenuBar, m_frameToolBar and (most
        importantly) m_mainWidget */
 
-    int minWidth = GetMinWidth(),
-        minHeight = GetMinHeight(),
-        maxWidth = GetMaxWidth(),
-        maxHeight = GetMaxHeight();
-
-#ifdef __WXGPE__
-    // GPE's window manager doesn't like size hints
-    // at all, esp. when the user has to use the
-    // virtual keyboard.
-    minWidth = -1;
-    minHeight = -1;
-    maxWidth = -1;
-    maxHeight = -1;
-#endif
-
-    if ((minWidth != -1) && (m_width < minWidth)) m_width = minWidth;
-    if ((minHeight != -1) && (m_height < minHeight)) m_height = minHeight;
-    if ((maxWidth != -1) && (m_width > maxWidth)) m_width = maxWidth;
-    if ((maxHeight != -1) && (m_height > maxHeight)) m_height = maxHeight;
+    ConstrainSize();
 
     if (m_mainWidget)
     {
@@ -1102,8 +1073,6 @@ void wxTopLevelWindowGTK::OnInternalIdle()
         GtkOnSize();
 
         // we'll come back later
-        if (g_isIdle)
-            wxapp_install_idle_handler();
         return;
     }
 
@@ -1156,11 +1125,6 @@ void wxTopLevelWindowGTK::SetTitle( const wxString &title )
     gtk_window_set_title( GTK_WINDOW(m_widget), wxGTK_CONV( title ) );
 }
 
-void wxTopLevelWindowGTK::SetIcon( const wxIcon &icon )
-{
-    SetIcons( wxIconBundle( icon ) );
-}
-
 void wxTopLevelWindowGTK::SetIcons( const wxIconBundle &icons )
 {
     wxASSERT_MSG( (m_widget != NULL), wxT("invalid frame") );
@@ -1168,15 +1132,13 @@ void wxTopLevelWindowGTK::SetIcons( const wxIconBundle &icons )
     wxTopLevelWindowBase::SetIcons( icons );
 
     GList *list = NULL;
-    size_t max = icons.m_icons.GetCount();
 
-    for (size_t i = 0; i < max; i++)
+    const size_t numIcons = icons.GetIconCount();
+    for ( size_t i = 0; i < numIcons; i++ )
     {
-        if (icons.m_icons[i].Ok())
-        {
-            list = g_list_prepend(list, icons.m_icons[i].GetPixbuf());
-        }
+        list = g_list_prepend(list, icons.GetIconByIndex(i).GetPixbuf());
     }
+
     gtk_window_set_icon_list(GTK_WINDOW(m_widget), list);
     g_list_free(list);
 }
@@ -1399,6 +1361,13 @@ bool wxTopLevelWindowGTK::SetTransparent(wxByte alpha)
 
 bool wxTopLevelWindowGTK::CanSetTransparent()
 {
+    // allow to override automatic detection as it's far from perfect
+    static const wxChar *SYSOPT_TRANSPARENT = wxT("gtk.tlw.can-set-transparent");
+    if ( wxSystemOptions::HasOption(SYSOPT_TRANSPARENT) )
+    {
+        return wxSystemOptions::GetOptionInt(SYSOPT_TRANSPARENT) != 0;
+    }
+
 #if GTK_CHECK_VERSION(2,10,0)
     if (!gtk_check_version(2,10,0))
     {