]>
git.saurik.com Git - wxWidgets.git/blob - src/generic/textdlgg.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxTextEntryDialog
4 // Author: Julian Smart
8 // Copyright: (c) Julian Smart and Markus Holzem
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "textdlgg.h"
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
26 #include "wx/dialog.h"
27 #include "wx/button.h"
28 #include "wx/stattext.h"
29 #include "wx/textctrl.h"
34 #include "wx/statline.h"
37 #include "wx/generic/textdlgg.h"
39 /* Split message, using constraints to position controls */
40 static wxSize
wxSplitMessage2( const wxString
&message
, wxWindow
*parent
)
44 wxString
line( _T("") );
45 for (uint pos
= 0; pos
< message
.Len(); pos
++)
47 if (message
[pos
] == _T('\n'))
51 wxStaticText
*s1
= new wxStaticText( parent
, -1, line
, wxPoint(15,y
) );
52 wxSize
size1( s1
->GetSize() );
53 if (size1
.x
> w
) w
= size1
.x
;
66 wxStaticText
*s2
= new wxStaticText( parent
, -1, line
, wxPoint(15,y
) );
67 wxSize
size2( s2
->GetSize() );
68 if (size2
.x
> w
) w
= size2
.x
;
73 return wxSize(w
+30,y
);
78 #if !USE_SHARED_LIBRARY
79 BEGIN_EVENT_TABLE(wxTextEntryDialog
, wxDialog
)
80 EVT_BUTTON(wxID_OK
, wxTextEntryDialog::OnOK
)
83 IMPLEMENT_CLASS(wxTextEntryDialog
, wxDialog
)
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
)
90 m_dialogStyle
= style
;
95 wxSize
message_size( wxSplitMessage2( message
, this ) );
97 wxButton
*ok
= (wxButton
*) NULL
;
98 wxButton
*cancel
= (wxButton
*) NULL
;
101 int y
= message_size
.y
+ 15;
103 wxTextCtrl
*textCtrl
= new wxTextCtrl(this, wxID_TEXT
, value
, wxPoint(-1, y
), wxSize(350, -1));
109 ok
= new wxButton( this, wxID_OK
, _("OK"), wxPoint(-1,y
), wxSize(80,-1) );
110 m_buttons
.Append( ok
);
113 if (style
& wxCANCEL
)
115 cancel
= new wxButton( this, wxID_CANCEL
, _("Cancel"), wxPoint(-1,y
), wxSize(80,-1) );
116 m_buttons
.Append( cancel
);
125 int w
= wxMax( 350, m_buttons
.GetCount() * 100 );
126 w
= wxMax( w
, message_size
.x
);
127 int space
= w
/ (m_buttons
.GetCount()*2);
129 textCtrl
->SetSize( 20, -1, w
-10, -1 );
132 wxNode
*node
= m_buttons
.First();
135 wxWindow
*win
= (wxWindow
*)node
->Data();
136 int x
= (m
*2+1)*space
- 40 + 15;
143 (void) new wxStaticLine( this, -1, wxPoint(0,y
-20), wxSize(w
+30, 5) );
146 SetSize( w
+30, y
+40 );
154 void wxTextEntryDialog::OnOK(wxCommandEvent
& WXUNUSED(event
) )
156 wxTextCtrl
*textCtrl
= (wxTextCtrl
*)FindWindow(wxID_TEXT
);
158 m_value
= textCtrl
->GetValue();