]> git.saurik.com Git - wxWidgets.git/blame - src/common/dlgcmn.cpp
search progress bar has smooth gauge under win95 now
[wxWidgets.git] / src / common / dlgcmn.cpp
CommitLineData
e37feda2
VZ
1/////////////////////////////////////////////////////////////////////////////
2// Name: common/dlgcmn.cpp
3// Purpose: common (to all ports) wxDialog functions
4// Author: Vadim Zeitlin
5// Modified by:
6// Created: 28.06.99
7// RCS-ID: $Id$
8// Copyright: (c) Vadim Zeitlin
9// Licence: wxWindows license
10/////////////////////////////////////////////////////////////////////////////
11
12// ============================================================================
13// declarations
14// ============================================================================
15
16// ----------------------------------------------------------------------------
17// headers
18// ----------------------------------------------------------------------------
19
e37feda2 20#ifdef __GNUG__
1b68e0b5 21 #pragma implementation "dialogbase.h"
e37feda2
VZ
22#endif
23
24// For compilers that support precompilation, includes "wx.h".
25#include "wx/wxprec.h"
26
27#ifdef __BORLANDC__
28 #pragma hdrstop
29#endif
30
31#ifndef WX_PRECOMP
32 #include "wx/dialog.h"
33 #include "wx/dcclient.h"
9f3a38fc 34 #include "wx/intl.h"
e37feda2 35 #include "wx/settings.h"
9f3a38fc 36 #include "wx/stattext.h"
92afa2b1 37 #include "wx/sizer.h"
e37feda2
VZ
38#endif
39
92afa2b1
RR
40//--------------------------------------------------------------------------
41// wxDialogBase
42//--------------------------------------------------------------------------
e37feda2 43
92afa2b1 44wxSizer *wxDialogBase::CreateTextSizer( const wxString &message )
e37feda2 45{
92afa2b1 46 wxBoxSizer *box = new wxBoxSizer( wxVERTICAL );
b730516c 47
8a5137d7
RR
48 // get line height for empty lines
49 int y = 0;
50 wxFont new_font( GetFont() );
51 if (!new_font.Ok()) new_font = *wxSWISS_FONT;
52 GetTextExtent( "H", (int*)NULL, &y, (int*)NULL, (int*)NULL, &new_font );
b730516c 53
92afa2b1
RR
54 wxString line;
55 for (size_t pos = 0; pos < message.Len(); pos++)
e37feda2 56 {
223d09f6 57 if (message[pos] == wxT('\n'))
e37feda2 58 {
92afa2b1 59 if (!line.IsEmpty())
e37feda2 60 {
92afa2b1
RR
61 wxStaticText *s1 = new wxStaticText( this, -1, line );
62 box->Add( s1 );
223d09f6 63 line = wxT("");
e37feda2 64 }
8a5137d7
RR
65 else
66 {
67 box->Add( 5, y );
68 }
e37feda2
VZ
69 }
70 else
71 {
92afa2b1 72 line += message[pos];
e37feda2
VZ
73 }
74 }
b730516c 75
92afa2b1
RR
76 // remaining text behind last '\n'
77 if (!line.IsEmpty())
e37feda2 78 {
92afa2b1
RR
79 wxStaticText *s2 = new wxStaticText( this, -1, line );
80 box->Add( s2 );
e37feda2 81 }
b730516c 82
92afa2b1 83 return box;
e37feda2 84}
b730516c 85
92afa2b1 86wxSizer *wxDialogBase::CreateButtonSizer( long flags )
e37feda2 87{
92afa2b1 88 wxBoxSizer *box = new wxBoxSizer( wxHORIZONTAL );
e37feda2 89
92afa2b1
RR
90#if defined(__WXMSW__) || defined(__WXMAC__)
91 int margin = 6;
92#else
93 int margin = 10;
94#endif
e37feda2 95
92afa2b1
RR
96 wxButton *ok = (wxButton *) NULL;
97 wxButton *cancel = (wxButton *) NULL;
98 wxButton *yes = (wxButton *) NULL;
99 wxButton *no = (wxButton *) NULL;
9c884972
RR
100
101 // always show an OK button, unless only YES_NO is given
102 if ((flags & wxYES_NO) == 0) flags = flags | wxOK;
b730516c
RD
103
104 if (flags & wxYES_NO)
e37feda2 105 {
92afa2b1
RR
106 yes = new wxButton( this, wxID_YES, _("Yes") );
107 box->Add( yes, 0, wxLEFT|wxRIGHT, margin );
108 no = new wxButton( this, wxID_NO, _("No") );
109 box->Add( no, 0, wxLEFT|wxRIGHT, margin );
b730516c
RD
110 } else
111 if (flags & wxYES)
92afa2b1
RR
112 {
113 yes = new wxButton( this, wxID_YES, _("Yes") );
114 box->Add( yes, 0, wxLEFT|wxRIGHT, margin );
b730516c
RD
115 } else
116 if (flags & wxNO)
92afa2b1
RR
117 {
118 no = new wxButton( this, wxID_NO, _("No") );
119 box->Add( no, 0, wxLEFT|wxRIGHT, margin );
e37feda2 120 }
92afa2b1 121
b730516c 122 if (flags & wxOK)
e37feda2 123 {
92afa2b1
RR
124 ok = new wxButton( this, wxID_OK, _("OK") );
125 box->Add( ok, 0, wxLEFT|wxRIGHT, margin );
e37feda2
VZ
126 }
127
b730516c
RD
128 if (flags & wxFORWARD)
129 box->Add( new wxButton( this, wxID_FORWARD, _("Forward") ), 0, wxLEFT|wxRIGHT, margin );
e37feda2 130
b730516c 131 if (flags & wxBACKWARD)
92afa2b1 132 box->Add( new wxButton( this, wxID_BACKWARD, _("Backward") ), 0, wxLEFT|wxRIGHT, margin );
e37feda2 133
b730516c 134 if (flags & wxSETUP)
92afa2b1 135 box->Add( new wxButton( this, wxID_SETUP, _("Setup") ), 0, wxLEFT|wxRIGHT, margin );
e37feda2 136
b730516c 137 if (flags & wxMORE)
92afa2b1 138 box->Add( new wxButton( this, wxID_MORE, _("More...") ), 0, wxLEFT|wxRIGHT, margin );
e37feda2 139
92afa2b1
RR
140 if (flags & wxHELP)
141 box->Add( new wxButton( this, wxID_HELP, _("Help") ), 0, wxLEFT|wxRIGHT, margin );
e37feda2 142
b730516c 143 if (flags & wxCANCEL)
e37feda2 144 {
92afa2b1
RR
145 cancel = new wxButton( this, wxID_CANCEL, _("Cancel") );
146 box->Add( cancel, 0, wxLEFT|wxRIGHT, margin );
e37feda2
VZ
147 }
148
b730516c
RD
149 if (flags & wxNO_DEFAULT)
150 {
151 if (no)
152 {
153 no->SetDefault();
154 no->SetFocus();
155 }
156 }
157 else
92afa2b1
RR
158 {
159 if (ok)
160 {
161 ok->SetDefault();
162 ok->SetFocus();
163 }
164 else if (yes)
165 {
166 yes->SetDefault();
167 yes->SetFocus();
168 }
169 }
b730516c 170
92afa2b1 171 return box;
e37feda2
VZ
172}
173