OpenASIP  2.0
Public Member Functions | Private Member Functions | List of all members
MessageDialog Class Reference

#include <MessageDialog.hh>

Inheritance diagram for MessageDialog:
Inheritance graph
Collaboration diagram for MessageDialog:
Collaboration graph

Public Member Functions

 MessageDialog (wxWindow *parent, const wxString &title, const wxString &message, long style)
 
virtual ~MessageDialog ()
 

Private Member Functions

wxString wordWrap (const wxString &string, unsigned int lineWidth)
 
wxString suppressLines (const wxString &string, int maxLines)
 

Detailed Description

MessageDialog is base class for all dialogs diaplaying a simple text message. MessageDialog extends wxMessageDialog functionality by word wrapping long lines to multiple lines, and suppressing lines of very long messages.

Definition at line 44 of file MessageDialog.hh.

Constructor & Destructor Documentation

◆ MessageDialog()

MessageDialog::MessageDialog ( wxWindow *  parent,
const wxString &  title,
const wxString &  message,
long  style 
)

Constructor.

Definition at line 48 of file MessageDialog.cc.

52  :
53  wxMessageDialog(
54  parent,
56  title, style) {
57 
58 }

◆ ~MessageDialog()

MessageDialog::~MessageDialog ( )
virtual

Destructor.

Definition at line 65 of file MessageDialog.cc.

65  {
66 }

Member Function Documentation

◆ suppressLines()

wxString MessageDialog::suppressLines ( const wxString &  string,
int  maxLines 
)
private

Truncates a string to given number of lines. If lines are suppressed, text '[n lines suppressed.]' is appended to the truncated string, where n is the number of lines suppressd.

Parameters
stringString to truncate.
maxLinesMaximum number of lines.
Returns
Truncated string.

Definition at line 131 of file MessageDialog.cc.

131  {
132 
133  int lineCount = 0;
134  wxString truncated;
135 
136  wxStringTokenizer lines(
137  string, _T("\n"), wxTOKEN_RET_EMPTY|wxTOKEN_RET_DELIMS);
138 
139  while (lineCount < maxLines && lines.HasMoreTokens()) {
140  // Get maximum number of lines to the result string.
141  lineCount++;
142  truncated.Append(lines.GetNextToken());
143  }
144 
145  if (!lines.HasMoreTokens()) {
146  // No lines suppressed.
147  return truncated;
148  }
149 
150  int suppressed = 0;
151  while (lines.HasMoreTokens()) {
152  // Count suppressed lines.
153  lines.GetNextToken();
154  suppressed++;
155  }
156 
157  truncated.Append(_T("\n [ "));
158  truncated.Append(WxConversion::toWxString(suppressed));
159  truncated.Append(_T(" lines suppressed.]"));
160  return truncated;
161 }

References WxConversion::toWxString().

Here is the call graph for this function:

◆ wordWrap()

wxString MessageDialog::wordWrap ( const wxString &  string,
unsigned int  lineWidth 
)
private

Wraps lines longer than given width to multiple lines. Existing line breaks aren't modified, but are taken to account when determining line lengths. Lines are wrapped at word boundaries only, unless a word is longer than the given line width.

Parameters
stringString to wrap.
lineWidthMaximum line width.
Returns
Word wrapped string.

Definition at line 80 of file MessageDialog.cc.

80  {
81 
82  wxString wrapped;
83  wxStringTokenizer lines(string, _T("\n"), wxTOKEN_RET_EMPTY);
84 
85  while (lines.HasMoreTokens()) {
86  // Handle each existing line of the string separately.
87  wxString line = lines.GetNextToken();
88  wxStringTokenizer words(line, _T(" \t"), wxTOKEN_RET_DELIMS);
89  wxString wrappedLine;
90  int length = 0;
91  while (words.HasMoreTokens()) {
92  // Handle lines word by word.
93  wxString word = words.GetNextToken();
94  if (length + word.length() < lineWidth) {
95  // Word fits to the current line.
96  wrappedLine.Append(word);
97  length = length + word.length();
98  } else if (word.length() < lineWidth) {
99  // Word doesn't fit to the current line, but isn't longer
100  // than the maximum line width.
101  wrappedLine.Append(_(" \n"));
102  wrappedLine.Append(word);
103  length = word.length();
104  } else {
105  // Word is longer than the maximum line width.
106  unsigned int i = 0;
107  for (; i < word.length(); i = i + (lineWidth - 1)) {
108  wrappedLine.Append(_T(" \n"));
109  wrappedLine.Append(word.Mid(i, lineWidth - 1));
110  length = word.length() - i;
111  }
112  }
113  }
114  wrappedLine.Append(_T("\n"));
115  wrapped.Append(wrappedLine);
116  }
117 
118  return wrapped;
119 }

The documentation for this class was generated from the following files:
WxConversion::toWxString
static wxString toWxString(const std::string &source)
MAX_LINES
const int MAX_LINES
Definition: MessageDialog.cc:42
MAX_LINE_WIDTH
const unsigned int MAX_LINE_WIDTH
Definition: MessageDialog.cc:40
MessageDialog::wordWrap
wxString wordWrap(const wxString &string, unsigned int lineWidth)
Definition: MessageDialog.cc:80
MessageDialog::suppressLines
wxString suppressLines(const wxString &string, int maxLines)
Definition: MessageDialog.cc:131