Implement OnLayerRightClick for Gerber layer widget

This commit is contained in:
Seppe Stas 2017-09-22 12:36:47 +02:00 committed by Maciej Suminski
parent d7b143f6f0
commit e46fdb0115
2 changed files with 36 additions and 37 deletions

View File

@ -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()
void GERBER_LAYER_WIDGET::AddRightClickMenuItems( wxMenu& menu )
{
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 )
{
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 );

View File

@ -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_