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.

254 lines
7.8 KiB

15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
15 years ago
  1. // file dialog_helpers.h
  2. #ifndef _DIALOG_HELPERS_H_
  3. #define _DIALOG_HELPERS_H_
  4. /* some small helper classes used in dialogs
  5. * Due to use of wxFormBuilder to create dialogs
  6. * Many of them should be removed
  7. */
  8. /**
  9. * class WinEDAListBox
  10. *
  11. * Used to display a list of elements for selection, and an help of info line
  12. * about the selected item.
  13. */
  14. class WinEDAListBox : public wxDialog
  15. {
  16. private:
  17. wxListBox* m_listBox;
  18. wxTextCtrl* m_messages;
  19. void (*m_callBackFct)( wxString& Text );
  20. public:
  21. /**
  22. * Constructor:
  23. * @param aParent = apointeur to the parent window
  24. * @param aTitle = the title shown on top.
  25. * @param aItemList = a wxArrayStrin: the list of elements.
  26. * @param aRefText = an item name if an item must be preselected.
  27. * @param aCallBackFunction callback function to display comments
  28. * @param aPos = position of the dialog.
  29. */
  30. WinEDAListBox( EDA_DRAW_FRAME* aParent, const wxString& aTitle,
  31. const wxArrayString& aItemList, const wxString& aRefText,
  32. void(* aCallBackFunction)(wxString& Text) = NULL,
  33. wxPoint aPos = wxDefaultPosition );
  34. ~WinEDAListBox();
  35. void SortList();
  36. void Append( const wxString& aItemStr );
  37. void InsertItems( const wxArrayString& aItemList, int aPosition = 0 );
  38. void MoveMouseToOrigin();
  39. wxString GetTextSelection();
  40. private:
  41. void OnClose( wxCloseEvent& event );
  42. void OnCancelClick( wxCommandEvent& event );
  43. void OnOkClick( wxCommandEvent& event );
  44. void ClickOnList( wxCommandEvent& event );
  45. void D_ClickOnList( wxCommandEvent& event );
  46. void OnKeyEvent( wxKeyEvent& event );
  47. DECLARE_EVENT_TABLE()
  48. };
  49. /************************************************/
  50. /* Class to enter a line, is some dialog frames */
  51. /************************************************/
  52. class WinEDA_EnterText
  53. {
  54. public:
  55. bool m_Modify;
  56. private:
  57. wxString m_NewText;
  58. wxTextCtrl* m_FrameText;
  59. wxStaticText* m_Title;
  60. public:
  61. WinEDA_EnterText( wxWindow* parent, const wxString& Title,
  62. const wxString& TextToEdit, wxBoxSizer* BoxSizer,
  63. const wxSize& Size, bool Multiline = false );
  64. ~WinEDA_EnterText()
  65. {
  66. }
  67. wxString GetValue();
  68. void GetValue( char* buffer, int lenmax );
  69. void SetValue( const wxString& new_text );
  70. void Enable( bool enbl );
  71. void SetFocus() { m_FrameText->SetFocus(); }
  72. void SetInsertionPoint( int n ) { m_FrameText->SetInsertionPoint( n ); }
  73. void SetSelection( int n, int m )
  74. {
  75. m_FrameText->SetSelection( n, m );
  76. }
  77. };
  78. /************************************************************************/
  79. /* Class to edit/enter a graphic text and its dimension ( INCHES or MM )*/
  80. /************************************************************************/
  81. class WinEDA_GraphicTextCtrl
  82. {
  83. public:
  84. UserUnitType m_UserUnit;
  85. int m_Internal_Unit;
  86. wxTextCtrl* m_FrameText;
  87. wxTextCtrl* m_FrameSize;
  88. private:
  89. wxStaticText* m_Title;
  90. public:
  91. WinEDA_GraphicTextCtrl( wxWindow* parent, const wxString& Title,
  92. const wxString& TextToEdit, int textsize,
  93. UserUnitType user_unit, wxBoxSizer* BoxSizer, int framelen = 200,
  94. int internal_unit = EESCHEMA_INTERNAL_UNIT );
  95. ~WinEDA_GraphicTextCtrl();
  96. wxString GetText();
  97. int GetTextSize();
  98. void Enable( bool state );
  99. void SetTitle( const wxString& title );
  100. void SetFocus() { m_FrameText->SetFocus(); }
  101. void SetValue( const wxString& value );
  102. void SetValue( int value );
  103. /**
  104. * Function FormatSize
  105. * formats a string containing the size in the desired units.
  106. */
  107. static wxString FormatSize( int internalUnit, UserUnitType user_unit, int textSize );
  108. static int ParseSize( const wxString& sizeText, int internalUnit,
  109. UserUnitType user_unit );
  110. };
  111. /**************************************************************************/
  112. /* Class to edit/enter a coordinate (pair of values) ( INCHES or MM ) in */
  113. /* dialog boxes, */
  114. /**************************************************************************/
  115. class WinEDA_PositionCtrl
  116. {
  117. public:
  118. UserUnitType m_UserUnit;
  119. int m_Internal_Unit;
  120. wxPoint m_Pos_To_Edit;
  121. wxTextCtrl* m_FramePosX;
  122. wxTextCtrl* m_FramePosY;
  123. private:
  124. wxStaticText* m_TextX, * m_TextY;
  125. public:
  126. WinEDA_PositionCtrl( wxWindow* parent, const wxString& title,
  127. const wxPoint& pos_to_edit,
  128. UserUnitType user_unit, wxBoxSizer* BoxSizer,
  129. int internal_unit = EESCHEMA_INTERNAL_UNIT );
  130. ~WinEDA_PositionCtrl();
  131. void Enable( bool x_win_on, bool y_win_on );
  132. void SetValue( int x_value, int y_value );
  133. wxPoint GetValue();
  134. };
  135. /*************************************************************
  136. * Class to edit/enter a size (pair of values for X and Y size)
  137. * ( INCHES or MM ) in dialog boxes
  138. ***************************************************************/
  139. class WinEDA_SizeCtrl : public WinEDA_PositionCtrl
  140. {
  141. public:
  142. WinEDA_SizeCtrl( wxWindow* parent, const wxString& title,
  143. const wxSize& size_to_edit,
  144. UserUnitType user_unit, wxBoxSizer* BoxSizer,
  145. int internal_unit = EESCHEMA_INTERNAL_UNIT );
  146. ~WinEDA_SizeCtrl() { }
  147. wxSize GetValue();
  148. };
  149. /****************************************************************/
  150. /* Class to edit/enter a value ( INCHES or MM ) in dialog boxes */
  151. /****************************************************************/
  152. class WinEDA_ValueCtrl
  153. {
  154. public:
  155. UserUnitType m_UserUnit;
  156. int m_Value;
  157. wxTextCtrl* m_ValueCtrl;
  158. private:
  159. int m_Internal_Unit;
  160. wxStaticText* m_Text;
  161. public:
  162. WinEDA_ValueCtrl( wxWindow* parent, const wxString& title, int value,
  163. UserUnitType user_unit, wxBoxSizer* BoxSizer,
  164. int internal_unit = EESCHEMA_INTERNAL_UNIT );
  165. ~WinEDA_ValueCtrl();
  166. int GetValue();
  167. void SetValue( int new_value );
  168. void Enable( bool enbl );
  169. void SetToolTip( const wxString& text )
  170. {
  171. m_ValueCtrl->SetToolTip( text );
  172. }
  173. };
  174. /*************************/
  175. /* class WinEDAChoiceBox */
  176. /*************************/
  177. /* class to display a choice list.
  178. * This is a wrapper to wxComboBox (or wxChoice)
  179. * but because they have some problems, WinEDAChoiceBox uses workarounds:
  180. * - in wxGTK 2.6.2 wxGetSelection() does not work properly,
  181. * - and wxChoice crashes if compiled in non unicode mode and uses utf8 codes
  182. */
  183. #define EVT_KICAD_CHOICEBOX EVT_COMBOBOX
  184. class WinEDAChoiceBox : public wxComboBox
  185. {
  186. public:
  187. WinEDAChoiceBox( wxWindow* parent, wxWindowID id,
  188. const wxPoint& pos = wxDefaultPosition,
  189. const wxSize& size = wxDefaultSize,
  190. int n = 0, const wxString choices[] = NULL ) :
  191. wxComboBox( parent, id, wxEmptyString, pos, size,
  192. n, choices, wxCB_READONLY )
  193. {
  194. }
  195. WinEDAChoiceBox( wxWindow* parent, wxWindowID id,
  196. const wxPoint& pos, const wxSize& size,
  197. const wxArrayString& choices ) :
  198. wxComboBox( parent, id, wxEmptyString, pos, size,
  199. choices, wxCB_READONLY )
  200. {
  201. }
  202. int GetChoice()
  203. {
  204. return GetCurrentSelection();
  205. }
  206. };
  207. #endif