forked from cheng/wallet
135 lines
3.4 KiB
C++
135 lines
3.4 KiB
C++
|
/////////////////////////////////////////////////////////////////////////////
|
|||
|
// Name: dialogs.cpp
|
|||
|
// Purpose: updating to make it more relevant to my code
|
|||
|
// and more similar to my code.
|
|||
|
//
|
|||
|
// Leaving most of useless to me examples in place
|
|||
|
// unless I am completely sure they are will never
|
|||
|
// be useful.
|
|||
|
//
|
|||
|
// Some of the stuff here does not quite work
|
|||
|
// Only half implemented. Eg, log message
|
|||
|
// The primary child of Frame is a scrollable
|
|||
|
// window "MyCanvas" to which nothing ever gets
|
|||
|
// written after it is created. And the tip
|
|||
|
// of the day dialog fails sould be under help)
|
|||
|
//
|
|||
|
// On the other hand, lots of cool bits of code
|
|||
|
// that really deserve to be copied, like
|
|||
|
// hooking the windows system menu of
|
|||
|
// a window.
|
|||
|
//
|
|||
|
/////////////////////////////////////////////////////////////////////////////
|
|||
|
#include "stdafx.h"
|
|||
|
|
|||
|
wxIMPLEMENT_APP(MyApp);
|
|||
|
|
|||
|
wxBEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
|
|||
|
EVT_PAINT(MyCanvas::OnPaint)
|
|||
|
wxEND_EVENT_TABLE()
|
|||
|
|
|||
|
#if wxUSE_CMDLINE_PARSER
|
|||
|
static const char* PROGRESS_SWITCH = "progress";
|
|||
|
|
|||
|
void MyApp::OnInitCmdLine(wxCmdLineParser& parser)
|
|||
|
{
|
|||
|
wxApp::OnInitCmdLine(parser);
|
|||
|
|
|||
|
parser.AddOption("", PROGRESS_SWITCH,
|
|||
|
"Style for the startup progress dialog (wxPD_XXX)",
|
|||
|
wxCMD_LINE_VAL_NUMBER);
|
|||
|
}
|
|||
|
|
|||
|
bool MyApp::OnCmdLineParsed(wxCmdLineParser& parser)
|
|||
|
{
|
|||
|
if (!wxApp::OnCmdLineParsed(parser))
|
|||
|
return false;
|
|||
|
|
|||
|
parser.Found(PROGRESS_SWITCH, &m_startupProgressStyle);
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
#endif // wxUSE_CMDLINE_PARSER
|
|||
|
|
|||
|
// `Main program' equivalent, creating windows and returning main app frame
|
|||
|
bool MyApp::OnInit()
|
|||
|
{
|
|||
|
if (!wxApp::OnInit())
|
|||
|
return false;
|
|||
|
|
|||
|
#if wxUSE_PROGRESSDLG
|
|||
|
if (m_startupProgressStyle != -1)
|
|||
|
{
|
|||
|
// Show a test progress dialog before the main event loop is started:
|
|||
|
// it should still work.
|
|||
|
const int PROGRESS_COUNT = 100;
|
|||
|
wxProgressDialog dlg
|
|||
|
(
|
|||
|
"Progress in progress",
|
|||
|
"Please wait, starting...",
|
|||
|
PROGRESS_COUNT,
|
|||
|
NULL,
|
|||
|
m_startupProgressStyle|wxPD_AUTO_HIDE
|
|||
|
);
|
|||
|
for (int i = 0; i <= PROGRESS_COUNT; i++)
|
|||
|
{
|
|||
|
wxString msg;
|
|||
|
switch (i)
|
|||
|
{
|
|||
|
case 15:
|
|||
|
msg = "And the same dialog but with a very, very, very long"
|
|||
|
" message, just to test how it appears in this case.";
|
|||
|
break;
|
|||
|
|
|||
|
case 30:
|
|||
|
msg = "Back to brevity";
|
|||
|
break;
|
|||
|
|
|||
|
case 80:
|
|||
|
msg = "Back and adjusted";
|
|||
|
dlg.Fit();
|
|||
|
break;
|
|||
|
}
|
|||
|
|
|||
|
if (!dlg.Update(i, msg))
|
|||
|
break;
|
|||
|
|
|||
|
wxMilliSleep(50);
|
|||
|
}
|
|||
|
}
|
|||
|
#endif // wxUSE_PROGRESSDLG
|
|||
|
|
|||
|
#if wxUSE_IMAGE
|
|||
|
wxInitAllImageHandlers();
|
|||
|
#endif
|
|||
|
const char* szUtf8Test = " 🙃tick ✔ Pi Π π ϖ π °";
|
|||
|
|
|||
|
// Create the main frame window
|
|||
|
Frame* frame = new Frame(szUtf8Test);
|
|||
|
frame->Show(true);
|
|||
|
#if wxUSE_STARTUP_TIPS
|
|||
|
if (frame->m_showTipsAtStartup) {
|
|||
|
auto event = new wxCommandEvent(wxEVT_MENU, DIALOGS_TIP);
|
|||
|
wxQueueEvent(frame, event);
|
|||
|
}
|
|||
|
#endif // wxUSE_STARTUP_TIPS
|
|||
|
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
// ----------------------------------------------------------------------------
|
|||
|
// MyCanvas
|
|||
|
// ----------------------------------------------------------------------------
|
|||
|
|
|||
|
void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event))
|
|||
|
{
|
|||
|
wxPaintDC dc(this);
|
|||
|
dc.SetBackgroundMode(wxBRUSHSTYLE_TRANSPARENT);
|
|||
|
const char* szUtf8Test = R"|(wxWidgets common dialogs “(✔
|
|||
|
🙃 ✔ π ° )” test application)|";
|
|||
|
dc.DrawText(szUtf8Test, 10, 10);
|
|||
|
dc.DrawText("fred fred", 10, 40);
|
|||
|
}
|
|||
|
|