summaryrefslogtreecommitdiffstats
path: root/src/libs/7zip/unix/CPP/Windows/Control/Controls.cpp
blob: 2191d800974e8edbc61d3fd62793b964b1406be4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
// Dialog.cpp

#include "StdAfx.h"

// For compilers that support precompilation, includes "wx/wx.h".
#include "wx/wxprec.h"

#ifdef __BORLANDC__
    #pragma hdrstop
#endif

// for all others, include the necessary headers (this file is usually all you
// need because it includes almost all "standard" wxWidgets headers)
#ifndef WX_PRECOMP
	#include "wx/wx.h"
	#include "wx/imaglist.h"
	#include "wx/listctrl.h"
#endif  

#undef _WIN32
 
#include "Windows/Control/Dialog.h"

void verify_main_thread(void);

class LockGUI
{
	bool _IsMain;
	public:
		LockGUI() {
			verify_main_thread();
			_IsMain = wxThread::IsMain();
			if (!_IsMain) {
				// DEBUG
				printf("GuiEnter-Controls(0x%lx)\n",wxThread::GetCurrentId());
				abort(); // FIXME wxMutexGuiEnter();
			}
	       	}
		~LockGUI() { 
			if (!_IsMain) {
				wxMutexGuiLeave();
				// DEBUG printf("GuiLeave(0x%lx)\n",wxThread::GetCurrentId());
			}
	       	}
};
/////////////////////////

static const wxString CLASS_NAME_wxStaticText = wxT("wxStaticText");
static const wxString CLASS_NAME_wxTextCtrl = wxT("wxTextCtrl");

namespace NWindows {
	namespace NControl {

		void CDialogChildControl::SetText(LPCWSTR s)
		{
			LockGUI lock;
			const wxChar * class_name = _window->GetClassInfo()->GetClassName ();

			if ( CLASS_NAME_wxStaticText == class_name) {
				((wxStaticText *)_window)->SetLabel(s);
			} else if ( CLASS_NAME_wxTextCtrl == class_name) {
				((wxTextCtrl *)_window)->SetLabel(s);
			} else {
				// ((wxControl *)_window)->SetValue(s); // FIXME
				printf("INTERNAL ERROR - CDialogChildControl::SetText(class=%ls) not implemented\n",class_name);
				exit(-1);
			}
		}

		bool CDialogChildControl::GetText(CSysString &s)
		{
			wxString str;
			{
				LockGUI lock;
				const wxChar * class_name = _window->GetClassInfo()->GetClassName ();
				if ( CLASS_NAME_wxStaticText == class_name) {
	  				str = ((wxStaticText *)_window)->GetLabel();
				} else if ( CLASS_NAME_wxTextCtrl == class_name) {
					str = ((wxTextCtrl *)_window)->GetLabel();
				} else {
	  				// FIXME str = ((wxTextCtrl *)_window)->GetValue();
					printf("INTERNAL ERROR - CDialogChildControl::GetText(class=%ls) not implemented\n",class_name);
					exit(-1);
				}
			}
	  		s = str;
	  		return true;
		}
	}
}

///////////////////////// Windows/Control/ComboBox.cpp
#include "Windows/Control/ComboBox.h"

namespace NWindows {
	namespace NControl {

		void CComboBox::Attach(wxWindow * newWindow) { _choice = (wxComboBox*)newWindow; }

		wxWindow * CComboBox::Detach()
		{
			wxWindow * window = _choice;
			_choice = NULL;
			return window;
		}

		CComboBox::operator HWND() const { return (HWND)_choice; }

			
			int CComboBox::AddString(const TCHAR * txt) {
				LockGUI lock;
				wxString item(txt);
				return _choice->Append(item);
			}

			void CComboBox::SetText(LPCTSTR s) {
				LockGUI lock;
				wxString str(s);
				_choice->SetValue(str);
			}

			void CComboBox::GetText(CSysString &s) {
				LockGUI lock;
				wxString str = _choice->GetValue();
				s = str;
			}

