File: clConfigurationSelectionCtrl.cpp

package info (click to toggle)
codelite 12.0+dfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster, sid
  • 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 (127 lines) | stat: -rw-r--r-- 4,375 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
#include "bitmap_loader.h"
#include "clConfigurationSelectionCtrl.h"
#include "codelite_events.h"
#include "drawingutils.h"
#include "event_notifier.h"
#include "globals.h"
#include "imanager.h"
#include "wxStringHash.h"
#include <wx/dcbuffer.h>
#include <wx/dcgraph.h>
#include <wx/menu.h>

clConfigurationSelectionCtrl::clConfigurationSelectionCtrl(wxWindow* parent, wxWindowID winid, const wxPoint& pos,
                                                           const wxSize& size, long style)
    : wxPanel(parent, winid, pos, size, style)
    , m_state(eButtonState::kNormal)
{
    Bind(wxEVT_ENTER_WINDOW, &clConfigurationSelectionCtrl::OnEnterWindow, this);
    Bind(wxEVT_LEAVE_WINDOW, &clConfigurationSelectionCtrl::OnLeaveWindow, this);
    Bind(wxEVT_PAINT, &clConfigurationSelectionCtrl::OnPaint, this);
    Bind(wxEVT_ERASE_BACKGROUND, &clConfigurationSelectionCtrl::OnEraseBG, this);
    Bind(wxEVT_LEFT_DOWN, &clConfigurationSelectionCtrl::OnLeftDown, this);
    SetBackgroundStyle(wxBG_STYLE_PAINT);
    SetSizeHints(DrawingUtils::GetBestSize("ABCDEFGHIJKLp"));
}

clConfigurationSelectionCtrl::~clConfigurationSelectionCtrl()
{
    Unbind(wxEVT_ENTER_WINDOW, &clConfigurationSelectionCtrl::OnEnterWindow, this);
    Unbind(wxEVT_LEAVE_WINDOW, &clConfigurationSelectionCtrl::OnLeaveWindow, this);
    Unbind(wxEVT_PAINT, &clConfigurationSelectionCtrl::OnPaint, this);
    Unbind(wxEVT_ERASE_BACKGROUND, &clConfigurationSelectionCtrl::OnEraseBG, this);
    Unbind(wxEVT_LEFT_DOWN, &clConfigurationSelectionCtrl::OnLeftDown, this);
}

void clConfigurationSelectionCtrl::OnPaint(wxPaintEvent& e)
{
    wxAutoBufferedPaintDC dc(this);
    PrepareDC(dc);

#ifdef __WXGTK__
    wxDC &gcdc = dc;
#else
    wxGCDC gcdc(dc);
    PrepareDC(gcdc);
#endif
    
    wxRect rect = GetClientRect();
    dc.SetPen(DrawingUtils::GetPanelBgColour());
    dc.SetBrush(DrawingUtils::GetPanelBgColour());
    dc.DrawRectangle(rect);
    
    // Build the text to draw
    wxString label;
    label << m_activeProject << " :: " << m_activeConfiguration;
    DrawingUtils::DrawButton(gcdc, this, GetClientRect(), label, wxNullBitmap, eButtonKind::kDropDown,
                             eButtonState::kNormal);
}

void clConfigurationSelectionCtrl::OnEraseBG(wxEraseEvent& e) {}

void clConfigurationSelectionCtrl::Update(const wxArrayString& projects, const wxArrayString& configurations)
{
    m_projects = projects;
    m_configurations = configurations;
}

void clConfigurationSelectionCtrl::Clear() {}

void clConfigurationSelectionCtrl::OnLeftDown(wxMouseEvent& e)
{
    wxUnusedVar(e);
    wxPoint pt = GetClientRect().GetBottomLeft();
#ifdef __WXOSX__
    pt.y += 5;
#endif
    wxMenu menu;
    std::unordered_map<int, wxString> M;
    for(size_t i = 0; i < m_configurations.GetCount(); ++i) {
        wxMenuItem* item = menu.Append(wxID_ANY, m_configurations.Item(i), "", wxITEM_CHECK);
        if(m_configurations.Item(i) == m_activeConfiguration) { item->Check(); }
        M[item->GetId()] = m_configurations.Item(i);
    }
    menu.AppendSeparator();
    wxMenuItem* openConfig = new wxMenuItem(NULL, wxID_ANY, OPEN_CONFIG_MGR_STR, "", wxITEM_CHECK);
    // openConfig->SetBitmap(clGetManager()->GetStdIcons()->LoadBitmap("cog"));
    openConfig = menu.Append(openConfig);
    M[openConfig->GetId()] = OPEN_CONFIG_MGR_STR;

    int selection = GetPopupMenuSelectionFromUser(menu, pt);
    if(selection == wxID_NONE) { return; }

    wxString newConfig = M[selection];
    clCommandEvent changeEvent(wxEVT_WORKSPACE_BUILD_CONFIG_CHANGED);
    changeEvent.SetString(newConfig);
    EventNotifier::Get()->AddPendingEvent(changeEvent);

    if(newConfig != OPEN_CONFIG_MGR_STR) { m_activeConfiguration = newConfig; }
    m_state = eButtonState::kNormal;
    Refresh();
}

void clConfigurationSelectionCtrl::OnEnterWindow(wxMouseEvent& e)
{
    wxUnusedVar(e);
    m_state = eButtonState::kHover;
    Refresh();
}

void clConfigurationSelectionCtrl::OnLeaveWindow(wxMouseEvent& e)
{
    wxUnusedVar(e);
    m_state = eButtonState::kNormal;
    Refresh();
}

void clConfigurationSelectionCtrl::SetActiveConfiguration(const wxString& activeConfiguration)
{
    this->m_activeConfiguration = activeConfiguration;
    Refresh();
}

void clConfigurationSelectionCtrl::SetActiveProject(const wxString& activeProject)
{
    this->m_activeProject = activeProject;
    Refresh();
}