]> Creatis software - bbtk.git/blob - kernel/appli/bbStudio/bbStudio.cxx
2acaa14ade80e2883873df6259e8c60b72063008
[bbtk.git] / kernel / appli / bbStudio / bbStudio.cxx
1 #ifdef _USE_WXWIDGETS_
2
3 //==========================================================================
4 // WITH WX
5 //==========================================================================
6 #include "bbtkWxGUIScriptingInterface.h"
7
8 #include <wx/cmdline.h> 
9 #include <vector>
10
11
12 static const wxCmdLineEntryDesc cmdLineDesc[] =
13 {
14   { wxCMD_LINE_PARAM,  NULL, NULL, _T("file1 [file2 [...]]"), wxCMD_LINE_VAL_STRING, wxCMD_LINE_PARAM_OPTIONAL }, 
15   { wxCMD_LINE_SWITCH, _T("h"), _T("help"),   _T("Prints this help") },
16   { wxCMD_LINE_SWITCH, _T("d"), _T("debug"),   _T("Message all 9") },
17   { wxCMD_LINE_NONE }
18 };
19
20
21
22 class wxBBIApp : public wxApp
23 {
24 public:
25   bool OnInit( );
26   int  OnExit() { return true; }
27   void OnInitCmdLine(wxCmdLineParser& parser);
28   bool OnCmdLineParsed(wxCmdLineParser& parser);
29
30   bool usage;
31   std::vector<std::string> input_file;
32 };
33
34 IMPLEMENT_APP(wxBBIApp);
35
36 void wxBBIApp::OnInitCmdLine(wxCmdLineParser& parser)
37 {
38   //    std::cout << "OnInitCmdLine"<<std::endl;
39   parser.SetDesc(cmdLineDesc);
40 }
41
42 bool wxBBIApp::OnCmdLineParsed(wxCmdLineParser& parser)
43 {
44   int argc = parser.GetParamCount();
45   for (int i=0; i<argc; ++i) 
46     {
47       std::string s = bbtk::wx2std(parser.GetParam(i));
48       input_file.push_back(s);
49     }
50
51   bool help = ( parser.Found(_T("h")) );
52   usage = (help && (input_file.size()==0));
53   if (usage) {
54     std::cout << "bbStudio (The Black Box Development Studio) - bbtk "
55               << bbtk::GetVersion() << " - (c) Creatis 2007-2008"
56               << std::endl;
57     parser.Usage();
58   }
59   else 
60   {
61         if ( parser.Found(_T("d")) )
62         {
63                 bbtk::MessageManager::SetMessageLevel("all",9);
64         }
65   }
66
67
68   return true;
69 }
70
71
72
73 // ----------------------------------------------------------------------------
74 // The `main program' equivalent, creating the windows and returning the
75 // main frame
76 bool wxBBIApp::OnInit( )
77 {
78   //    std::cout << "OnInit"<<std::endl;
79   wxApp::OnInit();
80 #ifdef __WXGTK__
81   //See http://www.wxwindows.org/faqgtk.htm#locale
82   setlocale(LC_NUMERIC, "C");
83 #endif
84   if (usage) return false;
85   
86   bbtk::WxGUIScriptingInterface *I = 
87     new bbtk::WxGUIScriptingInterface(0);
88   SetTopWindow(I);  
89   I->Show(true);
90
91   std::vector<std::string>::const_iterator i;
92   i=input_file.begin(); 
93   if (i!=input_file.end()) I->Open(*i);
94
95   return true;
96 }
97
98
99 #if defined(_WIN32) 
100
101 //  How to have a Console and wxWidgets
102 //  http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
103 //   In Visual C++ 6 (7 should be similar), to create an application that is both a console application 
104 //  (cout's to the console are visible) and has a wxWidgets GUI, 
105 //  you need to use the linker option "/subsystem:console" and the following code:
106 int main(int argc, char* argv[])
107 {
108         return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), SW_SHOWNORMAL);
109 }
110
111 #endif // defined(_WIN32) 
112
113
114 #else
115 //==========================================================================
116 // WITHOUT WX
117 //==========================================================================
118 #include <iostream>
119 int main(int argc, char* argv[])
120 {  
121   std::cout << "bbStudio was not compiled with wxWidgets : ciao !" <<std::endl;
122   return 0;
123 }
124
125 // EOF
126 #endif //#ifdef _USE_WXWIDGETS_
127
128
129