X-Git-Url: https://main.carlh.net/gitweb/?a=blobdiff_plain;f=src%2Fwx%2Ffonts_dialog.cc;h=3f8bca239551a5ef94666a2db61f1ec0372bec26;hb=c5dab5fdc0edde080e408a6d24fa059e27106ef5;hp=aa9fd1540a2b8d67f217aa40c45a98b33abd4e06;hpb=2a01820de9229fd778787421ec4f7bbf1e4b8bf1;p=dcpomatic.git diff --git a/src/wx/fonts_dialog.cc b/src/wx/fonts_dialog.cc index aa9fd1540..3f8bca239 100644 --- a/src/wx/fonts_dialog.cc +++ b/src/wx/fonts_dialog.cc @@ -1,5 +1,5 @@ /* - Copyright (C) 2014-2015 Carl Hetherington + Copyright (C) 2014-2016 Carl Hetherington This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,22 +17,27 @@ */ -#include "lib/font.h" -#include "lib/subtitle_content.h" #include "fonts_dialog.h" #include "wx_util.h" +#include "system_font_dialog.h" +#include "font_files_dialog.h" +#include "lib/font.h" +#include "lib/content.h" +#include "lib/subtitle_content.h" #include +#include +#include using std::list; using std::string; using std::cout; using boost::shared_ptr; -FontsDialog::FontsDialog (wxWindow* parent, shared_ptr content) +FontsDialog::FontsDialog (wxWindow* parent, shared_ptr content) : wxDialog (parent, wxID_ANY, _("Fonts")) , _content (content) { - _fonts = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxSize (400, 200), wxLC_REPORT | wxLC_SINGLE_SEL); + _fonts = new wxListCtrl (this, wxID_ANY, wxDefaultPosition, wxSize (550, 200), wxLC_REPORT | wxLC_SINGLE_SEL); { wxListItem ip; @@ -41,25 +46,37 @@ FontsDialog::FontsDialog (wxWindow* parent, shared_ptr content) ip.SetWidth (100); _fonts->InsertColumn (0, ip); } - + { wxListItem ip; ip.SetId (1); - ip.SetText (_("Font file")); - ip.SetWidth (300); + ip.SetText (_("Normal file")); + ip.SetWidth (150); _fonts->InsertColumn (1, ip); } - wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL); - sizer->Add (_fonts, 1, wxEXPAND); + { + wxListItem ip; + ip.SetId (2); + ip.SetText (_("Italic file")); + ip.SetWidth (150); + _fonts->InsertColumn (2, ip); + } { - wxSizer* s = new wxBoxSizer (wxVERTICAL); - _set_file = new wxButton (this, wxID_ANY, _("Set file...")); - s->Add (_set_file, 0, wxTOP | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP); - sizer->Add (s, 0, wxLEFT, DCPOMATIC_SIZER_X_GAP); + wxListItem ip; + ip.SetId (3); + ip.SetText (_("Bold file")); + ip.SetWidth (150); + _fonts->InsertColumn (3, ip); } + wxBoxSizer* sizer = new wxBoxSizer (wxHORIZONTAL); + sizer->Add (_fonts, 1, wxEXPAND | wxLEFT | wxRIGHT, DCPOMATIC_SIZER_X_GAP); + + _edit = new wxButton (this, wxID_ANY, _("Edit...")); + sizer->Add (_edit, 0, wxTOP | wxBOTTOM, DCPOMATIC_BUTTON_STACK_GAP); + wxBoxSizer* overall_sizer = new wxBoxSizer (wxVERTICAL); overall_sizer->Add (sizer, 1, wxEXPAND | wxALL, DCPOMATIC_SIZER_X_GAP); @@ -70,84 +87,76 @@ FontsDialog::FontsDialog (wxWindow* parent, shared_ptr content) SetSizerAndFit (overall_sizer); - _set_file->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&FontsDialog::set_file_clicked, this)); + _edit->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&FontsDialog::edit_clicked, this)); _fonts->Bind (wxEVT_COMMAND_LIST_ITEM_SELECTED, boost::bind (&FontsDialog::selection_changed, this)); _fonts->Bind (wxEVT_COMMAND_LIST_ITEM_DESELECTED, boost::bind (&FontsDialog::selection_changed, this)); setup (); - update_sensitivity (); } void FontsDialog::setup () { - shared_ptr content = _content.lock (); + shared_ptr content = _content.lock (); if (!content) { return; } - + _fonts->DeleteAllItems (); - list > fonts = content->fonts (); size_t n = 0; - for (list >::const_iterator i = fonts.begin(); i != fonts.end(); ++i) { + BOOST_FOREACH (shared_ptr i, content->subtitle->fonts ()) { wxListItem item; item.SetId (n); _fonts->InsertItem (item); - _fonts->SetItem (n, 0, std_to_wx ((*i)->id ())); - if ((*i)->file ()) { - _fonts->SetItem (n, 1, (*i)->file().get().leaf().string ()); + _fonts->SetItem (n, 0, std_to_wx (i->id ())); + if (i->file(FontFiles::NORMAL)) { + _fonts->SetItem (n, 1, i->file(FontFiles::NORMAL).get().leaf().string ()); } ++n; } + + setup_sensitivity (); +} + +void +FontsDialog::selection_changed () +{ + setup_sensitivity (); +} + +void +FontsDialog::setup_sensitivity () +{ + int const item = _fonts->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + _edit->Enable (item != -1); } void -FontsDialog::set_file_clicked () +FontsDialog::edit_clicked () { - shared_ptr content = _content.lock (); + shared_ptr content = _content.lock (); if (!content) { return; } - int item = _fonts->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); - if (item == -1) { - return; + int const item = _fonts->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + string const id = wx_to_std (_fonts->GetItemText (item, 0)); + shared_ptr font; + BOOST_FOREACH (shared_ptr i, content->subtitle->fonts()) { + if (i->id() == id) { + font = i; + } } - - /* The wxFD_CHANGE_DIR here prevents a `could not set working directory' error 123 on Windows when using - non-Latin filenames or paths. - */ - wxFileDialog* d = new wxFileDialog (this, _("Choose a font file"), wxT (""), wxT (""), wxT ("*.ttf"), wxFD_CHANGE_DIR); - int const r = d->ShowModal (); - - if (r != wxID_OK) { - d->Destroy (); + + if (!font) { return; } - string id = wx_to_std (_fonts->GetItemText (item, 0)); - - list > fonts = content->fonts (); - for (list >::iterator i = fonts.begin(); i != fonts.end(); ++i) { - if ((*i)->id() == id) { - (*i)->set_file (wx_to_std (d->GetPath ())); - } + FontFilesDialog* d = new FontFilesDialog (this, font->files ()); + if (d->ShowModal () == wxID_OK) { + font->set_files (d->get ()); } - d->Destroy (); setup (); } - -void -FontsDialog::selection_changed () -{ - update_sensitivity (); -} - -void -FontsDialog::update_sensitivity () -{ - int const item = _fonts->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); - _set_file->Enable (item != -1); -}