Use wxEVT_CONTEXT_MENU for context menus rather than right button down so that the context menu key works correctly. Updates #1238.

Originally committed to SVN as r5578.
This commit is contained in:
Thomas Goyne 2011-08-31 04:17:37 +00:00
parent 1c4410bb87
commit d82e2bb496
10 changed files with 98 additions and 98 deletions

View file

@ -115,6 +115,8 @@ BaseGrid::BaseGrid(wxWindow* parent, agi::Context *context, const wxSize& size,
OPT_SUB("Colour/Subtitle Grid/Selection", Refresh); OPT_SUB("Colour/Subtitle Grid/Selection", Refresh);
OPT_SUB("Colour/Subtitle Grid/Standard", Refresh); OPT_SUB("Colour/Subtitle Grid/Standard", Refresh);
OPT_SUB("Subtitle/Grid/Highlight Subtitles in Frame", Refresh); OPT_SUB("Subtitle/Grid/Highlight Subtitles in Frame", Refresh);
Bind(wxEVT_CONTEXT_MENU, &BaseGrid::OnContextMenu, this);
} }
BaseGrid::~BaseGrid() { BaseGrid::~BaseGrid() {
@ -641,10 +643,9 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
#endif #endif
// Row that mouse is over // Row that mouse is over
bool click = event.ButtonDown(wxMOUSE_BTN_LEFT); bool click = event.LeftDown();
bool dclick = event.LeftDClick(); bool dclick = event.LeftDClick();
int row = event.GetY()/lineHeight + yPos - 1; int row = event.GetY()/lineHeight + yPos - 1;
bool headerClick = row < yPos;
if (holding && !click) { if (holding && !click) {
row = mid(0,row,GetRows()-1); row = mid(0,row,GetRows()-1);
} }
@ -742,11 +743,6 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
return; return;
} }
// Popup
if (event.RightDown()) {
OnPopupMenu(headerClick);
}
// Mouse wheel // Mouse wheel
if (event.GetWheelRotation() != 0) { if (event.GetWheelRotation() != 0) {
int step = 3 * event.GetWheelRotation() / event.GetWheelDelta(); int step = 3 * event.GetWheelRotation() / event.GetWheelDelta();
@ -757,6 +753,14 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
event.Skip(); event.Skip();
} }
void BaseGrid::OnContextMenu(wxContextMenuEvent &evt) {
wxPoint pos = evt.GetPosition();
if (pos == wxDefaultPosition || ScreenToClient(pos).y > lineHeight)
OpenBodyContextMenu();
else
OpenHeaderContextMenu();
}
void BaseGrid::ScrollTo(int y) { void BaseGrid::ScrollTo(int y) {
int w,h; int w,h;
GetClientSize(&w,&h); GetClientSize(&w,&h);

View file

@ -91,6 +91,7 @@ class BaseGrid : public wxWindow, public BaseSelectionController<AssDialogue> {
/// is completed; should be a subset of selection /// is completed; should be a subset of selection
Selection batch_selection_removed; Selection batch_selection_removed;
void OnContextMenu(wxContextMenuEvent &evt);
void OnPaint(wxPaintEvent &event); void OnPaint(wxPaintEvent &event);
void OnSize(wxSizeEvent &event); void OnSize(wxSizeEvent &event);
void OnScroll(wxScrollEvent &event); void OnScroll(wxScrollEvent &event);
@ -100,7 +101,8 @@ class BaseGrid : public wxWindow, public BaseSelectionController<AssDialogue> {
void DrawImage(wxDC &dc, bool paint_columns[]); void DrawImage(wxDC &dc, bool paint_columns[]);
void ScrollTo(int y); void ScrollTo(int y);
virtual void OnPopupMenu(bool alternate = false) { } virtual void OpenHeaderContextMenu() { }
virtual void OpenBodyContextMenu() { }
protected: protected:
int colWidth[16]; ///< Width in pixels of each column int colWidth[16]; ///< Width in pixels of each column

View file

@ -182,6 +182,8 @@ SubsTextEditCtrl::SubsTextEditCtrl(wxWindow* parent, wxSize wsize, long style, S
Bind(wxEVT_STC_STYLENEEDED, &SubsTextEditCtrl::UpdateCallTip, this); Bind(wxEVT_STC_STYLENEEDED, &SubsTextEditCtrl::UpdateCallTip, this);
Bind(wxEVT_CONTEXT_MENU, &SubsTextEditCtrl::OnContextMenu, this);
OPT_SUB("Subtitle/Edit Box/Font Face", &SubsTextEditCtrl::SetStyles, this); OPT_SUB("Subtitle/Edit Box/Font Face", &SubsTextEditCtrl::SetStyles, this);
OPT_SUB("Subtitle/Edit Box/Font Size", &SubsTextEditCtrl::SetStyles, this); OPT_SUB("Subtitle/Edit Box/Font Size", &SubsTextEditCtrl::SetStyles, this);
OPT_SUB("Colour/Subtitle/Syntax/Normal", &SubsTextEditCtrl::SetStyles, this); OPT_SUB("Colour/Subtitle/Syntax/Normal", &SubsTextEditCtrl::SetStyles, this);
@ -204,7 +206,6 @@ SubsTextEditCtrl::~SubsTextEditCtrl() {
} }
BEGIN_EVENT_TABLE(SubsTextEditCtrl,wxStyledTextCtrl) BEGIN_EVENT_TABLE(SubsTextEditCtrl,wxStyledTextCtrl)
EVT_MOUSE_EVENTS(SubsTextEditCtrl::OnMouseEvent)
EVT_KILL_FOCUS(SubsTextEditCtrl::OnLoseFocus) EVT_KILL_FOCUS(SubsTextEditCtrl::OnLoseFocus)
EVT_MENU(EDIT_MENU_SPLIT_PRESERVE,SubsTextEditCtrl::OnSplitLinePreserve) EVT_MENU(EDIT_MENU_SPLIT_PRESERVE,SubsTextEditCtrl::OnSplitLinePreserve)
@ -763,23 +764,20 @@ void SubsTextEditCtrl::SetTextTo(wxString text) {
Thaw(); Thaw();
} }
void SubsTextEditCtrl::OnMouseEvent(wxMouseEvent &event) { void SubsTextEditCtrl::OnContextMenu(wxContextMenuEvent &event) {
if (event.ButtonUp(wxMOUSE_BTN_RIGHT)) { if (!grid->GetActiveLine())
if (grid->GetActiveLine() != 0) {
int pos = PositionFromPoint(event.GetPosition());
ShowPopupMenu(pos);
return; return;
wxPoint pos = event.GetPosition();
int activePos;
if (pos == wxDefaultPosition) {
activePos = GetCurrentPos();
} }
else {
activePos = PositionFromPoint(ScreenToClient(pos));
} }
event.Skip();
GetParent()->GetEventHandler()->ProcessEvent(event);
}
void SubsTextEditCtrl::ShowPopupMenu(int activePos) {
wxMenu menu; wxMenu menu;
if (activePos == -1) activePos = GetCurrentPos();
activePos = GetReverseUnicodePosition(activePos); activePos = GetReverseUnicodePosition(activePos);
currentWord = GetWordAtPosition(activePos); currentWord = GetWordAtPosition(activePos);

View file

@ -79,9 +79,7 @@ class SubsTextEditCtrl : public ScintillaTextCtrl {
/// DOCME /// DOCME
int tipProtoN; int tipProtoN;
void ShowPopupMenu(int activePos=-1); void OnContextMenu(wxContextMenuEvent &);
void OnMouseEvent(wxMouseEvent &event);
void OnSplitLinePreserve(wxCommandEvent &event); void OnSplitLinePreserve(wxCommandEvent &event);
void OnSplitLineEstimate(wxCommandEvent &event); void OnSplitLineEstimate(wxCommandEvent &event);
void OnAddToDictionary(wxCommandEvent &event); void OnAddToDictionary(wxCommandEvent &event);

View file

@ -115,11 +115,7 @@ void SubtitlesGrid::OnSubtitlesOpen() {
SetColumnWidths(); SetColumnWidths();
} }
/// @brief Popup menu void SubtitlesGrid::OpenHeaderContextMenu() {
/// @param alternate
void SubtitlesGrid::OnPopupMenu(bool alternate) {
// Alternate
if (alternate) {
const wxString strings[] = { const wxString strings[] = {
_("Line Number"), _("Line Number"),
_("Layer"), _("Layer"),
@ -136,13 +132,12 @@ void SubtitlesGrid::OnPopupMenu(bool alternate) {
// Create Menu // Create Menu
wxMenu menu; wxMenu menu;
for (size_t i=0;i<columns;i++) { for (size_t i=0;i<columns;i++) {
menu.Append(MENU_SHOW_COL + i,strings[i],_T(""),wxITEM_CHECK)->Check(showCol[i]); menu.Append(MENU_SHOW_COL + i,strings[i],"",wxITEM_CHECK)->Check(showCol[i]);
} }
PopupMenu(&menu); PopupMenu(&menu);
}
return; void SubtitlesGrid::OpenBodyContextMenu() {
}
if (!context_menu) context_menu = menu::GetMenu("grid_context", context); if (!context_menu) context_menu = menu::GetMenu("grid_context", context);
menu::OpenPopupMenu(context_menu, this); menu::OpenPopupMenu(context_menu, this);
} }

View file

@ -62,7 +62,8 @@ class SubtitlesGrid: public BaseGrid {
agi::signal::Connection seekListener; agi::signal::Connection seekListener;
wxMenu *context_menu; wxMenu *context_menu;
void OnPopupMenu(bool alternate=false); void OpenHeaderContextMenu();
void OpenBodyContextMenu();
void OnShowColMenu(wxCommandEvent &event); void OnShowColMenu(wxCommandEvent &event);

View file

@ -104,10 +104,10 @@ wxTextCtrl(parent,id,value,pos,size,TimeEditWindowStyle | style,validator,name)
isEnd = false; isEnd = false;
Bind(wxEVT_COMMAND_TEXT_UPDATED, &TimeEdit::OnModified, this); Bind(wxEVT_COMMAND_TEXT_UPDATED, &TimeEdit::OnModified, this);
Bind(wxEVT_CONTEXT_MENU, &TimeEdit::OnContextMenu, this);
} }
BEGIN_EVENT_TABLE(TimeEdit, wxTextCtrl) BEGIN_EVENT_TABLE(TimeEdit, wxTextCtrl)
EVT_MOUSE_EVENTS(TimeEdit::OnMouseEvent)
EVT_KEY_DOWN(TimeEdit::OnKeyDown) EVT_KEY_DOWN(TimeEdit::OnKeyDown)
EVT_MENU(Time_Edit_Copy,TimeEdit::OnCopy) EVT_MENU(Time_Edit_Copy,TimeEdit::OnCopy)
EVT_MENU(Time_Edit_Paste,TimeEdit::OnPaste) EVT_MENU(Time_Edit_Paste,TimeEdit::OnPaste)
@ -259,20 +259,13 @@ void TimeEdit::OnKeyDown(wxKeyEvent &event) {
/// @brief Mouse event /// @brief Mouse event
/// @param event /// @param event
void TimeEdit::OnMouseEvent(wxMouseEvent &event) { void TimeEdit::OnContextMenu(wxContextMenuEvent &event) {
// Right click context menu
if (event.RightUp()) {
if (!byFrame && OPT_GET("Subtitle/Time Edit/Insert Mode")->GetBool()) { if (!byFrame && OPT_GET("Subtitle/Time Edit/Insert Mode")->GetBool()) {
wxMenu menu; wxMenu menu;
menu.Append(Time_Edit_Copy,_("&Copy")); menu.Append(Time_Edit_Copy,_("&Copy"));
menu.Append(Time_Edit_Paste,_("&Paste")); menu.Append(Time_Edit_Paste,_("&Paste"));
PopupMenu(&menu); PopupMenu(&menu);
return;
} }
}
// Allow other events through
event.Skip();
} }
/// @brief Menu Copy /// @brief Menu Copy

View file

@ -67,7 +67,7 @@ private:
/// DOCME /// DOCME
void OnModified(wxCommandEvent &event); void OnModified(wxCommandEvent &event);
void OnMouseEvent(wxMouseEvent &event); void OnContextMenu(wxContextMenuEvent &event);
void OnKeyDown(wxKeyEvent &event); void OnKeyDown(wxKeyEvent &event);
void OnCopy(wxCommandEvent &event); void OnCopy(wxCommandEvent &event);
void OnPaste(wxCommandEvent &event); void OnPaste(wxCommandEvent &event);

View file

@ -77,11 +77,6 @@
#include "visual_tool_scale.h" #include "visual_tool_scale.h"
#include "visual_tool_vector_clip.h" #include "visual_tool_vector_clip.h"
BEGIN_EVENT_TABLE(VideoDisplay, wxGLCanvas)
EVT_MOUSE_EVENTS(VideoDisplay::OnMouseEvent)
EVT_KEY_DOWN(VideoDisplay::OnKeyDown)
END_EVENT_TABLE()
/// Attribute list for gl canvases; set the canvases to doublebuffered rgba with an 8 bit stencil buffer /// Attribute list for gl canvases; set the canvases to doublebuffered rgba with an 8 bit stencil buffer
int attribList[] = { WX_GL_RGBA , WX_GL_DOUBLEBUFFER, WX_GL_STENCIL_SIZE, 8, 0 }; int attribList[] = { WX_GL_RGBA , WX_GL_DOUBLEBUFFER, WX_GL_STENCIL_SIZE, 8, 0 };
@ -136,6 +131,14 @@ VideoDisplay::VideoDisplay(
if (freeSize) { if (freeSize) {
Bind(wxEVT_SIZE, &VideoDisplay::OnSizeEvent, this); Bind(wxEVT_SIZE, &VideoDisplay::OnSizeEvent, this);
} }
Bind(wxEVT_CONTEXT_MENU, &VideoDisplay::OnContextMenu, this);
Bind(wxEVT_KEY_DOWN, &VideoDisplay::OnKeyDown, this);
Bind(wxEVT_LEFT_DOWN, &VideoDisplay::OnMouseEvent, this);
Bind(wxEVT_LEFT_UP, &VideoDisplay::OnMouseEvent, this);
Bind(wxEVT_MOTION, &VideoDisplay::OnMouseEvent, this);
Bind(wxEVT_ENTER_WINDOW, &VideoDisplay::OnMouseEnter, this);
Bind(wxEVT_LEAVE_WINDOW, &VideoDisplay::OnMouseLeave, this);
Bind(wxEVT_MOUSEWHEEL, &VideoDisplay::OnMouseWheel, this);
SetCursor(wxNullCursor); SetCursor(wxNullCursor);
@ -163,8 +166,7 @@ void VideoDisplay::ShowCursor(bool show) {
SetCursor(wxNullCursor); SetCursor(wxNullCursor);
} }
else { else {
wxCursor cursor(wxCURSOR_BLANK); SetCursor(wxCursor(wxCURSOR_BLANK));
SetCursor(cursor);
} }
} }
@ -395,33 +397,37 @@ void VideoDisplay::OnMouseEvent(wxMouseEvent& event) {
// Disable when playing // Disable when playing
if (con->videoController->IsPlaying()) return; if (con->videoController->IsPlaying()) return;
if (event.ButtonUp(wxMOUSE_BTN_RIGHT)) { if (event.ButtonDown())
SetFocus();
video.x = event.GetX();
video.y = event.GetY();
tool->OnMouseEvent(event);
}
void VideoDisplay::OnMouseEnter(wxMouseEvent& event) {
ShowCursor(activeMode != Video_Mode_Standard);
tool->OnMouseEvent(event);
}
void VideoDisplay::OnMouseLeave(wxMouseEvent& event) {
video.x = INT_MIN;
video.y = INT_MIN;
tool->OnMouseEvent(event);
}
void VideoDisplay::OnMouseWheel(wxMouseEvent& event) {
if (int wheel = event.GetWheelRotation())
SetZoom (zoomValue + .125 * (wheel / event.GetWheelDelta()));
}
void VideoDisplay::OnContextMenu(wxContextMenuEvent&) {
if (!context_menu.get()) context_menu.reset(menu::GetMenu("video_context", con)); if (!context_menu.get()) context_menu.reset(menu::GetMenu("video_context", con));
ShowCursor(true); ShowCursor(true);
menu::OpenPopupMenu(context_menu.get(), this); menu::OpenPopupMenu(context_menu.get(), this);
return;
}
if (event.ButtonDown(wxMOUSE_BTN_ANY)) {
SetFocus();
}
int wheel = event.GetWheelRotation();
if (wheel) {
SetZoom (zoomValue + .125 * (wheel / event.GetWheelDelta()));
}
if (event.Leaving()) {
video.x = INT_MIN;
video.y = INT_MIN;
}
else {
video.x = event.GetX();
video.y = event.GetY();
}
tool->OnMouseEvent(event);
ShowCursor(activeMode != Video_Mode_Standard);
} }
void VideoDisplay::OnKeyDown(wxKeyEvent &event) { void VideoDisplay::OnKeyDown(wxKeyEvent &event) {
/// @todo /// @todo
int kc = event.GetKeyCode(); int kc = event.GetKeyCode();
@ -489,6 +495,7 @@ void VideoDisplay::SetMode(int mode) {
// Update size as the new typesetting tool may have changed the subtoolbar size // Update size as the new typesetting tool may have changed the subtoolbar size
UpdateSize(); UpdateSize();
ShowCursor(activeMode != Video_Mode_Standard);
} }
void VideoDisplay::ToScriptCoords(int *x, int *y) const { void VideoDisplay::ToScriptCoords(int *x, int *y) const {

View file

@ -168,9 +168,13 @@ class VideoDisplay : public wxGLCanvas {
void OnKeyDown(wxKeyEvent &event); void OnKeyDown(wxKeyEvent &event);
/// @brief Mouse event handler /// @brief Mouse event handler
void OnMouseEvent(wxMouseEvent& event); void OnMouseEvent(wxMouseEvent& event);
void OnMouseWheel(wxMouseEvent& event);
void OnMouseEnter(wxMouseEvent& event);
void OnMouseLeave(wxMouseEvent& event);
/// @brief Recalculate video positioning and scaling when the available area or zoom changes /// @brief Recalculate video positioning and scaling when the available area or zoom changes
void OnSizeEvent(wxSizeEvent &event); void OnSizeEvent(wxSizeEvent &event);
void OnMode(const wxCommandEvent &event); void OnMode(const wxCommandEvent &event);
void OnContextMenu(wxContextMenuEvent&);
public: public:
/// @brief Constructor /// @brief Constructor
@ -204,6 +208,4 @@ public:
/// @param[out] x x coordinate /// @param[out] x x coordinate
/// @param[out] y y coordinate /// @param[out] y y coordinate
void GetMousePosition(int *x, int *y) const; void GetMousePosition(int *x, int *y) const;
DECLARE_EVENT_TABLE()
}; };