Code::Blocks  SVN r11506
threadsdlg.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU General Public License, version 3
3  * http://www.gnu.org/licenses/gpl-3.0.html
4  *
5  * $Revision: 10024 $
6  * $Id: threadsdlg.cpp 10024 2014-11-06 09:23:26Z jenslody $
7  * $HeadURL: https://svn.code.sf.net/p/codeblocks/code/trunk/src/src/threadsdlg.cpp $
8  */
9 
10 #include "sdk.h"
11 
12 #ifndef CB_PRECOMP
13  #include <wx/listctrl.h>
14  #include <wx/menu.h>
15  #include <wx/sizer.h>
16 
17  #include "cbplugin.h"
18  #include "debuggermanager.h"
19 #endif
20 
21 #include "threadsdlg.h"
22 #include "cbcolourmanager.h"
23 #include "debuggermanager.h"
24 
25 namespace
26 {
27  const int idList = wxNewId();
28  const int idSwitch = wxNewId();
29 }
30 
31 BEGIN_EVENT_TABLE(ThreadsDlg, wxPanel)
32  EVT_LIST_ITEM_RIGHT_CLICK(idList, ThreadsDlg::OnListRightClick)
33  EVT_LIST_ITEM_ACTIVATED(idList, ThreadsDlg::OnListDoubleClick)
34  EVT_MENU(idSwitch, ThreadsDlg::OnSwitchThread)
35 END_EVENT_TABLE()
36 
37 
39 {
40  m_list = new wxListCtrl(this, idList, wxDefaultPosition, wxDefaultSize,
42  wxBoxSizer* bs = new wxBoxSizer(wxVERTICAL);
43  bs->Add(m_list, 1, wxEXPAND | wxALL);
44  SetAutoLayout(true);
45  SetSizer(bs);
46 
48  m_list->SetFont(font);
49  m_list->InsertColumn(0, _("Active"), wxLIST_FORMAT_LEFT, 64);
50  m_list->InsertColumn(1, _("Number"), wxLIST_FORMAT_RIGHT, 64);
51  m_list->InsertColumn(2, _("Info"), wxLIST_FORMAT_LEFT);
52 
53  Manager::Get()->GetColourManager()->RegisterColour(_("Debugger"), _("Active thread text"),
54  wxT("dbg_threads_active_text"), *wxWHITE);
55  Manager::Get()->GetColourManager()->RegisterColour(_("Debugger"), _("Active thread background"),
56  wxT("dbg_threads_active_back"), *wxRED);
57 }
58 
60 {
62  if (!plugin)
63  return;
64 
66 
67  m_list->Freeze();
69  long active_index = -1;
70  for (int ii = 0; ii < plugin->GetThreadsCount(); ++ii)
71  {
72  cb::shared_ptr<const cbThread> thread = plugin->GetThread(ii);
73 
74  long index = m_list->InsertItem(m_list->GetItemCount(), thread->IsActive() ? wxT("-->") : wxT(""));
75 
76  m_list->SetItem(index, 1, wxString::Format(wxT("%d"), thread->GetNumber()));
77  m_list->SetItem(index, 2, thread->GetInfo());
78  if (thread->IsActive())
79  {
80  m_list->SetItemTextColour(index, colours->GetColour(wxT("dbg_threads_active_text")));
81  m_list->SetItemBackgroundColour(index, colours->GetColour(wxT("dbg_threads_active_back")));
82  active_index = index;
83  }
84  }
85  if (active_index != -1)
86  m_list->EnsureVisible(active_index);
87  m_list->Thaw();
88  for (int ii = 0; ii < m_list->GetColumnCount(); ++ii)
89  {
91  }
92 }
93 
94 //void ThreadsDlg::AddThread(const wxString& active_mark, const wxString& thread_num, const wxString& thread_info)
95 //{
96 // m_list->Freeze();
97 // m_list->InsertItem(m_list->GetItemCount(), active_mark);
98 // int idx = m_list->GetItemCount() - 1;
99 // m_list->SetItem(idx, 1, thread_num);
100 // m_list->SetItem(idx, 2, thread_info);
101 //
102 // m_list->SetColumnWidth(2, wxLIST_AUTOSIZE);
103 // m_list->Thaw();
104 //}
105 
107 {
108  if (m_list->GetSelectedItemCount() == 0)
109  return;
110  wxMenu m;
111  m.Append(idSwitch, _("Switch to this thread"));
112  m_list->PopupMenu(&m);
113 }
114 
115 void ThreadsDlg::OnListDoubleClick(cb_unused wxListEvent& /* event */) // TODO: verify this please
116 {
117  wxCommandEvent event; // is ignoring the original event and using an empty event really what is intended?
118  OnSwitchThread(event);
119 }
120 
122 {
123  if (m_list->GetSelectedItemCount() == 0)
124  return;
125 
126  // find selected item index
128 
129  wxString thread;
130  wxListItem info;
131  info.m_itemId = index;
132  info.m_col = 1;
133  info.m_mask = wxLIST_MASK_TEXT;
134  if (m_list->GetItem(info))
135  thread = info.m_text;
136  else
137  return;
138 
139  unsigned long thread_num;
140  if (thread.ToULong(&thread_num, 10))
141  {
143  if(plugin)
144  plugin->SwitchToThread(thread_num);
145  }
146 }
147 
148 void ThreadsDlg::EnableWindow(bool enable)
149 {
150  m_list->Enable(enable);
151 }
cbDebuggerPlugin * GetActiveDebugger()
int wxNewId()
virtual int GetThreadsCount() const =0
int GetSelectedItemCount() const
void SetItemBackgroundColour(long item, const wxColour &col)
Base class for debugger plugins.
Definition: cbplugin.h:397
static Manager * Get()
Use Manager::Get() to get a pointer to its instance Manager::Get() is guaranteed to never return an i...
Definition: manager.cpp:182
long GetNextItem(long item, int geometry=wxLIST_NEXT_ALL, int state=wxLIST_STATE_DONTCARE) const
void Reload()
Definition: threadsdlg.cpp:59
#define wxLC_HRULES
void RegisterColour(const wxString &category, const wxString &name, const wxString &id, const wxColour &defaultColour)
#define wxLC_REPORT
void OnListRightClick(wxListEvent &event)
Definition: threadsdlg.cpp:106
wxMenuItem * Append(int id, const wxString &item=wxEmptyString, const wxString &helpString=wxEmptyString, wxItemKind kind=wxITEM_NORMAL)
#define wxLIST_STATE_SELECTED
bool ToULong(unsigned long *val, int base=10) const
#define wxT(string)
void OnListDoubleClick(wxListEvent &event)
Definition: threadsdlg.cpp:115
#define wxLIST_MASK_TEXT
wxListCtrl * m_list
Definition: threadsdlg.h:33
long InsertItem(wxListItem &info)
DebuggerManager * GetDebuggerManager() const
Definition: manager.cpp:484
void EnableWindow(bool enable)
Definition: threadsdlg.cpp:148
wxColour GetColour(const wxString &id) const
wxColour * wxRED
wxSizerItem * Add(wxWindow *window, const wxSizerFlags &flags)
void SetItemTextColour(long item, const wxColour &col)
const wxSize wxDefaultSize
const wxPoint wxDefaultPosition
bool DeleteAllItems()
int GetItemCount() const
wxColour * wxWHITE
#define wxLC_SINGLE_SEL
const wxString & _(const wxString &string)
ColourManager * GetColourManager() const
Definition: manager.cpp:489
virtual bool SwitchToThread(int thread_number)=0
virtual cb::shared_ptr< const cbThread > GetThread(int index) const =0
int GetColumnCount() const
bool SetItem(wxListItem &info)
void OnSwitchThread(wxCommandEvent &event)
Definition: threadsdlg.cpp:121
bool SetColumnWidth(int col, int width)
#define wxLC_VRULES
bool EnsureVisible(long item)
static wxString Format(const wxString &format,...)
bool GetItem(wxListItem &info) const