diff --git a/contrib/gtkgensurf/gtkcompat.h b/contrib/gtkgensurf/gtkcompat.h new file mode 100644 index 00000000..e3789acc --- /dev/null +++ b/contrib/gtkgensurf/gtkcompat.h @@ -0,0 +1,5 @@ + +#if ! GTK_CHECK_VERSION(3, 0, 0) +# define gtk_widget_get_allocated_height(widget) (((GtkWidget *) (widget))->allocation.height) +# define gtk_widget_get_allocated_width(widget) (((GtkWidget *) (widget))->allocation.width) +#endif diff --git a/contrib/gtkgensurf/view.cpp b/contrib/gtkgensurf/view.cpp index ab24dcbd..105af8c0 100644 --- a/contrib/gtkgensurf/view.cpp +++ b/contrib/gtkgensurf/view.cpp @@ -21,6 +21,7 @@ #include #include #include "gensurf.h" +#include "gtkcompat.h" #undef ISOMETRIC @@ -101,7 +102,7 @@ void ShowPreview(){ } static void draw_preview(){ - int width = g_pPreviewWidget->allocation.width, height = g_pPreviewWidget->allocation.height; + int width = gtk_widget_get_allocated_width( g_pPreviewWidget ), height = gtk_widget_get_allocated_height( g_pPreviewWidget ); g_GLTable.m_pfn_qglClearColor( 0, 0, 0, 1 ); g_GLTable.m_pfn_qglViewport( 0, 0, width, height ); @@ -181,7 +182,7 @@ static gint expose( GtkWidget *widget, GdkEventExpose *event, gpointer data ){ } static void button_press( GtkWidget *widget, GdkEventButton *event, gpointer data ){ - POINT pt = { (long)event->x, widget->allocation.height - (long)event->y }; + POINT pt = { (long)event->x, gtk_widget_get_allocated_height( widget ) - (long)event->y }; bool Selected; double x,y; int i, j, k, ks; @@ -290,7 +291,7 @@ static void button_press( GtkWidget *widget, GdkEventButton *event, gpointer dat } static void motion( GtkWidget *widget, GdkEventMotion *event, gpointer data ){ - POINT pt = { (long)event->x, widget->allocation.height - (long)event->y }; + POINT pt = { (long)event->x, gtk_widget_get_allocated_height( widget ) - (long)event->y }; if ( !VertexMode ) { return; diff --git a/plugins/textool/TexTool.cpp b/plugins/textool/TexTool.cpp index 40322b90..47e4f997 100644 --- a/plugins/textool/TexTool.cpp +++ b/plugins/textool/TexTool.cpp @@ -27,6 +27,7 @@ // #include "StdAfx.h" +#include "gtkcompat.h" static void dialog_button_callback( GtkWidget *widget, gpointer data ){ GtkWidget *parent; @@ -588,8 +589,8 @@ static gint expose( GtkWidget *widget, GdkEventExpose *event, gpointer data ){ } if ( g_bTexViewReady ) { - g_2DView.m_rect.bottom = widget->allocation.height; - g_2DView.m_rect.right = widget->allocation.width; + g_2DView.m_rect.bottom = gtk_widget_get_allocated_height( widget ); + g_2DView.m_rect.right = gtk_widget_get_allocated_width( widget ); if ( !g_QglTable.m_pfn_glwidget_make_current( g_pToolWidget ) ) { Sys_Printf( "TexTool: glMakeCurrent failed\n" ); diff --git a/plugins/textool/gtkcompat.h b/plugins/textool/gtkcompat.h new file mode 100644 index 00000000..e3789acc --- /dev/null +++ b/plugins/textool/gtkcompat.h @@ -0,0 +1,5 @@ + +#if ! GTK_CHECK_VERSION(3, 0, 0) +# define gtk_widget_get_allocated_height(widget) (((GtkWidget *) (widget))->allocation.height) +# define gtk_widget_get_allocated_width(widget) (((GtkWidget *) (widget))->allocation.width) +#endif diff --git a/radiant/camwindow.cpp b/radiant/camwindow.cpp index 4655d1a3..8a8d5e0f 100644 --- a/radiant/camwindow.cpp +++ b/radiant/camwindow.cpp @@ -26,6 +26,7 @@ // #include "stdafx.h" +#include "gtkcompat.h" #include #include @@ -140,7 +141,7 @@ void update_xor_rectangle( XORRectangle& xor_rectangle ){ } void CamWnd::OnMouseMove( guint32 flags, int pointx, int pointy ){ - int height = m_pWidget->allocation.height; + int height = gtk_widget_get_allocated_height( m_pWidget ); // NOTE RR2DO2 this hasn't got any use anymore really. It is an old qeradiant feature // that can be re-enabled by removing the checks for HasCapture and not shift/ctrl down // but the scaling/rotating (unless done with the steps set in the surface inspector @@ -208,7 +209,7 @@ void CamWnd::OnRButtonUp( guint32 nFlags, int pointx, int pointy ){ } void CamWnd::OriginalMouseUp( guint32 nFlags, int pointx, int pointy ){ - int height = m_pWidget->allocation.height; + int height = gtk_widget_get_allocated_height( m_pWidget ); if ( g_qeglobals.d_select_mode == sel_facets_on || g_qeglobals.d_select_mode == sel_facets_off ) { g_qeglobals.d_select_mode = sel_brush; @@ -221,7 +222,7 @@ void CamWnd::OriginalMouseUp( guint32 nFlags, int pointx, int pointy ){ } void CamWnd::OriginalMouseDown( guint32 nFlags, int pointx, int pointy ){ - int height = m_pWidget->allocation.height; + int height = gtk_widget_get_allocated_height( m_pWidget ); SetFocus(); SetCapture(); diff --git a/radiant/gtkcompat.h b/radiant/gtkcompat.h new file mode 100644 index 00000000..e3789acc --- /dev/null +++ b/radiant/gtkcompat.h @@ -0,0 +1,5 @@ + +#if ! GTK_CHECK_VERSION(3, 0, 0) +# define gtk_widget_get_allocated_height(widget) (((GtkWidget *) (widget))->allocation.height) +# define gtk_widget_get_allocated_width(widget) (((GtkWidget *) (widget))->allocation.width) +#endif diff --git a/radiant/gtkmisc.cpp b/radiant/gtkmisc.cpp index 1a62b3db..aaebae81 100644 --- a/radiant/gtkmisc.cpp +++ b/radiant/gtkmisc.cpp @@ -40,6 +40,7 @@ #endif #include +#include "gtkcompat.h" #ifdef _WIN32 #include @@ -70,8 +71,8 @@ void save_window_pos( GtkWidget *wnd, window_position_t& pos ){ get_window_pos( wnd, &pos.x, &pos.y ); - pos.w = wnd->allocation.width; - pos.h = wnd->allocation.height; + pos.w = gtk_widget_get_allocated_width( wnd ); + pos.h = gtk_widget_get_allocated_height( wnd ); #ifdef DBG_WINDOWPOS //Sys_Printf("save_window_pos 'Window %s'\n",buf); @@ -94,9 +95,9 @@ void win32_get_window_pos( GtkWidget *widget, gint *x, gint *y ){ *x = point.x; *y = point.y; - *x = max( *x,-widget->allocation.width + 10 ); + *x = max( *x,-gtk_widget_get_allocated_width( widget ) + 10 ); *x = min( *x,primaryMonitorRect.width - 10 ); - *y = max( *y,-widget->allocation.height + 10 ); + *y = max( *y,-gtk_widget_get_allocated_height( widget ) + 10 ); *y = min( *y,primaryMonitorRect.height - 10 ); } else { diff --git a/radiant/mainframe.cpp b/radiant/mainframe.cpp index e0fefa21..ec7a9ab0 100644 --- a/radiant/mainframe.cpp +++ b/radiant/mainframe.cpp @@ -39,6 +39,7 @@ extern "C" { #if defined ( __linux__ ) || defined ( __APPLE__ ) #include #endif +#include "gtkcompat.h" #include "gtkmisc.h" #include "groupdialog.h" #include "patchdialog.h" @@ -2274,9 +2275,9 @@ GtkWidget *watchit = NULL; void CheckWatchit( char *msg ){ static int width = 0; - if ( ( watchit != NULL ) && ( watchit->allocation.width != width ) ) { - Sys_Printf( "CheckWatchit %s: %d\n", msg, watchit->allocation.width ); - width = watchit->allocation.width; + if ( ( watchit != NULL ) && ( gtk_widget_get_allocated_width( watchit ) != width ) ) { + Sys_Printf( "CheckWatchit %s: %d\n", msg, gtk_widget_get_allocated_width( watchit ) ); + width = gtk_widget_get_allocated_width( watchit ); } } #endif diff --git a/radiant/texwindow.cpp b/radiant/texwindow.cpp index 3a09e7bc..6b0b9a5d 100644 --- a/radiant/texwindow.cpp +++ b/radiant/texwindow.cpp @@ -48,6 +48,7 @@ #include "str.h" #include "missing.h" #include "texmanip.h" +#include "gtkcompat.h" #define TYP_MIPTEX 68 @@ -1702,7 +1703,7 @@ void TexWnd::OnExpose() { else { QE_CheckOpenGLForErrors(); - Texture_Draw( m_pWidget->allocation.width, m_pWidget->allocation.height - g_nTextureOffset ); + Texture_Draw( gtk_widget_get_allocated_width( m_pWidget ), gtk_widget_get_allocated_height( m_pWidget ) - g_nTextureOffset ); QE_CheckOpenGLForErrors(); SwapBuffers(); } @@ -1710,8 +1711,8 @@ void TexWnd::OnExpose() { GtkAdjustment *vadjustment = gtk_range_get_adjustment( GTK_RANGE( g_qeglobals_gui.d_texture_scroll ) ); gtk_adjustment_set_value( vadjustment, -g_qeglobals.d_texturewin.originy ); - gtk_adjustment_set_page_size( vadjustment, m_pWidget->allocation.height ); - gtk_adjustment_set_page_increment( vadjustment, m_pWidget->allocation.height / 2 ); + gtk_adjustment_set_page_size( vadjustment, gtk_widget_get_allocated_height( m_pWidget ) ); + gtk_adjustment_set_page_increment( vadjustment, gtk_widget_get_allocated_height( m_pWidget ) / 2 ); gtk_adjustment_set_step_increment( vadjustment, 20 ); gtk_adjustment_set_lower( vadjustment, 0 ); gtk_adjustment_set_upper( vadjustment, g_qeglobals.d_texturewin.m_nTotalHeight ); @@ -1842,8 +1843,8 @@ void TexWnd::DragDropTexture( guint32 flags, int pointx, int pointy ){ get_window_pos( widget, &x, &y ); if ( m_ptX < x || m_ptY < y || - m_ptX > x + widget->allocation.width || - m_ptY > y + widget->allocation.height ) { + m_ptX > x + gtk_widget_get_allocated_width( widget ) || + m_ptY > y + gtk_widget_get_allocated_height( widget ) ) { return; } diff --git a/radiant/ui.cpp b/radiant/ui.cpp index 08609aeb..ac05bf38 100644 --- a/radiant/ui.cpp +++ b/radiant/ui.cpp @@ -26,6 +26,7 @@ // #include "stdafx.h" +#include "gtkcompat.h" CPtrArray l_Listeners[RADIANT_MSGCOUNT]; CPtrArray l_WindowListeners; @@ -230,7 +231,7 @@ void DispatchRadiantMsg( int Msg ){ } void CXYWndWrapper::SnapToGrid( int x1, int y1, vec3_t pt ){ - int height = g_pParentWnd->ActiveXY()->GetWidget()->allocation.height; + int height = gtk_widget_get_allocated_height( g_pParentWnd->ActiveXY()->GetWidget() ); g_pParentWnd->ActiveXY()->SnapToPoint( x1, height - 1 - y1, pt ); } diff --git a/radiant/xywindow.cpp b/radiant/xywindow.cpp index 07de2def..7c641cad 100644 --- a/radiant/xywindow.cpp +++ b/radiant/xywindow.cpp @@ -26,6 +26,7 @@ // #include "stdafx.h" +#include "gtkcompat.h" #include #include #include @@ -461,7 +462,7 @@ void CreateEntityFromName( const char* name, const vec3_t origin ){ } void CreateRightClickEntity( XYWnd* pWnd, int x, int y, const char* pName ){ - int height = pWnd->GetWidget()->allocation.height; + int height = gtk_widget_get_allocated_height( pWnd->GetWidget() ); vec3_t point; pWnd->SnapToPoint( x, height - 1 - y, point ); @@ -1875,19 +1876,19 @@ void XYWnd::XY_MouseMoved( int x, int y, int buttons ){ void XYWnd::OriginalButtonDown( guint32 nFlags, int pointx, int pointy ){ SetFocus(); SetCapture(); - XY_MouseDown( pointx, m_pWidget->allocation.height - 1 - pointy, nFlags ); + XY_MouseDown( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, nFlags ); m_nScrollFlags = nFlags; } void XYWnd::OriginalButtonUp( guint32 nFlags, int pointx, int pointy ){ - XY_MouseUp( pointx, m_pWidget->allocation.height - 1 - pointy, nFlags ); + XY_MouseUp( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, nFlags ); ReleaseCapture(); } void XYWnd::DropClipPoint( guint32 nFlags, int pointx, int pointy ){ if ( g_pMovingClip ) { SetCapture(); - SnapToPoint( pointx, m_pWidget->allocation.height - 1 - pointy, *g_pMovingClip ); + SnapToPoint( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, *g_pMovingClip ); } else { @@ -1920,7 +1921,7 @@ void XYWnd::DropClipPoint( guint32 nFlags, int pointx, int pointy ){ g_Clip1.m_ptScreenX = pointx; g_Clip1.m_ptScreenY = pointy; } - SnapToPoint( pointx, m_pWidget->allocation.height - 1 - pointy, *pPt ); + SnapToPoint( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, *pPt ); // third coordinates for clip point: use d_work_max // Arnout: changed to use center of selection for clipping, saves level designers moving points all over the map // g_pParentWnd->ActiveXY()->GetViewType() @@ -1938,14 +1939,14 @@ void XYWnd::DropClipPoint( guint32 nFlags, int pointx, int pointy ){ void XYWnd::DropPathPoint( guint32 nFlags, int pointx, int pointy ){ if ( g_pMovingPath ) { SetCapture(); - SnapToPoint( pointx, m_pWidget->allocation.height - 1 - pointy, *g_pMovingPath ); + SnapToPoint( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, *g_pMovingPath ); } else { g_PathPoints[g_nPathCount].Set( true ); g_PathPoints[g_nPathCount].m_ptScreenX = pointx; g_PathPoints[g_nPathCount].m_ptScreenY = pointy; - SnapToPoint( pointx, m_pWidget->allocation.height - 1 - pointy, g_PathPoints[g_nPathCount] ); + SnapToPoint( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, g_PathPoints[g_nPathCount] ); // third coordinates for dropped point: use d_work_max // g_pParentWnd->ActiveXY()->GetViewType() // cf VIEWTYPE definition: enum VIEWTYPE {YZ, XZ, XY}; diff --git a/radiant/zwindow.cpp b/radiant/zwindow.cpp index 810ea526..5ab0369d 100644 --- a/radiant/zwindow.cpp +++ b/radiant/zwindow.cpp @@ -27,6 +27,7 @@ #include "stdafx.h" #include "zwindow.h" +#include "gtkcompat.h" // ============================================================================= // ZWnd class @@ -49,43 +50,43 @@ void ZWnd::OnCreate(){ void ZWnd::OnLButtonDown( guint32 nFlags, int pointx, int pointy ){ SetFocus(); SetCapture(); - Z_MouseDown( pointx, m_pWidget->allocation.height - 1 - pointy, nFlags ); + Z_MouseDown( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, nFlags ); } void ZWnd::OnMButtonDown( guint32 nFlags, int pointx, int pointy ){ SetFocus(); SetCapture(); - Z_MouseDown( pointx, m_pWidget->allocation.height - 1 - pointy, nFlags ); + Z_MouseDown( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, nFlags ); } void ZWnd::OnRButtonDown( guint32 nFlags, int pointx, int pointy ){ SetFocus(); SetCapture(); - Z_MouseDown( pointx, m_pWidget->allocation.height - 1 - pointy, nFlags ); + Z_MouseDown( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, nFlags ); } void ZWnd::OnLButtonUp( guint32 nFlags, int pointx, int pointy ){ - Z_MouseUp( pointx, m_pWidget->allocation.height - 1 - pointy, nFlags ); + Z_MouseUp( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, nFlags ); ReleaseCapture(); } void ZWnd::OnMButtonUp( guint32 nFlags, int pointx, int pointy ){ - Z_MouseUp( pointx, m_pWidget->allocation.height - 1 - pointy, nFlags ); + Z_MouseUp( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, nFlags ); ReleaseCapture(); } void ZWnd::OnRButtonUp( guint32 nFlags, int pointx, int pointy ){ - Z_MouseUp( pointx, m_pWidget->allocation.height - 1 - pointy, nFlags ); + Z_MouseUp( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, nFlags ); ReleaseCapture(); } void ZWnd::OnMouseMove( guint32 nFlags, int pointx, int pointy ){ - float fz = z.origin[2] + ( ( m_pWidget->allocation.height - 1 - pointy ) - ( z.height / 2 ) ) / z.scale; + float fz = z.origin[2] + ( ( gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy ) - ( z.height / 2 ) ) / z.scale; fz = floor( fz / g_qeglobals.d_gridsize + 0.5 ) * g_qeglobals.d_gridsize; CString strStatus; strStatus.Format( "Z:: %.1f", fz ); g_pParentWnd->SetStatusText( 1, strStatus ); - Z_MouseMoved( pointx, m_pWidget->allocation.height - 1 - pointy, nFlags ); + Z_MouseMoved( pointx, gtk_widget_get_allocated_height( m_pWidget ) - 1 - pointy, nFlags ); } void ZWnd::OnExpose(){