From e97f20a0f2bcff6b144b8ab81c73c1d412361864 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Wed, 23 Sep 1998 13:56:00 +0000 Subject: [PATCH] wxMotif: wxWindow/Client/PaintDC starting to work. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@769 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/motif/todo.txt | 3 ++ include/wx/defs.h | 1 + include/wx/motif/dcclient.h | 1 + src/generic/statusbr.cpp | 6 ++- src/motif/colour.cpp | 13 ++----- src/motif/dcclient.cpp | 25 +++++++++++- src/motif/font.cpp | 6 ++- src/motif/settings.cpp | 76 +++++++++++++++++++++++++++++-------- src/motif/window.cpp | 8 +++- 9 files changed, 109 insertions(+), 30 deletions(-) diff --git a/docs/motif/todo.txt b/docs/motif/todo.txt index 52f9d8e0f9..8d6a1775aa 100644 --- a/docs/motif/todo.txt +++ b/docs/motif/todo.txt @@ -11,6 +11,9 @@ Updated: 21/9/98 libxpm exists and use that? What about PNGs? Can we use gdk as per wxGTK? Probably not. +- Work out why XFreeFont in font.cpp produces a segv. This is + currently commented out, which presumably causes a memory leak. + - wxRegion - Bitmap versions of widgets (wxBitmapButton etc.) diff --git a/include/wx/defs.h b/include/wx/defs.h index 0082470ae1..13c94ff050 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -901,6 +901,7 @@ typedef void* WXPixmap; typedef void* WXFontStructPtr; typedef void* WXGC; typedef void* WXRegion; +typedef void* WXFont; #endif #endif diff --git a/include/wx/motif/dcclient.h b/include/wx/motif/dcclient.h index a4d303e885..10bae9365f 100644 --- a/include/wx/motif/dcclient.h +++ b/include/wx/motif/dcclient.h @@ -118,6 +118,7 @@ protected: int m_currentStyle ; int m_currentFill ; int m_autoSetting ; // See comment in dcclient.cpp + WXFont m_oldFont; }; class WXDLLEXPORT wxPaintDC: public wxWindowDC diff --git a/src/generic/statusbr.cpp b/src/generic/statusbr.cpp index 58a104aa7e..da95f833d9 100644 --- a/src/generic/statusbr.cpp +++ b/src/generic/statusbr.cpp @@ -62,9 +62,9 @@ wxStatusBar::wxStatusBar(void) wxStatusBar::~wxStatusBar(void) { -#ifdef __WXMSW__ + // #ifdef __WXMSW__ SetFont(wxNullFont); -#endif + // #endif if ( m_statusWidths ) delete[] m_statusWidths; @@ -178,6 +178,8 @@ void wxStatusBar::OnPaint(wxPaintEvent& WXUNUSED(event) ) for ( i = 0; i < m_nFields; i ++ ) DrawField(dc, i); + + dc.SetFont(wxNullFont); } void wxStatusBar::DrawFieldText(wxDC& dc, int i) diff --git a/src/motif/colour.cpp b/src/motif/colour.cpp index c3dca7072c..a6a1287ff6 100644 --- a/src/motif/colour.cpp +++ b/src/motif/colour.cpp @@ -73,6 +73,7 @@ wxColour::wxColour (const wxString& col) m_red = the_colour->Red (); m_green = the_colour->Green (); m_blue = the_colour->Blue (); + m_pixel = the_colour->m_pixel; m_isInit = TRUE; } else @@ -82,9 +83,6 @@ wxColour::wxColour (const wxString& col) m_blue = 0; m_isInit = FALSE; } -/* TODO - m_pixel = PALETTERGB (m_red, m_green, m_blue); -*/ } wxColour::~wxColour () @@ -99,6 +97,7 @@ wxColour& wxColour::operator = (const wxString& col) m_red = the_colour->Red (); m_green = the_colour->Green (); m_blue = the_colour->Blue (); + m_pixel = the_colour->m_pixel; m_isInit = TRUE; } else @@ -108,9 +107,7 @@ wxColour& wxColour::operator = (const wxString& col) m_blue = 0; m_isInit = FALSE; } -/* TODO - m_pixel = PALETTERGB (m_red, m_green, m_blue); -*/ + return (*this); } @@ -120,9 +117,7 @@ void wxColour::Set (unsigned char r, unsigned char g, unsigned char b) m_green = g; m_blue = b; m_isInit = TRUE; -/* TODO - m_pixel = PALETTERGB (m_red, m_green, m_blue); -*/ + m_pixel = -1; } // Allocate a colour, or nearest colour, using the given display. diff --git a/src/motif/dcclient.cpp b/src/motif/dcclient.cpp index 7ef4bf61ef..9f994b2747 100644 --- a/src/motif/dcclient.cpp +++ b/src/motif/dcclient.cpp @@ -89,6 +89,7 @@ wxWindowDC::wxWindowDC(void) m_userRegion = (WXRegion) 0; m_pixmap = (WXPixmap) 0; m_autoSetting = 0; + m_oldFont = (WXFont) 0; }; wxWindowDC::wxWindowDC( wxWindow *window ) @@ -136,10 +137,23 @@ wxWindowDC::wxWindowDC( wxWindow *window ) } m_backgroundPixel = (int) gcvalues.background; + + // Get the current Font so we can set it back later + XGCValues valReturn; + XGetGCValues((Display*) m_display, (GC) m_gc, GCFont, &valReturn); + m_oldFont = (WXFont) valReturn.font; }; wxWindowDC::~wxWindowDC(void) { + if ((m_oldFont != (WXFont) 0) && ((long) m_oldFont != -1)) + { + XSetFont ((Display*) m_display, (GC) m_gc, (Font) m_oldFont); + + if (m_window && m_window->GetBackingPixmap()) + XSetFont ((Display*) m_display,(GC) m_gcBacking, (Font) m_oldFont); + } + if (m_gc) XFreeGC ((Display*) m_display, (GC) m_gc); m_gc = (WXGC) 0; @@ -1323,7 +1337,16 @@ void wxWindowDC::SetFont( const wxFont &font ) m_font = font; if (!m_font.Ok()) + { + if ((m_oldFont != (WXFont) 0) && ((long) m_oldFont != -1)) + { + XSetFont ((Display*) m_display, (GC) m_gc, (Font) m_oldFont); + + if (m_window && m_window->GetBackingPixmap()) + XSetFont ((Display*) m_display,(GC) m_gcBacking, (Font) m_oldFont); + } return; + } WXFontStructPtr pFontStruct = m_font.FindOrCreateFontStruct(m_userScaleY*m_logicalScaleY); @@ -1339,7 +1362,7 @@ void wxWindowDC::SetPen( const wxPen &pen ) if (!Ok()) return; m_pen = pen; - if (m_pen.Ok()) + if (!m_pen.Ok()) return; wxBitmap oldStipple = m_currentStipple; diff --git a/src/motif/font.cpp b/src/motif/font.cpp index feeb310e0b..ae4ccd07ff 100644 --- a/src/motif/font.cpp +++ b/src/motif/font.cpp @@ -56,7 +56,10 @@ wxFontRefData::~wxFontRefData() while (node) { XFontStruct* fontStruct = (XFontStruct*) node->Data(); - XFreeFont((Display*) wxGetDisplay, fontStruct); + // TODO: why does freeing the font produce a segv??? + // Commenting it out will result in memory leaks, and + // maybe X resource problems, who knows... + // XFreeFont((Display*) wxGetDisplay, fontStruct); node = node->Next(); } m_fontsByScale.Clear(); @@ -290,6 +293,7 @@ WXFontStructPtr wxFont::FindOrCreateFontStruct(double scale) if (!font) font = LoadQueryFont(120, wxDEFAULT, wxNORMAL, wxNORMAL, M_FONTDATA->m_underlined); + wxASSERT_MSG( (font != (XFontStruct*) NULL), "Could not allocate even a default font -- something is wrong." ); } if (font) { diff --git a/src/motif/settings.cpp b/src/motif/settings.cpp index 357fe42c8f..9bfe3411ca 100644 --- a/src/motif/settings.cpp +++ b/src/motif/settings.cpp @@ -18,37 +18,83 @@ #endif #include "wx/settings.h" +#include "wx/gdicmn.h" wxColour wxSystemSettings::GetSystemColour(int index) { - // TODO - return wxColour(); + switch (index) + { + case wxSYS_COLOUR_SCROLLBAR: + // case wxSYS_COLOUR_DESKTOP: // Same as wxSYS_COLOUR_BACKGROUND + case wxSYS_COLOUR_BACKGROUND: + case wxSYS_COLOUR_ACTIVECAPTION: + case wxSYS_COLOUR_INACTIVECAPTION: + case wxSYS_COLOUR_MENU: + case wxSYS_COLOUR_WINDOW: + case wxSYS_COLOUR_WINDOWFRAME: + case wxSYS_COLOUR_ACTIVEBORDER: + case wxSYS_COLOUR_INACTIVEBORDER: + case wxSYS_COLOUR_BTNFACE: + // case wxSYS_COLOUR_3DFACE: // Same as wxSYS_COLOUR_BTNFACE + case wxSYS_COLOUR_GRAYTEXT: + { + return wxColour("LIGHT GREY"); + } + case wxSYS_COLOUR_BTNSHADOW: + // case wxSYS_COLOUR_3DSHADOW: // Same as wxSYS_COLOUR_BTNSHADOW + { + return wxColour("GREY"); + } + case wxSYS_COLOUR_3DDKSHADOW: + { + return *wxBLACK; + } + case wxSYS_COLOUR_HIGHLIGHT: + case wxSYS_COLOUR_BTNHIGHLIGHT: + // case wxSYS_COLOUR_3DHIGHLIGHT: // Same as wxSYS_COLOUR_BTNHIGHLIGHT + { + return *wxWHITE; + } + case wxSYS_COLOUR_3DLIGHT: + { + return wxColour("LIGHT GREY"); + } + case wxSYS_COLOUR_MENUTEXT: + case wxSYS_COLOUR_WINDOWTEXT: + case wxSYS_COLOUR_CAPTIONTEXT: + case wxSYS_COLOUR_INACTIVECAPTIONTEXT: + case wxSYS_COLOUR_INFOTEXT: + { + return *wxBLACK; + } + case wxSYS_COLOUR_HIGHLIGHTTEXT: + { + return *wxWHITE; + } + case wxSYS_COLOUR_INFOBK: + case wxSYS_COLOUR_APPWORKSPACE: + { + return *wxWHITE; + } + } + return *wxWHITE; } wxFont wxSystemSettings::GetSystemFont(int index) { - // TODO switch (index) { - case wxSYS_DEVICE_DEFAULT_FONT: - { - break; - } - case wxSYS_DEFAULT_PALETTE: - { - break; - } case wxSYS_SYSTEM_FIXED_FONT: { + return wxFont(12, wxMODERN, wxNORMAL, wxNORMAL, FALSE); break; } + case wxSYS_DEVICE_DEFAULT_FONT: case wxSYS_SYSTEM_FONT: - { - break; - } - default: case wxSYS_DEFAULT_GUI_FONT: + default: { + return wxFont(12, wxSWISS, wxNORMAL, wxNORMAL, FALSE); break; } } diff --git a/src/motif/window.cpp b/src/motif/window.cpp index dffcfcc268..bdf67fa1f3 100644 --- a/src/motif/window.cpp +++ b/src/motif/window.cpp @@ -419,7 +419,9 @@ bool wxWindow::Create(wxWindow *parent, wxWindowID id, XtAddEventHandler ((Widget) m_drawingArea, PointerMotionHintMask | EnterWindowMask | LeaveWindowMask | FocusChangeMask, False, (XtEventHandler) wxCanvasEnterLeave, (XtPointer) this); - return TRUE; + SetSize(pos.x, pos.y, size.x, size.y); + + return TRUE; } void wxWindow::SetFocus() @@ -759,6 +761,8 @@ void wxWindow::Refresh(bool eraseBack, const wxRectangle *rect) if (eraseBack) { wxClientDC dc(this); + wxBrush backgroundBrush(GetBackgroundColour(), wxSOLID); + dc.SetBackground(backgroundBrush); dc.Clear(); } @@ -1553,7 +1557,7 @@ void wxWindow::OnDefaultAction(wxControl *initiatingItem) void wxWindow::Clear() { - wxClientDC dc(this); + wxClientDC dc(this); wxBrush brush(GetBackgroundColour(), wxSOLID); dc.SetBackground(brush); dc.Clear(); -- 2.45.2