diff --git a/common/widgets/html_window.cpp b/common/widgets/html_window.cpp index afee719349..ae02fdcef3 100644 --- a/common/widgets/html_window.cpp +++ b/common/widgets/html_window.cpp @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2021 Mikołaj Wielgus <wielgusmikolaj@gmail.com> - * Copyright (C) 2021 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2021-2024 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -22,8 +22,11 @@ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA */ -#include <widgets/html_window.h> +#include <wx/menu.h> +#include <wx/clipbrd.h> +#include <wx/log.h> #include <wx/settings.h> +#include <widgets/html_window.h> HTML_WINDOW::HTML_WINDOW( wxWindow* aParent, wxWindowID aId, const wxPoint& aPos, @@ -32,6 +35,15 @@ HTML_WINDOW::HTML_WINDOW( wxWindow* aParent, wxWindowID aId, const wxPoint& aPos { Bind( wxEVT_SYS_COLOUR_CHANGED, wxSysColourChangedEventHandler( HTML_WINDOW::onThemeChanged ), this ); + + Connect( wxEVT_RIGHT_UP, wxMouseEventHandler( HTML_WINDOW::onRightClick ), nullptr, this ); +} + + +HTML_WINDOW::~HTML_WINDOW() +{ + // Disconnect Events + Disconnect( wxEVT_RIGHT_UP, wxMouseEventHandler( HTML_WINDOW::onRightClick ), nullptr, this ); } @@ -70,3 +82,32 @@ void HTML_WINDOW::onThemeChanged( wxSysColourChangedEvent &aEvent ) { ThemeChanged(); } + + +void HTML_WINDOW::onRightClick( wxMouseEvent& event ) +{ + wxMenu popup; + popup.Append( wxID_COPY, "Copy" ); + PopupMenu( &popup ); +} + + +void HTML_WINDOW::onMenuEvent( wxMenuEvent& event ) +{ + if( event.GetId() == wxID_COPY ) + { + wxLogNull doNotLog; // disable logging of failed clipboard actions + + if( wxTheClipboard->Open() ) + { + bool primarySelection = wxTheClipboard->IsUsingPrimarySelection(); + wxTheClipboard->UsePrimarySelection( false ); // required to use the main clipboard + wxTheClipboard->SetData( new wxTextDataObject( SelectionToText() ) ); + wxTheClipboard->Flush(); // Allow data to be available after closing KiCad + wxTheClipboard->Close(); + wxTheClipboard->UsePrimarySelection( primarySelection ); + } + } +} + + diff --git a/include/widgets/html_window.h b/include/widgets/html_window.h index 0f434c9f00..a179423b01 100644 --- a/include/widgets/html_window.h +++ b/include/widgets/html_window.h @@ -2,7 +2,7 @@ * This program source code file is part of KiCad, a free EDA CAD application. * * Copyright (C) 2021 Mikołaj Wielgus <wielgusmikolaj@gmail.com> - * Copyright (C) 2021 KiCad Developers, see AUTHORS.TXT for contributors. + * Copyright (C) 2021-2024 KiCad Developers, see AUTHORS.TXT for contributors. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -33,9 +33,11 @@ class HTML_WINDOW : public wxHtmlWindow { public: - HTML_WINDOW( wxWindow* aParent, wxWindowID aId=wxID_ANY, const wxPoint& aPos=wxDefaultPosition, - const wxSize& aSize=wxDefaultSize, long aStyle=wxHW_DEFAULT_STYLE, - const wxString& aName="htmlWindow" ); + HTML_WINDOW( wxWindow* aParent, wxWindowID aId = wxID_ANY, + const wxPoint& aPos = wxDefaultPosition, const wxSize& aSize = wxDefaultSize, + long aStyle = wxHW_DEFAULT_STYLE, const wxString& aName = wxT( "htmlWindow" ) ); + + ~HTML_WINDOW(); bool SetPage( const wxString& aSource ) override; bool AppendToPage( const wxString& aSource ); @@ -47,6 +49,8 @@ public: private: void onThemeChanged( wxSysColourChangedEvent& aEvent ); + void onRightClick( wxMouseEvent& event ); + void onMenuEvent( wxMenuEvent& event ); wxString m_pageSource; };