			int CComboBox::GetCount() const  {
				LockGUI lock;
			       	return _choice->GetCount();
			}

			void CComboBox::GetLBText(int index, CSysString &s) {
				LockGUI lock;
				wxString str = _choice->GetString(index);
				s = str;
			}

			void CComboBox::SetCurSel(int index) {
				LockGUI lock;
			       	_choice->SetSelection(index);
			}

			int CComboBox::GetCurSel() {
				LockGUI lock;
			       	return _choice->GetSelection();
			}

			void CComboBox::SetItemData(int index, int val) {
				LockGUI lock;
			       	_choice->SetClientData( index, (void *)(((char *)0) + val));
		       	}

			int CComboBox::GetItemData(int index)
			{
				LockGUI lock;
				void * data = _choice->GetClientData(index);
				int ret = (int)(((char *)data) - ((char *)0));
				return ret;
			}

			void CComboBox::Enable(bool state) {
				LockGUI lock;
			       	_choice->Enable(state);
			}

			void CComboBox::ResetContent() {
				LockGUI lock;
			       _choice->Clear();
		       	}
	}
}

///////////////////////// Windows/Control/Edit.cpp
#include "Windows/Control/Edit.h"

namespace NWindows {
	namespace NControl {

		void CEdit::SetPasswordChar(WPARAM c)  // Warning : does not work for wxMSW
		{
				LockGUI lock;
			long style = _window->GetWindowStyle();
			if ( c == 0 ) style &= ~(wxTE_PASSWORD);	
			else          style |= wxTE_PASSWORD;		
			_window->SetWindowStyle(style);
			_window->Refresh();
		}


		void CEdit::Show(int cmdShow)
		{
				LockGUI lock;
			// FIXME	_window->Show(cmdShow != SW_HIDE);
			_window->Enable(cmdShow != SW_HIDE);
		}

		void CEdit::SetText(LPCWSTR s)
		{
			LockGUI lock;
			((wxTextCtrl *)_window)->SetValue(s);
		}

		bool CEdit::GetText(CSysString &s)
		{
			wxString str;
			{
				LockGUI lock;
	  			str = ((wxTextCtrl *)_window)->GetValue();
			}
	  		s = str;
	  		return true;
		}
		
	}
}

///////////////////////// Windows/Control/ProgressBar.cpp
#include "Windows/Control/ProgressBar.h"

namespace NWindows {
	namespace NControl {

		CProgressBar::CProgressBar(wxWindow* newWindow):
		       	_window((wxGauge *)newWindow) , _minValue(0), _range(0) { }

	void CProgressBar::Attach(wxWindow* newWindow) { 
		_window = (wxGauge *)newWindow;
		_minValue = 0;
		_range = 0;
	}

	void CProgressBar::SetRange32(int minValue, int maxValue) {
		int range = maxValue - minValue;
		if (range >= 1)
		{
				LockGUI lock;
			_minValue = minValue;
			_range    = range;
			_window->SetRange(_range);
		}
  	}

	void CProgressBar::SetPos(int pos) {
		if (_range >= 1)
		{
				LockGUI lock;
			int value = pos - _minValue;
			if ((value >= 0) && (value <= _range)) _window->SetValue(value);
		}
	}

	}
}

///////////////////////// Windows/Control/StatusBar.cpp
#include "Windows/Control/StatusBar.h"

namespace NWindows {
	namespace NControl {

		void CStatusBar::Attach(wxWindow * newWindow) { _statusBar = (wxStatusBar*)newWindow; }

		wxWindow * CStatusBar::Detach()
		{
			wxWindow * window = _statusBar;
			_statusBar = NULL;
			return window;
		}

		void CStatusBar::SetText(int index, LPCTSTR text)
		{
			_statusBar->SetStatusText(text,index);
		}

	}

}

///////////////////////// Windows/Control/ListView.cpp
#include "Windows/Control/ListView.h"

