From c2fa61e833ffe9789ef3d3327157e17101a4a2ce Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 11 May 2001 17:55:28 +0000 Subject: [PATCH] Changed wxRootWindow from a global to a staic variable with an accessor function that initializes if on first use. This prevents core dumps for apps that try to create wxBitmaps before the wxApp object is initialized. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10129 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/gtk/app.cpp | 37 ++++++++++----- src/gtk/bitmap.cpp | 63 +++++++++++++------------ src/gtk/cursor.cpp | 6 +-- src/gtk/dcclient.cpp | 8 ++-- src/gtk/minifram.cpp | 104 +++++++++++++++++++++--------------------- src/gtk/utilsgtk.cpp | 4 +- src/gtk1/app.cpp | 37 ++++++++++----- src/gtk1/bitmap.cpp | 63 +++++++++++++------------ src/gtk1/cursor.cpp | 6 +-- src/gtk1/dcclient.cpp | 8 ++-- src/gtk1/minifram.cpp | 104 +++++++++++++++++++++--------------------- src/gtk1/utilsgtk.cpp | 4 +- 12 files changed, 234 insertions(+), 210 deletions(-) diff --git a/src/gtk/app.cpp b/src/gtk/app.cpp index 14935b2780..07fadb9ea6 100644 --- a/src/gtk/app.cpp +++ b/src/gtk/app.cpp @@ -52,7 +52,7 @@ extern bool g_isIdle; bool g_mainThreadLocked = FALSE; gint g_pendingTag = 0; -GtkWidget *wxRootWindow = (GtkWidget*) NULL; +static GtkWidget *gs_RootWindow = (GtkWidget*) NULL; //----------------------------------------------------------------------------- // local functions @@ -92,11 +92,11 @@ bool wxYield() } #endif // wxUSE_THREADS -#ifdef __WXDEBUG__ +#ifdef __WXDEBUG__ if (gs_inYield) wxFAIL_MSG( wxT("wxYield called recursively" ) ); #endif - + gs_inYield = TRUE; if (!g_isIdle) @@ -137,8 +137,8 @@ bool wxYieldIfNeeded() { if (gs_inYield) return FALSE; - - return wxYield(); + + return wxYield(); } //----------------------------------------------------------------------------- @@ -168,7 +168,7 @@ void wxWakeUpIdle() gint wxapp_pending_callback( gpointer WXUNUSED(data) ) { if (!wxTheApp) return TRUE; - + // when getting called from GDK's time-out handler // we are no longer within GDK's grab on the GUI // thread so we must lock it here ourselves @@ -195,7 +195,7 @@ gint wxapp_pending_callback( gpointer WXUNUSED(data) ) gint wxapp_idle_callback( gpointer WXUNUSED(data) ) { if (!wxTheApp) return TRUE; - + // when getting called from GDK's time-out handler // we are no longer within GDK's grab on the GUI // thread so we must lock it here ourselves @@ -228,7 +228,7 @@ void wxapp_install_idle_handler() if (g_pendingTag == 0) g_pendingTag = gtk_idle_add_priority( 900, wxapp_pending_callback, (gpointer) NULL ); - + /* This routine gets called by all event handlers indicating that the idle is over. It may also get called from other thread for sending events @@ -245,7 +245,7 @@ static int g_threadUninstallLevel = 0; void wxapp_install_thread_wakeup() { g_threadUninstallLevel++; - + if (g_threadUninstallLevel != 1) return; if (wxTheApp->m_wakeUpTimerTag) return; @@ -256,7 +256,7 @@ void wxapp_install_thread_wakeup() void wxapp_uninstall_thread_wakeup() { g_threadUninstallLevel--; - + if (g_threadUninstallLevel != 0) return; if (!wxTheApp->m_wakeUpTimerTag) return; @@ -626,6 +626,19 @@ void wxApp::CleanUp() #endif // wxUSE_LOG } +//----------------------------------------------------------------------------- +// Access to the root window global +//----------------------------------------------------------------------------- + +GtkWidget* wxGetRootWindow() +{ + if (gs_RootWindow == NULL) { + gs_RootWindow = gtk_window_new( GTK_WINDOW_TOPLEVEL ); + gtk_widget_realize( gs_RootWindow ); + } + return gs_RootWindow; +} + //----------------------------------------------------------------------------- // wxEntry //----------------------------------------------------------------------------- @@ -676,6 +689,7 @@ int wxEntryStart( int argc, char *argv[] ) return 0; } + int wxEntryInitGui() { int retValue = 0; @@ -683,8 +697,7 @@ int wxEntryInitGui() if ( !wxTheApp->OnInitGui() ) retValue = -1; - wxRootWindow = gtk_window_new( GTK_WINDOW_TOPLEVEL ); - gtk_widget_realize( wxRootWindow ); + wxGetRootWindow(); return retValue; } diff --git a/src/gtk/bitmap.cpp b/src/gtk/bitmap.cpp index 170e8daf4f..f0ad2fe56b 100644 --- a/src/gtk/bitmap.cpp +++ b/src/gtk/bitmap.cpp @@ -40,7 +40,7 @@ extern void gdk_wx_draw_bitmap (GdkDrawable *drawable, // data //----------------------------------------------------------------------------- -extern GtkWidget *wxRootWindow; +extern GtkWidget *wxGetRootWindow(); //----------------------------------------------------------------------------- // wxMask @@ -89,7 +89,7 @@ bool wxMask::Create( const wxBitmap& bitmap, wxImage image( bitmap ); if (!image.Ok()) return FALSE; - m_bitmap = gdk_pixmap_new( wxRootWindow->window, image.GetWidth(), image.GetHeight(), 1 ); + m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, image.GetWidth(), image.GetHeight(), 1 ); GdkGC *gc = gdk_gc_new( m_bitmap ); GdkColor color; @@ -108,9 +108,9 @@ bool wxMask::Create( const wxBitmap& bitmap, unsigned char green = colour.Green(); unsigned char blue = colour.Blue(); - GdkVisual *visual = gdk_window_get_visual( wxRootWindow->window ); + GdkVisual *visual = gdk_window_get_visual( wxGetRootWindow()->window ); wxASSERT( visual ); - + int bpp = visual->depth; if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15; if (bpp == 15) @@ -170,7 +170,7 @@ bool wxMask::Create( const wxBitmap& bitmap, int paletteIndex ) wxPalette *pal = bitmap.GetPalette(); wxCHECK_MSG( pal, FALSE, wxT("Cannot create mask from bitmap without palette") ); - + pal->GetRGB(paletteIndex, &r, &g, &b); return Create(bitmap, wxColour(r, g, b)); @@ -188,7 +188,7 @@ bool wxMask::Create( const wxBitmap& bitmap ) wxCHECK_MSG( bitmap.GetBitmap(), FALSE, wxT("Cannot create mask from colour bitmap") ); - m_bitmap = gdk_pixmap_new( wxRootWindow->window, bitmap.GetWidth(), bitmap.GetHeight(), 1 ); + m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, bitmap.GetWidth(), bitmap.GetHeight(), 1 ); if (!m_bitmap) return FALSE; @@ -268,7 +268,7 @@ bool wxBitmap::Create( int width, int height, int depth ) wxCHECK_MSG( (width > 0) && (height > 0), FALSE, wxT("invalid bitmap size") ) - GdkVisual *visual = gdk_window_get_visual( wxRootWindow->window ); + GdkVisual *visual = gdk_window_get_visual( wxGetRootWindow()->window ); wxASSERT( visual ); if (depth == -1) depth = visual->depth; @@ -282,12 +282,12 @@ bool wxBitmap::Create( int width, int height, int depth ) M_BMPDATA->m_height = height; if (depth == 1) { - M_BMPDATA->m_bitmap = gdk_pixmap_new( wxRootWindow->window, width, height, 1 ); + M_BMPDATA->m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 ); M_BMPDATA->m_bpp = 1; } else { - M_BMPDATA->m_pixmap = gdk_pixmap_new( wxRootWindow->window, width, height, depth ); + M_BMPDATA->m_pixmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, depth ); M_BMPDATA->m_bpp = visual->depth; } @@ -298,14 +298,14 @@ bool wxBitmap::CreateFromXpm( const char **bits ) { wxCHECK_MSG( bits != NULL, FALSE, wxT("invalid bitmap data") ) - GdkVisual *visual = gdk_window_get_visual( wxRootWindow->window ); + GdkVisual *visual = gdk_window_get_visual( wxGetRootWindow()->window ); wxASSERT( visual ); - + m_refData = new wxBitmapRefData(); GdkBitmap *mask = (GdkBitmap*) NULL; - M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm_d( wxRootWindow->window, &mask, NULL, (gchar **) bits ); + M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm_d( wxGetRootWindow()->window, &mask, NULL, (gchar **) bits ); wxCHECK_MSG( M_BMPDATA->m_pixmap, FALSE, wxT("couldn't create pixmap") ); @@ -318,13 +318,12 @@ bool wxBitmap::CreateFromXpm( const char **bits ) gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) ); M_BMPDATA->m_bpp = visual->depth; // ? - + if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); return TRUE; } -extern GtkWidget *wxRootWindow; bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) { @@ -332,7 +331,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) wxCHECK_MSG( depth == -1 || depth == 1, FALSE, wxT("invalid bitmap depth") ) m_refData = new wxBitmapRefData(); - + if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); // ------ @@ -346,11 +345,11 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) SetHeight( height ); SetWidth( width ); - SetBitmap( gdk_pixmap_new( wxRootWindow->window, width, height, 1 ) ); + SetBitmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 ) ); SetDepth( 1 ); - GdkVisual *visual = gdk_window_get_visual( wxRootWindow->window ); + GdkVisual *visual = gdk_window_get_visual( wxGetRootWindow()->window ); wxASSERT( visual ); // Create picture image @@ -371,7 +370,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) mask_image = gdk_image_new_bitmap( visual, mask_data, width, height ); wxMask *mask = new wxMask(); - mask->m_bitmap = gdk_pixmap_new( wxRootWindow->window, width, height, 1 ); + mask->m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 ); SetMask( mask ); } @@ -431,7 +430,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) gdk_gc_unref( mask_gc ); } } - + // ------ // convertion to colour bitmap: // ------ @@ -443,11 +442,11 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) SetHeight( height ); SetWidth( width ); - SetPixmap( gdk_pixmap_new( wxRootWindow->window, width, height, -1 ) ); + SetPixmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, -1 ) ); // Retrieve depth - GdkVisual *visual = gdk_window_get_visual( wxRootWindow->window ); + GdkVisual *visual = gdk_window_get_visual( wxGetRootWindow()->window ); wxASSERT( visual ); int bpp = visual->depth; @@ -501,7 +500,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) mask_image = gdk_image_new_bitmap( visual, mask_data, width, height ); wxMask *mask = new wxMask(); - mask->m_bitmap = gdk_pixmap_new( wxRootWindow->window, width, height, 1 ); + mask->m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 ); SetMask( mask ); } @@ -636,7 +635,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) wxImage wxBitmap::ConvertToImage() const { wxImage image; - + wxCHECK_MSG( Ok(), wxNullImage, wxT("invalid bitmap") ); GdkImage *gdk_image = (GdkImage*) NULL; @@ -657,7 +656,7 @@ wxImage wxBitmap::ConvertToImage() const } wxCHECK_MSG( gdk_image, wxNullImage, wxT("couldn't create image") ); - + image.Create( GetWidth(), GetHeight() ); char unsigned *data = image.GetData(); @@ -691,7 +690,7 @@ wxImage wxBitmap::ConvertToImage() const { GdkVisual *visual = gdk_window_get_visual( GetPixmap() ); - if (visual == NULL) visual = gdk_window_get_visual( wxRootWindow->window ); + if (visual == NULL) visual = gdk_window_get_visual( wxGetRootWindow()->window ); bpp = visual->depth; if (bpp == 16) bpp = visual->red_prec + visual->green_prec + visual->blue_prec; red_shift_right = visual->red_shift; @@ -765,7 +764,7 @@ wxImage wxBitmap::ConvertToImage() const } gdk_image_destroy( gdk_image ); - if (gdk_image_mask) gdk_image_destroy( gdk_image_mask ); + if (gdk_image_mask) gdk_image_destroy( gdk_image_mask ); return image; } @@ -790,7 +789,7 @@ wxBitmap::wxBitmap( const char bits[], int width, int height, int WXUNUSED(depth M_BMPDATA->m_mask = (wxMask *) NULL; M_BMPDATA->m_bitmap = - gdk_bitmap_create_from_data( wxRootWindow->window, (gchar *) bits, width, height ); + gdk_bitmap_create_from_data( wxGetRootWindow()->window, (gchar *) bits, width, height ); M_BMPDATA->m_width = width; M_BMPDATA->m_height = height; M_BMPDATA->m_bpp = 1; @@ -890,7 +889,7 @@ wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const if (GetMask()) { wxMask *mask = new wxMask; - mask->m_bitmap = gdk_pixmap_new( wxRootWindow->window, rect.width, rect.height, 1 ); + mask->m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, rect.width, rect.height, 1 ); GdkGC *gc = gdk_gc_new( mask->m_bitmap ); gdk_wx_draw_bitmap( mask->m_bitmap, gc, M_BMPDATA->m_mask->m_bitmap, 0, 0, rect.x, rect.y, rect.width, rect.height ); @@ -921,16 +920,16 @@ bool wxBitmap::LoadFile( const wxString &name, int type ) if (!wxFileExists(name)) return FALSE; - GdkVisual *visual = gdk_window_get_visual( wxRootWindow->window ); + GdkVisual *visual = gdk_window_get_visual( wxGetRootWindow()->window ); wxASSERT( visual ); - + if (type == wxBITMAP_TYPE_XPM) { m_refData = new wxBitmapRefData(); GdkBitmap *mask = (GdkBitmap*) NULL; - M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm( wxRootWindow->window, &mask, NULL, name.fn_str() ); + M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm( wxGetRootWindow()->window, &mask, NULL, name.fn_str() ); if (mask) { @@ -939,7 +938,7 @@ bool wxBitmap::LoadFile( const wxString &name, int type ) } gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) ); - + M_BMPDATA->m_bpp = visual->depth; } else // try if wxImage can load it diff --git a/src/gtk/cursor.cpp b/src/gtk/cursor.cpp index 4ce0228ce7..c419a36837 100644 --- a/src/gtk/cursor.cpp +++ b/src/gtk/cursor.cpp @@ -110,7 +110,7 @@ wxCursor::wxCursor( int cursorId ) M_CURSORDATA->m_cursor = gdk_cursor_new( gdk_cur ); } -extern GtkWidget *wxRootWindow; +extern GtkWidget *wxGetRootWindow(); wxCursor::wxCursor(const char bits[], int width, int height, int hotSpotX, int hotSpotY, @@ -127,8 +127,8 @@ wxCursor::wxCursor(const char bits[], int width, int height, if (hotSpotY < 0 || hotSpotY >= height) hotSpotY = 0; - GdkBitmap *data = gdk_bitmap_create_from_data( wxRootWindow->window, (gchar *) bits, width, height ); - GdkBitmap *mask = gdk_bitmap_create_from_data( wxRootWindow->window, (gchar *) maskBits, width, height); + GdkBitmap *data = gdk_bitmap_create_from_data( wxGetRootWindow()->window, (gchar *) bits, width, height ); + GdkBitmap *mask = gdk_bitmap_create_from_data( wxGetRootWindow()->window, (gchar *) maskBits, width, height); m_refData = new wxCursorRefData; M_CURSORDATA->m_cursor = gdk_cursor_new_from_pixmap( diff --git a/src/gtk/dcclient.cpp b/src/gtk/dcclient.cpp index f283c9b53a..00ff2ed06c 100644 --- a/src/gtk/dcclient.cpp +++ b/src/gtk/dcclient.cpp @@ -54,7 +54,7 @@ static GdkPixmap *hatches[num_hatches]; static GdkPixmap **hatch_bitmap = (GdkPixmap **) NULL; -extern GtkWidget *wxRootWindow; +extern GtkWidget *wxGetRootWindow(); //----------------------------------------------------------------------------- // constants @@ -415,7 +415,7 @@ bool wxWindowDC::DoGetPixel( wxCoord x1, wxCoord y1, wxColour *col ) const memdc.SelectObject(bitmap); memdc.Blit(0, 0, 1, 1, (wxDC*) this, x1, y1); memdc.SelectObject(wxNullBitmap); - + wxImage image(bitmap); col->Set(image.GetRed(0, 0), image.GetGreen(0, 0), image.GetBlue(0, 0)); return TRUE; @@ -1021,7 +1021,7 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, if (!m_currentClippingRegion.IsNull()) { GdkColor col; - new_mask = gdk_pixmap_new( wxRootWindow->window, ww, hh, 1 ); + new_mask = gdk_pixmap_new( wxGetRootWindow()->window, ww, hh, 1 ); GdkGC *gc = gdk_gc_new( new_mask ); col.pixel = 0; gdk_gc_set_foreground( gc, &col ); @@ -1206,7 +1206,7 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he if (!m_currentClippingRegion.IsNull()) { GdkColor col; - new_mask = gdk_pixmap_new( wxRootWindow->window, bm_ww, bm_hh, 1 ); + new_mask = gdk_pixmap_new( wxGetRootWindow()->window, bm_ww, bm_hh, 1 ); GdkGC *gc = gdk_gc_new( new_mask ); col.pixel = 0; gdk_gc_set_foreground( gc, &col ); diff --git a/src/gtk/minifram.cpp b/src/gtk/minifram.cpp index ec6f44a3c5..8e823f312b 100644 --- a/src/gtk/minifram.cpp +++ b/src/gtk/minifram.cpp @@ -37,7 +37,7 @@ extern bool g_isIdle; extern bool g_blockEventsOnDrag; extern bool g_blockEventsOnScroll; -extern GtkWidget *wxRootWindow; +extern GtkWidget *wxGetRootWindow(); //----------------------------------------------------------------------------- // local functions @@ -47,7 +47,7 @@ extern GtkWidget *wxRootWindow; static void DrawFrame( GtkWidget *widget, int x, int y, int w, int h ) { - int org_x = 0; + int org_x = 0; int org_y = 0; gdk_window_get_origin( widget->window, &org_x, &org_y ); x += org_x; @@ -56,7 +56,7 @@ static void DrawFrame( GtkWidget *widget, int x, int y, int w, int h ) GdkGC *gc = gdk_gc_new( GDK_ROOT_PARENT() ); gdk_gc_set_subwindow( gc, GDK_INCLUDE_INFERIORS ); gdk_gc_set_function( gc, GDK_INVERT ); - + gdk_draw_rectangle( GDK_ROOT_PARENT(), gc, FALSE, x, y, w, h ); gdk_gc_unref( gc ); } @@ -71,10 +71,10 @@ static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *g if (!win->m_hasVMT) return; if (gdk_event->count > 0) return; - + GtkPizza *pizza = GTK_PIZZA(widget); - - gtk_draw_shadow( widget->style, + + gtk_draw_shadow( widget->style, pizza->bin_window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, @@ -82,26 +82,26 @@ static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *g win->m_width, win->m_height ); if (!win->m_title.IsEmpty() && - ((win->GetWindowStyle() & wxCAPTION) || - (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) || + ((win->GetWindowStyle() & wxCAPTION) || + (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) || (win->GetWindowStyle() & wxTINY_CAPTION_VERT))) { GdkGC *gc = gdk_gc_new( pizza->bin_window ); GdkFont *font = wxSMALL_FONT->GetInternalFont(1.0); - + gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] ); - gdk_draw_rectangle( pizza->bin_window, gc, TRUE, - 3, - 3, + gdk_draw_rectangle( pizza->bin_window, gc, TRUE, + 3, + 3, win->m_width - 7, font->ascent + font->descent+1 ); - + gdk_gc_set_foreground( gc, &widget->style->fg[GTK_STATE_SELECTED] ); - gdk_draw_string( pizza->bin_window, font, gc, - 6, - 3+font->ascent, + gdk_draw_string( pizza->bin_window, font, gc, + 6, + 3+font->ascent, win->m_title.mb_str() ); - + gdk_gc_unref( gc ); } } @@ -115,37 +115,37 @@ static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNU if (g_isIdle) wxapp_install_idle_handler(); if (!win->m_hasVMT) return; - + GtkPizza *pizza = GTK_PIZZA(widget); - - gtk_draw_shadow( widget->style, + + gtk_draw_shadow( widget->style, pizza->bin_window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, 0, 0, win->m_width, win->m_height ); - + if (!win->m_title.IsEmpty() && - ((win->GetWindowStyle() & wxCAPTION) || - (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) || + ((win->GetWindowStyle() & wxCAPTION) || + (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) || (win->GetWindowStyle() & wxTINY_CAPTION_VERT))) { GdkGC *gc = gdk_gc_new( pizza->bin_window ); GdkFont *font = wxSMALL_FONT->GetInternalFont(1.0); - + gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] ); - gdk_draw_rectangle( pizza->bin_window, gc, TRUE, - 3, + gdk_draw_rectangle( pizza->bin_window, gc, TRUE, + 3, 3, win->m_width - 7, font->ascent + font->descent+1 ); - + gdk_gc_set_foreground( gc, &widget->style->fg[GTK_STATE_SELECTED] ); - gdk_draw_string( pizza->bin_window, font, gc, - 6, - 3+font->ascent, + gdk_draw_string( pizza->bin_window, font, gc, + 6, + 3+font->ascent, win->m_title.mb_str() ); - + gdk_gc_unref( gc ); } } @@ -165,7 +165,7 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton if (win->m_isDragging) return TRUE; gdk_window_raise( win->m_widget->window ); - + gdk_pointer_grab( widget->window, FALSE, (GdkEventMask) (GDK_BUTTON_PRESS_MASK | @@ -177,13 +177,13 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton (GdkWindow *) NULL, (GdkCursor *) NULL, (unsigned int) GDK_CURRENT_TIME ); - + win->m_diffX = (int)gdk_event->x; win->m_diffY = (int)gdk_event->y; DrawFrame( widget, 0, 0, win->m_width, win->m_height ); win->m_oldX = 0; win->m_oldY = 0; - + win->m_isDragging = TRUE; return TRUE; @@ -202,15 +202,15 @@ static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButto if (g_blockEventsOnScroll) return TRUE; if (!win->m_isDragging) return TRUE; - + win->m_isDragging = FALSE; - + int x = (int)gdk_event->x; int y = (int)gdk_event->y; - + DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height ); gdk_pointer_ungrab ( (guint32)GDK_CURRENT_TIME ); - int org_x = 0; + int org_x = 0; int org_y = 0; gdk_window_get_origin( widget->window, &org_x, &org_y ); x += org_x - win->m_diffX; @@ -235,7 +235,7 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion if (g_blockEventsOnScroll) return TRUE; if (!win->m_isDragging) return TRUE; - + if (gdk_event->is_hint) { int x = 0; @@ -251,7 +251,7 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion win->m_oldX = (int)gdk_event->x - win->m_diffX; win->m_oldY = (int)gdk_event->y - win->m_diffY; DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height ); - + return TRUE; } @@ -307,47 +307,47 @@ bool wxMiniFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title if ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT)) m_miniTitle = 13; - + m_miniEdge = 3; m_isDragging = FALSE; m_oldX = -1; m_oldY = -1; m_diffX = 0; m_diffY = 0; - + wxFrame::Create( parent, id, title, pos, size, style, name ); if ((style & wxSYSTEM_MENU) && ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT))) { GdkBitmap *mask = (GdkBitmap*) NULL; - GdkPixmap *pixmap = gdk_pixmap_create_from_xpm_d( wxRootWindow->window, &mask, NULL, cross_xpm ); - + GdkPixmap *pixmap = gdk_pixmap_create_from_xpm_d( wxGetRootWindow()->window, &mask, NULL, cross_xpm ); + GtkWidget *pw = gtk_pixmap_new( pixmap, mask ); gdk_bitmap_unref( mask ); gdk_pixmap_unref( pixmap ); gtk_widget_show( pw ); - + GtkWidget *close_button = gtk_button_new(); gtk_container_add( GTK_CONTAINER(close_button), pw ); - - gtk_pizza_put( GTK_PIZZA(m_mainWidget), - close_button, + + gtk_pizza_put( GTK_PIZZA(m_mainWidget), + close_button, size.x-16, 4, 11, 11 ); - + gtk_widget_show( close_button ); - + gtk_signal_connect( GTK_OBJECT(close_button), "clicked", GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this ); } - + /* these are called when the borders are drawn */ gtk_signal_connect( GTK_OBJECT(m_mainWidget), "expose_event", GTK_SIGNAL_FUNC(gtk_window_own_expose_callback), (gpointer)this ); gtk_signal_connect( GTK_OBJECT(m_mainWidget), "draw", GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this ); - + /* these are required for dragging the mini frame around */ gtk_signal_connect( GTK_OBJECT(m_mainWidget), "button_press_event", GTK_SIGNAL_FUNC(gtk_window_button_press_callback), (gpointer)this ); diff --git a/src/gtk/utilsgtk.cpp b/src/gtk/utilsgtk.cpp index f1f809c5d3..611d02bf16 100644 --- a/src/gtk/utilsgtk.cpp +++ b/src/gtk/utilsgtk.cpp @@ -46,7 +46,7 @@ // data //----------------------------------------------------------------------------- -extern GtkWidget *wxRootWindow; +extern GtkWidget *wxGetRootWindow(); //---------------------------------------------------------------------------- // misc. @@ -117,7 +117,7 @@ bool wxColourDisplay() int wxDisplayDepth() { - return gdk_window_get_visual( wxRootWindow->window )->depth; + return gdk_window_get_visual( wxGetRootWindow()->window )->depth; } int wxGetOsVersion(int *majorVsn, int *minorVsn) diff --git a/src/gtk1/app.cpp b/src/gtk1/app.cpp index 14935b2780..07fadb9ea6 100644 --- a/src/gtk1/app.cpp +++ b/src/gtk1/app.cpp @@ -52,7 +52,7 @@ extern bool g_isIdle; bool g_mainThreadLocked = FALSE; gint g_pendingTag = 0; -GtkWidget *wxRootWindow = (GtkWidget*) NULL; +static GtkWidget *gs_RootWindow = (GtkWidget*) NULL; //----------------------------------------------------------------------------- // local functions @@ -92,11 +92,11 @@ bool wxYield() } #endif // wxUSE_THREADS -#ifdef __WXDEBUG__ +#ifdef __WXDEBUG__ if (gs_inYield) wxFAIL_MSG( wxT("wxYield called recursively" ) ); #endif - + gs_inYield = TRUE; if (!g_isIdle) @@ -137,8 +137,8 @@ bool wxYieldIfNeeded() { if (gs_inYield) return FALSE; - - return wxYield(); + + return wxYield(); } //----------------------------------------------------------------------------- @@ -168,7 +168,7 @@ void wxWakeUpIdle() gint wxapp_pending_callback( gpointer WXUNUSED(data) ) { if (!wxTheApp) return TRUE; - + // when getting called from GDK's time-out handler // we are no longer within GDK's grab on the GUI // thread so we must lock it here ourselves @@ -195,7 +195,7 @@ gint wxapp_pending_callback( gpointer WXUNUSED(data) ) gint wxapp_idle_callback( gpointer WXUNUSED(data) ) { if (!wxTheApp) return TRUE; - + // when getting called from GDK's time-out handler // we are no longer within GDK's grab on the GUI // thread so we must lock it here ourselves @@ -228,7 +228,7 @@ void wxapp_install_idle_handler() if (g_pendingTag == 0) g_pendingTag = gtk_idle_add_priority( 900, wxapp_pending_callback, (gpointer) NULL ); - + /* This routine gets called by all event handlers indicating that the idle is over. It may also get called from other thread for sending events @@ -245,7 +245,7 @@ static int g_threadUninstallLevel = 0; void wxapp_install_thread_wakeup() { g_threadUninstallLevel++; - + if (g_threadUninstallLevel != 1) return; if (wxTheApp->m_wakeUpTimerTag) return; @@ -256,7 +256,7 @@ void wxapp_install_thread_wakeup() void wxapp_uninstall_thread_wakeup() { g_threadUninstallLevel--; - + if (g_threadUninstallLevel != 0) return; if (!wxTheApp->m_wakeUpTimerTag) return; @@ -626,6 +626,19 @@ void wxApp::CleanUp() #endif // wxUSE_LOG } +//----------------------------------------------------------------------------- +// Access to the root window global +//----------------------------------------------------------------------------- + +GtkWidget* wxGetRootWindow() +{ + if (gs_RootWindow == NULL) { + gs_RootWindow = gtk_window_new( GTK_WINDOW_TOPLEVEL ); + gtk_widget_realize( gs_RootWindow ); + } + return gs_RootWindow; +} + //----------------------------------------------------------------------------- // wxEntry //----------------------------------------------------------------------------- @@ -676,6 +689,7 @@ int wxEntryStart( int argc, char *argv[] ) return 0; } + int wxEntryInitGui() { int retValue = 0; @@ -683,8 +697,7 @@ int wxEntryInitGui() if ( !wxTheApp->OnInitGui() ) retValue = -1; - wxRootWindow = gtk_window_new( GTK_WINDOW_TOPLEVEL ); - gtk_widget_realize( wxRootWindow ); + wxGetRootWindow(); return retValue; } diff --git a/src/gtk1/bitmap.cpp b/src/gtk1/bitmap.cpp index 170e8daf4f..f0ad2fe56b 100644 --- a/src/gtk1/bitmap.cpp +++ b/src/gtk1/bitmap.cpp @@ -40,7 +40,7 @@ extern void gdk_wx_draw_bitmap (GdkDrawable *drawable, // data //----------------------------------------------------------------------------- -extern GtkWidget *wxRootWindow; +extern GtkWidget *wxGetRootWindow(); //----------------------------------------------------------------------------- // wxMask @@ -89,7 +89,7 @@ bool wxMask::Create( const wxBitmap& bitmap, wxImage image( bitmap ); if (!image.Ok()) return FALSE; - m_bitmap = gdk_pixmap_new( wxRootWindow->window, image.GetWidth(), image.GetHeight(), 1 ); + m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, image.GetWidth(), image.GetHeight(), 1 ); GdkGC *gc = gdk_gc_new( m_bitmap ); GdkColor color; @@ -108,9 +108,9 @@ bool wxMask::Create( const wxBitmap& bitmap, unsigned char green = colour.Green(); unsigned char blue = colour.Blue(); - GdkVisual *visual = gdk_window_get_visual( wxRootWindow->window ); + GdkVisual *visual = gdk_window_get_visual( wxGetRootWindow()->window ); wxASSERT( visual ); - + int bpp = visual->depth; if ((bpp == 16) && (visual->red_mask != 0xf800)) bpp = 15; if (bpp == 15) @@ -170,7 +170,7 @@ bool wxMask::Create( const wxBitmap& bitmap, int paletteIndex ) wxPalette *pal = bitmap.GetPalette(); wxCHECK_MSG( pal, FALSE, wxT("Cannot create mask from bitmap without palette") ); - + pal->GetRGB(paletteIndex, &r, &g, &b); return Create(bitmap, wxColour(r, g, b)); @@ -188,7 +188,7 @@ bool wxMask::Create( const wxBitmap& bitmap ) wxCHECK_MSG( bitmap.GetBitmap(), FALSE, wxT("Cannot create mask from colour bitmap") ); - m_bitmap = gdk_pixmap_new( wxRootWindow->window, bitmap.GetWidth(), bitmap.GetHeight(), 1 ); + m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, bitmap.GetWidth(), bitmap.GetHeight(), 1 ); if (!m_bitmap) return FALSE; @@ -268,7 +268,7 @@ bool wxBitmap::Create( int width, int height, int depth ) wxCHECK_MSG( (width > 0) && (height > 0), FALSE, wxT("invalid bitmap size") ) - GdkVisual *visual = gdk_window_get_visual( wxRootWindow->window ); + GdkVisual *visual = gdk_window_get_visual( wxGetRootWindow()->window ); wxASSERT( visual ); if (depth == -1) depth = visual->depth; @@ -282,12 +282,12 @@ bool wxBitmap::Create( int width, int height, int depth ) M_BMPDATA->m_height = height; if (depth == 1) { - M_BMPDATA->m_bitmap = gdk_pixmap_new( wxRootWindow->window, width, height, 1 ); + M_BMPDATA->m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 ); M_BMPDATA->m_bpp = 1; } else { - M_BMPDATA->m_pixmap = gdk_pixmap_new( wxRootWindow->window, width, height, depth ); + M_BMPDATA->m_pixmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, depth ); M_BMPDATA->m_bpp = visual->depth; } @@ -298,14 +298,14 @@ bool wxBitmap::CreateFromXpm( const char **bits ) { wxCHECK_MSG( bits != NULL, FALSE, wxT("invalid bitmap data") ) - GdkVisual *visual = gdk_window_get_visual( wxRootWindow->window ); + GdkVisual *visual = gdk_window_get_visual( wxGetRootWindow()->window ); wxASSERT( visual ); - + m_refData = new wxBitmapRefData(); GdkBitmap *mask = (GdkBitmap*) NULL; - M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm_d( wxRootWindow->window, &mask, NULL, (gchar **) bits ); + M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm_d( wxGetRootWindow()->window, &mask, NULL, (gchar **) bits ); wxCHECK_MSG( M_BMPDATA->m_pixmap, FALSE, wxT("couldn't create pixmap") ); @@ -318,13 +318,12 @@ bool wxBitmap::CreateFromXpm( const char **bits ) gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) ); M_BMPDATA->m_bpp = visual->depth; // ? - + if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); return TRUE; } -extern GtkWidget *wxRootWindow; bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) { @@ -332,7 +331,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) wxCHECK_MSG( depth == -1 || depth == 1, FALSE, wxT("invalid bitmap depth") ) m_refData = new wxBitmapRefData(); - + if (wxTheBitmapList) wxTheBitmapList->AddBitmap(this); // ------ @@ -346,11 +345,11 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) SetHeight( height ); SetWidth( width ); - SetBitmap( gdk_pixmap_new( wxRootWindow->window, width, height, 1 ) ); + SetBitmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 ) ); SetDepth( 1 ); - GdkVisual *visual = gdk_window_get_visual( wxRootWindow->window ); + GdkVisual *visual = gdk_window_get_visual( wxGetRootWindow()->window ); wxASSERT( visual ); // Create picture image @@ -371,7 +370,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) mask_image = gdk_image_new_bitmap( visual, mask_data, width, height ); wxMask *mask = new wxMask(); - mask->m_bitmap = gdk_pixmap_new( wxRootWindow->window, width, height, 1 ); + mask->m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 ); SetMask( mask ); } @@ -431,7 +430,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) gdk_gc_unref( mask_gc ); } } - + // ------ // convertion to colour bitmap: // ------ @@ -443,11 +442,11 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) SetHeight( height ); SetWidth( width ); - SetPixmap( gdk_pixmap_new( wxRootWindow->window, width, height, -1 ) ); + SetPixmap( gdk_pixmap_new( wxGetRootWindow()->window, width, height, -1 ) ); // Retrieve depth - GdkVisual *visual = gdk_window_get_visual( wxRootWindow->window ); + GdkVisual *visual = gdk_window_get_visual( wxGetRootWindow()->window ); wxASSERT( visual ); int bpp = visual->depth; @@ -501,7 +500,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) mask_image = gdk_image_new_bitmap( visual, mask_data, width, height ); wxMask *mask = new wxMask(); - mask->m_bitmap = gdk_pixmap_new( wxRootWindow->window, width, height, 1 ); + mask->m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, width, height, 1 ); SetMask( mask ); } @@ -636,7 +635,7 @@ bool wxBitmap::CreateFromImage( const wxImage& image, int depth ) wxImage wxBitmap::ConvertToImage() const { wxImage image; - + wxCHECK_MSG( Ok(), wxNullImage, wxT("invalid bitmap") ); GdkImage *gdk_image = (GdkImage*) NULL; @@ -657,7 +656,7 @@ wxImage wxBitmap::ConvertToImage() const } wxCHECK_MSG( gdk_image, wxNullImage, wxT("couldn't create image") ); - + image.Create( GetWidth(), GetHeight() ); char unsigned *data = image.GetData(); @@ -691,7 +690,7 @@ wxImage wxBitmap::ConvertToImage() const { GdkVisual *visual = gdk_window_get_visual( GetPixmap() ); - if (visual == NULL) visual = gdk_window_get_visual( wxRootWindow->window ); + if (visual == NULL) visual = gdk_window_get_visual( wxGetRootWindow()->window ); bpp = visual->depth; if (bpp == 16) bpp = visual->red_prec + visual->green_prec + visual->blue_prec; red_shift_right = visual->red_shift; @@ -765,7 +764,7 @@ wxImage wxBitmap::ConvertToImage() const } gdk_image_destroy( gdk_image ); - if (gdk_image_mask) gdk_image_destroy( gdk_image_mask ); + if (gdk_image_mask) gdk_image_destroy( gdk_image_mask ); return image; } @@ -790,7 +789,7 @@ wxBitmap::wxBitmap( const char bits[], int width, int height, int WXUNUSED(depth M_BMPDATA->m_mask = (wxMask *) NULL; M_BMPDATA->m_bitmap = - gdk_bitmap_create_from_data( wxRootWindow->window, (gchar *) bits, width, height ); + gdk_bitmap_create_from_data( wxGetRootWindow()->window, (gchar *) bits, width, height ); M_BMPDATA->m_width = width; M_BMPDATA->m_height = height; M_BMPDATA->m_bpp = 1; @@ -890,7 +889,7 @@ wxBitmap wxBitmap::GetSubBitmap( const wxRect& rect) const if (GetMask()) { wxMask *mask = new wxMask; - mask->m_bitmap = gdk_pixmap_new( wxRootWindow->window, rect.width, rect.height, 1 ); + mask->m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, rect.width, rect.height, 1 ); GdkGC *gc = gdk_gc_new( mask->m_bitmap ); gdk_wx_draw_bitmap( mask->m_bitmap, gc, M_BMPDATA->m_mask->m_bitmap, 0, 0, rect.x, rect.y, rect.width, rect.height ); @@ -921,16 +920,16 @@ bool wxBitmap::LoadFile( const wxString &name, int type ) if (!wxFileExists(name)) return FALSE; - GdkVisual *visual = gdk_window_get_visual( wxRootWindow->window ); + GdkVisual *visual = gdk_window_get_visual( wxGetRootWindow()->window ); wxASSERT( visual ); - + if (type == wxBITMAP_TYPE_XPM) { m_refData = new wxBitmapRefData(); GdkBitmap *mask = (GdkBitmap*) NULL; - M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm( wxRootWindow->window, &mask, NULL, name.fn_str() ); + M_BMPDATA->m_pixmap = gdk_pixmap_create_from_xpm( wxGetRootWindow()->window, &mask, NULL, name.fn_str() ); if (mask) { @@ -939,7 +938,7 @@ bool wxBitmap::LoadFile( const wxString &name, int type ) } gdk_window_get_size( M_BMPDATA->m_pixmap, &(M_BMPDATA->m_width), &(M_BMPDATA->m_height) ); - + M_BMPDATA->m_bpp = visual->depth; } else // try if wxImage can load it diff --git a/src/gtk1/cursor.cpp b/src/gtk1/cursor.cpp index 4ce0228ce7..c419a36837 100644 --- a/src/gtk1/cursor.cpp +++ b/src/gtk1/cursor.cpp @@ -110,7 +110,7 @@ wxCursor::wxCursor( int cursorId ) M_CURSORDATA->m_cursor = gdk_cursor_new( gdk_cur ); } -extern GtkWidget *wxRootWindow; +extern GtkWidget *wxGetRootWindow(); wxCursor::wxCursor(const char bits[], int width, int height, int hotSpotX, int hotSpotY, @@ -127,8 +127,8 @@ wxCursor::wxCursor(const char bits[], int width, int height, if (hotSpotY < 0 || hotSpotY >= height) hotSpotY = 0; - GdkBitmap *data = gdk_bitmap_create_from_data( wxRootWindow->window, (gchar *) bits, width, height ); - GdkBitmap *mask = gdk_bitmap_create_from_data( wxRootWindow->window, (gchar *) maskBits, width, height); + GdkBitmap *data = gdk_bitmap_create_from_data( wxGetRootWindow()->window, (gchar *) bits, width, height ); + GdkBitmap *mask = gdk_bitmap_create_from_data( wxGetRootWindow()->window, (gchar *) maskBits, width, height); m_refData = new wxCursorRefData; M_CURSORDATA->m_cursor = gdk_cursor_new_from_pixmap( diff --git a/src/gtk1/dcclient.cpp b/src/gtk1/dcclient.cpp index f283c9b53a..00ff2ed06c 100644 --- a/src/gtk1/dcclient.cpp +++ b/src/gtk1/dcclient.cpp @@ -54,7 +54,7 @@ static GdkPixmap *hatches[num_hatches]; static GdkPixmap **hatch_bitmap = (GdkPixmap **) NULL; -extern GtkWidget *wxRootWindow; +extern GtkWidget *wxGetRootWindow(); //----------------------------------------------------------------------------- // constants @@ -415,7 +415,7 @@ bool wxWindowDC::DoGetPixel( wxCoord x1, wxCoord y1, wxColour *col ) const memdc.SelectObject(bitmap); memdc.Blit(0, 0, 1, 1, (wxDC*) this, x1, y1); memdc.SelectObject(wxNullBitmap); - + wxImage image(bitmap); col->Set(image.GetRed(0, 0), image.GetGreen(0, 0), image.GetBlue(0, 0)); return TRUE; @@ -1021,7 +1021,7 @@ void wxWindowDC::DoDrawBitmap( const wxBitmap &bitmap, if (!m_currentClippingRegion.IsNull()) { GdkColor col; - new_mask = gdk_pixmap_new( wxRootWindow->window, ww, hh, 1 ); + new_mask = gdk_pixmap_new( wxGetRootWindow()->window, ww, hh, 1 ); GdkGC *gc = gdk_gc_new( new_mask ); col.pixel = 0; gdk_gc_set_foreground( gc, &col ); @@ -1206,7 +1206,7 @@ bool wxWindowDC::DoBlit( wxCoord xdest, wxCoord ydest, wxCoord width, wxCoord he if (!m_currentClippingRegion.IsNull()) { GdkColor col; - new_mask = gdk_pixmap_new( wxRootWindow->window, bm_ww, bm_hh, 1 ); + new_mask = gdk_pixmap_new( wxGetRootWindow()->window, bm_ww, bm_hh, 1 ); GdkGC *gc = gdk_gc_new( new_mask ); col.pixel = 0; gdk_gc_set_foreground( gc, &col ); diff --git a/src/gtk1/minifram.cpp b/src/gtk1/minifram.cpp index ec6f44a3c5..8e823f312b 100644 --- a/src/gtk1/minifram.cpp +++ b/src/gtk1/minifram.cpp @@ -37,7 +37,7 @@ extern bool g_isIdle; extern bool g_blockEventsOnDrag; extern bool g_blockEventsOnScroll; -extern GtkWidget *wxRootWindow; +extern GtkWidget *wxGetRootWindow(); //----------------------------------------------------------------------------- // local functions @@ -47,7 +47,7 @@ extern GtkWidget *wxRootWindow; static void DrawFrame( GtkWidget *widget, int x, int y, int w, int h ) { - int org_x = 0; + int org_x = 0; int org_y = 0; gdk_window_get_origin( widget->window, &org_x, &org_y ); x += org_x; @@ -56,7 +56,7 @@ static void DrawFrame( GtkWidget *widget, int x, int y, int w, int h ) GdkGC *gc = gdk_gc_new( GDK_ROOT_PARENT() ); gdk_gc_set_subwindow( gc, GDK_INCLUDE_INFERIORS ); gdk_gc_set_function( gc, GDK_INVERT ); - + gdk_draw_rectangle( GDK_ROOT_PARENT(), gc, FALSE, x, y, w, h ); gdk_gc_unref( gc ); } @@ -71,10 +71,10 @@ static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *g if (!win->m_hasVMT) return; if (gdk_event->count > 0) return; - + GtkPizza *pizza = GTK_PIZZA(widget); - - gtk_draw_shadow( widget->style, + + gtk_draw_shadow( widget->style, pizza->bin_window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, @@ -82,26 +82,26 @@ static void gtk_window_own_expose_callback( GtkWidget *widget, GdkEventExpose *g win->m_width, win->m_height ); if (!win->m_title.IsEmpty() && - ((win->GetWindowStyle() & wxCAPTION) || - (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) || + ((win->GetWindowStyle() & wxCAPTION) || + (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) || (win->GetWindowStyle() & wxTINY_CAPTION_VERT))) { GdkGC *gc = gdk_gc_new( pizza->bin_window ); GdkFont *font = wxSMALL_FONT->GetInternalFont(1.0); - + gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] ); - gdk_draw_rectangle( pizza->bin_window, gc, TRUE, - 3, - 3, + gdk_draw_rectangle( pizza->bin_window, gc, TRUE, + 3, + 3, win->m_width - 7, font->ascent + font->descent+1 ); - + gdk_gc_set_foreground( gc, &widget->style->fg[GTK_STATE_SELECTED] ); - gdk_draw_string( pizza->bin_window, font, gc, - 6, - 3+font->ascent, + gdk_draw_string( pizza->bin_window, font, gc, + 6, + 3+font->ascent, win->m_title.mb_str() ); - + gdk_gc_unref( gc ); } } @@ -115,37 +115,37 @@ static void gtk_window_own_draw_callback( GtkWidget *widget, GdkRectangle *WXUNU if (g_isIdle) wxapp_install_idle_handler(); if (!win->m_hasVMT) return; - + GtkPizza *pizza = GTK_PIZZA(widget); - - gtk_draw_shadow( widget->style, + + gtk_draw_shadow( widget->style, pizza->bin_window, GTK_STATE_NORMAL, GTK_SHADOW_OUT, 0, 0, win->m_width, win->m_height ); - + if (!win->m_title.IsEmpty() && - ((win->GetWindowStyle() & wxCAPTION) || - (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) || + ((win->GetWindowStyle() & wxCAPTION) || + (win->GetWindowStyle() & wxTINY_CAPTION_HORIZ) || (win->GetWindowStyle() & wxTINY_CAPTION_VERT))) { GdkGC *gc = gdk_gc_new( pizza->bin_window ); GdkFont *font = wxSMALL_FONT->GetInternalFont(1.0); - + gdk_gc_set_foreground( gc, &widget->style->bg[GTK_STATE_SELECTED] ); - gdk_draw_rectangle( pizza->bin_window, gc, TRUE, - 3, + gdk_draw_rectangle( pizza->bin_window, gc, TRUE, + 3, 3, win->m_width - 7, font->ascent + font->descent+1 ); - + gdk_gc_set_foreground( gc, &widget->style->fg[GTK_STATE_SELECTED] ); - gdk_draw_string( pizza->bin_window, font, gc, - 6, - 3+font->ascent, + gdk_draw_string( pizza->bin_window, font, gc, + 6, + 3+font->ascent, win->m_title.mb_str() ); - + gdk_gc_unref( gc ); } } @@ -165,7 +165,7 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton if (win->m_isDragging) return TRUE; gdk_window_raise( win->m_widget->window ); - + gdk_pointer_grab( widget->window, FALSE, (GdkEventMask) (GDK_BUTTON_PRESS_MASK | @@ -177,13 +177,13 @@ static gint gtk_window_button_press_callback( GtkWidget *widget, GdkEventButton (GdkWindow *) NULL, (GdkCursor *) NULL, (unsigned int) GDK_CURRENT_TIME ); - + win->m_diffX = (int)gdk_event->x; win->m_diffY = (int)gdk_event->y; DrawFrame( widget, 0, 0, win->m_width, win->m_height ); win->m_oldX = 0; win->m_oldY = 0; - + win->m_isDragging = TRUE; return TRUE; @@ -202,15 +202,15 @@ static gint gtk_window_button_release_callback( GtkWidget *widget, GdkEventButto if (g_blockEventsOnScroll) return TRUE; if (!win->m_isDragging) return TRUE; - + win->m_isDragging = FALSE; - + int x = (int)gdk_event->x; int y = (int)gdk_event->y; - + DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height ); gdk_pointer_ungrab ( (guint32)GDK_CURRENT_TIME ); - int org_x = 0; + int org_x = 0; int org_y = 0; gdk_window_get_origin( widget->window, &org_x, &org_y ); x += org_x - win->m_diffX; @@ -235,7 +235,7 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion if (g_blockEventsOnScroll) return TRUE; if (!win->m_isDragging) return TRUE; - + if (gdk_event->is_hint) { int x = 0; @@ -251,7 +251,7 @@ static gint gtk_window_motion_notify_callback( GtkWidget *widget, GdkEventMotion win->m_oldX = (int)gdk_event->x - win->m_diffX; win->m_oldY = (int)gdk_event->y - win->m_diffY; DrawFrame( widget, win->m_oldX, win->m_oldY, win->m_width, win->m_height ); - + return TRUE; } @@ -307,47 +307,47 @@ bool wxMiniFrame::Create( wxWindow *parent, wxWindowID id, const wxString &title if ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT)) m_miniTitle = 13; - + m_miniEdge = 3; m_isDragging = FALSE; m_oldX = -1; m_oldY = -1; m_diffX = 0; m_diffY = 0; - + wxFrame::Create( parent, id, title, pos, size, style, name ); if ((style & wxSYSTEM_MENU) && ((style & wxCAPTION) || (style & wxTINY_CAPTION_HORIZ) || (style & wxTINY_CAPTION_VERT))) { GdkBitmap *mask = (GdkBitmap*) NULL; - GdkPixmap *pixmap = gdk_pixmap_create_from_xpm_d( wxRootWindow->window, &mask, NULL, cross_xpm ); - + GdkPixmap *pixmap = gdk_pixmap_create_from_xpm_d( wxGetRootWindow()->window, &mask, NULL, cross_xpm ); + GtkWidget *pw = gtk_pixmap_new( pixmap, mask ); gdk_bitmap_unref( mask ); gdk_pixmap_unref( pixmap ); gtk_widget_show( pw ); - + GtkWidget *close_button = gtk_button_new(); gtk_container_add( GTK_CONTAINER(close_button), pw ); - - gtk_pizza_put( GTK_PIZZA(m_mainWidget), - close_button, + + gtk_pizza_put( GTK_PIZZA(m_mainWidget), + close_button, size.x-16, 4, 11, 11 ); - + gtk_widget_show( close_button ); - + gtk_signal_connect( GTK_OBJECT(close_button), "clicked", GTK_SIGNAL_FUNC(gtk_button_clicked_callback), (gpointer*)this ); } - + /* these are called when the borders are drawn */ gtk_signal_connect( GTK_OBJECT(m_mainWidget), "expose_event", GTK_SIGNAL_FUNC(gtk_window_own_expose_callback), (gpointer)this ); gtk_signal_connect( GTK_OBJECT(m_mainWidget), "draw", GTK_SIGNAL_FUNC(gtk_window_own_draw_callback), (gpointer)this ); - + /* these are required for dragging the mini frame around */ gtk_signal_connect( GTK_OBJECT(m_mainWidget), "button_press_event", GTK_SIGNAL_FUNC(gtk_window_button_press_callback), (gpointer)this ); diff --git a/src/gtk1/utilsgtk.cpp b/src/gtk1/utilsgtk.cpp index f1f809c5d3..611d02bf16 100644 --- a/src/gtk1/utilsgtk.cpp +++ b/src/gtk1/utilsgtk.cpp @@ -46,7 +46,7 @@ // data //----------------------------------------------------------------------------- -extern GtkWidget *wxRootWindow; +extern GtkWidget *wxGetRootWindow(); //---------------------------------------------------------------------------- // misc. @@ -117,7 +117,7 @@ bool wxColourDisplay() int wxDisplayDepth() { - return gdk_window_get_visual( wxRootWindow->window )->depth; + return gdk_window_get_visual( wxGetRootWindow()->window )->depth; } int wxGetOsVersion(int *majorVsn, int *minorVsn) -- 2.45.2