Code::Blocks  SVN r11506
cbstatusbar.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
3  * http://www.gnu.org/licenses/lgpl-3.0.html
4  *
5  */
6 
7 #include "sdk_precomp.h"
8 
9 #ifndef CB_PRECOMP
10  #include <wx/frame.h> // wxFrame
11  #include <wx/menu.h>
12  #include <wx/statusbr.h>
13  #include "cbplugin.h"
14  #include "compiler.h" // GetSwitches
15  #include "sdk_events.h"
16  #include "manager.h"
17  #include "projectbuildtarget.h"
18  #include "cbproject.h"
19  #include "logmanager.h"
20 #endif
21 
22 #include "cbstatusbar.h"
23 
24 BEGIN_EVENT_TABLE(cbStatusBar, wxStatusBar)
25  EVT_SIZE(cbStatusBar::OnSize)
26 END_EVENT_TABLE()
27 
28 
29 cbStatusBar::cbStatusBar(wxWindow* parent, cb_unused wxWindowID id, long style, const wxString& name) // TODO: Check if window id should be removed?
30  : wxStatusBar(parent, wxID_ANY, style, name)
31 {
32 }
33 
35 {
36 }
37 
39 {
40  int pos = GetFieldNumberOfPlugin(plugin);
41  if (pos != -1)
42  wxStatusBar::SetStatusText(text, pos);
43 }
44 
46 {
47  int pos = GetFieldNumberOfPlugin(plugin);
48  if (pos != -1)
49  return wxStatusBar::GetStatusText(pos);
50  return wxEmptyString;
51 }
52 
54 {
55  int pos = GetFieldNumberOfPlugin(plugin);
56  if (pos != -1)
57  return wxStatusBar::GetFieldRect(pos, rect);
58  return false;
59 }
60 
61 void cbStatusBar::SetStatusWidths(int n, const int* widths)
62 {
63  if (widths)
64  {
65  m_MainWidths.clear();
66  for (int i = 0 ; i < n ; i++)
67  m_MainWidths.push_back(widths[i]);
68  UpdateWidths();
69  }
70 }
71 
72 void cbStatusBar::AddField(cbPlugin* plugin, wxWindow* ctrl, int width)
73 {
74  cbStatusBarElement elem;
75  elem.control = ctrl;
76  elem.width = width;
77  elem.plugin = plugin;
78 
79  m_Elements.push_back(elem);
80 
81  UpdateWidths();
82 
83  return;
84 }
85 void cbStatusBar::AddField(cbPlugin* plugin, int width)
86 {
87  return AddField(plugin, (wxControl*)NULL, width);
88 }
89 
91 {
92  for (ElementVector::iterator it = m_Elements.begin() ; it != m_Elements.end() ; it++)
93  {
94  if (it->plugin == plugin)
95  {
96  if (it->control)
97  it->control->Destroy();
98  m_Elements.erase(it);
99  break;
100  }
101  }
102  UpdateWidths();
103 }
104 
106 {
108  event.Skip();
109 }
110 
112 {
113  unsigned int n = m_MainWidths.size() + m_Elements.size();
114 
115  int *widths = new int[n];
116  unsigned int i = 0;
117  for (; i < m_MainWidths.size() ; i++)
118  widths[i] = m_MainWidths[i];
119  for (int k= 0 ; i < n ; i++, k++)
120  widths[i] = m_Elements[k].width;
121 
123  wxStatusBar::SetStatusWidths(n, widths);
124  delete[] widths;
125 }
126 
128 {
129  for (unsigned int i = 0 ; i < m_Elements.size(); i++)
130  {
131  wxWindow *ctrl = m_Elements[i].control;
132  if (ctrl)
133  {
134  wxRect rect;
135  GetFieldRectByPlugin(m_Elements[i].plugin, rect);
136  ctrl->SetSize(rect.x + 2, rect.y + 2, rect.width - 4, rect.height - 4);
137  }
138  }
139 }
140 
142 {
143  for (unsigned int i = 0 ; i < m_Elements.size() ; i++)
144  {
145  if (m_Elements[i].plugin == plugin)
146  return i+m_MainWidths.size();
147  }
148  // return -1 to indicate that the id does not exist
149  return -1;
150 }
void SetStatusWidths(int n, const int *widths) override
Definition: cbstatusbar.cpp:61
Base class for plugins.
Definition: cbplugin.h:84
std::vector< int > m_MainWidths
Definition: cbstatusbar.h:89
virtual wxString GetStatusTextByPlugin(cbPlugin *plugin) const
Returns the string associated with a status bar field.
Definition: cbstatusbar.cpp:45
virtual void SetStatusText(const wxString &text, int i=0)
void UpdateWidths()
virtual void SetStatusWidths(int n, const int *widths_field)
ElementVector m_Elements
Definition: cbstatusbar.h:88
void AdjustFieldsSize()
int GetFieldNumberOfPlugin(cbPlugin *plugin) const
A custom status bar which can contain controls, icons...
Definition: cbstatusbar.h:18
wxString wxEmptyString
void OnSize(wxSizeEvent &event)
virtual bool GetFieldRect(int i, wxRect &rect) const
int width
virtual wxString GetStatusText(int i=0) const
virtual void SetFieldsCount(int number=1, const int *widths=NULL)
void AddField(cbPlugin *plugin, wxWindow *ctrl, int width)
Add a new field, which contains a control, to the status bar.
Definition: cbstatusbar.cpp:72
void RemoveField(cbPlugin *plugin)
Remove a field from the status bar.
Definition: cbstatusbar.cpp:90
int height
~cbStatusBar() override
Definition: cbstatusbar.cpp:34
#define NULL
Definition: prefix.cpp:59
int wxWindowID
virtual void SetStatusTextByPlugin(const wxString &text, cbPlugin *plugin)
Sets the text for one field.
Definition: cbstatusbar.cpp:38
virtual bool GetFieldRectByPlugin(cbPlugin *plugin, wxRect &rect) const
Returns the size and position of a field&#39;s internal bounding rectangle.
Definition: cbstatusbar.cpp:53