Ticket #15138: stacktracetest.cpp

File stacktracetest.cpp, 7.3 KB (added by suzumizaki, 7 years ago)

C++ code for test. Please replace minimal.cpp, save as utf-8 or utf-16, build debug mode, and push button and check whether dialog can show "日本語の関数".

Line 
1/////////////////////////////////////////////////////////////////////////////
2// Name:        stacktracetest.cpp
3// Purpose:     Minimal wxWidgets sample
4// Author:      Suzumizaki-kimitaka (Copied from minimal.cpp and modified)
5// Modified by:
6// Created:     2013-04-06
7// RCS-ID:     
8// Copyright:   (c) Julian Smart
9// Licence:     wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19#include "stdafx.h"
20
21// For compilers that support precompilation, includes "wx/wx.h".
22#include "wx/wxprec.h"
23
24#ifdef __BORLANDC__
25    #pragma hdrstop
26#endif
27
28// for all others, include the necessary headers (this file is usually all you
29// need because it includes almost all "standard" wxWidgets headers)
30#ifndef WX_PRECOMP
31    #include "wx/wx.h"
32#endif
33
34#include <wx/dcbuffer.h>
35#define _DBGHELP_
36#include <wx/msw/debughlp.h>
37
38// ----------------------------------------------------------------------------
39// private classes
40// ----------------------------------------------------------------------------
41
42// Define a new application type, each program should derive a class from wxApp
43class MyApp : public wxApp
44{
45public:
46    // override base class virtuals
47    // ----------------------------
48
49    // this one is called on application startup and is a good place for the app
50    // initialization (doing it here and not in the ctor allows to have an error
51    // return: if OnInit() returns false, the application terminates)
52    virtual bool OnInit();
53};
54
55// Define a new frame type: this is going to be our main frame
56class MyFrame : public wxFrame
57{
58public:
59    // ctor(s)
60    MyFrame(const wxString& title);
61
62    // event handlers (these functions should _not_ be virtual)
63    void OnQuit(wxCommandEvent& event);
64    void OnAbout(wxCommandEvent& event);
65        void OnTryJapaneseNamedFunction(wxCommandEvent&);
66
67private:
68    // any class wishing to process wxWidgets events must use this macro
69    DECLARE_EVENT_TABLE()
70};
71
72// ----------------------------------------------------------------------------
73// constants
74// ----------------------------------------------------------------------------
75
76// IDs for the controls and the menu commands
77enum
78{
79    // menu items
80    Minimal_Quit = wxID_EXIT,
81
82    // it is important for the id corresponding to the "About" command to have
83    // this standard value as otherwise it won't be handled properly under Mac
84    // (where it is special and put into the "Apple" menu)
85    Minimal_About = wxID_ABOUT
86};
87
88// ----------------------------------------------------------------------------
89// event tables and other macros for wxWidgets
90// ----------------------------------------------------------------------------
91
92// the event tables connect the wxWidgets events with the functions (event
93// handlers) which process them. It can be also done at run-time, but for the
94// simple menu events like this the static method is much simpler.
95BEGIN_EVENT_TABLE(MyFrame, wxFrame)
96    EVT_MENU(Minimal_Quit,  MyFrame::OnQuit)
97    EVT_MENU(Minimal_About, MyFrame::OnAbout)
98END_EVENT_TABLE()
99
100// Create a new application object: this macro will allow wxWidgets to create
101// the application object during program execution (it's better than using a
102// static object for many reasons) and also implements the accessor function
103// wxGetApp() which will return the reference of the right type (i.e. MyApp and
104// not wxApp)
105IMPLEMENT_APP(MyApp)
106
107// ============================================================================
108// implementation
109// ============================================================================
110
111// ----------------------------------------------------------------------------
112// the application class
113// ----------------------------------------------------------------------------
114
115// 'Main program' equivalent: the program execution "starts" here
116bool MyApp::OnInit()
117{
118    // call the base class initialization method, currently it only parses a
119    // few common command-line options but it could be do more in the future
120    if ( !wxApp::OnInit() )
121        return false;
122
123    // create the main application window
124    MyFrame *frame = new MyFrame("wxWidgets Stacktrace test");
125
126    // and show it (the frames, unlike simple controls, are not shown when
127    // created initially)
128    frame->Show(true);
129
130    // success: wxApp::OnRun() will be called which will enter the main message
131    // loop and the application will run. If we returned false here, the
132    // application would exit immediately.
133    return true;
134}
135
136// ----------------------------------------------------------------------------
137// main frame
138// ----------------------------------------------------------------------------
139
140// frame constructor
141MyFrame::MyFrame(const wxString& title)
142       : wxFrame(NULL, wxID_ANY, title)
143{
144
145#if wxUSE_MENUS
146    // create a menu bar
147    wxMenu *fileMenu = new wxMenu;
148
149    // the "About" item should be in the help menu
150    wxMenu *helpMenu = new wxMenu;
151    helpMenu->Append(Minimal_About, "&About\tF1", "Show about dialog");
152
153    fileMenu->Append(Minimal_Quit, "E&xit\tAlt-X", "Quit this program");
154
155    // now append the freshly created menu to the menu bar...
156    wxMenuBar *menuBar = new wxMenuBar();
157    menuBar->Append(fileMenu, "&File");
158    menuBar->Append(helpMenu, "&Help");
159
160    // ... and attach this menu bar to the frame
161    SetMenuBar(menuBar);
162#endif // wxUSE_MENUS
163
164#if wxUSE_STATUSBAR
165    // create a status bar just for fun (by default with 1 pane only)
166    CreateStatusBar(2);
167    SetStatusText("Welcome to wxWidgets!");
168#endif // wxUSE_STATUSBAR
169
170        wxPanel* panel = new wxPanel(this, wxNewId());
171        wxBoxSizer* sizer = new wxBoxSizer(wxVERTICAL);
172        wxButton * button = new wxButton(panel, wxNewId(), "Test non-ASCII named function");
173        sizer->Add(button, wxSizerFlags(1).Expand().Border());
174        panel->SetSizerAndFit(sizer);
175        Bind(wxEVT_COMMAND_BUTTON_CLICKED, &MyFrame::OnTryJapaneseNamedFunction, this, button->GetId());
176}
177
178
179// event handlers
180
181void MyFrame::OnQuit(wxCommandEvent& WXUNUSED(event))
182{
183    // true is to force the frame to close
184    Close(true);
185}
186
187void MyFrame::OnAbout(wxCommandEvent& WXUNUSED(event))
188{
189    wxMessageBox(wxString::Format
190                 (
191                    "Welcome to %s!\n"
192                    "\n"
193                    "This is the minimal wxWidgets sample\n"
194                    "running under %s.",
195                    wxVERSION_STRING,
196                    wxGetOsDescription()
197                 ),
198                 "About stop by assertion",
199                 wxOK | wxICON_INFORMATION,
200                 this);
201}
202
203wxString 日本語の関数テスト()
204{
205        // Integer is given as string. Ofcourse stop by assertion.
206        return wxString::Format("%1$s", 200);
207}
208
209void MyFrame::OnTryJapaneseNamedFunction(wxCommandEvent&)
210{
211        // When you run in debug mode, can you see following function name
212        // in the error stop dialog?
213        日本語の関数テスト();
214}