summaryrefslogtreecommitdiff
path: root/src/wx/timecode.cc
blob: 043d4bc87536b8b5cd968dda7d0fab5180313392 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
    Copyright (C) 2013-2014 Carl Hetherington <cth@carlh.net>

    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
    the Free Software Foundation; either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program; if not, write to the Free Software
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

*/

#include "lib/util.h"
#include "timecode.h"
#include "wx_util.h"
#include <iostream>

using std::string;
using std::cout;

TimecodeBase::TimecodeBase (wxWindow* parent)
	: wxPanel (parent)
{
	wxSize const s = TimecodeBase::size (parent);

	wxTextValidator validator (wxFILTER_INCLUDE_CHAR_LIST);
	wxArrayString list;

	wxString n (wxT ("0123456789"));
	for (size_t i = 0; i < n.Length(); ++i) {
		list.Add (n[i]);
	}

	validator.SetIncludes (list);

	_sizer = new wxBoxSizer (wxHORIZONTAL);

	_editable = new wxPanel (this);
	wxSizer* editable_sizer = new wxBoxSizer (wxHORIZONTAL);
	_hours = new wxTextCtrl (_editable, wxID_ANY, wxT(""), wxDefaultPosition, s, 0, validator);
	_hours->SetMaxLength (2);
	editable_sizer->Add (_hours);
	add_label_to_sizer (editable_sizer, _editable, wxT (":"), false);
	_minutes = new wxTextCtrl (_editable, wxID_ANY, wxT(""), wxDefaultPosition, s, 0, validator);
	_minutes->SetMaxLength (2);
	editable_sizer->Add (_minutes);
	add_label_to_sizer (editable_sizer, _editable, wxT (":"), false);
	_seconds = new wxTextCtrl (_editable, wxID_ANY, wxT(""), wxDefaultPosition, s, 0, validator);
	_seconds->SetMaxLength (2);
	editable_sizer->Add (_seconds);
	add_label_to_sizer (editable_sizer, _editable, wxT (":"), false);
	_frames = new wxTextCtrl (_editable, wxID_ANY, wxT(""), wxDefaultPosition, s, 0, validator);
	_frames->SetMaxLength (2);
	editable_sizer->Add (_frames);
	_set_button = new wxButton (_editable, wxID_ANY, _("Set"));
	editable_sizer->Add (_set_button, 0, wxLEFT | wxRIGHT, 8);
	_editable->SetSizerAndFit (editable_sizer);
	_sizer->Add (_editable);

	_fixed = add_label_to_sizer (_sizer, this, wxT ("42"), false);

	_hours->Bind	  (wxEVT_COMMAND_TEXT_UPDATED,   boost::bind (&TimecodeBase::changed, this));
	_minutes->Bind	  (wxEVT_COMMAND_TEXT_UPDATED,   boost::bind (&TimecodeBase::changed, this));
	_seconds->Bind	  (wxEVT_COMMAND_TEXT_UPDATED,   boost::bind (&TimecodeBase::changed, this));
	_frames->Bind	  (wxEVT_COMMAND_TEXT_UPDATED,   boost::bind (&TimecodeBase::changed, this));
	_set_button->Bind (wxEVT_COMMAND_BUTTON_CLICKED, boost::bind (&TimecodeBase::set_clicked, this));

	_set_button->Enable (false);

	set_editable (true);

	SetSizerAndFit (_sizer);
}

void
TimecodeBase::clear ()
{
	checked_set (_hours, wxT (""));
	checked_set (_minutes, wxT (""));
	checked_set (_seconds, wxT (""));
	checked_set (_frames, wxT (""));
	checked_set (_fixed, wxT (""));
}

void
TimecodeBase::changed ()
{
	_set_button->Enable (true);
}

void
TimecodeBase::set_clicked ()
{
	Changed ();
	_set_button->Enable (false);
}

void
TimecodeBase::set_editable (bool e)
{
	_editable->Show (e);
	_fixed->Show (!e);
	_sizer->Layout ();
}

wxSize
TimecodeBase::size (wxWindow* parent)
{
	wxClientDC dc (parent);
	wxSize size = dc.GetTextExtent (wxT ("9999"));
	size.SetHeight (-1);
	return size;
}