From 861d1be00481fb975c0d7a8c085c8dec3852e1c9 Mon Sep 17 00:00:00 2001
From: Seppe Stas <seppestas@gmail.com>
Date: Fri, 22 Sep 2017 12:36:47 +0200
Subject: [PATCH 2/2] Implement OnLayerRightClick for Gerber layer widget
MIME-Version: 1.0
Content-Type: multipart/mixed; boundary="------------2.11.0 (Apple Git-81)"

This is a multi-part message in MIME format.
--------------2.11.0 (Apple Git-81)
Content-Type: text/plain; charset=UTF-8; format=fixed
Content-Transfer-Encoding: 8bit

---
 gerbview/class_gerbview_layer_widget.cpp | 38 ++++++++++++--------------------
 gerbview/class_gerbview_layer_widget.h   | 33 +++++++++++++++++----------
 2 files changed, 35 insertions(+), 36 deletions(-)


--------------2.11.0 (Apple Git-81)
Content-Type: text/x-patch; name="0002-Implement-OnLayerRightClick-for-Gerber-layer-widget.patch"
Content-Transfer-Encoding: 8bit
Content-Disposition: attachment; filename="0002-Implement-OnLayerRightClick-for-Gerber-layer-widget.patch"

diff --git a/gerbview/class_gerbview_layer_widget.cpp b/gerbview/class_gerbview_layer_widget.cpp
index d484f9a4e..e67a8a5fd 100644
--- a/gerbview/class_gerbview_layer_widget.cpp
+++ b/gerbview/class_gerbview_layer_widget.cpp
@@ -72,9 +72,6 @@ GERBER_LAYER_WIDGET::GERBER_LAYER_WIDGET( GERBVIEW_FRAME* aParent, wxWindow* aFo
     Connect( ID_LAYER_MANAGER_START, ID_LAYER_MANAGER_END,
         wxEVT_COMMAND_MENU_SELECTED,
         wxCommandEventHandler( GERBER_LAYER_WIDGET::onPopupSelection ), NULL, this );
-
-    // install the right click handler into each control at end of ReFill()
-    // using installRightLayerClickHandler
 }
 
 GERBER_FILE_IMAGE_LIST* GERBER_LAYER_WIDGET::GetImagesList()
@@ -126,27 +123,9 @@ void GERBER_LAYER_WIDGET::ReFillRender()
     AppendRenderRows( renderRows, DIM(renderRows) );
 }
 
-void GERBER_LAYER_WIDGET::installRightLayerClickHandler()
-{
-    int rowCount = GetLayerRowCount();
-
-    for( int row=0;  row<rowCount;  ++row )
-    {
-        for( int col=0; col<LYR_COLUMN_COUNT;  ++col )
-        {
-            wxWindow* w = getLayerComp( row, col );
-
-            w->Connect( wxEVT_RIGHT_DOWN, wxMouseEventHandler(
-                GERBER_LAYER_WIDGET::onRightDownLayers ), NULL, this );
-        }
-    }
-}
-
 
-void GERBER_LAYER_WIDGET::onRightDownLayers( wxMouseEvent& event )
+void GERBER_LAYER_WIDGET::AddRightClickMenuItems( wxMenu& menu )
 {
-    wxMenu          menu;
-
     // Remember: menu text is capitalized (see our rules_for_capitalization_in_Kicad_UI.txt)
     menu.Append( new wxMenuItem( &menu, ID_SHOW_ALL_LAYERS,
                                  _("Show All Layers") ) );
@@ -163,6 +142,14 @@ void GERBER_LAYER_WIDGET::onRightDownLayers( wxMouseEvent& event )
     menu.AppendSeparator();
     menu.Append( new wxMenuItem( &menu, ID_SORT_GBR_LAYERS,
                                  _( "Sort Layers if X2 Mode" ) ) );
+}
+
+
+void GERBER_LAYER_WIDGET::onRightDownLayers( wxMouseEvent& event )
+{
+    wxMenu          menu;
+
+    AddRightClickMenuItems( menu );
     PopupMenu( &menu );
 
     passOnFocus();
@@ -246,12 +233,15 @@ void GERBER_LAYER_WIDGET::ReFill()
     }
 
     Thaw();
-
-    installRightLayerClickHandler();
 }
 
 //-----<LAYER_WIDGET callbacks>-------------------------------------------
 
+void GERBER_LAYER_WIDGET::OnLayerRightClick( wxMenu& aMenu )
+{
+    AddRightClickMenuItems( aMenu );
+}
+
 void GERBER_LAYER_WIDGET::OnLayerColorChange( int aLayer, COLOR4D aColor )
 {
     myframe->SetLayerColor( aLayer, aColor );
diff --git a/gerbview/class_gerbview_layer_widget.h b/gerbview/class_gerbview_layer_widget.h
index dcac8a781..3ef8870bf 100644
--- a/gerbview/class_gerbview_layer_widget.h
+++ b/gerbview/class_gerbview_layer_widget.h
@@ -33,18 +33,6 @@
 
 #include <layer_widget.h>
 
-// popup menu ids. in layer manager
-enum LAYER_MANAGER
-{
-    ID_LAYER_MANAGER_START = wxID_HIGHEST+1,
-    ID_SHOW_ALL_LAYERS = ID_LAYER_MANAGER_START,
-    ID_SHOW_NO_LAYERS,
-    ID_SHOW_NO_LAYERS_BUT_ACTIVE,
-    ID_ALWAYS_SHOW_NO_LAYERS_BUT_ACTIVE,
-    ID_SORT_GBR_LAYERS,
-    ID_LAYER_MANAGER_END = ID_SORT_GBR_LAYERS,
-};
-
 /**
  * Class GERBER_LAYER_WIDGET
  * is here to implement the abtract functions of LAYER_WIDGET so they
@@ -100,6 +88,7 @@ public:
     void ReFillRender();
 
     //-----<implement LAYER_WIDGET abstract callback functions>-----------
+    void OnLayerRightClick( wxMenu& aMenu ) override;
     void OnLayerColorChange( int aLayer, COLOR4D aColor ) override;
     bool OnLayerSelect( int aLayer ) override;
     void OnLayerVisible( int aLayer, bool isVisible, bool isFinal ) override;
@@ -125,6 +114,26 @@ public:
     bool OnLayerSelected();     // postprocess after an active layer selection
                                 // ensure active layer visible if
                                 // m_alwaysShowActiveCopperLayer is true;
+
+    /**
+     * Function addRightClickMenuItems
+     * add menu items to a menu that should be shown when right-clicking
+     * the Gerber layer widget.
+     */
+    void AddRightClickMenuItems( wxMenu& menu );
+
+protected:
+    // popup menu ids. in layer manager
+    enum LAYER_MANAGER
+    {
+        ID_LAYER_MANAGER_START = LAYER_WIDGET::ID_LAST_VALUE,
+        ID_SHOW_ALL_LAYERS = ID_LAYER_MANAGER_START,
+        ID_SHOW_NO_LAYERS,
+        ID_SHOW_NO_LAYERS_BUT_ACTIVE,
+        ID_ALWAYS_SHOW_NO_LAYERS_BUT_ACTIVE,
+        ID_SORT_GBR_LAYERS,
+        ID_LAYER_MANAGER_END = ID_SORT_GBR_LAYERS,
+    };
 };
 
 #endif  // _CLASS_GERBER_LAYER_WIDGET_H_

--------------2.11.0 (Apple Git-81)--


