-// Get size *available for subwindows* i.e. excluding menu bar etc.
-void wxWindow::GetClientSize(int *x, int *y) const
-{
- Widget widget = (Widget) GetClientWidget();
- Dimension xx, yy;
- XtVaGetValues(widget, XmNwidth, &xx, XmNheight, &yy, NULL);
- *x = xx; *y = yy;
-}
-
-void wxWindow::SetSize(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;
- GetSize(& oldW, & oldH);
- GetPosition(& oldX, & oldY);
-
- bool useOldPos = FALSE;
- bool useOldSize = FALSE;
-
- if ((x == -1) && (x == -1) && ((sizeFlags & wxSIZE_ALLOW_MINUS_ONE) == 0))
- useOldPos = TRUE;
- else if (x == oldX && y == oldY)
- useOldPos = TRUE;
-
- if ((width == -1) && (height == -1))
- useOldSize = TRUE;
- else if (width == oldW && height == oldH)
- useOldSize = TRUE;
-
- if (!wxNoOptimize::CanOptimize())
- {
- useOldSize = FALSE; useOldPos = FALSE;
- }
-
- if (useOldPos && useOldSize)
- return;
-
- if (m_drawingArea)
- {
- CanvasSetSize(x, y, width, height, sizeFlags);
- return;
- }
- Widget widget = (Widget) GetTopWidget();
- if (!widget)
- return;
-
- bool managed = XtIsManaged( widget );
- if (managed)
- XtUnmanageChild(widget);
-
- int xx = x; int yy = y;
- AdjustForParentClientOrigin(xx, yy, sizeFlags);
-
- if (!useOldPos)
- {
- if (x > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
- XtVaSetValues(widget, XmNx, xx, NULL);
- if (y > -1 || (sizeFlags & wxSIZE_ALLOW_MINUS_ONE))
- XtVaSetValues(widget, XmNy, yy, NULL);
- }
- if (!useOldSize)
- {
- if (width > -1)
- XtVaSetValues(widget, XmNwidth, width, NULL);
- if (height > -1)
- XtVaSetValues(widget, XmNheight, height, NULL);
- }
-
- if (managed)
- XtManageChild(widget);
-
- // How about this bit. Maybe we don't need to generate size events
- // all the time -- they'll be generated when the window is sized anyway.
- /*
- wxSizeEvent sizeEvent(wxSize(width, height), GetId());
- sizeEvent.SetEventObject(this);
-
- GetEventHandler()->ProcessEvent(sizeEvent);
- */
-}
-
-void wxWindow::SetClientSize(int width, int height)
-{
- if (m_drawingArea)
- {
- CanvasSetClientSize(width, height);
- return;
- }
-
- Widget widget = (Widget) GetTopWidget();
-
- if (width > -1)
- XtVaSetValues(widget, XmNwidth, width, NULL);
- if (height > -1)
- XtVaSetValues(widget, XmNheight, height, NULL);
-
- wxSizeEvent sizeEvent(wxSize(width, height), GetId());
- sizeEvent.SetEventObject(this);
-
- GetEventHandler()->ProcessEvent(sizeEvent);
-}
-
-// For implementation purposes - sometimes decorations make the client area
-// smaller
-wxPoint wxWindow::GetClientAreaOrigin() const
-{
- return wxPoint(0, 0);
-}
-
-// Makes an adjustment to the window position (for example, a frame that has
-// a toolbar that it manages itself).
-void wxWindow::AdjustForParentClientOrigin(int& x, int& y, int sizeFlags)
-{
- if (((sizeFlags & wxSIZE_NO_ADJUSTMENTS) == 0) && GetParent())
- {
- wxPoint pt(GetParent()->GetClientAreaOrigin());
- x += pt.x; y += pt.y;
- }
-}
-
-bool wxWindow::Show(bool show)
-{
- if (show)
- {
- if (m_borderWidget || m_scrolledWindow)
- {
- if (m_drawingArea)
- XtMapWidget((Widget) m_drawingArea);
- XtMapWidget(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
- }
- else
- {
- WXWidget topWidget = GetTopWidget();
- if (GetTopWidget())
- XtMapWidget((Widget) GetTopWidget());
- else if (GetMainWidget())
- XtMapWidget((Widget) GetMainWidget());
- }
- }
- else
- {
- if (m_borderWidget || m_scrolledWindow)
- {
- if (m_drawingArea)
- XtUnmapWidget((Widget) m_drawingArea);
- XtUnmapWidget(m_borderWidget ? (Widget) m_borderWidget : (Widget) m_scrolledWindow);
- }
- else
- {
- if (GetTopWidget())
- XtUnmapWidget((Widget) GetTopWidget());
- else if (GetMainWidget())
- XtUnmapWidget((Widget) GetMainWidget());
- }
- }
-
- /*
- Window xwin = (Window) GetXWindow();
- Display *xdisp = (Display*) GetXDisplay();
- if (show)
- XMapWindow(xdisp, xwin);
- else
- XUnmapWindow(xdisp, xwin);
- */
-
- m_isShown = show;
-
- return TRUE;
-}
-
-bool wxWindow::IsShown() const
-{
- return m_isShown;
-}
-
-int wxWindow::GetCharHeight() const
-{
- if (!m_windowFont.Ok())
- return 0;
-
- WXFontStructPtr pFontStruct = m_windowFont.GetFontStruct(1.0, GetXDisplay());
-
- int direction, ascent, descent;
- XCharStruct overall;
- XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent,
- &descent, &overall);
- // return (overall.ascent + overall.descent);
- return (ascent + descent);
-}
-
-int wxWindow::GetCharWidth() const
-{
- if (!m_windowFont.Ok())
- return 0;
-
- WXFontStructPtr pFontStruct = m_windowFont.GetFontStruct(1.0, GetXDisplay());
-
- int direction, ascent, descent;
- XCharStruct overall;
- XTextExtents ((XFontStruct*) pFontStruct, "x", 1, &direction, &ascent,
- &descent, &overall);
- return overall.width;
-}
-
-/* Helper function for 16-bit fonts */
-static int str16len(const char *s)
-{
- int count = 0;
-
- while (s[0] && s[1]) {
- count++;
- s += 2;
- }
-
- return count;
-}
-
-void wxWindow::GetTextExtent(const wxString& string, int *x, int *y,
- int *descent, int *externalLeading, const wxFont *theFont, bool use16) const
-{
- wxFont *fontToUse = (wxFont *)theFont;
- if (!fontToUse)
- fontToUse = (wxFont *) & m_windowFont;
-
- if (!fontToUse->Ok())
- return;
-
- WXFontStructPtr pFontStruct = theFont->GetFontStruct(1.0, GetXDisplay());
-
- int direction, ascent, descent2;
- XCharStruct overall;
- int slen;
-
- if (use16) slen = str16len(string); else slen = strlen(string);
-
- if (use16)
- XTextExtents16((XFontStruct*) pFontStruct, (XChar2b *) (char*) (const char*) string, slen, &direction,
- &ascent, &descent2, &overall);
- else
- XTextExtents((XFontStruct*) pFontStruct, (char*) (const char*) string, slen, &direction,
- &ascent, &descent2, &overall);
-
- *x = (overall.width);
- *y = (ascent + descent2);
- if (descent)
- *descent = descent2;
- if (externalLeading)
- *externalLeading = 0;
-}
-
-void wxWindow::Refresh(bool eraseBack, const wxRect *rect)
-{
- m_needsRefresh = TRUE;
- Display *display = XtDisplay((Widget) GetMainWidget());
- Window thisWindow = XtWindow((Widget) GetMainWidget());
-
- XExposeEvent dummyEvent;
- int width, height;
- GetSize(&width, &height);
-
- dummyEvent.type = Expose;
- dummyEvent.display = display;
- dummyEvent.send_event = True;
- dummyEvent.window = thisWindow;
- if (rect)
- {
- dummyEvent.x = rect->x;
- dummyEvent.y = rect->y;
- dummyEvent.width = rect->width;
- dummyEvent.height = rect->height;
- }
- else
- {
- dummyEvent.x = 0;
- dummyEvent.y = 0;
- dummyEvent.width = width;
- dummyEvent.height = height;
- }
- dummyEvent.count = 0;
-
- if (eraseBack)
- {
- wxClientDC dc(this);
- wxBrush backgroundBrush(GetBackgroundColour(), wxSOLID);
- dc.SetBackground(backgroundBrush);
- if (rect)
- dc.Clear(*rect);
- else
- dc.Clear();
- }
-
- XSendEvent(display, thisWindow, False, ExposureMask, (XEvent *)&dummyEvent);
-}
-
-// Responds to colour changes: passes event on to children.
-void wxWindow::OnSysColourChanged(wxSysColourChangedEvent& event)
-{
- wxNode *node = GetChildren().First();
- while ( node )
- {
- // Only propagate to non-top-level windows
- wxWindow *win = (wxWindow *)node->Data();
- if ( win->GetParent() )
- {
- wxSysColourChangedEvent event2;
- event.m_eventObject = win;
- win->GetEventHandler()->ProcessEvent(event2);
- }
-
- node = node->Next();
- }
-}
-
-// This can be called by the app (or wxWindows) to do default processing for the current
-// event. Save message/event info in wxWindow so they can be used in this function.
-long wxWindow::Default()
-{
- // TODO
- return 0;
-}
-
-void wxWindow::InitDialog()
-{
- wxInitDialogEvent event(GetId());
- event.SetEventObject( this );
- GetEventHandler()->ProcessEvent(event);
-}
-
-// Default init dialog behaviour is to transfer data to window
-void wxWindow::OnInitDialog(wxInitDialogEvent& event)
-{
- TransferDataToWindow();
-}
-
-// Caret manipulation
-void wxWindow::CreateCaret(int w, int h)
-{
- m_caretWidth = w;
- m_caretHeight = h;
- m_caretEnabled = TRUE;
-}
-
-void wxWindow::CreateCaret(const wxBitmap *WXUNUSED(bitmap))
-{
- // TODO
-}
-
-void wxWindow::ShowCaret(bool show)
-{
- // TODO
-}
-
-void wxWindow::DestroyCaret()
-{
- // TODO
- m_caretEnabled = FALSE;
-}
-
-void wxWindow::SetCaretPos(int x, int y)
-{
- // TODO
-}
-
-void wxWindow::GetCaretPos(int *x, int *y) const
-{
- // TODO
-}
-
-wxWindow *wxGetActiveWindow()
-{
- // TODO
- return NULL;
-}
-
-void wxWindow::SetSizeHints(int minW, int minH, int maxW, int maxH, int incW, int incH)
-{
- m_minSizeX = minW;
- m_minSizeY = minH;
- m_maxSizeX = maxW;
- m_maxSizeY = maxH;
-
- if (!this->IsKindOf(CLASSINFO(wxFrame)))
- return;
-
- wxFrame *frame = (wxFrame *)this;
- Widget widget = (Widget) frame->GetShellWidget();
-
- if (minW > -1)
- XtVaSetValues(widget, XmNminWidth, minW, NULL);
- if (minH > -1)
- XtVaSetValues(widget, XmNminHeight, minH, NULL);
- if (maxW > -1)
- XtVaSetValues(widget, XmNmaxWidth, maxW, NULL);
- if (maxH > -1)
- XtVaSetValues(widget, XmNmaxHeight, maxH, NULL);
- if (incW > -1)
- XtVaSetValues(widget, XmNwidthInc, incW, NULL);
- if (incH > -1)
- XtVaSetValues(widget, XmNheightInc, incH, NULL);
-}
-
-void wxWindow::Centre(int direction)
-{
- int x, y, width, height, panel_width, panel_height, new_x, new_y;
-
- wxWindow *father = (wxWindow *)GetParent();
- if (!father)
- return;
-
- father->GetClientSize(&panel_width, &panel_height);
- GetSize(&width, &height);
- GetPosition(&x, &y);
-
- new_x = -1;
- new_y = -1;
-
- if (direction & wxHORIZONTAL)
- new_x = (int)((panel_width - width)/2);
-
- if (direction & wxVERTICAL)
- new_y = (int)((panel_height - height)/2);
-
- SetSize(new_x, new_y, -1, -1);
-