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/Standard", Refresh);
OPT_SUB("Subtitle/Grid/Highlight Subtitles in Frame", Refresh);
Bind(wxEVT_CONTEXT_MENU, &BaseGrid::OnContextMenu, this);
}
BaseGrid::~BaseGrid() {
@ -641,10 +643,9 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
#endif
// Row that mouse is over
bool click = event.ButtonDown(wxMOUSE_BTN_LEFT);
bool click = event.LeftDown();
bool dclick = event.LeftDClick();
int row = event.GetY()/lineHeight + yPos - 1;
bool headerClick = row < yPos;
if (holding && !click) {
row = mid(0,row,GetRows()-1);
}
@ -742,11 +743,6 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
return;
}
// Popup
if (event.RightDown()) {
OnPopupMenu(headerClick);
}
// Mouse wheel
if (event.GetWheelRotation() != 0) {
int step = 3 * event.GetWheelRotation() / event.GetWheelDelta();
@ -757,6 +753,14 @@ void BaseGrid::OnMouseEvent(wxMouseEvent &event) {
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) {
int 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
Selection batch_selection_removed;
void OnContextMenu(wxContextMenuEvent &evt);
void OnPaint(wxPaintEvent &event);
void OnSize(wxSizeEvent &event);
void OnScroll(wxScrollEvent &event);
@ -100,7 +101,8 @@ class BaseGrid : public wxWindow, public BaseSelectionController<AssDialogue> {
void DrawImage(wxDC &dc, bool paint_columns[]);
void ScrollTo(int y);
virtual void OnPopupMenu(bool alternate = false) { }
virtual void OpenHeaderContextMenu() { }
virtual void OpenBodyContextMenu() { }
protected:
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_CONTEXT_MENU, &SubsTextEditCtrl::OnContextMenu, this);
OPT_SUB("Subtitle/Edit Box/Font Face", &SubsTextEditCtrl::SetStyles, this);
OPT_SUB("Subtitle/Edit Box/Font Size", &SubsTextEditCtrl::SetStyles, this);
OPT_SUB("Colour/Subtitle/Syntax/Normal", &SubsTextEditCtrl::SetStyles, this);
@ -204,7 +206,6 @@ SubsTextEditCtrl::~SubsTextEditCtrl() {
}
BEGIN_EVENT_TABLE(SubsTextEditCtrl,wxStyledTextCtrl)
EVT_MOUSE_EVENTS(SubsTextEditCtrl::OnMouseEvent)
EVT_KILL_FOCUS(SubsTextEditCtrl::OnLoseFocus)
EVT_MENU(EDIT_MENU_SPLIT_PRESERVE,SubsTextEditCtrl::OnSplitLinePreserve)
@ -763,23 +764,20 @@ void SubsTextEditCtrl::SetTextTo(wxString text) {
Thaw();
}
void SubsTextEditCtrl::OnMouseEvent(wxMouseEvent &event) {
if (event.ButtonUp(wxMOUSE_BTN_RIGHT)) {
if (grid->GetActiveLine() != 0) {
int pos = PositionFromPoint(event.GetPosition());
ShowPopupMenu(pos);
void SubsTextEditCtrl::OnContextMenu(wxContextMenuEvent &event) {
if (!grid->GetActiveLine())
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;
if (activePos == -1) activePos = GetCurrentPos();
activePos = GetReverseUnicodePosition(activePos);
currentWord = GetWordAtPosition(activePos);

View file

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

View file

@ -115,11 +115,7 @@ void SubtitlesGrid::OnSubtitlesOpen() {
SetColumnWidths();
}
/// @brief Popup menu
/// @param alternate
void SubtitlesGrid::OnPopupMenu(bool alternate) {
// Alternate
if (alternate) {
void SubtitlesGrid::OpenHeaderContextMenu() {
const wxString strings[] = {
_("Line Number"),
_("Layer"),
@ -136,13 +132,12 @@ void SubtitlesGrid::OnPopupMenu(bool alternate) {
// Create Menu
wxMenu menu;
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);
return;
}
void SubtitlesGrid::OpenBodyContextMenu() {
if (!context_menu) context_menu = menu::GetMenu("grid_context", context);
menu::OpenPopupMenu(context_menu, this);
}

View file

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

View file

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

View file

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

View file

@ -77,11 +77,6 @@
#include "visual_tool_scale.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
int attribList[] = { WX_GL_RGBA , WX_GL_DOUBLEBUFFER, WX_GL_STENCIL_SIZE, 8, 0 };
@ -136,6 +131,14 @@ VideoDisplay::VideoDisplay(
if (freeSize) {
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);
@ -163,8 +166,7 @@ void VideoDisplay::ShowCursor(bool show) {
SetCursor(wxNullCursor);
}
else {
wxCursor cursor(wxCURSOR_BLANK);
SetCursor(cursor);
SetCursor(wxCursor(wxCURSOR_BLANK));
}
}
@ -395,33 +397,37 @@ void VideoDisplay::OnMouseEvent(wxMouseEvent& event) {
// Disable when playing
if (con->videoController->IsPlaying()) return;
if (event.ButtonUp(wxMOUSE_BTN_RIGHT)) {
if (!context_menu.get()) context_menu.reset(menu::GetMenu("video_context", con));
ShowCursor(true);
menu::OpenPopupMenu(context_menu.get(), this);
return;
if (event.ButtonDown())
SetFocus();
video.x = event.GetX();
video.y = event.GetY();
tool->OnMouseEvent(event);
}
if (event.ButtonDown(wxMOUSE_BTN_ANY)) {
SetFocus();
void VideoDisplay::OnMouseEnter(wxMouseEvent& event) {
ShowCursor(activeMode != Video_Mode_Standard);
tool->OnMouseEvent(event);
}
int wheel = event.GetWheelRotation();
if (wheel) {
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()));
}
if (event.Leaving()) {
video.x = INT_MIN;
video.y = INT_MIN;
}
else {
video.x = event.GetX();
video.y = event.GetY();
void VideoDisplay::OnContextMenu(wxContextMenuEvent&) {
if (!context_menu.get()) context_menu.reset(menu::GetMenu("video_context", con));
ShowCursor(true);
menu::OpenPopupMenu(context_menu.get(), this);
}
tool->OnMouseEvent(event);
ShowCursor(activeMode != Video_Mode_Standard);
}
void VideoDisplay::OnKeyDown(wxKeyEvent &event) {
/// @todo
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
UpdateSize();
ShowCursor(activeMode != Video_Mode_Standard);
}
void VideoDisplay::ToScriptCoords(int *x, int *y) const {

View file

@ -168,9 +168,13 @@ class VideoDisplay : public wxGLCanvas {
void OnKeyDown(wxKeyEvent &event);
/// @brief Mouse event handler
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
void OnSizeEvent(wxSizeEvent &event);
void OnMode(const wxCommandEvent &event);
void OnContextMenu(wxContextMenuEvent&);
public:
/// @brief Constructor
@ -204,6 +208,4 @@ public:
/// @param[out] x x coordinate
/// @param[out] y y coordinate
void GetMousePosition(int *x, int *y) const;
DECLARE_EVENT_TABLE()
};