Don't mention wxDCImpl in wxDC documentation This is a private class, we shouldn't advertise its existence.
Make wxDC objects moveable Note that wxReadOnlyDC can't be made moveable easily because it doesn't have an object to use as "owner". This is not really a problem as such objects can't be created anyhow.
Make wxGCDC moveable too and test using its move ctor Modify a test case to use move ctor.
Initialize pointer to null before using it
Initialize character before using it
Merge branch 'moveable-dc' Make wxDC-derived objects moveable. See #25726.
Merge branch 'Warnings' of github.com:Blake-Madden/wxWidgets Suppress clang static analysis warnings about uninitialized variables. See #25730.
... | ... | @@ -164,6 +164,8 @@ public: |
164 | 164 | // wxDCImpl
|
165 | 165 | //-----------------------------------------------------------------------------
|
166 | 166 | |
167 | +// This class is only used by wxDC and wxWidgets itself, do not use it in the
|
|
168 | +// application code.
|
|
167 | 169 | class WXDLLIMPEXP_CORE wxDCImpl: public wxObject
|
168 | 170 | {
|
169 | 171 | public:
|
... | ... | @@ -171,6 +173,7 @@ public: |
171 | 173 | virtual ~wxDCImpl();
|
172 | 174 | |
173 | 175 | wxDC *GetOwner() const { return m_owner; }
|
176 | + void SetOwner(wxDC* owner) { m_owner = owner; }
|
|
174 | 177 | |
175 | 178 | wxWindow* GetWindow() const { return m_window; }
|
176 | 179 | |
... | ... | @@ -919,7 +922,7 @@ protected: |
919 | 922 | {
|
920 | 923 | }
|
921 | 924 | |
922 | - wxDCImpl * const m_pimpl;
|
|
925 | + wxDCImpl *m_pimpl;
|
|
923 | 926 | };
|
924 | 927 | |
925 | 928 | // Full device context class, providing functions for drawing on the device in
|
... | ... | @@ -927,6 +930,37 @@ protected: |
927 | 930 | class WXDLLIMPEXP_CORE wxDC : public wxReadOnlyDC
|
928 | 931 | {
|
929 | 932 | public:
|
933 | + // Device context objects are not copyable but are moveable.
|
|
934 | + wxDC(const wxDC&) = delete;
|
|
935 | + wxDC& operator=(const wxDC&) = delete;
|
|
936 | + |
|
937 | + wxDC(wxDC&& other) noexcept
|
|
938 | + : wxReadOnlyDC(other.m_pimpl)
|
|
939 | + {
|
|
940 | + if ( m_pimpl )
|
|
941 | + {
|
|
942 | + m_pimpl->SetOwner(this);
|
|
943 | + other.m_pimpl = nullptr;
|
|
944 | + }
|
|
945 | + }
|
|
946 | + |
|
947 | + wxDC& operator=(wxDC&& other) noexcept
|
|
948 | + {
|
|
949 | + if ( this != &other )
|
|
950 | + {
|
|
951 | + delete m_pimpl;
|
|
952 | + m_pimpl = other.m_pimpl;
|
|
953 | + if ( m_pimpl )
|
|
954 | + {
|
|
955 | + m_pimpl->SetOwner(this);
|
|
956 | + other.m_pimpl = nullptr;
|
|
957 | + }
|
|
958 | + }
|
|
959 | + |
|
960 | + return *this;
|
|
961 | + }
|
|
962 | + |
|
963 | + |
|
930 | 964 | // copy attributes (font, colours and writing direction) from another DC
|
931 | 965 | void CopyAttributes(const wxDC& dc);
|
932 | 966 | |
... | ... | @@ -1337,7 +1371,6 @@ protected: |
1337 | 1371 | |
1338 | 1372 | private:
|
1339 | 1373 | wxDECLARE_ABSTRACT_CLASS(wxDC);
|
1340 | - wxDECLARE_NO_COPY_CLASS(wxDC);
|
|
1341 | 1374 | };
|
1342 | 1375 | |
1343 | 1376 | // ----------------------------------------------------------------------------
|
... | ... | @@ -35,6 +35,13 @@ public: |
35 | 35 | wxGCDC(wxGraphicsContext* context);
|
36 | 36 | |
37 | 37 | wxGCDC();
|
38 | + |
|
39 | + wxGCDC(const wxGCDC&) = delete;
|
|
40 | + wxGCDC& operator=(const wxGCDC&) = delete;
|
|
41 | + |
|
42 | + wxGCDC(wxGCDC&&) = default;
|
|
43 | + wxGCDC& operator=(wxGCDC&&) = default;
|
|
44 | + |
|
38 | 45 | virtual ~wxGCDC();
|
39 | 46 | |
40 | 47 | #ifdef __WXMSW__
|
... | ... | @@ -46,7 +53,6 @@ public: |
46 | 53 | |
47 | 54 | private:
|
48 | 55 | wxDECLARE_DYNAMIC_CLASS(wxGCDC);
|
49 | - wxDECLARE_NO_COPY_CLASS(wxGCDC);
|
|
50 | 56 | };
|
51 | 57 | |
52 | 58 |
... | ... | @@ -789,12 +789,6 @@ public: |
789 | 789 | of the two wxCoord ones or wxPoint and wxSize instead of the four
|
790 | 790 | wxCoord parameters.
|
791 | 791 | |
792 | - Beginning with wxWidgets 2.9.0 the entire wxDC code has been
|
|
793 | - reorganized. All platform dependent code (actually all drawing code)
|
|
794 | - has been moved into backend classes which derive from a common
|
|
795 | - wxDCImpl class. The user-visible classes such as wxClientDC and
|
|
796 | - wxPaintDC merely forward all calls to the backend implementation.
|
|
797 | - |
|
798 | 792 | In wxWidgets 3.3.0 the new wxReadOnlyDC class was extracted from wxDC: it
|
799 | 793 | contains all the functions that don't actually draw on the device context,
|
800 | 794 | but just return information about it. This class should be rarely used
|
... | ... | @@ -803,6 +797,9 @@ public: |
803 | 797 | and such functions can now also be called with wxInfoDC objects as
|
804 | 798 | arguments.
|
805 | 799 | |
800 | + Although copying wxDC objects is not allowed because it wouldn't make
|
|
801 | + sense, objects of wxDC-derived classes can be moved, in C++ sense, allowing
|
|
802 | + to return them from functions since wxWidgets 3.3.2.
|
|
806 | 803 | |
807 | 804 | @section dc_units Device and logical units
|
808 | 805 |
... | ... | @@ -350,7 +350,7 @@ char wxStreamBuffer::Peek() |
350 | 350 | return 0;
|
351 | 351 | }
|
352 | 352 | |
353 | - char c;
|
|
353 | + char c = 0;
|
|
354 | 354 | GetFromBuffer(&c, sizeof(c));
|
355 | 355 | m_buffer_pos--;
|
356 | 356 | |
... | ... | @@ -363,7 +363,7 @@ char wxStreamBuffer::GetChar() |
363 | 363 | |
364 | 364 | wxCHECK_MSG( inStream, 0, wxT("should have a stream in wxStreamBuffer") );
|
365 | 365 | |
366 | - char c;
|
|
366 | + char c = 0;
|
|
367 | 367 | if ( !HasBuffer() )
|
368 | 368 | {
|
369 | 369 | inStream->OnSysRead(&c, sizeof(c));
|
... | ... | @@ -1494,7 +1494,7 @@ ToNumeric(T* pVal, |
1494 | 1494 | PreserveErrno preserveErrno;
|
1495 | 1495 | errno = 0;
|
1496 | 1496 | |
1497 | - wxStringCharType *end;
|
|
1497 | + wxStringCharType *end = nullptr;
|
|
1498 | 1498 | |
1499 | 1499 | const R res = convert(start, &end, base);
|
1500 | 1500 | if ( rangeCheck && !rangeCheck(res) )
|
... | ... | @@ -34,26 +34,25 @@ public: |
34 | 34 | {
|
35 | 35 | m_bmp.Create(100, 100);
|
36 | 36 | m_dc.SelectObject(m_bmp);
|
37 | - m_gcdc = new wxGCDC(m_dc);
|
|
37 | + m_gcdc = wxGCDC(m_dc);
|
|
38 | 38 | }
|
39 | 39 | |
40 | 40 | ~GCDCBoundingBoxTestCase()
|
41 | 41 | {
|
42 | - delete m_gcdc;
|
|
43 | 42 | m_dc.SelectObject(wxNullBitmap);
|
44 | 43 | m_bmp = wxNullBitmap;
|
45 | 44 | }
|
46 | 45 | |
47 | 46 | virtual void setUp() override
|
48 | 47 | {
|
49 | - m_gcdc->ResetBoundingBox();
|
|
48 | + m_gcdc.ResetBoundingBox();
|
|
50 | 49 | }
|
51 | 50 | |
52 | 51 | private:
|
53 | 52 | wxBitmap m_bmp;
|
54 | 53 | wxMemoryDC m_dc;
|
55 | 54 | |
56 | - wxGCDC *m_gcdc;
|
|
55 | + wxGCDC m_gcdc;
|
|
57 | 56 | |
58 | 57 | void AssertBox(int minX, int minY, int width, int height, int margin = 0)
|
59 | 58 | {
|
... | ... | @@ -68,19 +67,19 @@ private: |
68 | 67 | WX_ASSERT_MESSAGE(("%d != %d", actual, expected), \
|
69 | 68 | abs(actual - expected) <= delta)
|
70 | 69 | |
71 | - WX_ASSERT_CLOSE(minX, m_gcdc->MinX(), margin);
|
|
72 | - WX_ASSERT_CLOSE(minY, m_gcdc->MinY(), margin);
|
|
73 | - WX_ASSERT_CLOSE(maxX, m_gcdc->MaxX(), margin);
|
|
74 | - WX_ASSERT_CLOSE(maxY, m_gcdc->MaxY(), margin);
|
|
70 | + WX_ASSERT_CLOSE(minX, m_gcdc.MinX(), margin);
|
|
71 | + WX_ASSERT_CLOSE(minY, m_gcdc.MinY(), margin);
|
|
72 | + WX_ASSERT_CLOSE(maxX, m_gcdc.MaxX(), margin);
|
|
73 | + WX_ASSERT_CLOSE(maxY, m_gcdc.MaxY(), margin);
|
|
75 | 74 | |
76 | 75 | #undef WX_ASSERT_CLOSE
|
77 | 76 | }
|
78 | 77 | else
|
79 | 78 | {
|
80 | - CPPUNIT_ASSERT_EQUAL(minX, m_gcdc->MinX());
|
|
81 | - CPPUNIT_ASSERT_EQUAL(minY, m_gcdc->MinY());
|
|
82 | - CPPUNIT_ASSERT_EQUAL(maxX, m_gcdc->MaxX());
|
|
83 | - CPPUNIT_ASSERT_EQUAL(maxY, m_gcdc->MaxY());
|
|
79 | + CPPUNIT_ASSERT_EQUAL(minX, m_gcdc.MinX());
|
|
80 | + CPPUNIT_ASSERT_EQUAL(minY, m_gcdc.MinY());
|
|
81 | + CPPUNIT_ASSERT_EQUAL(maxX, m_gcdc.MaxX());
|
|
82 | + CPPUNIT_ASSERT_EQUAL(maxY, m_gcdc.MaxY());
|
|
84 | 83 | }
|
85 | 84 | }
|
86 | 85 | |
... | ... | @@ -155,7 +154,7 @@ void GCDCBoundingBoxTestCase::DrawBitmap() |
155 | 154 | wxBitmap bitmap;
|
156 | 155 | bitmap.Create(12, 12);
|
157 | 156 | |
158 | - m_gcdc->DrawBitmap(bitmap, 5, 5);
|
|
157 | + m_gcdc.DrawBitmap(bitmap, 5, 5);
|
|
159 | 158 | AssertBox(5, 5, 12, 12);
|
160 | 159 | }
|
161 | 160 | |
... | ... | @@ -166,40 +165,40 @@ void GCDCBoundingBoxTestCase::DrawIcon() |
166 | 165 | wxIcon icon;
|
167 | 166 | icon.CopyFromBitmap(bitmap);
|
168 | 167 | |
169 | - m_gcdc->DrawIcon(icon, 42, 42);
|
|
168 | + m_gcdc.DrawIcon(icon, 42, 42);
|
|
170 | 169 | AssertBox(42, 42, 16, 16);
|
171 | 170 | }
|
172 | 171 | |
173 | 172 | void GCDCBoundingBoxTestCase::DrawLine()
|
174 | 173 | {
|
175 | - m_gcdc->DrawLine(10, 10, 20, 15);
|
|
174 | + m_gcdc.DrawLine(10, 10, 20, 15);
|
|
176 | 175 | AssertBox(10, 10, 10, 5);
|
177 | 176 | }
|
178 | 177 | |
179 | 178 | void GCDCBoundingBoxTestCase::CrossHair()
|
180 | 179 | {
|
181 | 180 | int w, h;
|
182 | - m_gcdc->GetSize(&w, &h);
|
|
181 | + m_gcdc.GetSize(&w, &h);
|
|
183 | 182 | |
184 | - m_gcdc->CrossHair(33, 33);
|
|
183 | + m_gcdc.CrossHair(33, 33);
|
|
185 | 184 | AssertBox(0, 0, w, h);
|
186 | 185 | }
|
187 | 186 | |
188 | 187 | void GCDCBoundingBoxTestCase::DrawArc()
|
189 | 188 | {
|
190 | - m_gcdc->DrawArc(25, 30, 15, 40, 25, 40); // quarter circle
|
|
189 | + m_gcdc.DrawArc(25, 30, 15, 40, 25, 40); // quarter circle
|
|
191 | 190 | AssertBox(15, 30, 10, 10, 3);
|
192 | 191 | }
|
193 | 192 | |
194 | 193 | void GCDCBoundingBoxTestCase::DrawEllipticArc()
|
195 | 194 | {
|
196 | - m_gcdc->DrawEllipticArc(40, 50, 30, 20, 0, 180); // half circle
|
|
195 | + m_gcdc.DrawEllipticArc(40, 50, 30, 20, 0, 180); // half circle
|
|
197 | 196 | AssertBox(40, 50, 30, 10, 3);
|
198 | 197 | }
|
199 | 198 | |
200 | 199 | void GCDCBoundingBoxTestCase::DrawPoint()
|
201 | 200 | {
|
202 | - m_gcdc->DrawPoint(20, 20);
|
|
201 | + m_gcdc.DrawPoint(20, 20);
|
|
203 | 202 | AssertBox(20, 20, 0, 0);
|
204 | 203 | }
|
205 | 204 | |
... | ... | @@ -211,7 +210,7 @@ void GCDCBoundingBoxTestCase::DrawLines() |
211 | 210 | points[2] = wxPoint(30, 20);
|
212 | 211 | points[3] = wxPoint(20, 30);
|
213 | 212 | |
214 | - m_gcdc->DrawLines(4, points, 7, 8);
|
|
213 | + m_gcdc.DrawLines(4, points, 7, 8);
|
|
215 | 214 | AssertBox(17, 18, 20, 20);
|
216 | 215 | }
|
217 | 216 | |
... | ... | @@ -223,7 +222,7 @@ void GCDCBoundingBoxTestCase::DrawSpline() |
223 | 222 | points[1] = wxPoint(20, 20);
|
224 | 223 | points[2] = wxPoint(40, 50);
|
225 | 224 | |
226 | - m_gcdc->DrawSpline(3, points);
|
|
225 | + m_gcdc.DrawSpline(3, points);
|
|
227 | 226 | AssertBox(10, 20, 30, 30, 5);
|
228 | 227 | }
|
229 | 228 | #endif // wxUSE_SPLINES
|
... | ... | @@ -235,7 +234,7 @@ void GCDCBoundingBoxTestCase::DrawPolygon() |
235 | 234 | points[1] = wxPoint(20, 10);
|
236 | 235 | points[2] = wxPoint(30, 30);
|
237 | 236 | |
238 | - m_gcdc->DrawPolygon(3, points, -5, -7);
|
|
237 | + m_gcdc.DrawPolygon(3, points, -5, -7);
|
|
239 | 238 | AssertBox(5, 3, 20, 20);
|
240 | 239 | }
|
241 | 240 | |
... | ... | @@ -252,25 +251,25 @@ void GCDCBoundingBoxTestCase::DrawPolyPolygon() |
252 | 251 | points[4] = wxPoint(30, 40);
|
253 | 252 | points[5] = wxPoint(40, 60);
|
254 | 253 | |
255 | - m_gcdc->DrawPolyPolygon(2, lenghts, points, 12, 5);
|
|
254 | + m_gcdc.DrawPolyPolygon(2, lenghts, points, 12, 5);
|
|
256 | 255 | AssertBox(22, 15, 30, 50, 4);
|
257 | 256 | }
|
258 | 257 | |
259 | 258 | void GCDCBoundingBoxTestCase::DrawRectangle()
|
260 | 259 | {
|
261 | - m_gcdc->DrawRectangle(2, 2, 12, 12);
|
|
260 | + m_gcdc.DrawRectangle(2, 2, 12, 12);
|
|
262 | 261 | AssertBox(2, 2, 12, 12);
|
263 | 262 | }
|
264 | 263 | |
265 | 264 | void GCDCBoundingBoxTestCase::DrawRoundedRectangle()
|
266 | 265 | {
|
267 | - m_gcdc->DrawRoundedRectangle(27, 27, 12, 12, 2);
|
|
266 | + m_gcdc.DrawRoundedRectangle(27, 27, 12, 12, 2);
|
|
268 | 267 | AssertBox(27, 27, 12, 12);
|
269 | 268 | }
|
270 | 269 | |
271 | 270 | void GCDCBoundingBoxTestCase::DrawEllipse()
|
272 | 271 | {
|
273 | - m_gcdc->DrawEllipse(54, 45, 23, 12);
|
|
272 | + m_gcdc.DrawEllipse(54, 45, 23, 12);
|
|
274 | 273 | AssertBox(54, 45, 23, 12);
|
275 | 274 | }
|
276 | 275 | |
... | ... | @@ -280,7 +279,7 @@ void GCDCBoundingBoxTestCase::Blit() |
280 | 279 | bitmap.Create(20, 20);
|
281 | 280 | wxMemoryDC dc(bitmap);
|
282 | 281 | |
283 | - m_gcdc->Blit(20, 10, 12, 7, &dc, 0, 0);
|
|
282 | + m_gcdc.Blit(20, 10, 12, 7, &dc, 0, 0);
|
|
284 | 283 | AssertBox(20, 10, 12, 7);
|
285 | 284 | |
286 | 285 | dc.SelectObject(wxNullBitmap);
|
... | ... | @@ -292,7 +291,7 @@ void GCDCBoundingBoxTestCase::StretchBlit() |
292 | 291 | bitmap.Create(20, 20);
|
293 | 292 | wxMemoryDC dc(bitmap);
|
294 | 293 | |
295 | - m_gcdc->StretchBlit(30, 50, 5, 5, &dc, 0, 0, 12, 4);
|
|
294 | + m_gcdc.StretchBlit(30, 50, 5, 5, &dc, 0, 0, 12, 4);
|
|
296 | 295 | AssertBox(30, 50, 5, 5);
|
297 | 296 | |
298 | 297 | dc.SelectObject(wxNullBitmap);
|
... | ... | @@ -302,9 +301,9 @@ void GCDCBoundingBoxTestCase::DrawRotatedText() |
302 | 301 | {
|
303 | 302 | wxString text("vertical");
|
304 | 303 | wxCoord w, h;
|
305 | - m_gcdc->GetTextExtent(text, &w, &h);
|
|
304 | + m_gcdc.GetTextExtent(text, &w, &h);
|
|
306 | 305 | |
307 | - m_gcdc->DrawRotatedText(text, 43, 22, -90);
|
|
306 | + m_gcdc.DrawRotatedText(text, 43, 22, -90);
|
|
308 | 307 | AssertBox(43 - h, 22, h, w, 3);
|
309 | 308 | }
|
310 | 309 | |
... | ... | @@ -312,52 +311,52 @@ void GCDCBoundingBoxTestCase::DrawText() |
312 | 311 | {
|
313 | 312 | wxString text("H");
|
314 | 313 | wxCoord w, h;
|
315 | - m_gcdc->GetTextExtent(text, &w, &h);
|
|
314 | + m_gcdc.GetTextExtent(text, &w, &h);
|
|
316 | 315 | |
317 | - m_gcdc->DrawText(text, 3, 3);
|
|
316 | + m_gcdc.DrawText(text, 3, 3);
|
|
318 | 317 | AssertBox(3, 3, w, h, 3);
|
319 | 318 | }
|
320 | 319 | |
321 | 320 | void GCDCBoundingBoxTestCase::GradientFillLinear()
|
322 | 321 | {
|
323 | 322 | wxRect rect(16, 16, 30, 40);
|
324 | - m_gcdc->GradientFillLinear(rect, *wxWHITE, *wxBLACK, wxNORTH);
|
|
323 | + m_gcdc.GradientFillLinear(rect, *wxWHITE, *wxBLACK, wxNORTH);
|
|
325 | 324 | AssertBox(16, 16, 30, 40);
|
326 | 325 | }
|
327 | 326 | |
328 | 327 | void GCDCBoundingBoxTestCase::GradientFillConcentric()
|
329 | 328 | {
|
330 | 329 | wxRect rect(6, 6, 30, 40);
|
331 | - m_gcdc->GradientFillConcentric(rect, *wxWHITE, *wxBLACK, wxPoint(10, 10));
|
|
330 | + m_gcdc.GradientFillConcentric(rect, *wxWHITE, *wxBLACK, wxPoint(10, 10));
|
|
332 | 331 | AssertBox(6, 6, 30, 40);
|
333 | 332 | }
|
334 | 333 | |
335 | 334 | void GCDCBoundingBoxTestCase::DrawCheckMark()
|
336 | 335 | {
|
337 | - m_gcdc->DrawCheckMark(32, 24, 16, 16);
|
|
336 | + m_gcdc.DrawCheckMark(32, 24, 16, 16);
|
|
338 | 337 | AssertBox(32, 24, 16, 16);
|
339 | 338 | }
|
340 | 339 | |
341 | 340 | void GCDCBoundingBoxTestCase::DrawRectangleAndReset()
|
342 | 341 | {
|
343 | - m_gcdc->DrawRectangle(2, 2, 12, 12);
|
|
344 | - m_gcdc->ResetBoundingBox();
|
|
342 | + m_gcdc.DrawRectangle(2, 2, 12, 12);
|
|
343 | + m_gcdc.ResetBoundingBox();
|
|
345 | 344 | AssertBox(0, 0, 0, 0);
|
346 | 345 | }
|
347 | 346 | |
348 | 347 | void GCDCBoundingBoxTestCase::DrawTwoRectangles()
|
349 | 348 | {
|
350 | - m_gcdc->DrawRectangle(10, 15, 50, 30);
|
|
351 | - m_gcdc->DrawRectangle(15, 20, 55, 35);
|
|
349 | + m_gcdc.DrawRectangle(10, 15, 50, 30);
|
|
350 | + m_gcdc.DrawRectangle(15, 20, 55, 35);
|
|
352 | 351 | AssertBox(10, 15, 60, 40);
|
353 | 352 | }
|
354 | 353 | |
355 | 354 | void GCDCBoundingBoxTestCase::DrawRectsOnTransformedDC()
|
356 | 355 | {
|
357 | - m_gcdc->DrawRectangle(10, 15, 50, 30);
|
|
358 | - m_gcdc->SetDeviceOrigin(15, 20);
|
|
359 | - m_gcdc->DrawRectangle(15, 20, 45, 35);
|
|
360 | - m_gcdc->SetDeviceOrigin(5, 10);
|
|
356 | + m_gcdc.DrawRectangle(10, 15, 50, 30);
|
|
357 | + m_gcdc.SetDeviceOrigin(15, 20);
|
|
358 | + m_gcdc.DrawRectangle(15, 20, 45, 35);
|
|
359 | + m_gcdc.SetDeviceOrigin(5, 10);
|
|
361 | 360 | AssertBox(5, 5, 65, 60);
|
362 | 361 | }
|
363 | 362 |
—
View it on GitLab.
You're receiving this email because of your account on gitlab.com. Manage all notifications · Help