source: git/src/paneldlg.cc @ e5fc9b1

RELEASE/1.1RELEASE/1.2debug-cidebug-ci-sanitisersfaster-cavernloglog-selectstereostereo-2025walls-datawalls-data-hanging-as-warningwarn-only-for-hanging-survey
Last change on this file since e5fc9b1 was 2f2509e, checked in by Mark Shinwell <mark>, 23 years ago

more preferences work

git-svn-id: file:///home/survex-svn/survex/branches/survex-1_1@2115 4b37db11-9a0c-4f06-9ece-9ab7cdaee568

  • Property mode set to 100644
File size: 6.5 KB
Line 
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
27static const wxWindowID ID_PAGE_BASE = 100;
28static const wxWindowID ID_PAGE_BASE_IMG = 150;
29static const wxWindowID ID_PAGE_BASE_PANEL = 200;
30static const wxWindowID ID_PAGE_BASE_IMG_END = ID_PAGE_BASE_PANEL - 1;
31
32BEGIN_EVENT_TABLE(PanelDlg, wxDialog)
33    EVT_COMMAND_RANGE(ID_PAGE_BASE_IMG, ID_PAGE_BASE_IMG_END, wxEVT_COMMAND_BUTTON_CLICKED, PanelDlg::OnPageChange)
34END_EVENT_TABLE()
35
36PanelDlg::PanelDlg(wxWindow* parent, wxWindowID id, const wxString& title) :
37    wxDialog(parent, id, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
38{
39}
40
41PanelDlg::~PanelDlg()
42{
43}
44
45void PanelDlg::OnPageChange(wxCommandEvent& event)
46{
47    // The user has requested a change of page.
48   
49    // Identify the new page.
50    int page = event.GetId() - ID_PAGE_BASE_IMG;
51    assert(page >= 0 && page < m_Pages.size());
52    list<PanelDlgPage*>::iterator iter = m_Pages.begin();
53    for (int x = 0; x < page; x++) iter++;
54    PanelDlgPage* page_ptr = *iter;
55    assert(page_ptr);
56
57    if (page_ptr == m_CurrentPage) return;
58   
59    // Remove the current page from display.
60    m_CurrentPage->Hide();
61    m_VertSizer->Remove(m_CurrentPage);
62    m_VertSizer->Layout();
63
64    // Display the new page.
65    m_VertSizer->Prepend(page_ptr, 1 /* fill available space */, wxALL, 4);
66    m_CurrentPage = page_ptr;
67
68    // Force a re-layout of the sizer.
69    m_VertSizer->Layout();
70    page_ptr->Show();
71}
72
73void PanelDlg::SetPages(list<PanelDlgPage*> pages)
74{
75    assert(pages.size() >= 1);
76
77    m_Pages = pages;
78
79    // Create sizers.
80    wxBoxSizer* horiz_sizer = new wxBoxSizer(wxHORIZONTAL);
81    m_VertSizer = new wxBoxSizer(wxVERTICAL);
82
83    // Create the left-hand page button panel.
84    wxScrolledWindow* scrolled_win = new wxScrolledWindow(this, 3000, wxDefaultPosition, wxDefaultSize,
85                                                          wxVSCROLL | wxSUNKEN_BORDER);
86    wxPanel* page_panel = new wxPanel(scrolled_win, 2000);
87
88    // Get the background colour and calculate a "darker" version of it.
89    wxColour col = page_panel->GetBackgroundColour();
90   
91    unsigned char r = (unsigned char)(double(col.Red()) * 0.4);
92    unsigned char g = (unsigned char)(double(col.Green()) * 0.4);
93    unsigned char b = (unsigned char)(double(col.Blue()) * 0.4);
94
95    col.Set(r, g, b);
96
97    // Fill the page button panel.
98    wxBoxSizer* page_panel_sizer = new wxBoxSizer(wxVERTICAL);
99    const int PAGE_ICON_HEAD_FOOT = 12;
100    const int PAGE_ICON_HEIGHT = 75;
101    const int PAGE_PANEL_WIDTH = int((48 + (2*PAGE_ICON_HEAD_FOOT)) * 4.0/3.0);
102    list<PanelDlgPage*>::iterator iter = pages.begin();
103    int page_num = 0;
104    while (iter != pages.end()) {
105        PanelDlgPage* page = *iter++;
106
107        // Get the text and icon for this button.
108        const wxString& text = page->GetName();
109        const wxBitmap& icon = page->GetIcon();
110
111        // Create the button and label together inside a panel.
112        wxPanel* panel = new wxPanel(page_panel, ID_PAGE_BASE_PANEL + page_num);
113        wxBoxSizer* panel_sizer = new wxBoxSizer(wxVERTICAL);
114        wxBitmapButton* img_button = new wxBitmapButton(panel, ID_PAGE_BASE_IMG + page_num, icon,
115                                                        wxPoint(0, 0), wxSize(48, 48));
116        wxStaticText* label = new wxStaticText(panel, ID_PAGE_BASE + page_num, text);
117        page_panel_sizer->Add(8, PAGE_ICON_HEAD_FOOT); // add a spacer
118        panel_sizer->Add(img_button, 0, wxALIGN_CENTER, 4);
119        panel_sizer->Add(label, 0, wxALIGN_CENTER, 4);
120        panel->SetAutoLayout(true);
121        panel->SetSizer(panel_sizer);
122        panel->SetSize(PAGE_PANEL_WIDTH - 8, PAGE_ICON_HEIGHT - PAGE_ICON_HEAD_FOOT);
123
124        page_panel_sizer->Add(panel, 0 /* not vertically stretchable */, wxALIGN_CENTER);
125        panel->SetBackgroundColour(col);
126
127        page_num++;
128    }
129    page_panel_sizer->Add(8, PAGE_ICON_HEAD_FOOT); // add a spacer
130    page_panel->SetAutoLayout(true);
131    page_panel->SetSizer(page_panel_sizer);
132    int height = PAGE_ICON_HEAD_FOOT + (page_num * PAGE_ICON_HEIGHT);
133    page_panel->SetSizeHints(PAGE_PANEL_WIDTH, height);
134    page_panel->SetSize(PAGE_PANEL_WIDTH, height);
135    scrolled_win->SetScrollbars(0, height / page_num, 0, page_num);
136    scrolled_win->SetSize(/* FIXME */ 16 + PAGE_PANEL_WIDTH, 500);
137 
138    // Darken the background colour.
139    page_panel->SetBackgroundColour(col);
140
141    // Fill the horizontal sizer.
142    horiz_sizer->Add(scrolled_win, 0 /* not horizontally stretchable */, wxEXPAND | wxALL, 2);
143    horiz_sizer->Add(m_VertSizer, 1 /* fill available space */, wxEXPAND | wxALL, 2);
144
145    // Retrieve the panel for the first page.
146    PanelDlgPage* first_page = *(pages.begin());
147    assert(first_page);
148    m_CurrentPage = first_page;
149
150    // Create the OK/Cancel button panel.
151    m_ButtonSizer = new wxBoxSizer(wxHORIZONTAL);
152    wxButton* ok_button = new wxButton(this, wxID_OK, "OK");
153    ok_button->SetDefault();
154    wxButton* cancel_button = new wxButton(this, wxID_CANCEL, "Cancel");
155    m_ButtonSizer->Add(ok_button, 0 /* not horizontally stretchable */, wxALIGN_RIGHT | wxRIGHT, 4);
156    m_ButtonSizer->Add(cancel_button, 0 /* not horizontally stretchable */, wxALIGN_RIGHT);
157
158    // Fill the sizer holding the page and the button panel.
159    m_VertSizer->Add(first_page, 1 /* fill available space */, wxALIGN_TOP | wxALL, 4);
160    m_VertSizer->Add(m_ButtonSizer, 0 /* not vertically stretchable */, wxALIGN_RIGHT | wxALL, 4);
161
162    // Cause the dialog to use the horizontal sizer.
163    SetAutoLayout(true);
164    SetSizer(horiz_sizer);
165    horiz_sizer->Fit(this);
166
167    // Set a reasonable size and centre the dialog with respect to the parent window.
168    SetSize(500, PAGE_ICON_HEIGHT*4 + PAGE_ICON_HEAD_FOOT);
169    CentreOnParent();
170}
171
Note: See TracBrowser for help on using the repository browser.