File: LLDBTooltip.cpp

package info (click to toggle)
codelite 6.1.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 48,992 kB
  • ctags: 43,502
  • sloc: cpp: 334,263; ansic: 18,441; xml: 4,713; yacc: 2,653; lex: 2,449; python: 1,188; sh: 385; makefile: 40
file content (256 lines) | stat: -rw-r--r-- 7,600 bytes parent folder | download
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
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////
//
// copyright            : (C) 2014 The CodeLite Team
// file name            : LLDBTooltip.cpp
//
// -------------------------------------------------------------------------
// A
//              _____           _      _     _ _
//             /  __ \         | |    | |   (_) |
//             | /  \/ ___   __| | ___| |    _| |_ ___
//             | |    / _ \ / _  |/ _ \ |   | | __/ _ )
//             | \__/\ (_) | (_| |  __/ |___| | ||  __/
//              \____/\___/ \__,_|\___\_____/_|\__\___|
//
//                                                  F i l e
//
//    This program is free software; you can redistribute it and/or modify
//    it under the terms of the GNU General Public License as published by
//    the Free Software Foundation; either version 2 of the License, or
//    (at your option) any later version.
//
//////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////

#include "LLDBTooltip.h"
#include "LLDBPlugin.h"
#include "macros.h"
#include "event_notifier.h"
#include <wx/wupdlock.h>
#include "cl_config.h"

LLDBTooltip::LLDBTooltip(wxWindow* parent, LLDBPlugin* plugin)
    : LLDBTooltipBase(parent)
    , m_plugin(plugin)
    , m_dragging(false)
{
    int initialSizeW = clConfig::Get().Read("LLDBTooltipW", wxNOT_FOUND);
    int initialSizeH = clConfig::Get().Read("LLDBTooltipH", wxNOT_FOUND);

    if(initialSizeH != wxNOT_FOUND && initialSizeW != wxNOT_FOUND) {
        wxSize initSize(initialSizeW, initialSizeH);

        if(initSize.GetWidth() > 200 && initSize.GetHeight() > 150) {
            SetSize(initSize);

        } else {
            SetSize(wxSize(200, 150));
        }
    }

    m_plugin->GetLLDB()->Bind(wxEVT_LLDB_VARIABLE_EXPANDED, &LLDBTooltip::OnLLDBVariableExpanded, this);
    m_panelStatus->Bind(wxEVT_MOUSE_CAPTURE_LOST, &LLDBTooltip::OnCaptureLost, this);
}

LLDBTooltip::~LLDBTooltip()
{
    if(m_panelStatus->HasCapture()) {
        m_panelStatus->ReleaseMouse();
    }

    // store the size
    wxSize sz = GetSize();
    clConfig::Get().Write("LLDBTooltipW", sz.GetWidth());
    clConfig::Get().Write("LLDBTooltipH", sz.GetHeight());

    m_plugin->GetLLDB()->Unbind(wxEVT_LLDB_VARIABLE_EXPANDED, &LLDBTooltip::OnLLDBVariableExpanded, this);
    m_panelStatus->Unbind(wxEVT_MOUSE_CAPTURE_LOST, &LLDBTooltip::OnCaptureLost, this);
}

void LLDBTooltip::OnItemExpanding(wxTreeEvent& event)
{
    CHECK_ITEM_RET(event.GetItem());
    LLDBVariableClientData* data = ItemData(event.GetItem());

    wxTreeItemIdValue cookie;
    wxTreeItemId child = m_treeCtrl->GetFirstChild(event.GetItem(), cookie);
    if(m_treeCtrl->GetItemText(child) == "<dummy>") {

        // dummy item, remove it
        m_treeCtrl->DeleteChildren(event.GetItem());
        m_plugin->GetLLDB()->RequestVariableChildren(data->GetVariable()->GetLldbId());

        // Store the treeitemid parent in cache
        m_itemsPendingExpansion.insert(std::make_pair(data->GetVariable()->GetLldbId(), event.GetItem()));

    } else {
        event.Skip();
    }
}

void LLDBTooltip::Show(const wxString& displayName, LLDBVariable::Ptr_t variable)
{
    DoCleanup();
    wxTreeItemId item = m_treeCtrl->AddRoot(
        variable->ToString(displayName), wxNOT_FOUND, wxNOT_FOUND, new LLDBVariableClientData(variable));
    if(variable->HasChildren()) {
        m_treeCtrl->AppendItem(item, "<dummy>");
    }

    Move(::wxGetMousePosition());
    wxPopupWindow::Show();
    m_treeCtrl->SetFocus();
}

void LLDBTooltip::DoCleanup()
{
    m_treeCtrl->DeleteAllItems();
    m_itemsPendingExpansion.clear();
}

