Professional Documents
Culture Documents
Imron02: From Beginner To Expert
Imron02: From Beginner To Expert
imron02
For the answer the first open your editor (In this tutorial I using codeblocks) and create a project with name you like. Example I create with name
Test then add new file with name “Frame.h”
1 of 5 12/12/2020, 5:05 pm
Wxwidgets. Simple application using wxribbon and wxauinotebook. | imron02 https://imron02.wordpress.com/2014/12/11/wxwidgets-simple-application-using-wxribbon-and-wxau...
Frame.h
1 #ifndef FRAME_H
2 #define FRAME_H
3
4 #include <wx/wx.h>
5 #include <wx/aui/aui.h>
6 #include <wx/ribbon/bar.h>
7 #include <wx/ribbon/buttonbar.h>
8 #include <wx/artprov.h>
9
10 class MainFrame : public wxFrame
11 {
12 public:
13 MainFrame(const wxString& title);
14
15 // Destructor
16 virtual ~MainFrame();
17
18 private:
19 wxAuiNotebook* auiNotebook;
20
21 // ribbon
22 wxRibbonBar* ribbonBar;
23 wxRibbonPage* homeRibbonPage;
24 wxRibbonPage* editRibbonPage;
25 wxRibbonPanel* homeRibbonPanel;
26 wxRibbonPanel* itemRibbonPanel;
27 wxRibbonButtonBar* homeRibbonButtonBar;
28 wxRibbonButtonBar* itemRibbonButtonBar;
29 };
30
31 #endif // FRAME
2 of 5 12/12/2020, 5:05 pm
Wxwidgets. Simple application using wxribbon and wxauinotebook. | imron02 https://imron02.wordpress.com/2014/12/11/wxwidgets-simple-application-using-wxribbon-and-wxau...
Frame.cpp
1 #include "Frame.h"
2
3 MainFrame::MainFrame(const wxString& title)
4 : wxFrame(NULL, wxID_ANY, title, wxDefaultPosition, wxSize(900, 700), wxDEFAULT_FRAME_STYLE | wxSUNKEN_BORDER)
5 {
6 // Ribbon
7 ribbonBar = new wxRibbonBar(this, -1, wxDefaultPosition, wxDefaultSize, wxRIBBON_BAR_FLOW_HORIZONTAL
8 | wxRIBBON_BAR_SHOW_PAGE_LABELS
9 | wxRIBBON_BAR_SHOW_PANEL_EXT_BUTTONS
10 | wxRIBBON_BAR_SHOW_TOGGLE_BUTTON
11 );
12
13 homeRibbonPage = new wxRibbonPage(ribbonBar, wxID_ANY, wxT("Master Data"), wxNullBitmap);
14 editRibbonPage = new wxRibbonPage(ribbonBar, wxID_ANY, wxT("Edit Page"), wxNullBitmap);
15
16 homeRibbonPanel = new wxRibbonPanel(homeRibbonPage, wxID_ANY, wxT("Home"), wxNullBitmap,
17 wxDefaultPosition, wxDefaultSize,
18 wxRIBBON_PANEL_NO_AUTO_MINIMISE);
19 itemRibbonPanel = new wxRibbonPanel(homeRibbonPage, wxID_ANY, wxT("Data Item"),
20 wxNullBitmap, wxDefaultPosition, wxDefaultSize,
21 wxRIBBON_PANEL_NO_AUTO_MINIMISE);
22
23 homeRibbonButtonBar = new wxRibbonButtonBar(homeRibbonPanel);
24 itemRibbonButtonBar = new wxRibbonButtonBar(itemRibbonPanel);
25
26 homeRibbonButtonBar->AddButton(wxID_ANY, wxT("Home Menu"),
27 wxArtProvider::GetBitmap(wxART_ADD_BOOKMARK, wxART_TOOLBAR, wxSize(16,15)));
28
29 itemRibbonButtonBar->AddButton(wxID_ANY, wxT("Daftar Guru"),
30 wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(16,15)));
31 itemRibbonButtonBar->AddButton(wxID_ANY, wxT("Tambah Guru"),
32 wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(16,15)));
33 itemRibbonButtonBar->AddButton(wxID_ANY, wxT("Daftar Siswa"),
34 wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(16,15)));
35 itemRibbonButtonBar->AddButton(wxID_ANY, wxT("Tambah Siswa"),
36 wxArtProvider::GetBitmap(wxART_QUESTION, wxART_TOOLBAR, wxSize(16,15)));
37
38 ribbonBar->AddPageHighlight(ribbonBar->GetPageCount() - 1);
39 ribbonBar->Realize();
40
41 // set style msw provider
42 ribbonBar->DismissExpandedPanel();
43 ribbonBar->SetArtProvider(new wxRibbonMSWArtProvider);
44
45 // aui notebook
46 wxSize client_size = GetClientSize();
47
48 auiNotebook = new wxAuiNotebook(this, wxID_ANY,
49 wxPoint(client_size.x, client_size.y),
50 wxSize(430,200),
51 wxAUI_NB_CLOSE_BUTTON | wxAUI_NB_SCROLL_BUTTONS);
52 auiNotebook->Freeze();
53 wxBitmap page_bmp = wxArtProvider::GetBitmap(wxART_NORMAL_FILE, wxART_OTHER, wxSize(16,16));
54
55 auiNotebook->AddPage(new wxTextCtrl(auiNotebook, wxID_ANY, wxT("Some text"),
56 wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxNO_BORDER),
57 wxT("Home"), false, page_bmp);
58 auiNotebook->AddPage(new wxTextCtrl(auiNotebook, wxID_ANY, wxT("Some text"),
59 wxDefaultPosition, wxDefaultSize, wxTE_MULTILINE|wxNO_BORDER),
60 wxT("Item 1"), false, page_bmp);
61
62 auiNotebook->SetPageToolTip(0, "Menu utama sistem informasi akademik");
63 auiNotebook->Thaw();
64
65 // set layout
66 wxSizer* sizer = new wxBoxSizer(wxVERTICAL);
67 sizer->Add(ribbonBar, 0, wxEXPAND);
68 sizer->Add(auiNotebook, 1, wxEXPAND);
69 SetSizer(sizer);
70
71 Centre();
72 }
73
74 MainFrame::~MainFrame() {}
Explanations:
3 of 5 12/12/2020, 5:05 pm
Wxwidgets. Simple application using wxribbon and wxauinotebook. | imron02 https://imron02.wordpress.com/2014/12/11/wxwidgets-simple-application-using-wxribbon-and-wxau...
4. Line 23-24 is to create the bu on bar place. Look at the icon home menu, daftar guru, and etc
5. Line 26-36 is to add the bu on to bu on bar (line 23-24)
6. Line 38 is used to add highlight to the ribbon page. Look at the difference in the picture below:
–Detailed Description
8. 42-43 is to force style MSW. If we are not using that so if we run the program on Linux, you can look like this:
MainApp.h
1 #ifndef MAIN_H
2 #define MAIN_H
3
4 #include <wx/wx.h>
5
6 class MainApp : public wxApp
7 {
8 public:
9 virtual bool OnInit();
10 };
11
12 #endif // MAIN_H
MainApp.cpp
1 #include "MainApp.h"
2 #include "Frame.h"
3
4 bool MainApp::OnInit()
5 {
6 // call main frame
7 MainFrame* mainFrame = new MainFrame("SIA");
8 mainFrame->Show(true);
9 return true;
10 }
11
12 wxIMPLEMENT_APP(MainApp);
Note: Before you building this source, don’t forget to add the libraries “-lwx_gtk2u_ribbon-3.0 and -lwx_gtk2u_aui-3.0” on codeblocks linker
4 of 5 12/12/2020, 5:05 pm
Wxwidgets. Simple application using wxribbon and wxauinotebook. | imron02 https://imron02.wordpress.com/2014/12/11/wxwidgets-simple-application-using-wxribbon-and-wxau...
Posted in C++ and tagged C++, wxauinotebook, wxribbon, Wxwidgets on December 11, 2014 by imron02. Leave a comment
5 of 5 12/12/2020, 5:05 pm