namespace NWindows {
namespace NControl {

	void CListView::Attach(wxWindow * newWindow) {
		_list = (wxListCtrl *)newWindow;
	}

	CListView::operator HWND() const { return (HWND)_list; }

	int CListView::GetItemCount() const {return  _list->GetItemCount(); }

	int CListView::InsertItem(int index, LPCTSTR text) {
		return _list->InsertItem(index, text);
	}
	int CListView::InsertItem(const LVITEM* item) {
		/*
		int col = item->iSubItem;
		wxString text;
		if (item->mask & LVIF_TEXT) text = item->pszText;

		// printf("%p->InsertItem(id=%d,%ls)\n",_list,item->iItem, (const wchar_t *)text);
		return _list->InsertItem(item->iItem, text);        
		*/
		wxListItem info;
		long mask = 0;
		info.SetId(item->iItem);
		if (item->mask & LVIF_TEXT)
		{
			info.SetText(item->pszText);
			mask |= wxLIST_MASK_TEXT;
		}
		if (item->mask & LVIF_PARAM)
		{
			info.SetData(item->lParam);
			mask |= wxLIST_MASK_DATA;
		}
		if (item->mask & LVIF_STATE)
		{
			info.SetState(item->state);
			mask |= wxLIST_MASK_STATE;
		}
		// FIXME if (item->mask & LVIF_IMAGE)
		
		info.SetMask(mask);

		return _list->InsertItem(info);        
	}

	void CListView::SetItem(const LVITEM* item)  {
		int col = item->iSubItem;
		wxString text;
		if (item->mask & LVIF_TEXT) text = item->pszText;
		// printf("%p->SetItem(id=%d,col=%d,%ls)\n",_list,item->iItem, col,(const wchar_t *)text);
		_list->SetItem(item->iItem, col, text);
	}

	int CListView::SetSubItem(int index, int subIndex, LPCTSTR text)
	{
		return _list->SetItem(index, subIndex, text);
	}

	void SetUnicodeFormat(bool fUnicode) { return ;  }

	void CListView::InsertColumn(int columnIndex, LPCTSTR text, int width)
	{
		  _list->InsertColumn(columnIndex, text, wxLIST_FORMAT_LEFT, width);
	}

	void CListView::InsertColumn(int columnIndex, const LVCOLUMNW *columnInfo)
	{
		  wxString text;
		  int format = wxLIST_FORMAT_LEFT;
		  int width = -1;
		  if (columnInfo->mask & LVCF_FMT)
		  {
			  if (columnInfo->fmt == LVCFMT_LEFT) format = wxLIST_FORMAT_LEFT;
			  if (columnInfo->fmt == LVCFMT_RIGHT) format = wxLIST_FORMAT_RIGHT;
		  }
		  if (columnInfo->mask & LVCF_TEXT)  text = columnInfo->pszText;
		  if (columnInfo->mask & LVCF_WIDTH) width   = columnInfo->cx;
		  // FIXME LVCF_SUBITEM
		// printf("%p->InsertColumn(%d,%ls)\n",_list,columnIndex,(const wchar_t *)heading);
		  _list->InsertColumn(columnIndex, text, format, width);
	  }

	  void CListView::DeleteAllItems() {
		  _list->DeleteAllItems();
		  printf("%p->DeleteAllItems()\n",_list);
	  }

	void CListView::SetRedraw(bool b) { 
		if (b) _list->Thaw();
		else   _list->Freeze();
		printf(" %p->SetRedraw()\n",_list);
	}

	void CListView::SetItemCount(int count) {
		// ONLY IF VIRTUAL REPORT -- _list->SetItemCount(count);
		printf(" %p->SetItemCount(%d)\n",_list,count);
	}

	  void CListView::InvalidateRect(void *, bool)  {
		  printf("FIXME %p->InvalidateRect()\n",_list);/* FIXME */
	  }

