You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

134 lines
4.9 KiB

  1. /**
  2. * @file pagelayout_editor/onrightclick.cpp
  3. * @brief functions called on rigth click mouse event
  4. */
  5. /*
  6. * This program source code file is part of KiCad, a free EDA CAD application.
  7. *
  8. * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
  9. * Copyright (C) 2013 CERN
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License
  13. * as published by the Free Software Foundation; either version 2
  14. * of the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, you may find one here:
  23. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  24. * or you may search the http://www.gnu.org website for the version 2 license,
  25. * or you may write to the Free Software Foundation, Inc.,
  26. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  27. */
  28. #include <fctsys.h>
  29. #include <class_drawpanel.h>
  30. #include <pl_editor_id.h>
  31. #include <pl_editor_frame.h>
  32. #include <design_tree_frame.h>
  33. #include <properties_frame.h>
  34. #include <menus_helpers.h>
  35. #include <worksheet_shape_builder.h>
  36. #include <class_worksheet_dataitem.h>
  37. #include <hotkeys.h>
  38. // Helper function to add menuitems relative to items creation
  39. void AddNewItemsCommand( wxMenu* aMainMenu )
  40. {
  41. AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_LINE, _( "Add Line" ),
  42. KiBitmap( add_dashed_line_xpm ) );
  43. AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_RECT, _( "Add Rectangle" ),
  44. KiBitmap( add_rectangle_xpm ) );
  45. AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_TEXT, _( "Add Text" ),
  46. KiBitmap( text_xpm ) );
  47. AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_BITMAP, _( "Add Bitmap" ),
  48. KiBitmap( image_xpm ) );
  49. AddMenuItem( aMainMenu, ID_POPUP_ITEM_APPEND_PAGE_LAYOUT,
  50. _( "Append Existing Page Layout Design File" ),
  51. KiBitmap( pagelayout_load_xpm ) );
  52. }
  53. /* Prepare the right-click pullup menu.
  54. * The menu already has a list of zoom commands.
  55. */
  56. bool PL_EDITOR_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* aPopMenu )
  57. {
  58. bool busy = GetScreen()->GetCurItem() != NULL;
  59. wxString msg;
  60. // If the tool ID_ZOOM_SELECTION is currently in use, add a
  61. if( GetToolId() == ID_ZOOM_SELECTION && !busy )
  62. {
  63. AddMenuItem( aPopMenu, ID_NO_TOOL_SELECTED, _( "End Tool" ),
  64. KiBitmap( cursor_xpm ) );
  65. aPopMenu->AppendSeparator();
  66. }
  67. if( ! busy ) // No item currently edited
  68. {
  69. WORKSHEET_DATAITEM* old_item = m_treePagelayout->GetPageLayoutSelectedItem();
  70. WORKSHEET_DATAITEM* item = Locate( aPosition );
  71. if( item && old_item != item )
  72. {
  73. m_treePagelayout->SelectCell( item );
  74. m_canvas->Refresh();
  75. }
  76. // Add menus to edit and delete the item
  77. if( item )
  78. {
  79. if( (item->GetFlags() & LOCATE_STARTPOINT) )
  80. {
  81. msg = AddHotkeyName( _( "Move Start Point" ), PlEditorHokeysDescr,
  82. HK_MOVE_START_POINT );
  83. AddMenuItem( aPopMenu, ID_POPUP_ITEM_MOVE_START_POINT, msg,
  84. KiBitmap( move_xpm ) );
  85. }
  86. if( (item->GetFlags() & LOCATE_ENDPOINT ) )
  87. {
  88. msg = AddHotkeyName( _( "Move End Point" ), PlEditorHokeysDescr,
  89. HK_MOVE_END_POINT );
  90. AddMenuItem( aPopMenu, ID_POPUP_ITEM_MOVE_END_POINT, msg,
  91. KiBitmap( move_xpm ) );
  92. }
  93. msg = AddHotkeyName( _( "Move Item" ), PlEditorHokeysDescr,
  94. HK_MOVE_ITEM );
  95. AddMenuItem( aPopMenu, ID_POPUP_ITEM_MOVE, msg,
  96. KiBitmap( move_xpm ) );
  97. aPopMenu->AppendSeparator();
  98. msg = AddHotkeyName( _( "Delete" ), PlEditorHokeysDescr,
  99. HK_DELETE_ITEM );
  100. AddMenuItem( aPopMenu, ID_POPUP_ITEM_DELETE, msg, KiBitmap( delete_xpm ) );
  101. aPopMenu->AppendSeparator();
  102. }
  103. }
  104. else // An item is currently in edit
  105. {
  106. msg = AddHotkeyName( _( "Place Item" ), PlEditorHokeysDescr,
  107. HK_PLACE_ITEM );
  108. AddMenuItem( aPopMenu, ID_POPUP_ITEM_PLACE, msg,
  109. KiBitmap( move_xpm ) );
  110. AddMenuItem( aPopMenu, ID_POPUP_ITEM_PLACE_CANCEL, _( "Cancel" ),
  111. KiBitmap( cancel_xpm ) );
  112. aPopMenu->AppendSeparator();
  113. }
  114. if( ! busy )
  115. {
  116. AddNewItemsCommand( aPopMenu );
  117. aPopMenu->AppendSeparator();
  118. }
  119. return true;
  120. }