/*
   mkvmerge GUI -- utility for splicing together matroska files
   from component media subtypes

   Distributed under the GPL
   see the file COPYING for details
   or visit http://www.gnu.org/copyleft/gpl.html

   declarations for the chapter tab

   Written by Moritz Bunkus <moritz@bunkus.org>.
*/

#ifndef __TAB_CHAPTERS_H
#define __TAB_CHAPTERS_H

#include <wx/button.h>
#include <wx/panel.h>
#include <wx/treectrl.h>

#include <matroska/KaxChapters.h>

#include "mmg/wx_kax_analyzer.h"
#include "common/wx.h"

#define ID_TRC_CHAPTERS                   16000
#define ID_B_ADDCHAPTER                   16001
#define ID_B_REMOVECHAPTER                16002
#define ID_T_CHAPTERVALUES                16003
#define ID_TC_CHAPTERNAME                 16004
#define ID_TC_CHAPTERSTART                16007
#define ID_TC_CHAPTEREND                  16008
#define ID_CB_CHAPTERSELECTLANGUAGECODE   16009
#define ID_CB_CHAPTERSELECTCOUNTRYCODE    16010
#define ID_B_ADDSUBCHAPTER                16011
#define ID_B_SETVALUES                    16012
#define ID_LB_CHAPTERNAMES                16013
#define ID_B_ADD_CHAPTERNAME              16014
#define ID_B_REMOVE_CHAPTERNAME           16015
#define ID_B_ADJUSTTIMECODES              16016
#define ID_CB_CHAPTERHIDDEN               16017
#define ID_CB_CHAPTERENABLED              16018
#define ID_TC_UID                         16019

using namespace libmatroska;

class tab_chapters: public wxPanel {
  DECLARE_CLASS(tab_chapters);
  DECLARE_EVENT_TABLE();
public:
  wxTreeCtrl *tc_chapters;
  wxTreeItemId tid_root;
  wxButton *b_add_chapter, *b_add_subchapter, *b_remove_chapter;
  wxButton *b_set_values, *b_adjust_timecodes;
  wxMenu *m_chapters;

  wxTextCtrl *tc_chapter_name, *tc_start_time, *tc_end_time;
  wxTextCtrl *tc_uid;
  wxMTX_COMBOBOX_TYPE *cob_language_code, *cob_country_code;
  wxListBox *lb_chapter_names;
  wxButton *b_add_chapter_name, *b_remove_chapter_name;
  wxCheckBox *cb_flag_hidden, *cb_flag_enabled;
  bool inputs_enabled, no_update;

  wxStaticText *st_start, *st_end, *st_uid, *st_name, *st_language;
  wxStaticText *st_country, *st_chapters;
  wxStaticBox *sb_names;

  wxString file_name;
  bool source_is_kax_file, source_is_simple_format;

  KaxChapters *chapters;

  wx_kax_analyzer_c *analyzer;

public:
  tab_chapters(wxWindow *parent, wxMenu *nm_chapters);
  ~tab_chapters();

  void on_new_chapters(wxCommandEvent &evt);
  void on_load_chapters(wxCommandEvent &evt);
  void on_save_chapters(wxCommandEvent &evt);
  void on_save_chapters_as(wxCommandEvent &evt);
  void on_save_chapters_to_kax_file(wxCommandEvent &evt);
  void on_verify_chapters(wxCommandEvent &evt);
  void on_add_chapter(wxCommandEvent &evt);
  void on_add_subchapter(wxCommandEvent &evt);
  void on_remove_chapter(wxCommandEvent &evt);
  void on_entry_selected(wxTreeEvent &evt);
  void on_language_code_selected(wxCommandEvent &evt);
  void on_country_code_selected(wxCommandEvent &evt);
  void on_chapter_name_selected(wxCommandEvent &evt);
  void on_chapter_name_changed(wxCommandEvent &evt);
  void on_chapter_name_enter(wxCommandEvent &evt);
  void on_add_chapter_name(wxCommandEvent &evt);
  void on_remove_chapter_name(wxCommandEvent &evt);
  void on_set_values(wxCommandEvent &evt);
  void on_adjust_timecodes(wxCommandEvent &evt);
  void on_flag_hidden(wxCommandEvent &evt);
  void on_flag_enabled(wxCommandEvent &evt);
  void set_values_recursively(wxTreeItemId id, const wxString &language,
                              bool set_language);
  void set_display_values(KaxChapterDisplay *display);
  void set_timecode_values(KaxChapterAtom *atom);
  void adjust_timecodes_recursively(wxTreeItemId id, int64_t adjust_by);

  bool copy_values(wxTreeItemId id);
  int64_t parse_time(wxString s);
  bool verify_atom_recursively(EbmlElement *e);
  bool verify(bool called_interactively = false);
  void add_recursively(wxTreeItemId &parent, EbmlMaster &master);
  wxString create_chapter_label(KaxChapterAtom &chapter);
  void fix_missing_languages(EbmlMaster &master);
  void enable_inputs(bool enable);
  void enable_buttons(bool enable);
  bool select_file_name();
  bool load(wxString name);
  void save();
  bool is_empty();
  void translate_ui();

protected:
  void write_chapters_to_matroska_file();
};

#endif // __TAB_CHAPTERS_H