	  int CListView::GetSelectedCount() const { 
		  int nb = _list->GetSelectedItemCount();
		  printf(" %p->GetSelectedCount()=>%d\n",_list,nb);
		  return nb;
	  }

	void /* bool */ CListView::EnsureVisible(int index, bool partialOK) {
	 	
		printf(" %p->EnsureVisible(%d)\n",_list,index);
		
		if (index == -1) index = 0;
		_list->EnsureVisible(index);

		// return true;
	}

	void CListView::SetItemState(int index, UINT state, UINT mask) {
		// don't work  _list->SetItemState(index, state, mask); !?
		// try SetItem ...
		/*
		wxListItem info;

		info.m_mask   = wxLIST_MASK_STATE; 
		info.m_itemId = index;
		info.m_col    = 0;
		info.m_state  = state;
		info.m_mask   = mask;

		_list->SetItem(info);
		*/
	 	
		printf(" %p->EnsureVisible(%d)\n",_list,index);
		
		if (index == -1) return;
		
		if (mask & LVIS_FOCUSED) {
			_list->SetItemState(index, state & LVIS_FOCUSED, mask & LVIS_FOCUSED);
		}

		if (mask & LVIS_SELECTED) {
			_list->SetItemState(index, state & LVIS_SELECTED, mask & LVIS_SELECTED);
		}

	  }

	  UINT CListView::GetItemState(int index, UINT mask) const
	  {
		UINT state = _list->GetItemState(index, mask);
		printf("FIXME %p->GetItemState(index=%d,mask=0x%x)=0x%x\n",_list,index,(unsigned)mask,(unsigned)state); /* FIXME */

		return state;
	  }

	  void /* bool */  CListView::Update() {
		  printf("FIXME %p->Update()\n",_list); /* FIXME */
	  }

	  bool CListView::DeleteColumn(int columnIndex) { 
		  // printf("%p->DeleteColumn()\n",_list); 
		  if (_list->GetColumnCount() < 1) return false;
		  return _list->DeleteColumn(columnIndex); // always return true !?
	  }

	  bool CListView::GetItemParam(int itemIndex, LPARAM &param) const
	  {
		param = _list->GetItemData(itemIndex);

		// printf(" %p->GetItemParam(%d) => %ld\n",_list,itemIndex,(long)param);

		return true;
	  }

	  int CListView::GetNextItem(int startIndex, UINT flags) const
          {
		int item = _list->GetNextItem(startIndex, wxLIST_NEXT_ALL, flags);
		printf(" %p->GetNextItem(%d) => %d\n",_list,startIndex,item);
		return item;

	  }

	int CListView::GetFocusedItem() const
	{
		int item = _list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
		printf(" %p->GetFocusedItem() => %d\n",_list,item);
		return item;
	}

	  void CListView::RedrawAllItems()
	  {
	  	printf("FIXME %p->RedrawAllItems()\n",_list);
	  }

	  // FIXME added
	  int CListView::GetColumnCount()
	  {
		return _list->GetColumnCount();
	  }

	  void CListView::SetFocus() { /* FIXME */ }

	  void CListView::RedrawItem(int item) { /* FIXME */ }

	bool CListView::SortItems(PFNLVCOMPARE compareFunction, LPARAM dataParam) { 
	  	printf(" %p->SortItems()\n",_list);
		return _list->SortItems(compareFunction, dataParam);
	}

	bool CListView::GetColumn(int columnIndex, LVCOLUMN* columnInfo)
	{
		columnInfo->cx = _list->GetColumnWidth(columnIndex);// FIXME
			
		bool ret = false;
		
		if (columnInfo->cx >= 1) ret = true;
			
		// printf("CListView::GetColumn(%d) cx=%d\n",columnIndex,(int)columnInfo->cx);

		return ret;
	}

	// HWND EditLabel(int itemIndex)
	void CListView::EditLabel(int itemIndex)
	{
		/* FIXME */
	}

}}