1 //####COPYRIGHTBEGIN####
3 // ----------------------------------------------------------------------------
4 // Copyright (C) 1998, 1999, 2000 Red Hat, Inc.
6 // This program is part of the eCos host tools.
8 // This program is free software; you can redistribute it and/or modify it
9 // under the terms of the GNU General Public License as published by the Free
10 // Software Foundation; either version 2 of the License, or (at your option)
13 // This program is distributed in the hope that it will be useful, but WITHOUT
14 // ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 // FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
18 // You should have received a copy of the GNU General Public License along with
19 // this program; if not, write to the Free Software Foundation, Inc.,
20 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 // ----------------------------------------------------------------------------
24 //####COPYRIGHTEND####
27 //===========================================================================
28 //#####DESCRIPTIONBEGIN####
31 // Contact(s): julians
35 // Description: Implementation file for ecFindDialog
42 //####DESCRIPTIONEND####
44 //===========================================================================
47 #pragma implementation "finddlg.cpp"
56 #include "wx/cshelp.h"
57 #include "wx/valgen.h"
60 #include "configtool.h"
61 #include "configtooldoc.h"
62 #include "configtoolview.h"
63 #include "configtree.h"
65 #include "appsettings.h"
67 //----------------------------------------------------------------------------
69 //----------------------------------------------------------------------------
71 BEGIN_EVENT_TABLE(ecFindDialog,wxDialog)
72 EVT_BUTTON(ecID_FIND_DIALOG_NEXT, ecFindDialog::OnFindNext)
73 EVT_CLOSE(ecFindDialog::OnCloseWindow)
74 EVT_BUTTON(wxID_CANCEL, ecFindDialog::OnCancel)
77 ecFindDialog::ecFindDialog( wxWindow *parent, wxWindowID id, const wxString &title,
78 const wxPoint &position, const wxSize& size, long style ) :
81 m_directionSelection = 1;
83 SetExtraStyle(wxDIALOG_EX_CONTEXTHELP);
85 wxDialog::Create( parent, id, title, position, size, style );
89 if (wxGetApp().GetSettings().m_findDialogPos.x == -1 && wxGetApp().GetSettings().m_findDialogPos.y == -1)
92 Move(wxGetApp().GetSettings().m_findDialogPos);
95 bool ecFindDialog::AddControls(wxWindow* parent)
97 //// Start of sizer-based control creation
99 wxSizer *item0 = new wxBoxSizer( wxHORIZONTAL );
101 wxSizer *item1 = new wxBoxSizer( wxVERTICAL );
103 wxSizer *item2 = new wxBoxSizer( wxHORIZONTAL );
105 wxStaticText *item3 = new wxStaticText( parent, wxID_STATIC, _(" Fi&nd what:"), wxDefaultPosition, wxDefaultSize, 0 );
106 item2->Add( item3, 0, wxALIGN_CENTRE|wxLEFT|wxTOP|wxBOTTOM, 5 );
108 wxTextCtrl *item4 = new wxTextCtrl( parent, ecID_FIND_DIALOG_WHAT, _(""), wxDefaultPosition, wxSize(200,-1), 0 );
109 item2->Add( item4, 1, wxALIGN_CENTRE|wxALL, 5 );
111 item1->Add( item2, 1, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 0 );
113 wxSizer *item5 = new wxBoxSizer( wxHORIZONTAL );
115 wxSizer *item6 = new wxBoxSizer( wxVERTICAL );
117 wxCheckBox *item7 = new wxCheckBox( parent, ecID_FIND_DIALOG_MATCH_WHOLE, _("Match &whole word only"), wxDefaultPosition, wxDefaultSize, 0 );
118 item6->Add( item7, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
120 wxCheckBox *item8 = new wxCheckBox( parent, ecID_FIND_DIALOG_MATCH_CASE, _("Match &case"), wxDefaultPosition, wxDefaultSize, 0 );
121 item6->Add( item8, 0, wxALIGN_CENTER_VERTICAL|wxALL, 5 );
123 item5->Add( item6, 0, wxALIGN_CENTRE|wxALL, 5 );
130 wxRadioBox *item9 = new wxRadioBox( parent, ecID_FIND_DIALOG_DIRECTION, _("Direction"), wxDefaultPosition, wxDefaultSize, 2, strs9, 1, wxRA_SPECIFY_ROWS );
131 item5->Add( item9, 0, wxALIGN_CENTRE|wxALL, 5 );
133 item1->Add( item5, 0, wxALIGN_CENTRE|wxRIGHT, 5 );
135 wxSizer *item10 = new wxBoxSizer( wxHORIZONTAL );
137 wxStaticText *item11 = new wxStaticText( parent, wxID_STATIC, _("&Search in:"), wxDefaultPosition, wxDefaultSize, 0 );
138 item10->Add( item11, 0, wxALIGN_CENTRE|wxALL, 5 );
144 _("Short descriptions"),
148 wxChoice *item12 = new wxChoice( parent, ecID_FIND_DIALOG_SEARCH_IN, wxDefaultPosition, wxSize(130,-1), 5, strs12, 0 );
149 item10->Add( item12, 0, wxALIGN_CENTRE|wxALL, 5 );
151 item1->Add( item10, 0, wxALIGN_CENTER_VERTICAL|wxLEFT|wxRIGHT, 5 );
153 item0->Add( item1, 0, wxALIGN_CENTRE|wxTOP|wxBOTTOM, 5 );
155 wxSizer *item13 = new wxBoxSizer( wxVERTICAL );
157 wxButton *item14 = new wxButton( parent, ecID_FIND_DIALOG_NEXT, _("&Find Next"), wxDefaultPosition, wxDefaultSize, 0 );
158 item14->SetDefault();
159 item13->Add( item14, 0, wxALIGN_CENTRE|wxALL, 5 );
161 wxButton *item15 = new wxButton( parent, wxID_CANCEL, _("&Close"), wxDefaultPosition, wxDefaultSize, 0 );
162 item13->Add( item15, 0, wxALIGN_CENTRE|wxALL, 5 );
165 wxButton *contextButton = new wxContextHelpButton( parent );
166 item13->Add( contextButton, 0, wxALIGN_CENTRE|wxALL, 5 );
169 item0->Add( item13, 0, wxALIGN_CENTER_HORIZONTAL|wxRIGHT|wxTOP|wxBOTTOM, 5 );
171 FindWindow(ecID_FIND_DIALOG_WHAT)->SetFocus();
174 FindWindow(ecID_FIND_DIALOG_WHAT)->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_findText));
175 FindWindow(ecID_FIND_DIALOG_MATCH_WHOLE)->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_findMatchWholeWord));
176 FindWindow(ecID_FIND_DIALOG_MATCH_CASE)->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_findMatchCase));
177 FindWindow(ecID_FIND_DIALOG_SEARCH_IN)->SetValidator(wxGenericValidator(& wxGetApp().GetSettings().m_findSearchWhat));
178 FindWindow(ecID_FIND_DIALOG_DIRECTION)->SetValidator(wxGenericValidator(& m_directionSelection));
181 FindWindow(ecID_FIND_DIALOG_WHAT)->SetHelpText(_("Enter your search text here."));
182 FindWindow(ecID_FIND_DIALOG_MATCH_WHOLE)->SetHelpText(_("Check to match whole words, clear to match parts of words."));
183 FindWindow(ecID_FIND_DIALOG_MATCH_CASE)->SetHelpText(_("Check if you want upper and lower case to be significant, clear otherwise."));
184 FindWindow(ecID_FIND_DIALOG_SEARCH_IN)->SetHelpText(_("Choose the category for your search."));
185 FindWindow(ecID_FIND_DIALOG_DIRECTION)->SetHelpText(_("Choose the direction of your search."));
186 FindWindow(ecID_FIND_DIALOG_NEXT)->SetHelpText(_("Click Find Next to search for the next match."));
187 FindWindow(wxID_CANCEL)->SetHelpText(_("Click Close to close the dialog."));
189 parent->SetAutoLayout( TRUE );
190 parent->SetSizer( item0 );
192 item0->Fit( parent );
193 item0->SetSizeHints( parent );
197 bool ecFindDialog::TransferDataToWindow()
199 // Convert to radiobox selection index from bool
200 m_directionSelection = wxGetApp().GetSettings().m_findDirection ? 1 : 0 ;
202 wxWindow::TransferDataToWindow();
207 bool ecFindDialog::TransferDataFromWindow()
209 wxWindow::TransferDataFromWindow();
211 // Convert from radiobox selection index to bool
212 wxGetApp().GetSettings().m_findDirection = (m_directionSelection == 1);
217 void ecFindDialog::OnFindNext(wxCommandEvent& event)
219 if (!TransferDataFromWindow())
221 if (!wxGetApp().GetConfigToolDoc())
224 ecConfigToolView *pControlView = (ecConfigToolView*) wxGetApp().GetConfigToolDoc()->GetFirstView();
226 ecConfigItem* item = pControlView->DoFind(wxGetApp().GetSettings().m_findText, this);
230 // Is the find window on top of the item?
233 if (wxGetApp().GetTreeCtrl()->GetBoundingRect(item->GetTreeItem(), rect1))
235 wxPoint topLeft(rect1.x, rect1.y);
236 wxPoint bottomRight(rect1.GetRight(), rect1.GetBottom());
238 topLeft = wxGetApp().GetTreeCtrl()->ClientToScreen(topLeft);
239 bottomRight = wxGetApp().GetTreeCtrl()->ClientToScreen(bottomRight);
241 rect2 = GetRect(); // screen coords
243 if (rect2.Inside(topLeft) || rect2.Inside(bottomRight))
245 Move(wxPoint(topLeft.x + rect1.width, rect2.y));
251 void ecFindDialog::OnCloseWindow(wxCloseEvent& event)
253 wxGetApp().GetSettings().m_findDialogPos = GetPosition();
254 wxGetApp().GetMainFrame()->m_findDialog = NULL;
259 void ecFindDialog::OnCancel(wxCommandEvent& event)
261 wxGetApp().GetSettings().m_findDialogPos = GetPosition();
262 wxGetApp().GetMainFrame()->m_findDialog = NULL;