- m_dialogStyle = style;
- m_selection = 0;
- m_clientData = NULL;
-
- // dialog layout constants
- static const int LAYOUT_X_MARGIN = 5;
- static const int LAYOUT_Y_MARGIN = 5;
- static const int MARGIN_BETWEEN_BUTTONS = 3*LAYOUT_X_MARGIN;
-
- // calc the message size
- // ---------------------
-
- // TODO this should be factored out to a common function (also used in
- // msgdlgg.cpp)
- wxClientDC dc(this);
- dc.SetFont(wxSystemSettings::GetSystemFont(wxSYS_DEFAULT_GUI_FONT));
-
- wxArrayString lines;
- wxString curLine;
- long height, width, heightTextMax = 0, widthTextMax = 0;
- for ( const char *pc = message; ; pc++ ) {
- if ( *pc == '\n' || *pc == '\0' ) {
- dc.GetTextExtent(curLine, &width, &height);
- if ( width > widthTextMax )
- widthTextMax = width;
- if ( height > heightTextMax )
- heightTextMax = height;
-
- lines.Add(curLine);
-
- if ( *pc == '\n' ) {
- curLine.Empty();
- }
- else {
- // the end of string
- break;
- }
- }
- else {
- curLine += *pc;
- }
- }
-
- size_t nLineCount = lines.Count();
- long hTotalMsg = heightTextMax*nLineCount;
-
- // calc the button size
- // --------------------
-
- bool hasCancel = FALSE;
-
- // 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") );
-
- wxString labelOk(_("OK"));
- long wButton = 0;
- dc.GetTextExtent(labelOk, &width, NULL);
- if ( width > wButton )
- wButton = width;
-
- wxString labelCancel;
- if ( style & wxCANCEL )
- {
- labelCancel = _("Cancel");
- dc.GetTextExtent(labelCancel, &width, NULL);
- if ( width > wButton )
- wButton = width;
-
- hasCancel = TRUE;
- }
-
- if ( wButton < 75 )
- wButton = 75;
- else
- wButton += 10;
-
- long hButton = wButton*23/75;
- 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
- // arbitrary...
- long hStatLine = 5;
-#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