]> Creatis software - bbtk.git/blob - kernel/appli/bbPackageBrowser/bbPackageBrowser.cxx
*** empty log message ***
[bbtk.git] / kernel / appli / bbPackageBrowser / bbPackageBrowser.cxx
1 #ifdef _USE_WXWIDGETS_
2
3
4
5 //==========================================================================
6 // WITH WX
7 //==========================================================================
8 #include "bbtkInterpreter.h"
9 #include "bbtkWxGUIHtmlBrowser.h" 
10 #include "bbtkWxGUIPackageBrowser2.h" 
11
12 //#include "../../src/icons/cc_run.xpm"
13 #include "../../src/icons/cc_exit.xpm"
14
15 using namespace bbtk;
16
17 class /*BBTK_EXPORT*/ WxGUIHelp : public wxFrame
18 //                                            public InterpreterUser
19 {
20 public:
21   WxGUIHelp( wxWindow *parent, wxString title, wxSize size );
22   ~WxGUIHelp();
23   void OnButtonRun(wxCommandEvent& WXUNUSED(event));
24   void OnButtonQuit(wxCommandEvent& WXUNUSED(event));
25
26   //  WxGUIHtmlBrowser* mWxGUIHtmlBrowser;
27   WxGUIPackageBrowser2* mWxGUIPackageBrowser;
28   //  wxButton* mwxButtonRun;
29   wxButton* mwxButtonQuit;
30
31 //  bool InterpreterUserHasOwnHtmlPageViewer() { return false; }
32 //  void InterpreterUserViewHtmlPage(const std::string&) {} 
33
34   DECLARE_EVENT_TABLE(); 
35 };
36
37 enum
38   {
39     ID_Button_Run,
40     ID_Button_Quit
41   };
42
43 WxGUIHelp::WxGUIHelp( wxWindow *parent, wxString title, wxSize size )
44   : wxFrame((wxFrame *)parent, -1, title, wxDefaultPosition, size)
45 //                                         InterpreterUser()  
46
47   wxBoxSizer *helpsizer = new wxBoxSizer(wxVERTICAL);
48   // mWxGUIHtmlBrowser = new WxGUIHtmlBrowser(this,wxSize(200,0));
49   //  helpsizer->Add (mWxGUIHtmlBrowser,1, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5  );
50   mWxGUIPackageBrowser = new WxGUIPackageBrowser2(this);
51   helpsizer->Add (mWxGUIPackageBrowser,1, wxGROW|wxLEFT|wxRIGHT|wxTOP, 5  );
52
53   wxBoxSizer *btnsizer = new wxBoxSizer(wxHORIZONTAL);
54   /*
55   wxBitmap bmp_run(cc_run_xpm);
56   mwxButtonRun = new wxBitmapButton(this,ID_Button_Run,bmp_run);
57   btnsizer->Add( mwxButtonRun, 0, wxALL, 5  );
58   */
59   wxBitmap bmp_quit(cc_exit_xpm);
60   mwxButtonQuit = new wxBitmapButton(this,ID_Button_Quit,bmp_quit);
61   btnsizer->Add( mwxButtonQuit, 0, wxALL, 5  );
62
63   helpsizer->Add( btnsizer );
64
65   // Creates and sets the parent window of all bbtk windows
66   /*
67   wxWindow* top = new wxPanel(this,-1);//,_T("top"));
68   top->Hide();
69   Wx::SetTopWindow(top);
70   */
71
72   SetSizer(helpsizer);
73   SetAutoLayout(true);
74   Layout();
75
76   // mWxGUIHtmlBrowser->GoHome();
77   mWxGUIPackageBrowser->IncludeAll();
78 }
79
80 WxGUIHelp::~WxGUIHelp() {}
81
82 /*
83 void WxGUIHelp::OnButtonRun(wxCommandEvent& WXUNUSED(event))
84 {  
85   //std::string filename = wx2std(mWxGUIHtmlBrowser->GetCurrentPage());
86   std::string filename = mWxGUIHtmlBrowser->GetCurrentPage();
87   size_t s = filename.length();
88   
89   Interpreter::Pointer I = Interpreter::New();
90   I->SetThrow(true);
91
92   if ((s>3) && (filename[s-1]=='s')
93       && (filename[s-2]=='b')
94       && (filename[s-3]=='b')
95       && (filename[s-4]=='.'))
96     {
97       try 
98         {
99           I->InterpretFile(filename);
100         }
101       catch (QuitException e) 
102         {
103           std::cout << "QuitException caught"<<std::endl;
104         }
105       catch (Exception e)
106         {
107           wxString mess;
108           mess += std2wx ( e.GetMessage() );
109           wxMessageBox(mess,_T("Error"),wxOK | wxICON_ERROR);
110         }
111       catch (...)
112         {         
113           wxMessageBox(_T("Undefined error during script execution"),
114                        _T("Error"),wxOK | wxICON_ERROR);
115
116         }
117     }
118   else
119     {
120       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);
121     }
122   
123   //delete I;
124 }
125 */
126
127 void WxGUIHelp::OnButtonQuit(wxCommandEvent& WXUNUSED(event))
128 {
129   Close();
130 }
131
132 //================================================================  
133 BEGIN_EVENT_TABLE(WxGUIHelp, wxFrame)
134 //  EVT_BUTTON(ID_Button_Run, WxGUIHelp::OnButtonRun )
135   EVT_BUTTON(ID_Button_Quit, WxGUIHelp::OnButtonQuit )
136 END_EVENT_TABLE()
137 //================================================================
138
139
140
141 class myApp : public wxApp
142 {
143 public:
144   bool OnInit( );
145   int  OnExit() { return true; }
146 };
147
148 IMPLEMENT_APP(myApp);
149
150
151 bool myApp::OnInit( )
152 {        
153   wxApp::OnInit();
154 #ifdef __WXGTK__
155   //See http://www.wxwindows.org/faqgtk.htm#locale
156   setlocale(LC_NUMERIC, "C");
157 #endif
158    wxInitAllImageHandlers();
159    
160    //  WxGUIHelp *I = new WxGUIHelp(0,_T("BBTK help browser"),wxSize(800,600));
161    
162    WxGUIPackageBrowser2Window*  I = 
163      new WxGUIPackageBrowser2Window(0,_T("bbtk help"),wxSize(1000,800));
164   SetTopWindow(I);  
165   I->Show(true);
166   return true;
167 }
168
169 /*
170 #if defined(_WIN32) 
171
172 //  How to have a Console and wxWidgets
173 //  http://www.wxwidgets.org/wiki/index.php/MSVC_Setup_Guide
174 //   In Visual C++ 6 (7 should be similar), to create an application that is both a console application 
175 //  (cout's to the console are visible) and has a wxWidgets GUI, 
176 //  you need to use the linker option "/subsystem:console" and the following code:
177 int main(int argc, char* argv[])
178 {
179         return WinMain(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), SW_SHOWNORMAL);
180 }
181 #endif // defined(_WIN32) 
182 */
183         
184 #else
185 //==========================================================================
186 // WITHOUT WX
187 //==========================================================================
188 int main(int argc, char* argv[])
189 {  
190   return 0;
191 }
192          
193 // EOF
194 #endif //#ifdef _USE_WXWIDGETS_
195
196
197