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.

127 lines
4.6 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) 2013 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( add_text_xpm ) );
  47. AddMenuItem( aMainMenu, ID_POPUP_ITEM_APPEND_PAGE_LAYOUT,
  48. _( "Append Page Layout Descr File" ),
  49. KiBitmap( import_xpm ) );
  50. AddMenuItem( aMainMenu, ID_POPUP_ITEM_ADD_BITMAP,
  51. _( "Add Bitmap" ),
  52. KiBitmap( image_xpm ) );
  53. }
  54. /* Prepare the right-click pullup menu.
  55. * The menu already has a list of zoom commands.
  56. */
  57. bool PL_EDITOR_FRAME::OnRightClick( const wxPoint& aPosition, wxMenu* aPopMenu )
  58. {
  59. bool busy = GetScreen()->GetCurItem() != NULL;
  60. wxString msg;
  61. if( ! busy ) // No item currently edited
  62. {
  63. WORKSHEET_DATAITEM* old_item = m_treePagelayout->GetPageLayoutSelectedItem();
  64. WORKSHEET_DATAITEM* item = Locate( aPosition );
  65. if( item && old_item != item )
  66. {
  67. m_treePagelayout->SelectCell( item );
  68. m_canvas->Refresh();
  69. }
  70. // Add menus to edit and delete the item
  71. if( item )
  72. {
  73. if( (item->GetFlags() & LOCATE_STARTPOINT) )
  74. {
  75. msg = AddHotkeyName( _( "Move Start Point" ), PlEditorHokeysDescr,
  76. HK_MOVE_START_POINT );
  77. AddMenuItem( aPopMenu, ID_POPUP_ITEM_MOVE_START_POINT, msg,
  78. KiBitmap( move_xpm ) );
  79. }
  80. if( (item->GetFlags() & LOCATE_ENDPOINT ) )
  81. {
  82. msg = AddHotkeyName( _( "Move End Point" ), PlEditorHokeysDescr,
  83. HK_MOVE_END_POINT );
  84. AddMenuItem( aPopMenu, ID_POPUP_ITEM_MOVE_END_POINT, msg,
  85. KiBitmap( move_xpm ) );
  86. }
  87. msg = AddHotkeyName( _( "Move Item" ), PlEditorHokeysDescr,
  88. HK_MOVE_ITEM );
  89. AddMenuItem( aPopMenu, ID_POPUP_ITEM_MOVE, msg,
  90. KiBitmap( move_xpm ) );
  91. aPopMenu->AppendSeparator();
  92. msg = AddHotkeyName( _( "Delete" ), PlEditorHokeysDescr,
  93. HK_DELETE_ITEM );
  94. AddMenuItem( aPopMenu, ID_POPUP_ITEM_DELETE, msg, KiBitmap( delete_xpm ) );
  95. aPopMenu->AppendSeparator();
  96. }
  97. }
  98. else // An item is currently in edit
  99. {
  100. msg = AddHotkeyName( _( "Place Item" ), PlEditorHokeysDescr,
  101. HK_PLACE_ITEM );
  102. AddMenuItem( aPopMenu, ID_POPUP_ITEM_PLACE, msg,
  103. KiBitmap( move_xpm ) );
  104. AddMenuItem( aPopMenu, ID_POPUP_ITEM_PLACE_CANCEL, _( "Cancel" ),
  105. KiBitmap( cancel_xpm ) );
  106. aPopMenu->AppendSeparator();
  107. }
  108. if( ! busy )
  109. {
  110. AddNewItemsCommand( aPopMenu );
  111. aPopMenu->AppendSeparator();
  112. }
  113. return true;
  114. }