Merge master.
[dcpomatic.git] / src / wx / audio_mapping_view.cc
index d62609d22e514392631a1db83fa3705ea5c7eaa1..43119ef4e245c69f7ff57e06382c585e563b6765 100644 (file)
@@ -1,3 +1,5 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
 /*
     Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
 
@@ -59,10 +61,17 @@ public:
 
        void Draw (wxGrid& grid, wxGridCellAttr &, wxDC& dc, const wxRect& rect, int row, int col, bool)
        {
+#if wxMAJOR_VERSION == 2 && wxMINOR_VERSION >= 9
+               dc.SetPen (*wxThePenList->FindOrCreatePen (wxColour (255, 255, 255), 0, wxPENSTYLE_SOLID));
+#else          
+               dc.SetPen (*wxThePenList->FindOrCreatePen (wxColour (255, 255, 255), 0, wxSOLID));
+#endif         
+               dc.DrawRectangle (rect);
+               
                wxRendererNative::Get().DrawCheckBox (
                        &grid,
                        dc, rect,
-                       grid.GetCellValue (row, col) == "1" ? static_cast<int>(wxCONTROL_CHECKED) : 0
+                       grid.GetCellValue (row, col) == wxT("1") ? static_cast<int>(wxCONTROL_CHECKED) : 0
                        );
        }
 
@@ -84,7 +93,11 @@ AudioMappingView::AudioMappingView (wxWindow* parent)
        _grid = new wxGrid (this, wxID_ANY);
 
        _grid->CreateGrid (0, 7);
+#if wxMINOR_VERSION == 9
        _grid->HideRowLabels ();
+#else
+       _grid->SetRowLabelSize (0);
+#endif 
        _grid->DisableDragRowSize ();
        _grid->DisableDragColSize ();
        _grid->EnableEditing (false);
@@ -101,9 +114,9 @@ AudioMappingView::AudioMappingView (wxWindow* parent)
 
        _grid->AutoSize ();
 
-       wxBoxSizer* s = new wxBoxSizer (wxVERTICAL);
-       s->Add (_grid, 1, wxEXPAND);
-       SetSizerAndFit (s);
+       _sizer = new wxBoxSizer (wxVERTICAL);
+       _sizer->Add (_grid, 1, wxEXPAND | wxALL);
+       SetSizerAndFit (_sizer);
 
        Connect (wxID_ANY, wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler (AudioMappingView::left_click), 0, this);
 }
@@ -115,11 +128,22 @@ AudioMappingView::left_click (wxGridEvent& ev)
                return;
        }
        
-       if (_grid->GetCellValue (ev.GetRow(), ev.GetCol()) == "1") {
-               _grid->SetCellValue (ev.GetRow(), ev.GetCol(), "0");
+       if (_grid->GetCellValue (ev.GetRow(), ev.GetCol()) == wxT("1")) {
+               _grid->SetCellValue (ev.GetRow(), ev.GetCol(), wxT("0"));
        } else {
-               _grid->SetCellValue (ev.GetRow(), ev.GetCol(), "1");
+               _grid->SetCellValue (ev.GetRow(), ev.GetCol(), wxT("1"));
+       }
+
+       AudioMapping mapping;
+       for (int i = 0; i < _grid->GetNumberRows(); ++i) {
+               for (int j = 1; j < _grid->GetNumberCols(); ++j) {
+                       if (_grid->GetCellValue (i, j) == wxT ("1")) {
+                               mapping.add (i, static_cast<libdcp::Channel> (j - 1));
+                       }
+               }
        }
+
+       Changed (mapping);
 }
 
 void
@@ -129,7 +153,7 @@ AudioMappingView::set_mapping (AudioMapping map)
                _grid->DeleteRows (0, _grid->GetNumberRows ());
        }
 
-       list<AudioMapping::Channel> content_channels = map.content_channels ();
+       list<int> content_channels = map.content_channels ();
        _grid->InsertRows (0, content_channels.size ());
 
        for (size_t r = 0; r < content_channels.size(); ++r) {
@@ -139,18 +163,14 @@ AudioMappingView::set_mapping (AudioMapping map)
        }
        
        int n = 0;
-       for (list<AudioMapping::Channel>::iterator i = content_channels.begin(); i != content_channels.end(); ++i) {
-               shared_ptr<const AudioContent> ac = i->content.lock ();
-               assert (ac);
-               _grid->SetCellValue (n, 0, wxString::Format ("%s %d", std_to_wx (ac->file().filename().string()), i->index + 1));
+       for (list<int>::iterator i = content_channels.begin(); i != content_channels.end(); ++i) {
+               _grid->SetCellValue (n, 0, wxString::Format (wxT("%d"), *i + 1));
 
                list<libdcp::Channel> const d = map.content_to_dcp (*i);
                for (list<libdcp::Channel>::const_iterator j = d.begin(); j != d.end(); ++j) {
-                       _grid->SetCellValue (n, static_cast<int> (*j) + 1, "1");
+                       _grid->SetCellValue (n, static_cast<int> (*j) + 1, wxT("1"));
                }
                ++n;
        }
-
-       _grid->AutoSize ();
 }