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 #ifndef CBSTATUSBAR_H
7 #define CBSTATUSBAR_H
8 
9 #include <vector>
10 #include <wx/statusbr.h>
11 
12 #include "settings.h"
13 
14 class cbPlugin;
15 
16 /** @brief A custom status bar which can contain controls, icons...
17   */
18 class DLLIMPORT cbStatusBar : public wxStatusBar
19 {
20 private:
21     friend class MainFrame; // gets initialized from mainframe
22 
23     // this will be used from friend mainframe
24     cbStatusBar(wxWindow* parent,  wxWindowID id, long style, const wxString& name);
cbStatusBar()25     cbStatusBar() { ; };
26     cbStatusBar ( const cbStatusBar& );
27     ~cbStatusBar() override;
28 
29 public:
30     /** Sets the text for one field.
31         @param text  The text to be set.
32         @param plugin  The pugin which wants to set its status text
33       */
34     virtual void SetStatusTextByPlugin(const wxString& text, cbPlugin* plugin);
35 
36     /** Returns the string associated with a status bar field.
37         @param  plugin  The plugin which wants to get its status text
38         @return The  status field string if the field id is valid, otherwise the empty string.
39       */
40     virtual wxString GetStatusTextByPlugin(cbPlugin* plugin) const;
41 
42     /** Returns the size and position of a field's internal bounding rectangle.
43         @param  plugin  The plugin which wants to know its status-field size.
44         @param rect  The rectangle values are placed in this variable.
45         @return true if the field id is valid, false otherwise.
46       */
47     virtual bool GetFieldRectByPlugin(cbPlugin *plugin, wxRect& rect) const;
48 
49     // functions used for the mainframe:
50     void SetStatusWidths(int n, const int* widths) override;
51 
52     /** Add a new field, which contains a control, to the status bar.
53         @param   plugin The plugin which wants to add a new statusfield
54         @param   ctrl   Pointer to the control to show on the new field.
55         @param   width  Width of the new field. See wxStatusBar::SetStatusWidths for the meaning of this parameter.
56       **/
57     void AddField(cbPlugin* plugin, wxWindow* ctrl, int width);
58 
59     /** Add a new field to the status bar. The field contains no control.
60         @see cbStatusBar::AddField(cbPlugin *plugin, wxWindow *ctrl, int width) for details.
61       **/
62     void AddField(cbPlugin* plugin, int width);
63 
64     /** Remove a field from the status bar.
65         If a control is associated wit this filed, RemoveField will destroy it.
66         @param id   The plugin which wants to remove its field
67       **/
68     void RemoveField(cbPlugin* plugin);
69 
70 private:
71     // event handlers
72     void OnSize(wxSizeEvent& event);
73     void UpdateWidths();
74 
75     void AdjustFieldsSize();
76     int  GetFieldNumberOfPlugin(cbPlugin* plugin) const;
77 
PushStatusText(cb_unused const wxString & text,cb_unused cbPlugin * plugin)78     void PushStatusText(cb_unused const wxString& text, cb_unused cbPlugin *plugin) { ; };
PopStatusText(cb_unused cbPlugin * plugin)79     void PopStatusText(cb_unused cbPlugin* plugin)                                  { ; };
80 
81     struct cbStatusBarElement
82     {
83         int       width;
84         wxWindow *control;
85         cbPlugin *plugin;
86     };
87     typedef std::vector<cbStatusBarElement> ElementVector;
88     ElementVector                           m_Elements;
89     std::vector<int>                        m_MainWidths;
90 
91     DECLARE_EVENT_TABLE()
92 };
93 
94 #endif //CBSTATUSBAR_H
95