- m_dialogStyle = style;
- m_selection = 0;
- m_stringSelection = "";
- m_clientData = NULL;
-
- wxBeginBusyCursor();
-
- wxSizer *topSizer = new wxSizer(this, wxSizerShrink);
- topSizer->SetBorder(10, 10);
-
- wxRowColSizer *messageSizer = new wxRowColSizer(topSizer, wxSIZER_COLS, 100);
- messageSizer->SetName("messageSizer");
-
-// bool centre = ((style & wxCENTRE) == wxCENTRE);
-
- wxList messageList;
- wxSplitMessage2(message, &messageList, this, messageSizer);
-
- // Insert a spacer
- wxSpacingSizer *spacingSizer = new wxSpacingSizer(topSizer, wxBelow, messageSizer, 10);
-
- wxListBox *listBox = new wxListBox(this, wxID_LISTBOX, wxPoint(-1, -1), wxSize(240, 160),
- n, choices);
- listBox->SetSelection(m_selection);
- if ( clientData )
- {
- int i;
- for ( i = 0; i < n; i++)
- {
- listBox->SetClientData(i, clientData[i]);
- }
- }
-
- wxRowColSizer *listBoxSizer = new wxRowColSizer(topSizer, wxSIZER_ROWS);
- listBoxSizer->AddSizerChild(listBox);
- listBoxSizer->SetName("listBoxSizer");
-
- // Create constraints for the text sizer
- wxLayoutConstraints *textC = new wxLayoutConstraints;
- textC->left.SameAs (messageSizer, wxLeft);
- textC->top.Below (spacingSizer);
- listBoxSizer->SetConstraints(textC);
-
- // Insert another spacer
- wxSpacingSizer *spacingSizer2 = new wxSpacingSizer(topSizer, wxBelow, listBoxSizer, 10);
- spacingSizer->SetName("spacingSizer2");
-
- // Insert a sizer for the buttons
- wxRowColSizer *buttonSizer = new wxRowColSizer(topSizer, wxSIZER_ROWS);
- buttonSizer->SetName("buttonSizer");
- buttonSizer->SetSpacing(12,0);
-
- // Specify constraints for the button sizer
- wxLayoutConstraints *c = new wxLayoutConstraints;
- c->width.AsIs ();
- c->height.AsIs ();
- c->top.Below (spacingSizer2);
- c->centreX.SameAs (listBoxSizer, wxCentreX);
- buttonSizer->SetConstraints(c);
-
- wxButton *ok = NULL;
- wxButton *cancel = NULL;
-
- if (style & wxOK) {
- ok = new wxButton(this, wxID_OK, _("OK"), wxDefaultPosition, wxSize(75,-1) );
- buttonSizer->AddSizerChild(ok);
- }
-
- if (style & wxCANCEL) {
- cancel = new wxButton(this, wxID_CANCEL, _("Cancel"), wxDefaultPosition, wxSize(75,-1));
- buttonSizer->AddSizerChild(cancel);
- }
-
- if (ok)
- {
- ok->SetDefault();
- ok->SetFocus();
- }
-
- Layout();
- Centre(wxBOTH);
-
- wxEndBusyCursor();
-
- return TRUE;
+ m_selection = 0;
+ m_clientData = NULL;
+
+ // calc the message size
+ // ---------------------
+
+ wxArrayString lines;
+ wxSize sizeText = SplitTextMessage(message, &lines);
+ long heightTextMax = sizeText.GetHeight(),
+ widthTextMax = sizeText.GetWidth();
+ size_t nLineCount = lines.Count();
+ long hTotalMsg = heightTextMax*nLineCount;
+
+ // calc the button size
+ // --------------------
+
+ // always create the OK button - the code below supposes we do have buttons
+ // and besides the user should have some way to close this dialog
+ wxASSERT_MSG( style & wxOK, _T("this dialog should have OK button") );
+
+ bool hasCancel = (style & wxCANCEL) != 0;
+
+ wxSize sizeButtons = GetStandardButtonSize(hasCancel);
+
+ long wButton = sizeButtons.GetWidth(),
+ hButton = sizeButtons.GetHeight();
+
+ long wTotalButtons = wButton;
+ if ( hasCancel )
+ {
+ wTotalButtons *= 2; // second button
+ wTotalButtons += MARGIN_BETWEEN_BUTTONS; // margin between the 2
+ }
+
+ // listbox and stat line
+ // ---------------------
+
+ // make the listbox at least as tall as the message - otherwise it looks
+ // ugly (the lower limit of 300 for the width is arbitrary OTOH)
+ //
+ // NB: we write "n + 2" because the horiz. scrollbar also takes some place
+ long hListbox = wxMax((n + 2) * heightTextMax, hTotalMsg),
+ wListbox = wxMax(300, wxMax(wTotalButtons, widthTextMax));
+
+#if wxUSE_STATLINE
+ long hStatLine = wxStaticLine::GetDefaultSize();
+#endif
+
+ // now the complete dialog size
+ // ----------------------------
+
+ long hDialog = 2*LAYOUT_Y_MARGIN + // top margin
+ hTotalMsg + // message
+ 2*LAYOUT_Y_MARGIN + // margin between text and listbox
+ hListbox + // listbox
+#if wxUSE_STATLINE
+ LAYOUT_Y_MARGIN + // margin
+ hStatLine + // separator line
+#endif
+ 2*LAYOUT_Y_MARGIN + // margin between listbox and buttons
+ hButton + // button(s)
+ LAYOUT_Y_MARGIN; // bottom margin
+
+ long wDialog = wxMax(wListbox, wxMax(wTotalButtons, widthTextMax)) +
+ 4*LAYOUT_X_MARGIN; // 2 from each side
+
+ // create the controls
+ // -------------------
+
+ // message
+ wxStaticText *text;
+ int y = 2*LAYOUT_Y_MARGIN;
+ for ( size_t nLine = 0; nLine < nLineCount; nLine++ )
+ {
+ text = new wxStaticText(this, -1, lines[nLine],
+ wxPoint(2*LAYOUT_X_MARGIN, y),
+ wxSize(widthTextMax, heightTextMax));
+ y += heightTextMax;
+ }
+
+ y += 2*LAYOUT_X_MARGIN;
+
+ // listbox
+ m_listbox = new wxListBox( this, wxID_LISTBOX,
+ wxPoint(2*LAYOUT_X_MARGIN, y),
+ wxSize(wListbox, hListbox),
+ n, choices,
+ wxLB_HSCROLL);
+ y += hListbox;
+
+ if ( clientData )
+ {
+ for (int i = 0; i < n; i++)
+ m_listbox->SetClientData(i, clientData[i]);
+ }
+
+ // separator line
+#if wxUSE_STATLINE
+ (void) new wxStaticLine( this, -1,
+ wxPoint(2*LAYOUT_X_MARGIN, y + LAYOUT_Y_MARGIN),
+ wxSize(wDialog - 4*LAYOUT_X_MARGIN, hStatLine) );
+
+ y += LAYOUT_Y_MARGIN + hStatLine;
+#endif
+
+ // buttons
+
+ y += 2*LAYOUT_X_MARGIN;
+
+ CreateStandardButtons(wDialog, y, wButton, hButton, hasCancel);
+
+ SetClientSize( wDialog, hDialog );
+
+ Centre( wxBOTH );
+
+ return TRUE;