Updates for makefile.unx
[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 #include "wx/sizer.h"
32 #endif
33
34 #if wxUSE_STATLINE
35 #include "wx/statline.h"
36 #endif
37
38 #include "wx/gtk/textdlg.h"
39
40 static void wxSplitMessage2( const wxString &message, wxWindow *parent, wxSizer* sizer )
41 {
42 wxString line;
43 for (size_t pos = 0; pos < message.Len(); pos++)
44 {
45 if (message[pos] == _T('\n'))
46 {
47 if (!line.IsEmpty())
48 {
49 wxStaticText *s1 = new wxStaticText( parent, -1, line );
50 sizer->Add( s1 );
51 line = _T("");
52 }
53 }
54 else
55 {
56 line += message[pos];
57 }
58 }
59
60 // remaining text behind last '\n'
61 if (!line.IsEmpty())
62 {
63 wxStaticText *s2 = new wxStaticText( parent, -1, line );
64 sizer->Add( s2 );
65 }
66 }
67
68 // wxTextEntryDialog
69
70 #if !USE_SHARED_LIBRARY
71 BEGIN_EVENT_TABLE(wxTextEntryDialog, wxDialog)
72 EVT_BUTTON(wxID_OK, wxTextEntryDialog::OnOK)
73 END_EVENT_TABLE()
74
75 IMPLEMENT_CLASS(wxTextEntryDialog, wxDialog)
76 #endif
77
78 wxTextEntryDialog::wxTextEntryDialog(wxWindow *parent, const wxString& message, const wxString& caption,
79 const wxString& value, long style, const wxPoint& pos):
80 wxDialog(parent, -1, caption, pos, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxDIALOG_MODAL|wxTAB_TRAVERSAL)
81 {
82 m_dialogStyle = style;
83 m_value = value;
84
85 wxBeginBusyCursor();
86
87 wxBox *topsizer = new wxBox( wxVERTICAL );
88
89 // 1) text message
90 wxBox *textsizer = new wxBox( wxVERTICAL );
91 wxSplitMessage2( message, this, textsizer );
92 topsizer->Add( textsizer, 0, wxALL, 10 );
93
94 // 2) text ctrl
95 wxTextCtrl *textCtrl = new wxTextCtrl(this, wxID_TEXT, value, wxDefaultPosition, wxSize(300, -1));
96 topsizer->Add( textCtrl, 1, wxEXPAND | wxLEFT|wxRIGHT, 15 );
97
98 #if wxUSE_STATLINE
99 // 3) static line
100 topsizer->Add( new wxStaticLine( this, -1 ), 0, wxEXPAND | wxLEFT|wxRIGHT|wxTOP, 10 );
101 #endif
102
103
104 // 4) buttons
105 wxBox *buttonsizer = new wxBox( wxHORIZONTAL );
106
107 wxButton *ok = (wxButton *) NULL;
108 if (style & wxOK)
109 {
110 ok = new wxButton( this, wxID_OK, _("OK") );
111 buttonsizer->Add( ok, 0, wxLEFT|wxRIGHT, 10 );
112 }
113
114 wxButton *cancel = (wxButton *) NULL;
115 if (style & wxCANCEL)
116 {
117 cancel = new wxButton( this, wxID_CANCEL, _("Cancel") );
118 buttonsizer->Add( cancel, 0, wxLEFT|wxRIGHT, 10 );
119 }
120
121 topsizer->Add( buttonsizer, 0, wxCENTRE | wxALL, 10 );
122
123 topsizer->SetSizeHints( this );
124 topsizer->Fit( this );
125 SetSizer( topsizer );
126 SetAutoLayout( TRUE );
127
128 Centre( wxBOTH );
129
130 if (ok)
131 ok->SetDefault();
132
133 textCtrl->SetFocus();
134
135 wxEndBusyCursor();
136 }
137
138 void wxTextEntryDialog::OnOK(wxCommandEvent& WXUNUSED(event) )
139 {
140 wxTextCtrl *textCtrl = (wxTextCtrl *)FindWindow(wxID_TEXT);
141 if ( textCtrl )
142 m_value = textCtrl->GetValue();
143
144 EndModal(wxID_OK);
145 }
146