]>
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/listbox.h"
28 #include "wx/button.h"
29 #include "wx/stattext.h"
30 #include "wx/textctrl.h"
31 #include "wx/layout.h"
35 #include "wx/generic/textdlgg.h"
39 #if !USE_SHARED_LIBRARY
40 BEGIN_EVENT_TABLE(wxTextEntryDialog
, wxDialog
)
41 EVT_BUTTON(wxID_OK
, wxTextEntryDialog::OnOK
)
44 IMPLEMENT_CLASS(wxTextEntryDialog
, wxDialog
)
47 // Split message, using constraints to position controls
48 static void wxSplitMessage2(const char *message
, wxList
*messageList
, wxWindow
*parent
, wxRowColSizer
*sizer
)
50 char *copyMessage
= copystring(message
);
52 size_t len
= strlen(copyMessage
);
53 char *currentMessage
= copyMessage
;
55 // wxWindow *lastWindow = parent;
58 while ((i
< len
) && (copyMessage
[i
] != '\n')) i
++;
59 if (i
< len
) copyMessage
[i
] = 0;
60 wxStaticText
*mess
= new wxStaticText(parent
, -1, currentMessage
);
63 wxLayoutConstraints *c = new wxLayoutConstraints;
64 c->left.SameAs (parent, wxLeft, 10);
65 c->top.SameAs (lastWindow, wxBottom, 5);
69 mess->SetConstraints(c);
71 sizer
->AddSizerChild(mess
);
73 messageList
->Append(mess
);
75 currentMessage
= copyMessage
+ i
+ 1;
80 wxTextEntryDialog::wxTextEntryDialog(wxWindow
*parent
, const wxString
& message
, const wxString
& caption
,
81 const wxString
& value
, long style
, const wxPoint
& pos
):
82 wxDialog(parent
, -1, caption
, pos
, wxDefaultSize
, wxDEFAULT_DIALOG_STYLE
|wxDIALOG_MODAL
)
84 m_dialogStyle
= style
;
89 wxSizer
*topSizer
= new wxSizer(this, wxSizerShrink
);
90 topSizer
->SetBorder(10, 10);
92 wxRowColSizer
*messageSizer
= new wxRowColSizer(topSizer
, wxSIZER_COLS
, 100);
93 messageSizer
->SetName("messageSizer");
95 // bool centre = ((style & wxCENTRE) == wxCENTRE);
98 wxSplitMessage2(message
, &messageList
, this, messageSizer
);
101 wxSpacingSizer
*spacingSizer
= new wxSpacingSizer(topSizer
, wxBelow
, messageSizer
, 10);
103 wxTextCtrl
*textCtrl
= new wxTextCtrl(this, wxID_TEXT
, value
, wxPoint(-1, -1), wxSize(350, -1));
105 wxRowColSizer
*textSizer
= new wxRowColSizer(topSizer
, wxSIZER_ROWS
);
106 textSizer
->AddSizerChild(textCtrl
);
107 textSizer
->SetName("textSizer");
109 // Create constraints for the text sizer
110 wxLayoutConstraints
*textC
= new wxLayoutConstraints
;
111 textC
->left
.SameAs (messageSizer
, wxLeft
);
112 textC
->top
.Below (spacingSizer
);
113 textSizer
->SetConstraints(textC
);
115 // Insert another spacer
116 wxSpacingSizer
*spacingSizer2
= new wxSpacingSizer(topSizer
, wxBelow
, textSizer
, 10);
117 spacingSizer
->SetName("spacingSizer2");
119 // Insert a sizer for the buttons
120 wxRowColSizer
*buttonSizer
= new wxRowColSizer(topSizer
, wxSIZER_ROWS
);
121 buttonSizer
->SetName("buttonSizer");
123 // Specify constraints for the button sizer
124 wxLayoutConstraints
*c
= new wxLayoutConstraints
;
127 c
->top
.Below (spacingSizer2
);
128 c
->centreX
.SameAs (textSizer
, wxCentreX
);
129 buttonSizer
->SetConstraints(c
);
130 buttonSizer
->SetSpacing(12,0);
133 wxButton
*cancel
= NULL
;
136 ok
= new wxButton(this, wxID_OK
, _("OK"), wxDefaultPosition
, wxSize(75,-1));
137 buttonSizer
->AddSizerChild(ok
);
140 if (style
& wxCANCEL
) {
141 cancel
= new wxButton(this, wxID_CANCEL
, _("Cancel"), wxDefaultPosition
, wxSize(75,-1));
142 buttonSizer
->AddSizerChild(cancel
);
154 void wxTextEntryDialog::OnOK(wxCommandEvent
& WXUNUSED(event
) )
156 wxTextCtrl
*textCtrl
= (wxTextCtrl
*)FindWindow(wxID_TEXT
);
158 m_value
= textCtrl
->GetValue();