File: clResizableTooltip.cpp

package info (click to toggle)
codelite 12.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 95,112 kB
  • sloc: cpp: 424,040; ansic: 18,284; php: 9,569; lex: 4,186; yacc: 2,820; python: 2,294; sh: 312; makefile: 51; xml: 13
file content (150 lines) | stat: -rw-r--r-- 3,893 bytes parent folder | download | duplicates (2)
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
#include "clResizableTooltip.h"
#include <wx/wupdlock.h>
#include "event_notifier.h"
#include <wx/gdicmn.h>

wxDEFINE_EVENT(wxEVT_TOOLTIP_DESTROY, clCommandEvent);
wxDEFINE_EVENT(wxEVT_TOOLTIP_ITEM_EXPANDING, clCommandEvent);

clResizableTooltip::clResizableTooltip(wxEvtHandler* owner)
    : clResizableTooltipBase(EventNotifier::Get()->TopFrame())
    , m_dragging(false)
    , m_owner(owner)
{
    m_treeCtrl->SetFont(wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT));
}

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

void clResizableTooltip::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();
        }

        // Notify to the owner that this tooltip should be destroyed
        clCommandEvent destroyEvent(wxEVT_TOOLTIP_DESTROY);
        destroyEvent.SetEventObject(this);
        m_owner->AddPendingEvent(destroyEvent);
    }
}

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

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

void clResizableTooltip::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 clResizableTooltip::OnStatusEnterWindow(wxMouseEvent& event)
{
    event.Skip();
#ifndef __WXGTK__
    ::wxSetCursor(wxCURSOR_SIZING);
#endif
}

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

void clResizableTooltip::OnItemExpanding(wxTreeEvent& event) { event.Skip(); }

void clResizableTooltip::Clear() { m_treeCtrl->DeleteAllItems(); }

void clResizableTooltip::DoUpdateSize(bool performClean)
{
    if(m_dragging) {
        wxCoord ww, hh;
        wxPoint mousePt = ::wxGetMousePosition();
        ww = mousePt.x - m_topLeft.x;
        hh = mousePt.y - m_topLeft.y;
        
        wxRect curect(m_topLeft, wxSize(ww, hh));
        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 clResizableTooltip::OnCaptureLost(wxMouseCaptureLostEvent& event)
{
    event.Skip();
    if(m_panelStatus->HasCapture()) {
        m_panelStatus->ReleaseMouse();
        m_dragging = true;
    }
}

void clResizableTooltip::ShowTip()
{
    m_topLeft = ::wxGetMousePosition();
    Move(m_topLeft);
    wxPopupWindow::Show();
    if(GetTreeCtrl() && GetTreeCtrl()->IsShown()) {
        GetTreeCtrl()->SetFocus();
    }
    
}