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.

251 lines
8.1 KiB

* 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
  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <dick@softplc.com>
  5. * Copyright (C) 2012-2019, 2024 KiCad Developers, see AUTHORS.txt for contributors.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License
  9. * as published by the Free Software Foundation; either version 2
  10. * of the License, or (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program; if not, you may find one here:
  19. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  20. * or you may search the http://www.gnu.org website for the version 2 license,
  21. * or you may write to the Free Software Foundation, Inc.,
  22. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  23. */
  24. #ifndef DIALOG_SHIM_
  25. #define DIALOG_SHIM_
  26. #include <kicommon.h>
  27. #include <eda_units.h>
  28. #include <kiway_holder.h>
  29. #include <wx/dialog.h>
  30. #include <map>
  31. class EDA_BASE_FRAME;
  32. class wxGridEvent;
  33. class wxGUIEventLoop;
  34. struct WINDOW_THAWER
  35. {
  36. WINDOW_THAWER( wxWindow* aWindow )
  37. {
  38. m_window = aWindow;
  39. m_freezeCount = 0;
  40. while( m_window->IsFrozen() )
  41. {
  42. m_window->Thaw();
  43. m_freezeCount++;
  44. }
  45. }
  46. ~WINDOW_THAWER()
  47. {
  48. while( m_freezeCount > 0 )
  49. {
  50. m_window->Freeze();
  51. m_freezeCount--;
  52. }
  53. }
  54. protected:
  55. wxWindow* m_window;
  56. int m_freezeCount;
  57. };
  58. class WDO_ENABLE_DISABLE;
  59. // These macros are for DIALOG_SHIM only, NOT for KIWAY_PLAYER. KIWAY_PLAYER
  60. // has its own support for quasi modal and its platform specific issues are different
  61. // than for a wxDialog.
  62. #define SHOWQUASIMODAL ShowQuasiModal
  63. #define ENDQUASIMODAL EndQuasiModal
  64. /**
  65. * Dialog helper object to sit in the inheritance tree between wxDialog and any class written
  66. * by wxFormBuilder.
  67. *
  68. * To put it there, use wxFormBuilder tool and set:
  69. * <br> subclass name = DIALOG_SHIM
  70. * <br> subclass header = dialog_shim.h
  71. * <br>
  72. * in the dialog window's properties.
  73. */
  74. class KICOMMON_API DIALOG_SHIM : public wxDialog, public KIWAY_HOLDER
  75. {
  76. public:
  77. DIALOG_SHIM( wxWindow* aParent, wxWindowID id, const wxString& title,
  78. const wxPoint& pos = wxDefaultPosition,
  79. const wxSize& size = wxDefaultSize,
  80. long style = wxDEFAULT_FRAME_STYLE | wxRESIZE_BORDER,
  81. const wxString& name = wxDialogNameStr );
  82. ~DIALOG_SHIM();
  83. /**
  84. * Sets the window (usually a wxTextCtrl) that should be focused when the dialog is
  85. * shown.
  86. */
  87. void SetInitialFocus( wxWindow* aWindow )
  88. {
  89. m_initialFocusTarget = aWindow;
  90. }
  91. int ShowModal() override;
  92. int ShowQuasiModal(); // disable only the parent window, otherwise modal.
  93. void EndQuasiModal( int retCode ); // End quasi-modal mode
  94. bool IsQuasiModal() const { return m_qmodal_showing; }
  95. bool Show( bool show ) override;
  96. bool Enable( bool enable ) override;
  97. void OnPaint( wxPaintEvent &event );
  98. void OnModify();
  99. void ClearModify();
  100. /**
  101. * Force the position of the dialog to a new position
  102. * @param aNewPosition is the new forced position
  103. */
  104. void SetPosition( const wxPoint& aNewPosition );
  105. EDA_UNITS GetUserUnits() const
  106. {
  107. return m_units;
  108. }
  109. void SelectAllInTextCtrls( wxWindowList& children );
  110. void SetupStandardButtons( std::map<int, wxString> aLabels = {} );
  111. static bool IsCtrl( int aChar, const wxKeyEvent& e )
  112. {
  113. return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() &&
  114. !e.ShiftDown() && !e.MetaDown();
  115. }
  116. static bool IsShiftCtrl( int aChar, const wxKeyEvent& e )
  117. {
  118. return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() &&
  119. e.ShiftDown() && !e.MetaDown();
  120. }
  121. protected:
  122. /**
  123. * In all dialogs, we must call the same functions to fix minimal dlg size, the default
  124. * position and perhaps some others to fix a few issues depending on Windows Managers
  125. * this helper function does these calls.
  126. *
  127. * finishDialogSettings must be called from derived classes after all widgets have been
  128. * initialized, and therefore their size fixed. If TransferDataToWindow() is used to
  129. * initialize widgets, at the end of TransferDataToWindow, or better yet, at end of a
  130. * wxInitDialogEvent handler.
  131. */
  132. void finishDialogSettings();
  133. /**
  134. * Set the dialog to the given dimensions in "dialog units". These are units equivalent
  135. * to 4* the average character width and 8* the average character height, allowing a dialog
  136. * to be sized in a way that scales it with the system font.
  137. */
  138. void setSizeInDU( int x, int y );
  139. /**
  140. * Convert an integer number of dialog units to pixels, horizontally. See SetSizeInDU or
  141. * wxDialog documentation for more information.
  142. */
  143. int horizPixelsFromDU( int x ) const;
  144. /**
  145. * Convert an integer number of dialog units to pixels, vertically. See SetSizeInDU or
  146. * wxDialog documentation for more information.
  147. */
  148. int vertPixelsFromDU( int y ) const;
  149. /**
  150. * Clear the existing dialog size and position.
  151. *
  152. * This will cause the dialog size to be clear so the next time the dialog is shown
  153. * the sizers will layout the dialog accordingly. This useful when there are dialog
  154. * windows that size changes due to layout dependency hidden controls.
  155. */
  156. void resetSize();
  157. virtual void OnCharHook( wxKeyEvent& aEvt );
  158. /**
  159. * Override this method to perform dialog tear down actions not suitable for object dtor.
  160. *
  161. * @warning This only gets called for dialogs that are shown in the quasimodal mode. If
  162. * you need to perform tear down actions in modal or modeless dialogs, create
  163. * a close window event handler.
  164. */
  165. virtual void TearDownQuasiModal() {}
  166. private:
  167. /**
  168. * Properly handle the wxCloseEvent when in the quasimodal mode when not calling
  169. * EndQuasiModal which is possible with any dialog derived from #DIALOG_SHIM.
  170. */
  171. void OnCloseWindow( wxCloseEvent& aEvent );
  172. /**
  173. * Properly handle the default button events when in the quasimodal mode when not
  174. * calling EndQuasiModal which is possible with any dialog derived from #DIALOG_SHIM.
  175. */
  176. void OnButton( wxCommandEvent& aEvent );
  177. void onChildSetFocus( wxFocusEvent& aEvent );
  178. DECLARE_EVENT_TABLE();
  179. protected:
  180. EDA_UNITS m_units; // userUnits for display and parsing
  181. std::string m_hash_key; // alternate for class_map when classname re-used
  182. // The following disables the storing of a user size. It is used primarily for dialogs
  183. // with conditional content which don't need user sizing.
  184. bool m_useCalculatedSize;
  185. // On MacOS (at least) SetFocus() calls made in the constructor will fail because a
  186. // window that isn't yet visible will return false to AcceptsFocus(). So we must delay
  187. // the initial-focus SetFocus() call to the first paint event.
  188. bool m_firstPaintEvent;
  189. wxWindow* m_initialFocusTarget;
  190. bool m_isClosing;
  191. wxGUIEventLoop* m_qmodal_loop; // points to nested event_loop, NULL means not qmodal
  192. // and dismissed
  193. bool m_qmodal_showing;
  194. WDO_ENABLE_DISABLE* m_qmodal_parent_disabler;
  195. EDA_BASE_FRAME* m_parentFrame;
  196. std::vector<wxWindow*> m_tabOrder;
  197. // The size asked by the caller, used the first time the dialog is created
  198. wxSize m_initialSize;
  199. // Used to support first-esc-cancels-edit logic
  200. std::map<wxWindow*, wxString> m_beforeEditValues;
  201. };
  202. #endif // DIALOG_SHIM_