~ubuntu-branches/debian/sid/filezilla/sid

« back to all changes in this revision

Viewing changes to src/interface/StatusView.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Adam Cécile (Le_Vert)
  • Date: 2008-07-05 21:00:24 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080705210024-mvzp21zlyheschi6
Tags: 3.0.11.1-1
* wxWidgets 2.8 just entered unstable ! Upload to unstable.
* New upstream release.
* Bump Standards-Version to 3.8.0.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#include "FileZilla.h"
2
2
#include "StatusView.h"
3
 
#if wxMAJOR_VERSION > 2 || wxMINOR_VERSION > 6
4
3
#include <wx/wupdlock.h>
5
 
#endif
 
4
#include "Options.h"
6
5
 
7
6
#ifdef _DEBUG
8
7
#define new DEBUG_NEW
16
15
        EVT_MENU(XRCID("ID_COPYTOCLIPBOARD"), CStatusView::OnCopy)
17
16
END_EVENT_TABLE()
18
17
 
 
18
class CFastTextCtrl : public wxTextCtrl
 
19
{
 
20
public:
 
21
        CFastTextCtrl(wxWindow* parent)
 
22
                : wxTextCtrl(parent, -1, _T(""), wxDefaultPosition, wxDefaultSize,
 
23
                                         wxNO_BORDER | wxVSCROLL | wxTE_MULTILINE |
 
24
                                         wxTE_READONLY | wxTE_RICH | wxTE_RICH2 | wxTE_NOHIDESEL |
 
25
                                         wxTAB_TRAVERSAL)
 
26
        {
 
27
        }
 
28
#ifdef __WXMSW__
 
29
        // wxTextCtrl::Remove is somewhat slow, this is a faster version
 
30
        virtual void Remove(long from, long to)
 
31
        {
 
32
                DoSetSelection(from, to, false);
 
33
 
 
34
                m_updatesCount = -2;        // suppress any update event
 
35
 
 
36
                ::SendMessage((HWND)GetHandle(), EM_REPLACESEL, 0, (LPARAM)_T(""));
 
37
        }
 
38
#endif
 
39
 
 
40
        DECLARE_EVENT_TABLE();
 
41
 
 
42
        void OnText(wxCommandEvent& event)
 
43
        {
 
44
                // Do nothing here.
 
45
                // Having this event handler prevents the event from propagating up the
 
46
                // window hierarchy which saves a few CPU cycles.
 
47
        }
 
48
 
 
49
#ifdef __WXMSW__
 
50
        void OnNavigationKey(wxNavigationKeyEvent& event)
 
51
        {
 
52
                wxWindow* parent = GetParent();
 
53
                event.SetEventObject(parent);
 
54
                parent->ProcessEvent(event);
 
55
        }
 
56
#else
 
57
        void OnKeyDown(wxKeyEvent& event)
 
58
        {
 
59
                if (event.GetKeyCode() != WXK_TAB)
 
60
                {
 
61
                        event.Skip();
 
62
                        return;
 
63
                }
 
64
 
 
65
                wxWindow* parent = GetParent();
 
66
 
 
67
                wxNavigationKeyEvent navEvent;
 
68
                navEvent.SetEventObject(parent);
 
69
                navEvent.SetDirection(!event.ShiftDown());
 
70
                navEvent.SetFromTab(true);
 
71
                navEvent.ResumePropagation(1);
 
72
                parent->ProcessEvent(navEvent);
 
73
        }
 
74
#endif
 
75
};
 
76
 
 
77
BEGIN_EVENT_TABLE(CFastTextCtrl, wxTextCtrl)
 
78
        EVT_TEXT(wxID_ANY, CFastTextCtrl::OnText)
 
79
#ifdef __WXMSW__
 
80
        EVT_NAVIGATION_KEY(CFastTextCtrl::OnNavigationKey)
 
81
#else
 
82
        EVT_KEY_DOWN(CFastTextCtrl::OnKeyDown)
 
83
#endif
 
84
END_EVENT_TABLE()
 
85
 
 
86
 
19
87
CStatusView::CStatusView(wxWindow* parent, wxWindowID id)
20
88
        : wxWindow(parent, id, wxDefaultPosition, wxDefaultSize, wxSUNKEN_BORDER)
