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