]> git.sur5r.net Git - bacula/bacula/blob - bacula/src/wx-console/main.cpp
added win32 unicode support for wx-console (compile with _UNICODE)
[bacula/bacula] / bacula / src / wx-console / main.cpp
1 /*
2  *
3  *    Bacula wx-console application
4  *
5  *    Nicolas Boichat, April 2004
6  *
7  *    Version $Id$
8  */
9 /*
10    Copyright (C) 2004-2005 Kern Sibbald
11
12    This program is free software; you can redistribute it and/or
13    modify it under the terms of the GNU General Public License
14    as published by the Free Software Foundation; either version 2
15    of the License, or (at your option) any later version.
16
17    This program is distributed in the hope that it will be useful,
18    but WITHOUT ANY WARRANTY; without even the implied warranty of
19    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20    GNU General Public License for more details.
21
22    You should have received a copy of the GNU General Public License
23    along with this program; if not, write to the Free Software
24    Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
25  */
26
27 // ============================================================================
28 // declarations
29 // ============================================================================
30
31 // ----------------------------------------------------------------------------
32 // headers
33 // ----------------------------------------------------------------------------
34
35 #include <wx/wxprec.h>
36 #include <wx/config.h>
37
38 #include "wxbmainframe.h"
39
40 #include "csprint.h"
41
42 void InitWinAPIWrapper();
43
44 /* Dummy functions */
45 int generate_daemon_event(JCR *jcr, const char *event) { return 1; }
46 int generate_job_event(JCR *jcr, const char *event) { return 1; }
47
48
49 // ----------------------------------------------------------------------------
50 // resources
51 // ----------------------------------------------------------------------------
52
53 class MyApp : public wxApp
54 {
55 public:
56    virtual bool OnInit();
57 };
58
59 // ============================================================================
60 // implementation
61 // ============================================================================
62
63 IMPLEMENT_APP(MyApp)
64
65 // ----------------------------------------------------------------------------
66 // the application class
67 // ----------------------------------------------------------------------------
68
69 // 'Main program' equivalent: the program execution "starts" here
70 bool MyApp::OnInit()
71 {
72    long posx, posy, sizex, sizey;
73    int displayx, displayy;
74    InitWinAPIWrapper();
75    wxConfig::Get()->Read(wxT("/Position/X"), &posx, 50);
76    wxConfig::Get()->Read(wxT("/Position/Y"), &posy, 50);
77    wxConfig::Get()->Read(wxT("/Size/Width"), &sizex, 780);
78    wxConfig::Get()->Read(wxT("/Size/Height"), &sizey, 500);
79    
80    wxDisplaySize(&displayx, &displayy);
81    
82    /* Check if we are on the screen... */
83    if ((posx+sizex > displayx) || (posy+sizey > displayy)) {
84       /* Try to move the top-left corner first */
85       posx = 50;
86       posy = 50;
87       if ((posx+sizex > displayx) || (posy+sizey > displayy)) {
88          posx = 25;
89          posy = 25;
90          sizex = displayx - 50;
91          sizey = displayy - 50;
92       }
93    }
94
95    wxbMainFrame *frame = wxbMainFrame::CreateInstance(wxT("Bacula wx-console"),
96                          wxPoint(posx, posy), wxSize(sizex, sizey));
97
98    frame->Show(TRUE);
99
100    frame->Print(wxString(wxT("Welcome to bacula wx-console ")) << wxT(VERSION) << wxT(" (") << wxT(BDATE) << wxT(")!\n"), CS_DEBUG);
101
102    frame->StartConsoleThread(wxT(""));
103    
104    return TRUE;
105 }