{"id":3844,"date":"2021-12-14T11:41:42","date_gmt":"2021-12-14T11:41:42","guid":{"rendered":"http:\/\/truelogic.org\/wordpress\/?p=3844"},"modified":"2021-12-14T11:41:44","modified_gmt":"2021-12-14T11:41:44","slug":"4d-wxwidgets-multiple-toolbars","status":"publish","type":"post","link":"https:\/\/truelogic.org\/wordpress\/2021\/12\/14\/4d-wxwidgets-multiple-toolbars\/","title":{"rendered":"4d. wxWidgets &#8211; Multiple Toolbars"},"content":{"rendered":"\n<p><strong>OVERVIEW<\/strong><\/p>\n\n\n\n<p>We extend the code from the previous section to have two toolbars and divide the existing icons between the two. We use a wxBoxSizer in this case so that we can put the toolbars one below the other. We look at using sizers later in this series.<\/p>\n\n\n\n<p><strong>SAMPLE CODE<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">toolbars2.h<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &lt;wx\/wxprec.h&gt;\n#ifndef WX_PRECOMP\n\t#include &lt;wx\/wx.h&gt;\n#endif\n\nclass Toolbar: public wxFrame {\n\n\tpublic:\n\t\tToolbar(const wxString&amp; title);\n\t\tvoid OnToolItem(wxCommandEvent &amp;evt);\n\t\tvoid OnToolItem2(wxCommandEvent &amp;evt);\n\n};\n\nconst int ID_NEW = 101;\nconst int ID_SAVE = 102;\nconst int ID_OPEN = 103;\nconst int ID_EXPORT = 104;\n\n\n<\/pre><\/div>\n\n\n<pre class=\"wp-block-preformatted\">toolbars2.cpp<\/pre>\n\n\n<div class=\"wp-block-syntaxhighlighter-code \"><pre class=\"brush: cpp; title: ; notranslate\" title=\"\">\n#include &quot;toolbars2.h&quot;\n\nToolbar::Toolbar(const wxString&amp; title):\n\twxFrame(NULL, -1, title, wxDefaultPosition, wxSize(500,300)) {\n\n\tSetBackgroundColour(wxColour(255,255,255));\n\twxImage::AddHandler(new wxPNGHandler());\t\n\twxBitmap bmpAdd (wxT(&quot;bulb.png&quot;), wxBITMAP_TYPE_PNG);\n\twxBitmap bmpSave (wxT(&quot;folder.png&quot;), wxBITMAP_TYPE_PNG);\n\twxBitmap bmpOpen (wxT(&quot;edit.png&quot;), wxBITMAP_TYPE_PNG);\n\twxBitmap bmpExport (wxT(&quot;export.png&quot;), wxBITMAP_TYPE_PNG);\n\t\n\twxToolBar *tbr = new wxToolBar(this, -1);\n\ttbr-&gt;AddTool(ID_NEW, wxT(&quot;Add&quot;), bmpAdd);\n\ttbr-&gt;AddTool(ID_SAVE, wxT(&quot;Save&quot;), bmpSave);\n\ttbr-&gt;Realize();\n\ttbr-&gt;Bind(wxEVT_TOOL, &amp;Toolbar::OnToolItem, this);\n\n\twxBoxSizer *vbox = new wxBoxSizer(wxVERTICAL);\n\n\twxToolBar *tbr2 = new wxToolBar(this, -1, wxDefaultPosition, wxDefaultSize, wxTB_BOTTOM);\n\ttbr2-&gt;AddTool(ID_OPEN, wxT(&quot;Open&quot;), bmpOpen);\n\ttbr2-&gt;AddTool(ID_EXPORT, wxT(&quot;Export&quot;), bmpExport);\n\ttbr2-&gt;Bind(wxEVT_TOOL, &amp;Toolbar::OnToolItem2, this);\n\ttbr2-&gt;Realize();\n\tvbox-&gt;Add(tbr, 0, wxEXPAND | wxALL);\n\tvbox-&gt;Add(tbr2, 0, wxEXPAND | wxALL);\n\tSetSizer(vbox);\n\n}\n\nvoid Toolbar::OnToolItem(wxCommandEvent &amp;evt) {\n\n\tint eventId= evt.GetId();\n\twxString strId = wxT(&quot;&quot;);\n\tstrId = wxString::Format(wxT(&quot;%d&quot;), evt.GetId());\n\twxPuts(strId);\n\tif (eventId == ID_NEW) \n\t\twxLogMessage(&quot;New file item&quot;);\n\telse if (eventId == ID_SAVE )\n\t\twxLogMessage(&quot;Save file item&quot;);\n\telse if (eventId == wxID_EXIT)\n\t\tClose(true);\n}\n\nvoid Toolbar::OnToolItem2(wxCommandEvent &amp;evt) {\n\n\tint eventId= evt.GetId();\n\twxString strId = wxT(&quot;&quot;);\n\tstrId = wxString::Format(wxT(&quot;%d&quot;), evt.GetId());\n\twxPuts(strId);\n\tif (eventId == ID_OPEN) \n\t\twxLogMessage(&quot;Open file item&quot;);\n\telse if (eventId == ID_EXPORT) \n\t\twxLogMessage(&quot;Export file item&quot;);\n\n\telse if (eventId == wxID_EXIT)\n\t\tClose(true);\n}\n\n\n\n<\/pre><\/div>\n\n\n<p>The output is given below<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"790\" height=\"413\" src=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-14-17-10-27.png\" alt=\"\" class=\"wp-image-3845\" srcset=\"https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-14-17-10-27.png 790w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-14-17-10-27-620x324.png 620w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-14-17-10-27-300x157.png 300w, https:\/\/truelogic.org\/wordpress\/wp-content\/uploads\/2021\/12\/Screenshot-from-2021-12-14-17-10-27-768x401.png 768w\" sizes=\"auto, (max-width: 790px) 100vw, 790px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<div class=\"mh-excerpt\"><p>OVERVIEW We extend the code from the previous section to have two toolbars and divide the existing icons between the two. We use a wxBoxSizer <a class=\"mh-excerpt-more\" href=\"https:\/\/truelogic.org\/wordpress\/2021\/12\/14\/4d-wxwidgets-multiple-toolbars\/\" title=\"4d. wxWidgets &#8211; Multiple Toolbars\">[&#8230;]<\/a><\/p>\n<\/div>","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-3844","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3844","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/comments?post=3844"}],"version-history":[{"count":1,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3844\/revisions"}],"predecessor-version":[{"id":3846,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/posts\/3844\/revisions\/3846"}],"wp:attachment":[{"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/media?parent=3844"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/categories?post=3844"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/truelogic.org\/wordpress\/wp-json\/wp\/v2\/tags?post=3844"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}