KiCad PCB EDA Suite
html_messagebox.cpp
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
5  * Copyright (C) 2014-2021 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 
25 #include <wx/clipbrd.h>
26 #include <kicad_string.h>
28 
29 
30 HTML_MESSAGE_BOX::HTML_MESSAGE_BOX( wxWindow* aParent, const wxString& aTitle,
31  const wxPoint& aPosition, const wxSize& aSize ) :
32  DIALOG_DISPLAY_HTML_TEXT_BASE( aParent, wxID_ANY, aTitle, aPosition, aSize )
33 {
34  m_htmlWindow->SetLayoutDirection( wxLayout_LeftToRight );
35  ListClear();
36 
37  // Gives a default logical size (the actual size depends on the display definition)
38  if( aSize != wxDefaultSize )
39  setSizeInDU( aSize.x, aSize.y );
40 
41  Center();
42 
43  m_sdbSizer1OK->SetDefault();
44 }
45 
46 
48 {
49  // Prevent wxWidgets bug which fails to release when closing the window on an <esc>.
50  if( m_htmlWindow->HasCapture() )
51  m_htmlWindow->ReleaseMouse();
52 }
53 
54 
55 void HTML_MESSAGE_BOX::OnOKButtonClick( wxCommandEvent& event )
56 {
57  // the dialog can be shown quasi-model, modal, or not modeless.
58  // therefore, use the right way to close it.
59  if( IsQuasiModal() )
60  EndQuasiModal( wxID_OK );
61  else if( IsModal() )
62  EndModal( wxID_OK );
63  else
64  Destroy();
65 }
66 
67 
69 {
70  m_htmlWindow->SetPage( wxEmptyString );
71 }
72 
73 
74 void HTML_MESSAGE_BOX::ListSet( const wxString& aList )
75 {
76  wxArrayString strings_list;
77  wxStringSplit( aList, strings_list, wxChar( '\n' ) );
78 
79  wxString msg = wxT( "<ul>" );
80 
81  for ( unsigned ii = 0; ii < strings_list.GetCount(); ii++ )
82  {
83  msg += wxT( "<li>" );
84  msg += strings_list.Item( ii ) + wxT( "</li>" );
85  }
86 
87  msg += wxT( "</ul>" );
88 
89  m_htmlWindow->AppendToPage( msg );
90 }
91 
92 
93 void HTML_MESSAGE_BOX::ListSet( const wxArrayString& aList )
94 {
95  wxString msg = wxT( "<ul>" );
96 
97  for( unsigned ii = 0; ii < aList.GetCount(); ii++ )
98  {
99  msg += wxT( "<li>" );
100  msg += aList.Item( ii ) + wxT( "</li>" );
101  }
102 
103  msg += wxT( "</ul>" );
104 
105  m_htmlWindow->AppendToPage( msg );
106 }
107 
108 
109 void HTML_MESSAGE_BOX::MessageSet( const wxString& message )
110 {
111  wxString message_value = wxString::Format(
112  wxT( "<b>%s</b><br>" ), message );
113 
114  m_htmlWindow->AppendToPage( message_value );
115 }
116 
117 
118 void HTML_MESSAGE_BOX::AddHTML_Text( const wxString& message )
119 {
120  m_htmlWindow->AppendToPage( message );
121 }
122 
123 
125 {
126  m_sdbSizer1->Show( false );
127  Layout();
128 
129  Show( true );
130 }
131 
132 
133 void HTML_MESSAGE_BOX::OnCharHook( wxKeyEvent& aEvent )
134 {
135  // shift-return (Mac default) or Ctrl-Return (GTK) for OK
136  if( aEvent.GetKeyCode() == WXK_ESCAPE )
137  {
138  wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
139  return;
140  }
141  else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'A' )
142  {
143  m_htmlWindow->SelectAll();
144  return;
145  }
146  else if( aEvent.GetModifiers() == wxMOD_CONTROL && aEvent.GetKeyCode() == 'C' )
147  {
148  wxLogNull doNotLog; // disable logging of failed clipboard actions
149 
150  if( wxTheClipboard->Open() )
151  {
152  wxTheClipboard->SetData( new wxTextDataObject( m_htmlWindow->SelectionToText() ) );
153  wxTheClipboard->Close();
154  }
155 
156  return;
157  }
158 
159  aEvent.Skip();
160 }
void setSizeInDU(int x, int y)
Set the dialog to the given dimensions in "dialog units".
bool IsQuasiModal() const
Definition: dialog_shim.h:107
virtual bool IsModal() const
Return true if the frame is shown in our modal mode and false if the frame is shown as an usual frame...
Class DIALOG_DISPLAY_HTML_TEXT_BASE.
void ListSet(const wxString &aList)
Add a list of items.
~HTML_MESSAGE_BOX() override
void MessageSet(const wxString &message)
Add a message (in bold) to message list.
bool Show(bool show) override
void wxStringSplit(const wxString &aText, wxArrayString &aStrings, wxChar aSplitter)
Split aString to a string list separated at aSplitter.
Definition: string.cpp:807
void Format(OUTPUTFORMATTER *out, int aNestLevel, int aCtl, const CPTREE &aTree)
Output a PTREE into s-expression format via an OUTPUTFORMATTER derivative.
Definition: ptree.cpp:200
void ShowModeless()
Show a modeless version of the dialog (without an OK button).
void OnOKButtonClick(wxCommandEvent &event) override
void EndQuasiModal(int retCode)
void AddHTML_Text(const wxString &message)
Add HTML text (without any change) to message list.
virtual void OnCharHook(wxKeyEvent &aEvt) override
HTML_MESSAGE_BOX(wxWindow *aParent, const wxString &aTitle=wxEmptyString, const wxPoint &aPosition=wxDefaultPosition, const wxSize &aSize=wxDefaultSize)