]> git.saurik.com Git - wxWidgets.git/blame - samples/memcheck/memcheck.cpp
Unix compilation fixes after last commit
[wxWidgets.git] / samples / memcheck / memcheck.cpp
CommitLineData
457814b5
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: memcheck.cpp
3// Purpose: Memory-checking sample
4// Author: Julian Smart
5// Modified by:
6// Created: 04/01/98
7// RCS-ID: $Id$
6aa89a22 8// Copyright: (c) Julian Smart
2f6c54eb 9// Licence: wxWindows license
457814b5
JS
10/////////////////////////////////////////////////////////////////////////////
11
457814b5
JS
12// For compilers that support precompilation, includes "wx.h".
13#include "wx/wxprec.h"
14
15#ifdef __BORLANDC__
16#pragma hdrstop
17#endif
18
19#ifndef WX_PRECOMP
20#include "wx/wx.h"
21#endif
22
c6376731 23#include "wx/datetime.h"
457814b5 24
618f2efa 25#if defined(__WXGTK__) || defined(__WXX11__) || defined(__WXMOTIF__) || defined(__WXMAC__)
47908e25
RR
26#include "mondrian.xpm"
27#endif
28
6b037754
JS
29#ifndef __WXDEBUG__
30#error This program must be compiled in debug mode.
457814b5
JS
31#endif
32
7fe7d506
JS
33// Normally, new is automatically defined to be the
34// debugging version. If not, this does it.
b58deaec 35#if !defined(new) && defined(WXDEBUG_NEW) && wxUSE_MEMORY_TRACING && wxUSE_GLOBAL_MEMORY_OPERATORS
7fe7d506
JS
36#define new WXDEBUG_NEW
37#endif
38
457814b5
JS
39// Define a new application type
40class MyApp: public wxApp
41{ public:
42 bool OnInit(void);
43};
44
45// Define a new frame type
46class MyFrame: public wxFrame
47{ public:
48 MyFrame(wxFrame *parent);
49 void OnQuit(wxCommandEvent& event);
50
51DECLARE_EVENT_TABLE()
52};
53
54IMPLEMENT_APP(MyApp)
55
56// `Main program' equivalent, creating windows and returning main app frame
57bool MyApp::OnInit(void)
58{
59 // Create the main frame window
c67daf87 60 MyFrame *frame = new MyFrame((wxFrame *) NULL);
457814b5
JS
61
62 // Give it an icon
7fe7d506 63 frame->SetIcon(wxICON(mondrian));
457814b5
JS
64
65 // Make a menubar
66 wxMenu *file_menu = new wxMenu;
67
0c7cbf7d 68 file_menu->Append(wxID_EXIT, _T("E&xit"));
457814b5 69 wxMenuBar *menu_bar = new wxMenuBar;
0c7cbf7d 70 menu_bar->Append(file_menu, _T("File"));
457814b5
JS
71 frame->SetMenuBar(menu_bar);
72
73 // Make a panel with a message
74 wxPanel *panel = new wxPanel(frame);
75
0c7cbf7d 76 (void)new wxStaticText(panel, wxID_ANY, _T("Hello, this is a minimal debugging wxWidgets program!"), wxPoint(10, 10));
457814b5
JS
77
78 // Show the frame
0c7cbf7d 79 frame->Show(true);
457814b5 80
c242a1ec 81#if wxUSE_MEMORY_TRACING
bd7d06f2 82 wxDebugContext::SetCheckpoint();
ea787af1
JS
83#endif
84
85 // object allocation
86 wxBrush* brush = new wxBrush(*wxRED);
87 wxBitmap* bitmap = new wxBitmap(100, 100);
88
89 // non-object allocation
90 char *ordinaryNonObject = new char[1000];
457814b5 91
e55ad60e 92 wxString *thing = new wxString;
c6376731
VZ
93
94#if wxUSE_DATETIME
95 wxDateTime* date = new wxDateTime;
96#endif // wxUSE_DATETIME
457814b5 97
457814b5
JS
98 const char *data = (const char*) thing ;
99
c242a1ec 100#if wxUSE_MEMORY_TRACING
2db0bbde
JS
101 // On MSW, Dump() crashes if using wxLogGui,
102 // so use wxLogStderr instead.
103 wxLog* oldLog = wxLog::SetActiveTarget(new wxLogStderr);
104
bd7d06f2
RR
105 wxDebugContext::PrintClasses();
106 wxDebugContext::Dump();
107 wxDebugContext::PrintStatistics();
457814b5 108
2db0bbde
JS
109 // Set back to wxLogGui
110 delete wxLog::SetActiveTarget(oldLog);
ea787af1 111#endif
2db0bbde 112
6b037754 113 // Don't delete these objects, to force wxApp to flag a memory leak.
457814b5
JS
114// delete thing;
115// delete date;
116// delete[] ordinaryNonObject;
0c7cbf7d
WS
117
118 return true;
457814b5
JS
119}
120
121BEGIN_EVENT_TABLE(MyFrame, wxFrame)
122 EVT_MENU(wxID_EXIT, MyFrame::OnQuit)
123END_EVENT_TABLE()
124
125// My frame constructor
126MyFrame::MyFrame(wxFrame *parent):
0c7cbf7d 127 wxFrame(parent, wxID_ANY, _T("MemCheck wxWidgets Sample"), wxDefaultPosition, wxSize(400, 200))
457814b5
JS
128{}
129
130// Intercept menu commands
cb43b372 131void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
457814b5 132{
0c7cbf7d 133 Close(true);
457814b5
JS
134}
135