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.

1427 lines
42 KiB

4 years ago
4 years ago
4 years ago
3 years ago
Modular-Kicad milestone B), major portions: *) Rework the set language support, simplify it by using KIWAY. Now any major frame with a "change language" menu can change the language for all KIWAY_PLAYERs in the whole KIWAY. Multiple KIWAYs are not supported yet. *) Simplify "modal wxFrame" support, and add that support exclusively to KIWAY_PLAYER where it is inherited by all derivatives. The function KIWAY_PLAYER::ShowModal() is in the vtable and so is cross module capable. *) Remove the requirements and assumptions that the wxFrame hierarchy always had PCB_EDIT_FRAME and SCH_EDIT_FRAME as immediate parents of their viewers and editors. This is no longer the case, nor required. *) Use KIWAY::Player() everywhere to make KIWAY_PLAYERs, this registers the KIWAY_PLAYER within the KIWAY and makes it very easy to find an open frame quickly. It also gives control to the KIWAY as to frame hierarchical relationships. *) Change single_top to use the KIWAY for loading a KIFACE and instantiating the single KIWAY_PLAYER, see bullet immediately above. *) Add KIWAY::OnKiwayEnd() and call it from PGM_BASE at program termination, this gives the KIFACEs a chance to save their final configuration dope to disk. *) Add dedicated FRAME_T's for the modal frames, so m_Ident can be tested and these modal frames are distinctly different than their non-modal equivalents. KIWAY_PLAYER::IsModal() is !not! a valid test during the wxFrame's constructor, so this is another important reason for having a dedicated FRAME_T for each modal wxFrame. On balance, more lines were deleted than were added to achieve all this.
12 years ago
5 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
4 years ago
4 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
4 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
4 years ago
* KIWAY Milestone A): Make major modules into DLL/DSOs. ! The initial testing of this commit should be done using a Debug build so that all the wxASSERT()s are enabled. Also, be sure and keep enabled the USE_KIWAY_DLLs option. The tree won't likely build without it. Turning it off is senseless anyways. If you want stable code, go back to a prior version, the one tagged with "stable". * Relocate all functionality out of the wxApp derivative into more finely targeted purposes: a) DLL/DSO specific b) PROJECT specific c) EXE or process specific d) configuration file specific data e) configuration file manipulations functions. All of this functionality was blended into an extremely large wxApp derivative and that was incompatible with the desire to support multiple concurrently loaded DLL/DSO's ("KIFACE")s and multiple concurrently open projects. An amazing amount of organization come from simply sorting each bit of functionality into the proper box. * Switch to wxConfigBase from wxConfig everywhere except instantiation. * Add classes KIWAY, KIFACE, KIFACE_I, SEARCH_STACK, PGM_BASE, PGM_KICAD, PGM_SINGLE_TOP, * Remove "Return" prefix on many function names. * Remove obvious comments from CMakeLists.txt files, and from else() and endif()s. * Fix building boost for use in a DSO on linux. * Remove some of the assumptions in the CMakeLists.txt files that windows had to be the host platform when building windows binaries. * Reduce the number of wxStrings being constructed at program load time via static construction. * Pass wxConfigBase* to all SaveSettings() and LoadSettings() functions so that these functions are useful even when the wxConfigBase comes from another source, as is the case in the KICAD_MANAGER_FRAME. * Move the setting of the KIPRJMOD environment variable into class PROJECT, so that it can be moved into a project variable soon, and out of FP_LIB_TABLE. * Add the KIWAY_PLAYER which is associated with a particular PROJECT, and all its child wxFrames and wxDialogs now have a Kiway() member function which returns a KIWAY& that that window tree branch is in support of. This is like wxWindows DNA in that child windows get this member with proper value at time of construction. * Anticipate some of the needs for milestones B) and C) and make code adjustments now in an effort to reduce work in those milestones. * No testing has been done for python scripting, since milestone C) has that being largely reworked and re-thought-out.
12 years ago
3 years ago
4 years ago
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2017 Jean-Pierre Charras, jp.charras at wanadoo.fr
  5. * Copyright (C) 2013 Wayne Stambaugh <stambaughw@gmail.com>
  6. * Copyright (C) 1992-2022 KiCad Developers, see AUTHORS.txt for contributors.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License
  10. * as published by the Free Software Foundation; either version 2
  11. * of the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, you may find one here:
  20. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  21. * or you may search the http://www.gnu.org website for the version 2 license,
  22. * or you may write to the Free Software Foundation, Inc.,
  23. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  24. */
  25. #include <bitmaps.h>
  26. #include <bitmap_store.h>
  27. #include <dialog_shim.h>
  28. #include <dialogs/panel_common_settings.h>
  29. #include <dialogs/panel_mouse_settings.h>
  30. #include <dialogs/panel_data_collection.h>
  31. #include <eda_dde.h>
  32. #include <filehistory.h>
  33. #include <id.h>
  34. #include <kiface_base.h>
  35. #include <menus_helpers.h>
  36. #include <hotkeys_basic.h>
  37. #include <panel_hotkeys_editor.h>
  38. #include <paths.h>
  39. #include <confirm.h>
  40. #include <panel_pcm_settings.h>
  41. #include <pgm_base.h>
  42. #include <settings/app_settings.h>
  43. #include <settings/common_settings.h>
  44. #include <settings/settings_manager.h>
  45. #include <project/project_local_settings.h>
  46. #include <tool/action_manager.h>
  47. #include <tool/action_menu.h>
  48. #include <tool/action_toolbar.h>
  49. #include <tool/actions.h>
  50. #include <tool/common_control.h>
  51. #include <tool/tool_manager.h>
  52. #include <tool/tool_dispatcher.h>
  53. #include <trace_helpers.h>
  54. #include <widgets/paged_dialog.h>
  55. #include <widgets/infobar.h>
  56. #include <widgets/wx_aui_art_providers.h>
  57. #include <wx/app.h>
  58. #include <wx/config.h>
  59. #include <wx/display.h>
  60. #include <wx/stdpaths.h>
  61. #include <wx/string.h>
  62. #include <wx/treebook.h>
  63. #include <kiplatform/app.h>
  64. #include <kiplatform/ui.h>
  65. #include <functional>
  66. #include <kiface_ids.h>
  67. wxDEFINE_EVENT( UNITS_CHANGED, wxCommandEvent );
  68. // Minimum window size
  69. static const wxSize minSize( FRAME_T aFrameType )
  70. {
  71. switch( aFrameType )
  72. {
  73. case KICAD_MAIN_FRAME_T:
  74. return wxSize( 406, 354 );
  75. default:
  76. return wxSize( 500, 400 );
  77. }
  78. }
  79. static const wxSize defaultSize( FRAME_T aFrameType )
  80. {
  81. switch( aFrameType )
  82. {
  83. case KICAD_MAIN_FRAME_T:
  84. return wxSize( 850, 540 );
  85. default:
  86. return wxSize( 1280, 720 );
  87. }
  88. }
  89. BEGIN_EVENT_TABLE( EDA_BASE_FRAME, wxFrame )
  90. EVT_MENU( wxID_ABOUT, EDA_BASE_FRAME::OnKicadAbout )
  91. EVT_MENU( wxID_PREFERENCES, EDA_BASE_FRAME::OnPreferences )
  92. EVT_CHAR_HOOK( EDA_BASE_FRAME::OnCharHook )
  93. EVT_MENU_OPEN( EDA_BASE_FRAME::OnMenuEvent )
  94. EVT_MENU_CLOSE( EDA_BASE_FRAME::OnMenuEvent )
  95. EVT_MENU_HIGHLIGHT_ALL( EDA_BASE_FRAME::OnMenuEvent )
  96. EVT_MOVE( EDA_BASE_FRAME::OnMove )
  97. EVT_SIZE( EDA_BASE_FRAME::OnSize )
  98. EVT_MAXIMIZE( EDA_BASE_FRAME::OnMaximize )
  99. EVT_SYS_COLOUR_CHANGED( EDA_BASE_FRAME::onSystemColorChange )
  100. EVT_ICONIZE( EDA_BASE_FRAME::onIconize )
  101. END_EVENT_TABLE()
  102. void EDA_BASE_FRAME::commonInit( FRAME_T aFrameType )
  103. {
  104. m_ident = aFrameType;
  105. m_maximizeByDefault = false;
  106. m_infoBar = nullptr;
  107. m_settingsManager = nullptr;
  108. m_fileHistory = nullptr;
  109. m_supportsAutoSave = false;
  110. m_autoSavePending = false;
  111. m_undoRedoCountMax = DEFAULT_MAX_UNDO_ITEMS;
  112. m_isClosing = false;
  113. m_isNonUserClose = false;
  114. m_autoSaveTimer = new wxTimer( this, ID_AUTO_SAVE_TIMER );
  115. m_autoSaveRequired = false;
  116. m_mruPath = PATHS::GetDefaultUserProjectsPath();
  117. m_frameSize = defaultSize( aFrameType );
  118. m_displayIndex = -1;
  119. m_auimgr.SetArtProvider( new WX_AUI_DOCK_ART() );
  120. m_settingsManager = &Pgm().GetSettingsManager();
  121. // Set a reasonable minimal size for the frame
  122. SetSizeHints( minSize( aFrameType ).x, minSize( aFrameType ).y, -1, -1, -1, -1 );
  123. // Store dimensions of the user area of the main window.
  124. GetClientSize( &m_frameSize.x, &m_frameSize.y );
  125. Connect( ID_AUTO_SAVE_TIMER, wxEVT_TIMER,
  126. wxTimerEventHandler( EDA_BASE_FRAME::onAutoSaveTimer ) );
  127. // hook wxEVT_CLOSE_WINDOW so we can call SaveSettings(). This function seems
  128. // to be called before any other hook for wxCloseEvent, which is necessary.
  129. Connect( wxEVT_CLOSE_WINDOW, wxCloseEventHandler( EDA_BASE_FRAME::windowClosing ) );
  130. initExitKey();
  131. }
  132. EDA_BASE_FRAME::EDA_BASE_FRAME( wxWindow* aParent, FRAME_T aFrameType, const wxString& aTitle,
  133. const wxPoint& aPos, const wxSize& aSize, long aStyle,
  134. const wxString& aFrameName, KIWAY* aKiway,
  135. const EDA_IU_SCALE& aIuScale ) :
  136. wxFrame( aParent, wxID_ANY, aTitle, aPos, aSize, aStyle, aFrameName ),
  137. TOOLS_HOLDER(),
  138. KIWAY_HOLDER( aKiway, KIWAY_HOLDER::FRAME ),
  139. UNITS_PROVIDER( aIuScale, EDA_UNITS::MILLIMETRES )
  140. {
  141. commonInit( aFrameType );
  142. }
  143. wxWindow* EDA_BASE_FRAME::findQuasiModalDialog()
  144. {
  145. for( wxWindow* iter : GetChildren() )
  146. {
  147. DIALOG_SHIM* dlg = dynamic_cast<DIALOG_SHIM*>( iter );
  148. if( dlg && dlg->IsQuasiModal() )
  149. return dlg;
  150. }
  151. // FIXME: CvPcb is currently implemented on top of KIWAY_PLAYER rather than DIALOG_SHIM,
  152. // so we have to look for it separately.
  153. if( m_ident == FRAME_SCH )
  154. {
  155. wxWindow* cvpcb = wxWindow::FindWindowByName( "CvpcbFrame" );
  156. if( cvpcb )
  157. return cvpcb;
  158. }
  159. return nullptr;
  160. }
  161. void EDA_BASE_FRAME::windowClosing( wxCloseEvent& event )
  162. {
  163. // Don't allow closing when a quasi-modal is open.
  164. wxWindow* quasiModal = findQuasiModalDialog();
  165. if( quasiModal )
  166. {
  167. // Raise and notify; don't give the user a warning regarding "quasi-modal dialogs"
  168. // when they have no idea what those are.
  169. quasiModal->Raise();
  170. wxBell();
  171. if( event.CanVeto() )
  172. event.Veto();
  173. return;
  174. }
  175. if( event.GetId() == wxEVT_QUERY_END_SESSION
  176. || event.GetId() == wxEVT_END_SESSION )
  177. {
  178. // End session means the OS is going to terminate us
  179. m_isNonUserClose = true;
  180. }
  181. if( canCloseWindow( event ) )
  182. {
  183. m_isClosing = true;
  184. APP_SETTINGS_BASE* cfg = config();
  185. if( cfg )
  186. SaveSettings( cfg ); // virtual, wxFrame specific
  187. doCloseWindow();
  188. // Destroy (safe delete frame) this frame only in non modal mode.
  189. // In modal mode, the caller will call Destroy().
  190. if( !IsModal() )
  191. Destroy();
  192. }
  193. else
  194. {
  195. if( event.CanVeto() )
  196. event.Veto();
  197. }
  198. }
  199. EDA_BASE_FRAME::~EDA_BASE_FRAME()
  200. {
  201. delete m_autoSaveTimer;
  202. delete m_fileHistory;
  203. ClearUndoRedoList();
  204. SocketCleanup();
  205. KIPLATFORM::APP::RemoveShutdownBlockReason( this );
  206. }
  207. bool EDA_BASE_FRAME::ProcessEvent( wxEvent& aEvent )
  208. {
  209. #ifdef __WXMAC__
  210. // Apple in its infinite wisdom will raise a disabled window before even passing
  211. // us the event, so we have no way to stop it. Instead, we have to catch an
  212. // improperly ordered disabled window and quasi-modal dialog here and reorder
  213. // them.
  214. if( !IsEnabled() && IsActive() )
  215. {
  216. wxWindow* dlg = findQuasiModalDialog();
  217. if( dlg )
  218. dlg->Raise();
  219. }
  220. #endif
  221. if( !wxFrame::ProcessEvent( aEvent ) )
  222. return false;
  223. if( Pgm().m_Quitting )
  224. return true;
  225. if( !m_isClosing && m_supportsAutoSave && IsShown() && IsActive()
  226. && m_autoSavePending != isAutoSaveRequired()
  227. && GetAutoSaveInterval() > 0 )
  228. {
  229. if( !m_autoSavePending )
  230. {
  231. wxLogTrace( traceAutoSave, wxT( "Starting auto save timer." ) );
  232. m_autoSaveTimer->Start( GetAutoSaveInterval() * 1000, wxTIMER_ONE_SHOT );
  233. m_autoSavePending = true;
  234. }
  235. else if( m_autoSaveTimer->IsRunning() )
  236. {
  237. wxLogTrace( traceAutoSave, wxT( "Stopping auto save timer." ) );
  238. m_autoSaveTimer->Stop();
  239. m_autoSavePending = false;
  240. }
  241. }
  242. return true;
  243. }
  244. int EDA_BASE_FRAME::GetAutoSaveInterval() const
  245. {
  246. return Pgm().GetCommonSettings()->m_System.autosave_interval;
  247. }
  248. void EDA_BASE_FRAME::onAutoSaveTimer( wxTimerEvent& aEvent )
  249. {
  250. // Don't stomp on someone else's timer event.
  251. if( aEvent.GetId() != ID_AUTO_SAVE_TIMER )
  252. {
  253. aEvent.Skip();
  254. return;
  255. }
  256. if( !doAutoSave() )
  257. m_autoSaveTimer->Start( GetAutoSaveInterval() * 1000, wxTIMER_ONE_SHOT );
  258. }
  259. bool EDA_BASE_FRAME::doAutoSave()
  260. {
  261. wxCHECK_MSG( false, true, wxT( "Auto save timer function not overridden. Bad programmer!" ) );
  262. }
  263. void EDA_BASE_FRAME::OnCharHook( wxKeyEvent& aKeyEvent )
  264. {
  265. wxLogTrace( kicadTraceKeyEvent, "EDA_BASE_FRAME::OnCharHook %s", dump( aKeyEvent ) );
  266. // Key events can be filtered here.
  267. // Currently no filtering is made.
  268. aKeyEvent.Skip();
  269. }
  270. void EDA_BASE_FRAME::OnMenuEvent( wxMenuEvent& aEvent )
  271. {
  272. if( !m_toolDispatcher )
  273. aEvent.Skip();
  274. else
  275. m_toolDispatcher->DispatchWxEvent( aEvent );
  276. }
  277. void EDA_BASE_FRAME::RegisterUIUpdateHandler( int aID, const ACTION_CONDITIONS& aConditions )
  278. {
  279. UIUpdateHandler evtFunc = std::bind( &EDA_BASE_FRAME::HandleUpdateUIEvent,
  280. std::placeholders::_1,
  281. this,
  282. aConditions );
  283. m_uiUpdateMap[aID] = evtFunc;
  284. Bind( wxEVT_UPDATE_UI, evtFunc, aID );
  285. }
  286. void EDA_BASE_FRAME::UnregisterUIUpdateHandler( int aID )
  287. {
  288. const auto it = m_uiUpdateMap.find( aID );
  289. if( it == m_uiUpdateMap.end() )
  290. return;
  291. Unbind( wxEVT_UPDATE_UI, it->second, aID );
  292. }
  293. void EDA_BASE_FRAME::HandleUpdateUIEvent( wxUpdateUIEvent& aEvent, EDA_BASE_FRAME* aFrame,
  294. ACTION_CONDITIONS aCond )
  295. {
  296. bool checkRes = false;
  297. bool enableRes = true;
  298. bool showRes = true;
  299. bool isCut = aEvent.GetId() == ACTIONS::cut.GetUIId();
  300. bool isCopy = aEvent.GetId() == ACTIONS::copy.GetUIId();
  301. bool isPaste = aEvent.GetId() == ACTIONS::paste.GetUIId();
  302. SELECTION& selection = aFrame->GetCurrentSelection();
  303. try
  304. {
  305. checkRes = aCond.checkCondition( selection );
  306. enableRes = aCond.enableCondition( selection );
  307. showRes = aCond.showCondition( selection );
  308. }
  309. catch( std::exception& )
  310. {
  311. // Something broke with the conditions, just skip the event.
  312. aEvent.Skip();
  313. return;
  314. }
  315. if( isCut || isCopy || isPaste )
  316. {
  317. wxWindow* focus = wxWindow::FindFocus();
  318. wxTextEntry* textEntry = dynamic_cast<wxTextEntry*>( focus );
  319. if( textEntry && isCut && textEntry->CanCut() )
  320. enableRes = true;
  321. else if( textEntry && isCopy && textEntry->CanCopy() )
  322. enableRes = true;
  323. else if( textEntry && isPaste && textEntry->CanPaste() )
  324. enableRes = true;
  325. }
  326. aEvent.Enable( enableRes );
  327. aEvent.Show( showRes );
  328. // wxWidgets 3.1.5+ includes a field in the event that says if the event supports being
  329. // checked, since wxMenuItems don't want to be checked unless they actually are checkable
  330. #if wxCHECK_VERSION( 3, 1, 5 )
  331. if( aEvent.IsCheckable() )
  332. aEvent.Check( checkRes );
  333. #else
  334. bool canCheck = true;
  335. // wxMenuItems don't want to be checked unless they actually are checkable, so we have to
  336. // check to see if they can be and can't just universally apply a check in this event.
  337. if( wxMenu* menu = dynamic_cast<wxMenu*>( aEvent.GetEventObject() ) )
  338. canCheck = menu->FindItem( aEvent.GetId() )->IsCheckable();
  339. if( canCheck )
  340. aEvent.Check( checkRes );
  341. #endif
  342. }
  343. void EDA_BASE_FRAME::setupUIConditions()
  344. {
  345. // Setup the conditions to check a language menu item
  346. auto isCurrentLang =
  347. [] ( const SELECTION& aSel, int aLangIdentifier )
  348. {
  349. return Pgm().GetSelectedLanguageIdentifier() == aLangIdentifier;
  350. };
  351. for( unsigned ii = 0; LanguagesList[ii].m_KI_Lang_Identifier != 0; ii++ )
  352. {
  353. ACTION_CONDITIONS cond;
  354. cond.Check( std::bind( isCurrentLang, std::placeholders::_1,
  355. LanguagesList[ii].m_WX_Lang_Identifier ) );
  356. RegisterUIUpdateHandler( LanguagesList[ii].m_KI_Lang_Identifier, cond );
  357. }
  358. }
  359. void EDA_BASE_FRAME::ReCreateMenuBar()
  360. {
  361. }
  362. void EDA_BASE_FRAME::AddStandardHelpMenu( wxMenuBar* aMenuBar )
  363. {
  364. COMMON_CONTROL* commonControl = m_toolManager->GetTool<COMMON_CONTROL>();
  365. ACTION_MENU* helpMenu = new ACTION_MENU( false, commonControl );
  366. helpMenu->Add( ACTIONS::help );
  367. helpMenu->Add( ACTIONS::gettingStarted );
  368. helpMenu->Add( ACTIONS::listHotKeys );
  369. helpMenu->Add( ACTIONS::getInvolved );
  370. helpMenu->Add( ACTIONS::donate );
  371. helpMenu->Add( ACTIONS::reportBug );
  372. helpMenu->AppendSeparator();
  373. helpMenu->Add( _( "&About KiCad" ), "", wxID_ABOUT, BITMAPS::about );
  374. // Trailing space keeps OSX from hijacking our menu (and disabling everything in it).
  375. aMenuBar->Append( helpMenu, _( "&Help" ) + wxS( " " ) );
  376. }
  377. void EDA_BASE_FRAME::ShowChangedLanguage()
  378. {
  379. TOOLS_HOLDER::ShowChangedLanguage();
  380. if( GetMenuBar() )
  381. {
  382. ReCreateMenuBar();
  383. GetMenuBar()->Refresh();
  384. }
  385. }
  386. void EDA_BASE_FRAME::CommonSettingsChanged( bool aEnvVarsChanged, bool aTextVarsChanged )
  387. {
  388. TOOLS_HOLDER::CommonSettingsChanged( aEnvVarsChanged, aTextVarsChanged );
  389. COMMON_SETTINGS* settings = Pgm().GetCommonSettings();
  390. if( m_fileHistory )
  391. {
  392. int historySize = settings->m_System.file_history_size;
  393. m_fileHistory->SetMaxFiles( (unsigned) std::max( 0, historySize ) );
  394. }
  395. GetBitmapStore()->ThemeChanged();
  396. ThemeChanged();
  397. if( GetMenuBar() )
  398. {
  399. // For icons in menus, icon scaling & hotkeys
  400. ReCreateMenuBar();
  401. GetMenuBar()->Refresh();
  402. }
  403. }
  404. void EDA_BASE_FRAME::ThemeChanged()
  405. {
  406. ClearScaledBitmapCache();
  407. // Update all the toolbars to have new icons
  408. wxAuiPaneInfoArray panes = m_auimgr.GetAllPanes();
  409. for( size_t i = 0; i < panes.GetCount(); ++i )
  410. {
  411. if( ACTION_TOOLBAR* toolbar = dynamic_cast<ACTION_TOOLBAR*>( panes[i].window ) )
  412. toolbar->RefreshBitmaps();
  413. }
  414. }
  415. void EDA_BASE_FRAME::OnSize( wxSizeEvent& aEvent )
  416. {
  417. #ifdef __WXMAC__
  418. int currentDisplay = wxDisplay::GetFromWindow( this );
  419. if( m_displayIndex >= 0 && currentDisplay >= 0 && currentDisplay != m_displayIndex )
  420. {
  421. wxLogTrace( traceDisplayLocation, "OnSize: current display changed %d to %d",
  422. m_displayIndex, currentDisplay );
  423. m_displayIndex = currentDisplay;
  424. ensureWindowIsOnScreen();
  425. }
  426. #endif
  427. aEvent.Skip();
  428. }
  429. void EDA_BASE_FRAME::LoadWindowState( const wxString& aFileName )
  430. {
  431. if( !Pgm().GetCommonSettings()->m_Session.remember_open_files )
  432. return;
  433. const PROJECT_FILE_STATE* state = Prj().GetLocalSettings().GetFileState( aFileName );
  434. if( state != nullptr )
  435. {
  436. LoadWindowState( state->window );
  437. }
  438. }
  439. void EDA_BASE_FRAME::LoadWindowState( const WINDOW_STATE& aState )
  440. {
  441. bool wasDefault = false;
  442. m_framePos.x = aState.pos_x;
  443. m_framePos.y = aState.pos_y;
  444. m_frameSize.x = aState.size_x;
  445. m_frameSize.y = aState.size_y;
  446. wxLogTrace( traceDisplayLocation, "Config position (%d, %d) with size (%d, %d)",
  447. m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
  448. // Ensure minimum size is set if the stored config was zero-initialized
  449. if( m_frameSize.x < minSize( m_ident ).x || m_frameSize.y < minSize( m_ident ).y )
  450. {
  451. m_frameSize = defaultSize( m_ident );
  452. wasDefault = true;
  453. wxLogTrace( traceDisplayLocation, "Using minimum size (%d, %d)",
  454. m_frameSize.x, m_frameSize.y );
  455. }
  456. wxLogTrace( traceDisplayLocation, "Number of displays: %d", wxDisplay::GetCount() );
  457. if( aState.display >= wxDisplay::GetCount() )
  458. {
  459. wxLogTrace( traceDisplayLocation, "Previous display not found" );
  460. // If it isn't attached, use the first display
  461. // Warning wxDisplay has 2 ctor variants. the parameter needs a type:
  462. const unsigned int index = 0;
  463. wxDisplay display( index );
  464. wxRect clientSize = display.GetGeometry();
  465. m_framePos = wxDefaultPosition;
  466. // Ensure the window fits on the display, since the other one could have been larger
  467. if( m_frameSize.x > clientSize.width )
  468. m_frameSize.x = clientSize.width;
  469. if( m_frameSize.y > clientSize.height )
  470. m_frameSize.y = clientSize.height;
  471. }
  472. else
  473. {
  474. wxPoint upperRight( m_framePos.x + m_frameSize.x, m_framePos.y );
  475. wxPoint upperLeft( m_framePos.x, m_framePos.y );
  476. wxDisplay display( aState.display );
  477. wxRect clientSize = display.GetClientArea();
  478. int yLimTop = clientSize.y;
  479. int yLimBottom = clientSize.y + clientSize.height;
  480. int xLimLeft = clientSize.x;
  481. int xLimRight = clientSize.x + clientSize.width;
  482. if( upperLeft.x > xLimRight || // Upper left corner too close to right edge of screen
  483. upperRight.x < xLimLeft || // Upper right corner too close to left edge of screen
  484. upperLeft.y < yLimTop || // Upper corner too close to the bottom of the screen
  485. upperLeft.y > yLimBottom )
  486. {
  487. m_framePos = wxDefaultPosition;
  488. wxLogTrace( traceDisplayLocation, "Resetting to default position" );
  489. }
  490. }
  491. wxLogTrace( traceDisplayLocation, "Final window position (%d, %d) with size (%d, %d)",
  492. m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
  493. SetSize( m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
  494. // Center the window if we reset to default
  495. if( m_framePos.x == -1 )
  496. {
  497. wxLogTrace( traceDisplayLocation, "Centering window" );
  498. Center();
  499. m_framePos = GetPosition();
  500. }
  501. // Record the frame sizes in an un-maximized state
  502. m_normalFrameSize = m_frameSize;
  503. m_normalFramePos = m_framePos;
  504. // Maximize if we were maximized before
  505. if( aState.maximized || ( wasDefault && m_maximizeByDefault ) )
  506. {
  507. wxLogTrace( traceDisplayLocation, "Maximizing window" );
  508. Maximize();
  509. }
  510. m_displayIndex = wxDisplay::GetFromWindow( this );
  511. }
  512. void EDA_BASE_FRAME::ensureWindowIsOnScreen()
  513. {
  514. wxDisplay display( wxDisplay::GetFromWindow( this ) );
  515. wxRect clientSize = display.GetClientArea();
  516. wxPoint pos = GetPosition();
  517. wxSize size = GetWindowSize();
  518. wxLogTrace( traceDisplayLocation,
  519. "ensureWindowIsOnScreen: clientArea (%d, %d) w %d h %d", clientSize.x, clientSize.y,
  520. clientSize.width, clientSize.height );
  521. if( pos.y < clientSize.y )
  522. {
  523. wxLogTrace( traceDisplayLocation,
  524. "ensureWindowIsOnScreen: y pos %d below minimum, setting to %d", pos.y,
  525. clientSize.y );
  526. pos.y = clientSize.y;
  527. }
  528. if( pos.x < clientSize.x )
  529. {
  530. wxLogTrace( traceDisplayLocation,
  531. "ensureWindowIsOnScreen: x pos %d is off the client rect, setting to %d", pos.x,
  532. clientSize.x );
  533. pos.x = clientSize.x;
  534. }
  535. if( pos.x + size.x - clientSize.x > clientSize.width )
  536. {
  537. int newWidth = clientSize.width - ( pos.x - clientSize.x );
  538. wxLogTrace( traceDisplayLocation,
  539. "ensureWindowIsOnScreen: effective width %d above available %d, setting to %d",
  540. pos.x + size.x, clientSize.width, newWidth );
  541. size.x = newWidth;
  542. }
  543. if( pos.y + size.y - clientSize.y > clientSize.height )
  544. {
  545. int newHeight = clientSize.height - ( pos.y - clientSize.y );
  546. wxLogTrace( traceDisplayLocation,
  547. "ensureWindowIsOnScreen: effective height %d above available %d, setting to %d",
  548. pos.y + size.y, clientSize.height, newHeight );
  549. size.y = newHeight;
  550. }
  551. wxLogTrace( traceDisplayLocation, "Updating window position (%d, %d) with size (%d, %d)",
  552. pos.x, pos.y, size.x, size.y );
  553. SetSize( pos.x, pos.y, size.x, size.y );
  554. }
  555. void EDA_BASE_FRAME::LoadWindowSettings( const WINDOW_SETTINGS* aCfg )
  556. {
  557. LoadWindowState( aCfg->state );
  558. m_perspective = aCfg->perspective;
  559. m_mruPath = aCfg->mru_path;
  560. TOOLS_HOLDER::CommonSettingsChanged( false, false );
  561. }
  562. void EDA_BASE_FRAME::SaveWindowSettings( WINDOW_SETTINGS* aCfg )
  563. {
  564. if( IsIconized() )
  565. return;
  566. // If the window is maximized, we use the saved window size from before it was maximized
  567. if( IsMaximized() )
  568. {
  569. m_framePos = m_normalFramePos;
  570. m_frameSize = m_normalFrameSize;
  571. }
  572. else
  573. {
  574. m_frameSize = GetWindowSize();
  575. m_framePos = GetPosition();
  576. }
  577. aCfg->state.pos_x = m_framePos.x;
  578. aCfg->state.pos_y = m_framePos.y;
  579. aCfg->state.size_x = m_frameSize.x;
  580. aCfg->state.size_y = m_frameSize.y;
  581. aCfg->state.maximized = IsMaximized();
  582. aCfg->state.display = wxDisplay::GetFromWindow( this );
  583. wxLogTrace( traceDisplayLocation, "Saving window maximized: %s",
  584. IsMaximized() ? "true" : "false" );
  585. wxLogTrace( traceDisplayLocation, "Saving config position (%d, %d) with size (%d, %d)",
  586. m_framePos.x, m_framePos.y, m_frameSize.x, m_frameSize.y );
  587. // Once this is fully implemented, wxAuiManager will be used to maintain
  588. // the persistence of the main frame and all it's managed windows and
  589. // all of the legacy frame persistence position code can be removed.
  590. aCfg->perspective = m_auimgr.SavePerspective().ToStdString();
  591. aCfg->mru_path = m_mruPath;
  592. }
  593. void EDA_BASE_FRAME::LoadSettings( APP_SETTINGS_BASE* aCfg )
  594. {
  595. LoadWindowSettings( GetWindowSettings( aCfg ) );
  596. // Get file history size from common settings
  597. int fileHistorySize = Pgm().GetCommonSettings()->m_System.file_history_size;
  598. // Load the recently used files into the history menu
  599. m_fileHistory = new FILE_HISTORY( (unsigned) std::max( 0, fileHistorySize ),
  600. ID_FILE1, ID_FILE_LIST_CLEAR );
  601. m_fileHistory->Load( *aCfg );
  602. }
  603. void EDA_BASE_FRAME::SaveSettings( APP_SETTINGS_BASE* aCfg )
  604. {
  605. SaveWindowSettings( GetWindowSettings( aCfg ) );
  606. bool fileOpen = m_isClosing && m_isNonUserClose;
  607. wxString currentlyOpenedFile = GetCurrentFileName();
  608. if( Pgm().GetCommonSettings()->m_Session.remember_open_files && !currentlyOpenedFile.IsEmpty() )
  609. {
  610. wxFileName rfn( currentlyOpenedFile );
  611. rfn.MakeRelativeTo( Prj().GetProjectPath() );
  612. Prj().GetLocalSettings().SaveFileState( rfn.GetFullPath(), &aCfg->m_Window, fileOpen );
  613. }
  614. // Save the recently used files list
  615. if( m_fileHistory )
  616. {
  617. // Save the currently opened file in the file history
  618. if( !currentlyOpenedFile.IsEmpty() )
  619. UpdateFileHistory( currentlyOpenedFile );
  620. m_fileHistory->Save( *aCfg );
  621. }
  622. }
  623. WINDOW_SETTINGS* EDA_BASE_FRAME::GetWindowSettings( APP_SETTINGS_BASE* aCfg )
  624. {
  625. return &aCfg->m_Window;
  626. }
  627. APP_SETTINGS_BASE* EDA_BASE_FRAME::config() const
  628. {
  629. // KICAD_MANAGER_FRAME overrides this
  630. return Kiface().KifaceSettings();
  631. }
  632. const SEARCH_STACK& EDA_BASE_FRAME::sys_search()
  633. {
  634. return Kiface().KifaceSearch();
  635. }
  636. wxString EDA_BASE_FRAME::help_name()
  637. {
  638. return Kiface().GetHelpFileName();
  639. }
  640. void EDA_BASE_FRAME::PrintMsg( const wxString& text )
  641. {
  642. SetStatusText( text );
  643. }
  644. void EDA_BASE_FRAME::CreateInfoBar()
  645. {
  646. #if defined( __WXOSX_MAC__ )
  647. m_infoBar = new WX_INFOBAR( GetToolCanvas() );
  648. #else
  649. m_infoBar = new WX_INFOBAR( this, &m_auimgr );
  650. m_auimgr.AddPane( m_infoBar, EDA_PANE().InfoBar().Name( "InfoBar" ).Top().Layer(1) );
  651. #endif
  652. }
  653. void EDA_BASE_FRAME::FinishAUIInitialization()
  654. {
  655. #if defined( __WXOSX_MAC__ )
  656. m_auimgr.Update();
  657. #else
  658. // Call Update() to fix all pane default sizes, especially the "InfoBar" pane before
  659. // hiding it.
  660. m_auimgr.Update();
  661. // We don't want the infobar displayed right away
  662. m_auimgr.GetPane( "InfoBar" ).Hide();
  663. m_auimgr.Update();
  664. #endif
  665. }
  666. void EDA_BASE_FRAME::ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton,
  667. WX_INFOBAR::MESSAGE_TYPE aType )
  668. {
  669. m_infoBar->RemoveAllButtons();
  670. if( aShowCloseButton )
  671. m_infoBar->AddCloseButton();
  672. GetInfoBar()->ShowMessageFor( aErrorMsg, 8000, wxICON_ERROR, aType );
  673. }
  674. void EDA_BASE_FRAME::ShowInfoBarError( const wxString& aErrorMsg, bool aShowCloseButton,
  675. std::function<void(void)> aCallback )
  676. {
  677. m_infoBar->RemoveAllButtons();
  678. if( aShowCloseButton )
  679. m_infoBar->AddCloseButton();
  680. if( aCallback )
  681. m_infoBar->SetCallback( aCallback );
  682. GetInfoBar()->ShowMessageFor( aErrorMsg, 6000, wxICON_ERROR );
  683. }
  684. void EDA_BASE_FRAME::ShowInfoBarWarning( const wxString& aWarningMsg, bool aShowCloseButton )
  685. {
  686. m_infoBar->RemoveAllButtons();
  687. if( aShowCloseButton )
  688. m_infoBar->AddCloseButton();
  689. GetInfoBar()->ShowMessageFor( aWarningMsg, 6000, wxICON_WARNING );
  690. }
  691. void EDA_BASE_FRAME::ShowInfoBarMsg( const wxString& aMsg, bool aShowCloseButton )
  692. {
  693. m_infoBar->RemoveAllButtons();
  694. if( aShowCloseButton )
  695. m_infoBar->AddCloseButton();
  696. GetInfoBar()->ShowMessageFor( aMsg, 8000, wxICON_INFORMATION );
  697. }
  698. void EDA_BASE_FRAME::UpdateFileHistory( const wxString& FullFileName, FILE_HISTORY* aFileHistory )
  699. {
  700. if( !aFileHistory )
  701. aFileHistory = m_fileHistory;
  702. wxASSERT( aFileHistory );
  703. aFileHistory->AddFileToHistory( FullFileName );
  704. // Update the menubar to update the file history menu
  705. if( !m_isClosing && GetMenuBar() )
  706. {
  707. ReCreateMenuBar();
  708. GetMenuBar()->Refresh();
  709. }
  710. }
  711. wxString EDA_BASE_FRAME::GetFileFromHistory( int cmdId, const wxString& type,
  712. FILE_HISTORY* aFileHistory )
  713. {
  714. if( !aFileHistory )
  715. aFileHistory = m_fileHistory;
  716. wxASSERT( aFileHistory );
  717. int baseId = aFileHistory->GetBaseId();
  718. wxASSERT( cmdId >= baseId && cmdId < baseId + (int) aFileHistory->GetCount() );
  719. unsigned i = cmdId - baseId;
  720. if( i < aFileHistory->GetCount() )
  721. {
  722. wxString fn = aFileHistory->GetHistoryFile( i );
  723. if( wxFileName::FileExists( fn ) )
  724. {
  725. return fn;
  726. }
  727. else
  728. {
  729. DisplayErrorMessage( this, wxString::Format( _( "File '%s' was not found." ), fn ) );
  730. aFileHistory->RemoveFileFromHistory( i );
  731. }
  732. }
  733. // Update the menubar to update the file history menu
  734. if( GetMenuBar() )
  735. {
  736. ReCreateMenuBar();
  737. GetMenuBar()->Refresh();
  738. }
  739. return wxEmptyString;
  740. }
  741. void EDA_BASE_FRAME::ClearFileHistory( FILE_HISTORY* aFileHistory )
  742. {
  743. if( !aFileHistory )
  744. aFileHistory = m_fileHistory;
  745. wxASSERT( aFileHistory );
  746. aFileHistory->ClearFileHistory();
  747. // Update the menubar to update the file history menu
  748. if( GetMenuBar() )
  749. {
  750. ReCreateMenuBar();
  751. GetMenuBar()->Refresh();
  752. }
  753. }
  754. void EDA_BASE_FRAME::OnKicadAbout( wxCommandEvent& event )
  755. {
  756. void ShowAboutDialog( EDA_BASE_FRAME * aParent ); // See AboutDialog_main.cpp
  757. ShowAboutDialog( this );
  758. }
  759. void EDA_BASE_FRAME::OnPreferences( wxCommandEvent& event )
  760. {
  761. PAGED_DIALOG dlg( this, _( "Preferences" ), true );
  762. wxTreebook* book = dlg.GetTreebook();
  763. PANEL_HOTKEYS_EDITOR* hotkeysPanel = new PANEL_HOTKEYS_EDITOR( this, book, false );
  764. KIFACE* kiface = nullptr;
  765. std::vector<int> expand;
  766. Kiway().GetActions( hotkeysPanel->ActionsList() );
  767. book->AddPage( new PANEL_COMMON_SETTINGS( &dlg, book ), _( "Common" ) );
  768. book->AddPage( new PANEL_MOUSE_SETTINGS( &dlg, book ), _( "Mouse and Touchpad" ) );
  769. book->AddPage( hotkeysPanel, _( "Hotkeys" ) );
  770. #ifdef KICAD_USE_SENTRY
  771. book->AddPage( new PANEL_DATA_COLLECTION( &dlg, book ), _( "Data Collection" ) );
  772. #endif
  773. #define CREATE_PANEL( key ) kiface->CreateKiWindow( book, key, &Kiway() )
  774. // If a dll is not loaded, the loader will show an error message.
  775. try
  776. {
  777. kiface = Kiway().KiFACE( KIWAY::FACE_SCH );
  778. kiface->GetActions( hotkeysPanel->ActionsList() );
  779. if( GetFrameType() == FRAME_SCH_SYMBOL_EDITOR )
  780. expand.push_back( book->GetPageCount() );
  781. book->AddPage( new wxPanel( book ), _( "Symbol Editor" ) );
  782. book->AddSubPage( CREATE_PANEL( PANEL_SYM_DISP_OPTIONS ), _( "Display Options" ) );
  783. book->AddSubPage( CREATE_PANEL( PANEL_SYM_EDIT_OPTIONS ), _( "Editing Options" ) );
  784. book->AddSubPage( CREATE_PANEL( PANEL_SYM_COLORS ), _( "Colors" ) );
  785. if( GetFrameType() == FRAME_SCH )
  786. expand.push_back( book->GetPageCount() );
  787. book->AddPage( new wxPanel( book ), _( "Schematic Editor" ) );
  788. book->AddSubPage( CREATE_PANEL( PANEL_SCH_DISP_OPTIONS ), _( "Display Options" ) );
  789. book->AddSubPage( CREATE_PANEL( PANEL_SCH_EDIT_OPTIONS ), _( "Editing Options" ) );
  790. book->AddSubPage( CREATE_PANEL( PANEL_SCH_ANNO_OPTIONS ), _( "Annotation Options" ) );
  791. book->AddSubPage( CREATE_PANEL( PANEL_SCH_COLORS ), _( "Colors" ) );
  792. book->AddSubPage( CREATE_PANEL( PANEL_SCH_FIELD_NAME_TEMPLATES ),
  793. _( "Field Name Templates" ) );
  794. }
  795. catch( ... )
  796. {
  797. }
  798. try
  799. {
  800. kiface = Kiway().KiFACE( KIWAY::FACE_PCB );
  801. kiface->GetActions( hotkeysPanel->ActionsList() );
  802. if( GetFrameType() == FRAME_FOOTPRINT_EDITOR )
  803. expand.push_back( book->GetPageCount() );
  804. book->AddPage( new wxPanel( book ), _( "Footprint Editor" ) );
  805. book->AddSubPage( CREATE_PANEL( PANEL_FP_DISPLAY_OPTIONS ), _( "Display Options" ) );
  806. book->AddSubPage( CREATE_PANEL( PANEL_FP_EDIT_OPTIONS ), _( "Editing Options" ) );
  807. book->AddSubPage( CREATE_PANEL( PANEL_FP_COLORS ), _( "Colors" ) );
  808. book->AddSubPage( CREATE_PANEL( PANEL_FP_DEFAULT_VALUES ), _( "Default Values" ) );
  809. if( GetFrameType() == FRAME_PCB_EDITOR )
  810. expand.push_back( book->GetPageCount() );
  811. book->AddPage( new wxPanel( book ), _( "PCB Editor" ) );
  812. book->AddSubPage( CREATE_PANEL( PANEL_PCB_DISPLAY_OPTIONS ), _( "Display Options" ) );
  813. book->AddSubPage( CREATE_PANEL( PANEL_PCB_EDIT_OPTIONS ), _( "Editing Options" ) );
  814. book->AddSubPage( CREATE_PANEL( PANEL_PCB_COLORS ), _( "Colors" ) );
  815. book->AddSubPage( CREATE_PANEL( PANEL_PCB_ACTION_PLUGINS ), _( "Action Plugins" ) );
  816. book->AddSubPage( CREATE_PANEL( PANEL_PCB_ORIGINS_AXES ), _( "Origins & Axes" ) );
  817. if( GetFrameType() == FRAME_PCB_DISPLAY3D )
  818. expand.push_back( book->GetPageCount() );
  819. book->AddPage( new wxPanel( book ), _( "3D Viewer" ) );
  820. book->AddSubPage( CREATE_PANEL( PANEL_3DV_DISPLAY_OPTIONS ), _( "General" ) );
  821. book->AddSubPage( CREATE_PANEL( PANEL_3DV_OPENGL ), _( "Realtime Renderer" ) );
  822. book->AddSubPage( CREATE_PANEL( PANEL_3DV_RAYTRACING ), _( "Raytracing Renderer" ) );
  823. book->AddSubPage( CREATE_PANEL( PANEL_3DV_COLORS ), _( "Colors" ) );
  824. }
  825. catch( ... )
  826. {
  827. }
  828. try
  829. {
  830. kiface = Kiway().KiFACE( KIWAY::FACE_GERBVIEW );
  831. kiface->GetActions( hotkeysPanel->ActionsList() );
  832. if( GetFrameType() == FRAME_GERBER )
  833. expand.push_back( book->GetPageCount() );
  834. book->AddPage( new wxPanel( book ), _( "Gerber Viewer" ) );
  835. book->AddSubPage( CREATE_PANEL( PANEL_GBR_DISPLAY_OPTIONS ), _( "Display Options" ) );
  836. book->AddSubPage( CREATE_PANEL( PANEL_GBR_COLORS ), _( "Colors" ) );
  837. book->AddSubPage( CREATE_PANEL( PANEL_GBR_EXCELLON_OPTIONS ), _( "Excellon Options" ) );
  838. }
  839. catch( ... )
  840. {
  841. }
  842. try
  843. {
  844. kiface = Kiway().KiFACE( KIWAY::FACE_PL_EDITOR );
  845. kiface->GetActions( hotkeysPanel->ActionsList() );
  846. if( GetFrameType() == FRAME_PL_EDITOR )
  847. expand.push_back( book->GetPageCount() );
  848. book->AddPage( new wxPanel( book ), _( "Drawing Sheet Editor" ) );
  849. book->AddSubPage( CREATE_PANEL( PANEL_DS_DISPLAY_OPTIONS ), _( "Display Options" ) );
  850. book->AddSubPage( CREATE_PANEL( PANEL_DS_COLORS ), _( "Colors" ) );
  851. book->AddPage( new PANEL_PCM_SETTINGS( book ), _( "Plugin and Content Manager" ) );
  852. }
  853. catch( ... )
  854. {
  855. }
  856. // Update all of the action hotkeys. The process of loading the actions through
  857. // the KiFACE will only get us the default hotkeys
  858. ReadHotKeyConfigIntoActions( wxEmptyString, hotkeysPanel->ActionsList() );
  859. for( size_t i = 0; i < book->GetPageCount(); ++i )
  860. book->GetPage( i )->Layout();
  861. for( int page : expand )
  862. book->ExpandNode( page );
  863. if( dlg.ShowModal() == wxID_OK )
  864. {
  865. Pgm().GetSettingsManager().Save();
  866. dlg.Kiway().CommonSettingsChanged( false, false );
  867. }
  868. #undef CREATE_PANEL
  869. }
  870. void EDA_BASE_FRAME::OnDropFiles( wxDropFilesEvent& aEvent )
  871. {
  872. wxString* files = aEvent.GetFiles();
  873. for( int nb = 0; nb < aEvent.GetNumberOfFiles(); nb++ )
  874. {
  875. const wxFileName fn = wxFileName( files[nb] );
  876. for( const auto& [ext, tool] : m_acceptedExts )
  877. {
  878. if( IsExtensionAccepted( fn.GetExt(), { ext.ToStdString() } ) )
  879. {
  880. m_AcceptedFiles.emplace( m_AcceptedFiles.end(), fn );
  881. break;
  882. }
  883. }
  884. }
  885. DoWithAcceptedFiles();
  886. m_AcceptedFiles.clear();
  887. }
  888. void EDA_BASE_FRAME::DoWithAcceptedFiles()
  889. {
  890. for( const wxFileName& file : m_AcceptedFiles )
  891. {
  892. wxString fn = file.GetFullPath();
  893. m_toolManager->RunAction( *m_acceptedExts.at( file.GetExt() ), true, &fn );
  894. }
  895. }
  896. bool EDA_BASE_FRAME::IsWritable( const wxFileName& aFileName, bool aVerbose )
  897. {
  898. wxString msg;
  899. wxFileName fn = aFileName;
  900. // Check for absence of a file path with a file name. Unfortunately KiCad
  901. // uses paths relative to the current project path without the ./ part which
  902. // confuses wxFileName. Making the file name path absolute may be less than
  903. // elegant but it solves the problem.
  904. if( fn.GetPath().IsEmpty() && fn.HasName() )
  905. fn.MakeAbsolute();
  906. wxCHECK_MSG( fn.IsOk(), false,
  907. wxT( "File name object is invalid. Bad programmer!" ) );
  908. wxCHECK_MSG( !fn.GetPath().IsEmpty(), false,
  909. wxT( "File name object path <" ) + fn.GetFullPath() +
  910. wxT( "> is not set. Bad programmer!" ) );
  911. if( fn.IsDir() && !fn.IsDirWritable() )
  912. {
  913. msg.Printf( _( "Insufficient permissions to folder '%s'." ), fn.GetPath() );
  914. }
  915. else if( !fn.FileExists() && !fn.IsDirWritable() )
  916. {
  917. msg.Printf( _( "Insufficient permissions to save file '%s'." ), fn.GetFullPath() );
  918. }
  919. else if( fn.FileExists() && !fn.IsFileWritable() )
  920. {
  921. msg.Printf( _( "Insufficient permissions to save file '%s'." ), fn.GetFullPath() );
  922. }
  923. if( !msg.IsEmpty() )
  924. {
  925. if( aVerbose )
  926. wxMessageBox( msg );
  927. return false;
  928. }
  929. return true;
  930. }
  931. void EDA_BASE_FRAME::CheckForAutoSaveFile( const wxFileName& aFileName )
  932. {
  933. wxCHECK_RET( aFileName.IsOk(), wxT( "Invalid file name!" ) );
  934. wxFileName autoSaveFileName = aFileName;
  935. // Check for auto save file.
  936. autoSaveFileName.SetName( GetAutoSaveFilePrefix() + aFileName.GetName() );
  937. wxLogTrace( traceAutoSave,
  938. wxT( "Checking for auto save file " ) + autoSaveFileName.GetFullPath() );
  939. if( !autoSaveFileName.FileExists() )
  940. return;
  941. wxString msg = wxString::Format( _( "Well this is potentially embarrassing!\n"
  942. "It appears that the last time you were editing\n"
  943. "%s\n"
  944. "KiCad exited before saving.\n"
  945. "\n"
  946. "Do you wish to open the auto-saved file instead?" ),
  947. aFileName.GetFullName() );
  948. int response = wxMessageBox( msg, Pgm().App().GetAppDisplayName(), wxYES_NO | wxICON_QUESTION,
  949. this );
  950. // Make a backup of the current file, delete the file, and rename the auto save file to
  951. // the file name.
  952. if( response == wxYES )
  953. {
  954. if( !wxRenameFile( autoSaveFileName.GetFullPath(), aFileName.GetFullPath() ) )
  955. {
  956. wxMessageBox( _( "The auto save file could not be renamed to the board file name." ),
  957. Pgm().App().GetAppDisplayName(), wxOK | wxICON_EXCLAMATION, this );
  958. }
  959. }
  960. else
  961. {
  962. wxLogTrace( traceAutoSave,
  963. wxT( "Removing auto save file " ) + autoSaveFileName.GetFullPath() );
  964. // Remove the auto save file when using the previous file as is.
  965. wxRemoveFile( autoSaveFileName.GetFullPath() );
  966. }
  967. }
  968. bool EDA_BASE_FRAME::IsContentModified() const
  969. {
  970. // This function should be overridden in child classes
  971. return false;
  972. }
  973. void EDA_BASE_FRAME::initExitKey()
  974. {
  975. wxAcceleratorEntry entries[1];
  976. entries[0].Set( wxACCEL_CTRL, int( 'Q' ), wxID_EXIT );
  977. wxAcceleratorTable accel( 1, entries );
  978. SetAcceleratorTable( accel );
  979. }
  980. void EDA_BASE_FRAME::ClearUndoRedoList()
  981. {
  982. ClearUndoORRedoList( UNDO_LIST );
  983. ClearUndoORRedoList( REDO_LIST );
  984. }
  985. void EDA_BASE_FRAME::PushCommandToUndoList( PICKED_ITEMS_LIST* aNewitem )
  986. {
  987. m_undoList.PushCommand( aNewitem );
  988. // Delete the extra items, if count max reached
  989. if( m_undoRedoCountMax > 0 )
  990. {
  991. int extraitems = GetUndoCommandCount() - m_undoRedoCountMax;
  992. if( extraitems > 0 )
  993. ClearUndoORRedoList( UNDO_LIST, extraitems );
  994. }
  995. }
  996. void EDA_BASE_FRAME::PushCommandToRedoList( PICKED_ITEMS_LIST* aNewitem )
  997. {
  998. m_redoList.PushCommand( aNewitem );
  999. // Delete the extra items, if count max reached
  1000. if( m_undoRedoCountMax > 0 )
  1001. {
  1002. int extraitems = GetRedoCommandCount() - m_undoRedoCountMax;
  1003. if( extraitems > 0 )
  1004. ClearUndoORRedoList( REDO_LIST, extraitems );
  1005. }
  1006. }
  1007. PICKED_ITEMS_LIST* EDA_BASE_FRAME::PopCommandFromUndoList( )
  1008. {
  1009. return m_undoList.PopCommand();
  1010. }
  1011. PICKED_ITEMS_LIST* EDA_BASE_FRAME::PopCommandFromRedoList( )
  1012. {
  1013. return m_redoList.PopCommand();
  1014. }
  1015. void EDA_BASE_FRAME::OnModify()
  1016. {
  1017. m_autoSaveRequired = true;
  1018. }
  1019. void EDA_BASE_FRAME::ChangeUserUnits( EDA_UNITS aUnits )
  1020. {
  1021. SetUserUnits( aUnits );
  1022. unitsChangeRefresh();
  1023. wxCommandEvent e( UNITS_CHANGED );
  1024. ProcessEventLocally( e );
  1025. }
  1026. void EDA_BASE_FRAME::OnMaximize( wxMaximizeEvent& aEvent )
  1027. {
  1028. // When we maximize the window, we want to save the old information
  1029. // so that we can add it to the settings on next window load.
  1030. // Contrary to the documentation, this event seems to be generated
  1031. // when the window is also being unmaximized on OSX, so we only
  1032. // capture the size information when we maximize the window when on OSX.
  1033. #ifdef __WXOSX__
  1034. if( !IsMaximized() )
  1035. #endif
  1036. {
  1037. m_normalFrameSize = GetWindowSize();
  1038. m_normalFramePos = GetPosition();
  1039. wxLogTrace( traceDisplayLocation,
  1040. "Maximizing window - Saving position (%d, %d) with size (%d, %d)",
  1041. m_normalFramePos.x, m_normalFramePos.y,
  1042. m_normalFrameSize.x, m_normalFrameSize.y );
  1043. }
  1044. // Skip event to actually maximize the window
  1045. aEvent.Skip();
  1046. }
  1047. wxSize EDA_BASE_FRAME::GetWindowSize()
  1048. {
  1049. #ifdef __WXGTK__
  1050. wxSize winSize = GetSize();
  1051. // GTK includes the window decorations in the normal GetSize call,
  1052. // so we have to use a GTK-specific sizing call that returns the
  1053. // non-decorated window size.
  1054. if( m_ident == KICAD_MAIN_FRAME_T )
  1055. {
  1056. int width = 0;
  1057. int height = 0;
  1058. GTKDoGetSize( &width, &height );
  1059. winSize.Set( width, height );
  1060. }
  1061. #else
  1062. wxSize winSize = GetSize();
  1063. #endif
  1064. return winSize;
  1065. }
  1066. void EDA_BASE_FRAME::HandleSystemColorChange()
  1067. {
  1068. // Update the icon theme when the system theme changes and update the toolbars
  1069. GetBitmapStore()->ThemeChanged();
  1070. ThemeChanged();
  1071. // This isn't handled by ThemeChanged()
  1072. if( GetMenuBar() )
  1073. {
  1074. // For icons in menus, icon scaling & hotkeys
  1075. ReCreateMenuBar();
  1076. GetMenuBar()->Refresh();
  1077. }
  1078. }
  1079. void EDA_BASE_FRAME::onSystemColorChange( wxSysColourChangedEvent& aEvent )
  1080. {
  1081. // Call the handler to update the colors used in the frame
  1082. HandleSystemColorChange();
  1083. // Skip the change event to ensure the rest of the window controls get it
  1084. aEvent.Skip();
  1085. }
  1086. void EDA_BASE_FRAME::onIconize( wxIconizeEvent& aEvent )
  1087. {
  1088. // Call the handler
  1089. handleIconizeEvent( aEvent );
  1090. // Skip the event.
  1091. aEvent.Skip();
  1092. }
  1093. #ifdef _WIN32
  1094. WXLRESULT EDA_BASE_FRAME::MSWWindowProc( WXUINT message, WXWPARAM wParam, WXLPARAM lParam )
  1095. {
  1096. // This will help avoid the menu keeping focus when the alt key is released
  1097. // You can still trigger accelerators as long as you hold down alt
  1098. if( message == WM_SYSCOMMAND )
  1099. {
  1100. if( wParam == SC_KEYMENU && ( lParam >> 16 ) <= 0 )
  1101. return 0;
  1102. }
  1103. return wxFrame::MSWWindowProc( message, wParam, lParam );
  1104. }
  1105. #endif