LabelDialog::LabelDialog(wxWindow *parent, DirManager *dirmanager, TrackList *tracks, ViewInfo &viewinfo, double rate) : wxDialog(parent, wxID_ANY, _("Edit Labels"), wxDefaultPosition, wxSize(800, 600), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER), mDirManager(dirmanager), mTracks(tracks), mViewInfo(&viewinfo), mRate(rate) { // Create the main sizer wxBoxSizer *vs = new wxBoxSizer(wxVERTICAL); // A little instruction vs->Add(new wxStaticText(this, wxID_ANY, _("Press F2 or double click to edit cell contents.")), 0, wxALIGN_LEFT | wxALL, 5); // Create the main sizer mGrid = new Grid(this, wxID_ANY); vs->Add(mGrid, 1, wxEXPAND | wxALL, 5); // Create the action buttons wxBoxSizer *hs = new wxBoxSizer(wxHORIZONTAL); hs->Add(new wxButton(this, ID_INSERTA, _("Insert &After")), 1, wxCENTER | wxALL, 5); hs->Add(new wxButton(this, ID_INSERTB, _("Insert &Before")), 1, wxCENTER | wxALL, 5); hs->Add(new wxButton(this, ID_REMOVE, _("&Remove")), 1, wxCENTER | wxALL, 5); hs->Add(new wxButton(this, ID_IMPORT, _("&Import...")), 1, wxCENTER | wxALL, 5); hs->Add(new wxButton(this, ID_EXPORT, _("&Export...")), 1, wxCENTER | wxALL, 5); vs->Add(hs, 0, wxEXPAND | wxCENTER | wxALL, 5); // Create the exit buttons vs->Add(CreateStdButtonSizer(this, eCancelButton|eOkButton), 0, wxEXPAND); // Make it so SetSizer(vs); // Build the initial (empty) grid mGrid->CreateGrid(0, Col_Max); mGrid->SetDefaultCellAlignment(wxALIGN_LEFT, wxALIGN_CENTER); int i; for (i = 0; i < Col_Max; i++) { mGrid->SetColLabelValue(i, headers[i]); } // Create and remember editors. No need to delete these as the wxGrid will // do it for us. mChoiceEditor = (ChoiceEditor *) mGrid->GetDefaultEditorForType(GRID_VALUE_CHOICE); mTimeEditor = (TimeEditor *) mGrid->GetDefaultEditorForType(GRID_VALUE_TIME); // Initialize and set the track name column attributes wxGridCellAttr *attr = new wxGridCellAttr(); attr->SetEditor(mChoiceEditor); mGrid->SetColAttr(Col_Track, attr); mTrackNames.Add(_("New...")); // Initialize and set the time column attributes attr = new wxGridCellAttr(); attr->SetRenderer(mGrid->GetDefaultRendererForType(GRID_VALUE_TIME)); attr->SetEditor(mTimeEditor); attr->SetAlignment(wxALIGN_CENTER, wxALIGN_CENTER); mGrid->SetColAttr(Col_Stime, attr); mGrid->SetColAttr(Col_Etime, attr->Clone()); // Seems there's a bug in wxGrid. Adding only 1 row does not // allow SetCellSize() to work properly and you will not get // the expected 1 row by 4 column cell. // // So, we set the minimum row height to 0 and basically hide // the extra row by setting its height to 0. And not allowing the // rows to be manually resized prevents the user from ever seeing // the extra row. mGrid->SetRowMinimalAcceptableHeight(0); mGrid->EnableDragRowSize(false); // Locate all labels in current track list FindAllLabels(); // Populate the grid TransferDataToWindow(); // Resize the label name column and ensure it doesn't go below an // arbitrary width. // // This should not be in TransferDataToWindow() since a user might // resize the column and we'd resize it back to the minimum. mGrid->AutoSizeColumn(Col_Label, false ); mGrid->SetColSize(Col_Label, wxMax(150, mGrid->GetColSize(Col_Label))); mGrid->SetColMinimalWidth(Col_Label, mGrid->GetColSize(Col_Label)); // Layout the works Layout(); // Resize width based on width of columns and the vertical scrollbar wxRect r = mGrid->GetGridColLabelWindow()->GetRect(); wxScrollBar sb(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL); r.width += sb.GetSize().GetWidth() + 6; SetClientSize(r.width, 300); // Make sure it doesn't go below this size r = GetRect(); SetSizeHints(r.GetWidth(), r.GetHeight()); // Center on display Center(); }
LabelDialog::LabelDialog(wxWindow *parent, TrackFactory &factory, TrackList *tracks, ViewInfo &viewinfo, double rate, const wxString & format) : wxDialog(parent, wxID_ANY, _("Edit Labels"), wxDefaultPosition, wxSize(800, 600), wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER), mFactory(factory), mTracks(tracks), mViewInfo(&viewinfo), mRate(rate), mFormat(format) { SetName(GetTitle()); { // Create the main sizer auto vs = std::make_unique<wxBoxSizer>(wxVERTICAL); // A little instruction wxStaticText *instruct = safenew wxStaticText(this, wxID_ANY, _("Press F2 or double click to edit cell contents.")); instruct->SetName(instruct->GetLabel()); // fix for bug 577 (NVDA/Narrator screen readers do not read static text in dialogs) vs->Add(instruct, 0, wxALIGN_LEFT | wxALL, 5); // Create the main sizer mGrid = safenew Grid(this, wxID_ANY); vs->Add(mGrid, 1, wxEXPAND | wxALL, 5); // Create the action buttons { auto hs = std::make_unique<wxBoxSizer>(wxHORIZONTAL); hs->Add(safenew wxButton(this, ID_INSERTA, _("Insert &After")), 1, wxCENTER | wxALL, 5); hs->Add(safenew wxButton(this, ID_INSERTB, _("Insert &Before")), 1, wxCENTER | wxALL, 5); hs->Add(safenew wxButton(this, ID_REMOVE, _("&Remove")), 1, wxCENTER | wxALL, 5); hs->Add(safenew wxButton(this, ID_IMPORT, _("&Import...")), 1, wxCENTER | wxALL, 5); hs->Add(safenew wxButton(this, ID_EXPORT, _("&Export...")), 1, wxCENTER | wxALL, 5); vs->Add(hs.release(), 0, wxEXPAND | wxCENTER | wxALL, 5); } // Create the exit buttons vs->Add(CreateStdButtonSizer(this, eCancelButton | eOkButton).release(), 0, wxEXPAND); // Make it so SetSizer(vs.release()); } // Build the initial (empty) grid mGrid->CreateGrid(0, Col_Max); mGrid->SetDefaultCellAlignment(wxALIGN_LEFT, wxALIGN_CENTER); /* i18n-hint: (noun). A track contains waves, audio etc.*/ mGrid->SetColLabelValue(0,_("Track")); /* i18n-hint: (noun)*/ mGrid->SetColLabelValue(1,_("Label")); /* i18n-hint: (noun) of a label*/ mGrid->SetColLabelValue(2,_("Start Time")); /* i18n-hint: (noun) of a label*/ mGrid->SetColLabelValue(3,_("End Time")); // Create and remember editors. No need to DELETE these as the wxGrid will // do it for us. (The DecRef() that is needed after GetDefaultEditorForType // becomes the duty of the wxGridCellAttr objects after we set them in the grid.) mChoiceEditor = (ChoiceEditor *) mGrid->GetDefaultEditorForType(GRID_VALUE_CHOICE); mTimeEditor = (TimeEditor *) mGrid->GetDefaultEditorForType(GRID_VALUE_TIME); // Initialize and set the track name column attributes wxGridCellAttr *attr; mGrid->SetColAttr(Col_Track, (attr = safenew wxGridCellAttr)); attr->SetEditor(mChoiceEditor); mTrackNames.Add(_("New...")); // Initialize and set the time column attributes mGrid->SetColAttr(Col_Stime, (attr = safenew wxGridCellAttr)); // Don't need DecRef() after this GetDefaultRendererForType. attr->SetRenderer(mGrid->GetDefaultRendererForType(GRID_VALUE_TIME)); attr->SetEditor(mTimeEditor); attr->SetAlignment(wxALIGN_CENTER, wxALIGN_CENTER); mGrid->SetColAttr(Col_Etime, attr->Clone()); // Seems there's a bug in wxGrid. Adding only 1 row does not // allow SetCellSize() to work properly and you will not get // the expected 1 row by 4 column cell. // // So, we set the minimum row height to 0 and basically hide // the extra row by setting its height to 0. And not allowing the // rows to be manually resized prevents the user from ever seeing // the extra row. mGrid->SetRowMinimalAcceptableHeight(0); mGrid->EnableDragRowSize(false); // Locate all labels in current track list FindAllLabels(); // Populate the grid TransferDataToWindow(); // Resize the label name column and ensure it doesn't go below an // arbitrary width. // // This should not be in TransferDataToWindow() since a user might // resize the column and we'd resize it back to the minimum. mGrid->AutoSizeColumn(Col_Label, false ); mGrid->SetColSize(Col_Label, wxMax(150, mGrid->GetColSize(Col_Label))); mGrid->SetColMinimalWidth(Col_Label, mGrid->GetColSize(Col_Label)); // Layout the works Layout(); // Resize width based on width of columns and the vertical scrollbar wxRect r = mGrid->GetGridColLabelWindow()->GetRect(); wxScrollBar sb(this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSB_VERTICAL); r.width += sb.GetSize().GetWidth() + 6; SetClientSize(r.width, 300); // Make sure it doesn't go below this size r = GetRect(); SetSizeHints(r.GetWidth(), r.GetHeight()); // Center on display Center(); }