[02c7c1a] | 1 | // |
---|
| 2 | // paneldlg.cc |
---|
| 3 | // |
---|
| 4 | // Dialog boxes with multiple pages and a selector panel. |
---|
| 5 | // |
---|
| 6 | // Copyright (C) 2002 Mark R. Shinwell |
---|
| 7 | // |
---|
| 8 | // This program is free software; you can redistribute it and/or modify |
---|
| 9 | // it under the terms of the GNU General Public License as published by |
---|
| 10 | // the Free Software Foundation; either version 2 of the License, or |
---|
| 11 | // (at your option) any later version. |
---|
| 12 | // |
---|
| 13 | // This program is distributed in the hope that it will be useful, |
---|
| 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 16 | // GNU General Public License for more details. |
---|
| 17 | // |
---|
| 18 | // You should have received a copy of the GNU General Public License |
---|
| 19 | // along with this program; if not, write to the Free Software |
---|
| 20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
---|
| 21 | // |
---|
| 22 | |
---|
| 23 | #include "paneldlg.h" |
---|
| 24 | |
---|
| 25 | #include <assert.h> |
---|
| 26 | |
---|
| 27 | static const wxWindowID ID_PAGE_BASE = 100; |
---|
| 28 | static const wxWindowID ID_PAGE_BASE_IMG = 150; |
---|
| 29 | static const wxWindowID ID_PAGE_BASE_PANEL = 150; |
---|
| 30 | |
---|
| 31 | PanelDlg::PanelDlg(wxWindow* parent, wxWindowID id, const wxString& title) : |
---|
| 32 | wxDialog(parent, id, title)//, wxDefaultPosition, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER) |
---|
| 33 | { |
---|
| 34 | } |
---|
| 35 | |
---|
| 36 | PanelDlg::~PanelDlg() |
---|
| 37 | { |
---|
| 38 | } |
---|
| 39 | |
---|
| 40 | void PanelDlg::SetPages(list<PanelDlgPage*> pages) |
---|
| 41 | { |
---|
| 42 | assert(pages.size() >= 1); |
---|
| 43 | |
---|
| 44 | // Create sizers. |
---|
| 45 | wxBoxSizer* horiz_sizer = new wxBoxSizer(wxHORIZONTAL); |
---|
| 46 | m_VertSizer = new wxBoxSizer(wxVERTICAL); |
---|
| 47 | |
---|
| 48 | // Create the left-hand page button panel. |
---|
| 49 | wxPanel* page_panel = new wxPanel(this, 2000, wxDefaultPosition, wxDefaultSize, |
---|
| 50 | wxTAB_TRAVERSAL | wxSUNKEN_BORDER); |
---|
| 51 | |
---|
| 52 | // Get the background colour and calculate a "darker" version of it. |
---|
| 53 | wxColour col = page_panel->GetBackgroundColour(); |
---|
| 54 | |
---|
| 55 | unsigned char r = (unsigned char)(double(col.Red()) * 0.4); |
---|
| 56 | unsigned char g = (unsigned char)(double(col.Green()) * 0.4); |
---|
| 57 | unsigned char b = (unsigned char)(double(col.Blue()) * 0.4); |
---|
| 58 | |
---|
| 59 | col.Set(r, g, b); |
---|
| 60 | |
---|
| 61 | // Fill the page button panel. |
---|
| 62 | wxBoxSizer* page_panel_sizer = new wxBoxSizer(wxVERTICAL); |
---|
| 63 | const int PAGE_ICON_HEAD_FOOT = 12; |
---|
| 64 | const int PAGE_ICON_HEIGHT = 75; |
---|
| 65 | const int PAGE_PANEL_WIDTH = 48 + (2*PAGE_ICON_HEAD_FOOT); |
---|
| 66 | page_panel_sizer->Add(10, PAGE_ICON_HEAD_FOOT); // add a spacer |
---|
| 67 | list<PanelDlgPage*>::iterator iter = pages.begin(); |
---|
| 68 | int page_num = 0; |
---|
| 69 | while (iter != pages.end()) { |
---|
| 70 | PanelDlgPage* page = *iter++; |
---|
| 71 | |
---|
| 72 | // Get the text and icon for this button. |
---|
| 73 | const wxString& text = page->GetName(); |
---|
| 74 | const wxBitmap& icon = page->GetIcon(); |
---|
| 75 | |
---|
| 76 | // Create the button and label together inside a panel. |
---|
| 77 | wxPanel* panel = new wxPanel(page_panel, ID_PAGE_BASE_PANEL + page_num); |
---|
| 78 | wxBoxSizer* panel_sizer = new wxBoxSizer(wxVERTICAL); |
---|
| 79 | wxBitmapButton* img_button = new wxBitmapButton(panel, ID_PAGE_BASE_IMG + page_num, icon, |
---|
| 80 | wxPoint(0, 0), wxSize(48, 48)); |
---|
| 81 | wxStaticText* label = new wxStaticText(panel, ID_PAGE_BASE + page_num, text); |
---|
| 82 | panel_sizer->Add(img_button, 0, wxALIGN_CENTER, 4); |
---|
| 83 | panel_sizer->Add(label, 0, wxALIGN_CENTER, 4); |
---|
| 84 | panel->SetAutoLayout(true); |
---|
| 85 | panel->SetSizer(panel_sizer); |
---|
| 86 | panel->SetSize(PAGE_PANEL_WIDTH - 8, PAGE_ICON_HEIGHT); |
---|
| 87 | |
---|
| 88 | page_panel_sizer->Add(panel, 0 /* not vertically stretchable */, wxALIGN_CENTER); |
---|
| 89 | panel->SetBackgroundColour(col); |
---|
| 90 | |
---|
| 91 | page_num++; |
---|
| 92 | } |
---|
| 93 | page_panel->SetAutoLayout(true); |
---|
| 94 | page_panel->SetSizer(page_panel_sizer); |
---|
| 95 | int height = PAGE_ICON_HEAD_FOOT*2 + ((page_num - 1) * PAGE_ICON_HEIGHT); |
---|
| 96 | page_panel->SetSizeHints(PAGE_PANEL_WIDTH, height); |
---|
| 97 | page_panel->SetSize(PAGE_PANEL_WIDTH, height); |
---|
| 98 | |
---|
| 99 | // Darken the background colour. |
---|
| 100 | page_panel->SetBackgroundColour(col); |
---|
| 101 | |
---|
| 102 | // Fill the horizontal sizer. |
---|
| 103 | horiz_sizer->Add(page_panel, 0 /* not horizontally stretchable */, wxEXPAND | wxALL, 2); |
---|
| 104 | horiz_sizer->Add(m_VertSizer, 1 /* fill available space */, wxEXPAND | wxALL, 2); |
---|
| 105 | |
---|
| 106 | // Retrieve the panel for the first page. |
---|
| 107 | PanelDlgPage* first_page = *(pages.begin()); |
---|
| 108 | assert(first_page); |
---|
| 109 | |
---|
| 110 | // Create the OK/Cancel button panel. |
---|
| 111 | wxBoxSizer* button_sizer = new wxBoxSizer(wxHORIZONTAL); |
---|
| 112 | wxButton* ok_button = new wxButton(this, wxID_OK, "OK"); |
---|
| 113 | wxButton* cancel_button = new wxButton(this, wxID_CANCEL, "Cancel"); |
---|
| 114 | button_sizer->Add(ok_button, 0 /* not horizontally stretchable */, wxALIGN_RIGHT | wxRIGHT, 4); |
---|
| 115 | button_sizer->Add(cancel_button, 0 /* not horizontally stretchable */, wxALIGN_RIGHT); |
---|
| 116 | |
---|
| 117 | // Fill the sizer holding the page and the button panel. |
---|
| 118 | m_VertSizer->Add(first_page, 1 /* fill available space */, wxALIGN_TOP | wxALL, 4); |
---|
| 119 | m_VertSizer->Add(button_sizer, 0 /* not vertically stretchable */, wxALIGN_BOTTOM | wxALL, 4); |
---|
| 120 | |
---|
| 121 | // Cause the dialog to use the horizontal sizer. |
---|
| 122 | SetAutoLayout(true); |
---|
| 123 | SetSizer(horiz_sizer); |
---|
| 124 | horiz_sizer->Fit(this); |
---|
| 125 | |
---|
| 126 | // Set a reasonable size. |
---|
| 127 | SetSize(500, 350); |
---|
| 128 | } |
---|
| 129 | |
---|