2006-01-16 22:02:54 +01:00
|
|
|
// Copyright (c) 2005, Rodrigo Braz Monteiro
|
|
|
|
// All rights reserved.
|
|
|
|
//
|
|
|
|
// Redistribution and use in source and binary forms, with or without
|
|
|
|
// modification, are permitted provided that the following conditions are met:
|
|
|
|
//
|
|
|
|
// * Redistributions of source code must retain the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer.
|
|
|
|
// * Redistributions in binary form must reproduce the above copyright notice,
|
|
|
|
// this list of conditions and the following disclaimer in the documentation
|
|
|
|
// and/or other materials provided with the distribution.
|
|
|
|
// * Neither the name of the Aegisub Group nor the names of its contributors
|
|
|
|
// may be used to endorse or promote products derived from this software
|
|
|
|
// without specific prior written permission.
|
|
|
|
//
|
|
|
|
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
|
|
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
|
|
|
|
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
// POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
2006-01-16 22:02:54 +01:00
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// $Id$
|
|
|
|
|
|
|
|
/// @file timeedit_ctrl.cpp
|
|
|
|
/// @brief Edit-control for editing SSA-format timestamps
|
|
|
|
/// @ingroup custom_control
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2011-12-22 22:18:16 +01:00
|
|
|
#include "timeedit_ctrl.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#ifndef AGI_PRE
|
2011-12-22 22:18:16 +01:00
|
|
|
#include <tr1/functional>
|
|
|
|
|
2006-12-17 18:19:45 +01:00
|
|
|
#include <wx/clipbrd.h>
|
2009-09-10 12:26:50 +02:00
|
|
|
#include <wx/dataobj.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <wx/menu.h>
|
|
|
|
#include <wx/valtext.h>
|
|
|
|
#endif
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
#include "ass_time.h"
|
2010-05-21 03:13:36 +02:00
|
|
|
#include "compat.h"
|
2011-12-22 22:18:16 +01:00
|
|
|
#include "include/aegisub/context.h"
|
2010-05-21 03:13:36 +02:00
|
|
|
#include "main.h"
|
2010-07-08 06:29:04 +02:00
|
|
|
#include "video_context.h"
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2012-03-25 06:05:06 +02:00
|
|
|
#define TimeEditWindowStyle
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-12-22 22:18:16 +01:00
|
|
|
enum {
|
|
|
|
Time_Edit_Copy = 1320,
|
|
|
|
Time_Edit_Paste
|
|
|
|
};
|
|
|
|
|
|
|
|
TimeEdit::TimeEdit(wxWindow* parent, wxWindowID id, agi::Context *c, const wxString& value, const wxSize& size, bool asEnd)
|
2011-12-22 22:18:45 +01:00
|
|
|
: wxTextCtrl(parent, id, value, wxDefaultPosition, size, wxTE_CENTRE | wxTE_PROCESS_ENTER)
|
2011-12-22 22:18:16 +01:00
|
|
|
, c(c)
|
|
|
|
, byFrame(false)
|
|
|
|
, isEnd(asEnd)
|
|
|
|
, insert(!OPT_GET("Subtitle/Time Edit/Insert Mode")->GetBool())
|
|
|
|
, insert_opt(OPT_SUB("Subtitle/Time Edit/Insert Mode", &TimeEdit::OnInsertChanged, this))
|
2006-01-16 22:02:54 +01:00
|
|
|
{
|
2007-06-23 08:07:32 +02:00
|
|
|
// Set validator
|
|
|
|
wxTextValidator val(wxFILTER_INCLUDE_CHAR_LIST);
|
|
|
|
wxArrayString includes;
|
2011-09-28 21:43:11 +02:00
|
|
|
includes.Add("0");
|
|
|
|
includes.Add("1");
|
|
|
|
includes.Add("2");
|
|
|
|
includes.Add("3");
|
|
|
|
includes.Add("4");
|
|
|
|
includes.Add("5");
|
|
|
|
includes.Add("6");
|
|
|
|
includes.Add("7");
|
|
|
|
includes.Add("8");
|
|
|
|
includes.Add("9");
|
|
|
|
includes.Add(".");
|
|
|
|
includes.Add(":");
|
2007-06-23 08:07:32 +02:00
|
|
|
val.SetIncludes(includes);
|
|
|
|
SetValidator(val);
|
|
|
|
|
|
|
|
// Other stuff
|
2012-10-12 03:52:36 +02:00
|
|
|
if (!value) SetValue(time.GetAssFormated());
|
2010-07-20 05:11:11 +02:00
|
|
|
|
2012-05-04 04:53:14 +02:00
|
|
|
Bind(wxEVT_COMMAND_MENU_SELECTED, std::tr1::bind(&TimeEdit::CopyTime, this), Time_Edit_Copy);
|
|
|
|
Bind(wxEVT_COMMAND_MENU_SELECTED, std::tr1::bind(&TimeEdit::PasteTime, this), Time_Edit_Paste);
|
2010-07-20 05:11:11 +02:00
|
|
|
Bind(wxEVT_COMMAND_TEXT_UPDATED, &TimeEdit::OnModified, this);
|
2011-08-31 06:17:37 +02:00
|
|
|
Bind(wxEVT_CONTEXT_MENU, &TimeEdit::OnContextMenu, this);
|
2011-12-22 22:18:16 +01:00
|
|
|
Bind(wxEVT_KEY_DOWN, &TimeEdit::OnKeyDown, this);
|
2011-12-22 22:29:18 +01:00
|
|
|
Bind(wxEVT_KILL_FOCUS, &TimeEdit::OnFocusLost, this);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2011-12-22 22:28:51 +01:00
|
|
|
void TimeEdit::SetTime(AssTime new_time) {
|
|
|
|
if (time != new_time) {
|
|
|
|
time = new_time;
|
2010-07-20 05:11:11 +02:00
|
|
|
UpdateText();
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2011-12-22 22:30:22 +01:00
|
|
|
int TimeEdit::GetFrame() const {
|
|
|
|
return c->videoController->FrameAtTime(time, isEnd ? agi::vfr::END : agi::vfr::START);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimeEdit::SetFrame(int fn) {
|
|
|
|
SetTime(c->videoController->TimeAtFrame(fn, isEnd ? agi::vfr::END : agi::vfr::START));
|
|
|
|
}
|
|
|
|
|
2010-07-20 05:11:11 +02:00
|
|
|
void TimeEdit::SetByFrame(bool enableByFrame) {
|
|
|
|
if (enableByFrame == byFrame) return;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-12-22 22:18:16 +01:00
|
|
|
byFrame = enableByFrame && c->videoController->TimecodesLoaded();
|
|
|
|
UpdateText();
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-12-22 22:18:16 +01:00
|
|
|
void TimeEdit::OnModified(wxCommandEvent &event) {
|
|
|
|
event.Skip();
|
2006-01-16 22:02:54 +01:00
|
|
|
if (byFrame) {
|
2011-12-22 22:30:14 +01:00
|
|
|
long temp = 0;
|
2006-01-16 22:02:54 +01:00
|
|
|
GetValue().ToLong(&temp);
|
2011-12-22 22:30:14 +01:00
|
|
|
time = c->videoController->TimeAtFrame(temp, isEnd ? agi::vfr::END : agi::vfr::START);
|
2007-06-23 08:07:32 +02:00
|
|
|
}
|
2011-12-22 22:18:16 +01:00
|
|
|
else if (insert)
|
2012-02-14 01:35:06 +01:00
|
|
|
time = GetValue();
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2007-06-23 08:07:32 +02:00
|
|
|
|
2011-12-22 22:18:16 +01:00
|
|
|
void TimeEdit::UpdateText() {
|
|
|
|
if (byFrame)
|
2011-12-22 22:28:51 +01:00
|
|
|
ChangeValue(wxString::Format("%d", c->videoController->FrameAtTime(time, isEnd ? agi::vfr::END : agi::vfr::START)));
|
2011-12-22 22:18:16 +01:00
|
|
|
else
|
2012-10-12 03:52:36 +02:00
|
|
|
ChangeValue(time.GetAssFormated());
|
2007-06-23 08:07:32 +02:00
|
|
|
}
|
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
void TimeEdit::OnKeyDown(wxKeyEvent &event) {
|
|
|
|
int key = event.GetKeyCode();
|
2011-12-22 22:18:16 +01:00
|
|
|
if (event.CmdDown()) {
|
|
|
|
if (key == 'C' || key == 'X')
|
2006-12-17 18:19:45 +01:00
|
|
|
CopyTime();
|
2011-12-22 22:18:16 +01:00
|
|
|
else if (key == 'V')
|
2006-12-17 18:19:45 +01:00
|
|
|
PasteTime();
|
2011-12-22 22:18:16 +01:00
|
|
|
else
|
2011-12-22 22:18:07 +01:00
|
|
|
event.Skip();
|
2012-05-28 16:18:40 +02:00
|
|
|
return;
|
2006-12-17 18:19:45 +01:00
|
|
|
}
|
2012-05-28 16:18:40 +02:00
|
|
|
|
2012-05-28 16:18:10 +02:00
|
|
|
// Shift-Insert would paste the stuff anyway
|
|
|
|
// but no one updates the private "time" variable.
|
2012-05-28 16:18:40 +02:00
|
|
|
if (event.ShiftDown() && key == WXK_INSERT) {
|
|
|
|
PasteTime();
|
|
|
|
return;
|
2012-05-28 16:18:10 +02:00
|
|
|
}
|
2012-05-28 16:18:40 +02:00
|
|
|
|
|
|
|
// Translate numpad presses to normal numbers
|
|
|
|
if (key >= WXK_NUMPAD0 && key <= WXK_NUMPAD9)
|
|
|
|
key += '0' - WXK_NUMPAD0;
|
|
|
|
|
|
|
|
// If overwriting is disabled, we're in frame mode, or it's a key we
|
|
|
|
// don't care about just let the standard processing happen
|
|
|
|
event.Skip();
|
|
|
|
if (byFrame) return;
|
|
|
|
if (insert) return;
|
|
|
|
if ((key < '0' || key > '9') && key != WXK_BACK && key != WXK_DELETE && key != ';' && key != '.') return;
|
|
|
|
|
|
|
|
event.Skip(false);
|
|
|
|
|
|
|
|
long start = GetInsertionPoint();
|
|
|
|
wxString text = GetValue();
|
|
|
|
|
|
|
|
// Delete does nothing
|
|
|
|
if (key == WXK_DELETE) return;
|
|
|
|
// Back just moves cursor back one without deleting
|
|
|
|
if (key == WXK_BACK) {
|
|
|
|
if (start > 0)
|
|
|
|
SetInsertionPoint(start - 1);
|
|
|
|
return;
|
2011-12-22 22:18:16 +01:00
|
|
|
}
|
2012-05-28 16:18:40 +02:00
|
|
|
// Cursor is at the end so do nothing
|
|
|
|
if (start >= (long)text.size()) return;
|
|
|
|
|
|
|
|
// If the cursor is at punctuation, move it forward to the next digit
|
|
|
|
if (text[start] == ':' || text[start] == '.')
|
|
|
|
++start;
|
|
|
|
|
|
|
|
// : and . hop over punctuation but never insert anything
|
|
|
|
if (key == ';' || key == '.') {
|
|
|
|
SetInsertionPoint(start);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Overwrite the digit
|
|
|
|
time = text.Left(start) + (char)key + text.Mid(start + 1);
|
2012-10-12 03:52:36 +02:00
|
|
|
SetValue(time.GetAssFormated());
|
2012-05-28 16:18:40 +02:00
|
|
|
SetInsertionPoint(start + 1);
|
2007-06-23 08:07:32 +02:00
|
|
|
}
|
|
|
|
|
2011-12-22 22:18:16 +01:00
|
|
|
void TimeEdit::OnInsertChanged(agi::OptionValue const& opt) {
|
|
|
|
insert = !opt.GetBool();
|
2007-06-23 08:07:32 +02:00
|
|
|
}
|
|
|
|
|
2011-12-22 22:18:16 +01:00
|
|
|
void TimeEdit::OnContextMenu(wxContextMenuEvent &evt) {
|
|
|
|
if (byFrame || insert) {
|
|
|
|
evt.Skip();
|
2006-12-17 18:19:45 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-22 22:18:16 +01:00
|
|
|
wxMenu menu;
|
|
|
|
menu.Append(Time_Edit_Copy, _("&Copy"));
|
|
|
|
menu.Append(Time_Edit_Paste, _("&Paste"));
|
|
|
|
PopupMenu(&menu);
|
|
|
|
}
|
|
|
|
|
2011-12-22 22:29:18 +01:00
|
|
|
void TimeEdit::OnFocusLost(wxFocusEvent &evt) {
|
|
|
|
if (insert || byFrame)
|
|
|
|
UpdateText();
|
|
|
|
evt.Skip();
|
|
|
|
}
|
|
|
|
|
2011-12-22 22:18:16 +01:00
|
|
|
void TimeEdit::CopyTime() {
|
2006-12-17 18:19:45 +01:00
|
|
|
if (wxTheClipboard->Open()) {
|
2011-12-22 22:18:16 +01:00
|
|
|
wxTheClipboard->SetData(new wxTextDataObject(GetValue()));
|
2006-12-17 18:19:45 +01:00
|
|
|
wxTheClipboard->Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void TimeEdit::PasteTime() {
|
|
|
|
if (byFrame) {
|
|
|
|
Paste();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (wxTheClipboard->Open()) {
|
|
|
|
wxString text;
|
|
|
|
if (wxTheClipboard->IsSupported(wxDF_TEXT)) {
|
|
|
|
wxTextDataObject data;
|
|
|
|
wxTheClipboard->GetData(data);
|
2011-12-22 22:18:16 +01:00
|
|
|
text = data.GetText().Trim(false).Trim(true);
|
2006-12-17 18:19:45 +01:00
|
|
|
}
|
|
|
|
wxTheClipboard->Close();
|
|
|
|
|
2012-02-14 01:35:06 +01:00
|
|
|
AssTime tempTime(text);
|
2012-10-12 03:52:36 +02:00
|
|
|
if (tempTime.GetAssFormated() == text) {
|
2011-12-22 22:18:16 +01:00
|
|
|
SetTime(tempTime);
|
|
|
|
SetSelection(0, GetValue().size());
|
2012-02-23 01:46:33 +01:00
|
|
|
|
|
|
|
wxCommandEvent evt(wxEVT_COMMAND_TEXT_UPDATED, GetId());
|
|
|
|
evt.SetEventObject(this);
|
|
|
|
HandleWindowEvent(evt);
|
2006-12-17 18:19:45 +01:00
|
|
|
}
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|