filterpanel.cpp

00001 
00002 // Name:        filterpanel.cpp
00003 // Purpose:     wxPackageFilterPanel
00004 // Author:      Julian Smart, Francesco Montorsi
00005 // Modified by:
00006 // Created:     04/06/2006 11:57:15
00007 // RCS-ID:      $Id: filterpanel.cpp,v 1.2 2007/01/01 20:06:21 frm Exp $
00008 // Copyright:   (c) 2004 Francesco Montorsi
00009 // Licence:     wxWidgets license
00011 
00012 
00013 // For compilers that support precompilation, includes "wx/wx.h".
00014 #include "wx/wxprec.h"
00015 
00016 #ifdef __BORLANDC__
00017 #pragma hdrstop
00018 #endif
00019 
00020 #ifndef WX_PRECOMP
00021 #include "wx/wx.h"
00022 #endif
00023 
00024 #include "guipm/filterpanel.h"
00025 #include "wxp/package.h"
00026 #include <wx/tokenzr.h>
00027 
00028 
00029 // ----------------------------------------------------------------------------
00030 // wxPackageFilterPanel
00031 // ----------------------------------------------------------------------------
00032 
00033 IMPLEMENT_DYNAMIC_CLASS( wxPackageFilterPanel, wxPanel )
00034 DEFINE_EVENT_TYPE(wxEVT_COMMAND_FILTER_PACKAGES)
00035 BEGIN_EVENT_TABLE( wxPackageFilterPanel, wxPanel )
00036     EVT_TEXT_ENTER(ID_FILTER_KEYWORDS, wxPackageFilterPanel::OnFilterUpdate)
00037     EVT_TEXT(ID_FILTER_KEYWORDS, wxPackageFilterPanel::OnFilterUpdate)
00038     EVT_CHOICE(wxID_ANY, wxPackageFilterPanel::OnFilterUpdate)
00039 END_EVENT_TABLE()
00040 
00041 wxPackageFilterPanel::wxPackageFilterPanel( )
00042 {
00043 }
00044 
00045 wxPackageFilterPanel::wxPackageFilterPanel( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
00046 {
00047     Create(parent, id, pos, size, style);
00048 }
00049 
00050 bool wxPackageFilterPanel::Create( wxWindow* parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style )
00051 {
00052     SetExtraStyle(GetExtraStyle()|wxWS_EX_BLOCK_EVENTS);
00053     wxPanel::Create( parent, id, pos, size, style );
00054 
00055     CreateControls();
00056     GetSizer()->Fit(this);
00057     GetSizer()->SetSizeHints(this);
00058 
00059     return true;
00060 }
00061 
00062 void wxPackageFilterPanel::CreateControls()
00063 {
00064     wxPackageFilterPanel* itemPanel1 = this;
00065 
00066     wxStaticBox* itemStaticBoxSizer2Static = new wxStaticBox(itemPanel1, wxID_ANY, _("Filters"));
00067     wxStaticBoxSizer* itemStaticBoxSizer2 = new wxStaticBoxSizer(itemStaticBoxSizer2Static, wxVERTICAL);
00068     itemPanel1->SetSizer(itemStaticBoxSizer2);
00069 
00070     wxFlexGridSizer* itemFlexGridSizer3 = new wxFlexGridSizer(2, 2, 0, 0);
00071     itemFlexGridSizer3->AddGrowableCol(1);
00072     itemStaticBoxSizer2->Add(itemFlexGridSizer3, 1, wxGROW, 5);
00073 
00074     wxStaticText* itemStaticText4 = new wxStaticText( itemPanel1, wxID_STATIC, _("Platform:"), wxDefaultPosition, wxDefaultSize, 0 );
00075     itemFlexGridSizer3->Add(itemStaticText4, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
00076 
00077     m_pSupportedPort = new wxChoice( itemPanel1, ID_FILTER_SUPPORTED_WXPORT, wxDefaultPosition, wxDefaultSize, 0, NULL, 0 );
00078     itemFlexGridSizer3->Add(m_pSupportedPort, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
00079 
00080     wxStaticText* itemStaticText6 = new wxStaticText( itemPanel1, wxID_STATIC, _("Category:"), wxDefaultPosition, wxDefaultSize, 0 );
00081     itemFlexGridSizer3->Add(itemStaticText6, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
00082 
00083     m_pCategory = new wxChoice( itemPanel1, ID_FILTER_CATEGORY, wxDefaultPosition, wxDefaultSize, wxPC_MAX, wxPackageCategoryName, 0 );
00084     itemFlexGridSizer3->Add(m_pCategory, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
00085 
00086     wxStaticText* itemStaticText8 = new wxStaticText( itemPanel1, wxID_STATIC, _("&Keywords:"), wxDefaultPosition, wxDefaultSize, 0 );
00087     itemFlexGridSizer3->Add(itemStaticText8, 0, wxALIGN_CENTER_HORIZONTAL|wxALIGN_CENTER_VERTICAL|wxALL|wxADJUST_MINSIZE, 5);
00088 
00089     m_pKeywords = new wxTextCtrl( itemPanel1, ID_FILTER_KEYWORDS, _T(""), wxDefaultPosition, wxDefaultSize, 0 );
00090     itemFlexGridSizer3->Add(m_pKeywords, 0, wxGROW|wxALIGN_CENTER_VERTICAL|wxALL, 5);
00091 
00092     for (size_t i=0; i<wxPORT_MAX; i++)
00093         m_pSupportedPort->Append(wxPlatformInfo::GetPortIdName((wxPortId)(1 << i), false));
00094 
00095     // NB: the "any" values will be mapped to the wxPC_MAX and wxPORT_MAX values
00096 
00097     m_pSupportedPort->Append(_("Any"));
00098     m_pSupportedPort->SetStringSelection(_("Any"));
00099 
00100     m_pCategory->Append(_("Any"));
00101     m_pCategory->SetStringSelection(_("Any"));
00102 }
00103 
00104 bool wxPackageFilterPanel::IsToPreserve(const wxPackage &p) const
00105 {
00106 #define wxPORT_ANY            (1 << wxPORT_MAX)
00107 
00108     // wxPackagePlatform enum values are power of two
00109     // since they can be combined with OR
00110     wxPortId port = (wxPortId)(1 << m_pSupportedPort->GetCurrentSelection());
00111     if (port != wxPORT_ANY &&
00112         (p.GetSupportedPortFlag() & port) == 0)
00113         return false;
00114 
00115     wxPackageCategory cat = (wxPackageCategory)m_pCategory->GetCurrentSelection();
00116     if (cat != wxPC_MAX &&
00117         p.GetPrimaryCategory() != cat &&
00118         p.GetSecondaryCategory() != cat)
00119         return false;
00120 
00121     // all keywords should be present
00122     wxArrayString arr = wxString2Array(m_pKeywords->GetValue());
00123     for (size_t i=0; i<arr.GetCount(); i++)
00124         if (!p.GetKeywordsStr().Contains(arr[i]))
00125             return false;
00126 
00127     // all checks were passed
00128     return true;
00129 }
00130 
00131 
00132 // ----------------------------------------------------------------------------
00133 // wxPackageFilterPanel - event handlers
00134 // ----------------------------------------------------------------------------
00135 
00136 void wxPackageFilterPanel::OnFilterUpdate(wxCommandEvent & WXUNUSED(ev))
00137 {
00138     // tell our owner that it needs to refilter the packages
00139     wxCommandEvent update(wxEVT_COMMAND_FILTER_PACKAGES, GetId());
00140 
00141     // NB: we must send the event to the parent not to GetEventHandler()!
00142     GetParent()->AddPendingEvent(update);
00143 }

Generated on Thu Feb 1 22:14:31 2007 for wxWidgets Package Manager by  doxygen 1.5.1-p1