| 1 | ///////////////////////////////////////////////////////////////////////////// |
| 2 | // File: region.cpp |
| 3 | // Purpose: Region class |
| 4 | // Author: Markus Holzem/Julian Smart/AUTHOR |
| 5 | // Created: Fri Oct 24 10:46:34 MET 1997 |
| 6 | // RCS-ID: $Id$ |
| 7 | // Copyright: (c) 1997 Markus Holzem/Julian Smart/AUTHOR |
| 8 | // Licence: wxWindows licence |
| 9 | ///////////////////////////////////////////////////////////////////////////// |
| 10 | |
| 11 | #ifdef __GNUG__ |
| 12 | #pragma implementation "region.h" |
| 13 | #endif |
| 14 | |
| 15 | #include "wx/wxprec.h" |
| 16 | |
| 17 | #ifdef __BORLANDC__ |
| 18 | #pragma hdrstop |
| 19 | #endif |
| 20 | |
| 21 | #include "wx/msw/region.h" |
| 22 | #include "wx/gdicmn.h" |
| 23 | |
| 24 | #include <windows.h> |
| 25 | |
| 26 | IMPLEMENT_DYNAMIC_CLASS(wxRegion, wxGDIObject) |
| 27 | IMPLEMENT_DYNAMIC_CLASS(wxRegionIterator, wxObject) |
| 28 | |
| 29 | //----------------------------------------------------------------------------- |
| 30 | // wxRegionRefData implementation |
| 31 | //----------------------------------------------------------------------------- |
| 32 | |
| 33 | class WXDLLEXPORT wxRegionRefData : public wxGDIRefData { |
| 34 | public: |
| 35 | wxRegionRefData() |
| 36 | { |
| 37 | } |
| 38 | |
| 39 | wxRegionRefData(const wxRegionRefData& data) |
| 40 | { |
| 41 | // TODO |
| 42 | } |
| 43 | |
| 44 | ~wxRegionRefData() |
| 45 | { |
| 46 | // TODO |
| 47 | } |
| 48 | |
| 49 | HRGN m_region; |
| 50 | }; |
| 51 | |
| 52 | |
| 53 | //----------------------------------------------------------------------------- |
| 54 | // wxRegion |
| 55 | //----------------------------------------------------------------------------- |
| 56 | |
| 57 | /*! |
| 58 | * Create an empty region. |
| 59 | */ |
| 60 | wxRegion::wxRegion() |
| 61 | { |
| 62 | m_refData = new wxRegionRefData; |
| 63 | // TODO create empty region |
| 64 | } |
| 65 | |
| 66 | wxRegion::wxRegion(long x, long y, long w, long h) |
| 67 | { |
| 68 | m_refData = new wxRegionRefData; |
| 69 | // TODO create rect region |
| 70 | } |
| 71 | |
| 72 | wxRegion::wxRegion(const wxPoint& topLeft, const wxPoint& bottomRight) |
| 73 | { |
| 74 | m_refData = new wxRegionRefData; |
| 75 | // TODO create rect region |
| 76 | } |
| 77 | |
| 78 | wxRegion::wxRegion(const wxRect& rect) |
| 79 | { |
| 80 | m_refData = new wxRegionRefData; |
| 81 | // TODO create rect region |
| 82 | } |
| 83 | |
| 84 | /*! |
| 85 | * Destroy the region. |
| 86 | */ |
| 87 | wxRegion::~wxRegion() |
| 88 | { |
| 89 | // m_refData unrefed in ~wxObject |
| 90 | } |
| 91 | |
| 92 | //----------------------------------------------------------------------------- |
| 93 | //# Modify region |
| 94 | //----------------------------------------------------------------------------- |
| 95 | |
| 96 | //! Clear current region |
| 97 | void wxRegion::Clear() |
| 98 | { |
| 99 | UnRef(); |
| 100 | } |
| 101 | |
| 102 | //! Combine rectangle (x, y, w, h) with this. |
| 103 | bool wxRegion::Combine(long x, long y, long width, long height, wxRegionOp op) |
| 104 | { |
| 105 | // Don't change shared data |
| 106 | if (!m_refData) { |
| 107 | m_refData = new wxRegionRefData(); |
| 108 | } else if (m_refData->GetRefCount() > 1) { |
| 109 | wxRegionRefData* ref = (wxRegionRefData*)m_refData; |
| 110 | UnRef(); |
| 111 | m_refData = new wxRegionRefData(*ref); |
| 112 | } |
| 113 | // If ref count is 1, that means it's 'ours' anyway so no action. |
| 114 | |
| 115 | // TODO create rect region |
| 116 | |
| 117 | int mode = 0; // TODO platform-specific code |
| 118 | switch (op) |
| 119 | { |
| 120 | case wxRGN_AND: |
| 121 | // TODO |
| 122 | break ; |
| 123 | case wxRGN_OR: |
| 124 | // TODO |
| 125 | break ; |
| 126 | case wxRGN_XOR: |
| 127 | // TODO |
| 128 | break ; |
| 129 | case wxRGN_DIFF: |
| 130 | // TODO |
| 131 | break ; |
| 132 | case wxRGN_COPY: |
| 133 | default: |
| 134 | // TODO |
| 135 | break ; |
| 136 | } |
| 137 | |
| 138 | // TODO do combine region |
| 139 | |
| 140 | return FALSE; |
| 141 | } |
| 142 | |
| 143 | //! Union /e region with this. |
| 144 | bool wxRegion::Combine(const wxRegion& region, wxRegionOp op) |
| 145 | { |
| 146 | if (region.Empty()) |
| 147 | return FALSE; |
| 148 | |
| 149 | // Don't change shared data |
| 150 | if (!m_refData) { |
| 151 | m_refData = new wxRegionRefData(); |
| 152 | } else if (m_refData->GetRefCount() > 1) { |
| 153 | wxRegionRefData* ref = (wxRegionRefData*)m_refData; |
| 154 | UnRef(); |
| 155 | m_refData = new wxRegionRefData(*ref); |
| 156 | } |
| 157 | |
| 158 | int mode = 0; // TODO platform-specific code |
| 159 | switch (op) |
| 160 | { |
| 161 | case wxRGN_AND: |
| 162 | // TODO |
| 163 | break ; |
| 164 | case wxRGN_OR: |
| 165 | // TODO |
| 166 | break ; |
| 167 | case wxRGN_XOR: |
| 168 | // TODO |
| 169 | break ; |
| 170 | case wxRGN_DIFF: |
| 171 | // TODO |
| 172 | break ; |
| 173 | case wxRGN_COPY: |
| 174 | default: |
| 175 | // TODO |
| 176 | break ; |
| 177 | } |
| 178 | |
| 179 | // TODO combine region |
| 180 | |
| 181 | return FALSE; |
| 182 | } |
| 183 | |
| 184 | bool wxRegion::Combine(const wxRect& rect, wxRegionOp op) |
| 185 | { |
| 186 | return Combine(rect.GetLeft(), rect.GetTop(), rect.GetWidth(), rect.GetHeight(), op); |
| 187 | } |
| 188 | |
| 189 | //----------------------------------------------------------------------------- |
| 190 | //# Information on region |
| 191 | //----------------------------------------------------------------------------- |
| 192 | |
| 193 | // Outer bounds of region |
| 194 | void wxRegion::GetBox(long& x, long& y, long&w, long &h) const |
| 195 | { |
| 196 | if (m_refData) { |
| 197 | // TODO get box |
| 198 | } else { |
| 199 | x = y = w = h = 0; |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | wxRect wxRegion::GetBox() const |
| 204 | { |
| 205 | long x, y, w, h; |
| 206 | GetBox(x, y, w, h); |
| 207 | return wxRect(x, y, w, h); |
| 208 | } |
| 209 | |
| 210 | // Is region empty? |
| 211 | bool wxRegion::Empty() const |
| 212 | { |
| 213 | // TODO |
| 214 | return FALSE; |
| 215 | } |
| 216 | |
| 217 | //----------------------------------------------------------------------------- |
| 218 | //# Tests |
| 219 | //----------------------------------------------------------------------------- |
| 220 | |
| 221 | // Does the region contain the point (x,y)? |
| 222 | wxRegionContain wxRegion::Contains(long x, long y) const |
| 223 | { |
| 224 | if (!m_refData) |
| 225 | return wxOutRegion; |
| 226 | |
| 227 | // TODO. Return wxInRegion if within region. |
| 228 | if (0) |
| 229 | return wxInRegion; |
| 230 | return wxOutRegion; |
| 231 | } |
| 232 | |
| 233 | // Does the region contain the point pt? |
| 234 | wxRegionContain wxRegion::Contains(const wxPoint& pt) const |
| 235 | { |
| 236 | if (!m_refData) |
| 237 | return wxOutRegion; |
| 238 | |
| 239 | // TODO. Return wxInRegion if within region. |
| 240 | if (0) |
| 241 | return wxInRegion; |
| 242 | else |
| 243 | return wxOutRegion; |
| 244 | } |
| 245 | |
| 246 | // Does the region contain the rectangle (x, y, w, h)? |
| 247 | wxRegionContain wxRegion::Contains(long x, long y, long w, long h) const |
| 248 | { |
| 249 | if (!m_refData) |
| 250 | return wxOutRegion; |
| 251 | |
| 252 | // TODO. Return wxInRegion if within region. |
| 253 | if (0) |
| 254 | return wxInRegion; |
| 255 | else |
| 256 | return wxOutRegion; |
| 257 | } |
| 258 | |
| 259 | // Does the region contain the rectangle rect |
| 260 | wxRegionContain wxRegion::Contains(const wxRect& rect) const |
| 261 | { |
| 262 | if (!m_refData) |
| 263 | return wxOutRegion; |
| 264 | |
| 265 | long x, y, w, h; |
| 266 | x = rect.x; |
| 267 | y = rect.y; |
| 268 | w = rect.GetWidth(); |
| 269 | h = rect.GetHeight(); |
| 270 | return Contains(x, y, w, h); |
| 271 | } |
| 272 | |
| 273 | /////////////////////////////////////////////////////////////////////////////// |
| 274 | // // |
| 275 | // wxRegionIterator // |
| 276 | // // |
| 277 | /////////////////////////////////////////////////////////////////////////////// |
| 278 | |
| 279 | /*! |
| 280 | * Initialize empty iterator |
| 281 | */ |
| 282 | wxRegionIterator::wxRegionIterator() : m_current(0), m_numRects(0), m_rects(NULL) |
| 283 | { |
| 284 | } |
| 285 | |
| 286 | wxRegionIterator::~wxRegionIterator() |
| 287 | { |
| 288 | if (m_rects) |
| 289 | delete[] m_rects; |
| 290 | } |
| 291 | |
| 292 | /*! |
| 293 | * Initialize iterator for region |
| 294 | */ |
| 295 | wxRegionIterator::wxRegionIterator(const wxRegion& region) |
| 296 | { |
| 297 | m_rects = NULL; |
| 298 | |
| 299 | Reset(region); |
| 300 | } |
| 301 | |
| 302 | /*! |
| 303 | * Reset iterator for a new /e region. |
| 304 | */ |
| 305 | void wxRegionIterator::Reset(const wxRegion& region) |
| 306 | { |
| 307 | m_current = 0; |
| 308 | m_region = region; |
| 309 | |
| 310 | if (m_rects) |
| 311 | delete[] m_rects; |
| 312 | |
| 313 | m_rects = NULL; |
| 314 | |
| 315 | if (m_region.Empty()) |
| 316 | m_numRects = 0; |
| 317 | else |
| 318 | { |
| 319 | // TODO create m_rects and fill with rectangles for this region |
| 320 | m_numRects = 0; |
| 321 | } |
| 322 | } |
| 323 | |
| 324 | /*! |
| 325 | * Increment iterator. The rectangle returned is the one after the |
| 326 | * incrementation. |
| 327 | */ |
| 328 | void wxRegionIterator::operator ++ () |
| 329 | { |
| 330 | if (m_current < m_numRects) |
| 331 | ++m_current; |
| 332 | } |
| 333 | |
| 334 | /*! |
| 335 | * Increment iterator. The rectangle returned is the one before the |
| 336 | * incrementation. |
| 337 | */ |
| 338 | void wxRegionIterator::operator ++ (int) |
| 339 | { |
| 340 | if (m_current < m_numRects) |
| 341 | ++m_current; |
| 342 | } |
| 343 | |
| 344 | long wxRegionIterator::GetX() const |
| 345 | { |
| 346 | if (m_current < m_numRects) |
| 347 | return m_rects[m_current].x; |
| 348 | return 0; |
| 349 | } |
| 350 | |
| 351 | long wxRegionIterator::GetY() const |
| 352 | { |
| 353 | if (m_current < m_numRects) |
| 354 | return m_rects[m_current].y; |
| 355 | return 0; |
| 356 | } |
| 357 | |
| 358 | long wxRegionIterator::GetW() const |
| 359 | { |
| 360 | if (m_current < m_numRects) |
| 361 | return m_rects[m_current].width ; |
| 362 | return 0; |
| 363 | } |
| 364 | |
| 365 | long wxRegionIterator::GetH() const |
| 366 | { |
| 367 | if (m_current < m_numRects) |
| 368 | return m_rects[m_current].height; |
| 369 | return 0; |
| 370 | } |
| 371 | |