]> Creatis software - bbtk.git/blob - kernel/appli/bbPackageBrowser/bbPackageBrowser.cxx
Feature #1774
[bbtk.git] / kernel / appli / bbPackageBrowser / bbPackageBrowser.cxx
1 /*
2  # ---------------------------------------------------------------------
3  #
4  # Copyright (c) CREATIS (Centre de Recherche en Acquisition et Traitement de l'Image
5  #                        pour la SantÈ)
6  # Authors : Eduardo Davila, Frederic Cervenansky, Claire Mouton
7  # Previous Authors : Laurent Guigues, Jean-Pierre Roux
8  # CreaTools website : www.creatis.insa-lyon.fr/site/fr/creatools_accueil
9  #
10  #  This software is governed by the CeCILL-B license under French law and
11  #  abiding by the rules of distribution of free software. You can  use,
12  #  modify and/ or redistribute the software under the terms of the CeCILL-B
13  #  license as circulated by CEA, CNRS and INRIA at the following URL
14  #  http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
15  #  or in the file LICENSE.txt.
16  #
17  #  As a counterpart to the access to the source code and  rights to copy,
18  #  modify and redistribute granted by the license, users are provided only
19  #  with a limited warranty  and the software's author,  the holder of the
20  #  economic rights,  and the successive licensors  have only  limited
21  #  liability.
22  #
23  #  The fact that you are presently reading this means that you have had
24  #  knowledge of the CeCILL-B license and that you accept its terms.
25  # ------------------------------------------------------------------------ */
26
27
28 #ifdef _USE_WXWIDGETS_
29
30
31
32 //==========================================================================
33 // WITH WX
34 //==========================================================================
35 #include "bbtkInterpreter.h"
36 #include "bbtkWxGUIHtmlBrowser.h" 
37 #include "bbtkWxGUIPackageBrowser2.h" 
38
39 //#include "../../src/icons/cc_run.xpm"
40 #include "../../src/icons/cc_exit.xpm"
41
42 using namespace bbtk;
43
44 class /*BBTK_EXPORT*/ WxGUIHelp : public wxFrame
45 //                                            public InterpreterUser
46 {
47 public:
48   WxGUIHelp( wxWindow *parent, wxString title, wxSize size );
49   ~WxGUIHelp();
50   void OnButtonRun(wxCommandEvent& WXUNUSED(event));
51   void OnButtonQuit(wxCommandEvent& WXUNUSED(event));
52
53   //  WxGUIHtmlBrowser* mWxGUIHtmlBrowser;
54   WxGUIPackageBrowser2* mWxGUIPackageBrowser;
55   //  wxButton* mwxButtonRun;
56   wxButton* mwxButtonQuit;
57
58 //  bool InterpreterUserHasOwnHtmlPageViewer() { return false; }
59 //  void InterpreterUserViewHtmlPage(const std::string&) {} 
60
61   DECLARE_EVENT_TABLE(); 
62 };
63
64 enum
65   {
66     ID_Button_Run,
67     ID_Button_Quit
68   };
69
70 WxGUIHelp::WxGUIHelp( wxWindow *parent, wxString title, wxSize size )
71   : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
72 //                                         InterpreterUser()  
73
74   wxBoxSizer *helpsizer = new wxBoxSizer(wxVERTICAL);
75   // mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0));
76   //  helpsizer->Add (mWxGUIHtmlBrowser,1, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5  );
77   mWxGUIPackageBrowser = new WxGUIPackageBrowser2(this);
78   helpsizer->Add (mWxGUIPackageBrowser,1, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5  );
79
80   wxBoxSizer *btnsizer = new wxBoxSizer(wxHORIZONTAL);
81   /*
82   wxBitmap bmp_run(cc_run_xpm);
83   mwxButtonRun = new wxBitmapButton(this,ID_Button_Run,bmp_run);
84   btnsizer->Add( mwxButtonRun, 0, wxALL, 5  );
85   */
86   wxBitmap bmp_quit(cc_exit_xpm);
87   mwxButtonQuit = new wxBitmapButton(this,ID_Button_Quit,bmp_quit);
88   btnsizer->Add( mwxButtonQuit, 0, wxALL, 5  );
89
90   helpsizer->Add( btnsizer );
91
92   // Creates and sets the parent window of all bbtk windows
93   /*
94   wxWindow* top = new wxPanel(this,-1);//,_T("top"));
95   top->Hide();
96   Wx::SetTopWindow(top);
97   */
98
99   SetSizer(helpsizer);
100   SetAutoLayout(true);
101   Layout();
102
103   // mWxGUIHtmlBrowser->GoHome();
104   mWxGUIPackageBrowser->IncludeAll();
105 }
106
107 WxGUIHelp::~WxGUIHelp() {}
108
109 /*
110 void WxGUIHelp::OnButtonRun(wxCommandEvent& WXUNUSED(event))
111 {  
112   //std::string filename = wx2std(mWxGUIHtmlBrowser->GetCurrentPage());
113   std::string filename = mWxGUIHtmlBrowser->GetCurrentPage();
114   size_t s = filename.length();
115   
116   Interpreter::Pointer I = Interpreter::New();
117   I->SetThrow(true);
118
119   if ((s>3) && (filename[s-1]=='s')
120       && (filename[s-2]=='b')
121       && (filename[s-3]=='b')
122       && (filename[s-4]=='.'))
123     {
124       try 
125         {
126           I->InterpretFile(filename);
127         }
128       catch (QuitException e) 
129         {
130           std::cout << "QuitException caught"<<std::endl;
131         }
132       catch (Exception e)
133         {
134           wxString mess;
135           mess += std2wx ( e.GetMessage() );
136           wxMessageBox(mess,_T("Error"),wxOK | wxICON_ERROR);
137         }
138       catch (...)
139         {         
140           wxMessageBox(_T("Undefined error during script execution"),
141                        _T("Error"),wxOK | wxICON_ERROR);
142
143         }
144     }
145   else
146     {
147       wxMessageBox(_T("You can only execute .bbs script files (click on [source] in the field 'To use it' of a box) !"),_T("Warning"),wxOK | wxICON_ERROR);
148     }
149   
150   //delete I;
151 }
152 */
153
154 void WxGUIHelp::OnButtonQuit(wxCommandEvent& WXUNUSED(event))
155 {
156   Close();
157 }
158
159 //================================================================  
160 BEGIN_EVENT_TABLE(WxGUIHelp, wxFrame)
161 //  EVT_BUTTON(ID_Button_Run, WxGUIHelp::OnButtonRun )
162   EVT_BUTTON(ID_Button_Quit, WxGUIHelp::OnButtonQuit )
163 END_EVENT_TABLE()
164 //================================================================
165
166
167
168 class myApp : public wxApp
169 {
170 public:
171   bool OnInit( );
172   int  OnExit() { return true; }
173 };
174
175 IMPLEMENT_APP(myApp);
176
177
178 bool myApp::OnInit( )
179 {        
180   wxApp::OnInit();
181 #ifdef __WXGTK__
182   //See http://www.wxwindows.org/faqgtk.htm#locale
183   setlocale(LC_NUMERIC, "C");
184 #endif
185    wxInitAllImageHandlers();
186    
187    //  WxGUIHelp *I = new WxGUIHelp(0,_T("BBTK help browser"),wxSize(800,600));
188    
189    WxGUIPackageBrowser2Window*  I = 
190      new WxGUIPackageBrowser2Window(0,_T("bbtk help"),wxSize(1000,800));
191   SetTopWindow(I);  
192   I->Show(true);
193   return true;
194 }
195
196 /*
197 #if defined(_WIN32) 
198
199 //  How to have a Console and wxWidgets
200 //  http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
201 //   In Visual C++ 6 (7 should be similar), to create an application that is both a console application 
202 //  (cout's to the console are visible) and has a wxWidgets GUI, 
203 //  you need to use the linker option "/subsystem:console" and the following code:
204 int main(int argc, char* argv[])
205 {
206         return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), SW_SHOWNORMAL);
207 }
208 #endif // defined(_WIN32) 
209 */
210         
211 #else
212 //==========================================================================
213 // WITHOUT WX
214 //==========================================================================
215 int main(int argc, char* argv[])
216 {  
217   return 0;
218 }
219          
220 // EOF
221 #endif //#ifdef _USE_WXWIDGETS_
222
223
224