21
89
{
22
90
        m_pTextCtrl = 0;
23
 
        m_pTextCtrl = new wxTextCtrl(this, -1, _T(""), wxDefaultPosition, wxDefaultSize,
24
 
                                                                wxNO_BORDER | wxVSCROLL | wxTE_MULTILINE |
25
 
                                                                wxTE_READONLY | wxTE_RICH | wxTE_RICH2 | wxTE_NOHIDESEL | wxTE_LINEWRAP);
 
91
        m_pTextCtrl = new CFastTextCtrl(this);
26
92
        m_pTextCtrl->SetFont(GetFont());
27
93
 
28
94
        m_pTextCtrl->Connect(wxID_ANY, wxEVT_CONTEXT_MENU, wxContextMenuEventHandler(CStatusView::OnContextMenu), 0, this);
30
96
        m_nLineCount = 0;
31
97
 
32
98
        InitDefAttr();
 
99
 
 
100
        m_shown = IsShown();
33
101
}
34
102
 
35
103
CStatusView::~CStatusView()
40
108
{
41
109
        if (m_pTextCtrl)
42
110
        {
43
 
                m_pTextCtrl->SetSize(GetClientSize());
 
111
                wxSize s = GetClientSize();
 
112
                m_pTextCtrl->SetSize(0, 0, s.GetWidth(), s.GetHeight());
44
113
        }
45
114
}
46
115
 
47
116
void CStatusView::AddToLog(CLogmsgNotification *pNotification)
48
117
{
49
 
        AddToLog(pNotification->msgType, pNotification->msg);
 
118
        AddToLog(pNotification->msgType, pNotification->msg, wxDateTime::Now());
50
119
}
51
120
 
52
 
void CStatusView::AddToLog(enum MessageType messagetype, wxString message)
 
121
void CStatusView::AddToLog(enum MessageType messagetype, const wxString& message, const wxDateTime& time)
53
122
{
 
123
        if (!m_shown)
 
124
        {
 
125
                struct t_line line;
 
126
                line.messagetype = messagetype;
 
127
                line.message = message;
 
128
                line.time = time;
 
129
 
 
130
                m_hiddenLines.push_back(line);
 
131
                if (m_hiddenLines.size() > MAX_LINECOUNT)
 
132
                        m_hiddenLines.pop_front();
 
133
                return;
 
134
        }
 
135
 
 
136
        const int messageLength = message.Length();
 
137
 
 
138
#ifndef __WXGTK__
 
139
        wxWindowUpdateLocker *pLock = 0;
 
140
#endif //__WXGTK__
54
141
        wxString prefix;
55
 
        
 
142
        prefix.Alloc(25 + messageLength);
 
143
 
56
144
        if (m_nLineCount)
57
145
                prefix = _T("\n");
58
 
        
 
146
 
 
147
        if (m_showTimestamps)
 
148
        {
 
149
                if (time != m_lastTime)
 
150
                {
 
151
                        m_lastTime = time;
 
152
                        m_lastTimeString = time.Format(_T("%H:%M:%S\t"));
 
153
                }
 
154
                prefix += m_lastTimeString;
 
155
        }
 
156
 
59
157
        if (m_nLineCount == MAX_LINECOUNT)
60
158
        {
61
 
#if wxMAJOR_VERSION > 2 || wxMINOR_VERSION > 6
62
 
                wxWindowUpdateLocker lock(m_pTextCtrl);
63
 
#else
64
 
                m_pTextCtrl->Freeze();
65
 
#endif
 
159
#ifndef __WXGTK__
 
160
                pLock = new wxWindowUpdateLocker(m_pTextCtrl);
 
161
#endif //__WXGTK__
66
162
                m_pTextCtrl->Remove(0, m_lineLengths.front() + 1);
67
163
                m_lineLengths.pop_front();
68
 
#if !(wxMAJOR_VERSION > 2 || wxMINOR_VERSION > 6)
69
 
                m_pTextCtrl->Thaw();
70
 
#endif
71
164
        }
72
165
        else
73
166
                m_nLineCount++;
76
169
 
77
170
        prefix += m_attributeCache[messagetype].prefix;
78
171
 
79
 
        int lineLength = m_attributeCache[messagetype].len + message.Length();
 
172
        int lineLength = m_attributeCache[messagetype].len + messageLength;
80
173
 
81
 
#if wxMAJOR_VERSION > 2 || wxMINOR_VERSION > 6
82
174
        if (m_rtl)
83
175
        {
84
176
                // Unicode control characters that control reading direction
99
191
                        lineLength += 2;
100
192
                }
101
193
        }
102
 
#endif
103
194
 
104
195
        m_lineLengths.push_back(lineLength);
105
196
 
106
 
        m_pTextCtrl->AppendText(prefix + message);
 