void LLDBTooltip::OnCheckMousePosition(wxTimerEvent& event)
{
#ifdef __WXMSW__
    // On Windows, wxPopupWindow does not return a correct position
    // in screen coordinates. So we use the inside tree-ctrl to
    // calc our position and size
    wxPoint tipPoint = m_treeCtrl->GetPosition();
    tipPoint = m_treeCtrl->ClientToScreen(tipPoint);
    wxSize tipSize = GetSize();
    // Construct a wxRect from the tip size/position
    wxRect rect(tipPoint, tipSize);
#else
    // Linux and OSX it works
    wxRect rect(GetRect());
#endif

    // and increase it by 15 pixels
    rect.Inflate(15, 15);
    if(!rect.Contains(::wxGetMousePosition())) {
        if(m_panelStatus->HasCapture()) {
            m_panelStatus->ReleaseMouse();
        }
        m_plugin->CallAfter(&LLDBPlugin::DestroyTooltip);
    }
}

LLDBVariableClientData* LLDBTooltip::ItemData(const wxTreeItemId& item) const
{
    return dynamic_cast<LLDBVariableClientData*>(m_treeCtrl->GetItemData(item));
}

void LLDBTooltip::OnLLDBVariableExpanded(LLDBEvent& event)
{
    int variableId = event.GetVariableId();
    std::map<int, wxTreeItemId>::iterator iter = m_itemsPendingExpansion.find(event.GetVariableId());
    if(iter == m_itemsPendingExpansion.end()) {
        // does not belong to us
        event.Skip();
        return;
    }

    wxTreeItemId parentItem = iter->second;

    // add the variables to the tree
    for(size_t i = 0; i < event.GetVariables().size(); ++i) {
        DoAddVariable(parentItem, event.GetVariables().at(i));
    }

    // Expand the parent item
    if(m_treeCtrl->HasChildren(parentItem)) {
        m_treeCtrl->Expand(parentItem);
    }

    // remove it
    m_itemsPendingExpansion.erase(iter);
}

void LLDBTooltip::DoAddVariable(const wxTreeItemId& parent, LLDBVariable::Ptr_t variable)
{
    wxTreeItemId item = m_treeCtrl->AppendItem(
        parent, variable->ToString(), wxNOT_FOUND, wxNOT_FOUND, new LLDBVariableClientData(variable));
    if(variable->HasChildren()) {
        m_treeCtrl->AppendItem(item, "<dummy>");
    }
}

void LLDBTooltip::OnStatusBarLeftDown(wxMouseEvent& event)
{
    m_dragging = true;
#ifndef __WXGTK__
    wxSetCursor(wxCURSOR_SIZING);
#endif
    m_panelStatus->CaptureMouse();
}

void LLDBTooltip::OnStatusBarLeftUp(wxMouseEvent& event)
{
    event.Skip();
    DoUpdateSize(true);
}

void LLDBTooltip::OnCaptureLost(wxMouseCaptureLostEvent& e)
{
    e.Skip();
    if(m_panelStatus->HasCapture()) {
        m_panelStatus->ReleaseMouse();
        m_dragging = true;
    }
}

void LLDBTooltip::OnStatusBarMotion(wxMouseEvent& event)
{
    event.Skip();
    if(m_dragging) {
        wxRect curect = GetScreenRect();
        wxPoint curpos = ::wxGetMousePosition();

        int xDiff = curect.GetBottomRight().x - curpos.x;
        int yDiff = curect.GetBottomRight().y - curpos.y;

        if((abs(xDiff) > 3) || (abs(yDiff) > 3)) {
            DoUpdateSize(false);
        }
    }
}

void LLDBTooltip::DoUpdateSize(bool performClean)
{
    if(m_dragging) {
        wxRect curect = GetScreenRect();
        curect.SetBottomRight(::wxGetMousePosition());
        if(curect.GetHeight() > 100 && curect.GetWidth() > 100) {
#ifdef __WXMSW__
            wxWindowUpdateLocker locker(EventNotifier::Get()->TopFrame());
#endif
            SetSize(curect);
        }
    }

    if(performClean) {
        m_dragging = false;
        if(m_panelStatus->HasCapture()) {
            m_panelStatus->ReleaseMouse();
        }
#ifndef __WXGTK__
        wxSetCursor(wxNullCursor);
#endif
    }
}

void LLDBTooltip::OnStatusEnterWindow(wxMouseEvent& event)
{
    event.Skip();
#ifndef __WXGTK__
    ::wxSetCursor(wxCURSOR_SIZING);
#endif
}

void LLDBTooltip::OnStatusLeaveWindow(wxMouseEvent& event)
{
    event.Skip();
#ifndef __WXGTK__
    ::wxSetCursor(wxNullCursor);
#endif
}