-
Notifications
You must be signed in to change notification settings - Fork 0
/
wxMsFrame.cpp
470 lines (435 loc) · 14.7 KB
/
wxMsFrame.cpp
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
//-------------------------------------------------------------------
// Name: wxMsFrame .cpp
// Purpose: main frame file for wxMS Mail Screener
// Author: A. Wiegert
//
// Copyright:
// Licence: wxWidgets license
//-------------------------------------------------------------------
//-------------------------------------------------------------------
// Note __VISUALC__ is defined by wxWidgets, not by MSVC IDE
// and thus won't be defined until some wxWidgets headers are included
#if defined( _MSC_VER )
# if defined ( _DEBUG )
// this statement NEEDS to go BEFORE all headers
# define _CRTDBG_MAP_ALLOC
# endif
#endif
#include "wxMsPreProcDefsh.h" // needs to be first
// ------------------------------------------------------------------
//-------------------------------------------------------------------
// Standard wxWidgets headers
//-------------------------------------------------------------------
// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
// For all others, include the necessary headers (this file is
// usually all you
// need because it includes almost all "standard" wxWidgets headers)
#ifndef WX_PRECOMP
#include "wx/wx.h"
#endif
//-------------------------------------------------------------------
// Header of this .cpp file
//-------------------------------------------------------------------
#include <wx/event.h>
#include <wx/msgdlg.h>
#include "wxMsFrameh.h"
#if defined( WANT_FILEVERSION )
#include "fileVerh.h"
#endif
#if defined( WANT_TASKBAR )
#include "rc/smile.xpm"
#endif
#include <list>
#include "curl/curl.h"
// ------------------------------------------------------------------
// Note __VISUALC__ is defined by wxWidgets, not by MSVC IDE
// and thus won't be defined until some wxWidgets headers are included
#if defined( _MSC_VER )
// this block needs to AFTER all headers
#include <crtdbg.h>
#ifdef _DEBUG
#define DEBUG_NEW new(_NORMAL_BLOCK, __FILE__, __LINE__)
#define new DEBUG_NEW
#endif
#endif
// ------------------------------------------------------------------
extern MyApp *theApp;
//-------------------------------------------------------------------
// The event tables connect the wxWidgets events with the functions (event
// handlers) which process them. It can be also done at run-time, but for the
// simple menu events like this the static method is much simpler.
// The reason why the menuitems and tools are given the same name in the
// XRC file, is that both a tool (a toolbar item) and a menuitem are designed
// to fire the same kind of event (an EVT_MENU) and thus I give them the same
// ID name to help new users emphasize this point which is often overlooked
// when starting out with wxWidgets.
BEGIN_EVENT_TABLE(MyFrame, wxFrame)
EVT_MENU(wxID_EXIT, MyFrame::OnExit )
EVT_GRID_COL_SIZE( MyFrame::OnMailGridColSize )
// mail grid context menu handlers
EVT_MENU( wxID_CONTEXT_DELETE_MSG, MyFrame::OnContextDelMsg )
EVT_MENU( wxID_CONTEXT_PREVIEW_MSG, MyFrame::OnContextPreview )
EVT_MENU( wxID_CONTEXT_MARK_DEL_MSG, MyFrame::OnContextMarkDelMsg )
EVT_MENU( wxID_CONTEXT_MARK_BOUNCE_MSG, MyFrame::OnContextMarkBounceMsg )
EVT_MENU( wxID_CONTEXT_ADD_BLACK_MSG, MyFrame::OnContextAddBlackMsg )
EVT_MENU( wxID_CONTEXT_ADD_FRIEND_MSG, MyFrame::OnContextAddFriendMsg )
// for checkboxes in mailgrid
EVT_CHECKBOX( wxID_ANY, MyFrame::CheckboxHandler)
EVT_TIMER( MAIL_CHECK_TIMER_ID, MyFrame::OnMailCheckTimer)
EVT_TIMER( MAIL_SERVER_CHECK_TIMER_ID, MyFrame::OnMailConnectTimer)
EVT_TIMER( MAIL_DISPLAY_TIMER_ID, MyFrame::OnMailDisplayTimer)
EVT_IDLE( MyFrame::OnIdle)
END_EVENT_TABLE()
// ------------------------------------------------------------------
MyFrame::MyFrame( wxWindow* parent )
: MyFrameBase( parent ), m_tMailCheckTimer(this, MAIL_CHECK_TIMER_ID ),
m_tMailDisplayTimer(this, MAIL_DISPLAY_TIMER_ID ),
m_tMailServerConnectCheckTimer( this, MAIL_SERVER_CHECK_TIMER_ID )
{
m_iRightClickRow = 0;
m_iWheelRotation = 0;
m_wasColLabels.Clear();
m_wasColLabels.Empty();
m_walColWidths.Clear();
m_walColWidths.Empty();
m_bStop = false;
m_iNIdleCalls = 0;
m_bAnyAccountsActive = false;
m_bNeedStartupMailCheck = m_bNeedStartupNewversionCheck = true;
#if defined( _MSC_VER )
m_pAppProgress = NULL;
m_pAppProgress = new wxAppProgressIndicator(this);
if( m_pAppProgress->IsAvailable() )
{
m_pAppProgress->SetRange( 100 );
m_bHaveAppProgress = true;
}
else
{
m_pAppProgress = NULL;
m_bHaveAppProgress = false;
}
m_toolBarMain->Refresh();
// wxSleep( 5 );
#endif
// 1 minute interval
m_iMailTimerTicks = 0;
m_iConnectCheckTimerTicks = 0;
m_tMailCheckTimer.Start(1000 * 60 );
m_bRunning = m_bCancelled = false;
m_lNTopLines = g_iniPrefs.data[IE_OPT_MAX_TOP_LINES].dataCurrent.lVal;
// Update the mail grid display
// It is also possible to use event tables, but dynamic binding is simpler.
Bind( wxEVT_THREAD, &MyFrame::OnUpdateDisplay, this );
m_Pop3MsgList.clear();
#if defined( WANT_FILEVERSION )
//#include "fileVerh.h"
wxFileVersion fVer;
// open the executable's version info
bool bErr = fVer.Open();
if( bErr == false )
{
wxString wsT;
wsT.Printf( _("Cannot find the .EXE file version, exiting !") );
wxMessageBox( wsT, _("Error") );
//return;
}
wxString wsFV = fVer.GetFixedFileVersion();
// and close the
// fVer.Close();
giMajorVersion = fVer.GetMajorVersion();
giMinorVersion = fVer.GetMinorVersion();
giBuildNumber = fVer.GetBuildNumber();
// fVer.GetSpecialBuild();
#endif
#if defined( WANT_HELP )
#if defined( WANT_ZIP_HELP )
//wxFileSystem::AddHandler(new wxZipFSHandler);
//m_pProvider = new wxHelpControllerHelpProvider;
//wxHelpProvider::Set( m_pProvider );
m_pProvider->SetHelpController(GetHelpController());
if( !GetHelpController()->AddBook(wxFileName(_T("wx??Help.zip"))))
{
wxLogError( _("Cannot initialize the Help system."));
}
#else
#if defined( _MSC_VER )
// help file now is in the %USER%/AppData/Roaming for Vista
wxString wsCurPath = wxStandardPaths::Get().GetResourcesDir();
wxFileName wfnHelpFile;
wfnHelpFile.AssignDir( wxGetApp().m_wsConfigDir );
// and construct the help file name
wxString wsHelpFile = wxGetApp().m_wsAppName;
wfnHelpFile.SetName( wsHelpFile + _T("Help") );
wfnHelpFile.SetExt( _T("chm") );
wsHelpFile = m_wsCurHelpFile = wfnHelpFile.GetFullPath();
if( ! ::wxFileExists( m_wsCurHelpFile ) )
{
wxLogDebug( _("Cannot find the Help file %s."), m_wsCurHelpFile);
m_bFoundHelpFile = false;
m_wsCurHelpFile = wxEmptyString;
}
else
m_bFoundHelpFile = true;
m_pProvider = new wxHelpControllerHelpProvider;
wxHelpProvider::Set( m_pProvider );
m_pProvider->SetHelpController(GetHelpController());
// Note: this code only checks if the basic MS Help DLLs are available
// not whether or not the help file can be found
if( !GetHelpController()->Initialize( m_wsCurHelpFile ) )
{
wxLogError( _("Cannot initialize the MS HTML Help system."));
// m_bFoundHelpFile = false;
}
#else
// under Linux
wxFileName wfnHelpFile;
m_msHtmlHelp.UseConfig(wxConfig::Get());
m_msHtmlHelp.SetTempDir(wxT("."));
wfnHelpFile.AssignDir( wxGetApp().m_wsConfigDir + _T("/Help") );
// and construct the help file name
wxString wsHelpFile;
wfnHelpFile.SetName( _T("wxMS-HB") );
// also works if ZIP handler is ininitialized
wfnHelpFile.SetExt( _T("htb") );
wsHelpFile = m_wsCurHelpFile = wfnHelpFile.GetFullPath();
if( ! ::wxFileExists( m_wsCurHelpFile ) )
{
wxLogDebug( _("Cannot find the Help file %s."), m_wsCurHelpFile);
m_bFoundHelpFile = false;
m_wsCurHelpFile = wxEmptyString;
}
else
{
m_bFoundHelpFile = true;
m_msHtmlHelp.AddBook( m_wsCurHelpFile );
}
#endif
#endif
#endif
#if defined( WANT_LOG_WIN )
// set up Log Window
// send text to it via something like:
// wxLogStatus(_T("Caret is at (%d, %d)"), m_xCaret, m_yCaret);
m_pLogWin = new wxLogTextCtrl( m_textCtrlLog );
m_pLogOld = wxLog::SetActiveTarget( m_pLogWin );
#endif
GetGaugeProgress()->SetValue( 0 );
#if defined( WANT_DBGRPRT )
#ifndef _DEBUG
// remove the crash menu item if in release mode
int iCrashId = m_menubarMain->FindMenu( _T("Crash") );
wxASSERT( iCrashId != wxNOT_FOUND );
wxString wsMenu;
for ( size_t i = 0; i < m_menubarMain->GetMenuCount(); i ++ )
{
wsMenu = m_menubarMain->GetMenuLabelText( i );
if ( wsMenu.IsSameAs( _T("Crash") ) )
m_menubarMain->Remove( i );
}
#endif
#endif
}
//-----------------------------------------------------------------------------
// Private methods
//-----------------------------------------------------------------------------
/**
* We need to call
* Destroy();
* instead of
* Close(true); // so the main frame dtor will be called
* when the application is closed from the File menu or with Alt-F4
* This function is NOT called when the user closes the application
* using the red 'x' on the system menu.
* That action calls the main frame dtor directly.
*/
void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event))
{
Destroy();
}
#if 0 // neither used nor called
// ------------------------------------------------------------------
/**
* If CanVeto() returns false, the system is shutting down.
* and we MUST exit.
*/
void MyFrame::OnClose( wxCloseEvent& event )
{
if ( event.CanVeto() ) // is the app itself shutting donw
{
if ( GetThread() && // DoStartALongTask() may have not been called
GetThread()->IsRunning() )
{
{
wxCriticalSectionLocker lock(m_csCancelled);
m_bCancelled = true;
}
GetThread()->Wait();
}
}
Destroy();
}
#endif
//-----------------------------------------------------------------------------
MyFrame::~MyFrame()
{
#if defined( WANT_NEW_STOP )
wxGetApp().m_bShuttingDown = true;
// needs to be done in the main frame dtor
// here we don't care whether it is the app only or of the OS requested a shutdown
// if ( event.CanVeto() ) // is the app itself shutting down
{
if (GetThread() && // DoStartTask() may have not been called
GetThread()->IsRunning() )
{
{
wxCriticalSectionLocker lock(m_csCancelled);
m_bCancelled = true;
}
// wait for the thread to finish
// bombs - we're shutting down in any case
// GetThread()->Wait();
#if defined( WANT_SEMAPHORE )
// now wait for them to really terminate
wxGetApp().m_semAllDone.Wait();
#endif
}
}
#endif
// save the frame position
int x, y, w, h;
GetSize(&w, &h);
g_iniPrefs.data[IE_FRAME_W].dataCurrent.lVal = w;
g_iniPrefs.data[IE_FRAME_H].dataCurrent.lVal = h;
GetPosition(&x, &y);
g_iniPrefs.data[IE_FRAME_X].dataCurrent.lVal = x;
g_iniPrefs.data[IE_FRAME_Y].dataCurrent.lVal = y;
g_iniPrefs.data[IE_SASH_POS].dataCurrent.lVal =
m_splitterMain->GetSashPosition();
#if defined( WANT_SCALING )
// shrink app frame at startup is new reso;ution is smaller than old
wxDisplaySize( &x, &y );
g_iniPrefs.data[IE_RESOLUTION_X].dataCurrent.lVal = x;
g_iniPrefs.data[IE_RESOLUTION_Y].dataCurrent.lVal = y;
#endif
wxGetApp().SaveAccounts();
SaveColWidths();
SaveColLabels();
ClearMessages();
curl_global_cleanup();
#if defined( _MSC_VER )
if ( m_pAppProgress )
delete m_pAppProgress;
#endif
}
//-----------------------------------------------------------------------------
void MyFrame::OnQuit( wxCommandEvent &WXUNUSED(event) )
{
Close( true );
}
// ------------------------------------------------------------------
/**
* Clear the message data array.
*/
void MyFrame::ClearMessages()
{
{
// ensure noone modifies the message data while we
// get ready to display it ???
wxCriticalSectionLocker lock(m_CS_Pop3MsgList);
m_Pop3MsgList.clear();
}
}
// ------------------------------------------------------------------
void MyFrame::OnClearList(wxCommandEvent& event)
{
wxUnusedVar(event);
ClearMessages();
DisplayMailList();
}
// ------------------------------------------------------------------
/**
* MUST use the WANT_STARTUP_IN_IDLE option, otherwise the toolbar won't
* show until after the mail check returns.
*/
void MyFrame::OnIdle(wxIdleEvent& WXUNUSED(event))
{
m_iNIdleCalls++;
#if defined( WANT_MSVC_INTERNET_TEST )
/* This arrangement displays the status once at start up &
* not again until it changes.
*/
static int s_isOnline = -1; // not true nor false
bool isOnline = wxGetApp().GetDialer()->IsOnline();
if ( s_isOnline != (int)isOnline )
{
s_isOnline = isOnline;
#if wxUSE_STATUSBAR
#if defined( _MSC_VER )
SetStatusText(isOnline ? wxT("Online") : wxT("Offline"), 4 );
#endif // WANT_MSVC_INTERNET_TEST
#endif // wxUSE_STATUSBAR
}
#endif // WANT_MSVC_INTERNET_TEST
#if defined( WANT_STARTUP_IN_IDLE )
// MUST use this option, otherwise tool bar won't show until
// after the mail check returns.
#if defined( WANT_SEMAPHORE )
// signal the main frame that we can start threads
wxGetApp().m_semAllDone.Post();
#endif
wxString wsT;
if( wxGetApp().IsInternetAvailable() )
{
if( g_iniPrefs.data[IE_OPT_AUTO_UPDATE_CHECK].dataCurrent.bVal && m_bNeedStartupNewversionCheck )
{
m_bNeedStartupNewversionCheck = false;
Check4Update( false ); // mo "You have the latest version" needed/wanted
}
// check & download mail at start up?
if( g_iniPrefs.data[IE_CHECK_MAIL_STARTUP].dataCurrent.bVal && m_bNeedStartupMailCheck )
{
m_bNeedStartupMailCheck = false; // one-time toggle
// check default account as left by user last time
Check4NewMail();
}
}
else
{
wsT.Printf( _("Internet Connection is unavailable!\n") );
wxMessageBox( wsT, "Error", wxOK );
wxLogMessage( wsT ); // does not show
}
#endif
}
// ------------------------------------------------------------------
void MyFrame::ClearPop3CommandData()
{
wxCriticalSectionLocker lock(m_CS_Pop3MsgList);
m_Pop3CommandData.sm_wsResultData =
m_Pop3CommandData.sm_wsAccountName =
m_Pop3CommandData.sm_wsPop3ServerUrl =
m_Pop3CommandData.sm_wsUserName =
m_Pop3CommandData.sm_wsUserPassword = wxEmptyString;
m_Pop3CommandData.sm_bSuccess = false;
m_Pop3CommandData.sm_lResultCode = -1l;
m_Pop3CommandData.sm_wasCommands.Clear();
}
// ------------------------------------------------------------------
// Constructor
wxMsPasswordPromptDlg::wxMsPasswordPromptDlg( wxWindow* parent) :
wxMsBasePasswordPromptDlg( parent )
{
m_parent = parent;
};
// ------------------------------------------------------------------
bool MyFrame::Cancelled()
{
wxCriticalSectionLocker lock(m_csCancelled);
return m_bCancelled;
}
// ------------------------------- eof ------------------------------