source: git/src/paneldlg.cc @ 55a5a1d

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 55a5a1d was 55a5a1d, checked in by Mark Shinwell <mark>, 23 years ago

PanelDlg? work

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

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