#include "wx/msgdlg.h"
#include "wx/frame.h"
#include "wx/scrolwin.h"
-
+#include "wx/module.h"
#include "wx/menuitem.h"
#include "wx/log.h"
+#include "wx/listimpl.cpp"
+
#if wxUSE_DRAG_AND_DROP
#include "wx/dnd.h"
#endif
// global variables for this module
// ----------------------------------------------------------------------------
-static wxHashTable *gs_wxWidgetHashTable;
+extern wxHashTable *wxWidgetHashTable;
// ----------------------------------------------------------------------------
// private functions
// implementation
// ============================================================================
+// ----------------------------------------------------------------------------
+// list types
+// ----------------------------------------------------------------------------
+
+WX_DEFINE_LIST(wxRectList);
+
// ----------------------------------------------------------------------------
// helper functions
// ----------------------------------------------------------------------------
// ----------------------------------------------------------------------------
// Helper function
-void wxWindow::CreateScrollbar(int orientation)
+void wxWindow::CreateScrollbar(wxOrientation orientation)
{
wxCHECK_RET( m_drawingArea, "this window can't have scrollbars" );
XtVaSetValues((Widget) m_scrolledWindow, XmNresizePolicy, XmRESIZE_ANY, NULL);
}
-void wxWindow::DestroyScrollbar(int orientation)
+void wxWindow::DestroyScrollbar(wxOrientation orientation)
{
wxCHECK_RET( m_drawingArea, "this window can't have scrollbars" );
}
// Get the window with the focus
-wxWindow *wxWindow::FindFocus()
+wxWindow *wxWindowBase::FindFocus()
{
// TODO Problems:
// (1) Can there be multiple focussed widgets in an application?
return winFocus;
}
-void wxWindow::Enable(bool enable)
+bool wxWindow::Enable(bool enable)
{
if ( !wxWindowBase::Enable(enable) )
return FALSE;
- Widget wMain = GetMainWidget();
+ Widget wMain = (Widget)GetMainWidget();
if ( wMain )
{
XtSetSensitive(wMain, enable);
XLowerWindow(XtDisplay(wTop), window);
}
-void wxWindow::SetTitle( const wxString& title)
+void wxWindow::SetTitle(const wxString& title)
{
- SetWindowText(GetHwnd(), title.c_str());
+ XtVaSetValues((Widget)GetMainWidget(), XmNtitle, title.c_str(), NULL);
}
wxString wxWindow::GetTitle() const
{
- return wxGetWindowText(GetHWND());
+ char *title;
+ XtVaGetValues((Widget)GetMainWidget(), XmNtitle, &title, NULL);
+
+ return wxString(title);
}
void wxWindow::CaptureMouse()
if ( m_winCaptured )
return;
- Widget wMain = GetMainWidget();
+ Widget wMain = (Widget)GetMainWidget();
if ( wMain )
XtAddGrab(wMain, TRUE, FALSE);
if ( !m_winCaptured )
return;
- Widget wMain = GetMainWidget();
+ Widget wMain = (Widget)GetMainWidget();
if ( wMain )
XtRemoveGrab(wMain);
Widget w = (Widget) GetMainWidget();
Window win = XtWindow(w);
XDefineCursor((Display*) dpy, win, (Cursor) x_cursor);
+
+ return TRUE;
}
// Coordinates relative to the window
// can scroll.
int wxWindow::GetScrollRange(int orient) const
{
- Widget scrollBar = (Widget)GetScrollbar(orient);
+ Widget scrollBar = (Widget)GetScrollbar((wxOrientation)orient);
wxCHECK_MSG( scrollBar, 0, "no such scrollbar" );
int range;
int wxWindow::GetScrollThumb(int orient) const
{
- Widget scrollBar = (Widget)GetScrollbar(orient);
+ Widget scrollBar = (Widget)GetScrollbar((wxOrientation)orient);
wxCHECK_MSG( scrollBar, 0, "no such scrollbar" );
int thumb;
void wxWindow::SetScrollPos(int orient, int pos, bool WXUNUSED(refresh))
{
- Widget scrollBar = (Widget)GetScrollbar(orient);
+ Widget scrollBar = (Widget)GetScrollbar((wxOrientation)orient);
if ( scrollBar )
{
XtVaSetValues (scrollBar, XmNvalue, pos, NULL);
}
- SetInternalScrollPos(orient, pos);
+ SetInternalScrollPos((wxOrientation)orient, pos);
}
// New function that will replace some of the above.
thumbVisible = range;
// Save the old state to see if it changed
- WXWidget oldScrollBar = GetScrollbar(orient);
+ WXWidget oldScrollBar = GetScrollbar((wxOrientation)orient);
if (orient == wxHORIZONTAL)
{
CreateScrollbar(wxVERTICAL);
}
}
- WXWidget newScrollBar = GetScrollbar(orient);
+ WXWidget newScrollBar = GetScrollbar((wxOrientation)orient);
if (oldScrollBar != newScrollBar)
{
NULL);
}
- SetInternalScrollPos(orient, pos);
+ SetInternalScrollPos((wxOrientation)orient, pos);
int newW, newH;
GetSize(& newW, & newH);
}
// Get total size
-void wxWindow::GetSize(int *x, int *y) const
+void wxWindow::DoGetSize(int *x, int *y) const
{
if (m_drawingArea)
{
*x = xx; *y = yy;
}
-void wxWindow::GetPosition(int *x, int *y) const
+void wxWindow::DoGetPosition(int *x, int *y) const
{
if (m_drawingArea)
{
*x = xx; *y = yy;
}
-void wxWindow::ScreenToClient(int *x, int *y) const
+void wxWindow::DoScreenToClient(int *x, int *y) const
{
Widget widget = (Widget) GetClientWidget();
Display *display = XtDisplay((Widget) GetMainWidget());
XTranslateCoordinates(display, rootWindow, thisWindow, xx, yy, x, y, &childWindow);
}
-void wxWindow::ClientToScreen(int *x, int *y) const
+void wxWindow::DoClientToScreen(int *x, int *y) const
{
Widget widget = (Widget) GetClientWidget();
Display *display = XtDisplay(widget);
// Get size *available for subwindows* i.e. excluding menu bar etc.
-void wxWindow::GetClientSize(int *x, int *y) const
+void wxWindow::DoGetClientSize(int *x, int *y) const
{
Widget widget = (Widget) GetClientWidget();
Dimension xx, yy;
int wxWindow::GetCharHeight() const
{
- wxCHECK_MSG( m_windowFont.Ok(), 0, "valid window font needed" );
+ wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" );
- WXFontStructPtr pFontStruct = m_windowFont.GetFontStruct(1.0, GetXDisplay());
+ WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, GetXDisplay());
int direction, ascent, descent;
XCharStruct overall;
int wxWindow::GetCharWidth() const
{
- wxCHECK_MSG( m_windowFont.Ok(), 0, "valid window font needed" );
+ wxCHECK_MSG( m_font.Ok(), 0, "valid window font needed" );
- WXFontStructPtr pFontStruct = m_windowFont.GetFontStruct(1.0, GetXDisplay());
+ WXFontStructPtr pFontStruct = m_font.GetFontStruct(1.0, GetXDisplay());
int direction, ascent, descent;
XCharStruct overall;
{
wxFont *fontToUse = (wxFont *)theFont;
if (!fontToUse)
- fontToUse = (wxFont *) & m_windowFont;
+ fontToUse = (wxFont *) & m_font;
- wxCHECK_RET( fontToUse.Ok(), "valid window font needed" );
+ wxCHECK_RET( fontToUse->Ok(), "valid window font needed" );
WXFontStructPtr pFontStruct = theFont->GetFontStruct(1.0, GetXDisplay());
void wxWindow::ClearUpdateRects()
{
- wxNode* node = m_updateRects.First();
+ wxRectList::Node* node = m_updateRects.GetFirst();
while (node)
{
- wxRect* rect = (wxRect*) node->Data();
+ wxRect* rect = node->GetData();
delete rect;
- node = node->Next();
+ node = node->GetNext();
}
+
m_updateRects.Clear();
}
bool wxAddWindowToTable(Widget w, wxWindow *win)
{
wxWindow *oldItem = NULL;
- if ((oldItem = (wxWindow *)gs_wxWidgetHashTable->Get ((long) w)))
+ if ((oldItem = (wxWindow *)wxWidgetHashTable->Get ((long) w)))
{
wxLogDebug("Widget table clash: new widget is %ld, %s",
(long)w, win->GetClassInfo()->GetClassName());
return FALSE;
}
- gs_wxWidgetHashTable->Put((long) w, win);
+ wxWidgetHashTable->Put((long) w, win);
return TRUE;
}
wxWindow *wxGetWindowFromTable(Widget w)
{
- return (wxWindow *)gs_wxWidgetHashTable->Get((long) w);
+ return (wxWindow *)wxWidgetHashTable->Get((long) w);
}
void wxDeleteWindowFromTable(Widget w)
{
- gs_wxWidgetHashTable->Delete((long)w);
+ wxWidgetHashTable->Delete((long)w);
}
// ----------------------------------------------------------------------------
// Get the underlying X window
WXWindow wxWindow::GetXWindow() const
{
- Widget wMain = GetMainWidget();
+ Widget wMain = (Widget)GetMainWidget();
if ( wMain )
return (WXWindow) XtWindow(wMain);
else
// Get the underlying X display
WXDisplay *wxWindow::GetXDisplay() const
{
- Widget wMain = GetMainWidget();
+ Widget wMain = (Widget)GetMainWidget();
if ( wMain )
return (WXDisplay*) XtDisplay(wMain);
else
XEvent * event = cbs->event;
wxWindow * win = (wxWindow *) clientData;
- Display * display = (Display *) win->GetXDisplay();
switch (event->type)
{
case Expose:
{
- 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)
{
#if 0
win->DoPaint();
win->ClearUpdateRects();
}
+ else
+ {
+ win->AddUpdateRect(event->xexpose.x, event->xexpose.y,
+ event->xexpose.width, event->xexpose.height);
+ }
break;
}
}
if (local_event.xbutton.button == Button1)
{
eventType = wxEVT_LEFT_DOWN;
- canvas->m_button1Pressed = TRUE;
+ canvas->SetButton1(TRUE);
}
else if (local_event.xbutton.button == Button2)
{
eventType = wxEVT_MIDDLE_DOWN;
- canvas->m_button2Pressed = TRUE;
+ canvas->SetButton2(TRUE);
}
else if (local_event.xbutton.button == Button3)
{
eventType = wxEVT_RIGHT_DOWN;
- canvas->m_button3Pressed = TRUE;
+ canvas->SetButton3(TRUE);
}
}
else if (local_event.xany.type == ButtonRelease)
if (local_event.xbutton.button == Button1)
{
eventType = wxEVT_LEFT_UP;
- canvas->m_button1Pressed = FALSE;
+ canvas->SetButton1(FALSE);
}
else if (local_event.xbutton.button == Button2)
{
eventType = wxEVT_MIDDLE_UP;
- canvas->m_button2Pressed = FALSE;
+ canvas->SetButton2(FALSE);
}
else if (local_event.xbutton.button == Button3)
{
eventType = wxEVT_RIGHT_UP;
- canvas->m_button3Pressed = FALSE;
+ canvas->SetButton3(FALSE);
}
}
wxMouseEvent wxevent (eventType);
- wxevent.m_eventHandle = (char *) &local_event;
wxevent.m_leftDown = ((eventType == wxEVT_LEFT_DOWN)
|| (event_left_is_down (&local_event)
// get button and time-stamp
int button = 0;
- if (wxevent.LeftDown()) button = 1;
- else if (wxevent.MiddleDown()) button = 2;
- else if (wxevent.RightDown()) button = 3;
+ if (wxevent.LeftDown())
+ button = 1;
+ else if (wxevent.MiddleDown())
+ button = 2;
+ else if (wxevent.RightDown())
+ button = 3;
long ts = wxevent.GetTimestamp();
+
// check, if single or double click
- if (canvas->m_lastButton && canvas->m_lastButton==button && (ts - canvas->m_lastTS) < dclickTime)
+ int buttonLast = canvas->GetLastClickedButton();
+ long lastTS = canvas->GetLastClickTime();
+ if ( buttonLast && buttonLast == button && (ts - lastTS) < dclickTime )
{
// I have a dclick
- canvas->m_lastButton = 0;
+ canvas->SetLastClick(0, ts);
switch ( eventType )
{
case wxEVT_LEFT_DOWN:
else
{
// not fast enough or different button
- canvas->m_lastTS = ts;
- canvas->m_lastButton = button;
+ canvas->SetLastClick(button, ts);
}
}
}
{
// Widget can be a label or the actual widget.
- wxWindow *window = wxGetWindowFromTable(drawingArea);
+ wxWindow *window = wxGetWindowFromTable(wid);
if (window)
{
wxMouseEvent wxevent(0);
XtPointer clientData,
XmScaleCallbackStruct *cbs)
{
- Widget scrolledWindow = XtParent (scrollbar);
wxWindow *win = wxGetWindowFromTable(scrollbar);
int orientation = (int) clientData;
switch(event -> type)
{
- case Expose :
+ 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();
}
+ else
+ {
+ win->AddUpdateRect(event->xexpose.x, event->xexpose.y,
+ event->xexpose.width, event->xexpose.height);
+ }
+
break;
}
}
if (managed)
XtUnmanageChild (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
- XtVaSetValues((Widget) m_drawingArea, XmNresizePolicy, XmRESIZE_ANY, NULL);
+ XtVaSetValues(drawingArea, XmNresizePolicy, XmRESIZE_ANY, NULL);
int xx = x; int yy = y;
AdjustForParentClientOrigin(xx, yy, sizeFlags);
w -= (spacing + wsbar);
- // XtVaSetValues ((Widget) m_drawingArea, XmNwidth, w, NULL);
+#if 0
+ XtVaSetValues(drawingArea, XmNwidth, w, NULL);
+#endif // 0
}
if (h > -1)
{
h -= (spacing + wsbar);
- // XtVaSetValues ((Widget) m_drawingArea, XmNheight, h, NULL);
-
+#if 0
+ XtVaSetValues(drawingArea, XmNheight, h, NULL);
+#endif // 0
}
}
if (managed)
XtManageChild (m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
- XtVaSetValues((Widget) m_drawingArea, XmNresizePolicy, XmRESIZE_NONE, NULL);
+ XtVaSetValues(drawingArea, XmNresizePolicy, XmRESIZE_NONE, NULL);
#if 0
int ww, hh;
wxSizeEvent sizeEvent(wxSize(ww, hh), GetId());
sizeEvent.SetEventObject(this);
- GetEventHandler()->ProcessEvent(sizeEvent);
+ GetEventHandler()->ProcessEvent(sizeEvent);
#endif // 0
}
{
Widget drawingArea = (Widget) m_drawingArea;
- XtVaSetValues((Widget) m_drawingArea, XmNresizePolicy, XmRESIZE_ANY, NULL);
+ XtVaSetValues(drawingArea, XmNresizePolicy, XmRESIZE_ANY, NULL);
if (w > -1)
- XtVaSetValues ((Widget) m_drawingArea, XmNwidth, w, NULL);
+ XtVaSetValues(drawingArea, XmNwidth, w, NULL);
if (h > -1)
- XtVaSetValues ((Widget) m_drawingArea, XmNheight, h, NULL);
+ XtVaSetValues(drawingArea, XmNheight, h, NULL);
#if 0
// TODO: is this necessary?
}
#endif // 0
- XtVaSetValues((Widget) m_drawingArea, XmNresizePolicy, XmRESIZE_NONE, NULL);
+ XtVaSetValues(drawingArea, XmNresizePolicy, XmRESIZE_NONE, NULL);
#if 0
- allowRepainting = TRUE;
- DoRefresh ();
+ allowRepainting = TRUE;
+ DoRefresh ();
- wxSizeEvent sizeEvent(wxSize(w, h), GetId());
- sizeEvent.SetEventObject(this);
+ wxSizeEvent sizeEvent(wxSize(w, h), GetId());
+ sizeEvent.SetEventObject(this);
- GetEventHandler()->ProcessEvent(sizeEvent);
+ GetEventHandler()->ProcessEvent(sizeEvent);
#endif // 0
}
if (xevent->xany.type == LeaveNotify)
{
- win->m_button1Pressed = FALSE;
- win->m_button2Pressed = FALSE;
- win->m_button3Pressed = FALSE;
+ win->SetButton1(FALSE);
+ win->SetButton2(FALSE);
+ win->SetButton3(FALSE);
return FALSE;
}
else if (xevent->xany.type == MotionNotify)
if (xevent->xbutton.button == Button1)
{
eventType = wxEVT_LEFT_DOWN;
- win->m_button1Pressed = TRUE;
+ win->SetButton1(TRUE);
}
else if (xevent->xbutton.button == Button2)
{
eventType = wxEVT_MIDDLE_DOWN;
- win->m_button2Pressed = TRUE;
+ win->SetButton2(TRUE);
}
else if (xevent->xbutton.button == Button3)
{
eventType = wxEVT_RIGHT_DOWN;
- win->m_button3Pressed = TRUE;
+ win->SetButton3(TRUE);
}
}
else if (xevent->xany.type == ButtonRelease)
if (xevent->xbutton.button == Button1)
{
eventType = wxEVT_LEFT_UP;
- win->m_button1Pressed = FALSE;
+ win->SetButton1(FALSE);
}
else if (xevent->xbutton.button == Button2)
{
eventType = wxEVT_MIDDLE_UP;
- win->m_button2Pressed = FALSE;
+ win->SetButton2(FALSE);
}
else if (xevent->xbutton.button == Button3)
{
eventType = wxEVT_RIGHT_UP;
- win->m_button3Pressed = FALSE;
+ win->SetButton3(FALSE);
}
else return FALSE;
}
- else return FALSE;
+ else
+ {
+ return FALSE;
+ }
- wxevent.m_eventHandle = (char *)xevent;
wxevent.SetEventType(eventType);
Position x1, y1;
NULL);
}
-void wxWindow::SetBackgroundColour(const wxColour& col)
+bool wxWindow::SetBackgroundColour(const wxColour& col)
{
- m_backgroundColour = col;
+ if ( !wxWindowBase::SetBackgroundColour(col) )
+ return FALSE;
+
ChangeBackgroundColour();
+
+ return TRUE;
}
-void wxWindow::SetForegroundColour(const wxColour& col)
+bool wxWindow::SetForegroundColour(const wxColour& col)
{
- m_foregroundColour = col;
+ if ( !wxWindowBase::SetForegroundColour(col) )
+ return FALSE;
+
ChangeForegroundColour();
+
+ return TRUE;
}
void wxWindow::ChangeFont(bool keepOriginalSize)
// to its original size! We therefore have to set the size
// back again. TODO: a better way in Motif?
Widget w = (Widget) GetLabelWidget(); // Usually the main widget
- if (w && m_windowFont.Ok())
+ if (w && m_font.Ok())
{
int width, height, width1, height1;
GetSize(& width, & height);
// lesstif 0.87 hangs here
#ifndef LESSTIF_VERSION
XtVaSetValues (w,
- XmNfontList, (XmFontList) m_windowFont.GetFontList(1.0, XtDisplay(w)),
+ XmNfontList, (XmFontList) m_font.GetFontList(1.0, XtDisplay(w)),
NULL);
#endif
// wxNoOptimize: switch off size optimization
// ----------------------------------------------------------------------------
-int wxNoOptimize::m_count = 0;
-
-wxNoOptimize::wxNoOptimize()
-{
- m_count ++;
-}
-
-wxNoOptimize::~wxNoOptimize()
-{
- m_count --;
-}
-
-bool wxNoOptimize::CanOptimize()
-{
- return (m_count == 0);
-}
-
+int wxNoOptimize::ms_count = 0;