~ubuntu-branches/ubuntu/precise/p7zip/precise-updates

« back to all changes in this revision

Viewing changes to CPP/Windows/Control/Controls.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mohammed Adnène Trojette
  • Date: 2009-02-14 20:12:27 UTC
  • mfrom: (1.1.11 upstream) (2.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090214201227-go63qxm9ozfdma60
Tags: 4.65~dfsg.1-1
* New upstream release.
* Remove wx2.8 Build-Depends added by mistakes (7zG is not yet
  intended to be built).
* Use dh_clean without -k.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Dialog.cpp
 
2
 
 
3
#include "StdAfx.h"
 
4
 
 
5
// For compilers that support precompilation, includes "wx/wx.h".
 
6
#include "wx/wxprec.h"
 
7
 
 
8
#ifdef __BORLANDC__
 
9
    #pragma hdrstop
 
10
#endif
 
11
 
 
12
// for all others, include the necessary headers (this file is usually all you
 
13
// need because it includes almost all "standard" wxWidgets headers)
 
14
#ifndef WX_PRECOMP
 
15
        #include "wx/wx.h"
 
16
        #include "wx/imaglist.h"
 
17
        #include "wx/listctrl.h"
 
18
#endif  
 
19
 
 
20
#include "Windows/Control/Dialog.h"
 
21
 
 
22
class LockGUI
 
23
{
 
24
        bool _IsMain;
 
25
        public:
 
26
                LockGUI() { 
 
27
                        _IsMain = wxThread::IsMain();
 
28
                        if (!_IsMain) {
 
29
                                // DEBUG printf("GuiEnter(0x%lx)\n",wxThread::GetCurrentId());
 
30
                                wxMutexGuiEnter();
 
31
                        }
 
32
                }
 
33
                ~LockGUI() { 
 
34
                        if (!_IsMain) {
 
35
                                wxMutexGuiLeave();
 
36
                                // DEBUG printf("GuiLeave(0x%lx)\n",wxThread::GetCurrentId());
 
37
                        }
 
38
                }
 
39
};
 
40
/////////////////////////
 
41
 
 
42
namespace NWindows {
 
43
        namespace NControl {
 
44
 
 
45
                void CDialogChildControl::SetText(LPCWSTR s)
 
46
                {
 
47
                        LockGUI lock;
 
48
                        ((wxTextCtrl *)_window)->SetValue(s);
 
49
                }
 
50
 
 
51
                bool CDialogChildControl::GetText(CSysString &s)
 
52
                {
 
53
                        wxString str;
 
54
                        {
 
55
                                LockGUI lock;
 
56
                                str = ((wxTextCtrl *)_window)->GetValue();
 
57
                        }
 
58
                        s = str;
 
59
                        return true;
 
60
                }
 
61
        }
 
62
}
 
63
 
 
64
///////////////////////// Windows/Control/ComboBox.cpp
 
65
#include "Windows/Control/ComboBox.h"
 
66
 
 
67
namespace NWindows {
 
68
        namespace NControl {
 
69
 
 
70
                void CComboBox::Attach(wxWindow * newWindow) { _choice = (wxComboBox*)newWindow; }
 
71
 
 
72
                wxWindow * CComboBox::Detach()
 
73
                {
 
74
                        wxWindow * window = _choice;
 
75
                        _choice = NULL;
 
76
                        return window;
 
77
                }
 
78
                        
 
79
                        int CComboBox::AddString(const TCHAR * txt) {
 
80
                                LockGUI lock;
 
81
                                wxString item(txt);
 
82
                                return _choice->Append(item);
 
83
                        }
 
84
 
 
85
                        void CComboBox::SetText(LPCTSTR s) {
 
86
                                LockGUI lock;
 
87
                                wxString str(s);
 
88
                                _choice->SetValue(str);
 
89
                        }
 
90
 
 
91
                        void CComboBox::GetText(CSysString &s) {
 
92
                                LockGUI lock;
 
93
                                wxString str = _choice->GetValue();
 
94
                                s = str;
 
95
                        }
 
96
 
 
97
                        int CComboBox::GetCount() const  {
 
98
                                LockGUI lock;
 
99
                                return _choice->GetCount();
 
100
                        }
 
101
 
 
102
                        void CComboBox::GetLBText(int index, CSysString &s) {
 
103
                                LockGUI lock;
 
104
                                wxString str = _choice->GetString(index);
 
105
                                s = str;
 
106
                        }
 
107
 
 
108
                        void CComboBox::SetCurSel(int index) {
 
109
                                LockGUI lock;
 
110
                                _choice->SetSelection(index);
 
111
                        }
 
112
 
 
113
                        int CComboBox::GetCurSel() {
 
114
                                LockGUI lock;
 
115
                                return _choice->GetSelection();
 
116
                        }
 
117
 
 
118
                        void CComboBox::SetItemData(int index, int val) {
 
119
                                LockGUI lock;
 
120
                                _choice->SetClientData( index, (void *)(((char *)0) + val));
 
121
                        }
 
122
 
 
123
                        int CComboBox::GetItemData(int index)
 
124
                        {
 
125
                                LockGUI lock;
 
126
                                void * data = _choice->GetClientData(index);
 
127
                                int ret = (int)(((char *)data) - ((char *)0));
 
128
                                return ret;
 
129
                        }
 
130
 
 
131
                        void CComboBox::Enable(bool state) {
 
132
                                LockGUI lock;
 
133
                                _choice->Enable(state);
 
134
                        }
 
135
 
 
136
                        void CComboBox::ResetContent() {
 
137
                                LockGUI lock;
 
138
                               _choice->Clear();
 
139
                        }
 
140
        }
 
141
}
 
142
 
 
143
///////////////////////// Windows/Control/Edit.cpp
 
144
#include "Windows/Control/Edit.h"
 
145
 
 
146
namespace NWindows {
 
147
        namespace NControl {
 
148
 
 
149
                void CEdit::SetPasswordChar(WPARAM c)  // Warning : does not work for wxMSW
 
150
                {
 
151
                                LockGUI lock;
 
152
                        long style = _window->GetWindowStyle();
 
153
                        if ( c == 0 ) style &= ~(wxTE_PASSWORD);        
 
154
                        else          style |= wxTE_PASSWORD;           
 
155
                        _window->SetWindowStyle(style);
 
156
                        _window->Refresh();
 
157
                }
 
158
 
 
159
 
 
160
                void CEdit::Show(int cmdShow)
 
161
                {
 
162
                                LockGUI lock;
 
163
                        // FIXME        _window->Show(cmdShow != SW_HIDE);
 
164
                        _window->Enable(cmdShow != SW_HIDE);
 
165
                }
 
166
 
 
167
                void CEdit::SetText(LPCWSTR s)
 
168
                {
 
169
                        LockGUI lock;
 
170
                        ((wxTextCtrl *)_window)->SetValue(s);
 
171
                }
 
172
 
 
173
                bool CEdit::GetText(CSysString &s)
 
174
                {
 
175
                        wxString str;
 
176
                        {
 
177
                                LockGUI lock;
 
178
                                str = ((wxTextCtrl *)_window)->GetValue();
 
179
                        }
 
180
                        s = str;
 
181
                        return true;
 
182
                }
 
183
                
 
184
        }
 
185
}
 
186
 
 
187
///////////////////////// Windows/Control/ProgressBar.cpp
 
188
#include "Windows/Control/ProgressBar.h"
 
189
 
 
190
namespace NWindows {
 
191
        namespace NControl {
 
192
 
 
193
                CProgressBar::CProgressBar(wxWindow* newWindow):
 
194
                        _window((wxGauge *)newWindow) , _minValue(0), _range(0) { }
 
195
 
 
196
        void CProgressBar::Attach(wxWindow* newWindow) { 
 
197
                _window = (wxGauge *)newWindow;
 
198
                _minValue = 0;
 
199
                _range = 0;
 
200
        }
 
201
 
 
202
        void CProgressBar::SetRange32(int minValue, int maxValue) {
 
203
                int range = maxValue - minValue;
 
204
                if (range >= 1)
 
205
                {
 
206
                                LockGUI lock;
 
207
                        _minValue = minValue;
 
208
                        _range    = range;
 
209
                        _window->SetRange(_range);
 
210
                }
 
211
        }
 
212
 
 
213
        void CProgressBar::SetPos(int pos) {
 
214
                if (_range >= 1)
 
215
                {
 
216
                                LockGUI lock;
 
217
                        int value = pos - _minValue;
 
218
                        if ((value >= 0) && (value <= _range)) _window->SetValue(value);
 
219
                }
 
220
        }
 
221
 
 
222
        }
 
223
}
 
224
 
 
225
///////////////////////// Windows/Control/StatusBar.cpp
 
226
#include "Windows/Control/StatusBar.h"
 
227
 
 
228
namespace NWindows {
 
229
        namespace NControl {
 
230
 
 
231
                void CStatusBar::Attach(wxWindow * newWindow) { _statusBar = (wxStatusBar*)newWindow; }
 
232
 
 
233
                wxWindow * CStatusBar::Detach()
 
234
                {
 
235
                        wxWindow * window = _statusBar;
 
236
                        _statusBar = NULL;
 
237
                        return window;
 
238
                }
 
239
 
 
240
                void CStatusBar::SetText(int index, LPCTSTR text)
 
241
                {
 
242
                        _statusBar->SetStatusText(text,index);
 
243
                }
 
244
 
 
245
        }
 
246
 
 
247
}
 
248
 
 
249
///////////////////////// Windows/Control/ListView.cpp
 
250
#include "Windows/Control/ListView.h"
 
251
 
 
252
namespace NWindows {
 
253
namespace NControl {
 
254
 
 
255
        void CListView::Attach(wxWindow * newWindow) { _list = (wxListCtrl *)newWindow; }
 
256
 
 
257
        CListView::operator HWND() const { return (HWND)_list; }
 
258
 
 
259
        int CListView::GetItemCount() const {return  _list->GetItemCount(); }
 
260
 
 
261
        int CListView::InsertItem(int index, LPCTSTR text) { return _list->InsertItem(index, text);        }
 
262
        int CListView::InsertItem(const LVITEM* item) {
 
263
                /*
 
264
                int col = item->iSubItem;
 
265
                wxString text;
 
266
                if (item->mask & LVIF_TEXT) text = item->pszText;
 
267
 
 
268
                // printf("%p->InsertItem(id=%d,%ls)\n",_list,item->iItem, (const wchar_t *)text);
 
269
                return _list->InsertItem(item->iItem, text);        
 
270
                */
 
271
                wxListItem info;
 
272
                long mask = 0;
 
273
                info.SetId(item->iItem);
 
274
                if (item->mask & LVIF_TEXT)
 
275
                {
 
276
                        info.SetText(item->pszText);
 
277
                        mask |= wxLIST_MASK_TEXT;
 
278
                }
 
279
                if (item->mask & LVIF_PARAM)
 
280
                {
 
281
                        info.SetData(item->lParam);
 
282
                        mask |= wxLIST_MASK_DATA;
 
283
                }
 
284
                if (item->mask & LVIF_STATE)
 
285
                {
 
286
                        info.SetState(item->state);
 
287
                        mask |= wxLIST_MASK_STATE;
 
288
                }
 
289
                // FIXME if (item->mask & LVIF_IMAGE)
 
290
                
 
291
                info.SetMask(mask);
 
292
 
 
293
                return _list->InsertItem(info);        
 
294
        }
 
295
 
 
296
        void CListView::SetItem(const LVITEM* item)  {
 
297
                int col = item->iSubItem;
 
298
                wxString text;
 
299
                if (item->mask & LVIF_TEXT) text = item->pszText;
 
300
                // printf("%p->SetItem(id=%d,col=%d,%ls)\n",_list,item->iItem, col,(const wchar_t *)text);
 
301
                _list->SetItem(item->iItem, col, text);
 
302
        }
 
303
 
 
304
        int CListView::SetSubItem(int index, int subIndex, LPCTSTR text)
 
305
        {
 
306
                return _list->SetItem(index, subIndex, text);
 
307
        }
 
308
 
 
309
        void SetUnicodeFormat(bool fUnicode) { return ;  }
 
310
 
 
311
        void CListView::InsertColumn(int columnIndex, LPCTSTR text, int width)
 
312
        {
 
313
                  _list->InsertColumn(columnIndex, text, wxLIST_FORMAT_LEFT, width);
 
314
        }
 
315
 
 
316
        void CListView::InsertColumn(int columnIndex, const LVCOLUMNW *columnInfo)
 
317
        {
 
318
                  wxString text;
 
319
                  int format = wxLIST_FORMAT_LEFT;
 
320
                  int width = -1;
 
321
                  if (columnInfo->mask & LVCF_FMT)
 
322
                  {
 
323
                          if (columnInfo->fmt == LVCFMT_LEFT) format = wxLIST_FORMAT_LEFT;
 
324
                          if (columnInfo->fmt == LVCFMT_RIGHT) format = wxLIST_FORMAT_RIGHT;
 
325
                  }
 
326
                  if (columnInfo->mask & LVCF_TEXT)  text = columnInfo->pszText;
 
327
                  if (columnInfo->mask & LVCF_WIDTH) width   = columnInfo->cx;
 
328
                  // FIXME LVCF_SUBITEM
 
329
                // printf("%p->InsertColumn(%d,%ls)\n",_list,columnIndex,(const wchar_t *)heading);
 
330
                  _list->InsertColumn(columnIndex, text, format, width);
 
331
          }
 
332
 
 
333
          void CListView::DeleteAllItems() { _list->DeleteAllItems(); printf("%p->DeleteAllItems()\n",_list); }
 
334
 
 
335
        void CListView::SetRedraw(bool b) { 
 
336
                if (b) _list->Thaw();
 
337
                else   _list->Freeze();
 
338
                printf(" %p->SetRedraw()\n",_list);
 
339
        }
 
340
 
 
341
        void CListView::SetItemCount(int count) {
 
342
                _list->SetItemCount(count);
 
343
                printf(" %p->SetItemCount(%d)\n",_list,count);
 
344
        }
 
345
 
 
346
          void CListView::InvalidateRect(void *, bool)  { printf("FIXME %p->InvalidateRect()\n",_list);/* FIXME */ }
 
347
 
 
348
          int CListView::GetSelectedCount() const { 
 
349
                  int nb = _list->GetSelectedItemCount();
 
350
                  printf(" %p->GetSelectedCount()=>%d\n",_list,nb);
 
351
                  return nb;
 
352
          }
 
353
 
 
354
        void /* bool */ CListView::EnsureVisible(int index, bool partialOK) {
 
355
                _list->EnsureVisible(index);
 
356
                printf(" %p->EnsureVisible(%d)\n",_list,index);
 
357
                // return true;
 
358
        }
 
359
 
 
360
        void CListView::SetItemState(int index, UINT state, UINT mask) {
 
361
                // don't work  _list->SetItemState(index, state, mask); !?
 
362
                // try SetItem ...
 
363
                /*
 
364
                wxListItem info;
 
365
 
 
366
                info.m_mask   = wxLIST_MASK_STATE; 
 
367
                info.m_itemId = index;
 
368
                info.m_col    = 0;
 
369
                info.m_state  = state;
 
370
                info.m_mask   = mask;
 
371
 
 
372
                _list->SetItem(info);
 
373
                */
 
374
                if (mask & LVIS_FOCUSED) {
 
375
                        _list->SetItemState(index, state & LVIS_FOCUSED, mask & LVIS_FOCUSED);
 
376
                }
 
377
 
 
378
                if (mask & LVIS_SELECTED) {
 
379
                        _list->SetItemState(index, state & LVIS_SELECTED, mask & LVIS_SELECTED);
 
380
                }
 
381
 
 
382
                  printf("FIXME %p->SetItemState(index=%d,state=0x%x,mask=0x%x)\n",_list,index,(unsigned)state,(unsigned)mask); /* FIXME */
 
383
          }
 
384
 
 
385
          UINT CListView::GetItemState(int index, UINT mask) const
 
386
          {
 
387
                UINT state = _list->GetItemState(index, mask);
 
388
                printf("FIXME %p->GetItemState(index=%d,mask=0x%x)=0x%x\n",_list,index,(unsigned)mask,(unsigned)state); /* FIXME */
 
389
 
 
390
                return state;
 
391
          }
 
392
 
 
393
          void /* bool */  CListView::Update() { printf("FIXME %p->Update()\n",_list); /* FIXME */ }
 
394
 
 
395
          bool CListView::DeleteColumn(int columnIndex) { 
 
396
                  // printf("%p->DeleteColumn()\n",_list); 
 
397
                  if (_list->GetColumnCount() < 1) return false;
 
398
                  return _list->DeleteColumn(columnIndex); // always return true !?
 
399
          }
 
400
 
 
401
          bool CListView::GetItemParam(int itemIndex, LPARAM &param) const
 
402
          {
 
403
                param = _list->GetItemData(itemIndex);
 
404
 
 
405
                // printf(" %p->GetItemParam(%d) => %ld\n",_list,itemIndex,(long)param);
 
406
 
 
407
                return true;
 
408
          }
 
409
 
 
410
          int CListView::GetNextItem(int startIndex, UINT flags) const
 
411
          {
 
412
                int item = _list->GetNextItem(startIndex, wxLIST_NEXT_ALL, flags);
 
413
                printf(" %p->GetNextItem(%d) => %d\n",_list,startIndex,item);
 
414
                return item;
 
415
 
 
416
          }
 
417
 
 
418
        int CListView::GetFocusedItem() const
 
419
        {
 
420
                int item = _list->GetNextItem(-1, wxLIST_NEXT_ALL, wxLIST_STATE_FOCUSED);
 
421
                printf(" %p->GetFocusedItem() => %d\n",_list,item);
 
422
                return item;
 
423
        }
 
424
 
 
425
          void CListView::RedrawAllItems()
 
426
          {
 
427
                printf("FIXME %p->RedrawAllItems()\n",_list);
 
428
          }
 
429
 
 
430
          // FIXME added
 
431
          int CListView::GetColumnCount()
 
432
          {
 
433
                return _list->GetColumnCount();
 
434
          }
 
435
 
 
436
          void CListView::SetFocus() { /* FIXME */ }
 
437
 
 
438
          void CListView::RedrawItem(int item) { /* FIXME */ }
 
439
 
 
440
        bool CListView::SortItems(PFNLVCOMPARE compareFunction, LPARAM dataParam) { 
 
441
                printf(" %p->SortItems()\n",_list);
 
442
                return _list->SortItems(compareFunction, dataParam);
 
443
        }
 
444
 
 
445
        bool CListView::GetColumn(int columnIndex, LVCOLUMN* columnInfo)
 
446
        {
 
447
                wxListItem item;
 
448
                bool ret = _list->GetColumn(columnIndex, item);
 
449
 
 
450
                if (ret)
 
451
                {
 
452
                        columnInfo->iOrder = 0; // FIXME
 
453
                        columnInfo->cx = item.GetWidth();
 
454
                }
 
455
 
 
456
                return ret;
 
457
 
 
458
        }
 
459
 
 
460
        // HWND EditLabel(int itemIndex)
 
461
        void CListView::EditLabel(int itemIndex)
 
462
        {
 
463
                /* FIXME */
 
464
        }
 
465
 
 
466
}}
 
467