summaryrefslogtreecommitdiff
path: root/shared/customTooltip.cpp
blob: bffaa45da63310caa3c6a52707c77ca45dd84530 (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
#include "customTooltip.h"
#include <wx/stattext.h>
#include <wx/sizer.h>
#include <wx/statbmp.h>


class PopupFrameGenerated : public wxFrame
{
public:
    PopupFrameGenerated(wxWindow* parent,
                        wxWindowID id = wxID_ANY,
                        const wxString& title = wxEmptyString,
                        const wxPoint& pos = wxDefaultPosition,
                        const wxSize& size = wxSize( -1,-1 ),
                        long style = wxFRAME_NO_TASKBAR | wxSTAY_ON_TOP | wxSTATIC_BORDER);

    wxStaticText* m_staticTextMain;
    wxStaticBitmap* m_bitmapLeft;
};


PopupFrameGenerated::PopupFrameGenerated(
    wxWindow* parent,
    wxWindowID id,
    const wxString& title,
    const wxPoint& pos,
    const wxSize& size,
    long style ) : wxFrame(parent, id, title, pos, size, style)
{
    this->SetSizeHints( wxDefaultSize, wxDefaultSize );
    this->SetBackgroundColour( wxColour( 255, 255, 255 ) );

    wxBoxSizer* bSizer158;
    bSizer158 = new wxBoxSizer( wxHORIZONTAL );

    m_bitmapLeft = new wxStaticBitmap( this, wxID_ANY, wxNullBitmap, wxDefaultPosition, wxDefaultSize, 0 );
    bSizer158->Add( m_bitmapLeft, 0, wxALL|wxALIGN_CENTER_VERTICAL, 5 );

    m_staticTextMain = new wxStaticText( this, wxID_ANY, wxEmptyString, wxDefaultPosition, wxDefaultSize, 0 );
    m_staticTextMain->Wrap( -1 );
    bSizer158->Add( m_staticTextMain, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL, 5 );

    this->SetSizer( bSizer158 );
    this->Layout();
    bSizer158->Fit( this );
}


CustomTooltip::CustomTooltip() : tipWindow(new PopupFrameGenerated(NULL)), lastBmp(NULL)
{
    hide();
}


CustomTooltip::~CustomTooltip()
{
    tipWindow->Destroy();
}


void CustomTooltip::show(const wxString& text, wxPoint pos, const wxBitmap* bmp)
{
    if (bmp != lastBmp)
    {
        lastBmp = bmp;
        tipWindow->m_bitmapLeft->SetBitmap(bmp == NULL ? wxNullBitmap : *bmp);
    }

    if (text != tipWindow->m_staticTextMain->GetLabel())
        tipWindow->m_staticTextMain->SetLabel(text);

#ifdef FFS_LINUX
    tipWindow->Fit(); //Alas Fit() seems to be somewhat broken => this needs to be called EVERY time inside show, not only if text or bmp change.
#endif

    if (pos != tipWindow->GetScreenPosition())
        tipWindow->SetSize(pos.x + 30, pos.y, wxDefaultCoord, wxDefaultCoord);
    //attention!!! possible endless loop: mouse pointer must NOT be within tipWindow!
    //Else it will trigger a wxEVT_LEAVE_WINDOW which will hide the window, causing the window to be shown again in via this method, etc.

    if (!tipWindow->IsShown())
        tipWindow->Show();
}


void CustomTooltip::hide()
{
    tipWindow->Hide();
}
bgstack15