-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Expand file tree
/
Copy pathwxwidgets.cpp
More file actions
652 lines (584 loc) · 17.6 KB
/
wxwidgets.cpp
File metadata and controls
652 lines (584 loc) · 17.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
// Test library configuration for wxwidgets.cfg
//
// Usage:
// $ ./cppcheck --check-library --library=wxwidgets --enable=style,information --inconclusive --error-exitcode=1 --disable=missingInclude --inline-suppr test/cfg/wxwidgets.cpp
// =>
// No warnings about bad library configuration, unmatched suppressions, etc. exitcode=0
//
#include <wx/wx.h>
#include <wx/accel.h>
#include <wx/app.h>
#include <wx/dc.h>
#include <wx/log.h>
#include <wx/filefn.h>
#include <wx/geometry.h>
#include <wx/spinctrl.h>
#include <wx/artprov.h>
#include <wx/calctrl.h>
#include <wx/combo.h>
#include <wx/icon.h>
#include <wx/bitmap.h>
#include <wx/dataview.h>
#include <wx/datetime.h>
#include <wx/memory.h>
#include <wx/frame.h>
#include <wx/menu.h>
#include <wx/mimetype.h>
#include <wx/regex.h>
#include <wx/region.h>
#include <wx/stattext.h>
#include <wx/sizer.h>
#include <wx/string.h>
#include <wx/textctrl.h>
#include <wx/gdicmn.h>
#include <wx/propgrid/property.h>
#include <wx/position.h>
#include <wx/versioninfo.h>
void unreadVariable_wxPoint2DInt(const wxInt32 x, const wxPoint2DInt& pti, const wxPoint &pt)
{
// cppcheck-suppress unusedVariable
wxPoint2DInt a;
// cppcheck-suppress unreadVariable
wxPoint2DInt b(x, x);
// cppcheck-suppress unreadVariable
wxPoint2DInt c(pti);
// cppcheck-suppress unreadVariable
wxPoint2DInt d(pt);
}
void unreadVariable_wxPoint2DDouble(const wxDouble x, const wxPoint2DDouble& ptd, const wxPoint2DInt& pti, const wxPoint &pt)
{
// cppcheck-suppress unusedVariable
wxPoint2DDouble a;
// cppcheck-suppress unreadVariable
wxPoint2DDouble b(x, x);
// cppcheck-suppress unreadVariable
wxPoint2DDouble c(ptd);
// cppcheck-suppress unreadVariable
wxPoint2DDouble d(pti);
// cppcheck-suppress unreadVariable
wxPoint2DDouble e(pt);
}
void unusedVariable_wxAcceleratorEntry()
{
// cppcheck-suppress unusedVariable
wxAcceleratorEntry a;
}
void unreadVariable_wxDateSpan(const int x)
{
// cppcheck-suppress unusedVariable
wxDateSpan a;
// cppcheck-suppress unreadVariable
wxDateSpan b{x};
// cppcheck-suppress unreadVariable
wxDateSpan c{x, x};
// cppcheck-suppress unreadVariable
wxDateSpan d{x, x, x};
// cppcheck-suppress unreadVariable
wxDateSpan e{x, x, x, x};
}
void unreadVariable_wxTimeSpan(const long x, const wxLongLong y)
{
// cppcheck-suppress unusedVariable
wxTimeSpan a;
// TODO cppcheck-suppress unreadVariable
wxTimeSpan b{};
// cppcheck-suppress unreadVariable
wxTimeSpan c{x};
// cppcheck-suppress unreadVariable
wxTimeSpan d{x, x};
// cppcheck-suppress unreadVariable
wxTimeSpan e{x, x, y};
// cppcheck-suppress unreadVariable
wxTimeSpan f{x, x, y, y};
}
void unreadVariable_wxFileType(const wxFileTypeInfo &info)
{
// cppcheck-suppress unreadVariable
wxFileType a(info);
}
void unreadVariable_wxPosition(const int x)
{
// cppcheck-suppress unusedVariable
wxPosition a;
// TODO cppcheck-suppress unreadVariable
wxPosition b{};
// cppcheck-suppress unreadVariable
wxPosition c{x,x};
}
void unreadVariable_wxRegEx(const wxString &expr, const int flags)
{
// cppcheck-suppress unusedVariable
wxRegEx a;
// cppcheck-suppress unreadVariable
wxRegEx b{expr};
// cppcheck-suppress unreadVariable
wxRegEx c{expr, flags};
}
void unreadVariable_wxRegion(const wxCoord x, const wxPoint &pt, const wxRect &rect, const wxRegion ®ion, const wxBitmap &bmp)
{
// cppcheck-suppress unusedVariable
wxRegion a;
// TODO cppcheck-suppress unreadVariable
wxRegion b{};
// cppcheck-suppress unreadVariable
wxRegion c{x,x,x,x};
// cppcheck-suppress unreadVariable
wxRegion d{pt,pt};
// cppcheck-suppress unreadVariable
wxRegion e{rect};
// cppcheck-suppress unreadVariable
wxRegion f{region};
// cppcheck-suppress unreadVariable
wxRegion g{bmp};
}
void unreadVariable_wxVersionInfo(const wxString &name, const int major, const int minor, const int micro, const wxString &description, const wxString ©right)
{
// cppcheck-suppress unusedVariable
wxVersionInfo a;
// cppcheck-suppress unreadVariable
wxVersionInfo b(name);
// cppcheck-suppress unreadVariable
wxVersionInfo c(name, major);
// cppcheck-suppress unreadVariable
wxVersionInfo d(name, major, minor);
// cppcheck-suppress unreadVariable
wxVersionInfo e(name, major, minor, micro);
// cppcheck-suppress unreadVariable
wxVersionInfo f(name, major, minor, micro, description);
// cppcheck-suppress unreadVariable
wxVersionInfo g(name, major, minor, micro, description, copyright);
}
void unreadVariable_wxSize(const wxSize &s)
{
// cppcheck-suppress unusedVariable
wxSize a;
// TODO cppcheck-suppress unreadVariable
wxSize b{};
// cppcheck-suppress unreadVariable
wxSize c{4, 2};
// cppcheck-suppress unreadVariable
wxSize d(4, 2);
// cppcheck-suppress unreadVariable
wxSize e(s);
}
void unreadVariable_wxPoint(const wxRealPoint &rp, const int x, const int y)
{
// cppcheck-suppress unusedVariable
wxPoint a;
// TODO cppcheck-suppress unreadVariable
wxPoint b{};
// cppcheck-suppress unreadVariable
wxPoint c{4, 2};
// cppcheck-suppress unreadVariable
wxPoint d(4, 2);
// cppcheck-suppress unreadVariable
wxPoint e{x, 2};
// cppcheck-suppress unreadVariable
wxPoint f(4, y);
// cppcheck-suppress unreadVariable
wxPoint g(rp);
}
void unreadVariable_wxRealPoint(const wxPoint &pt, const double x, const double y)
{
// cppcheck-suppress unusedVariable
wxRealPoint a;
// TODO cppcheck-suppress unreadVariable
wxRealPoint b{};
// cppcheck-suppress unreadVariable
wxRealPoint c{4.0, 2.0};
// cppcheck-suppress unreadVariable
wxRealPoint d(4.0, 2.0);
// cppcheck-suppress unreadVariable
wxRealPoint e{x, 2.0};
// cppcheck-suppress unreadVariable
wxRealPoint f(4.0, y);
// cppcheck-suppress unreadVariable
wxRealPoint g(pt);
}
void unreadVariable_wxRect(const int x, const wxPoint &pt, const wxSize &sz)
{
// cppcheck-suppress unusedVariable
wxRect a;
// TODO cppcheck-suppress unreadVariable
wxRect b{};
// cppcheck-suppress unreadVariable
wxRect c{x,x,x,x};
// cppcheck-suppress unreadVariable
wxRect d{pt,sz};
// cppcheck-suppress unreadVariable
wxRect e{sz};
// cppcheck-suppress unreadVariable
wxRect f(x,x,x,x);
// cppcheck-suppress unreadVariable
wxRect g(pt,sz);
// cppcheck-suppress unreadVariable
wxRect h(sz);
}
void uninitvar_wxRegEx_GetMatch(const wxRegEx &obj, size_t *start, size_t *len, size_t index)
{
size_t s,l;
size_t *sPtr,*lPtr;
// cppcheck-suppress uninitvar
(void)obj.GetMatch(&s,lPtr);
// TODO cppcheck-suppress uninitvar
(void)obj.GetMatch(sPtr,&l);
(void)obj.GetMatch(&s,&l);
(void)obj.GetMatch(start,len);
(void)obj.GetMatch(start,len,0);
(void)obj.GetMatch(start,len,index);
}
#ifdef __VISUALC__
// Ensure no duplicateBreak warning is issued after wxLogApiError() calls.
// This function does not terminate execution.
bool duplicateBreak_wxLogApiError(const wxString &msg, const HRESULT &hr, wxString &str)
{
if (hr) {
wxLogApiError(msg,hr);
str = "fail";
return false;
}
return true;
}
#endif
void argDirection_wxString_ToDouble(const wxString &str)
{
// No warning is expected. Ensure both arguments are treated
// as output by library configuration
double value;
const bool convOk = str.ToDouble(&value);
if (convOk && value <= 42.0) {}
}
void argDirection_wxString_ToCDouble(const wxString &str)
{
// No warning is expected. Ensure both arguments are treated
// as output by library configuration
double value;
const bool convOk = str.ToCDouble(&value);
if (convOk && value <= 42.0) {}
}
void argDirection_wxTextCtrl_GetSelection(const wxTextCtrl *const textCtrl)
{
// No warning is expected. Ensure both arguments are treated
// as output by library configuration
long start;
long end;
textCtrl->GetSelection(&start, &end);
if (start > 0 && end > 0) {}
}
void useRetval_wxString_MakeCapitalized(wxString &str)
{
// No warning is expected for
str.MakeCapitalized();
}
void useRetval_wxString_MakeLower(wxString &str)
{
// No warning is expected for
str.MakeLower();
}
void useRetval_wxString_MakeUpper(wxString &str)
{
// No warning is expected for
str.MakeUpper();
}
wxString containerOutOfBounds_wxArrayString(void)
{
wxArrayString a;
a.Add("42");
a.Clear();
// TODO: wxArrayString is defined to be a vector
// TODO: cppcheck-suppress containerOutOfBounds
return a[0];
}
int containerOutOfBounds_wxArrayInt(void)
{
wxArrayInt a;
a.Add(42);
a.Clear();
// TODO: wxArrayString is defined to be a vector
// TODO: cppcheck-suppress containerOutOfBounds
return a[0];
}
void ignoredReturnValue_wxDC_GetSize(const wxDC &dc, wxCoord *width, wxCoord *height)
{
// No warning is expected for
dc.GetSize(width, height);
// No warning is expected for
(void)dc.GetSize();
}
void ignoredReturnValue_wxDC_GetSizeMM(const wxDC &dc, wxCoord *width, wxCoord *height)
{
// No warning is expected for
dc.GetSizeMM(width, height);
// Now warning is expected for
(void)dc.GetSizeMM();
}
wxSizerItem* invalidFunctionArgBool_wxSizer_Add(wxSizer *sizer, wxWindow * window, const wxSizerFlags &flags)
{
// No warning is expected for
return sizer->Add(window,flags);
}
bool invalidFunctionArgBool_wxPGProperty_Hide(wxPGProperty *pg, bool hide, int flags)
{
// cppcheck-suppress invalidFunctionArgBool
(void)pg->Hide(hide, true);
// No warning is expected for
return pg->Hide(hide, flags);
}
wxTextCtrlHitTestResult nullPointer_wxTextCtrl_HitTest(const wxTextCtrl& txtCtrl, const wxPoint& pos)
{
// no nullPointer-warning is expected
return txtCtrl.HitTest(pos, NULL);
}
void validCode()
{
wxString str = wxGetCwd();
(void)str;
wxLogGeneric(wxLOG_Message, "test %d", 0);
wxLogMessage("test %s", "str");
wxString translation1 = _("text");
wxString translation2 = wxGetTranslation("text");
wxString translation3 = wxGetTranslation("string", "domain");
(void)translation1;
(void)translation2;
(void)translation3;
}
#if wxUSE_GUI==1
void validGuiCode()
{
#if wxUSE_SPINCTRL==1
extern wxSpinCtrl spinCtrlInstance;
spinCtrlInstance.SetBase(10);
spinCtrlInstance.SetBase(16);
#endif
}
#endif
void nullPointer(const wxString &str)
{
// cppcheck-suppress nullPointer
wxLogGeneric(wxLOG_Message, (char*)NULL);
// cppcheck-suppress nullPointer
wxLogMessage((char*)NULL);
double *doublePtr = NULL;
// cppcheck-suppress nullPointer
(void)str.ToDouble(doublePtr);
double *doublePtr1 = NULL;
// cppcheck-suppress nullPointer
(void)str.ToCDouble(doublePtr1);
long * longPtr = NULL;
// cppcheck-suppress nullPointer
(void)str.ToLong(longPtr);
long * longPtr1 = NULL;
// cppcheck-suppress nullPointer
(void)str.ToCLong(longPtr1);
unsigned long * ulongPtr = NULL;
// cppcheck-suppress nullPointer
(void)str.ToULong(ulongPtr);
unsigned long * ulongPtr1 = NULL;
// cppcheck-suppress nullPointer
(void)str.ToCULong(ulongPtr1);
long long * longLongPtr = NULL;
// cppcheck-suppress nullPointer
(void)str.ToLongLong(longLongPtr);
unsigned long long * ulongLongPtr = NULL;
// cppcheck-suppress nullPointer
(void)str.ToULongLong(ulongLongPtr);
}
void nullPointer_wxSizer_Add(wxSizer &sizer, wxWindow *w)
{
wxWindow * const ptr = 0;
// @todo cppcheck-suppress nullPointer
sizer.Add(ptr);
// No warning shall be issued for
sizer.Add(w);
}
void uninitvar_wxSizer_Add(wxSizer &sizer, wxWindow *w,wxObject* userData)
{
int uninit1, uninit2, uninit3;
// cppcheck-suppress uninitvar
sizer.Add(w,uninit1);
// cppcheck-suppress uninitvar
sizer.Add(w,4,uninit2);
// cppcheck-suppress uninitvar
sizer.Add(w,4,2,uninit3,userData);
}
void ignoredReturnValue(const wxString &s)
{
// cppcheck-suppress ignoredReturnValue
wxGetCwd();
// cppcheck-suppress ignoredReturnValue
wxAtoi(s);
// cppcheck-suppress ignoredReturnValue
wxAtol(s);
// cppcheck-suppress ignoredReturnValue
wxAtof(s);
}
void invalidFunctionArg(const wxString &str)
{
#if wxUSE_SPINCTRL==1
extern wxSpinCtrl spinCtrlInstance;
// cppcheck-suppress invalidFunctionArg
spinCtrlInstance.SetBase(0);
// cppcheck-suppress invalidFunctionArg
spinCtrlInstance.SetBase(5);
#endif
long l;
// cppcheck-suppress invalidFunctionArg
(void)str.ToLong(&l, -1);
// cppcheck-suppress invalidFunctionArg
(void)str.ToLong(&l, 1);
// cppcheck-suppress invalidFunctionArg
(void)str.ToLong(&l, 37);
}
void uninitvar(wxWindow &w)
{
wxLogLevel logLevelUninit;
// cppcheck-suppress constVariable
char cBufUninit[10];
const char *pcUninit;
bool uninitBool;
// cppcheck-suppress uninitvar
wxLogGeneric(logLevelUninit, "test");
// cppcheck-suppress uninitvar
wxLogMessage(cBufUninit);
// cppcheck-suppress uninitvar
wxLogMessage(pcUninit);
// cppcheck-suppress uninitvar
w.Close(uninitBool);
}
void uninitvar_wxStaticText(wxStaticText &s)
{
// no warning
s.Wrap(-1);
int uninitInt;
// cppcheck-suppress uninitvar
s.Wrap(uninitInt);
}
void uninitvar_wxString_NumberConversion(const wxString &str, const int numberBase)
{
int uninitInteger1;
int uninitInteger2;
int uninitInteger3;
int uninitInteger4;
int uninitInteger5;
int uninitInteger6;
long l;
long long ll;
unsigned long ul;
unsigned long long ull;
// cppcheck-suppress uninitvar
(void)str.ToLong(&l, uninitInteger1);
// cppcheck-suppress uninitvar
(void)str.ToLongLong(&ll, uninitInteger2);
// cppcheck-suppress uninitvar
(void)str.ToULong(&ul, uninitInteger3);
// cppcheck-suppress uninitvar
(void)str.ToULongLong(&ull, uninitInteger4);
// cppcheck-suppress uninitvar
(void)str.ToCLong(&l, uninitInteger5);
// cppcheck-suppress uninitvar
(void)str.ToCULong(&ul, uninitInteger6);
}
void uninitvar_SetMenuBar(wxFrame * const framePtr, wxMenuBar * const menuBarPtr)
{
wxMenuBar *menuBar;
// cppcheck-suppress uninitvar
framePtr->SetMenuBar(menuBar);
framePtr->SetMenuBar(menuBarPtr);
}
void uninitvar_wxMenuBarAppend(wxMenuBar * const menuBarPtr, wxMenu * const menuPtr, const wxString &title)
{
wxMenu *menu;
// cppcheck-suppress uninitvar
menuBarPtr->Append(menu, title);
menuBarPtr->Append(menuPtr, title);
}
void deprecatedFunctions_wxDataViewCustomRenderer(wxDataViewCustomRenderer &dataViewCustomRenderer, wxPoint cursor, wxRect cell, wxDataViewModel *model, const wxDataViewItem &item, unsigned int col)
{
// cppcheck-suppress ActivateCalled
dataViewCustomRenderer.Activate(cell, model, item, col);
// cppcheck-suppress LeftClickCalled
dataViewCustomRenderer.LeftClick(cursor, cell, model, item, col);
}
void deprecatedFunctions([[maybe_unused]] wxApp &a,
const wxString &s,
[[maybe_unused]] wxArtProvider *artProvider,
[[maybe_unused]] wxCalendarCtrl &calenderCtrl,
wxComboCtrl &comboCtrl,
wxChar * path)
{
#ifdef __WXOSX__
// cppcheck-suppress MacOpenFileCalled
a.MacOpenFile(s);
#endif
#if wxCHECK_VERSION(3, 1, 0) // wxWidets-3.1.0 or higher:
// Some functions are not available anymore in newer versions
// @todo cppcheck-suppress ShowPopupCalled
comboCtrl.ShowPopup();
#else
// cppcheck-suppress InsertCalled
wxArtProvider::Insert(artProvider);
// cppcheck-suppress GetTextIndentCalled
// cppcheck-suppress ignoredReturnValue
comboCtrl.GetTextIndent();
// cppcheck-suppress HidePopupCalled
comboCtrl.HidePopup(true);
// cppcheck-suppress HidePopupCalled
comboCtrl.HidePopup(false);
// cppcheck-suppress HidePopupCalled
comboCtrl.HidePopup(/*default=false*/);
// cppcheck-suppress SetTextIndentCalled
comboCtrl.SetTextIndent(0);
#if wxUSE_DEBUG_CONTEXT==1
// cppcheck-suppress GetLevelCalled
// cppcheck-suppress ignoredReturnValue
wxDebugContext::GetLevel();
// cppcheck-suppress SetLevelCalled
wxDebugContext::SetLevel(42);
#endif
// cppcheck-suppress wxDos2UnixFilenameCalled
wxDos2UnixFilename(path);
// cppcheck-suppress wxFileNameFromPathCalled
// cppcheck-suppress ignoredReturnValue
wxFileNameFromPath(wxT_2("../test.c"));
#endif
#if defined(__WXMSW__) || defined(__WXGTK__)
// EnableYearChange() is not available on these GUI systems
#else
// cppcheck-suppress EnableYearChangeCalled
calenderCtrl.EnableYearChange(false);
// cppcheck-suppress EnableYearChangeCalled
calenderCtrl.EnableYearChange(true);
// cppcheck-suppress EnableYearChangeCalled
calenderCtrl.EnableYearChange(/*default=yes*/);
#endif
}
void wxString_test1(wxString s)
{
for (int i = 0; i <= s.size(); ++i) {
// cppcheck-suppress stlOutOfBounds
s[i] = 'x';
}
}
void wxString_test2()
{
wxString s;
// cppcheck-suppress containerOutOfBounds
s[1] = 'a';
s.append("abc");
s[1] = 'B';
printf("%s", static_cast<const char*>(s.c_str()));
wxPrintf("%s", s);
wxPrintf("%s", s.c_str());
s.Clear();
}
wxString::iterator wxString_test3()
{
wxString wxString1;
wxString wxString2;
// cppcheck-suppress mismatchingContainers
for (wxString::iterator it = wxString1.begin(); it != wxString2.end(); ++it)
{}
wxString::iterator it = wxString1.begin();
// cppcheck-suppress returnDanglingLifetime
return it;
}