wxWindow::wxWindow()
{
// Generic
+ m_isWindow = TRUE; // An optimization
m_windowId = 0;
m_windowStyle = 0;
m_windowParent = NULL;
// Destructor
wxWindow::~wxWindow()
{
- // Remove potential dangling pointer
- if (GetParent() && GetParent()->IsKindOf(CLASSINFO(wxPanel)))
- {
- wxPanel* panel = (wxPanel*) GetParent();
- if (panel->GetLastFocus() == this)
- panel->SetLastFocus((wxWindow*) NULL);
- }
-
//// Motif-specific
if (GetMainWidget())
// Destroy the window
if (GetMainWidget())
{
- wxDeleteWindowFromTable((Widget) GetMainWidget());
+ // If this line (XtDestroyWidget) causes a crash, you may comment it out.
+ // Child widgets will get destroyed automatically when a frame
+ // or dialog is destroyed, but before that you may get some memory
+ // leaks and potential layout problems if you delete and then add
+ // child windows.
XtDestroyWidget((Widget) GetMainWidget());
SetMainWidget((WXWidget) NULL);
}
const wxString& name)
{
// Generic
+ m_isWindow = TRUE; // An optimization
m_windowId = 0;
m_windowStyle = 0;
m_windowParent = NULL;
*x = xx; *y = yy;
}
-void wxWindow::SetSize(int x, int y, int width, int height, int sizeFlags)
+void wxWindow::DoSetSize(int x, int y, int width, int height, int sizeFlags)
{
// A bit of optimization to help sort out the flickers.
int oldX, oldY, oldW, oldH;
*/
}
-void wxWindow::SetClientSize(int width, int height)
+void wxWindow::DoSetClientSize(int width, int height)
{
if (m_drawingArea)
{
// Get the window with the focus
wxWindow *wxWindow::FindFocus()
{
- // TODO
- return NULL;
+ // TODO Problems:
+ // (1) Can there be multiple focussed widgets in an application?
+ // In which case we need to find the top-level window that's
+ // currently active.
+ // (2) The widget with the focus may not be in the widget table
+ // depending on which widgets I put in the table
+
+ wxNode *node = wxTopLevelWindows.First();
+ while (node)
+ {
+ wxWindow *win = (wxWindow *)node->Data();
+
+ Widget w = XmGetFocusWidget ((Widget) win->GetTopWidget()) ;
+
+ if (w != (Widget) NULL)
+ {
+ wxWindow* focusWin = wxGetWindowFromTable(w);
+ if (focusWin)
+ return focusWin;
+ }
+
+ node = node->Next();
+ }
+ return (wxWindow*) NULL;
}
void wxWindow::AddChild(wxWindow *child)
{
if ( m_windowValidator )
delete m_windowValidator;
- m_windowValidator = validator.Clone();
+ m_windowValidator = (wxValidator*) validator.Clone();
if ( m_windowValidator )
m_windowValidator->SetWindow(this) ;
// Get the underlying X window and display
WXWindow wxWindow::GetXWindow() const
{
- return (WXWindow) XtWindow((Widget) GetMainWidget());
+ if (GetMainWidget())
+ return (WXWindow) XtWindow((Widget) GetMainWidget());
+ else
+ return (WXWindow) 0;
}
WXDisplay *wxWindow::GetXDisplay() const
{
- return (WXDisplay*) XtDisplay((Widget) GetMainWidget());
+ if (GetMainWidget())
+ return (WXDisplay*) XtDisplay((Widget) GetMainWidget());
+ else
+ return (WXDisplay*) NULL;
}
WXWidget wxWindow::GetMainWidget() const
return (m_count == 0);
}
+// For repainting arbitrary windows
+void wxUniversalRepaintProc(Widget w, XtPointer WXUNUSED(c_data), XEvent *event, char *)
+{
+ Window window;
+ Display *display;
+
+ wxWindow* win = (wxWindow *)wxWidgetHashTable->Get((long)w);
+ if (!win)
+ return;
+
+ switch(event -> type)
+ {
+ case Expose :
+ {
+ window = (Window) win -> GetXWindow();
+ display = (Display *) win -> GetXDisplay();
+
+ wxRect* rect = new wxRect(event->xexpose.x, event->xexpose.y,
+ event->xexpose.width, event->xexpose.height);
+ win->m_updateRects.Append((wxObject*) rect);
+
+ if (event -> xexpose.count == 0)
+ {
+ win->DoPaint();
+
+ win->ClearUpdateRects();
+ }
+ break;
+ }
+ default :
+ {
+ cout << "\n\nNew Event ! is = " << event -> type << "\n";
+ break;
+ }
+ }
+}
+