Implement access to a global toplevel GdkWindow in a way that does not require always having an extra GtkWindow.
And don't use "RootWindow" in the name, it is not a root window in the X11 sense. Also add wxGetPangoContext() to get access to a PangoContext. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76465 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
70387b4857
commit
a0f10ec1d6
@ -164,22 +164,6 @@ bool wxApp::DoIdle()
|
||||
return keepSource;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Access to the root window global
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
GtkWidget* wxGetRootWindow()
|
||||
{
|
||||
static GtkWidget *s_RootWindow = NULL;
|
||||
|
||||
if (s_RootWindow == NULL)
|
||||
{
|
||||
s_RootWindow = gtk_window_new( GTK_WINDOW_TOPLEVEL );
|
||||
gtk_widget_realize( s_RootWindow );
|
||||
}
|
||||
return s_RootWindow;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxApp
|
||||
//-----------------------------------------------------------------------------
|
||||
|
@ -24,7 +24,7 @@
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
extern GtkWidget *wxGetRootWindow();
|
||||
GdkWindow* wxGetTopLevelGDK();
|
||||
|
||||
#ifndef __WXGTK3__
|
||||
static void PixmapToPixbuf(GdkPixmap* pixmap, GdkPixbuf* pixbuf, int w, int h)
|
||||
@ -245,7 +245,7 @@ bool wxMask::InitFromColour(const wxBitmap& bitmap, const wxColour& colour)
|
||||
}
|
||||
g_object_unref(image);
|
||||
}
|
||||
m_bitmap = gdk_bitmap_create_from_data(wxGetRootWindow()->window, (char*)out, w, h);
|
||||
m_bitmap = gdk_bitmap_create_from_data(wxGetTopLevelGDK(), (char*)out, w, h);
|
||||
delete[] out;
|
||||
#endif
|
||||
return true;
|
||||
@ -260,7 +260,7 @@ bool wxMask::InitFromMonoBitmap(const wxBitmap& bitmap)
|
||||
#ifdef __WXGTK3__
|
||||
InitFromColour(bitmap, *wxBLACK);
|
||||
#else
|
||||
m_bitmap = gdk_pixmap_new( wxGetRootWindow()->window, bitmap.GetWidth(), bitmap.GetHeight(), 1 );
|
||||
m_bitmap = gdk_pixmap_new(wxGetTopLevelGDK(), bitmap.GetWidth(), bitmap.GetHeight(), 1);
|
||||
|
||||
if (!m_bitmap) return false;
|
||||
|
||||
@ -375,7 +375,7 @@ wxBitmapRefData::wxBitmapRefData(int width, int height, int depth)
|
||||
m_bpp = 24;
|
||||
#else
|
||||
if (m_bpp < 0)
|
||||
m_bpp = gdk_drawable_get_depth(wxGetRootWindow()->window);
|
||||
m_bpp = gdk_drawable_get_depth(wxGetTopLevelGDK());
|
||||
m_alphaRequested = depth == 32;
|
||||
#endif
|
||||
}
|
||||
@ -443,7 +443,7 @@ wxBitmap::wxBitmap(const char bits[], int width, int height, int depth)
|
||||
}
|
||||
#else
|
||||
M_BMPDATA->m_pixmap = gdk_bitmap_create_from_data(
|
||||
wxGetRootWindow()->window, bits, width, height);
|
||||
wxGetTopLevelGDK(), bits, width, height);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@ -466,7 +466,8 @@ wxBitmap::wxBitmap(const char* const* bits)
|
||||
}
|
||||
#else
|
||||
GdkBitmap* mask = NULL;
|
||||
GdkPixmap* pixmap = gdk_pixmap_create_from_xpm_d(wxGetRootWindow()->window, &mask, NULL, const_cast<char**>(bits));
|
||||
GdkPixmap* pixmap = gdk_pixmap_create_from_xpm_d(
|
||||
wxGetTopLevelGDK(), &mask, NULL, const_cast<char**>(bits));
|
||||
if (pixmap)
|
||||
{
|
||||
int width, height;
|
||||
@ -655,7 +656,7 @@ bool wxBitmap::CreateFromImageAsPixmap(const wxImage& image, int depth)
|
||||
// move index to next byte boundary
|
||||
bit_index = (bit_index + 7) & ~7u;
|
||||
}
|
||||
SetPixmap(gdk_bitmap_create_from_data(wxGetRootWindow()->window, (char*)out, w, h));
|
||||
SetPixmap(gdk_bitmap_create_from_data(wxGetTopLevelGDK(), (char*)out, w, h));
|
||||
delete[] out;
|
||||
|
||||
if (!M_BMPDATA) // SetPixmap may have failed
|
||||
@ -663,7 +664,7 @@ bool wxBitmap::CreateFromImageAsPixmap(const wxImage& image, int depth)
|
||||
}
|
||||
else
|
||||
{
|
||||
SetPixmap(gdk_pixmap_new(wxGetRootWindow()->window, w, h, depth));
|
||||
SetPixmap(gdk_pixmap_new(wxGetTopLevelGDK(), w, h, depth));
|
||||
if (!M_BMPDATA)
|
||||
return false;
|
||||
|
||||
@ -1170,7 +1171,7 @@ GdkPixmap *wxBitmap::GetPixmap() const
|
||||
}
|
||||
else
|
||||
{
|
||||
bmpData->m_pixmap = gdk_pixmap_new(wxGetRootWindow()->window,
|
||||
bmpData->m_pixmap = gdk_pixmap_new(wxGetTopLevelGDK(),
|
||||
bmpData->m_width, bmpData->m_height, bmpData->m_bpp == 1 ? 1 : -1);
|
||||
}
|
||||
return bmpData->m_pixmap;
|
||||
|
@ -22,6 +22,8 @@
|
||||
#include "wx/gtk/private/object.h"
|
||||
#include "wx/gtk/private/gtk2-compat.h"
|
||||
|
||||
GdkWindow* wxGetTopLevelGDK();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// wxCursorRefData
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -67,9 +69,6 @@ wxCursorRefData::~wxCursorRefData()
|
||||
|
||||
IMPLEMENT_DYNAMIC_CLASS(wxCursor, wxGDIObject)
|
||||
|
||||
// used in the following two ctors
|
||||
extern GtkWidget *wxGetRootWindow();
|
||||
|
||||
wxCursor::wxCursor()
|
||||
{
|
||||
}
|
||||
@ -143,7 +142,8 @@ wxCursor::wxCursor(const char bits[], int width, int height,
|
||||
}
|
||||
}
|
||||
}
|
||||
M_CURSORDATA->m_cursor = gdk_cursor_new_from_pixbuf(gtk_widget_get_display(wxGetRootWindow()), pixbuf, hotSpotX, hotSpotY);
|
||||
M_CURSORDATA->m_cursor = gdk_cursor_new_from_pixbuf(
|
||||
gdk_window_get_display(wxGetTopLevelGDK()), pixbuf, hotSpotX, hotSpotY);
|
||||
#else
|
||||
if (!maskBits)
|
||||
maskBits = bits;
|
||||
@ -153,9 +153,9 @@ wxCursor::wxCursor(const char bits[], int width, int height,
|
||||
bg = wxWHITE;
|
||||
|
||||
GdkBitmap* data = gdk_bitmap_create_from_data(
|
||||
gtk_widget_get_window(wxGetRootWindow()), const_cast<char*>(bits), width, height);
|
||||
wxGetTopLevelGDK(), const_cast<char*>(bits), width, height);
|
||||
GdkBitmap* mask = gdk_bitmap_create_from_data(
|
||||
gtk_widget_get_window(wxGetRootWindow()), const_cast<char*>(maskBits), width, height);
|
||||
wxGetTopLevelGDK(), const_cast<char*>(maskBits), width, height);
|
||||
|
||||
M_CURSORDATA->m_cursor = gdk_cursor_new_from_pixmap(
|
||||
data, mask, fg->GetColor(), bg->GetColor(),
|
||||
@ -275,7 +275,8 @@ void wxCursor::InitFromImage( const wxImage & image )
|
||||
}
|
||||
}
|
||||
m_refData = new wxCursorRefData;
|
||||
M_CURSORDATA->m_cursor = gdk_cursor_new_from_pixbuf(gtk_widget_get_display(wxGetRootWindow()), pixbuf, hotSpotX, hotSpotY);
|
||||
M_CURSORDATA->m_cursor = gdk_cursor_new_from_pixbuf(
|
||||
gdk_window_get_display(wxGetTopLevelGDK()), pixbuf, hotSpotX, hotSpotY);
|
||||
g_object_unref(pixbuf);
|
||||
}
|
||||
|
||||
|
@ -20,7 +20,7 @@
|
||||
#endif
|
||||
#include "wx/gtk/private/gtk2-compat.h"
|
||||
|
||||
GtkWidget* wxGetRootWindow();
|
||||
GdkWindow* wxGetTopLevelGDK();
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
@ -76,7 +76,7 @@ void wxClientDisplayRect(int* x, int* y, int* width, int* height)
|
||||
GdkRectangle rect = { 0, 0, 672, 396 };
|
||||
#else
|
||||
GdkRectangle rect;
|
||||
GdkWindow* window = gtk_widget_get_window(wxGetRootWindow());
|
||||
GdkWindow* window = wxGetTopLevelGDK();
|
||||
GdkScreen* screen = gdk_window_get_screen(window);
|
||||
int monitor = gdk_screen_get_monitor_at_window(screen, window);
|
||||
gdk_screen_get_monitor_workarea(screen, monitor, &rect);
|
||||
@ -119,7 +119,7 @@ public:
|
||||
|
||||
static inline GdkScreen* GetScreen()
|
||||
{
|
||||
return gtk_widget_get_screen(wxGetRootWindow());
|
||||
return gdk_window_get_screen(wxGetTopLevelGDK());
|
||||
}
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
@ -35,14 +35,14 @@
|
||||
#include "wx/apptrait.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <glib.h>
|
||||
#include "wx/gtk/private/gtk2-compat.h"
|
||||
|
||||
GdkWindow* wxGetTopLevelGDK();
|
||||
|
||||
// ============================================================================
|
||||
// wxEventLoop implementation
|
||||
// ============================================================================
|
||||
|
||||
extern GtkWidget *wxGetRootWindow();
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxEventLoop running and exiting
|
||||
// ----------------------------------------------------------------------------
|
||||
@ -393,7 +393,7 @@ void wxGUIEventLoop::DoYieldFor(long eventsToProcess)
|
||||
// then we fall into a never-ending loop...
|
||||
|
||||
// put all unprocessed GDK events back in the queue
|
||||
GdkDisplay* disp = gtk_widget_get_display(wxGetRootWindow());
|
||||
GdkDisplay* disp = gdk_window_get_display(wxGetTopLevelGDK());
|
||||
for (size_t i=0; i<m_arrGdkEvents.GetCount(); i++)
|
||||
{
|
||||
GdkEvent* ev = (GdkEvent*)m_arrGdkEvents[i];
|
||||
|
@ -55,11 +55,7 @@
|
||||
|
||||
#include "wx/gtk/private/gtk2-compat.h"
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// data
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
extern GtkWidget *wxGetRootWindow();
|
||||
GdkWindow* wxGetTopLevelGDK();
|
||||
|
||||
//----------------------------------------------------------------------------
|
||||
// misc.
|
||||
@ -77,7 +73,7 @@ void wxBell()
|
||||
#ifdef GDK_WINDOWING_X11
|
||||
void *wxGetDisplay()
|
||||
{
|
||||
return GDK_DISPLAY_XDISPLAY(gtk_widget_get_display(wxGetRootWindow()));
|
||||
return GDK_DISPLAY_XDISPLAY(gdk_window_get_display(wxGetTopLevelGDK()));
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -100,7 +96,7 @@ bool wxColourDisplay()
|
||||
|
||||
int wxDisplayDepth()
|
||||
{
|
||||
return gdk_visual_get_depth(gtk_widget_get_visual(wxGetRootWindow()));
|
||||
return gdk_visual_get_depth(gdk_window_get_visual(wxGetTopLevelGDK()));
|
||||
}
|
||||
|
||||
wxWindow* wxFindWindowAtPoint(const wxPoint& pt)
|
||||
|
@ -241,6 +241,55 @@ const char* wxDumpGtkWidget(GtkWidget* w)
|
||||
return s.c_str();
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// global top level GtkWidget/GdkWindow
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
static bool wxGetTopLevel(GtkWidget** widget, GdkWindow** window)
|
||||
{
|
||||
wxWindowList::const_iterator i = wxTopLevelWindows.begin();
|
||||
for (; i != wxTopLevelWindows.end(); ++i)
|
||||
{
|
||||
const wxWindow* win = *i;
|
||||
if (win->m_widget)
|
||||
{
|
||||
GdkWindow* gdkwin = gtk_widget_get_window(win->m_widget);
|
||||
if (gdkwin)
|
||||
{
|
||||
if (widget)
|
||||
*widget = win->m_widget;
|
||||
if (window)
|
||||
*window = gdkwin;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
GdkWindow* wxGetTopLevelGDK()
|
||||
{
|
||||
GdkWindow* window;
|
||||
if (!wxGetTopLevel(NULL, &window))
|
||||
window = gdk_get_default_root_window();
|
||||
return window;
|
||||
}
|
||||
|
||||
PangoContext* wxGetPangoContext()
|
||||
{
|
||||
PangoContext* context;
|
||||
GtkWidget* widget;
|
||||
if (wxGetTopLevel(&widget, NULL))
|
||||
{
|
||||
context = gtk_widget_get_pango_context(widget);
|
||||
g_object_ref(context);
|
||||
}
|
||||
else
|
||||
context = gdk_pango_context_get_for_screen(gdk_screen_get_default());
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// "expose_event"/"draw" from m_wxwindow
|
||||
//-----------------------------------------------------------------------------
|
||||
@ -2208,19 +2257,6 @@ bool wxGetKeyState(wxKeyCode WXUNUSED(key))
|
||||
}
|
||||
#endif // __WINDOWS__
|
||||
|
||||
static GdkDisplay* GetDisplay()
|
||||
{
|
||||
wxWindow* tlw = NULL;
|
||||
if (!wxTopLevelWindows.empty())
|
||||
tlw = wxTopLevelWindows.front();
|
||||
GdkDisplay* display;
|
||||
if (tlw && tlw->m_widget)
|
||||
display = gtk_widget_get_display(tlw->m_widget);
|
||||
else
|
||||
display = gdk_display_get_default();
|
||||
return display;
|
||||
}
|
||||
|
||||
wxMouseState wxGetMouseState()
|
||||
{
|
||||
wxMouseState ms;
|
||||
@ -2229,7 +2265,7 @@ wxMouseState wxGetMouseState()
|
||||
gint y;
|
||||
GdkModifierType mask;
|
||||
|
||||
GdkDisplay* display = GetDisplay();
|
||||
GdkDisplay* display = gdk_window_get_display(wxGetTopLevelGDK());
|
||||
#ifdef __WXGTK3__
|
||||
GdkDeviceManager* manager = gdk_display_get_device_manager(display);
|
||||
GdkDevice* device = gdk_device_manager_get_client_pointer(manager);
|
||||
@ -4891,7 +4927,7 @@ wxWindow* wxFindWindowAtPointer(wxPoint& pt)
|
||||
// Get the current mouse position.
|
||||
void wxGetMousePosition(int* x, int* y)
|
||||
{
|
||||
GdkDisplay* display = GetDisplay();
|
||||
GdkDisplay* display = gdk_window_get_display(wxGetTopLevelGDK());
|
||||
#ifdef __WXGTK3__
|
||||
GdkDeviceManager* manager = gdk_display_get_device_manager(display);
|
||||
GdkDevice* device = gdk_device_manager_get_client_pointer(manager);
|
||||
|
@ -41,12 +41,9 @@
|
||||
|
||||
#if wxUSE_PANGO
|
||||
|
||||
#include "pango/pango.h"
|
||||
#include <pango/pango.h>
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
#include "gtk/gtk.h"
|
||||
extern GtkWidget *wxGetRootWindow();
|
||||
#endif // __WXGTK20__
|
||||
PangoContext* wxGetPangoContext();
|
||||
|
||||
extern "C"
|
||||
{
|
||||
@ -72,13 +69,8 @@ bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
|
||||
|
||||
PangoFontFamily **families = NULL;
|
||||
gint n_families = 0;
|
||||
pango_context_list_families (
|
||||
#ifdef __WXGTK20__
|
||||
gtk_widget_get_pango_context( wxGetRootWindow() ),
|
||||
#else
|
||||
wxTheApp->GetPangoContext(),
|
||||
#endif
|
||||
&families, &n_families );
|
||||
PangoContext* context = wxGetPangoContext();
|
||||
pango_context_list_families(context, &families, &n_families);
|
||||
qsort (families, n_families, sizeof (PangoFontFamily *), wxCompareFamilies);
|
||||
|
||||
for ( int i = 0; i < n_families; i++ )
|
||||
@ -93,6 +85,7 @@ bool wxFontEnumerator::EnumerateFacenames(wxFontEncoding encoding,
|
||||
}
|
||||
}
|
||||
g_free(families);
|
||||
g_object_unref(context);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -40,11 +40,12 @@
|
||||
|
||||
#if wxUSE_PANGO
|
||||
|
||||
#include "pango/pango.h"
|
||||
#include <pango/pango.h>
|
||||
|
||||
PangoContext* wxGetPangoContext();
|
||||
|
||||
#ifdef __WXGTK20__
|
||||
#include "wx/gtk/private.h"
|
||||
extern GtkWidget *wxGetRootWindow();
|
||||
|
||||
#define wxPANGO_CONV wxGTK_CONV_SYS
|
||||
#define wxPANGO_CONV_BACK wxGTK_CONV_BACK_SYS
|
||||
@ -178,13 +179,8 @@ wxFontFamily wxNativeFontInfo::GetFamily() const
|
||||
PangoFontFamily **families;
|
||||
PangoFontFamily *family = NULL;
|
||||
int n_families;
|
||||
pango_context_list_families(
|
||||
#ifdef __WXGTK20__
|
||||
gtk_widget_get_pango_context( wxGetRootWindow() ),
|
||||
#else
|
||||
wxTheApp->GetPangoContext(),
|
||||
#endif
|
||||
&families, &n_families);
|
||||
PangoContext* context = wxGetPangoContext();
|
||||
pango_context_list_families(context, &families, &n_families);
|
||||
|
||||
for (int i = 0; i < n_families; ++i)
|
||||
{
|
||||
@ -197,6 +193,7 @@ wxFontFamily wxNativeFontInfo::GetFamily() const
|
||||
}
|
||||
|
||||
g_free(families);
|
||||
g_object_unref(context);
|
||||
|
||||
// Some gtk+ systems might query for a non-existing font from
|
||||
// wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) on initialization,
|
||||
|
@ -680,6 +680,12 @@ PangoContext* wxApp::GetPangoContext()
|
||||
return s_pangoContext;
|
||||
}
|
||||
|
||||
PangoContext* wxGetPangoContext()
|
||||
{
|
||||
PangoContext* context = wxTheApp->GetPangoContext();
|
||||
g_object_ref(context);
|
||||
return context;
|
||||
}
|
||||
#endif // wxUSE_UNICODE
|
||||
|
||||
WXColormap wxApp::GetMainColormap(WXDisplay* display)
|
||||
|
Loading…
Reference in New Issue
Block a user