Merge master.
[dcpomatic.git] / src / wx / audio_mapping_view.cc
index a5dacdfc258bda49aeeee8371ba240b1cceb96eb..43119ef4e245c69f7ff57e06382c585e563b6765 100644 (file)
@@ -1,3 +1,5 @@
+/* -*- c-basic-offset: 8; default-tab-width: 8; -*- */
+
 /*
     Copyright (C) 2013 Carl Hetherington <cth@carlh.net>
 
@@ -59,6 +61,13 @@ 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,
@@ -105,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);
 }
@@ -124,6 +133,17 @@ AudioMappingView::left_click (wxGridEvent& ev)
        } else {
                _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
@@ -133,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) {
@@ -143,10 +163,8 @@ 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 (wxT("%s %d"), std_to_wx (ac->file().filename().string()).data(), 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) {
@@ -154,7 +172,5 @@ AudioMappingView::set_mapping (AudioMapping map)
                }
                ++n;
        }
-
-       _grid->AutoSize ();
 }