Code/Resource
Windows Develop
Linux-Unix program
Internet-Socket-Network
Web Server
Browser Client
Ftp Server
Ftp Client
Browser Plugins
Proxy Server
Email Server
Email Client
WEB Mail
Firewall-Security
Telnet Server
Telnet Client
ICQ-IM-Chat
Search Engine
Sniffer Package capture
Remote Control
xml-soap-webservice
P2P
WEB(ASP,PHP,...)
TCP/IP Stack
SNMP
Grid Computing
SilverLight
DNS
Cluster Service
Network Security
Communication-Mobile
Game Program
Editor
Multimedia program
Graph program
Compiler program
Compress-Decompress algrithms
Crypt_Decrypt algrithms
Mathimatics-Numerical algorithms
MultiLanguage
Disk/Storage
Java Develop
assembly language
Applications
Other systems
Database system
Embeded-SCM Develop
FlashMX/Flex
source in ebook
Delphi VCL
OS Develop
MiddleWare
MPI
MacOS develop
LabView
ELanguage
Software/Tools
E-Books
Artical/Document
query.cpp
Package: shell.rar [view]
Upload User: xhy777
Upload Date: 2007-02-14
Package Size: 24088k
Code Size: 152k
Category:
Windows Kernel
Development Platform:
Visual C++
- #include "pch.h"
- #pragma hdrstop
- /*-----------------------------------------------------------------------------
- / Private data and helper functions
- /----------------------------------------------------------------------------*/
- //
- // ICommonQuery stuff
- //
- #ifdef UNICODE
- class CCommonQuery : public ICommonQuery, IObjectWithSite, ICommonQueryA, CUnknown
- #else
- class CCommonQuery : public ICommonQuery, IObjectWithSite, CUnknown
- #endif
- {
- private:
- IUnknown* _punkSite;
- public:
- CCommonQuery();
- ~CCommonQuery();
- // IUnknown
- STDMETHOD(QueryInterface)(REFIID riid, LPVOID* ppvObject);
- STDMETHOD_(ULONG, AddRef)();
- STDMETHOD_(ULONG, Release)();
- // ICommonQuery
- STDMETHOD(OpenQueryWindow)(THIS_ HWND hwndParent, LPOPENQUERYWINDOW pOpenQueryWnd, IDataObject** ppDataObject);
- #ifdef UNICODE
- // ICommonQueryA
- STDMETHOD(OpenQueryWindow)(THIS_ HWND hwndParent, LPOPENQUERYWINDOW_A pOpenQueryWnd, IDataObject** ppDataObject);
- #endif
- // IObjectWithSite
- STDMETHODIMP SetSite(IUnknown* punk);
- STDMETHODIMP GetSite(REFIID riid, void **ppv);
- };
- //
- // View layout constants used by our dialogs
- //
- #define VIEWER_DEFAULT_CY 200
- #define COMBOEX_IMAGE_CX 16
- #define COMBOEX_IMAGE_CY 16
- //
- // Internal reference to a form and page
- //
- typedef struct
- {
- HDSA hdsaPages; // DSA containing page entries
- DWORD dwFlags; // flags
- CLSID clsidForm; // CLSID identifier for this form
- LPTSTR pTitle; // title used for drop down / title bar
- HICON hIcon; // hIcon passed by caller
- INT iImage; // image list index of icon
- INT iForm; // visible index of form in control
- INT iPage; // currently selected page on form
- } QUERYFORM, * LPQUERYFORM;
- typedef struct
- {
- CLSID clsidForm; // CLSID to associate this form with
- BOOL fPageIsANSI : 1; // page was declared ANSI
- union
- {
- LPCQPAGE pPage; // CQPAGE structures
- #ifdef UNICODE
- LPCQPAGE_A pPageA;
- #endif
- };
- union
- {
- LPCQPAGEPROC pPageProc; // PageProc's used by thunking layer
- #ifdef UNICODE
- LPCQPAGEPROC_A pPageProcA;
- #endif
- };
- LPARAM lParam; // PAGEPROC lParam
- HWND hwndPage; // hWnd of page dialog // = NULL if none
- } QUERYFORMPAGE, * LPQUERYFORMPAGE;
- //
- // Internal reference of a scope
- //
- typedef struct
- {
- LPCQSCOPE pScope;
- INT iImage;
- } QUERYSCOPE, * LPQUERYSCOPE;
- //
- // CQueryFrame, our implementation of IQueryFrame
- //
- #define CALLFORMPAGES_ANSI 0x0001 // call only ANSI query form pages
- #define CALLFORMPAGES_UNICODE 0x0002 // call only UNICODE query form pages
- #define CALLFORMPAGES_ALL 0x0003
- class CQueryFrame : public IQueryFrame, CUnknown
- {
- friend INT QueryWnd_MessageProc(HWND hwnd, LPMSG pMsg);
- friend INT_PTR CALLBACK QueryWnd_DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
- public:
- CQueryFrame(IUnknown* punkSite, LPOPENQUERYWINDOW pOpenQueryWindow, IDataObject** ppDataObject);
- ~CQueryFrame();
- // IUnknown
- STDMETHOD(QueryInterface)(REFIID riid, LPVOID* ppvObject);
- STDMETHOD_(ULONG, AddRef)();
- STDMETHOD_(ULONG, Release)();
- // Internal helper functions
- STDMETHOD(DoModal)(HWND hwndParent);
- // IQueryFrame
- STDMETHOD(AddScope)(THIS_ LPCQSCOPE pScope, INT i, BOOL fSelect);
- STDMETHOD(GetWindow)(THIS_ HWND* phWnd);
- STDMETHOD(InsertMenus)(THIS_ HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidth);
- STDMETHOD(RemoveMenus)(THIS_ HMENU hmenuShared);
- STDMETHOD(SetMenu)(THIS_ HMENU hmenuShared, HOLEMENU holereservedMenu);
- STDMETHOD(SetStatusText)(THIS_ LPCTSTR pszStatusText);
- STDMETHOD(StartQuery)(THIS_ BOOL fStarting);
- STDMETHOD(LoadQuery)(THIS_ IPersistQuery* pPersistQuery);
- STDMETHOD(SaveQuery)(THIS_ IPersistQuery* pPersistQuery);
- STDMETHOD(CallForm)(THIS_ LPCLSID pclsidForm, UINT uMsg, WPARAM wParam, LPARAM lParam);
- STDMETHOD(GetScope)(THIS_ LPCQSCOPE* ppScope);
- STDMETHOD(GetHandler)(THIS_ REFIID riid, void **ppv);
- protected:
- // Helper functions
- VOID CloseQueryFrame(HRESULT hres);
- #if HIDE_SEARCH_PANE
- VOID HideSearchPane(BOOL fHide);
- #endif
- INT FrameMessageBox(LPCTSTR pPrompt, UINT uType);
- // Message handlers
- HRESULT OnInitDialog(HWND hwnd);
- VOID DoEnableControls(VOID);
- LRESULT OnNotify(INT idCtrl, LPNMHDR pNotify);
- VOID OnSize(INT cx, INT cy);
- VOID OnGetMinMaxInfo(LPMINMAXINFO lpmmi);
- VOID OnCommand(WPARAM wParam, LPARAM lParam);
- VOID OnInitMenu(HMENU hMenu);
- VOID OnEnterMenuLoop(BOOL fEntering);
- VOID OnMenuSelect(HMENU hMenu, UINT uID);
- HRESULT OnFindNow(VOID);
- BOOL OnNewQuery(BOOL fAlwaysPrompt);
- HRESULT OnBrowse(VOID);
- HRESULT OnHelp(LPHELPINFO pHelpInfo);
- // Form/Scope helper fucntions
- HRESULT InsertScopeIntoList(LPCQSCOPE pScope, INT i, BOOL fAddToControl);
- HRESULT AddScopeToControl(LPQUERYSCOPE pQueryScope, INT i);
- HRESULT PopulateScopeControl(VOID);
- HRESULT GetSelectedScope(LPQUERYSCOPE* ppQueryScope);
- HRESULT AddFromIQueryForm(IQueryForm* pQueryForm, HKEY hkeyForm);
- #ifdef UNICODE
- HRESULT AddFromIQueryFormA(IQueryFormA* pQueryForm, HKEY hkeyForm);
- #endif
- HRESULT GatherForms(VOID);
- HRESULT GetForms(HKEY hKeyForms, LPTSTR pName);
- HRESULT PopulateFormControl(BOOL fIncludeHidden);
- HRESULT SelectForm(REFCLSID clsidForm);
- VOID SelectFormPage(LPQUERYFORM pQueryForm, INT iPage);
- HRESULT CallFormPages(LPQUERYFORM pQueryForm, DWORD dwFlags, UINT uMsg, WPARAM wParam, LPARAM lParam);
- LPQUERYFORM FindQueryForm(REFCLSID clsidForm);
- private:
- IUnknown* _punkSite; // site object we need to pass through
- IQueryHandler* _pQueryHandler; // IQueryHandler object we need to interact with
- LPOPENQUERYWINDOW _pOpenQueryWnd; // copy of initial parameters provided by caller
- IDataObject** _ppDataObject; // receives the resulting data object from handler
- DWORD _dwHandlerViewFlags; // flags from the handler
- BOOL _fQueryRunning:1; // = 1 => query has been started, via IQueryFrame::StartQuery(TRUE)
- BOOL _fExitModalLoop:1; // = 1 => must leave modal loop
- BOOL _fScopesPopulated:1; // = 1 => scope control has been populated
- BOOL _fTrackingMenuBar:1; // = 1 => then we are tracking the menu bar, therefore send activates etc
- #if HIDE_SEARCH_PANE
- BOOL _fHideSearchPane:1; // = 1 => form area is currently hidden
- #endif
- BOOL _fAddScopesNYI:1; // = 1 => did AddScopes return E_NOTIMPL
- BOOL _fScopesAddedAsync:1; // = 1 => scopes added async by the handler
- BOOL _fScopeImageListSet:1; // = 1 => scope image list has been set
- HRESULT _hResult; // result value stored by CloseQueryFrame
- HKEY _hkHandler; // registry key for the handler
- HWND _hwnd; // main window handle
- HWND _hwndResults; // result viewer
- HWND _hwndStatus; // status bar
- HWND _hwndFrame; // Query Pages tab control
- HWND _hwndLookForLabel; // "Find:"
- HWND _hwndLookFor; // Form combo
- HWND _hwndLookInLabel; // "In:"
- HWND _hwndLookIn; // Scope combo
- HWND _hwndBrowse; // "Browse"
- HWND _hwndFindNow; // "Find now"
- HWND _hwndStop; // "Stop"
- HWND _hwndNewQuery; // "New Query"
- HWND _hwndOK; // "OK"
- HWND _hwndCancel; // "Cancel"
- HWND _hwndFindAnimation; // Query issued animation
- HICON _hiconSmall; // large/small app icons
- HICON _hiconLarge;
- HMENU _hmenuFile; // handle of the frames menu bar
- HIMAGELIST _himlForms; // image list for query form objects
- SIZE _szMinTrack; // minimum track size of the window
- INT _dxFormAreaLeft; // offset to left edge of form area (from window left)
- INT _dxFormAreaRight; // offset to right edge of form area (from window right)
- INT _dxButtonsLeft; // offset to left edge of buttons (from window right)
- INT _dxAnimationLeft; // offset to left edge of aniimation (from window right)
- INT _dyResultsTop; // offset to top of results (from top of window)
- INT _dyOKTop; // offset to top of "OK" buttom (from results top)
- INT _dxGap; // gap between OK + Cancel / LookIn + Browse
- INT _dyGap; // gap between bottom of OK,Cancel and the frame.
- INT _cyStatus; // height of the status bar
- HDSA _hdsaForms; // forms DSA
- HDSA _hdsaPages; // pages DSA
- SIZE _szForm; // size of the (current form we are displaying)
- HDSA _hdsaScopes; // scopes DSA
- INT _iDefaultScope; // index of the defualt scope to select (into DSA)
- LPQUERYFORM _pCurrentForm; // == NULL if none / else -> form structure
- LPQUERYFORMPAGE _pCurrentFormPage; // == NULL if none / else -> page structure
- };
- //
- // Helper functions
- //
- INT_PTR CALLBACK QueryWnd_DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
- INT QueryWnd_MessageProc(HWND hwnd, LPMSG pMsg);
- HRESULT _CallScopeProc(LPQUERYSCOPE pQueryScope, UINT uMsg, LPVOID pVoid);
- INT _FreeScope(LPQUERYSCOPE pQueryScope);
- INT _FreeScopeCB(LPVOID pItem, LPVOID pData);
- HRESULT _CallPageProc(LPQUERYFORMPAGE pQueryFormPage, UINT uMsg, WPARAM wParam, LPARAM lParam);
- INT _FreeQueryFormCB(LPVOID pItem, LPVOID pData);
- INT _FreeQueryForm(LPQUERYFORM pQueryForm);
- INT _FreeQueryFormPageCB(LPVOID pItem, LPVOID pData);
- INT _FreeQueryFormPage(LPQUERYFORMPAGE pQueryFormPage);
- #ifdef UNICODE
- HRESULT _AddFormsProcA(LPARAM lParam, LPCQFORM_A pForm);
- HRESULT _AddPagesProcA(LPARAM lParam, REFCLSID clsidForm, LPCQPAGE_A pPage);
- #endif
- HRESULT _AddFormsProc(LPARAM lParam, LPCQFORM_W pForm);
- HRESULT _AddPagesProc(LPARAM lParam, REFCLSID clsidForm, LPCQPAGE_W pPage);
- //
- // Help stuff
- //
- #define HELP_FILE (NULL)
- static DWORD const aHelpIDs[] =
- {
- 0, 0
- };
- //
- // constant strings
- //
- TCHAR const c_szCLSID[] = TEXT("CLSID");
- TCHAR const c_szForms[] = TEXT("Forms");
- TCHAR const c_szFlags[] = TEXT("Flags");
- TCHAR const c_szCommonQuery[] = TEXT("CommonQuery");
- TCHAR const c_szHandlerIs[] = TEXT("Handler");
- TCHAR const c_szFormIs[] = TEXT("Form");
- TCHAR const c_szSearchPaneHidden[] = TEXT("SearchPaneHidden");
- /*-----------------------------------------------------------------------------
- / CCommonQuery
- /----------------------------------------------------------------------------*/
- CCommonQuery::CCommonQuery() :
- _punkSite(NULL)
- {
- }
- CCommonQuery::~CCommonQuery()
- {
- DoRelease(_punkSite);
- }
- // IUnknown bits
- #undef CLASS_NAME
- #define CLASS_NAME CCommonQuery
- #include "unknown.inc"
- STDMETHODIMP CCommonQuery::QueryInterface(REFIID riid, LPVOID* ppvObject)
- {
- INTERFACES iface[] =
- {
- &IID_ICommonQuery, (ICommonQuery*)this,
- #ifdef UNICODE
- &IID_ICommonQueryA, (ICommonQueryA*)this,
- #endif
- };
- return HandleQueryInterface(riid, ppvObject, iface, ARRAYSIZE(iface));
- }
- //
- // handle creating a new instance of CLSID_CommonQuery
- //
- STDAPI CCommonQuery_CreateInstance(IUnknown* punkOuter, IUnknown** ppunk, LPCOBJECTINFO poi)
- {
- CCommonQuery *pcq = new CCommonQuery;
- if ( !pcq )
- return E_OUTOFMEMORY;
- HRESULT hres = pcq->QueryInterface(IID_IUnknown, (void **)ppunk);
- pcq->Release();
- return hres;
- }
- /*-----------------------------------------------------------------------------
- / ICommonQuery methods
- /----------------------------------------------------------------------------*/
- /*-----------------------------------------------------------------------------
- / OpenQueryWindow
- / ---------------
- / Display the query window for the given provider, including collecting
- / all the forms etc.
- /
- / In:
- / hwndParent -> parent window for this dialog
- / pOpenQueryWnd -> structure that defines how the window should be opened
- / ppDataObject -> receives a pointer to the data object
- /
- / Out:
- / HRESULT
- /----------------------------------------------------------------------------*/
- STDMETHODIMP CCommonQuery::OpenQueryWindow(THIS_ HWND hwndParent, LPOPENQUERYWINDOW pOpenQueryWnd, IDataObject** ppDataObject)
- {
- HRESULT hres;
- CQueryFrame* pQueryFrame = NULL;
- TraceEnter(TRACE_QUERY, "CCommonQuery::OpenQueryWindow");
- if ( !pOpenQueryWnd || (hwndParent && !IsWindow(hwndParent)) )
- ExitGracefully(hres, E_INVALIDARG, "Bad parameters");
- if ( ppDataObject )
- *(ppDataObject) = NULL;
- pQueryFrame = new CQueryFrame(_punkSite, pOpenQueryWnd, ppDataObject);
- TraceAssert(pQueryFrame);
- if ( !pQueryFrame )
- ExitGracefully(hres, E_OUTOFMEMORY, "Failed to construct the query window object");
- hres = pQueryFrame->DoModal(hwndParent); // don't bother fail gracefully etc
- FailGracefully(hres, "Failed on calling DoModal");
- exit_gracefully:
- DoRelease(pQueryFrame);
- TraceLeaveResult(hres);
- }
- /*-----------------------------------------------------------------------------
- / OpenQueryWindow - thunking from ANSI
- / ---------------
- / Display the query window for the given provider, including collecting
- / all the forms etc.
- /
- / In:
- / hwndParent -> parent window for this dialog
- / pOpenQueryWnd -> structure that defines how the window should be opened
- / ppDataObject -> receives a pointer to the data object
- /
- / Out:
- / HRESULT
- /----------------------------------------------------------------------------*/
- #ifdef UNICODE
- STDMETHODIMP CCommonQuery::OpenQueryWindow(THIS_ HWND hwndParent, LPOPENQUERYWINDOW_A pOpenQueryWnd, IDataObject** ppDataObject)
- {
- HRESULT hres;
- LPOPENQUERYWINDOW_W pOpenQueryWndW = NULL;
- TraceEnter(TRACE_QUERY, "CCommonQueryA::OpenQueryWindow");
- if ( !pOpenQueryWnd )
- ExitGracefully(hres, E_INVALIDARG, "No pOpenQueryWnd structure");
- // allocate the UNICODE verison of the OPENQUERYWINDOW structure that
- // we can then passed to the wide versions of this API.
- pOpenQueryWndW = (LPOPENQUERYWINDOW_W)LocalAlloc(LPTR, pOpenQueryWnd->cbStruct);
- if ( !pOpenQueryWndW )
- ExitGracefully(hres, E_OUTOFMEMORY, "Failed to allocate OPENQUERYWINDOW structure");
- Trace(TEXT("Copying OPENQUERYWINDOW structure to %08x (from %08x, size %08x)"),
- pOpenQueryWndW, pOpenQueryWnd, pOpenQueryWnd->cbStruct);
- CopyMemory(pOpenQueryWndW, pOpenQueryWnd, pOpenQueryWnd->cbStruct);
- // Thunk the persistance interface, this will be an ANSI assuming of course that
- // the caller has called the ANSI ICommonQuery interface.
- if ( !pOpenQueryWndW->pPersistQuery )
- {
- pOpenQueryWndW->pPersistQuery = new CPersistQueryW2A(pOpenQueryWnd->pPersistQuery);
- Trace(TEXT("pPersistA2W %08x"), pOpenQueryWndW->pPersistQuery);
- if ( !pOpenQueryWndW->pPersistQuery )
- ExitGracefully(hres, E_OUTOFMEMORY, "Failed to allocate persistance thunk");
- }
- hres = OpenQueryWindow(hwndParent, pOpenQueryWndW, ppDataObject);
- FailGracefully(hres, "Failed when calling UNICODE OpenQueryWindow function");
- exit_gracefully:
- if ( pOpenQueryWndW )
- {
- DoRelease(pOpenQueryWndW->pPersistQuery);
- LocalFree((HLOCAL)pOpenQueryWndW);
- }
- TraceLeaveResult(hres);
- }
- #endif
- /*----------------------------------------------------------------------------
- / IObjectWithSite
- /----------------------------------------------------------------------------*/
- STDMETHODIMP CCommonQuery::SetSite(IUnknown* punk)
- {
- HRESULT hres = S_OK;
- TraceEnter(TRACE_QUERY, "CCommonQuery::SetSite");
- DoRelease(_punkSite);
- if ( punk )
- {
- TraceMsg("QIing for IUnknown from the site object");
- hres = punk->QueryInterface(IID_IUnknown, (void **)&_punkSite);
- FailGracefully(hres, "Failed to get IUnknown from the site object");
- }
- exit_gracefully:
- TraceLeaveResult(hres);
- }
- /*---------------------------------------------------------------------------*/
- STDMETHODIMP CCommonQuery::GetSite(REFIID riid, void **ppv)
- {
- HRESULT hres;
- TraceEnter(TRACE_QUERY, "CCommonQuery::GetSite");
- if ( !_punkSite )
- ExitGracefully(hres, E_NOINTERFACE, "No site to QI from");
- hres = _punkSite->QueryInterface(riid, ppv);
- FailGracefully(hres, "QI failed on the site unknown object");
- exit_gracefully:
- TraceLeaveResult(hres);
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame
- /----------------------------------------------------------------------------*/
- CQueryFrame::CQueryFrame(IUnknown *punkSite, LPOPENQUERYWINDOW pOpenQueryWindow, IDataObject** ppDataObject) :
- _punkSite(punkSite),
- _pOpenQueryWnd(pOpenQueryWindow),
- _ppDataObject(ppDataObject),
- _hiconLarge(NULL),
- _hiconSmall(NULL)
- {
- TraceEnter(TRACE_FRAME, "CQueryFrame::CQueryFrame");
- if ( _punkSite )
- _punkSite->AddRef();
- TraceLeave();
- }
- CQueryFrame::~CQueryFrame()
- {
- TraceEnter(TRACE_FRAME, "CQueryFrame::~CQueryFrame");
- DoRelease(_punkSite);
- if ( _hiconLarge )
- DestroyIcon(_hiconLarge);
- if ( _hiconSmall )
- DestroyIcon(_hiconSmall);
- if ( _hkHandler )
- RegCloseKey(_hkHandler);
- if ( _hmenuFile )
- DestroyMenu(_hmenuFile);
- if ( _himlForms )
- ImageList_Destroy(_himlForms);
- if ( _hdsaForms )
- {
- Trace(TEXT("Destroying QUERYFORM DSA (%d)"), DSA_GetItemCount(_hdsaForms));
- DSA_DestroyCallback(_hdsaForms, _FreeQueryFormCB, NULL);
- _hdsaForms = NULL;
- }
- if ( _hdsaPages )
- {
- Trace(TEXT("Destroying QUERYFORMPAGE DSA (%d)"), DSA_GetItemCount(_hdsaPages));
- DSA_DestroyCallback(_hdsaPages, _FreeQueryFormPageCB, NULL);
- _hdsaPages = NULL;
- }
- if ( _hdsaScopes )
- {
- Trace(TEXT("Destroying QUERYSCOPE DSA (%d)"), DSA_GetItemCount(_hdsaScopes));
- DSA_DestroyCallback(_hdsaScopes, _FreeScopeCB, NULL);
- _hdsaScopes = NULL;
- }
- _pCurrentForm = NULL;
- _pCurrentFormPage = NULL;
- // Now discard the handler and its window (if we have one), if
- // we don't do this they will never kill their objects
- if ( _hwndResults )
- {
- DestroyWindow(_hwndResults);
- _hwndResults = NULL;
- }
- TraceLeave();
- }
- // IUnknown bits
- #undef CLASS_NAME
- #define CLASS_NAME CQueryFrame
- #include "unknown.inc"
- STDMETHODIMP CQueryFrame::QueryInterface(REFIID riid, LPVOID* ppvObject)
- {
- INTERFACES iface[] =
- {
- &IID_IQueryFrame, (IQueryFrame*)this,
- };
- return HandleQueryInterface(riid, ppvObject, iface, ARRAYSIZE(iface));
- }
- /*-----------------------------------------------------------------------------
- / IQueryFrame
- /----------------------------------------------------------------------------*/
- STDMETHODIMP CQueryFrame::DoModal(HWND hwndParent)
- {
- HRESULT hres;
- HWND hwndFrame = NULL;
- HWND hwndFocus = NULL;
- HWND hwndTopOwner = hwndParent;
- MSG msg;
- INITCOMMONCONTROLSEX iccex;
- TraceEnter(TRACE_FRAME, "CQueryFrame::DoModal");
- // initialize with the query handler we need
- hres = CoCreateInstance(_pOpenQueryWnd->clsidHandler, NULL, CLSCTX_INPROC_SERVER, IID_IQueryHandler, (LPVOID*)&_pQueryHandler);
- FailGracefully(hres, "Failed to get IQueryHandler for the given CLSID");
- hres = _pQueryHandler->Initialize(this, _pOpenQueryWnd->dwFlags, _pOpenQueryWnd->pHandlerParameters);
- FailGracefully(hres, "Failed to initialize the handler");
- // mimic the behaviour of DialogBox by working out which control previously
- // had focus, which window to disable and then running a message
- // pump for our dialog. Having done this we can then restore the state
- // back to something sensible.
- _fExitModalLoop = FALSE; // can be changed from hear down
- iccex.dwSize = SIZEOF(iccex);
- iccex.dwICC = ICC_USEREX_CLASSES;
- InitCommonControlsEx(&iccex);
- if ( _pOpenQueryWnd->dwFlags & OQWF_HIDESEARCHUI )
- {
- hwndFrame = CreateDialogParam(GLOBAL_HINSTANCE, MAKEINTRESOURCE(IDD_FILTER),
- hwndParent,
- QueryWnd_DlgProc, (LPARAM)this);
- }
- else
- {
- hwndFrame = CreateDialogParam(GLOBAL_HINSTANCE, MAKEINTRESOURCE(IDD_FIND),
- hwndParent,
- QueryWnd_DlgProc, (LPARAM)this);
- }
- if ( !hwndFrame )
- ExitGracefully(hres, E_FAIL, "Failed to create the dialog");
- hwndFocus = GetFocus();
- if ( hwndTopOwner )
- {
- // walk up the window stack looking for the window to be disabled, this must
- // be the top-most non-child window. If the resulting window is either
- // the desktop or is already disabled then don't bother.
- while ( GetWindowLong(hwndTopOwner, GWL_STYLE) & WS_CHILD )
- hwndTopOwner = GetParent(hwndTopOwner);
- TraceAssert(hwndTopOwner);
- if ( (hwndTopOwner == GetDesktopWindow())
- || EnableWindow(hwndTopOwner, FALSE) )
- {
- TraceMsg("Parent is disabled or the desktop window, therefore setting to NULL");
- hwndTopOwner = NULL;
- }
- }
- ShowWindow(hwndFrame, SW_SHOW); // show the query window
- while ( !_fExitModalLoop && GetMessage(&msg, NULL, 0, 0) > 0 )
- {
- if ( !QueryWnd_MessageProc(hwndFrame, &msg) && !IsDialogMessage(hwndFrame, &msg) )
- {
- TranslateMessage(&msg);
- DispatchMessage(&msg);
- }
- }
- // Now tidy up, make the parent the active window, enable the top most
- // window if there is one and restore focus as required.
- if ( hwndTopOwner )
- EnableWindow(hwndTopOwner, TRUE);
- if ( hwndParent && (GetActiveWindow() == hwndFrame) )
- {
- TraceMsg("Passing activation to parent");
- SetActiveWindow(hwndParent);
- }
- if ( IsWindow(hwndFocus) )
- SetFocus(hwndFocus);
- DestroyWindow(hwndFrame); // discard the current frame window
- exit_gracefully:
- DoRelease(_pQueryHandler);
- TraceLeaveResult(_hResult);
- }
- /*---------------------------------------------------------------------------*/
- STDMETHODIMP CQueryFrame::AddScope(THIS_ LPCQSCOPE pScope, INT i, BOOL fSelect)
- {
- HRESULT hres;
- TraceEnter(TRACE_FRAME, "CQueryFrame::AddScope");
- if ( !pScope )
- ExitGracefully(hres, E_INVALIDARG, "No scope to add to the list");
- // Add the scope to the control and then ensure that we either have
- // its index stored (for default selection) or we select the
- // item.
- if ( !_hdsaScopes || !DSA_GetItemCount(_hdsaScopes) )
- {
- TraceMsg("First scope being added, thefore selecting");
- fSelect = TRUE;
- }
- hres = InsertScopeIntoList(pScope, i, _fScopesPopulated);
- FailGracefully(hres, "Failed to add scope to control");
- if ( fSelect )
- {
- if ( !_fScopesPopulated )
- {
- Trace(TEXT("Storing default scope index %d"), ShortFromResult(hres));
- _iDefaultScope = ShortFromResult(hres);
- }
- else
- {
- Trace(TEXT("Selecting scope index %d"), ShortFromResult(hres));
- ComboBox_SetCurSel(_hwndLookIn, ShortFromResult(hres));
- }
- }
- // hres = S_OK;
- exit_gracefully:
- TraceLeaveResult(hres);
- }
- /*---------------------------------------------------------------------------*/
- STDMETHODIMP CQueryFrame::GetWindow(THIS_ HWND* phWnd)
- {
- TraceEnter(TRACE_FRAME, "CQueryFrame::GetWindow");
- TraceAssert(phWnd);
- *phWnd = _hwnd;
- TraceLeaveResult(S_OK);
- }
- /*---------------------------------------------------------------------------*/
- // Add a menu group to the given menu bar, updating the width index accordingly
- // so that other people can merge in accordingly
- VOID _DoInsertMenu(HMENU hMenu, INT iIndexTo, HMENU hMenuToInsert, INT iIndexFrom)
- {
- TCHAR szBuffer[MAX_PATH];
- HMENU hPopupMenu = NULL;
- TraceEnter(TRACE_FRAME, "_DoInsertMenu");
- hPopupMenu = CreatePopupMenu();
- if ( hPopupMenu )
- {
- Shell_MergeMenus(hPopupMenu, GetSubMenu(hMenuToInsert, iIndexFrom), 0x0, 0x0, 0x7fff, 0);
- GetMenuString(hMenuToInsert, iIndexFrom, szBuffer, ARRAYSIZE(szBuffer), MF_BYPOSITION);
- InsertMenu(hMenu, iIndexTo, MF_BYPOSITION|MF_POPUP, (UINT_PTR)hPopupMenu, szBuffer);
- }
- TraceLeave();
- }
- VOID _AddMenuGroup(HMENU hMenuShared, HMENU hMenuGroup, LONG iInsertAt, LPLONG pWidth)
- {
- HRESULT hres;
- TCHAR szBuffer[MAX_PATH];
- HMENU hMenu;
- INT i;
- TraceEnter(TRACE_FRAME, "_AddMenuGroup");
- TraceAssert(hMenuShared);
- TraceAssert(hMenuGroup);
- TraceAssert(pWidth);
- for ( i = 0 ; i < GetMenuItemCount(hMenuGroup) ; i++ )
- {
- _DoInsertMenu(hMenuShared, iInsertAt+i, hMenuGroup, i);
- *pWidth += 1;
- }
- TraceLeave();
- }
- STDMETHODIMP CQueryFrame::InsertMenus(THIS_ HMENU hmenuShared, LPOLEMENUGROUPWIDTHS lpMenuWidth)
- {
- HRESULT hres;
- TraceEnter(TRACE_FRAME, "CQueryFrame::InsertMenus");
- if ( !hmenuShared || !lpMenuWidth )
- ExitGracefully(hres, E_INVALIDARG, "Unable to insert menus");
- // if we don't have the menu bar already loaded then lets load it,
- // having done that we can then add our menu to the bar (we only
- // provide entries for the file menu).
- if ( !_hmenuFile )
- {
- _hmenuFile = LoadMenu(GLOBAL_HINSTANCE, MAKEINTRESOURCE(IDR_FILEMENUGROUP));
- if ( !_hmenuFile )
- ExitGracefully(hres, E_FAIL, "Failed to load base menu defn");
- }
- _AddMenuGroup(hmenuShared, _hmenuFile, 0, &lpMenuWidth->width[0]);
- hres = S_OK; // success
- exit_gracefully:
- TraceLeaveResult(hres);
- }
- /*---------------------------------------------------------------------------*/
- STDMETHODIMP CQueryFrame::RemoveMenus(THIS_ HMENU hmenuShared)
- {
- TraceEnter(TRACE_FRAME, "CQueryFrame::RemoveMenus");
- // We don't need to implement this as we copy or menus into the
- // menu that the handler supplies - fix DSQUERY if this ever
- // changes.
- TraceLeaveResult(S_OK);
- }
- /*---------------------------------------------------------------------------*/
- STDMETHODIMP CQueryFrame::SetMenu(THIS_ HMENU hmenuShared, HOLEMENU holereservedMenu)
- {
- TraceEnter(TRACE_FRAME, "CQueryFrame::SetMenu");
- if ( !(_pOpenQueryWnd->dwFlags & OQWF_HIDEMENUS) )
- {
- HMENU hmenuOld = ::GetMenu(_hwnd);
- if ( !hmenuShared )
- hmenuShared = _hmenuFile;
- ::SetMenu(_hwnd, hmenuShared);
- DoEnableControls(); // ensure the menu state is valid
- ::DrawMenuBar(_hwnd);
- if ( (hmenuOld != _hmenuFile) && (hmenuOld != hmenuShared) )
- {
- TraceMsg("Destroying old menu");
- DestroyMenu(hmenuOld);
- }
- }
- TraceLeaveResult(S_OK);
- }
- /*---------------------------------------------------------------------------*/
- STDMETHODIMP CQueryFrame::SetStatusText(THIS_ LPCTSTR pszStatusText)
- {
- TraceEnter(TRACE_FRAME, "CQueryFrame::SetStatusText");
- Trace(TEXT("Setting status text to: %s"), pszStatusText);
- if ( _hwndStatus )
- SendMessage(_hwndStatus, SB_SETTEXT, 0, (LPARAM)pszStatusText);
- TraceLeaveResult(S_OK);
- }
- /*---------------------------------------------------------------------------*/
- STDMETHODIMP CQueryFrame::StartQuery(THIS_ BOOL fStarting)
- {
- TraceEnter(TRACE_FRAME, "CQueryFrame::StartQuery");
- if ( fStarting )
- {
- Animate_Play(_hwndFindAnimation, 0, -1, -1);
- }
- else
- {
- Animate_Stop(_hwndFindAnimation);
- Animate_Seek(_hwndFindAnimation, 0); // go to start
- }
- if ( _pQueryHandler )
- _pQueryHandler->ActivateView(CQRVA_STARTQUERY, (WPARAM)fStarting, 0);
- // now set the controls into a sensble state
- _fQueryRunning = fStarting;
- DoEnableControls();
- TraceLeaveResult(S_OK);
- }
- /*---------------------------------------------------------------------------*/
- STDMETHODIMP CQueryFrame::LoadQuery(THIS_ IPersistQuery* pPersistQuery)
- {
- HRESULT hres;
- TCHAR szGUID[GUIDSTR_MAX+1];
- LPQUERYFORM pQueryForm = NULL;
- #ifdef UNICODE
- CPersistQueryA2W* pPersistQueryA2W = NULL;
- #endif
- #if HIDE_SEARCH_PANE
- BOOL fHideSearchPanes = FALSE;
- #endif
- GUID guid;
- TraceEnter(TRACE_FRAME, "CQueryFrame::LoadQuery");
- _pQueryHandler->StopQuery(); // ensure that the handler stops its processing
- // Attempt to read the handler GUID from the query stream, first try reading it as
- // as string then parsing it into something that we can use, if that fails then
- // try again, but this time read it as a structure.
- //
- // having aquired the GUID for the handler make sure that we have the correct handler
- // selected.
- if ( FAILED(pPersistQuery->ReadString(c_szCommonQuery, c_szHandlerIs, szGUID, ARRAYSIZE(szGUID))) ||
- !GetGUIDFromString(szGUID, &guid) )
- {
- TraceMsg("Trying new style handler GUID as struct");
- hres = pPersistQuery->ReadStruct(c_szCommonQuery, c_szHandlerIs, &guid, SIZEOF(guid));
- FailGracefully(hres, "Failed to read handler GUID as struct");
- }
- if ( guid != _pOpenQueryWnd->clsidHandler )
- ExitGracefully(hres, E_FAIL, "Persisted handler GUID and specified handler GUID don't match");
- #if HIDE_SEARCH_PANE
- if ( SUCCEEDED(pPersistQuery->ReadInt(c_szCommonQuery, c_szSearchPaneHidden, &fHideSearchPanes)) )
- {
- Trace(TEXT("Hide forms %d form file"), fHideSearchPanes);
- HideSearchPane(fHideSearchPanes);
- }
- #endif
- hres = _pQueryHandler->LoadQuery(pPersistQuery);
- FailGracefully(hres, "Handler failed to load its query data");
- // Get the form ID, then look up the form to see if we have one that matches,
- // if not then we cannot load any thing else. If we do haved that form then
- // ensure that we clear it and then load away.
- if ( FAILED(pPersistQuery->ReadString(c_szCommonQuery, c_szFormIs, szGUID, ARRAYSIZE(szGUID))) ||
- !GetGUIDFromString(szGUID, &guid) )
- {
- TraceMsg("Trying new style form GUID as struct");
- hres = pPersistQuery->ReadStruct(c_szCommonQuery, c_szFormIs, &guid, SIZEOF(guid));
- FailGracefully(hres, "Failed to read handler GUID as struct");
- }
- hres = SelectForm(guid);
- FailGracefully(hres, "Failed to select the query form");
- if ( hres == S_FALSE )
- ExitGracefully(hres, E_FAIL, "Failed to select the query form to read the query info");
- hres = CallFormPages(_pCurrentForm, CALLFORMPAGES_ALL, CQPM_CLEARFORM, 0, 0);
- FailGracefully(hres, "Failed to clear form before loading");
- // Load the persisted query from the stream, coping correctly with the
- // UNICODE / ANSI issue. We will be passed an IPersistQuery object which
- // we must then thunk accordingly if we are UNICODE for the pages we
- // are going to talk to.
- #ifndef UNICODE
- hres = CallFormPages(_pCurrentForm, CALLFORMPAGES_ANSI, CQPM_PERSIST, TRUE, (LPARAM)pPersistQuery);
- FailGracefully(hres, "Failed to load form data");
- #else
- hres = CallFormPages(_pCurrentForm, CALLFORMPAGES_UNICODE, CQPM_PERSIST, TRUE, (LPARAM)pPersistQuery);
- FailGracefully(hres, "Failed to load page data (UNICODE)");
- if ( SUCCEEDED(hres) )
- {
- pPersistQueryA2W = new CPersistQueryA2W(pPersistQuery);
- TraceAssert(pPersistQueryA2W);
- if ( !pPersistQueryA2W )
- ExitGracefully(hres, E_OUTOFMEMORY, "Failed to construct persistance thunk object");
- hres = CallFormPages(_pCurrentForm, CALLFORMPAGES_ANSI, CQPM_PERSIST, TRUE, (LPARAM)pPersistQueryA2W);
- FailGracefully(hres, "Failed to load page data (ANSI)");
- }
- #endif
- hres = S_OK; // success
- exit_gracefully:
- if ( SUCCEEDED(hres) )
- {
- TraceMsg("Query loaded successfully, select form query");
- SelectForm(guid);
- }
- #ifdef UNICODE
- DoRelease(pPersistQueryA2W);
- #endif
- TraceLeaveResult(hres);
- }
- /*---------------------------------------------------------------------------*/
- STDMETHODIMP CQueryFrame::SaveQuery(THIS_ IPersistQuery* pPersistQuery)
- {
- HRESULT hres;
- LPQUERYSCOPE pQueryScope;
- #ifdef UNICODE
- CPersistQueryA2W* pPersistQueryA2W = NULL;
- #endif
- TCHAR szBuffer[MAX_PATH];
- TraceEnter(TRACE_FRAME, "CQueryFrame::SaveQuery");
- if ( !pPersistQuery )
- ExitGracefully(hres, E_INVALIDARG, "No pPersistQuery object to write into");
- pPersistQuery->Clear(); // flush the contents
- hres = pPersistQuery->WriteStruct(c_szCommonQuery, c_szHandlerIs,
- &_pOpenQueryWnd->clsidHandler,
- SIZEOF(_pOpenQueryWnd->clsidHandler));
- FailGracefully(hres, "Failed to write handler GUID");
- hres = pPersistQuery->WriteStruct(c_szCommonQuery, c_szFormIs,
- &_pCurrentForm->clsidForm,
- SIZEOF(_pCurrentForm->clsidForm));
- FailGracefully(hres, "Failed to write form GUID");
- #if HIDE_SEARCH_PANE
- hres = pPersistQuery->WriteInt(c_szCommonQuery, c_szSearchPaneHidden, _fHideSearchPane);
- FailGracefully(hres, "Failed to write form hide state");
- #endif
- // Allow the handler to persist itself into the the stream, this includes
- // giving it the current scope to store.
- hres = GetSelectedScope(&pQueryScope);
- FailGracefully(hres, "Failed to get the scope from the LookIn control");
- hres = _pQueryHandler->SaveQuery(pPersistQuery, pQueryScope->pScope);
- FailGracefully(hres, "Failed when calling handler to persist itself");
- // Save the query into the stream, coping correctly with the
- // UNICODE / ANSI issue. We will be passed an IPersistQuery object which
- // we must then thunk accordingly if we are UNICODE for the pages we
- // are going to talk to.
- #ifndef UNICODE
- hres = CallFormPages(_pCurrentForm, CALLFORMPAGES_ANSI, CQPM_PERSIST, FALSE, (LPARAM)pPersistQuery);
- FailGracefully(hres, "Failed to load form data");
- #else
- hres = CallFormPages(_pCurrentForm, CALLFORMPAGES_UNICODE, CQPM_PERSIST, FALSE, (LPARAM)pPersistQuery);
- FailGracefully(hres, "Failed to load page data (UNICODE)");
- if ( SUCCEEDED(hres) )
- {
- pPersistQueryA2W = new CPersistQueryA2W(pPersistQuery);
- TraceAssert(pPersistQueryA2W);
- if ( !pPersistQueryA2W )
- ExitGracefully(hres, E_OUTOFMEMORY, "Failed to construct persistance thunk object");
- hres = CallFormPages(_pCurrentForm, CALLFORMPAGES_ANSI, CQPM_PERSIST, FALSE, (LPARAM)pPersistQueryA2W);
- FailGracefully(hres, "Failed to load page data (ANSI)");
- }
- #endif
- hres = S_OK;
- exit_gracefully:
- #ifdef UNICODE
- DoRelease(pPersistQueryA2W);
- #endif
- TraceLeaveResult(hres);
- }
- /*---------------------------------------------------------------------------*/
- STDMETHODIMP CQueryFrame::CallForm(THIS_ LPCLSID pclsidForm, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- HRESULT hres;
- LPQUERYFORM pQueryForm = _pCurrentForm;
- TraceEnter(TRACE_FRAME, "CQueryFrame::CallForm");
- if ( pclsidForm )
- {
- pQueryForm = FindQueryForm(*pclsidForm);
- TraceAssert(pQueryForm);
- }
- if ( !pQueryForm )
- ExitGracefully(hres, E_FAIL, "Failed to find query form for given CLSID");
- hres = CallFormPages(pQueryForm, CALLFORMPAGES_ALL, uMsg, wParam, lParam);
- FailGracefully(hres, "Failed when calling CallFormPages");
- // hres = S_OK;
- exit_gracefully:
- TraceLeaveResult(hres);
- }
- /*---------------------------------------------------------------------------*/
- STDMETHODIMP CQueryFrame::GetScope(THIS_ LPCQSCOPE* ppScope)
- {
- HRESULT hres;
- LPQUERYSCOPE pQueryScope;
- TraceEnter(TRACE_FRAME, "CQueryFrame::GetScope");
- if ( !ppScope )
- ExitGracefully(hres, E_INVALIDARG, "ppScope == NULL, thats bad");
- hres = GetSelectedScope(&pQueryScope);
- FailGracefully(hres, "Failed to get the current scope");
- *ppScope = (LPCQSCOPE)CoTaskMemAlloc(pQueryScope->pScope->cbStruct);
- TraceAssert(*ppScope);
- if ( !*ppScope )
- ExitGracefully(hres, E_OUTOFMEMORY, "Failed to allocate the scope block");
- memcpy(*ppScope, pQueryScope->pScope, pQueryScope->pScope->cbStruct);
- hres = S_OK;
- exit_gracefully:
- TraceLeaveResult(hres);
- }
- /*---------------------------------------------------------------------------*/
- STDMETHODIMP CQueryFrame::GetHandler(THIS_ REFIID riid, void **ppv)
- {
- HRESULT hres;
- TraceEnter(TRACE_FRAME, "CQueryFrame::GetHandler");
- if ( !_pQueryHandler )
- ExitGracefully(hres, E_UNEXPECTED, "_pQueryHandler is NULL");
- hres = _pQueryHandler->QueryInterface(riid, ppv);
- exit_gracefully:
- TraceLeaveResult(hres);
- }
- /*-----------------------------------------------------------------------------
- / Dialog box handler functions (core guts)
- /----------------------------------------------------------------------------*/
- #define REAL_WINDOW(hwnd)
- (hwnd &&
- IsWindowVisible(hwnd) &&
- IsWindowEnabled(hwnd) &&
- (GetWindowLong(hwnd, GWL_STYLE) & WS_TABSTOP))
- HWND _NextTabStop(HWND hwndSearch, BOOL fShift)
- {
- HWND hwnd;
- Trace(TEXT("hwndSearch %08x, fShift %d"), hwndSearch, fShift);
- // do we have a window to search into?
- while ( hwndSearch )
- {
- // if we have a window then lets check to see if it has any children?
- hwnd = GetWindow(hwndSearch, GW_CHILD);
- Trace(TEXT("Child of %08x is %08x"), hwndSearch, hwnd);
- if ( hwnd )
- {
- // it has a child therefore lets to go its first/last
- // and continue the search there for a window that
- // matches the criteria we are looking for.
- hwnd = GetWindow(hwnd, fShift ? GW_HWNDLAST:GW_HWNDFIRST);
- if ( !REAL_WINDOW(hwnd) )
- {
- Trace(TEXT("Trying to recurse into %08x"), hwnd);
- hwnd = _NextTabStop(hwnd, fShift);
- }
- Trace(TEXT("Tabstop child of %08x is %08x"), hwndSearch, hwnd);
- }
- // after all that is hwnd a valid window? if so then pass
- // that back out to the caller.
- if ( REAL_WINDOW(hwnd) )
- {
- Trace(TEXT("Child tab stop was %08x"), hwnd);
- return hwnd;
- }
- // do we have a sibling? if so then lets return that otherwise
- // lets just continue to search until we either run out of windows
- // or hit something interesting
- hwndSearch = GetWindow(hwndSearch, fShift ? GW_HWNDPREV:GW_HWNDNEXT);
- if ( REAL_WINDOW(hwndSearch) )
- {
- Trace(TEXT("Next tab stop was %08x"), hwndSearch);
- return hwndSearch;
- }
- }
- return hwndSearch;
- }
- INT QueryWnd_MessageProc(HWND hwnd, LPMSG pMsg)
- {
- LRESULT lResult = 0;
- CQueryFrame* pQueryFrame = NULL;
- NMHDR nmhdr;
- pQueryFrame = (CQueryFrame*)GetWindowLongPtr(hwnd, DWLP_USER);
- if ( !pQueryFrame )
- return 0;
- if ( (pMsg->message == WM_KEYDOWN) && (pMsg->wParam == VK_TAB) )
- {
- BOOL fCtrl = GetAsyncKeyState(VK_CONTROL) < 0;
- BOOL fShift = GetAsyncKeyState(VK_SHIFT) < 0;
- // ensure that the focus rectangles are shown
- #if (_WIN32_WINNT >= 0x0500)
- SendMessage(hwnd, WM_CHANGEUISTATE, MAKEWPARAM(UIS_CLEAR, UISF_HIDEFOCUS), 0);
- #endif
- if ( fCtrl )
- {
- // if this is a key press within the parent then lets ensure that we
- // allow the tab control to change the page correctly. otherwise lets
- // just hack around the problem of the result view not handling tabs
- // properly.
- INT iCur = TabCtrl_GetCurSel(pQueryFrame->_hwndFrame);
- INT nPages = TabCtrl_GetItemCount(pQueryFrame->_hwndFrame);
- if ( fShift )
- iCur += (nPages-1);
- else
- iCur++;
- pQueryFrame->SelectFormPage(pQueryFrame->_pCurrentForm, iCur % nPages);
- return 1; // we processed it
- }
- else
- {
- // is the window that has the focus a child of the result view, if
- // so then we must attempt to pass focus to its 1st child and hope
- // that is can do the rest.
- HWND hwndNext, hwnd = GetFocus();
- Trace(TEXT("Current focus window %08x"), hwnd);
- while ( hwnd && GetWindowLong(hwnd, GWL_STYLE) & WS_CHILD )
- {
- hwndNext = _NextTabStop(hwnd, fShift);
- Trace(TEXT("_NextTabStop yeilds %08x from %08x"), hwndNext, hwnd);
- if ( hwndNext )
- {
- Trace(TEXT("SetFocus on child %08x"), hwndNext);
- SetFocus(hwndNext);
- return 1;
- }
- while ( TRUE )
- {
- // look up the parent list trying to find a window that we can
- // tab back into. We must watch that when we walk out of the
- // child list we loop correctly at the top of the list.
- hwndNext = GetParent(hwnd);
- Trace(TEXT("Parent hwnd %08x"), hwndNext);
- if ( GetWindowLong(hwndNext, GWL_STYLE) & WS_CHILD )
- {
- // the parent window is a child, therefore we can check
- // to see if has any siblings.
- Trace(TEXT("hwndNext is a child, therefore hwndNext of it is %08x"),
- GetWindow(hwndNext, fShift ? GW_HWNDPREV:GW_HWNDNEXT));
- if ( GetWindow(hwndNext, fShift ? GW_HWNDPREV:GW_HWNDNEXT) )
- {
- hwnd = GetWindow(hwndNext, fShift ? GW_HWNDPREV:GW_HWNDNEXT);
- Trace(TEXT("Silbing window found %08x"), hwnd);
- break;
- }
- else
- {
- TraceMsg("There was no sibling, therefore continuing parent loop");
- hwnd = hwndNext;
- }
- }
- else
- {
- // we have hit the parent window of it all (the overlapped one)
- // therefore we must attempt to go to its first child. Walk forward
- // in the stack looking for a window that matches the
- // "REAL_WINDOW" conditions.
- hwnd = GetWindow(hwnd, fShift ? GW_HWNDLAST:GW_HWNDFIRST);
- Trace(TEXT("First child is %08x"), hwnd);
- break; // continue the sibling search etc
- }
- }
- if ( REAL_WINDOW(hwnd) )
- {
- SetFocus(hwnd);
- return 1;
- }
- }
- }
- }
- return 0;
- }
- //
- // Main DLGPROC
- //
- INT_PTR CALLBACK QueryWnd_DlgProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- CQueryFrame* pQueryFrame;
- if ( uMsg == WM_INITDIALOG )
- {
- HRESULT hres;
- pQueryFrame = (CQueryFrame*)lParam;
- SetWindowLongPtr(hwnd, DWLP_USER, (LRESULT)pQueryFrame);
- hres = pQueryFrame->OnInitDialog(hwnd);
- Trace(TEXT("OnInitDialog returns %08x"), hres);
- if ( FAILED(hres) )
- {
- TraceMsg("Failed to initialize the dialog, Destroying the window");
- pQueryFrame->CloseQueryFrame(hres);
- DestroyWindow(hwnd);
- }
- }
- else
- {
- pQueryFrame = (CQueryFrame*)GetWindowLongPtr(hwnd, DWLP_USER);
- if ( !pQueryFrame )
- goto exit_gracefully;
- switch ( uMsg )
- {
- case WM_ERASEBKGND:
- {
- HDC hdc = (HDC)wParam;
- RECT rc;
- // if we have a DC then lets fill it, and if we have a
- // query form then lets paint the divider between the menu bar and
- // this area.
- if ( hdc )
- {
- GetClientRect(hwnd, &rc);
- FillRect(hdc, &rc, (HBRUSH)(COLOR_3DFACE+1));
- if ( !(pQueryFrame->_pOpenQueryWnd->dwFlags & OQWF_HIDEMENUS) )
- {
- #if HIDE_SEARCH_PANE
- if ( !pQueryFrame->_fHideSearchPane )
- DrawEdge(hdc, &rc, EDGE_ETCHED, BF_TOP);
- #else
- DrawEdge(hdc, &rc, EDGE_ETCHED, BF_TOP);
- #endif
- }
- SetWindowLongPtr(hwnd, DWLP_MSGRESULT, 1L);
- }
- return 1;
- }
- case WM_NOTIFY:
- return pQueryFrame->OnNotify((int)wParam, (LPNMHDR)lParam);
- case WM_SIZE:
- pQueryFrame->OnSize(LOWORD(lParam), HIWORD(lParam));
- return(1);
- case WM_GETMINMAXINFO:
- pQueryFrame->OnGetMinMaxInfo((LPMINMAXINFO)lParam);
- return(1);
- case WM_COMMAND:
- pQueryFrame->OnCommand(wParam, lParam);
- return(1);
- case WM_ACTIVATE:
- pQueryFrame->_pQueryHandler->ActivateView(wParam ? CQRVA_ACTIVATE : CQRVA_DEACTIVATE, 0, 0);
- return(1);
- case WM_INITMENU:
- pQueryFrame->OnInitMenu((HMENU)wParam);
- return(1);
- case WM_SETCURSOR:
- {
- // do we have any scopes? if not then let us display the wait
- // cursor for the user. if we have a query running then lets
- // display the app start cursor.
- if ( !pQueryFrame->_fAddScopesNYI &&
- !ComboBox_GetCount(pQueryFrame->_hwndLookIn) )
- {
- if ( LOWORD(lParam) == HTCLIENT )
- {
- SetCursor(LoadCursor(NULL, MAKEINTRESOURCE(IDC_WAIT)));
- SetWindowLongPtr(hwnd, DWLP_MSGRESULT, 1L);
- return 1;
- }
- }
- break;
- }
- case WM_INITMENUPOPUP:
- {
- // only send sub-menu activates if the menu bar is being tracked, this is
- // handled within OnInitMenu, if we are not tracking the menu then we
- // assume that the client has already primed the menu and that they are
- // using some kind of popup menu.
- if ( pQueryFrame->_fTrackingMenuBar )
- pQueryFrame->_pQueryHandler->ActivateView(CQRVA_INITMENUBARPOPUP, wParam, lParam);
- return(1);
- }
- case WM_ENTERMENULOOP:
- pQueryFrame->OnEnterMenuLoop(TRUE);
- return(1);
- case WM_EXITMENULOOP:
- pQueryFrame->OnEnterMenuLoop(FALSE);
- return(1);
- case WM_MENUSELECT:
- {
- UINT uID = LOWORD(wParam);
- UINT uFlags = HIWORD(wParam);
- HMENU hMenu = (HMENU)lParam;
- // the command opens a popup menu the the uID is actually
- // the index into the menu, so lets ensure that we pick
- // up the correct ID by calling GetMenuItemInfo, note that
- // GetMenuItemID returns -1 in this case which is totally
- // useless.
- if ( uFlags & MF_POPUP )
- {
- MENUITEMINFO mii;
- ZeroMemory(&mii, SIZEOF(mii));
- mii.cbSize = SIZEOF(mii);
- mii.fMask = MIIM_ID;
- if ( GetMenuItemInfo(hMenu, uID, TRUE, &mii) )
- uID = mii.wID;
- }
- pQueryFrame->OnMenuSelect(hMenu, uID);
- return(1);
- }
- case WM_SYSCOMMAND:
- if ( wParam == SC_CLOSE )
- {
- pQueryFrame->CloseQueryFrame(S_FALSE);
- return(1);
- }
- break;
- case WM_CONTEXTMENU:
- {
- // there are a couple of controls we don't care about for the
- // frame, so lets ignore those when passing the CQRVA_CONTEXTMENU
- // through to the handler.
- POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) };
- ScreenToClient((HWND)wParam, &pt);
- switch ( GetDlgCtrlID(ChildWindowFromPoint((HWND)wParam, pt)) )
- {
- case IDC_FORMAREA:
- case IDC_FINDANIMATION:
- case IDC_STATUS:
- return TRUE; // handled
- default:
- pQueryFrame->_pQueryHandler->ActivateView(CQRVA_CONTEXTMENU, wParam, lParam);
- return TRUE;
- }
- return FALSE;
- }
- case WM_HELP:
- {
- LPHELPINFO phi = (LPHELPINFO)lParam;
- // filter out those controls we are not interested in (they make no sense)
- // to bother the user with
- switch ( GetDlgCtrlID((HWND)phi->hItemHandle) )
- {
- case IDC_FORMAREA:
- case IDC_FINDANIMATION:
- case IDC_STATUS:
- return TRUE;
- default:
- pQueryFrame->OnHelp(phi);
- return TRUE;
- }
- return FALSE;
- }
- case CQFWM_ADDSCOPE:
- {
- LPCQSCOPE pScope = (LPCQSCOPE)wParam;
- BOOL fSelect = LOWORD(lParam);
- INT iIndex = HIWORD(lParam);
- if ( SUCCEEDED(pQueryFrame->AddScope(pScope, iIndex, fSelect)) )
- SetWindowLongPtr(hwnd, DWLP_MSGRESULT, 1L);
- return 1;
- }
- case CQFWM_GETFRAME:
- {
- IQueryFrame** ppQueryFrame = (IQueryFrame**)lParam;
- if ( ppQueryFrame )
- {
- pQueryFrame->AddRef();
- *ppQueryFrame = pQueryFrame;
- SetWindowLongPtr(hwnd, DWLP_MSGRESULT, 1L);
- }
- return 1;
- }
- case CQFWM_ALLSCOPESADDED:
- {
- // there is an async scope collector, it has added all the scopes
- // so we must now attempt to issue the query if the we are in the
- // holding pattern waiting for the scopes to be collected.
- pQueryFrame->_fScopesAddedAsync = FALSE; // all scopes have been added
- if ( pQueryFrame->_pOpenQueryWnd->dwFlags & OQWF_ISSUEONOPEN )
- PostMessage(pQueryFrame->_hwnd, CQFWM_STARTQUERY, 0, 0);
- return 1;
- }
- case CQFWM_STARTQUERY:
- pQueryFrame->OnFindNow();
- return 1;
- default:
- break;
- }
- }
- exit_gracefully:
- return(0);
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::CloseQueryFrame
- / ----------------------------
- / Close the query window passing back the data object if required, and ensuring
- / that our result code indicates what is going on.
- /
- / In:
- / hResult = result code to pass to the caller
- /
- / Out:
- / -
- /----------------------------------------------------------------------------*/
- VOID CQueryFrame::CloseQueryFrame(HRESULT hres)
- {
- TraceEnter(TRACE_FRAME, "CQueryFrame::CloseQueryFrame");
- Trace(TEXT("hResult %08x"), hres);
- // If we succeeded then attempt to collect the IDataObject and pass it
- // back to the caller.
- if ( hres == S_OK )
- {
- if ( _ppDataObject )
- {
- hres = _pQueryHandler->GetViewObject(CQRVS_SELECTION, IID_IDataObject, (LPVOID*)_ppDataObject);
- FailGracefully(hres, "Failed when collecting the data object");
- }
- if ( (_pOpenQueryWnd->dwFlags & OQWF_SAVEQUERYONOK) && _pOpenQueryWnd->pPersistQuery )
- {
- hres = SaveQuery(_pOpenQueryWnd->pPersistQuery);
- FailGracefully(hres, "Failed when persisting query to IPersistQuery blob");
- }
- hres = S_OK; // success
- }
- exit_gracefully:
- _hResult = hres;
- _fExitModalLoop = TRUE; // bomb out of the modal loop
- TraceLeave();
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::HideSearchPane
- / -------------------------
- / Hide the form area of the query window. This involves hiding the controls
- / present and moving the contents of the windo to reflect the change we
- / are making.
- /
- / In:
- / fHide = show/hide flag
- /
- / Out:
- / -
- /----------------------------------------------------------------------------*/
- #if HIDE_SEARCH_PANE
- const UINT g_idControls[] =
- {
- CQID_BROWSE,
- CQID_FINDNOW,
- CQID_STOP,
- CQID_CLEARALL,
- IDC_FORMAREA,
- IDC_FINDANIMATION,
- };
- VOID CQueryFrame::HideSearchPane(BOOL fHide)
- {
- RECT rect, rcClient;
- MINMAXINFO mmi;
- INT i, cx, cy, cxClient, cyClient;
- INT nCmdShow = fHide ? SW_HIDE:SW_SHOW;
- TraceEnter(TRACE_FRAME, "CQueryFrame::HideSearchPane");
- if ( _fHideSearchPane != fHide )
- {
- _fHideSearchPane = fHide;
- LockWindowUpdate(_hwnd);
- // hide the window controls that we are not interested in,
- // taking special care for the optional controls on the window
- for ( i = 0 ; i < ARRAYSIZE(g_idControls); i++ )
- ShowWindow(GetDlgItem(_hwnd, g_idControls[i]), nCmdShow);
- if ( _pCurrentFormPage && _pCurrentFormPage->hwndPage )
- ShowWindow(_pCurrentFormPage->hwndPage, nCmdShow);
- if ( !(_pOpenQueryWnd->dwFlags & OQWF_REMOVEFORMS) )
- {
- ShowWindow(_hwndLookForLabel, nCmdShow);
- ShowWindow(_hwndLookFor, nCmdShow);
- }
- if ( !(_pOpenQueryWnd->dwFlags & OQWF_REMOVESCOPES) )
- {
- ShowWindow(_hwndLookInLabel, nCmdShow);
- ShowWindow(_hwndLookIn, nCmdShow);
- }
- if ( _pOpenQueryWnd->dwFlags & OQWF_OKCANCEL )
- {
- ShowWindow(_hwndOK, nCmdShow);
- if ( _hwndCancel )
- ShowWindow(_hwndCancel, nCmdShow);
- }
- // now adjust the main window area to cope with the
- // form being hidden or shown.
- GetClientRect(_hwnd, &rcClient);
- GetWindowRect(_hwnd, &rect);
- cxClient = rcClient.right - rcClient.left;
- cyClient = rcClient.bottom - rcClient.top;
- if ( _fHideSearchPane )
- {
- OnSize(cxClient, cyClient);
- }
- else
- {
- // when enabling the form area we must ensure that the window is
- // at least big enough to show it, therefore we need to get the
- // min track size, and apply that the current size. If there is
- // no change then we don't bother calling SetWindowPos, we just
- // call OnSize and let that take care of verything.
- OnGetMinMaxInfo(&mmi);
- cx = max(rect.right-rect.left, mmi.ptMinTrackSize.x); // width
- cy = max(rect.bottom-rect.top, mmi.ptMinTrackSize.y); // height
- if ( (cx == (rect.right - rect.left)) && (cy == (rect.bottom - rect.top)) )
- {
- TraceMsg("Calling OnSize, no physical size change to window");
- OnSize(cxClient, cyClient);
- }
- else
- {
- TraceMsg("Sizing window to make form visible");
- SetWindowPos(_hwnd, NULL, 0, 0, cx, cy, SWP_NOZORDER|SWP_NOMOVE);
- }
- }
- LockWindowUpdate(NULL);
- RedrawWindow(_hwnd, NULL, NULL, RDW_ERASE|RDW_FRAME|RDW_UPDATENOW|RDW_ALLCHILDREN);
- }
- DoEnableControls(); // ensure we fix the grey state of the controls
- TraceLeave();
- }
- #endif
- /*-----------------------------------------------------------------------------
- / CQueryFrame::FrameMessageBox
- / ----------------------------
- / Our message box for putting up prompts that relate to the current
- / query. We handle getting the view information and displaying
- / the prompt, returning the result from MessageBox.
- /
- / In:
- / pPrompt = text displayed as a prompt
- / uType = message box type
- /
- / Out:
- / INT
- /----------------------------------------------------------------------------*/
- INT CQueryFrame::FrameMessageBox(LPCTSTR pPrompt, UINT uType)
- {
- TCHAR szTitle[MAX_PATH];
- CQVIEWINFO vi;
- TraceEnter(TRACE_FRAME, "CQueryFrame::FrameMessageBox");
- ZeroMemory(&vi, SIZEOF(vi));
- //vi. dwFlags = 0; // display attributes
- if ( SUCCEEDED(_pQueryHandler->GetViewInfo(&vi)) && vi.hInstance && vi.idTitle )
- LoadString(vi.hInstance, vi.idTitle, szTitle, ARRAYSIZE(szTitle));
- else
- GetWindowText(_hwnd, szTitle, ARRAYSIZE(szTitle));
- TraceLeaveValue(MessageBox(_hwnd, pPrompt, szTitle, uType));
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::OnInitDlg
- / ----------------------
- / Handle a WM_INITDAILOG message, this is sent as the first thing the
- / dialog receives, therefore we must handle our initialization that
- / was not handled in the constructor.
- /
- / In:
- / hwnd = handle of dialog we are initializing
- /
- / Out:
- / HRESULT
- /----------------------------------------------------------------------------*/
- HRESULT CQueryFrame::OnInitDialog(HWND hwnd)
- {
- HRESULT hres;
- HICON hIcon = NULL;
- TCHAR szGUID[GUIDSTR_MAX+1];
- TCHAR szBuffer[MAX_PATH];
- CQVIEWINFO vi;
- INT dyControls = 0;
- RECT rect, rect2;
- SIZE size;
- TraceEnter(TRACE_FRAMEDLG, "CQueryFrame::OnInitDialog");
- // get the HKEY for the handler we are using
- hres = GetKeyForCLSID(_pOpenQueryWnd->clsidHandler, NULL, &_hkHandler);
- FailGracefully(hres, "Failed to open handlers HKEY");
- // pick up the control handles and store them, saves picking them up later
- _hwnd = hwnd;
- _hwndFrame = GetDlgItem(hwnd, IDC_FORMAREA);
- _hwndLookForLabel = GetDlgItem(hwnd, CQID_LOOKFORLABEL);
- _hwndLookFor = GetDlgItem(hwnd, CQID_LOOKFOR);
- _hwndLookInLabel = GetDlgItem(hwnd, CQID_LOOKINLABEL);
- _hwndLookIn = GetDlgItem(hwnd, CQID_LOOKIN);
- _hwndBrowse = GetDlgItem(hwnd, CQID_BROWSE);
- _hwndFindNow = GetDlgItem(hwnd, CQID_FINDNOW);
- _hwndStop = GetDlgItem(hwnd, CQID_STOP);
- _hwndNewQuery = GetDlgItem(hwnd, CQID_CLEARALL);
- _hwndFindAnimation = GetDlgItem(hwnd, IDC_FINDANIMATION);
- _hwndOK = GetDlgItem(hwnd, IDOK);
- _hwndCancel = GetDlgItem(hwnd, IDCANCEL);
- // call the IQueryHandler interface and get its display attributes,
- // then reflect these into the dialog we are about to display to the
- // outside world.
- vi.dwFlags = 0;
- vi.hInstance = NULL;
- vi.idLargeIcon = 0;
- vi.idSmallIcon = 0;
- vi.idTitle = 0;
- vi.idAnimation = 0;
- hres = _pQueryHandler->GetViewInfo(&vi);
- FailGracefully(hres, "Failed when getting the view info from the handler");
- _dwHandlerViewFlags = vi.dwFlags;
- if ( vi.hInstance )
- {
- HICON hiTemp = NULL;
- if ( vi.idLargeIcon )
- {
- _hiconLarge = (HICON)LoadImage(vi.hInstance,
- MAKEINTRESOURCE(vi.idLargeIcon),
- IMAGE_ICON,
- 0, 0,
- LR_DEFAULTCOLOR|LR_DEFAULTSIZE);
- if ( _hiconLarge )
- SendMessage(hwnd, WM_SETICON, ICON_BIG, (LPARAM)_hiconLarge);
- }
- if ( vi.idSmallIcon )
- {
- _hiconSmall = (HICON)LoadImage(vi.hInstance,
- MAKEINTRESOURCE(vi.idLargeIcon),
- IMAGE_ICON,
- GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON),
- LR_DEFAULTCOLOR);
- if ( _hiconSmall )
- SendMessage(hwnd, WM_SETICON, ICON_SMALL, (LPARAM)_hiconSmall);
- }
- if ( vi.idTitle )
- {
- LoadString(vi.hInstance, vi.idTitle, szBuffer, ARRAYSIZE(szBuffer));
- SetWindowText(hwnd, szBuffer);
- }
- }
- if ( vi.hInstance && vi.idAnimation )
- {
- SetWindowLongPtr(_hwndFindAnimation, GWLP_HINSTANCE, (LRESULT)vi.hInstance);
- Animate_Open(_hwndFindAnimation, MAKEINTRESOURCE(vi.idAnimation));
- }
- else
- {
- Animate_Open(_hwndFindAnimation, MAKEINTRESOURCE(AVI_FIND));
- }
- // now adjust the positions and hide the controls we are not interested in
- if ( _pOpenQueryWnd->dwFlags & OQWF_REMOVEFORMS )
- {
- ShowWindow(_hwndLookForLabel, SW_HIDE);
- ShowWindow(_hwndLookFor, SW_HIDE);
- }
- if ( _pOpenQueryWnd->dwFlags & OQWF_REMOVESCOPES )
- {
- ShowWindow(_hwndLookInLabel, SW_HIDE);
- ShowWindow(_hwndLookIn, SW_HIDE);
- ShowWindow(_hwndBrowse, SW_HIDE);
- }
- // hiding both the scopes and the forms control causes us to
- // move all the controls up by so many units.
- if ( (_pOpenQueryWnd->dwFlags & (OQWF_REMOVEFORMS|OQWF_REMOVESCOPES))
- == (OQWF_REMOVEFORMS|OQWF_REMOVESCOPES) )
- {
- GetRealWindowInfo(_hwndLookForLabel, &rect, NULL);
- GetRealWindowInfo(_hwndFrame, &rect2, NULL);
- dyControls += rect2.top - rect.top;
- Trace(TEXT("Moving all controls up by %d units"), dyControls);
- OffsetWindow(_hwndFrame, 0, -dyControls);
- OffsetWindow(_hwndFindNow, 0, -dyControls);
- OffsetWindow(_hwndStop, 0, -dyControls);
- OffsetWindow(_hwndNewQuery, 0, -dyControls);
- OffsetWindow(_hwndFindAnimation, 0, -dyControls);
- OffsetWindow(_hwndOK, 0, -dyControls);
- if ( _hwndCancel )
- OffsetWindow(_hwndCancel, 0, -dyControls);
- }
- // hiding OK/Cancel so lets adjust the size here to include the
- // OK/Cancel buttons disappearing, note that we update dyControls
- // to include this delta
- if ( !(_pOpenQueryWnd->dwFlags & OQWF_OKCANCEL) )
- {
- ShowWindow(_hwndOK, SW_HIDE);
- if ( _hwndCancel )
- ShowWindow(_hwndCancel, SW_HIDE);
- // if this is the filter dialog then lets ensure that
- // we trim the OK/Cancel buttons from the size by adjusting the
- // dyControls further.
- GetRealWindowInfo(_hwndOK, &rect, NULL);
- GetRealWindowInfo(_hwndFrame, &rect2, NULL);
- dyControls += rect.bottom - rect2.bottom;
- }
- // having performed that extra bit of initialization lets cache the
- // positions of the various controls, to make sizing more fun...
- GetClientRect(hwnd, &rect2);
- rect2.bottom -= dyControls;
- _dyResultsTop = rect2.bottom;
- GetRealWindowInfo(hwnd, NULL, &size);
- GetRealWindowInfo(_hwndFrame, &rect, &_szForm);
- Trace(TEXT("dyControls %d"), dyControls);
- size.cy -= dyControls;
- _dxFormAreaLeft = rect.left;
- _dxFormAreaRight = rect2.right - rect.right;
- _szMinTrack.cx = size.cx - _szForm.cx;
- _szMinTrack.cy = size.cy - _szForm.cy;
- if ( !(_pOpenQueryWnd->dwFlags & OQWF_HIDEMENUS) )
- {
- TraceMsg("Adjusting _szMinTrack.cy to account for menu bar");
- _szMinTrack.cy += GetSystemMetrics(SM_CYMENU);
- }
- GetRealWindowInfo(_hwndBrowse, &rect, NULL);
- _dxButtonsLeft = rect2.right - rect.left;
- GetRealWindowInfo(_hwndLookIn, &rect, NULL);
- _dxGap = (rect2.right - rect.right) - _dxButtonsLeft;
- GetRealWindowInfo(_hwndFindAnimation, &rect, NULL);
- _dxAnimationLeft = rect2.right - rect.left;
- GetRealWindowInfo(_hwndOK, &rect, NULL);
- _dyOKTop = rect2.bottom - rect.top;
- _dyGap = size.cy - rect.bottom;
- // Now collect the forms and pages, then walk them building the size
- // information that we need.
- hres = GatherForms();
- FailGracefully(hres, "Failed to init form list");
- _szMinTrack.cx += _szForm.cx;
- _szMinTrack.cy += _szForm.cy;
- // Populate the scope control by querying the handler for them,
- // if there are none then we display a suitable message box and
- // let the user know that something went wrong.
- hres = PopulateScopeControl();
- FailGracefully(hres, "Failed to init scope list");
- _fScopesPopulated = TRUE; // scope control now populated
- // perform final fix up of the window, ensure that we size it so that
- // the entire form and buttons are visible. Then set ourselves into the
- // no query state and reset the animation.
- SetWindowPos(hwnd,
- NULL,
- 0, 0,
- _szMinTrack.cx, _szMinTrack.cy,
- SWP_NOMOVE|SWP_NOZORDER);
- if ( _pOpenQueryWnd->dwFlags & OQWF_HIDEMENUS )
- ::SetMenu(hwnd, NULL);
- hres = PopulateFormControl(_pOpenQueryWnd->dwFlags & OQWF_SHOWOPTIONAL);
- FailGracefully(hres, "Failed to populate form control");
- // Now load the query which inturn selects the form that we should be using,
- // if there is no query to load then either use the default form or
- // the first in the list.
- if ( (_pOpenQueryWnd->dwFlags & OQWF_LOADQUERY) && _pOpenQueryWnd->pPersistQuery )
- {
- hres = LoadQuery(_pOpenQueryWnd->pPersistQuery);
- FailGracefully(hres, "Failed when to load query from supplied IPersistQuery");
- }
- else
- {
- if ( _pOpenQueryWnd->dwFlags & OQWF_DEFAULTFORM )
- {
- SelectForm(_pOpenQueryWnd->clsidDefaultForm);
- if ( !_pCurrentForm )
- ExitGracefully(hres, E_FAIL, "Failed to select the query form");
- }
- else
- {
- INT iForm = (int)ComboBox_GetItemData(_hwndLookFor, 0);
- LPQUERYFORM pQueryForm = (LPQUERYFORM)DSA_GetItemPtr(_hdsaForms, iForm);
- TraceAssert(pQueryForm);
- SelectForm(pQueryForm->clsidForm);
- }
- }
- StartQuery(FALSE);
- if ( _pCurrentFormPage )
- {
- Trace(TEXT("Setting focus to the form page (%08x)"), _pCurrentFormPage->hwndPage);
- SetFocus(_pCurrentFormPage->hwndPage);
- }
- #if HIDE_SEARCH_PANE
- // If we need to be issuing the query on open then lets ensure that
- // we have some scopes, if we do then we can just post ourselves a
- // WM_COMMAND with the relevant ID (IDC_FINDNOW).
- if ( _pOpenQueryWnd->dwFlags & OQWF_ISSUEONOPEN )
- {
- if ( _pOpenQueryWnd->dwFlags & OQWF_HIDESEARCHPANE )
- HideSearchPane(TRUE);
- PostMessage(_hwnd, CQFWM_STARTQUERY, 0, 0);
- }
- #else
- // issue on open, therefore lets get the query going, if there is async
- // scope collection then the query will be issued by the bg thread.
- if ( _pOpenQueryWnd->dwFlags & OQWF_ISSUEONOPEN )
- PostMessage(_hwnd, CQFWM_STARTQUERY, 0, 0);
- #endif
- SetForegroundWindow(hwnd);
- hres = S_OK; // success
- exit_gracefully:
- TraceLeaveResult(hres);
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::EnableControls
- / ---------------------------
- / Set the controls into their enabled/disabled state based on the
- / state of the dialog.
- /
- / In:
- / -
- /
- / Out:
- / HRESULT
- /----------------------------------------------------------------------------*/
- VOID CQueryFrame::DoEnableControls(VOID)
- {
- BOOL fScopes = (_fAddScopesNYI || ComboBox_GetCount(_hwndLookIn));
- #if HIDE_SEARCH_PANE
- BOOL fEnable = fScopes && !_fHideSearchPane;
- #else
- BOOL fEnable = fScopes;
- #endif
- UINT uEnable = fScopes ? MF_ENABLED:MF_GRAYED;
- HMENU hMenu = GetMenu(_hwnd);
- INT i;
- TraceEnter(TRACE_FRAMEDLG, "CQueryFrame::DoEnableControls");
- EnableWindow(_hwndFindNow, !_fQueryRunning && fEnable);
- EnableWindow(_hwndStop, _fQueryRunning && fEnable);
- EnableWindow(_hwndNewQuery, fEnable);
- EnableWindow(_hwndLookFor, !_fQueryRunning && fEnable);
- EnableWindow(_hwndLookIn, !_fQueryRunning && fEnable);
- EnableWindow(_hwndBrowse, !_fQueryRunning && fEnable);
- if ( _pCurrentForm )
- CallFormPages(_pCurrentForm, CALLFORMPAGES_ALL, CQPM_ENABLE, (BOOL)(!_fQueryRunning && fEnable), 0);
- if ( _hwndOK )
- EnableWindow(_hwndOK, !_fQueryRunning && fEnable);
- if ( _hwndCancel )
- EnableWindow(_hwndCancel, !_fQueryRunning && fEnable);
- for ( i = 0 ; i < GetMenuItemCount(hMenu) ; i++ )
- EnableMenuItem(hMenu, i, MF_BYPOSITION|uEnable);
- DrawMenuBar(_hwnd);
- TraceLeave();
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::OnNotify
- / ---------------------
- / Notify event received, decode it and handle accordingly
- /
- / In:
- / idCtrl = ID of control issuing notify
- / pNotify -> LPNMHDR structure
- /
- / Out:
- / LRESULT
- /----------------------------------------------------------------------------*/
- LRESULT CQueryFrame::OnNotify(INT idCtrl, LPNMHDR pNotify)
- {
- LRESULT lr = 0;
- TraceEnter(TRACE_FRAMEDLG, "CQueryFrame::OnNotify");
- // TCN_SELCHANGE used to indicate that the currently active
- // tab has been changed
- if ( pNotify->code == TCN_SELCHANGE )
- {
- INT iPage = TabCtrl_GetCurSel(_hwndFrame);
- TraceAssert(iPage >= 0);
- if ( iPage >= 0 )
- {
- SelectFormPage(_pCurrentForm, iPage);
- lr = 0;
- }
- }
- TraceLeaveResult((HRESULT)lr);
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::OnSize
- / -------------------
- / The window is being sized and we received a WM_SIZE, therefore move
- / the content of the window about.
- /
- / In:
- / cx = new width
- / cy = new height
- /
- / Out:
- / -
- /----------------------------------------------------------------------------*/
- VOID CQueryFrame::OnSize(INT cx, INT cy)
- {
- HDWP hdwp;
- RECT rect, rect2;
- SIZE sz, sz2;
- INT x, cxForm, cyForm;
- INT dyResultsTop = 0;
- TraceEnter(TRACE_FRAMEDLG, "CQueryFrame::OnSize");
- // do as much as we can within a DefWindowPos to aVOID too
- // much flicker.
- hdwp = BeginDeferWindowPos(16);
- if ( hdwp )
- {
- {
- // adjust the look for controls, if there is no scope then
- // stretch the look for control over the entire client area
- // of the window.
- if ( !(_pOpenQueryWnd->dwFlags & OQWF_REMOVEFORMS) )
- {
- if ( _pOpenQueryWnd->dwFlags & OQWF_REMOVESCOPES )
- {
- GetRealWindowInfo(_hwndLookFor, &rect, &sz);
- hdwp = DeferWindowPos(hdwp, _hwndLookFor, NULL,
- 0, 0,
- (cx - _dxFormAreaRight) - rect.left, sz.cy,
- SWP_NOZORDER|SWP_NOMOVE);
- }
- }
- // adjust the "look in" controls, if there is a form control
- // then stretch across the remaining space, otherwise move the
- // label and stretch the scope over the remaining space.
- if ( !(_pOpenQueryWnd->dwFlags & OQWF_REMOVESCOPES) )
- {
- INT xScopeRight;
- GetRealWindowInfo(_hwndLookIn, &rect, &sz);
- xScopeRight = cx - _dxFormAreaRight - _dxGap;
- if ( _pOpenQueryWnd->dwFlags & OQWF_HIDESEARCHUI )
- {
- //
- // when hiding the search UI, then adjust the button position to account for the
- // right edge of the dialog not having buttons.
- //
- xScopeRight -= (_dxButtonsLeft - _dxFormAreaRight) + _dxGap;
- }
- if ( _pOpenQueryWnd->dwFlags & OQWF_REMOVEFORMS )
- {
- GetRealWindowInfo(_hwndLookInLabel, &rect2, &sz2);
- hdwp = DeferWindowPos(hdwp, _hwndLookInLabel, NULL,
- _dxFormAreaLeft, rect2.top,
- 0, 0,
- SWP_NOSIZE|SWP_NOZORDER);
- hdwp = DeferWindowPos(hdwp, _hwndLookIn, NULL,