NumeRe v1.1.4
NumeRe: Framework für Numerische Rechnungen
tipdialog.cpp
Go to the documentation of this file.
1/*****************************************************************************
2 NumeRe: Framework fuer Numerische Rechnungen
3 Copyright (C) 2017 Erik Haenel et al.
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program. If not, see <http://www.gnu.org/licenses/>.
17******************************************************************************/
18
19#include "tipdialog.hpp"
20#include <wx/statline.h>
21#include <wx/artprov.h>
22
23#define wxID_NEXT_TIP 32000
24#if defined(__SMARTPHONE__)
25 #define wxLARGESMALL(large,small) small
26#else
27 #define wxLARGESMALL(large,small) large
28#endif
29
30BEGIN_EVENT_TABLE(TipDialog, wxDialog)
33
34TipDialog::TipDialog(wxWindow *parent, wxTipProvider *tipProvider, const wxArrayString& text, bool showAtStartup)
35 : wxDialog(GetParentForModalDialog(parent, 0), wxID_ANY, text[0], wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
36{
37 m_tipProvider = tipProvider;
38 bool isPda = (wxSystemSettings::GetScreenType() <= wxSYS_SCREEN_PDA);
39
40 // 1) create all controls in tab order
41 wxStaticText *__text = new wxStaticText(this, wxID_ANY, text[1]);
42
43 if (!isPda)
44 {
45 wxFont font = __text->GetFont();
46 font.SetPointSize(int(1.6 * font.GetPointSize()));
47 font.SetWeight(wxFONTWEIGHT_BOLD);
48 __text->SetFont(font);
49 }
50
51 m_text = new wxTextCtrl(this, wxID_ANY, wxEmptyString,
52 wxDefaultPosition, wxSize(200, 160),
53 wxTE_MULTILINE |
54 wxTE_READONLY |
55 wxTE_NO_VSCROLL |
56 wxTE_RICH2 | // a hack to get rid of vert scrollbar
57 wxDEFAULT_CONTROL_BORDER
58 );
59#if defined(__WXMSW__)
60 m_text->SetFont(wxFont(12, wxSWISS, wxNORMAL, wxNORMAL));
61#endif
62
63//#if defined(__WXPM__)
64 //
65 // The only way to get icons into an OS/2 static bitmap control
66 //
67// wxBitmap vBitmap;
68
69// vBitmap.SetId(wxICON_TIP); // OS/2 specific bitmap method--OS/2 wxBitmaps all have an ID.
70// // and for StatBmp's under OS/2 it MUST be a valid resource ID.
71//
72// wxStaticBitmap* bmp = new wxStaticBitmap(this, wxID_ANY, vBitmap);
73//
74//#else
75
76 wxIcon icon = wxArtProvider::GetIcon(wxART_TIP, wxART_CMN_DIALOG);
77 wxStaticBitmap *bmp = new wxStaticBitmap(this, wxID_ANY, icon);
78
79//#endif
80
81 m_checkbox = new wxCheckBox(this, wxID_ANY, text[3]);
82 m_checkbox->SetValue(showAtStartup);
83 m_checkbox->SetFocus();
84
85 // smart phones does not support or do not waste space for wxButtons
86#ifndef __SMARTPHONE__
87 wxButton *btnNext = new wxButton(this, wxID_NEXT_TIP, text[2]);
88#endif
89
90 // smart phones does not support or do not waste space for wxButtons
91#ifndef __SMARTPHONE__
92 wxButton *btnClose = new wxButton(this, wxID_CLOSE, text[4]);
93 SetAffirmativeId(wxID_CLOSE);
94#endif
95
96
97 // 2) put them in boxes
98
99 wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
100
101 wxBoxSizer *icon_text = new wxBoxSizer( wxHORIZONTAL );
102 icon_text->Add( bmp, 0, wxCENTER );
103 icon_text->Add( __text, 1, wxCENTER | wxLEFT, wxLARGESMALL(20,0) );
104 topsizer->Add( icon_text, 0, wxEXPAND | wxALL, wxLARGESMALL(10,0) );
105
106 topsizer->Add( m_text, 1, wxEXPAND | wxLEFT|wxRIGHT, wxLARGESMALL(10,0) );
107
108 wxBoxSizer *bottom = new wxBoxSizer( wxHORIZONTAL );
109 if (isPda)
110 topsizer->Add( m_checkbox, 0, wxCENTER|wxTOP );
111 else
112 bottom->Add( m_checkbox, 0, wxCENTER );
113
114 // smart phones does not support or do not waste space for wxButtons
115#ifdef __SMARTPHONE__
116 SetRightMenu(wxID_NEXT_TIP, _("Next"));
117 SetLeftMenu(wxID_CLOSE);
118#else
119 if (!isPda)
120 bottom->Add( 10,10,1 );
121 bottom->Add( btnNext, 0, wxCENTER | wxLEFT, wxLARGESMALL(10,0) );
122 bottom->Add( btnClose, 0, wxCENTER | wxLEFT, wxLARGESMALL(10,0) );
123#endif
124
125 if (isPda)
126 topsizer->Add( bottom, 0, wxCENTER | wxALL, 5 );
127 else
128 topsizer->Add( bottom, 0, wxEXPAND | wxALL, wxLARGESMALL(10,0) );
129
130 SetTipText();
131
132 SetSizer( topsizer );
133
134 topsizer->SetSizeHints( this );
135 topsizer->Fit( this );
136
137 Centre(wxBOTH | wxCENTER_FRAME);
138}
139
140
141bool ShowTip(wxWindow* parent, wxTipProvider* tipProvider, const wxArrayString& text, bool showAtStartUp)
142{
143 TipDialog dlg(parent, tipProvider, text, showAtStartUp);
144 dlg.ShowModal();
145
146 return dlg.ShowTipsOnStartup();
147}
148
149
150MyTipProvider::MyTipProvider(const std::vector<std::string>& vTipList) : wxTipProvider(vTipList.size())
151{
152 vTip = vTipList;
153 nth_tip = 0;
154 // --> Einen Seed (aus der Zeit generiert) an die rand()-Funktion zuweisen <--
155 srand(time(NULL));
156
157 if (!vTip.size())
158 return;
159 // --> Die aktuelle Begruessung erhalten wir als modulo(nGreetings)-Operation auf rand() <--
160 nth_tip = (rand() % vTip.size());
161 if (nth_tip >= vTip.size())
162 nth_tip = 0;
163}
164
MyTipProvider(const std::vector< std::string > &vTipList)
Definition: tipdialog.cpp:150
unsigned int nth_tip
Definition: tipdialog.hpp:31
std::vector< std::string > vTip
Definition: tipdialog.hpp:30
void OnNextTip(wxCommandEvent &WXUNUSED(event))
Definition: tipdialog.hpp:60
bool ShowTipsOnStartup() const
Definition: tipdialog.hpp:54
bool ShowTip(wxWindow *parent, wxTipProvider *tipProvider, const wxArrayString &text, bool showAtStartUp)
Definition: tipdialog.cpp:141
#define wxID_NEXT_TIP
Definition: tipdialog.cpp:23
#define wxLARGESMALL(large, small)
Definition: tipdialog.cpp:27
END_EVENT_TABLE()