197
        prefix += message;
 
198
        m_pTextCtrl->AppendText(prefix);
 
199
 
 
200
#ifndef __WXGTK__
 
201
        delete pLock;
 
202
#endif //__WXGTK__
107
203
}
108
204
 
109
205
void CStatusView::InitDefAttr()
110
206
{
 
207
        m_showTimestamps = COptions::Get()->GetOptionVal(OPTION_MESSAGELOG_TIMESTAMP) != 0;
 
208
        m_lastTime = wxDateTime::Now();
 
209
        m_lastTimeString = m_lastTime.Format(_T("%H:%M:%S\t"));
 
210
 
111
211
        // Measure withs of all types
112
212
        wxClientDC dc(this);
113
213
 
 
214
        int timestampWidth = 0;
 
215
        if (m_showTimestamps)
 
216
        {
 
217
                wxCoord width = 0;
 
218
                wxCoord height = 0;
 
219
                dc.GetTextExtent(_T("88:88:88"), &width, &height);
 
220
                timestampWidth = width;
 
221
        }
 
222
 
114
223
        int maxWidth = 0;
115
224
        wxCoord width = 0;
116
225
        wxCoord height = 0;
134
243
 
135
244
        dc.SetMapMode(wxMM_LOMETRIC);
136
245
 
137
 
        maxWidth = dc.DeviceToLogicalX(maxWidth) + 20;  
 
246
        maxWidth = dc.DeviceToLogicalX(maxWidth) + 20;
 
247
        if (timestampWidth != 0)
 
248
        {
 
249
                timestampWidth = dc.DeviceToLogicalX(timestampWidth) + 20;
 
250
                maxWidth += timestampWidth;
 
251
        }
138
252
        wxArrayInt array;
 
253
        if (timestampWidth != 0)
 
254
                array.Add(timestampWidth);
139
255
        array.Add(maxWidth);
140
256
        wxTextAttr defAttr;
141
257
        defAttr.SetTabs(array);
142
258
        defAttr.SetLeftIndent(0, maxWidth);
143
259
 
144
 
        defAttr.SetBackgroundColour(dc.GetTextBackground());
145
 
        
146
260
        for (int i = 0; i < MessageTypeCount; i++)
147
261
        {
148
262
                m_attributeCache[i].attr = defAttr;
173
287
                        break;
174
288
                default:
175
289
                        m_attributeCache[i].prefix = _("Status:");
176
 
                        m_attributeCache[i].attr.SetTextColour(wxColour(0, 0, 0));
 
290
                        m_attributeCache[i].attr.SetTextColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT));
177
291
                        break;
178
292
                }
179
293
                m_attributeCache[i].prefix += _T("\t");
180
294
                m_attributeCache[i].len = m_attributeCache[i].prefix.Length();
181
295
        }
182
296
 
183
 
#if wxMAJOR_VERSION > 2 || wxMINOR_VERSION > 6
184
297
        m_rtl = wxTheApp->GetLayoutDirection() == wxLayout_RightToLeft;
185
 
#endif
186
298
}
187
299
 
188
300
void CStatusView::OnContextMenu(wxContextMenuEvent& event)
207
319
{
208
320
        if (!m_pTextCtrl)
209
321
                return;
210
 
        
 
322
 
211
323
        long from, to;
212
324
        m_pTextCtrl->GetSelection(&from, &to);
213
325
        if (from != to)
221
333
                m_pTextCtrl->Thaw();
222
334
        }
223
335
}
 
336
 
 
337
void CStatusView::SetFocus()
 
338
{
 
339
        m_pTextCtrl->SetFocus();
 
340
}
 
341
 
 
342
bool CStatusView::Show(bool show /*=true*/)
 
343
{
 
344
        m_shown = show;
 
345
 
 
346
        if (show)
 
347
        {
 
348
                if (m_hiddenLines.size() == MAX_LINECOUNT)
 
349
                {
 
350
                        if (m_pTextCtrl)
 
351
                                m_pTextCtrl->Clear();
 
352
                        m_nLineCount = 0;
 
353
                        m_lineLengths.clear();
 
354
                }
 
355
 
 
356
                for (std::list<t_line>::const_iterator iter = m_hiddenLines.begin(); iter != m_hiddenLines.end(); iter++)
 
357
                {
 
358
                        AddToLog(iter->messagetype, iter->message, iter->time);
 
359
                }
 
360
                m_hiddenLines.clear();
 
361
        }
 
362
 
 
363
        return wxWindow::Show(show);
 
364
}