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.

307 lines
8.8 KiB

  1. /******************************************************************/
  2. /* basicframe.cpp - fonctions des classes du type WinEDA_BasicFrame */
  3. /******************************************************************/
  4. #ifdef __GNUG__
  5. #pragma implementation
  6. #endif
  7. #include "fctsys.h"
  8. #include <wx/fontdlg.h>
  9. #include "common.h"
  10. #include "online_help.h"
  11. #include "id.h"
  12. /*******************************************************/
  13. /* Constructeur de WinEDA_BasicFrame: la fenetre generale */
  14. /*******************************************************/
  15. WinEDA_BasicFrame::WinEDA_BasicFrame( wxWindow* father, int idtype,
  16. WinEDA_App* parent, const wxString& title,
  17. const wxPoint& pos, const wxSize& size, long style ) :
  18. wxFrame( father, -1, title, pos, size, style )
  19. {
  20. wxSize minsize;
  21. m_Ident = idtype;
  22. m_Parent = parent;
  23. SetFont( *g_StdFont );
  24. m_MenuBar = NULL; // menu du haut d'ecran
  25. m_HToolBar = NULL;
  26. m_FrameIsActive = TRUE;
  27. m_MsgFrameHeight = MSG_PANEL_DEFAULT_HEIGHT;
  28. minsize.x = 470;
  29. minsize.y = 350 + m_MsgFrameHeight;
  30. SetSizeHints( minsize.x, minsize.y, -1, -1, -1, -1 );
  31. /* Verification des parametres de creation */
  32. if( (size.x < minsize.x) || (size.y < minsize.y) )
  33. SetSize( 0, 0, minsize.x, minsize.y );
  34. // Create child subwindows.
  35. GetClientSize( &m_FrameSize.x, &m_FrameSize.y ); /* dimx, dimy = dimensions utiles de la
  36. * zone utilisateur de la fenetre principale */
  37. m_FramePos.x = m_FramePos.y = 0;
  38. m_FrameSize.y -= m_MsgFrameHeight;
  39. }
  40. /******************************************/
  41. WinEDA_BasicFrame::~WinEDA_BasicFrame()
  42. /******************************************/
  43. {
  44. if( m_Parent->m_HtmlCtrl )
  45. delete m_Parent->m_HtmlCtrl;
  46. m_Parent->m_HtmlCtrl = NULL;
  47. }
  48. /********************************************/
  49. void WinEDA_BasicFrame::ReCreateMenuBar()
  50. /********************************************/
  51. // Virtual function
  52. {
  53. }
  54. /*********************************************/
  55. void WinEDA_BasicFrame::GetSettings()
  56. /*********************************************/
  57. {
  58. wxString text;
  59. int Ypos_min;
  60. if( m_Parent->m_EDA_Config )
  61. {
  62. text = m_FrameName + wxT( "Pos_x" );
  63. m_Parent->m_EDA_Config->Read( text, &m_FramePos.x );
  64. text = m_FrameName + wxT( "Pos_y" );
  65. m_Parent->m_EDA_Config->Read( text, &m_FramePos.y );
  66. text = m_FrameName + wxT( "Size_x" );
  67. m_Parent->m_EDA_Config->Read( text, &m_FrameSize.x, 600 );
  68. text = m_FrameName + wxT( "Size_y" );
  69. m_Parent->m_EDA_Config->Read( text, &m_FrameSize.y, 400 );
  70. }
  71. // Ensure Window title bar is visible
  72. #ifdef __WXMAC__
  73. // for macOSX, the window must be below system (macOSX) toolbar
  74. Ypos_min = GetMBarHeight();
  75. #else
  76. Ypos_min = 0;
  77. #endif
  78. if( m_FramePos.y < Ypos_min )
  79. m_FramePos.y = Ypos_min;
  80. }
  81. /*****************************************/
  82. void WinEDA_BasicFrame::SaveSettings()
  83. /*****************************************/
  84. {
  85. wxString text;
  86. if( !m_Parent || !m_Parent->m_EDA_Config )
  87. return;
  88. if( !m_Parent->m_EDA_Config || IsIconized() )
  89. return;
  90. m_FrameSize = GetSize();
  91. m_FramePos = GetPosition();
  92. text = m_FrameName + wxT( "Pos_x" );
  93. m_Parent->m_EDA_Config->Write( text, (long) m_FramePos.x );
  94. text = m_FrameName + wxT( "Pos_y" );
  95. m_Parent->m_EDA_Config->Write( text, (long) m_FramePos.y );
  96. text = m_FrameName + wxT( "Size_x" );
  97. m_Parent->m_EDA_Config->Write( text, (long) m_FrameSize.x );
  98. text = m_FrameName + wxT( "Size_y" );
  99. m_Parent->m_EDA_Config->Write( text, (long) m_FrameSize.y );
  100. }
  101. /******************************************************/
  102. void WinEDA_BasicFrame::PrintMsg( const wxString& text )
  103. /******************************************************/
  104. {
  105. SetStatusText( text );
  106. #ifdef DEBUG
  107. printf( "%s\n", (const char*) text.mb_str() );
  108. #endif
  109. }
  110. /*************************************************************************/
  111. void WinEDA_BasicFrame::DisplayActivity( int PerCent, const wxString& Text )
  112. /*************************************************************************/
  113. /* Display a bargraph (0 to 50 point length) for a PerCent value from 0 to 100
  114. */
  115. {
  116. wxString Line;
  117. Line = Text;
  118. PerCent = (PerCent < 0) ? 0 : PerCent;
  119. PerCent = (PerCent > 100) ? 100 : PerCent;
  120. PerCent /= 2; // Bargraph is 0 .. 50 points from 0% to 100%
  121. if( PerCent )
  122. Line.Pad( PerCent, '*' );
  123. SetStatusText( Line );
  124. }
  125. /*******************************************************************/
  126. void WinEDA_BasicFrame::SetLastProject( const wxString& FullFileName )
  127. /*******************************************************************/
  128. /* Met a jour la liste des anciens projets
  129. */
  130. {
  131. unsigned ii;
  132. if( FullFileName.IsEmpty() )
  133. return;
  134. //suppression d'une ancienne trace eventuelle du meme fichier
  135. for( ii = 0; ii < m_Parent->m_LastProject.GetCount(); )
  136. {
  137. if( m_Parent->m_LastProject[ii].IsEmpty() )
  138. break;
  139. #ifdef __WINDOWS__
  140. if( m_Parent->m_LastProject[ii].CmpNoCase( FullFileName ) == 0 )
  141. #else
  142. if( m_Parent->m_LastProject[ii] == FullFileName )
  143. #endif
  144. {
  145. #if ( ( wxMAJOR_VERSION < 2) || ( ( wxMAJOR_VERSION == 2)&& (wxMINOR_VERSION <= 4 ) ) )
  146. m_Parent->m_LastProject.Remove( ii );
  147. #else
  148. m_Parent->m_LastProject.RemoveAt( ii );
  149. #endif
  150. }
  151. else
  152. ii++;
  153. }
  154. while( m_Parent->m_LastProject.GetCount() >= m_Parent->m_LastProjectMaxCount )
  155. {
  156. #if ( ( wxMAJOR_VERSION < 2) || ( ( wxMAJOR_VERSION == 2)&& (wxMINOR_VERSION <= 4 ) ) )
  157. files.Remove( files.GetCount() - 1 );
  158. #else
  159. m_Parent->m_LastProject.RemoveAt( m_Parent->m_LastProject.GetCount() - 1 );
  160. #endif
  161. }
  162. m_Parent->m_LastProject.Insert( FullFileName, 0 );
  163. ReCreateMenuBar();
  164. }
  165. /**************************************************/
  166. wxString WinEDA_BasicFrame::GetLastProject( int rang )
  167. /**************************************************/
  168. {
  169. if( rang < 0 )
  170. rang = 0;
  171. if( (unsigned) rang >= m_Parent->m_LastProject.GetCount() )
  172. return wxEmptyString;
  173. return m_Parent->m_LastProject[rang];
  174. }
  175. /**************************************************************/
  176. void WinEDA_BasicFrame::GetKicadHelp( wxCommandEvent& event )
  177. /**************************************************************/
  178. {
  179. #if defined ONLINE_HELP_FILES_FORMAT_IS_HTML
  180. if( m_Parent->m_HtmlCtrl == NULL )
  181. {
  182. m_Parent->InitOnLineHelp();
  183. }
  184. if( m_Parent->m_HtmlCtrl )
  185. {
  186. m_Parent->m_HtmlCtrl->DisplayContents();
  187. m_Parent->m_HtmlCtrl->Display( m_Parent->m_HelpFileName );
  188. }
  189. else
  190. {
  191. wxString msg;
  192. msg.Printf( _( "Help file %s not found" ), m_Parent->m_HelpFileName.GetData() );
  193. DisplayError( this, msg );
  194. }
  195. #elif defined ONLINE_HELP_FILES_FORMAT_IS_PDF
  196. wxString fullfilename = FindKicadHelpPath() + m_Parent->m_HelpFileName;
  197. if ( wxFileExists(fullfilename) )
  198. GetAssociatedDocument( this, wxEmptyString, fullfilename );
  199. else // Try to find file in English format:
  200. {
  201. fullfilename = FindKicadHelpPath() + wxT("../en/") + m_Parent->m_HelpFileName;;
  202. GetAssociatedDocument( this, wxEmptyString, fullfilename );
  203. }
  204. #else
  205. #error Help files format not defined
  206. #endif
  207. }
  208. /***********************************************************/
  209. void WinEDA_BasicFrame::GetKicadAbout( wxCommandEvent& event )
  210. /**********************************************************/
  211. {
  212. Print_Kicad_Infos( this, m_AboutTitle, wxEmptyString );
  213. }
  214. /********************************************************************/
  215. void WinEDA_BasicFrame::ProcessFontPreferences( int id )
  216. /********************************************************************/
  217. {
  218. wxFont font;
  219. switch( id )
  220. {
  221. case ID_PREFERENCES_FONT:
  222. break;
  223. case ID_PREFERENCES_FONT_STATUS:
  224. font = wxGetFontFromUser( this, *g_StdFont );
  225. if( font.Ok() )
  226. {
  227. int pointsize = font.GetPointSize();
  228. *g_StdFont = font;
  229. SetFont( *g_StdFont );
  230. if( GetStatusBar() )
  231. GetStatusBar()->SetFont( *g_StdFont );
  232. g_StdFontPointSize = pointsize;
  233. }
  234. break;
  235. case ID_PREFERENCES_FONT_DIALOG:
  236. font = wxGetFontFromUser( this, *g_DialogFont );
  237. if( font.Ok() )
  238. {
  239. int pointsize = font.GetPointSize();
  240. *g_DialogFont = font;
  241. SetFont( *g_DialogFont );
  242. g_DialogFontPointSize = pointsize;
  243. g_FixedFontPointSize = pointsize;
  244. g_FixedFont->SetPointSize( g_FixedFontPointSize );
  245. }
  246. break;
  247. default:
  248. DisplayError( this, wxT( "WinEDA_BasicFrame::ProcessFontPreferences Internal Error" ) );
  249. break;
  250. }
  251. }