1 #include "StdAfx.h"
2 
3 // For compilers that support precompilation, includes "wx/wx.h".
4 #include "wx/wxprec.h"
5 
6 #ifdef __BORLANDC__
7 #pragma hdrstop
8 #endif
9 
10 #ifndef WX_PRECOMP
11 #include "wx/wx.h"
12 #endif
13 
14 #include "wx/mimetype.h"
15 #include "wx/artprov.h"
16 #include "wx/imaglist.h"
17 
18 #include "resource.h"
19 
20 #include "App.h"
21 
22 #include "Windows/Control/DialogImpl.h"
23 #include "Windows/Control/ListView.h"
24 #include "Windows/Control/Window2.h"
25 
26 // FIXME
27 #undef IDCLOSE
28 #define IDCLOSE wxID_EXIT
29 
30 #define static const
31 #include "../GUI/p7zip_32.xpm"
32 #undef static
33 
34 extern HWND g_HWND;
35 
36 #define BASE_ID_PANEL_1 (1000 + 100 * 0)
37 #define BASE_ID_PANEL_2 (1000 + 100 * 1)
38 
39 ////////////////////////////////////// Tool bar images
40 #include "res/AddPNG.h"
41 #include "res/Add2PNG.h"
42 #include "res/ExtractPNG.h"
43 #include "res/Extract2PNG.h"
44 #include "res/TestPNG.h"
45 #include "res/Test2PNG.h"
46 #include "res/CopyPNG.h"
47 #include "res/Copy2PNG.h"
48 #include "res/MovePNG.h"
49 #include "res/Move2PNG.h"
50 #include "res/DeletePNG.h"
51 #include "res/Delete2PNG.h"
52 #include "res/InfoPNG.h"
53 #include "res/Info2PNG.h"
54 
55 #include <wx/mstream.h>
56 #define wxGetBitmapFromMemory(name) _wxGetBitmapFromMemory(name ## _png, sizeof(name ## _png))
57 
_wxGetBitmapFromMemory(const unsigned char * data,int length)58 static inline wxBitmap _wxGetBitmapFromMemory(const unsigned char *data, int length) {
59 	wxMemoryInputStream is(data, length);
60 	return wxBitmap(wxImage(is, wxBITMAP_TYPE_ANY, -1), -1);
61 }
62 
63 ///////////////////////////////////// SevenZipPanel.h /////////////////////
64 
65 #include <wx/listctrl.h>
66 
67 typedef wxListCtrl CExplorerListCtrl;
68 
69 class MyFrame;
70 
71 class SevenZipPanel : public wxPanel
72 {
73 	static int count;
74 
75 	CExplorerListCtrl *m_pListCtrlExplorer;
76 	NWindows::NControl::CWindow2 *_wList;
77 
78 
79 	wxBitmapButton *m_pBmpButtonParentFolder;
80 	wxComboBox *m_pComboBoxPath;
81 	wxStatusBar *m_pStatusBar;
82 
83 	MyFrame *m_frame;
84 
85 	wxImageList imgList;
86 
87 	int _panelIndex;
88 
89 	// wxString m_currentDirectory;
90 
91 	// int m_nbDirs;
92 
93 	// wxString m_prompt;
94 
95 public:
96 	SevenZipPanel(MyFrame *frame, wxWindow *parent,int id,int panelIndex);
97 
registerWindow2(NWindows::NControl::CWindow2 * w)98 	void registerWindow2(NWindows::NControl::CWindow2 *w)
99 	{
100 		_wList = w;
101 		_wList->OnMessage(WM_CREATE,0,0);
102 	}
103 
104 	void OnAnyButton( wxCommandEvent &event );
105 	void OnSelected(wxListEvent& event);
106 	void OnDeselected(wxListEvent& event);
107 	void OnActivated(wxListEvent& event);
108 	void OnFocused(wxListEvent& event);
109 	void OnLeftDownBeginDrag(wxListEvent& event);
110 	void OnRightClick(wxListEvent& event);
111 	void OnColumnClick(wxListEvent& event);
112 
113 	void OnLeftDown(wxMouseEvent &event );
114 	void OnRightDown(wxMouseEvent &event );
115 
WriteText(const wxString & text)116         void WriteText(const wxString& text) {
117 		printf("DEBUG : %ls\n",(const wchar_t *)text);
118         }
119 
120 	/* Don't work ...
121 	void OnCloseWindow(wxCloseEvent& WXUNUSED(event)) {
122 		_wList->OnDestroy();
123 	}
124 	*/
125 
evt_destroy()126 	void evt_destroy() {
127 		_wList->OnDestroy();
128 	}
129 
130 
131 private:
132 		DECLARE_EVENT_TABLE()
133 };
134 
135 
136 
137 ///////////////////////////////////// SevenZipPanel.h /////////////////////
138 
139 
140 
141 class MyFrame: public wxFrame
142 {
143 public:
144     // ctor
145  MyFrame(void (*fct)(HWND),wxFrame *frame, const wxString& title, int x, int y, int w, int h);
146     // virtual ~MyFrame();
147 
registerWindow2(int baseID,NWindows::NControl::CWindow2 * w)148 	void registerWindow2(int baseID,NWindows::NControl::CWindow2 *w)
149 	{
150 		printf("MyFrame::registerWindow2(%d,%p)\n",baseID,w);
151 		switch (baseID)
152 		{
153 			case BASE_ID_PANEL_1: _panel1->registerWindow2(w); break;
154 			case BASE_ID_PANEL_2: _panel2->registerWindow2(w); break;
155 			default: printf("FIXME - MyFrame::registerWindow2\n");
156 		}
157 	}
158 
159 	void PopulateToolbar(wxToolBar* toolBar);
160 	void RecreateToolbar();
161 
162 
163 protected:
164 	// callbacks
165 	void OnWorkerEvent(wxCommandEvent& event);
OnAnyMenu(wxCommandEvent & event)166 	void OnAnyMenu(wxCommandEvent& event)
167 	{
168 		extern bool OnMenuCommand(HWND hWnd, int id);
169 		extern void ExecuteCommand(UINT commandID);
170 
171 		int wmId = event.GetId();
172 
173 		if (wmId >= kToolbarStartID)
174 		{
175 			ExecuteCommand(wmId);
176 			return ; // 0;
177 		}
178 		OnMenuCommand(this, wmId);
179 	}
OnCloseWindow(wxCloseEvent & WXUNUSED (event))180 	void OnCloseWindow(wxCloseEvent& WXUNUSED(event))
181 	{
182 		if (_panel1) _panel1->evt_destroy();
183 		if (_panel2) _panel2->evt_destroy();
184 
185 		extern void main_WM_DESTROY();
186 		main_WM_DESTROY();
187 		Destroy();
188 	}
189 private:
190 	SevenZipPanel * _panel1;
191 	SevenZipPanel * _panel2;
192     DECLARE_EVENT_TABLE()
193 };
194 
195 enum {
196     WORKER_EVENT=100    // this one gets sent from the worker thread
197 };
198 
BEGIN_EVENT_TABLE(MyFrame,wxFrame)199 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
200 	EVT_MENU(WORKER_EVENT, MyFrame::OnWorkerEvent)
201 	EVT_MENU(wxID_ANY, MyFrame::OnAnyMenu)
202 	EVT_CLOSE(MyFrame::OnCloseWindow)
203 END_EVENT_TABLE()
204 
205 // My frame constructor
206 MyFrame::MyFrame(void (*wm_create)(HWND),wxFrame *frame, const wxString& title,
207                  int x, int y, int w, int h)
208        : wxFrame(frame, wxID_ANY, title, wxPoint(x, y), wxSize(w, h))
209 {
210 printf("===MyFrame::MyFrame===BEGIN===\n");
211 
212 	this->SetIcon(wxICON(p7zip_32));
213 
214 	g_HWND = this; // FIXME
215 
216 	wxBoxSizer *topsizer = new wxBoxSizer( wxVERTICAL );
217 
218 	_panel1 = new SevenZipPanel(this,this,BASE_ID_PANEL_1,0);  // FIXME panelIndex = 0
219 	_panel2 = 0;
220 	topsizer->Add(
221 		_panel1,
222 		1,            // make vertically stretchable
223 		wxEXPAND |    // make horizontally stretchable
224 		wxALL,        //   and make border all around
225 		0 );         // set border width to 10
226 
227 	// Create the toolbar
228 	// FIXME RecreateToolbar();
229 printf("===MyFrame::MyFrame===WM_CREATE===\n");
230        wm_create(this);
231 
232        // Create the toolbar // FIXME
233 	RecreateToolbar();
234 
235 
236 printf("===MyFrame::MyFrame===SIZER===\n");
237 
238 	SetSizer( topsizer );      // use the sizer for layout
239 
240 	topsizer->SetSizeHints( this );   // set size hints to honour minimum size
241 printf("===MyFrame::MyFrame===END===\n");
242 }
243 
244 void myCreateHandle(int n);
OnWorkerEvent(wxCommandEvent & event)245 void MyFrame::OnWorkerEvent(wxCommandEvent& event)
246 {
247 	int n = event.GetInt();
248 	myCreateHandle(n);
249 }
250 
251 wxWindow * g_window=0;
myCreateAndShowMainWindow(LPCTSTR title,void (* fct)(HWND))252 HWND myCreateAndShowMainWindow(LPCTSTR title,void (*fct)(HWND))
253 {
254     MyFrame *frame = new MyFrame(fct,(wxFrame *)NULL, title, 50, 50, 450, 340);
255    // Don't Show the frame !
256    frame->Show(true); // FIXME
257 
258    // FIXME : SetTopWindow(g_HWND);
259 
260    g_window = frame;
261 
262    return frame;
263 }
264 
265 
266 class myToolBar
267 {
268 	wxToolBar * m_toolbar;
269 
270 	bool m_bShowText;
271 
272 public:
myToolBar(wxToolBar * toolbar,bool bShowText)273 	myToolBar(wxToolBar * toolbar,bool bShowText ) : m_toolbar(toolbar), m_bShowText(bShowText)  { }
274 
AddTool(int toolId,const wxString & label,const wxBitmap & bitmap1,const wxString & shortHelpString=_T (""),wxItemKind kind=wxITEM_NORMAL)275 	myToolBar* AddTool(int toolId, const wxString& label, const wxBitmap& bitmap1, const wxString& shortHelpString = _T(""), wxItemKind kind = wxITEM_NORMAL)
276 	{
277 		wxString text = wxEmptyString;
278 		if (m_bShowText) text = label;
279 
280 		wxSize tb_size = m_toolbar->GetToolBitmapSize();
281 		int tb_witdh = tb_size.GetWidth();
282 		int tb_height = tb_size.GetHeight();
283 
284 		if ((bitmap1.GetWidth() > tb_witdh) || ( bitmap1.GetHeight()> tb_height))
285 		{
286 			wxBitmap bmp(bitmap1.ConvertToImage().Scale(tb_witdh, tb_height));
287 			m_toolbar->AddTool(toolId,text,bmp,shortHelpString,kind);
288 		}
289 		else
290 		{
291 			m_toolbar->AddTool(toolId,text,bitmap1,shortHelpString,kind);
292 		}
293 
294 		return this;
295 	}
296 
SetToolBitmapSize(const wxSize & size)297 	void SetToolBitmapSize(const wxSize& size)
298 	{
299 		m_toolbar->SetToolBitmapSize(size);
300 	}
301 
Realize()302 	bool Realize()
303 	{
304 		return m_toolbar->Realize();
305 	}
306 
AddSeparator()307 	void AddSeparator() { m_toolbar->AddSeparator(); }
308 };
309 
PopulateToolbar(wxToolBar * p_toolBar)310 void MyFrame::PopulateToolbar(wxToolBar* p_toolBar)
311 {/*
312  toolBar->AddTool(wxID_NEW, _T("New"),toolBarBitmaps[Tool_new], wxNullBitmap, wxITEM_NORMAL,
313  _T("New file"), _T("This is help for new file tool"));
314  */
315 	myToolBar toolBar(p_toolBar,true);
316 
317 	const int kWidth  = 24;
318 	const int kHeight = 24;
319 
320 	// FIXME toolBar->SetToolBitmapSize(wxSize(24,24));
321 	toolBar.SetToolBitmapSize(wxSize(kWidth,kHeight));
322 	toolBar.AddTool(kAddCommand, wxT("Add"), wxGetBitmapFromMemory(ADD2));
323 	toolBar.AddTool(kExtractCommand,wxT("Extract"), wxGetBitmapFromMemory(EXTRACT2));
324 	toolBar.AddTool(kTestCommand, wxT("Test"), wxGetBitmapFromMemory(TEST2));
325 
326 	toolBar.AddSeparator();
327 
328 	toolBar.AddTool(IDM_COPY_TO, wxT("Copy"), wxGetBitmapFromMemory(COPY2));
329 	toolBar.AddTool(IDM_MOVE_TO, wxT("Move"), wxGetBitmapFromMemory(MOVE2));
330 	toolBar.AddTool(IDM_DELETE, wxT("Delete"), wxGetBitmapFromMemory(DELETE2));
331 	toolBar.AddTool(IDM_FILE_PROPERTIES, wxT("Info"), wxGetBitmapFromMemory(INFO2));
332 
333 	////////////////////////////////////////////////////////
334 
335 	/* FIXME
336 	if (g_mimeDatabase)
337 	{
338 		toolBar.AddSeparator();
339 
340 		TryMime(&toolBar, _T("txt"));
341 		TryMime(&toolBar, _T("rar"));
342 		TryMime(&toolBar, _T("7z"));
343 	}
344 
345 	toolBar.AddSeparator();
346 
347 	wxIcon i_plus = wxArtProvider::GetIcon(wxART_ADD_BOOKMARK    , wxART_TOOLBAR  , wxSize(kWidth,kHeight));
348 	toolBar.AddTool(wxID_ANY, wxT("Add Bookmark"), i_plus);
349 
350 	wxIcon i_go_up_dir = wxArtProvider::GetIcon(wxART_GO_DIR_UP   , wxART_TOOLBAR  , wxSize(kWidth,kHeight));
351 	toolBar.AddTool(wxID_ANY, wxT("Go up dir"), i_go_up_dir);
352 
353 	wxIcon i_folder = wxArtProvider::GetIcon(wxART_FOLDER   , wxART_TOOLBAR  , wxSize(kWidth,kHeight));
354 	toolBar.AddTool(wxID_ANY, wxT("Folder"), i_folder);
355 
356 	wxIcon i_missing_image = wxArtProvider::GetIcon(wxART_MISSING_IMAGE   , wxART_TOOLBAR  , wxSize(kWidth,kHeight));
357 	toolBar.AddTool(wxID_ANY, wxT("missing image"), i_missing_image);
358 	*/
359 
360 	///////////////////////////////////////////////////////
361 
362 	toolBar.Realize();
363 
364 	// toolBar->SetRows(!(toolBar->IsVertical()) ? m_rows : 10 / m_rows);
365 }
RecreateToolbar()366 void MyFrame::RecreateToolbar()
367 {
368 	// delete and recreate the toolbar
369 	wxToolBar *toolBar = GetToolBar();
370 	// long style = toolBar ? toolBar->GetWindowStyle() : TOOLBAR_STYLE;
371 
372 	SetToolBar(NULL);
373 
374 	delete toolBar;
375 	/*
376 	style &= ~(wxTB_HORIZONTAL | wxTB_VERTICAL | wxTB_BOTTOM | wxTB_RIGHT | wxTB_HORZ_LAYOUT);
377 	switch( m_toolbarPosition )
378 	{
379 	case TOOLBAR_LEFT:style |= wxTB_LEFT; break;
380 	case TOOLBAR_TOP: style |= wxTB_TOP;break;
381 	case TOOLBAR_RIGHT:style |= wxTB_RIGHT;break;
382 	case TOOLBAR_BOTTOM:style |= wxTB_BOTTOM;break;
383 	}
384 	*/
385 	long style = wxTB_FLAT | wxTB_NODIVIDER | wxTB_TEXT; // TOOLBAR_STYLE | wxTB_TOP;
386 	/*
387 	if ( m_showTooltips ) style &= ~wxTB_NO_TOOLTIPS;
388 	else                  style |= wxTB_NO_TOOLTIPS;
389 
390 	if ( style & wxTB_TEXT && !(style & wxTB_NOICONS) && m_horzText ) style |= wxTB_HORZ_LAYOUT;
391 	*/
392 	toolBar = CreateToolBar(style, wxID_ANY);
393 
394 	PopulateToolbar(toolBar);
395 }
396 
registerWindow2(int baseID,NWindows::NControl::CWindow2 * w)397 void registerWindow2(int baseID,NWindows::NControl::CWindow2 *w)
398 {
399 	MyFrame * f = (MyFrame *) g_HWND;
400 	f->registerWindow2(baseID,w);
401 
402 }
403 
404 
405 /////////////////////////////////////////////////////////
406 #include "LangUtils.h"
407 
408 static const UINT kOpenBookmarkMenuID = 730;  // FIXME / duplicate
409 static const UINT kSetBookmarkMenuID = 740;
410 
411 
rc_MyLoadMenu(HWND hWnd)412 void rc_MyLoadMenu(HWND hWnd)
413 {
414 	wxFrame *hwnd = (wxFrame *)hWnd;
415 	wxMenu *m;
416 	wxMenu *m_file = m = new wxMenu;
417 	{
418 		m->Append(IDM_FILE_OPEN, _T("&Open\tEnter"));
419 		m->Append(IDM_FILE_OPEN_INSIDE,_T("Open &Inside\tCtrl+PgDn"));
420 		m->Append(IDM_FILE_OPEN_OUTSIDE,_T("Open O&utside\tShift+Enter"));
421 		m->Append(IDM_FILE_EDIT,_T("&Edit\tF4"));
422 		m->AppendSeparator();
423 		m->Append(IDM_RENAME,_T("Rena&me\tF2"));
424 		m->Append(IDM_COPY_TO,_T("&Copy To...\tF5"));
425 		m->Append(IDM_MOVE_TO,_T("&Move To...\tF6"));
426 		m->Append(IDM_DELETE,_T("&Delete\tDel"));
427 		m->AppendSeparator();
428 		m->Append(IDM_FILE_SPLIT,_T("&Split file..."));
429 		m->Append(IDM_FILE_COMBINE,_T("Com&bine files..."));
430 		m->AppendSeparator();
431 		m->Append(IDM_FILE_PROPERTIES,_T("P&roperties\tAlt+Enter"));
432 		m->Append(IDM_FILE_COMMENT,_T("Comme&nt\tCtrl+Z"));
433 		m->Append(IDM_FILE_CRC,_T("Calculate checksum"));
434 		m->AppendSeparator();
435 		m->Append(IDM_CREATE_FOLDER,_T("Create Folder\tF7"));
436 		m->Append(IDM_CREATE_FILE,_T("Create File\tCtrl+N"));
437 		m->AppendSeparator();
438 		m->Append(IDCLOSE,_T("E&xit\tAlt+F4"));
439 	}
440 	wxMenu *m_edit = m = new wxMenu;
441 	{
442 		m->Append(IDM_EDIT_CUT, _T("Cu&t\tCtrl+X"))->Enable(true);              // GRAYED
443 		// m->Enable(IDM_EDIT_CUT, false);
444 		m->Append(IDM_EDIT_COPY, _T("&Copy\tCtrl+C"))->Enable(true);            // GRAYED
445 		m->Append(IDM_EDIT_PASTE, _T("&Paste\tCtrl+V"))->Enable(true);          // GRAYED
446 		m->AppendSeparator();
447 		m->Append(IDM_SELECT_ALL, _T("Select &All\tShift+[Grey +]"));
448 		m->Append(IDM_DESELECT_ALL, _T("Deselect All\tShift+[Grey -]"));
449 		m->Append(IDM_INVERT_SELECTION, _T("&Invert Selection\tGrey *"));
450 		m->Append(IDM_SELECT, _T("Select...\tGrey +"));
451 		m->Append(IDM_DESELECT, _T("Deselect...\tGrey -"));
452 		m->Append(IDM_SELECT_BY_TYPE, _T("Select by Type\tAlt+[Grey+]"));
453 		m->Append(IDM_DESELECT_BY_TYPE, _T("Deselect by Type\tAlt+[Grey -]"));
454 	}
455 	wxMenu *m_view = m = new wxMenu;
456 	{
457 		m->AppendRadioItem(IDM_VIEW_LARGE_ICONS, _T("Lar&ge Icons\tCtrl+1"));
458 		m->AppendRadioItem(IDM_VIEW_SMALL_ICONS, _T("S&mall Icons\tCtrl+2"));
459 		m->AppendRadioItem(IDM_VIEW_LIST, _T("&List\tCtrl+3"));
460 		m->AppendRadioItem(IDM_VIEW_DETAILS, _T("&Details\tCtrl+4"))->Check(true);  // CHECKED
461 		m->AppendSeparator();
462 		m->Append(IDM_VIEW_ARANGE_BY_NAME, _T("Name\tCtrl+F3"));
463 		m->Append(IDM_VIEW_ARANGE_BY_TYPE, _T("Type\tCtrl+F4"));
464 		m->Append(IDM_VIEW_ARANGE_BY_DATE, _T("Date\tCtrl+F5"));
465 		m->Append(IDM_VIEW_ARANGE_BY_SIZE, _T("Size\tCtrl+F6"));
466 		m->Append(IDM_VIEW_ARANGE_NO_SORT, _T("Unsorted\tCtrl+F7"));
467 		m->AppendSeparator();
468 		m->AppendCheckItem(IDM_VIEW_FLAT_VIEW, _T("Flat View"));
469 		m->AppendCheckItem(IDM_VIEW_TWO_PANELS, _T("&2 Panels\tF9"));
470 
471 		{
472 			wxMenu* subMenu = new wxMenu;
473 			subMenu->AppendCheckItem(IDM_VIEW_ARCHIVE_TOOLBAR, _T("Archive Toolbar"));
474 			subMenu->AppendCheckItem(IDM_VIEW_STANDARD_TOOLBAR, _T("Standard Toolbar"));
475 			subMenu->AppendSeparator();
476 			subMenu->AppendCheckItem(IDM_VIEW_TOOLBARS_LARGE_BUTTONS, _T("Large Buttons"));
477 			subMenu->AppendCheckItem(IDM_VIEW_TOOLBARS_SHOW_BUTTONS_TEXT, _T("Show Buttons Text"));
478 			m->Append(12112, _T("Toolbars"), subMenu); // FIXME ID ?
479 		}
480 		m->AppendSeparator();
481 		m->Append(IDM_OPEN_ROOT_FOLDER, _T("Open Root Folder\t" STRING_PATH_SEPARATOR));
482 		m->Append(IDM_OPEN_PARENT_FOLDER, _T("Up One Level\tBackspace"));
483 		m->Append(IDM_FOLDERS_HISTORY, _T("Folders History...\tAlt+F12"));
484 		m->AppendSeparator();
485 		m->Append(IDM_VIEW_REFRESH, _T("&Refresh\tCtrl+R"));
486 	}
487 	wxMenu *m_favorites = m = new wxMenu;
488 	{
489 		{
490 			wxMenu* subMenu = new wxMenu;
491 			for (int i = 0; i < 10; i++)
492 			{
493 				UString s = LangString(IDS_BOOKMARK, 0x03000720);
494 				s += L" ";
495 				wchar_t c = (wchar_t)(L'0' + i);
496 				s += c;
497 				s += L"\tAlt+Shift+";
498 				s += c;
499 				subMenu->Append( kSetBookmarkMenuID + i, wxString(s));
500 			}
501 
502 			m->Append(12111, _T("&Add folder to Favorites as"), subMenu); // FIXME ID ?
503 		}
504 		m->AppendSeparator();
505 		for (int i = 0; i < 10; i++)
506 		{
507 			UString path = g_App.AppState.FastFolders.GetString(i);
508 			const int kMaxSize = 100;
509 			const int kFirstPartSize = kMaxSize / 2;
510 			if (path.Length() > kMaxSize)
511 			{
512 				path = path.Left(kFirstPartSize) + UString(L" ... ") +
513 					path.Right(kMaxSize - kFirstPartSize);
514 			}
515 			UString s = path;
516 			if (s.IsEmpty())
517 				s = L"-";
518 			s += L"\tAlt+";
519 			s += (wchar_t)(L'0' + i);
520 			// menu.AppendItem(MF_STRING, kOpenBookmarkMenuID + i, s);
521 			m->Append( kOpenBookmarkMenuID + i, wxString(s));
522 		}
523 
524 	}
525 	wxMenu *m_tools = m = new wxMenu;
526 	{
527 		m->Append(IDM_OPTIONS, _T("&Options..."));
528 		m->Append(IDM_BENCHMARK, _T("&Benchmark"));
529 	}
530 	wxMenu *m_help = m = new wxMenu;
531 	{
532 		m->Append(IDM_HELP_CONTENTS, _T("&Contents...\tF1"));
533 		m->AppendSeparator();
534 		m->Append(IDM_ABOUT, _T("&About 7-Zip..."));
535 	}
536 
537 	wxMenuBar *menuBar = new wxMenuBar;
538 
539 	menuBar->Append(m_file, _T("&File"));
540 	menuBar->Append(m_edit, _T("&Edit"));
541 	menuBar->Append(m_view, _T("&View"));
542 	menuBar->Append(m_favorites, _T("F&avorites"));
543 	menuBar->Append(m_tools, _T("&Tools"));
544 	menuBar->Append(m_help, _T("&Help"));
545 	hwnd->SetMenuBar(menuBar);
546 }
547 
548 //////////////////////////////////////////////////////////////////
549 
550 
551 static CStringTable g_stringTable[] =
552 {
553   /* resource.rc */
554   /***************/
555 	{ IDS_APP_TITLE, L"7-Zip File Manager" },
556 
557 	{ IDS_COPY                , L"Copy" },
558 	{ IDS_MOVE                , L"Move" },
559 	{ IDS_COPY_TO             , L"Copy to:" },
560 	{ IDS_MOVE_TO             , L"Move to:" },
561 	{ IDS_COPYING             , L"Copying..." },
562 	{ IDS_MOVING              , L"Moving..." },
563 	{ IDS_CANNOT_COPY         , L"You cannot move or copy items for such folders." },
564 	{ IDS_SPLITTING           , L"Splitting..." },
565 	{ IDS_SPLIT_CONFIRM_TITLE , L"Confirm Splitting" },
566 	{ IDS_SPLIT_CONFIRM_MESSAGE , L"Are you sure you want to split file into {0} volumes?" },
567 	{ IDS_SPLIT_VOL_MUST_BE_SMALLER , L"Volume size must be smaller than size of original file" },
568 
569 	{ IDS_COMBINE             , L"Combine Files" },
570 	{ IDS_COMBINE_TO          , L"&Combine to:" },
571 	{ IDS_COMBINING           , L"Combining..." },
572 	{ IDS_COMBINE_SELECT_ONE_FILE , L"Select only first file" },
573 
574 	{ IDS_CHECKSUM_CALCULATING , L"Checksum calculating..." },
575 	{ IDS_CHECKSUM_INFORMATION , L"Checksum information" },
576 	{ IDS_CHECKSUM_CRC_DATA     , L"CRC checksum for data:" },
577 	{ IDS_CHECKSUM_CRC_DATA_NAMES , L"CRC checksum for data and names:" },
578 
579 	{ IDS_SCANNING , L"Scanning..." },
580 
581 	{ IDS_PROPERTIES , L"Properties" },
582 
583 	{ IDS_OPERATION_IS_NOT_SUPPORTED , L"Operation is not supported." },
584 
585 	{ IDS_CONFIRM_FILE_DELETE , L"Confirm File Delete" },
586 	{ IDS_CONFIRM_FOLDER_DELETE , L"Confirm Folder Delete" },
587 	{ IDS_CONFIRM_ITEMS_DELETE , L"Confirm Multiple File Delete" },
588 	{ IDS_WANT_TO_DELETE_FILE , L"Are you sure you want to delete '{0}'?" },
589 	{ IDS_WANT_TO_DELETE_FOLDER , L"Are you sure you want to delete the folder '{0}' and all its contents?" },
590 	{ IDS_WANT_TO_DELETE_ITEMS  , L"Are you sure you want to delete these {0} items?" },
591 	{ IDS_DELETING            , L"Deleting..." },
592 	{ IDS_ERROR_DELETING      , L"Error Deleting File or Folder" },
593 	{ IDS_RENAMING            , L"Renaming..." },
594 	{ IDS_ERROR_RENAMING      , L"Error Renaming File or Folder" },
595 	{ IDS_CONFIRM_FILE_COPY   , L"Confirm File Copy" },
596 	{ IDS_WANT_TO_COPY_FILES  , L"Are you sure you want to copy files to archive" },
597 
598 	{ IDS_CREATE_FOLDER       , L"Create Folder" },
599 	{ IDS_CREATE_FOLDER_NAME  , L"Folder name:" },
600 	{ IDS_CREATE_FOLDER_DEFAULT_NAME , L"New Folder" },
601 	{ IDS_CREATE_FOLDER_ERROR , L"Error Creating Folder" },
602 	{ IDS_CREATE_FILE         , L"Create File" },
603 	{ IDS_CREATE_FILE_NAME    , L"File Name:" },
604 	{ IDS_CREATE_FILE_DEFAULT_NAME , L"New File" },
605 	{ IDS_CREATE_FILE_ERROR   , L"Error Creating File" },
606 	{ IDS_SELECT              , L"Select" },
607 	{ IDS_DESELECT            , L"Deselect" },
608 	{ IDS_SELECT_MASK         , L"Mask:" },
609 	{ IDS_FOLDERS_HISTORY     , L"Folders History" },
610 	{ IDS_N_SELECTED_ITEMS    , L"{0} object(s) selected" },
611 	{ IDS_FILES_COLON         , L"Files:" },
612 	{ IDS_FOLDERS_COLON       , L"Folders:" },
613 	{ IDS_SIZE_COLON          , L"Size:" },
614 
615 	{ IDS_PROP_TOTAL_SIZE     , L"Total Size" },
616 	{ IDS_PROP_FREE_SPACE     , L"Free Space" },
617 	{ IDS_PROP_CLUSTER_SIZE   , L"Cluster Size" },
618 	{ IDS_PROP_VOLUME_NAME    , L"Label" },
619 	{ IDS_PROP_LOCAL_NAME     , L"Local Name" },
620 	{ IDS_PROP_PROVIDER       , L"Provider" },
621 	{ IDS_OPTIONS             , L"Options" },
622 	{ IDS_COMMENT             , L"Comment" },
623 	{ IDS_COMMENT2            , L"&Comment:" },
624 	{ IDS_SYSTEM              , L"System" },
625 	{ IDS_TOO_MANY_ITEMS      , L"Too many items" },
626 	{ IDS_WANT_UPDATE_MODIFIED_FILE , L"File '{0}' was modified.\nDo you want to update it in the archive?" },
627 	{ IDS_CANNOT_UPDATE_FILE  , L"Can not update file\n'{0}'" },
628 	{ IDS_CANNOT_START_EDITOR , L"Cannot start editor." },
629 	{ IDS_OPENNING            , L"Opening..." },
630 	{ IDS_ADD                 , L"Add" },
631 	{ IDS_EXTRACT             , L"Extract" },
632 	{ IDS_TEST                , L"Test" },
633 	{ IDS_BUTTON_COPY         , L"Copy" },
634 	{ IDS_BUTTON_MOVE         , L"Move" },
635 	{ IDS_BUTTON_DELETE       , L"Delete" },
636 	{ IDS_BUTTON_INFO         , L"Info" },
637 	{ IDS_BOOKMARK            , L"Bookmark" },
638 	{ IDS_COMPUTER            , L"Computer" },
639 	{ IDS_NETWORK             , L"Network" },
640 
641 	{ IDS_PROGRESS_TESTING    , L"Testing" },
642 	{ IDS_MESSAGE_NO_ERRORS   , L"There are no errors" },
643 
644 	{ 0 , 0 }
645 };
646 
REGISTER_STRINGTABLE(g_stringTable)647 REGISTER_STRINGTABLE(g_stringTable)
648 
649 /////////////////////////////////////////////////////
650 
651 #include "res/ParentFolder.h"
652 
653 	SevenZipPanel::SevenZipPanel(MyFrame *frame, wxWindow *parent,int id,int panelIndex) :
654 	       	wxPanel(parent,id) , m_frame(frame), _wList(0)
655 	{
656 		_panelIndex = panelIndex;
657 
658 		int _baseID = id; // FIXME
659 		int _listID = _baseID + 1;
660 		int _comboBoxID = _baseID + 3;
661 		int _statusBarID = _comboBoxID + 1;
662 		int kParentFolderID = 100; // FIXME Panel.h
663 
664 
665 		///Sizer for adding the controls created by users
666 		wxBoxSizer* pMainSizer = new wxBoxSizer(wxVERTICAL);
667 		int sizes[] = {150, 250, 350, -1};
668 		wxArrayString pathArray;
669 		wxBoxSizer *pPathSizer = new wxBoxSizer(wxHORIZONTAL);
670 		m_pBmpButtonParentFolder = new wxBitmapButton(this, kParentFolderID, wxGetBitmapFromMemory(PARENT_FOLDER), wxDefaultPosition, wxDefaultSize, wxBU_AUTODRAW);
671 		m_pComboBoxPath = new wxComboBox(this, _comboBoxID, wxEmptyString, wxDefaultPosition, wxSize(300,-1), pathArray, wxCB_DROPDOWN | wxCB_SORT );
672 		pPathSizer->Add(m_pBmpButtonParentFolder, 0, wxALL|wxEXPAND, 0);
673 		pPathSizer->Add(m_pComboBoxPath, 1, wxALL|wxEXPAND, 5);
674 
675 		m_pListCtrlExplorer = new CExplorerListCtrl(this,_listID,wxDefaultPosition, wxSize(300,300),
676 			wxLC_REPORT |
677 			wxSUNKEN_BORDER | wxLC_EDIT_LABELS);
678 
679 		printf("DEBUG : new CExplorerListCtrl(id=%d) => %p\n",_listID,m_pListCtrlExplorer);
680 
681 		m_pStatusBar = new wxStatusBar(this, _statusBarID);
682 		m_pStatusBar->SetFieldsCount(4, sizes);
683 		pMainSizer->Add(pPathSizer, 0, wxALL|wxEXPAND, 0);
684 		pMainSizer->Add(m_pListCtrlExplorer, 1, wxALL|wxEXPAND, 0);
685 		pMainSizer->Add(m_pStatusBar, 0, wxALL|wxEXPAND, 0);
686 		SetSizer(pMainSizer);
687 		SetAutoLayout (true);
688 		Layout();
689 
690 
691 		// m_pListCtrlExplorer->SetDropTarget(new DnDFile(this));
692 
693 	}
694 
OnAnyButton(wxCommandEvent & event)695 	void SevenZipPanel::OnAnyButton( wxCommandEvent &event )
696 	{
697 		count++;
698 
699 		int id = event.GetId();
700 
701 		wxString msg = wxString::Format(_T("P %d : button %d \n"), count,id);
702 
703 		WriteText(msg);
704 
705 		_wList->OnMessage(WM_COMMAND , id , 0);
706 	}
707 
OnSelected(wxListEvent & event)708 	void SevenZipPanel::OnSelected(wxListEvent& event)
709 	{
710 		const wxListItem & item = event.GetItem();
711 		count++;
712 
713 		wxString msg = wxString::Format(_T("P %d : OnSelected %d \n"), count,event.GetId());
714 
715 		WriteText(msg);
716 
717 		NMLISTVIEW info;
718 		info.hdr.hwndFrom = m_pListCtrlExplorer;
719 		info.hdr.code     = LVN_ITEMCHANGED;
720 		info.uOldState    = 0;
721 		info.uNewState    = LVIS_SELECTED;
722 		info.lParam       = item.GetData(); // event.GetIndex(); // FIXME ? event.GetData();
723 		_wList->OnMessage(WM_NOTIFY , event.GetId() , (LPARAM)&info);
724 		/*
725 		if ( GetWindowStyle() & wxLC_REPORT )
726 		{
727 		wxListItem info;
728 		info.m_itemId = event.m_itemIndex;
729 		info.m_col = 1;
730 		info.m_mask = wxLIST_MASK_TEXT;
731 		if ( GetItem(info) )
732 		{
733 		wxLogMessage(wxT("Value of the 2nd field of the selected item: %s"),
734 		info.m_text.c_str());
735 		}
736 		else
737 		{
738 		wxFAIL_MSG(wxT("wxListCtrl::GetItem() failed"));
739 		}
740 		}
741 		*/
742 	}
743 
OnDeselected(wxListEvent & event)744 	void SevenZipPanel::OnDeselected(wxListEvent& event)
745 	{
746 		const wxListItem & item = event.GetItem();
747 		count++;
748 		wxString msg = wxString::Format(_T("P %d : OnDeselected %d \n"), count,event.GetId());
749 		WriteText(msg);
750 
751 		NMLISTVIEW info;
752 		info.hdr.hwndFrom = m_pListCtrlExplorer;
753 		info.hdr.code     = LVN_ITEMCHANGED;
754 		info.uOldState    = LVIS_SELECTED;
755 		info.uNewState    = 0;
756 		info.lParam       = item.GetData(); // event.GetIndex(); // FIXME ? event.GetData();
757 		_wList->OnMessage(WM_NOTIFY , event.GetId() , (LPARAM)&info);
758 	}
759 
OnColumnClick(wxListEvent & event)760 	void SevenZipPanel::OnColumnClick(wxListEvent& event)
761 	{
762 		count++;
763 		wxString msg = wxString::Format(_T("P %d : OnColumnClick %d col=%d\n"), count,event.GetId(),event.GetColumn());
764 		WriteText(msg);
765 
766 		NMLISTVIEW info;
767 		info.hdr.hwndFrom = m_pListCtrlExplorer;
768 		info.hdr.code     = LVN_COLUMNCLICK;
769 		info.iSubItem     = event.GetColumn();
770 		_wList->OnMessage(WM_NOTIFY , event.GetId() , (LPARAM)&info);
771 
772 	}
773 
774 
OnActivated(wxListEvent & event)775 	void SevenZipPanel::OnActivated(wxListEvent& event)
776 	{
777 		count++;
778 
779 		int ind = event.GetIndex();
780 
781 		NMHDR info;
782 		info.hwndFrom = m_pListCtrlExplorer;
783 		info.code     = NM_DBLCLK;
784 		_wList->OnMessage(WM_NOTIFY , event.GetId() , (LPARAM)&info);
785 
786 		/*
787 		if ((ind >= 0) && ( ind < m_nbDirs))
788 		{
789 			wxString msg = wxString::Format(_T("P %d : OnActivated %d : DIR = %d\n"), count,event.GetId(),ind);
790 			WriteText(msg);
791 
792 			wxString name = m_pListCtrlExplorer->GetItemText(ind);
793 
794 			wxFileName filename (m_currentDirectory,name);
795 			BinPath(filename.GetFullPath());
796 
797 		}
798 		else
799 		*/
800 		{
801 			wxString msg = wxString::Format(_T("P %d : OnActivated %d : FILE = %d\n"), count,event.GetId(),ind);
802 			WriteText(msg);
803 		}
804 
805 
806 	}
807 
OnFocused(wxListEvent & event)808 	void SevenZipPanel::OnFocused(wxListEvent& event)
809 	{
810 		count++;
811 
812 		wxString msg = wxString::Format(_T("P %d : OnFocused %d \n"), count,event.GetId());
813 
814 		WriteText(msg);
815 
816 		event.Skip();
817 	}
818 
OnLeftDownBeginDrag(wxListEvent & event)819 	void SevenZipPanel::OnLeftDownBeginDrag(wxListEvent& event)
820 	{
821 		count++;
822 
823 		wxString msg = wxString::Format(_T("P %d : OnLeftDownBeginDrag %d \n"), count,event.GetId());
824 		WriteText(msg);
825 
826 #if 0
827 		if (   m_pListCtrlExplorer->GetSelectedItemCount() < 1) return ;
828 
829         // start drag operation
830         wxFileDataObject filesData;
831 
832 
833 	long item = -1;
834     for ( ;; )
835     {
836         item = m_pListCtrlExplorer->GetNextItem(item,
837                                      wxLIST_NEXT_ALL,
838                                      wxLIST_STATE_SELECTED);
839         if ( item == -1 )
840             break;
841 
842         // this item is selected - do whatever is needed with it
843         // wxLogMessage("Item %ld is selected.", item);
844 		wxString file = m_currentDirectory + _T("/") + m_pListCtrlExplorer->GetItemText(item);
845 
846 		filesData.AddFile(file);
847 
848     }
849 
850 		msg = wxString::Format(_T("P %d : wxDropSource %d \n"), count,event.GetId());
851 		WriteText(msg);
852 
853         wxDropSource source(filesData, this,
854                             wxDROP_ICON(dnd_copy),
855                             wxDROP_ICON(dnd_move),
856                             wxDROP_ICON(dnd_none));
857 
858         int flags = 0;
859 		/*
860         if ( m_moveByDefault )
861             flags |= wxDrag_DefaultMove;
862         else if ( m_moveAllow )
863             flags |= wxDrag_AllowMove;
864 			*/
865 		flags |= wxDrag_AllowMove;
866 
867 		msg = wxString::Format(_T("P %d : DoDragDrop %d \n"), count,event.GetId());
868 		WriteText(msg);
869 
870 
871         wxDragResult result = source.DoDragDrop(flags);
872 
873 
874         const wxChar *pc;
875         switch ( result )
876         {
877             case wxDragError:   pc = _T("Error!");    break;
878             case wxDragNone:    pc = _T("Nothing");   break;
879             case wxDragCopy:    pc = _T("Copied");    break;
880             case wxDragMove:    pc = _T("Moved");     break;
881             case wxDragCancel:  pc = _T("Cancelled"); break;
882             default:            pc = _T("Huh?");      break;
883         }
884 
885         WriteText(wxString(_T("    Drag result: ")) + pc);
886 #endif
887 	}
888 
OnLeftDown(wxMouseEvent & WXUNUSED (event))889 void SevenZipPanel::OnLeftDown(wxMouseEvent &WXUNUSED(event) )
890 {
891 	WriteText(_T("OnLeftDown"));
892 #if 0
893     if ( !m_strText.empty() )
894     {
895         // start drag operation
896         wxTextDataObject textData(m_strText);
897         wxDropSource source(textData, this,
898                             wxDROP_ICON(dnd_copy),
899                             wxDROP_ICON(dnd_move),
900                             wxDROP_ICON(dnd_none));
901 
902         int flags = 0;
903         if ( m_moveByDefault )
904             flags |= wxDrag_DefaultMove;
905         else if ( m_moveAllow )
906             flags |= wxDrag_AllowMove;
907 
908         wxDragResult result = source.DoDragDrop(flags);
909 
910 #if wxUSE_STATUSBAR
911         const wxChar *pc;
912         switch ( result )
913         {
914             case wxDragError:   pc = _T("Error!");    break;
915             case wxDragNone:    pc = _T("Nothing");   break;
916             case wxDragCopy:    pc = _T("Copied");    break;
917             case wxDragMove:    pc = _T("Moved");     break;
918             case wxDragCancel:  pc = _T("Cancelled"); break;
919             default:            pc = _T("Huh?");      break;
920         }
921 
922         SetStatusText(wxString(_T("Drag result: ")) + pc);
923 #else
924         wxUnusedVar(result);
925 #endif // wxUSE_STATUSBAR
926     }
927 #endif // wxUSE_DRAG_AND_DROP
928 }
929 
OnRightClick(wxListEvent & event)930 void SevenZipPanel::OnRightClick(wxListEvent& event)
931 {
932 	wxPoint point = event.GetPoint();
933 
934 	WriteText(_T("OnRightClick"));
935     wxMenu menu; // (_T("Dnd sample menu"));
936 
937     menu.Append(wxID_ANY, _T("&Test drag..."));
938     menu.AppendSeparator();
939     menu.Append(wxID_ANY, _T("item1"));
940     menu.Append(wxID_ANY, _T("item2"));
941     menu.Append(wxID_ANY, _T("item3"));
942     menu.Append(wxID_ANY, _T("&About"));
943 
944     PopupMenu( &menu, point.x, point.y );
945 }
946 
947 int SevenZipPanel::count = 0;
948 
949 BEGIN_EVENT_TABLE(SevenZipPanel, wxPanel)
950 // EVT_MENU(wxID_ANY, SevenZipPanel::OnAnyMenu)
951 // EVT_LISTBOX   (wxID_ANY,       MyPanel::OnListBox)
952 // EVT_LISTBOX_DCLICK(wxID_ANY,          MyPanel::OnAnyListBoxDoubleClick)
953 EVT_BUTTON    (wxID_ANY,      SevenZipPanel::OnAnyButton)
954 
955  // EVT_CLOSE(SevenZipPanel::OnCloseWindow)
956 
957 /////////////////
958 EVT_LIST_ITEM_SELECTED(wxID_ANY,   SevenZipPanel::OnSelected)
959 EVT_LIST_ITEM_DESELECTED(wxID_ANY, SevenZipPanel::OnDeselected)
960 EVT_LIST_ITEM_ACTIVATED(wxID_ANY,  SevenZipPanel::OnActivated)
961 EVT_LIST_ITEM_FOCUSED(wxID_ANY,  SevenZipPanel::OnFocused)
962 
963 EVT_LIST_BEGIN_DRAG(wxID_ANY, SevenZipPanel::OnLeftDownBeginDrag)
964 EVT_LIST_ITEM_RIGHT_CLICK(wxID_ANY, SevenZipPanel::OnRightClick)
965 
966 EVT_LIST_COL_CLICK(wxID_ANY, SevenZipPanel::OnColumnClick)
967 
968 END_EVENT_TABLE()
969 
970 
971