Small changed to wxExtDialog
[wxWidgets.git] / src / gtk / textdlg.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: textdlgg.cpp
3 // Purpose: wxTextEntryDialog
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 04/01/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "textdlgg.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include <stdio.h>
25 #include "wx/utils.h"
26 #include "wx/dialog.h"
27 #include "wx/button.h"
28 #include "wx/stattext.h"
29 #include "wx/textctrl.h"
30 #include "wx/intl.h"
31 #endif
32
33 #if wxUSE_STATLINE
34 #include "wx/statline.h"
35 #endif
36
37 #include "wx/gtk/textdlg.h"
38
39 /* Split message, using constraints to position controls */
40 static wxSize wxSplitMessage2( const wxString &message, wxWindow *parent )
41 {
42 int y = 10;
43 int w = 50;
44 wxString line( _T("") );
45 for (size_t pos = 0; pos < message.Len(); pos++)
46 {
47 if (message[pos] == _T('\n'))
48 {
49 if (!line.IsEmpty())
50 {
51 wxStaticText *s1 = new wxStaticText( parent, -1, line, wxPoint(15,y) );
52 wxSize size1( s1->GetSize() );
53 if (size1.x > w) w = size1.x;
54 line = _T("");
55 }
56 y += 18;
57 }
58 else
59 {
60 line += message[pos];
61 }
62 }
63
64 if (!line.IsEmpty())
65 {
66 wxStaticText *s2 = new wxStaticText( parent, -1, line, wxPoint(15,y) );
67 wxSize size2( s2->GetSize() );
68 if (size2.x > w) w = size2.x;
69 }
70
71 y += 18;
72
73 return wxSize(w+30,y);
74 }
75
76 // wxTextEntryDialog
77
78 #if !USE_SHARED_LIBRARY
79 BEGIN_EVENT_TABLE(wxTextEntryDialog, wxDialog)
80 EVT_BUTTON(wxID_OK, wxTextEntryDialog::OnOK)
81 END_EVENT_TABLE()
82
83 IMPLEMENT_CLASS(wxTextEntryDialog, wxDialog)
84 #endif
85
86 wxTextEntryDialog::wxTextEntryDialog(wxWindow *parent, const wxString& message, const wxString& caption,
87 const wxString& value, long style, const wxPoint& pos):
88 wxDialog(parent, -1, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL|wxTAB_TRAVERSAL)
89 {
90 m_dialogStyle = style;
91 m_value = value;
92
93 wxBeginBusyCursor();
94
95 wxSize message_size( wxSplitMessage2( message, this ) );
96
97 wxButton *ok = (wxButton *) NULL;
98 wxButton *cancel = (wxButton *) NULL;
99 wxList m_buttons;
100
101 int y = message_size.y + 15;
102
103 wxTextCtrl *textCtrl = new wxTextCtrl(this, wxID_TEXT, value, wxPoint(-1, y), wxSize(350, -1));
104
105 y += 65;
106
107 if (style & wxOK)
108 {
109 ok = new wxButton( this, wxID_OK, _("OK"), wxPoint(-1,y), wxSize(80,-1) );
110 m_buttons.Append( ok );
111 }
112
113 if (style & wxCANCEL)
114 {
115 cancel = new wxButton( this, wxID_CANCEL, _("Cancel"), wxPoint(-1,y), wxSize(80,-1) );
116 m_buttons.Append( cancel );
117 }
118
119 if (ok)
120 {
121 ok->SetDefault();
122 ok->SetFocus();
123 }
124
125 int w = wxMax( 350, m_buttons.GetCount() * 100 );
126 w = wxMax( w, message_size.x );
127 int space = w / (m_buttons.GetCount()*2);
128
129 textCtrl->SetSize( 20, -1, w-10, -1 );
130
131 int m = 0;
132 wxNode *node = m_buttons.First();
133 while (node)
134 {
135 wxWindow *win = (wxWindow*)node->Data();
136 int x = (m*2+1)*space - 40 + 15;
137 win->Move( x, -1 );
138 node = node->Next();
139 m++;
140 }
141
142 #if wxUSE_STATLINE
143 (void) new wxStaticLine( this, -1, wxPoint(0,y-20), wxSize(w+30, 5) );
144 #endif
145
146 SetSize( w+30, y+40 );
147
148 Centre( wxBOTH );
149
150
151 wxEndBusyCursor();
152 }
153
154 void wxTextEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event) )
155 {
156 wxTextCtrl *textCtrl = (wxTextCtrl *)FindWindow(wxID_TEXT);
157 if ( textCtrl )
158 m_value = textCtrl->GetValue();
159
160 EndModal(wxID_OK);
161 }
162