replace wxHashTable with a type safe hash map of Window to wxWindow
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@28505 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
parent
fe8604acce
commit
b8033a5ddc
@ -13,6 +13,7 @@
|
||||
#define _WX_PRIVATE_H_
|
||||
|
||||
#include "wx/defs.h"
|
||||
#include "wx/hashmap.h"
|
||||
#include "wx/utils.h"
|
||||
#if defined( __cplusplus ) && defined( __VMS )
|
||||
#pragma message disable nosimpint
|
||||
@ -52,6 +53,12 @@ class wxWindow;
|
||||
// corresponding to the window for this widget
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
WX_DECLARE_HASH_MAP(Window, wxWindow *, wxIntegerHash, wxIntegerEqual, wxWindowHash);
|
||||
|
||||
// these hashes are defined in app.cpp
|
||||
extern wxWindowHash *wxWidgetHashTable;
|
||||
extern wxWindowHash *wxClientWidgetHashTable;
|
||||
|
||||
extern void wxDeleteWindowFromTable(Window w);
|
||||
extern wxWindow *wxGetWindowFromTable(Window w);
|
||||
extern bool wxAddWindowToTable(Window w, wxWindow *win);
|
||||
|
@ -46,8 +46,8 @@
|
||||
|
||||
extern wxList wxPendingDelete;
|
||||
|
||||
wxHashTable *wxWidgetHashTable = NULL;
|
||||
wxHashTable *wxClientWidgetHashTable = NULL;
|
||||
wxWindowHash *wxWidgetHashTable = NULL;
|
||||
wxWindowHash *wxClientWidgetHashTable = NULL;
|
||||
|
||||
static bool g_showIconic = FALSE;
|
||||
static wxSize g_initialSize = wxDefaultSize;
|
||||
@ -203,8 +203,8 @@ bool wxApp::Initialize(int& argc, wxChar **argv)
|
||||
wxFont::SetDefaultEncoding(wxLocale::GetSystemEncoding());
|
||||
#endif
|
||||
|
||||
wxWidgetHashTable = new wxHashTable(wxKEY_INTEGER);
|
||||
wxClientWidgetHashTable = new wxHashTable(wxKEY_INTEGER);
|
||||
wxWidgetHashTable = new wxWindowHash;
|
||||
wxClientWidgetHashTable = new wxWindowHash;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
@ -62,8 +62,6 @@
|
||||
// global variables for this module
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
extern wxHashTable *wxWidgetHashTable;
|
||||
extern wxHashTable *wxClientWidgetHashTable;
|
||||
static wxWindow* g_captureWindow = NULL;
|
||||
static GC g_eraseGC;
|
||||
|
||||
@ -1296,70 +1294,68 @@ void wxWindowX11::OnInternalIdle()
|
||||
// function which maintain the global hash table mapping Widgets to wxWidgets
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxAddWindowToTable(Window w, wxWindow *win)
|
||||
static bool DoAddWindowToTable(wxWindowHash *hash, Window w, wxWindow *win)
|
||||
{
|
||||
wxWindow *oldItem = NULL;
|
||||
if ((oldItem = (wxWindow *)wxWidgetHashTable->Get ((long) w)))
|
||||
if ( !hash->insert(wxWindowHash::value_type(w, win)).second )
|
||||
{
|
||||
wxLogDebug( wxT("Widget table clash: new widget is %ld, %s"),
|
||||
(long)w, win->GetClassInfo()->GetClassName());
|
||||
wxLogDebug( wxT("Widget table clash: new widget is 0x%08x, %s"),
|
||||
(unsigned int)w, win->GetClassInfo()->GetClassName());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
wxWidgetHashTable->Put((long) w, win);
|
||||
|
||||
wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x <-> window %p (%s)"),
|
||||
(unsigned int) w, win, win->GetClassInfo()->GetClassName());
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static inline wxWindow *DoGetWindowFromTable(wxWindowHash *hash, Window w)
|
||||
{
|
||||
wxWindowHash::iterator i = hash->find(w);
|
||||
return i == hash->end() ? NULL : i->second;
|
||||
}
|
||||
|
||||
static inline void DoDeleteWindowFromTable(wxWindowHash *hash, Window w)
|
||||
{
|
||||
wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x deleted"), (unsigned int) w);
|
||||
|
||||
hash->erase(w);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// public wrappers
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxAddWindowToTable(Window w, wxWindow *win)
|
||||
{
|
||||
return DoAddWindowToTable(wxWidgetHashTable, w, win);
|
||||
}
|
||||
|
||||
wxWindow *wxGetWindowFromTable(Window w)
|
||||
{
|
||||
return (wxWindow *)wxWidgetHashTable->Get((long) w);
|
||||
return DoGetWindowFromTable(wxWidgetHashTable, w);
|
||||
}
|
||||
|
||||
void wxDeleteWindowFromTable(Window w)
|
||||
{
|
||||
wxWidgetHashTable->Delete((long)w);
|
||||
DoDeleteWindowFromTable(wxWidgetHashTable, w);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// function which maintain the global hash table mapping client widgets
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
bool wxAddClientWindowToTable(Window w, wxWindow *win)
|
||||
{
|
||||
wxWindow *oldItem = NULL;
|
||||
if ((oldItem = (wxWindow *)wxClientWidgetHashTable->Get ((long) w)))
|
||||
{
|
||||
wxLogDebug( wxT("Client window table clash: new window is %ld, %s"),
|
||||
(long)w, win->GetClassInfo()->GetClassName());
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
wxClientWidgetHashTable->Put((long) w, win);
|
||||
|
||||
wxLogTrace( wxT("widget"), wxT("XWindow 0x%08x <-> window %p (%s)"),
|
||||
(unsigned int) w, win, win->GetClassInfo()->GetClassName());
|
||||
|
||||
return TRUE;
|
||||
return DoAddWindowToTable(wxClientWidgetHashTable, w, win);
|
||||
}
|
||||
|
||||
wxWindow *wxGetClientWindowFromTable(Window w)
|
||||
{
|
||||
return (wxWindow *)wxClientWidgetHashTable->Get((long) w);
|
||||
return DoGetWindowFromTable(wxClientWidgetHashTable, w);
|
||||
}
|
||||
|
||||
void wxDeleteClientWindowFromTable(Window w)
|
||||
{
|
||||
wxClientWidgetHashTable->Delete((long)w);
|
||||
DoDeleteWindowFromTable(wxClientWidgetHashTable, w);
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// add/remove window from the table
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// X11-specific accessors
|
||||
// ----------------------------------------------------------------------------
|
||||
|
Loading…
Reference in New Issue
Block a user