From 25f471275725cf712dd01f32c564d1bff107e997 Mon Sep 17 00:00:00 2001 From: Julian Smart Date: Wed, 27 Oct 1999 08:59:23 +0000 Subject: [PATCH] Fixed wxMotif's wxRegion/wxRegionIterator to optionally use wxRects. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@4208 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- distrib/msw/generic.rsp | 2 - docs/html/index.htm | 1 + include/wx/motif/region.h | 22 ++++-- include/wx/motif/window.h | 6 +- src/generic/choicdgg.cpp | 8 ++- src/motif/dcclient.cpp | 3 + src/motif/region.cpp | 146 ++++++++++++++++++++++++++++++++++++-- src/motif/window.cpp | 8 --- 8 files changed, 169 insertions(+), 27 deletions(-) diff --git a/distrib/msw/generic.rsp b/distrib/msw/generic.rsp index be6ab947ac..560c128109 100644 --- a/distrib/msw/generic.rsp +++ b/distrib/msw/generic.rsp @@ -125,8 +125,6 @@ include/wx/html/msw/*.ico include/wx/html/msw/*.rc lib/dummy -bin/*.* - tools/gettext/*.* bitmaps/xpm/16x16/*.* diff --git a/docs/html/index.htm b/docs/html/index.htm index f00dc99c38..b5c0f39264 100644 --- a/docs/html/index.htm +++ b/docs/html/index.htm @@ -206,6 +206,7 @@ For printing-related dialogs, see the printing sample. using wxFrame.
  • docvwmdi: : demonstrates use of the document view classes, using wxMDIParentFrame, wxMDIChildFrame. +
  • drawing: tests device context drawing.
  • dynamic: shows how to connect events to member functions dynamically.
  • forty: a great little card game by Chris Breeze. A diff --git a/include/wx/motif/region.h b/include/wx/motif/region.h index 969a44f654..e5bcccbd4d 100644 --- a/include/wx/motif/region.h +++ b/include/wx/motif/region.h @@ -20,8 +20,12 @@ #include "wx/gdiobj.h" #include "wx/gdicmn.h" -class WXDLLEXPORT wxRect; -class WXDLLEXPORT wxPoint; +// ---------------------------------------------------------------------------- +// A list of rectangles type used by wxRegion and wxWindow +// ---------------------------------------------------------------------------- + +WX_DECLARE_LIST(wxRect, wxRectList); + enum wxRegionContain { wxOutRegion = 0, wxPartRegion = 1, wxInRegion = 2 @@ -104,6 +108,16 @@ public: // Get the internal Region handle WXRegion GetXRegion() const; + +// 'Naughty' functions that allow wxWindows to use a list of rects +// instead of the region, in certain circumstances (e.g. when +// making a region out of the update rectangles). +// These are used by wxPaintDC::wxPaintDC and wxRegionIterator::Reset. + bool UsingRects() const; + wxRect* GetRects(); + int GetRectCount() const; + void SetRects(const wxRectList& rectList); + void SetRects(int count, const wxRect* rects); }; class WXDLLEXPORT wxRegionIterator : public wxObject { @@ -128,13 +142,13 @@ public: long GetWidth() const { return GetW(); } long GetH() const; long GetHeight() const { return GetH(); } - wxRect GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); } + wxRect GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); } private: long m_current; long m_numRects; wxRegion m_region; - wxRect* m_rects; + wxRect* m_rects; }; #endif diff --git a/include/wx/motif/window.h b/include/wx/motif/window.h index 77b8625430..fbb7b729e9 100644 --- a/include/wx/motif/window.h +++ b/include/wx/motif/window.h @@ -16,11 +16,7 @@ #pragma interface "window.h" #endif -// ---------------------------------------------------------------------------- -// A list of rectangles type used by wxWindow -// ---------------------------------------------------------------------------- - -WX_DECLARE_LIST(wxRect, wxRectList); +#include "wx/region.h" // ---------------------------------------------------------------------------- // wxWindow class for Motif - see also wxWindowBase diff --git a/src/generic/choicdgg.cpp b/src/generic/choicdgg.cpp index 560eee9c2b..a0636f159b 100644 --- a/src/generic/choicdgg.cpp +++ b/src/generic/choicdgg.cpp @@ -288,9 +288,11 @@ void wxSingleChoiceDialog::OnOK(wxCommandEvent& WXUNUSED(event)) { m_selection = m_listbox->GetSelection(); m_stringSelection = m_listbox->GetStringSelection(); + // TODO! +#ifndef __WXMOTIF__ if ( m_listbox->HasClientUntypedData() ) SetClientData(m_listbox->GetClientData(m_selection)); - +#endif EndModal(wxID_OK); } @@ -298,8 +300,12 @@ void wxSingleChoiceDialog::OnListBoxDClick(wxCommandEvent& WXUNUSED(event)) { m_selection = m_listbox->GetSelection(); m_stringSelection = m_listbox->GetStringSelection(); + + // TODO! +#ifndef __WXMOTIF__ if ( m_listbox->HasClientUntypedData() ) SetClientData(m_listbox->GetClientData(m_selection)); +#endif EndModal(wxID_OK); } diff --git a/src/motif/dcclient.cpp b/src/motif/dcclient.cpp index c013b9fe8b..42ad9258d7 100644 --- a/src/motif/dcclient.cpp +++ b/src/motif/dcclient.cpp @@ -2284,6 +2284,9 @@ wxPaintDC::wxPaintDC(wxWindow* win) : wxWindowDC(win) win->SetUpdateRegion(*region); + wxRegion& theRegion(win->GetUpdateRegion()); + theRegion.SetRects(updateRects); // We also store in terms of rects, for iteration to work. + // Set the clipping region. Any user-defined region will be combined with this // one in SetDCClipping. XSetRegion ((Display*) m_display, (GC) m_gc, (Region) region->GetXRegion()); diff --git a/src/motif/region.cpp b/src/motif/region.cpp index 8431d309fa..8b03f1052b 100644 --- a/src/motif/region.cpp +++ b/src/motif/region.cpp @@ -23,6 +23,14 @@ IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator, wxObject) #endif +// ---------------------------------------------------------------------------- +// list types +// ---------------------------------------------------------------------------- + +#include "wx/listimpl.cpp" + +WX_DEFINE_LIST(wxRectList); + //----------------------------------------------------------------------------- // wxRegionRefData implementation //----------------------------------------------------------------------------- @@ -32,21 +40,86 @@ public: wxRegionRefData() { m_region = XCreateRegion(); + m_usingRects = FALSE; + m_rects = (wxRect*) NULL; + m_rectCount = 0; } wxRegionRefData(const wxRegionRefData& data) { m_region = XCreateRegion(); + m_rects = (wxRect*) NULL; + m_rectCount = 0; XUnionRegion(m_region, data.m_region, m_region); + + SetRects(data.m_rectCount, data.m_rects); } ~wxRegionRefData() { XDestroyRegion(m_region); + DeleteRects(); } - Region m_region; + + wxRect* GetRects() { return m_rects; }; + void SetRects(const wxRectList& rectList); + void SetRects(int count, const wxRect* rects); + bool UsingRects() const { return m_usingRects; } + int GetRectCount() const { return m_rectCount; } + + void DeleteRects(); + + Region m_region; + wxRect* m_rects; + int m_rectCount; + bool m_usingRects; // TRUE if we're using the above. }; +void wxRegionRefData::SetRects(const wxRectList& rectList) +{ + DeleteRects(); + m_usingRects = (rectList.Number() > 0); + if (m_usingRects) + { + m_rectCount = rectList.Number(); + m_rects = new wxRect[m_rectCount]; + } + + wxRectList::Node* node = rectList.GetFirst(); + int i = 0; + while (node) { + wxRect* rect = node->GetData(); + m_rects[i] = * rect; + node = node->GetNext(); + i ++; + } +} + +void wxRegionRefData::SetRects(int count, const wxRect* rects) +{ + DeleteRects(); + m_usingRects = (count > 0); + if (m_usingRects) + { + m_rectCount = count; + m_rects = new wxRect[m_rectCount]; + int i; + for (i = 0; i < m_rectCount; i++) + m_rects[i] = rects[i]; + } +} + +void wxRegionRefData::DeleteRects() +{ + if (m_rects) + { + delete[] m_rects; + m_rects = (wxRect*) NULL; + } + m_rectCount = 0; + m_usingRects = FALSE; + } + #define M_REGION (((wxRegionRefData*)m_refData)->m_region) //----------------------------------------------------------------------------- @@ -296,6 +369,38 @@ wxRegionContain wxRegion::Contains(const wxRect& rect) const return Contains(x, y, w, h); } +bool wxRegion::UsingRects() const +{ + return ((wxRegionRefData*)m_refData)->UsingRects(); +} + +/* +wxRectList& wxRegion::GetRectList() +{ + return ((wxRegionRefData*)m_refData)->GetRectList(); +} +*/ + +wxRect* wxRegion::GetRects() +{ + return ((wxRegionRefData*)m_refData)->GetRects(); +} + +int wxRegion::GetRectCount() const +{ + return ((wxRegionRefData*)m_refData)->GetRectCount(); +} + +void wxRegion::SetRects(const wxRectList& rectList) +{ + ((wxRegionRefData*)m_refData)->SetRects(rectList); +} + +void wxRegion::SetRects(int count, const wxRect* rects) +{ + ((wxRegionRefData*)m_refData)->SetRects(count, rects); +} + /////////////////////////////////////////////////////////////////////////////// // // // wxRegionIterator // @@ -342,12 +447,39 @@ void wxRegionIterator::Reset(const wxRegion& region) m_numRects = 0; else { - // TODO create m_rects and fill with rectangles for this region - - // For now, fudge by getting the whole bounding box. - m_rects = new wxRect[1]; - m_numRects = 1; - m_rects[0] = m_region.GetBox(); + // Create m_rects and fill with rectangles for this region. + // Since we can't find the rectangles in a region, we cheat + // by retrieving the rectangles explicitly set in wxPaintDC::wxPaintDC + // (dcclient.cpp). + if (m_region.UsingRects()) + { + wxRect* rects = m_region.GetRects(); + int count = m_region.GetRectCount(); + m_numRects = count; + m_rects = new wxRect[m_numRects]; + + int i = 0; + for (i = 0; i < m_numRects; i++) + m_rects[i] = rects[i]; + + /* + int i = 0; + wxRectList::Node* node = rectList.GetFirst(); + while (node) { + wxRect* rect = node->GetData(); + m_rects[i] = * rect; + node = node->GetNext(); + i ++; + } + */ + } + else + { + // For now, fudge by getting the whole bounding box. + m_rects = new wxRect[1]; + m_numRects = 1; + m_rects[0] = m_region.GetBox(); + } } } diff --git a/src/motif/window.cpp b/src/motif/window.cpp index eb96d7f645..0959d93286 100644 --- a/src/motif/window.cpp +++ b/src/motif/window.cpp @@ -40,8 +40,6 @@ #include "wx/menuitem.h" #include "wx/log.h" -#include "wx/listimpl.cpp" - #if wxUSE_DRAG_AND_DROP #include "wx/dnd.h" #endif @@ -129,12 +127,6 @@ static int str16len(const char *s) // implementation // ============================================================================ -// ---------------------------------------------------------------------------- -// list types -// ---------------------------------------------------------------------------- - -WX_DEFINE_LIST(wxRectList); - // ---------------------------------------------------------------------------- // helper functions // ---------------------------------------------------------------------------- -- 2.45.2