GME  13
SearchDlg.h
Go to the documentation of this file.
00001 #if !defined(AFX_SEARCHDLG_H__E59A9A8F_05E1_48EB_BB09_897251FD3943__INCLUDED_)
00002 #define AFX_SEARCHDLG_H__E59A9A8F_05E1_48EB_BB09_897251FD3943__INCLUDED_
00003 
00004 #if _MSC_VER > 1000
00005 #pragma once
00006 #endif // _MSC_VER > 1000
00007 
00008 class CSearchCtrl;
00009 
00010 #include "ComHelp.h"
00011 #include "afxwin.h"
00012 #include "afxcmn.h"
00013 #include <vector>
00014 #include <algorithm>
00015 // SearchDlg.h : header file
00016 //
00017 
00019 // CSearchDlg dialog
00020 
00021 class CSearchDropTarget : public COleDropTarget
00022 {
00023 public:
00024         virtual DROPEFFECT OnDragEnter(CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
00025         virtual void OnDragLeave(CWnd* pWnd);
00026         virtual DROPEFFECT OnDragOver(CWnd* pWnd, COleDataObject* pDataObject, DWORD dwKeyState, CPoint point);
00027         virtual BOOL OnDrop(CWnd* pWnd, COleDataObject* pDataObject, DROPEFFECT dropEffect, CPoint point);
00028 };
00029 
00030 //struct used for sending information to sort function usd by List Control
00031 
00032 struct SortParam
00033 {
00034     CListCtrl * listCtrl;
00035     bool ascending;
00036     int columnIndex;
00037     SortParam(CListCtrl *listCtrl,int columnIndex, bool ascending)
00038     {
00039         this->listCtrl=listCtrl;
00040         this->columnIndex=columnIndex;
00041         this->ascending=ascending;
00042     }
00043 };
00044 
00045 
00046 static int CALLBACK 
00047 ListItemCompareProc(LPARAM lParam1, LPARAM lParam2, LPARAM lParamSort)
00048 {
00049      // lParamSort contains a pointer to the sort parameters.
00050 
00051    SortParam* sortParam = (SortParam*) lParamSort;
00052    CListCtrl *pListCtrl=sortParam->listCtrl;
00053 
00054    //get the 2 items to be compared
00055    CString    strItem1 = pListCtrl->GetItemText(lParam1, sortParam->columnIndex);
00056    CString    strItem2 = pListCtrl->GetItemText(lParam2, sortParam->columnIndex);
00057 
00058    if(sortParam->ascending)
00059        return _tcscmp(strItem1,strItem2);
00060 
00061    return _tcscmp(strItem2, strItem1);
00062 }
00063 
00064 class AutocompleteComboBox : public CComboBox
00065 {
00066         CString m_previous;
00067         std::vector<CString> m_options;
00068 public:
00069         void SetOptions(std::vector<CString>&& options)
00070         {
00071                 m_options = std::move(options);
00072         }
00073         DECLARE_MESSAGE_MAP()
00074         void OnEditChange();
00075 protected:
00076         virtual LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
00077 };
00078 
00079 class CSearchDlg : public CDialog
00080 {
00081 // Construction
00082 public:
00083         CSearchDlg();   // standard constructor
00084     ~CSearchDlg();
00085         BOOL OnInitDialog();
00086 
00087 //  These functions should be implemented to work with CSearchCtl
00088         void RemoveAll();                                               // must remove all search result
00089         void RemoveZombies();                                   // must remove results belong to zombie objects
00090         void EnableSearch();                                    // enable search functions
00091         void DisableSearch();                                   // must disable search functions
00092         void EnableScoped( BOOL enable);
00093 
00094         inline CSearchCtrl* getMyParent() { return GetCtrl(); }
00095         void clickGo();
00096         void itemDblClicked();
00097         void itemClicked();
00098    
00099     //added -kiran
00100     void SaveSearchHistory();
00101     void LoadSearchHistory();
00102     void CreateSearchHistory();
00103 
00104     //virtual LRESULT WindowProc(UINT message,  WPARAM wParam, LPARAM lParam);
00105     //virtual BOOL PreTranslateMessage(MSG *pMsg);
00106 
00107 // Dialog Data
00108         //{{AFX_DATA(CSearchDlg)
00109         enum { IDD = IDD_SEARCH_DIALOG };
00110         //CStatic       m_stcRefCtrl;
00111         CProgressCtrl   m_pgsSearch;
00112 
00113         CString m_edtNameFirst;
00114         CString m_edtKindNameFirst;
00115         CString m_edtRoleNameFirst;
00116     CString     m_edtAttributeFirst;
00117         
00118     //remove
00119     CString     m_edtAttrValue;
00120 
00121     CString m_edtNameSecond;
00122     CString m_edtRoleNameSecond;
00123     CString m_edtKindNameSecond;
00124     CString m_edtAttributeSecond;
00125 
00126         BOOL    m_chkAtom;
00127         BOOL    m_chkFullWord;
00128         BOOL    m_chkMod;
00129         BOOL    m_chkRef;
00130         BOOL    m_chkSet;
00131         BOOL    m_chkLocate;
00132         BOOL    m_chkMatchCase;
00133         
00134         CButton m_chkMatchCaseCtrl;
00135         CButton m_chkFullWordCtrl;
00136         CButton m_chkRefCtrl;
00137         CButton m_chkAtomCtrl;
00138         CButton m_chkSetCtrl;
00139         CButton m_chkModCtrl;
00140         CComboBox       m_cmbCtrl;
00141         CButton m_btnGO;
00142         CListCtrl       m_lstResults;
00143     CTreeCtrl m_treeSearchHistory;
00144 
00145     //first search criteria controls
00146         CComboBox       m_edtNameCtrlFirst;
00147         AutocompleteComboBox m_edtKindNameCtrlFirst;
00148         CComboBox       m_edtRoleNameCtrlFirst;
00149         CComboBox       m_edtAttributeCtrlFirst;
00150         
00151     //second search criteria controls
00152     CComboBox m_edtNameCtrlSecond;
00153     CComboBox m_edtRoleNameCtrlSecond;
00154     AutocompleteComboBox m_edtKindNameCtrlSecond;
00155     CComboBox m_edtAttributeCtrlSecond;
00156      
00157     CButton m_logicalGrp;
00158     CComboBox m_cmbCtrl2;
00159     int m_radioScope;
00160     BOOL m_searchResults;
00161     int m_radioLogical;
00162 
00163     //sort indicators for four result columns
00164     bool ascending[4];
00165 
00166 private:
00167     //insert history to combobox
00168     void InsertHistory(CString string);
00169 
00170     //prepare history string by appending search term name and value pairs. value is enclose by quotes
00171     void PrepareHistoryString(const CString &strCriteriaName,CString & strSearchValue,HTREEITEM hParent,CString &strSearch);
00172     void PrepareHistoryString(const CString &strCriteriaName,int & strSearchValue,HTREEITEM hParent,CString &strSearch);
00173     
00174     //reverse of prepare extract search value from the saved string
00175     //string and int version with string extracting string value and int version extracting
00176     //integer values
00177     void ReadHistoryValue(const CString &strCriteriaName, CString &strHistory, CString &strValue);
00178     void ReadHistoryValue(const CString &strCriteriaName,CString &strHistory, int &value);
00179    
00180     //called to enter history text to combobox
00181     //checks first if it exists at the first index of items
00182     //if it does it is not inserted, else inserted
00183     void InsertTextToControl(CString& strSearchTerm,CComboBox& control);
00184 
00185     
00186         //}}AFX_DATA
00187 
00188 // Overrides
00189         // ClassWizard generated virtual function overrides
00190         //{{AFX_VIRTUAL(CSearchDlg)
00191         protected:
00192         virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
00193         //}}AFX_VIRTUAL
00194 
00195 // Implementation
00196 protected:
00197         
00198     CSearchCtrl *GetCtrl() { return (CSearchCtrl*)GetParent(); }
00199         void BuildExtendedName(IMgaFCO *named, CString &extName);
00200         void BuildExtendedName(IMgaFolder *named, CString &extName);
00201         void DisplayResults();
00202     void SearchResults();
00203    
00204         CComPtr<IMgaFCOs> results;
00205         CComPtr<IMgaFCO> specialSearchFCO;
00206 public:
00207         void GetKinds(CComPtr<IMgaProject>& project)
00208         {
00209                 std::vector<CString> kinds;
00210                 CComPtr<IMgaMetaProject> meta;
00211                 project->get_RootMeta(&meta);
00212                 CComPtr<IMgaMetaFolder> root;
00213                 meta->get_RootFolder(&root);
00214                 CComPtr<IMgaMetaFCOs> metaFCOs;
00215                 root->get_DefinedFCOs(&metaFCOs);
00216                 MGACOLL_ITERATE(IMgaMetaFCO, metaFCOs)
00217                 {
00218                         _bstr_t name;
00219                         MGACOLL_ITER->get_Name(name.GetAddress());
00220                         kinds.push_back(CString(static_cast<const wchar_t*>(name)));
00221                 } MGACOLL_ITERATE_END;
00222                 std::sort(kinds.begin(), kinds.end());
00223                 m_edtKindNameCtrlFirst.SetOptions(std::vector<CString>(kinds));
00224                 m_edtKindNameCtrlSecond.SetOptions(std::move(kinds));
00225         }
00226 
00227         template<typename F>
00228         void ForEachSelectedFCO(F f)
00229         {
00230                 POSITION pos = m_lstResults.GetFirstSelectedItemPosition();
00231                 while (pos)
00232                 {
00233                         int nItem = m_lstResults.GetNextSelectedItem(pos);
00234                         long lParam = m_lstResults.GetItemData(nItem);
00235                         CComPtr<IMgaFCO> selected;
00236                         COMTHROW(results->get_Item(lParam + 1, &selected));
00237                         f(selected);
00238                 }
00239         }
00240 
00241 protected:
00242         BOOL m_scopedCtrlEnabled; // whether to enable scoped search at all
00243 
00244 
00245         // Generated message map functions
00246         //{{AFX_MSG(CSearchDlg)
00247         afx_msg void OnButtonGo();
00248         afx_msg void OnClickListResults(NMHDR* pNMHDR, LRESULT* pResult);
00249         afx_msg void OnDblclkListResults(NMHDR* pNMHDR, LRESULT* pResult);
00250         afx_msg void OnKeyDownListResults(NMHDR* pNMHDR, LRESULT* pResult);
00251         //}}AFX_MSG
00252         DECLARE_MESSAGE_MAP()
00253 
00254         friend class CSearchDropTarget;
00255         CSearchDropTarget dropTarget;
00256 public:
00257         afx_msg void OnSize(UINT nType, int cx, int cy);
00258         afx_msg void OnSizing(UINT fwSide, LPRECT pRect);
00259     afx_msg void OnCbnSelchangeCombotype();
00260     afx_msg void OnNMDblclkTreeSearchHistory(NMHDR *pNMHDR, LRESULT *pResult);
00261     // if the connections are to be searched for
00262     BOOL m_chkConnection;
00263     BOOL m_chkSplSearch;
00264     afx_msg void OnCheckSplSearch();
00265     // reference static text ctrl
00266     CStatic m_stcRefCtrl;
00267     CButton m_chkConnCtrl;
00268     afx_msg void OnLvnColumnclickListresults(NMHDR *pNMHDR, LRESULT *pResult);
00269     afx_msg void OnBnClickedButtonClear();
00270 };
00271 
00272 //{{AFX_INSERT_LOCATION}}
00273 // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
00274 
00275 #endif // !defined(AFX_SEARCHDLG_H__E59A9A8F_05E1_48EB_BB09_897251FD3943__INCLUDED_)