2 Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include <wx/renderer.h>
23 #include <libdcp/types.h>
24 #include "lib/audio_mapping.h"
25 #include "audio_mapping_view.h"
30 using boost::shared_ptr;
32 /* This could go away with wxWidgets 2.9, which has an API call
37 #define CHECKBOX_WIDTH 16
38 #define CHECKBOX_HEIGHT 16
42 #define CHECKBOX_WIDTH 20
43 #define CHECKBOX_HEIGHT 20
47 class NoSelectionStringRenderer : public wxGridCellStringRenderer
50 void Draw (wxGrid& grid, wxGridCellAttr& attr, wxDC& dc, const wxRect& rect, int row, int col, bool)
52 wxGridCellStringRenderer::Draw (grid, attr, dc, rect, row, col, false);
56 class CheckBoxRenderer : public wxGridCellRenderer
60 void Draw (wxGrid& grid, wxGridCellAttr &, wxDC& dc, const wxRect& rect, int row, int col, bool)
62 wxRendererNative::Get().DrawCheckBox (
65 grid.GetCellValue (row, col) == "1" ? static_cast<int>(wxCONTROL_CHECKED) : 0
69 wxSize GetBestSize (wxGrid &, wxGridCellAttr &, wxDC &, int, int)
71 return wxSize (CHECKBOX_WIDTH + 4, CHECKBOX_HEIGHT + 4);
74 wxGridCellRenderer* Clone () const
76 return new CheckBoxRenderer;
81 AudioMappingView::AudioMappingView (wxWindow* parent)
82 : wxPanel (parent, wxID_ANY)
84 _grid = new wxGrid (this, wxID_ANY);
86 _grid->CreateGrid (0, 7);
87 _grid->HideRowLabels ();
88 _grid->DisableDragRowSize ();
89 _grid->DisableDragColSize ();
90 _grid->EnableEditing (false);
91 _grid->SetCellHighlightPenWidth (0);
92 _grid->SetDefaultRenderer (new NoSelectionStringRenderer);
94 _grid->SetColLabelValue (0, _("Content channel"));
95 _grid->SetColLabelValue (1, _("L"));
96 _grid->SetColLabelValue (2, _("R"));
97 _grid->SetColLabelValue (3, _("C"));
98 _grid->SetColLabelValue (4, _("Lfe"));
99 _grid->SetColLabelValue (5, _("Ls"));
100 _grid->SetColLabelValue (6, _("Rs"));
104 wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
105 s->Add (_grid, 1, wxEXPAND);
108 Connect (wxID_ANY, wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler (AudioMappingView::left_click), 0, this);
112 AudioMappingView::left_click (wxGridEvent& ev)
114 if (ev.GetCol() == 0) {
118 if (_grid->GetCellValue (ev.GetRow(), ev.GetCol()) == "1") {
119 _grid->SetCellValue (ev.GetRow(), ev.GetCol(), "0");
121 _grid->SetCellValue (ev.GetRow(), ev.GetCol(), "1");
126 AudioMappingView::set_mapping (AudioMapping map)
128 if (_grid->GetNumberRows ()) {
129 _grid->DeleteRows (0, _grid->GetNumberRows ());
132 list<AudioMapping::Channel> content_channels = map.content_channels ();
133 _grid->InsertRows (0, content_channels.size ());
135 for (size_t r = 0; r < content_channels.size(); ++r) {
136 for (int c = 1; c < 7; ++c) {
137 _grid->SetCellRenderer (r, c, new CheckBoxRenderer);
142 for (list<AudioMapping::Channel>::iterator i = content_channels.begin(); i != content_channels.end(); ++i) {
143 shared_ptr<const AudioContent> ac = i->content.lock ();
145 _grid->SetCellValue (n, 0, wxString::Format ("%s %d", std_to_wx (ac->file().filename().string()), i->index + 1));
147 list<libdcp::Channel> const d = map.content_to_dcp (*i);
148 for (list<libdcp::Channel>::const_iterator j = d.begin(); j != d.end(); ++j) {
149 _grid->SetCellValue (n, static_cast<int> (*j) + 1, "1");