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++
- _dxFormAreaLeft+sz2.cx, rect.top,
- xScopeRight - (_dxFormAreaLeft + sz2.cx), sz.cy,
- SWP_NOZORDER);
- }
- else
- {
- hdwp = DeferWindowPos(hdwp, _hwndLookIn, NULL,
- 0, 0,
- xScopeRight - rect.left, sz.cy,
- SWP_NOZORDER|SWP_NOMOVE);
- }
- // browse control is displayed always if we are showing the
- // scopes.
- GetRealWindowInfo(_hwndBrowse, &rect, NULL);
- hdwp = DeferWindowPos(hdwp, _hwndBrowse, NULL,
- xScopeRight+_dxGap, rect.top,
- 0, 0,
- SWP_NOZORDER|SWP_NOSIZE);
- }
- // all the buttons have a fixed offset from the right edege
- // of the dialog, so just handle that as we can.
- if ( !(_pOpenQueryWnd->dwFlags & OQWF_HIDESEARCHUI) )
- {
- GetRealWindowInfo(_hwndFindNow, &rect, NULL);
- hdwp = DeferWindowPos(hdwp, _hwndFindNow, NULL,
- (cx - _dxButtonsLeft), rect.top,
- 0, 0,
- SWP_NOZORDER|SWP_NOSIZE);
- GetRealWindowInfo(_hwndStop, &rect, &sz);
- hdwp = DeferWindowPos(hdwp, _hwndStop, NULL,
- (cx - _dxButtonsLeft), rect.top,
- 0, 0,
- SWP_NOZORDER|SWP_NOSIZE);
- GetRealWindowInfo(_hwndNewQuery, &rect, NULL);
- hdwp = DeferWindowPos(hdwp, _hwndNewQuery, NULL,
- (cx - _dxButtonsLeft), rect.top,
- 0, 0,
- SWP_NOZORDER|SWP_NOSIZE);
- GetRealWindowInfo(_hwndFindAnimation, &rect2, &sz2);
- hdwp = DeferWindowPos(hdwp, _hwndFindAnimation, NULL,
- (cx - _dxAnimationLeft), rect2.top,
- 0, 0,
- SWP_NOZORDER|SWP_NOSIZE);
- }
- // position the form "frame" control
- GetRealWindowInfo(_hwndFrame, &rect, &sz);
- cxForm = (cx - _dxFormAreaRight) - rect.left;
- hdwp = DeferWindowPos(hdwp, _hwndFrame, NULL,
- 0, 0,
- cxForm, _szForm.cy,
- SWP_NOZORDER|SWP_NOMOVE);
- dyResultsTop = _dyResultsTop;
- // when we have a cancel button then ensure that it is to the right
- // of the OK button.
- if ( _hwndCancel )
- {
- GetRealWindowInfo(_hwndCancel, &rect, &sz);
- hdwp = DeferWindowPos(hdwp, _hwndCancel, NULL,
- (cx - _dxButtonsLeft), dyResultsTop - _dyOKTop,
- 0, 0,
- SWP_NOZORDER|SWP_NOSIZE);
- GetRealWindowInfo(_hwndOK, &rect, &sz);
- hdwp = DeferWindowPos(hdwp, _hwndOK, NULL,
- (cx - _dxButtonsLeft - _dxGap - sz.cx), dyResultsTop - _dyOKTop,
- 0, 0,
- SWP_NOZORDER|SWP_NOSIZE);
- }
- else
- {
- GetRealWindowInfo(_hwndOK, &rect, &sz);
- hdwp = DeferWindowPos(hdwp, _hwndOK, NULL,
- (cx - _dxButtonsLeft), dyResultsTop - _dyOKTop,
- 0, 0,
- SWP_NOZORDER|SWP_NOSIZE);
- }
- }
- // move the results and status bar as required
- if ( _hwndResults )
- {
- hdwp = DeferWindowPos(hdwp, _hwndStatus, NULL,
- 0, cy - _cyStatus,
- cx, _cyStatus,
- SWP_SHOWWINDOW|SWP_NOZORDER);
- hdwp = DeferWindowPos(hdwp, _hwndResults, NULL,
- 0, dyResultsTop,
- cx, max(0, cy - (dyResultsTop + _cyStatus)),
- SWP_SHOWWINDOW|SWP_NOZORDER);
- }
- EndDeferWindowPos(hdwp);
- // here is the strange bit, by this point we have moved & sized all the
- // controls on the dialog except the current page, as this is a child window
- // and not a control which in turn has controls doing this would break
- // the DefWindowPos path, therefore having updated everybody, lets update
- // the page.
- #if HIDE_SEARCH_PANE
- if ( !_fHideSearchPane && _pCurrentFormPage && _pCurrentFormPage->hwndPage )
- #else
- if ( _pCurrentFormPage && _pCurrentFormPage->hwndPage )
- #endif
- {
- GetRealWindowInfo(_hwndFrame, &rect, NULL);
- TabCtrl_AdjustRect(_hwndFrame, FALSE, &rect);
- cxForm = rect.right - rect.left;
- cyForm = rect.bottom - rect.top;
- SetWindowPos(_pCurrentFormPage->hwndPage, NULL,
- rect.left, rect.top, cxForm, cyForm,
- SWP_NOZORDER);
- }
- }
- TraceLeave();
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::OnGetMinMaxInfo
- / ----------------------------
- / The window is being sized and we received a WM_SIZE, therefore move
- / the content of the window about.
- /
- / In:
- / lpmmin -> MINMAXINFO structure
- /
- / Out:
- / -
- /----------------------------------------------------------------------------*/
- VOID CQueryFrame::OnGetMinMaxInfo(LPMINMAXINFO lpmmi)
- {
- RECT rect = {0, 0, 0, 0};
- TraceEnter(TRACE_FRAMEDLG, "CQueryFrame::OnGetMinMaxInfo");
- #if 0
- if ( !_fHideSearchPane )
- #endif
- {
- lpmmi->ptMinTrackSize.x = _szMinTrack.cx;
- lpmmi->ptMinTrackSize.y = _szMinTrack.cy;
- if ( !_hwndResults )
- {
- lpmmi->ptMaxSize.y = lpmmi->ptMinTrackSize.y;
- lpmmi->ptMaxTrackSize.y = lpmmi->ptMinTrackSize.y;
- }
- }
- #if 0
- else
- {
- AdjustWindowRect(&rect, GetWindowLong(_hwnd, GWL_STYLE), (NULL != GetMenu(_hwnd)));
- lpmmi->ptMinTrackSize.y = rect.bottom - rect.top;
- }
- #endif
- if ( _hwndResults && _hwndStatus )
- lpmmi->ptMinTrackSize.y += _cyStatus;
- TraceLeave();
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::OnCommand
- / ----------------------
- / We have recieved a WM_COMMAND so process it accordingly.
- /
- / In:
- / wParam, lParam = parameters from the message
- /
- / Out:
- / -
- /----------------------------------------------------------------------------*/
- VOID CQueryFrame::OnCommand(WPARAM wParam, LPARAM lParam)
- {
- HRESULT hres;
- UINT uID = LOWORD(wParam);
- UINT uNotify = HIWORD(wParam);
- HWND hwndControl = (HWND)lParam;
- INT i;
- TraceEnter(TRACE_FRAMEDLG, "CQueryFrame::OnCommand");
- Trace(TEXT("uID %08x, uNotify %d, hwndControl %08x"), uID, uNotify, hwndControl);
- switch ( uID )
- {
- case IDOK:
- TraceMsg("IDOK received");
- CloseQueryFrame(S_OK);
- break;
- case IDCANCEL:
- TraceMsg("IDCANCEL received");
- CloseQueryFrame(S_FALSE);
- break;
- case CQID_LOOKFOR:
- {
- if ( uNotify == CBN_SELCHANGE )
- {
- INT iSel = ComboBox_GetCurSel(_hwndLookFor);
- INT iForm = (int)ComboBox_GetItemData(_hwndLookFor, iSel);
- LPQUERYFORM pQueryForm = (LPQUERYFORM)DSA_GetItemPtr(_hdsaForms, iForm);
- TraceAssert(pQueryForm);
- if ( S_FALSE == SelectForm(pQueryForm->clsidForm) )
- {
- TraceMsg("SelectForm return S_FALSE, so the user doesn't want the new form");
- PostMessage(_hwndLookFor, CB_SETCURSEL, (WPARAM)_pCurrentForm->iForm, 0);
- }
- }
- break;
- }
- case CQID_BROWSE:
- OnBrowse();
- break;
- case CQID_FINDNOW:
- OnFindNow();
- break;
- case CQID_STOP:
- {
- LONG style;
- _pQueryHandler->StopQuery();
- // For some reason, the standard method of getting the old
- // def button used in SetDefButton() below isn't working,
- // so we have to forcibly remove the BS_DEFPUSHBUTTON style
- // from the CQID_STOP button.
- style = GetWindowLong(_hwndStop, GWL_STYLE) & ~BS_DEFPUSHBUTTON;
- SendMessage(_hwndStop,
- BM_SETSTYLE,
- MAKEWPARAM(style, 0),
- MAKELPARAM(TRUE, 0));
- SetDefButton(_hwnd, CQID_FINDNOW);
- SetFocus(_hwndFindNow);
- break;
- }
- case CQID_CLEARALL:
- OnNewQuery(TRUE); // discard the current query
- break;
- #if HIDE_SEARCH_PANE
- case CQID_VIEW_SEARCHPANE:
- HideSearchPane(!_fHideSearchPane);
- break;
- #endif
- case CQID_FILE_CLOSE:
- TraceMsg("CQID_FILE_CLOSE received");
- CloseQueryFrame(S_FALSE);
- break;
- default:
- _pQueryHandler->InvokeCommand(_hwnd, uID);
- break;
- }
- TraceLeave();
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::OnInitMenu
- / -----------------------
- / Handle telling the handler that the menu is being initialised, however
- / this should only happen if the menu being activated is the
- / menu bar, otherwise we assume that the caller is tracking a popup
- / menu and has performed the required initalization.
- /
- / In:
- / wParam, lParam = parameters from the WM_INITMENU
- /
- / Out:
- / -
- /----------------------------------------------------------------------------*/
- VOID CQueryFrame::OnInitMenu(HMENU hMenu)
- {
- TraceEnter(TRACE_FRAMEDLG, "CQueryFrame::OnInitMenu");
- _fTrackingMenuBar = (GetMenu(_hwnd) == hMenu);
- if ( _fTrackingMenuBar )
- {
- TraceMsg("Tracking the menu bar, sending activate");
- _pQueryHandler->ActivateView(CQRVA_INITMENUBAR, (WPARAM)hMenu, 0L);
- EnableMenuItem(hMenu, CQID_VIEW_SEARCHPANE,
- MF_BYCOMMAND|(_hwndResults != NULL) ? MF_ENABLED:MF_GRAYED);
- #if HIDE_SEARCH_PANE
- CheckMenuItem(hMenu, CQID_VIEW_SEARCHPANE,
- MF_BYCOMMAND|(_fHideSearchPane) ? MF_UNCHECKED:MF_CHECKED);
- #endif
- }
- TraceLeave();
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::OnEnterMenuLoop
- / ----------------------------
- / When the user displays a menu we must reflect this into the status bar
- / so that we can give the user help text relating to the commands they
- / select.
- /
- / In:
- / fEntering = entering the menu loop, or leaving.
- /
- / Out:
- / -
- /----------------------------------------------------------------------------*/
- VOID CQueryFrame::OnEnterMenuLoop(BOOL fEntering)
- {
- TraceEnter(TRACE_FRAMEDLG, "CQueryFrame::OnEnterMenuLoop");
- if ( _hwndStatus )
- {
- if ( fEntering )
- {
- SendMessage(_hwndStatus, SB_SIMPLE, (WPARAM)TRUE, 0L);
- SendMessage(_hwndStatus, SB_SETTEXT, (WPARAM)SBT_NOBORDERS|255, 0L);
- }
- else
- {
- SendMessage(_hwndStatus, SB_SIMPLE, (WPARAM)FALSE, 0L);
- }
- }
- TraceLeave();
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::OnMenuSelect
- / -------------------------
- / Get the status text for this menu item and display it to the user,
- / if this doesn't map to any particular command then NULL out
- / the string. At this point we also trap our commands.
- /
- / In:
- / hMenu = menu the user is on
- / uID = command ID for that item
- /
- / Out:
- / -
- /----------------------------------------------------------------------------*/
- VOID CQueryFrame::OnMenuSelect(HMENU hMenu, UINT uID)
- {
- TCHAR szBuffer[MAX_PATH] = { TEXT('') };
- TraceEnter(TRACE_FRAMEDLG, "CQueryFrame::OnMenuSelect");
- Trace(TEXT("hMenu %08x, uID %08x"), hMenu, uID);
- if ( _hwndStatus )
- {
- switch ( uID )
- {
- case CQID_FILE_CLOSE:
- case CQID_VIEW_SEARCHPANE:
- LoadString(GLOBAL_HINSTANCE, uID, szBuffer, ARRAYSIZE(szBuffer));
- break;
- default:
- _pQueryHandler->GetCommandString(uID, 0x0, szBuffer, ARRAYSIZE(szBuffer));
- break;
- }
- Trace(TEXT("Setting status bar to: %s"), szBuffer);
- SendMessage(_hwndStatus, SB_SETTEXT, (WPARAM)SBT_NOBORDERS|255, (LPARAM)szBuffer);
- }
- TraceLeave();
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::OnFindNow
- / ----------------------
- // Issue the query, resulting in a view window being created and then issuing
- // the parameter block to the query client.
- /
- / In:
- / Out:
- / HRESULT
- /----------------------------------------------------------------------------*/
- HRESULT CQueryFrame::OnFindNow(VOID)
- {
- HRESULT hres;
- CQPARAMS qp = { 0 };
- LPQUERYSCOPE pQueryScope = NULL;
- TCHAR szBuffer[MAX_PATH];
- BOOL fFixSize = TRUE;
- RECT rc;
- DECLAREWAITCURSOR;
- TraceEnter(TRACE_FRAMEDLG, "CQueryFrame::OnFindNow");
- TraceAssert(_pCurrentForm != NULL);
- if ( _fQueryRunning )
- ExitGracefully(hres, E_FAIL, "Quyery is already running");
- SetWaitCursor();
- // If we have not created the viewer before now lets do so, also at the
- // same time we attempt to fix the window size to ensure that enough
- // of the view is visible.
- if ( !_hwndResults )
- {
- if ( !_hwndStatus )
- {
- _hwndStatus = CreateStatusWindow(WS_CHILD, NULL, _hwnd, IDC_STATUS);
- GetClientRect(_hwndStatus, &rc);
- _cyStatus = rc.bottom - rc.top;
- }
- // Now construct the result viewer for us to use
- hres = _pQueryHandler->CreateResultView(_hwnd, &_hwndResults);
- FailGracefully(hres, "Failed when creating the view object");
- GetWindowRect(_hwnd, &rc);
- SetWindowPos(_hwnd, NULL,
- 0, 0,
- rc.right - rc.left,
- _szMinTrack.cy + VIEWER_DEFAULT_CY,
- SWP_NOZORDER|SWP_NOMOVE);
- }
- // are we still collecting the scopes async? If so then lets wait until
- // they have all arrived before we set the UI running.
- if ( _hdsaScopes && DSA_GetItemCount(_hdsaScopes) )
- {
- // Collect the parameters ready for starting the query, if this fails then
- // there is no point us continuing.
- ZeroMemory(&qp, SIZEOF(qp));
- qp.cbStruct = SIZEOF(qp);
- //qp.dwFlags = 0x0;
- qp.clsidForm = _pCurrentForm->clsidForm; // new NT5 beta 2
- hres = GetSelectedScope(&pQueryScope);
- FailGracefully(hres, "Failed to get the scope from the LookIn control");
- if ( pQueryScope )
- {
- Trace(TEXT("pQueryScope %08x"), pQueryScope);
- qp.pQueryScope = pQueryScope->pScope;
- }
- hres = CallFormPages(_pCurrentForm, CALLFORMPAGES_ALL, CQPM_GETPARAMETERS, 0, (LPARAM)&qp.pQueryParameters);
- FailGracefully(hres, "Failed when collecting parameters from form");
- if ( !qp.pQueryParameters )
- {
- LoadString(GLOBAL_HINSTANCE, IDS_ERR_NOPARAMS, szBuffer, ARRAYSIZE(szBuffer));
- FrameMessageBox(szBuffer, MB_ICONERROR|MB_OK);
- ExitGracefully(hres, E_FAIL, "Failed to issue the query, no parameters");
- }
- // We either already had a view, or have just created one. Either way
- // we must now prepare the query for sending.
- Trace(TEXT("qp.cbStruct %08x"), qp.cbStruct);
- Trace(TEXT("qp.dwFlags %08x"), qp.dwFlags);
- Trace(TEXT("qp.pQueryScope %08x"), qp.pQueryScope);
- Trace(TEXT("qp.pQueryParameters %08x"), qp.pQueryParameters);
- TraceGUID("qp.clsidForm: ", qp.clsidForm);
- hres = _pQueryHandler->IssueQuery(&qp);
- FailGracefully(hres, "Failed in IssueQuery");
- }
- else
- {
- // set the status text to reflect that we are initializng, otherwise it is
- // left empty and looks like we have crashed.
- if ( LoadString(GLOBAL_HINSTANCE, IDS_INITIALIZING, szBuffer, ARRAYSIZE(szBuffer)) )
- {
- SetStatusText(szBuffer);
- }
- }
- hres = S_OK; // success
- exit_gracefully:
- #if HIDE_SEARCH_PANE
- if ( FAILED(hres) && !_hwndResults && _fHideSearchPane )
- {
- TraceMsg("Form area hidden, no results viewer created so now showing it");
- HideSearchPane(FALSE);
- }
- #endif
- if ( qp.pQueryParameters )
- CoTaskMemFree(qp.pQueryParameters);
- ResetWaitCursor();
- TraceLeaveResult(hres);
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::OnNewQuery
- / -----------------------
- / Discard the current query, prompting the user as requierd.
- /
- / In:
- / fAlwaysPrompt = TRUE if we force prompting of the user
- /
- / Out:
- / BOOL
- /----------------------------------------------------------------------------*/
- BOOL CQueryFrame::OnNewQuery(BOOL fAlwaysPrompt)
- {
- BOOL fQueryCleared = TRUE;
- TCHAR szBuffer[MAX_PATH];
- RECT rc;
- TraceEnter(TRACE_FRAMEDLG, "CQueryFrame::OnNewQuery");
- if ( _hwndResults || fAlwaysPrompt )
- {
- LoadString(GLOBAL_HINSTANCE, IDS_CLEARCURRENT, szBuffer, ARRAYSIZE(szBuffer));
- if ( IDOK != FrameMessageBox(szBuffer, MB_ICONINFORMATION|MB_OKCANCEL) )
- ExitGracefully(fQueryCleared, FALSE, "Used cancled new query");
- if ( _pQueryHandler )
- _pQueryHandler->StopQuery();
- CallFormPages(_pCurrentForm, CALLFORMPAGES_ALL, CQPM_CLEARFORM, 0, 0);
- if ( _hwndResults )
- {
- DestroyWindow(_hwndResults); // no result view now
- _hwndResults = NULL;
- DestroyWindow(_hwndStatus); // no status bar
- _hwndStatus = NULL;
- GetWindowRect(_hwnd, &rc); // shrink the window
- SetWindowPos(_hwnd, NULL,
- 0, 0, rc.right - rc.left, _szMinTrack.cy,
- SWP_NOZORDER|SWP_NOMOVE);
- }
- }
- exit_gracefully:
- TraceLeaveValue(fQueryCleared);
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::OnBrowse
- / ---------------------
- / Browse for a new scope, adding it to the list if not already present,
- / or selecting the previous scope.
- /
- / In:
- / Out:
- / HRESULT
- /----------------------------------------------------------------------------*/
- HRESULT CQueryFrame::OnBrowse(VOID)
- {
- HRESULT hres;
- LPQUERYSCOPE pQueryScope = NULL;
- LPCQSCOPE pScope = NULL;
- TraceEnter(TRACE_FRAMEDLG, "CQueryFrame::OnBrowse");
- // Call the handler and get a scope allocation back, then add it to the list
- // of scopes to be displayed.
- hres = GetSelectedScope(&pQueryScope);
- FailGracefully(hres, "Failed to get the scope from the LookIn control");
- Trace(TEXT("Calling BrowseForScope _hwnd %08x, pQueryScope %08x (%08x)"),
- _hwnd, pQueryScope, pQueryScope->pScope);
- hres = _pQueryHandler->BrowseForScope(_hwnd, pQueryScope ? pQueryScope->pScope:NULL, &pScope);
- FailGracefully(hres, "Failed when calling BrowseForScope");
- if ( (hres != S_FALSE) && pScope )
- {
- hres = InsertScopeIntoList(pScope, DA_LAST, TRUE);
- FailGracefully(hres, "Failed when adding the scope to the control");
- ComboBox_SetCurSel(_hwndLookIn, ShortFromResult(hres));
- }
- hres = S_OK;
- exit_gracefully:
- if ( pScope )
- CoTaskMemFree(pScope);
- TraceLeaveResult(hres);
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::OnHelp
- / -------------------
- / Invoke the context sensitive help for the window, catch the
- / handler specific and page specific stuff and pass those help
- / requests down to the relevant objects.
- /
- / In:
- / pHelpInfo -> help info structure
- /
- / Out:
- / HRESULT
- /----------------------------------------------------------------------------*/
- HRESULT CQueryFrame::OnHelp(LPHELPINFO pHelpInfo)
- {
- HRESULT hres;
- RECT rc;
- HWND hwnd = (HWND)pHelpInfo->hItemHandle;
- TraceEnter(TRACE_FRAME, "CQueryFrame::OnHelp");
- // We are invoking help, theroefore we need ot check to see where element
- // of the window we are being invoked for. If it is the
- // result view then route the message to that, if its the form then
- // likewise.
- //
- // If we don't hit any of the extension controls then lets pass the
- // help onto WinHelp and get it to display the topics we have.
- if ( pHelpInfo->iContextType != HELPINFO_WINDOW )
- ExitGracefully(hres, E_FAIL, "WM_HELP handler only copes with WINDOW objects");
- if ( _pCurrentFormPage->hwndPage && IsChild(_pCurrentFormPage->hwndPage, hwnd) )
- {
- // it was on the query form page, therefore let it go there, that way
- // they can provide topics specific to them
- TraceMsg("Invoking help on the form pane");
- hres = _CallPageProc(_pCurrentFormPage, CQPM_HELP, 0, (LPARAM)pHelpInfo);
- FailGracefully(hres, "Failed when calling page proc to get help");
- }
- else
- {
- // pass the help information through to the handler as an activation,
- // this should really just be a new method, but this works.
- TraceMsg("Invoking help on the results pane");
- TraceAssert(_pQueryHandler);
- hres = _pQueryHandler->ActivateView(CQRVA_HELP, 0, (LPARAM)pHelpInfo);
- FailGracefully(hres, "Handler WndProc returned FALSE");
- }
- hres = S_OK;
- exit_gracefully:
- TraceLeaveResult(hres);
- }
- /*-----------------------------------------------------------------------------
- / Scope helper functions
- /----------------------------------------------------------------------------*/
- /*-----------------------------------------------------------------------------
- / _CallScopeProc
- / --------------
- / Releae the given scope object, freeing the object that is referenced
- / and passing a CQSM_RELEASE message to it.
- /
- / In:
- / pQueryScope -> scope object to be called
- / uMsg, pVoid -> parameters for the scope
- /
- / Out:
- / HRESULT
- /----------------------------------------------------------------------------*/
- HRESULT _CallScopeProc(LPQUERYSCOPE pQueryScope, UINT uMsg, LPVOID pVoid)
- {
- HRESULT hres;
- TraceEnter(TRACE_SCOPES, "_CallScopeProc");
- Trace(TEXT("pQueryScope %08x, uMsg %d, pVoid %08x"), pQueryScope, uMsg, pVoid);
- Trace(TEXT("(cbStruct %d, pScopeProc %08x, lParam %08x)"),
- pQueryScope->pScope->cbStruct,
- pQueryScope->pScope->pScopeProc,
- pQueryScope->pScope->lParam);
- if ( !pQueryScope )
- ExitGracefully(hres, S_OK, "pQueryScope == NULL");
- hres = (pQueryScope->pScope->pScopeProc)(pQueryScope->pScope, uMsg, pVoid);
- FailGracefully(hres, "Failed calling ScopeProc");
- exit_gracefully:
- TraceLeaveResult(hres);
- }
- /*-----------------------------------------------------------------------------
- / _FreeScope
- / ----------
- / Releae the given scope object, freeing the object that is referenced
- / and passing a CQSM_RELEASE message to it.
- /
- / In:
- / pQueryScope -> scope object to be released
- /
- / Out:
- / INT == 1 always
- /----------------------------------------------------------------------------*/
- INT _FreeScopeCB(LPVOID pItem, LPVOID pData)
- {
- return _FreeScope((LPQUERYSCOPE)pItem);
- }
- INT _FreeScope(LPQUERYSCOPE pQueryScope)
- {
- TraceEnter(TRACE_SCOPES, "_FreeScope");
- Trace(TEXT("pQueryScope %08x, pQueryScope->pScope %08x"), pQueryScope, pQueryScope->pScope);
- if ( pQueryScope )
- {
- _CallScopeProc(pQueryScope, CQSM_RELEASE, NULL);
- if ( pQueryScope->pScope )
- {
- LocalFree((HLOCAL)pQueryScope->pScope);
- pQueryScope->pScope = NULL;
- }
- }
- TraceLeaveValue(TRUE);
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::InsertScopeIntoList
- / --------------------------------
- / Adds the given scope to the scope picker.
- /
- / In:
- / pQueryScope -> zcope object to be added to the view
- / i = index to insert the scope at
- / fAddToControl = add the scope the picker control
- / ppQueryScope -> recieves the new query scope object / = NULL
- /
- / Out:
- / HRESULT
- /----------------------------------------------------------------------------*/
- HRESULT CQueryFrame::InsertScopeIntoList(LPCQSCOPE pScope, INT i, BOOL fAddToControl)
- {
- HRESULT hres;
- QUERYSCOPE qs;
- INT iScope;
- TraceEnter(TRACE_SCOPES, "CQueryFrame::InsertScopeIntoList");
- Trace(TEXT("pScope %08x, i %d, fAddToControl %d"), pScope, i, fAddToControl);
- if ( !pScope )
- ExitGracefully(hres, E_INVALIDARG, "pScope == NULL, not allowed");
- // if we don't have any scopes then allocate the DSA
- if ( !_hdsaScopes )
- {
- _hdsaScopes = DSA_Create(SIZEOF(QUERYSCOPE), 4);
- TraceAssert(_hdsaScopes);
- if ( !_hdsaScopes )
- ExitGracefully(hres, E_OUTOFMEMORY, "Failed to allocate the scope DPA");
- }
- // Walk the list of scopes checking to see if this one is already in
- // there, if not then we can add it.
- for ( iScope = 0 ; iScope < DSA_GetItemCount(_hdsaScopes) ; iScope++ )
- {
- LPQUERYSCOPE pQueryScope = (LPQUERYSCOPE)DSA_GetItemPtr(_hdsaScopes, iScope);
- TraceAssert(pQueryScope);
- if ( S_OK == _CallScopeProc(pQueryScope, CQSM_SCOPEEQUAL, pScope) )
- {
- hres = ResultFromShort(iScope);
- goto exit_gracefully;
- }
- }
- // Take a copy of the scope blob passed by the caller. We copy the entire
- // structure who's size is defined by cbStruct into a LocalAlloc block,
- // once we have this we can then build the QUERYSCOPE structure that references
- // it.
- Trace(TEXT("pScope->cbStruct == %d"), pScope->cbStruct);
- qs.pScope = (LPCQSCOPE)LocalAlloc(LPTR, pScope->cbStruct);
- if ( !qs.pScope )
- ExitGracefully(hres, E_OUTOFMEMORY, "Failed to allocate query scope");
- Trace(TEXT("Copying structure qs.pScope %08x, pScope %08x"), qs.pScope, pScope);
- CopyMemory(qs.pScope, pScope, pScope->cbStruct);
- //qs.pScope = NULL;
- qs.iImage = -1; // no image
- // We have a QUERYSCOPE, so initialize it, if that works then append it to the
- // DSA before either setting the return value or appending it to the control.
- _CallScopeProc(&qs, CQSM_INITIALIZE, NULL);
- iScope = DSA_InsertItem(_hdsaScopes, i, &qs);
- Trace(TEXT("iScope = %d"), iScope);
- if ( iScope == -1 )
- {
- _FreeScope(&qs);
- ExitGracefully(hres, E_OUTOFMEMORY, "Failed to add scope to DSA");
- }
- if ( fAddToControl )
- {
- LPQUERYSCOPE pQueryScope = (LPQUERYSCOPE)DSA_GetItemPtr(_hdsaScopes, iScope);
- TraceAssert(pQueryScope);
- Trace(TEXT("Calling AddScopeToControl with %08x (%d)"), pQueryScope, iScope);
- hres = AddScopeToControl(pQueryScope, iScope);
- }
- else
- {
- hres = ResultFromShort(iScope);
- }
- exit_gracefully:
- TraceLeaveResult(hres);
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::AddScopeToControl
- / ------------------------------
- / Adds the given scope to the scope picker.
- /
- / In:
- / pQueryScope -> zcope object to be added to the view
- / i = index into view where to insert the scope
- /
- / Out:
- / HRESULT ( == index of item added )
- /----------------------------------------------------------------------------*/
- HRESULT CQueryFrame::AddScopeToControl(LPQUERYSCOPE pQueryScope, INT i)
- {
- HRESULT hres;
- CQSCOPEDISPLAYINFO cqsdi;
- COMBOBOXEXITEM cbi;
- TCHAR szBuffer[MAX_PATH];
- TCHAR szIconLocation[MAX_PATH] = { 0 };
- INT item;
- TraceEnter(TRACE_SCOPES, "CQueryFrame::AddScopeToControl");
- if ( !pQueryScope )
- ExitGracefully(hres, E_INVALIDARG, "No scope specified");
- // Call the scope to get the display information about this
- // scope before we attempt to add it.
- cqsdi.cbStruct = SIZEOF(cqsdi);
- cqsdi.dwFlags = 0;
- cqsdi.pDisplayName = szBuffer;
- cqsdi.cchDisplayName = ARRAYSIZE(szBuffer);
- cqsdi.pIconLocation = szIconLocation;
- cqsdi.cchIconLocation = ARRAYSIZE(szIconLocation);
- cqsdi.iIconResID = 0;
- cqsdi.iIndent = 0;
- hres = _CallScopeProc(pQueryScope, CQSM_GETDISPLAYINFO, &cqsdi);
- FailGracefully(hres, "Failed to get display info for the scope");
- // Now add the item to the control, if they gave as an image then
- // add that to the image list (and tweak the INSERTITEM structure
- // accordingly).
- cbi.mask = CBEIF_TEXT|CBEIF_INDENT;
- cbi.iItem = i;
- cbi.pszText = cqsdi.pDisplayName;
- cbi.iIndent = cqsdi.iIndent;
- Trace(TEXT("Indent is %d"), cqsdi.iIndent);
- if ( szIconLocation[0] && cqsdi.iIconResID )
- {
- INT iImage;
- if ( !_fScopeImageListSet )
- {
- HIMAGELIST himlSmall;
- Shell_GetImageLists(NULL, &himlSmall);
- SendMessage(_hwndLookIn, CBEM_SETIMAGELIST, 0, (LPARAM)himlSmall);
- _fScopeImageListSet = TRUE;
- }
- cbi.mask |= CBEIF_IMAGE|CBEIF_SELECTEDIMAGE;
- cbi.iImage = Shell_GetCachedImageIndex(szIconLocation, cqsdi.iIconResID, 0x0);;
- cbi.iSelectedImage = cbi.iImage;
- Trace(TEXT("Image index set to: %d"), cbi.iImage);
- }
- item = (INT)SendMessage(_hwndLookIn, CBEM_INSERTITEM, 0, (LPARAM)&cbi);
- if ( item == -1 )
- ExitGracefully(hres, E_FAIL, "Failed when inserting the scope to the list");
- DoEnableControls(); // reflect button changes into UI
- hres = ResultFromShort(item);
- exit_gracefully:
- TraceLeaveResult(hres);
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::PopulateScopeControl
- / ---------------------------------
- / Collect the scopes that we want to display in the scope control and
- / then populate it. If the handler doesn't return any scopes then
- / we remove the control and assume that know what to do when they
- / don't receive a scope pointer.
- /
- / In:
- / -
- /
- / Out:
- / HRESULT
- /----------------------------------------------------------------------------*/
- HRESULT CQueryFrame::PopulateScopeControl(VOID)
- {
- HRESULT hres;
- LPQUERYSCOPE pQueryScope;
- INT i;
- TraceEnter(TRACE_SCOPES, "CQueryFrame::PopulateScopeControl");
- // Collect the scopes that we should be showing in the view, if we don't
- // get any back then we disable the scope control, if we do get some then
- // populate the scope control with them.
- hres = _pQueryHandler->AddScopes();
- _fAddScopesNYI = (hres == E_NOTIMPL);
- if ( hres != E_NOTIMPL )
- FailGracefully(hres, "Failed when calling handler to add scopes");
- if ( _hdsaScopes )
- {
- // We have some scopes, so now we create the image list that we can use
- // for icons with scopes. Then walk through the DPA getting the scope
- // to give us some display information about itself that we can
- // add to the combo box.
- ComboBox_SetExtendedUI(_hwndLookIn, TRUE);
- for ( i = 0 ; i < DSA_GetItemCount(_hdsaScopes); i++ )
- {
- pQueryScope = (LPQUERYSCOPE)DSA_GetItemPtr(_hdsaScopes, i);
- TraceAssert(pQueryScope);
- AddScopeToControl(pQueryScope, i);
- }
- }
- else
- {
- // we don't have any scopes after calling AddScopes, this is either
- // because the ::AddScopes method is not implemented, or the
- // scopes are being added async. If IssueQuery returned a success
- // we assume they are coming in async and flag as such in our
- // state.
- if ( !_fAddScopesNYI )
- {
- TraceMsg("Handler adding scopes async, so marking so");
- _fScopesAddedAsync = TRUE;
- }
- }
- hres = S_OK; // success
- exit_gracefully:
- Trace(TEXT("Default scope is index %d"), _iDefaultScope);
- ComboBox_SetCurSel(_hwndLookIn, _iDefaultScope);
- TraceLeaveResult(hres);
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::GetSelectedScope
- / -----------------------------
- / Get the selected from the the scope ComboBox, this is a reference into the
- / scope DSA.
- /
- / In:
- / ppQueryScope = receives a pointer to the new scope
- /
- / Out:
- / HRESULT
- /----------------------------------------------------------------------------*/
- HRESULT CQueryFrame::GetSelectedScope(LPQUERYSCOPE* ppQueryScope)
- {
- HRESULT hres;
- COMBOBOXEXITEM cbi;
- INT iScope;
- TraceEnter(TRACE_SCOPES, "CQueryFrame::GetSelectedScope");
- *ppQueryScope = NULL;
- if ( _hdsaScopes )
- {
- // Get the index for the current scope, if it doesn't give a real
- // index to a item in our view then barf! Otherwise look up the
- // associated scope.
- iScope = ComboBox_GetCurSel(_hwndLookIn);
- Trace(TEXT("iScope %d"), iScope);
- if ( iScope == -1 )
- ExitGracefully(hres, E_FAIL, "User entered scopes not supported yet");
- *ppQueryScope = (LPQUERYSCOPE)DSA_GetItemPtr(_hdsaScopes, iScope);
- TraceAssert(*ppQueryScope);
- }
- hres = S_OK;
- exit_gracefully:
- Trace(TEXT("Returning LPQUERYSCOPE %08x"), *ppQueryScope);
- TraceLeaveResult(hres);
- }
- /*-----------------------------------------------------------------------------
- / Form handling functions
- /----------------------------------------------------------------------------*/
- /*-----------------------------------------------------------------------------
- / _FreeQueryForm
- / ---------------
- / Destroy the QUERYFORM allocation being used to describe the form in
- / our DPA. We ensure that we issue a CQPM_RELEASE before doing anything
- /
- / In:
- / pQueryForm -> query form to be destroyed
- /
- / Out:
- / INT == 1 always
- /----------------------------------------------------------------------------*/
- INT _FreeQueryFormCB(LPVOID pItem, LPVOID pData)
- {
- return _FreeQueryForm((LPQUERYFORM)pItem);
- }
- INT _FreeQueryForm(LPQUERYFORM pQueryForm)
- {
- TraceEnter(TRACE_FORMS, "_FreeQueryForm");
- if ( pQueryForm )
- {
- if ( pQueryForm->hdsaPages )
- {
- DSA_DestroyCallback(pQueryForm->hdsaPages, _FreeQueryFormPageCB, NULL);
- pQueryForm->hdsaPages = NULL;
- }
- Str_SetPtr(&pQueryForm->pTitle, NULL);
- DestroyIcon(pQueryForm->hIcon);
- }
- TraceLeaveValue(TRUE);
- }
- /*-----------------------------------------------------------------------------
- / _FreeQueryFormPage
- / ------------------
- / Given a pointer to a query form page structure release the members that
- // are of interest, including calling the PAGEPROC to releasee the underlying
- / object.
- /
- / In:
- / pQueryFormPage -> page to be removed
- /
- / Out:
- / INT == 1 always
- /----------------------------------------------------------------------------*/
- INT _FreeQueryFormPageCB(LPVOID pItem, LPVOID pData)
- {
- return _FreeQueryFormPage((LPQUERYFORMPAGE)pItem);
- }
- INT _FreeQueryFormPage(LPQUERYFORMPAGE pQueryFormPage)
- {
- TraceEnter(TRACE_FORMS, "_FreeQueryFormPage");
- if ( pQueryFormPage )
- {
- _CallPageProc(pQueryFormPage, CQPM_RELEASE, 0, 0); // NB: ignore return code
- if ( pQueryFormPage->hwndPage )
- {
- DestroyWindow(pQueryFormPage->hwndPage);
- pQueryFormPage->hwndPage = NULL;
- }
- if ( pQueryFormPage->pPage )
- {
- LocalFree(pQueryFormPage->pPage);
- pQueryFormPage->pPage = NULL;
- }
- }
- TraceLeaveValue(TRUE);
- }
- /*-----------------------------------------------------------------------------
- / _CallPageProc
- / -------------
- / Call the given page object thunking the arguments as required if the
- / page object is non-UNICODE (only if building UNICODE).
- /
- / In:
- / pQueryFormPage -> page object to be called
- / uMsg, wParam, lParam = parameters for message
- /
- / Out:
- / HRESULT
- /----------------------------------------------------------------------------*/
- HRESULT _CallPageProc(LPQUERYFORMPAGE pQueryFormPage, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- HRESULT hres;
- TraceEnter(TRACE_FORMS, "_CallPageProc");
- Trace(TEXT("pQueryFormPage %08x, pPage %08x, uMsg %d, wParam %08x, lParam %08x"),
- pQueryFormPage, pQueryFormPage->pPage, uMsg, wParam, lParam);
- if ( !pQueryFormPage )
- ExitGracefully(hres, S_OK, "pQueryFormPage == NULL");
- hres = (pQueryFormPage->pPage->pPageProc)(pQueryFormPage->pPage, pQueryFormPage->hwndPage, uMsg, wParam, lParam);
- FailGracefully(hres, "Failed calling PageProc");
- // hres = S_OK;
- exit_gracefully:
- TraceLeaveResult(hres);
- }
- /*-----------------------------------------------------------------------------
- / ANSI functions for adding query forms/pages
- /----------------------------------------------------------------------------*/
- #ifdef UNICODE
- // ANSI CB to add forms to the form DSA.
- HRESULT _AddFormsProcA(LPARAM lParam, LPCQFORM_A pForm)
- {
- HRESULT hres;
- QUERYFORM qf;
- HDSA hdsaForms = (HDSA)lParam;
- USES_CONVERSION;
- TraceEnter(TRACE_FORMS, "_AddFormsProcA");
- if ( !pForm || !hdsaForms )
- ExitGracefully(hres, E_INVALIDARG, "Failed to add page pForm == NULL");
- // Allocate and thunk as required
- qf.hdsaPages = NULL; // DSA of pages
- qf.dwFlags = pForm->dwFlags; // flags
- qf.clsidForm = pForm->clsid; // CLSID identifier for this form
- qf.pTitle = NULL; // title used for drop down / title bar
- qf.hIcon = pForm->hIcon; // hIcon passed by caller
- qf.iImage = -1; // image list index of icon
- qf.iForm = 0; // visible index of form in control
- qf.iPage = 0; // currently selected page on form
- if ( !Str_SetPtr(&qf.pTitle, A2T(pForm->pszTitle)) )
- ExitGracefully(hres, E_OUTOFMEMORY, "Failed to copy form title string");
- // Allocate the DSA if one doesn't exist yet, then add in the form
- // structure as required.
- if ( -1 == DSA_AppendItem(hdsaForms, &qf) )
- ExitGracefully(hres, E_FAIL, "Failed to add form to the form DSA");
- hres = S_OK; // success
- exit_gracefully:
- if ( FAILED(hres) )
- _FreeQueryForm(&qf);
- TraceLeaveResult(hres);
- }
- // ANSI CB to add pages to the page DSA.
- HRESULT _AddPagesProcA(LPARAM lParam, REFCLSID clsidForm, LPCQPAGE_A pPage)
- {
- HRESULT hres;
- QUERYFORMPAGE qfp;
- HDSA hdsaPages = (HDSA)lParam;
- TraceEnter(TRACE_FORMS, "_AddPagesProcA");
- if ( !pPage || !hdsaPages )
- ExitGracefully(hres, E_INVALIDARG, "Failed to add page pPage == NULL");
- // copy the pPage structure for us to pass to the PAGEPROC later, nb: we
- // use the cbStruct field to indicate the size of blob we must copy.
- Trace(TEXT("pPage->cbStruct == %d"), pPage->cbStruct);
- qfp.pPage = (LPCQPAGE)LocalAlloc(LPTR, pPage->cbStruct);
- if ( !qfp.pPage )
- ExitGracefully(hres, E_OUTOFMEMORY, "Failed to allocate copy of page structure");
- Trace(TEXT("Copying structure qfp.pPage %08x, pPage %08x"), qfp.pPage, pPage);
- CopyMemory(qfp.pPage, pPage, pPage->cbStruct); // copy the page structure
- qfp.fPageIsANSI = TRUE;
- //qfp.pPage = NULL;
- qfp.clsidForm = clsidForm;
- qfp.pPageProcA = pPage->pPageProc;
- qfp.lParam = pPage->lParam;
- qfp.hwndPage = NULL;
- _CallPageProc(&qfp, CQPM_INITIALIZE, 0, 0);
- if ( -1 == DSA_AppendItem(hdsaPages, &qfp) )
- ExitGracefully(hres, E_FAIL, "Failed to add the form to the DSA");
- hres = S_OK; // succcess
- exit_gracefully:
- if ( FAILED(hres) )
- _FreeQueryFormPage(&qfp);
- TraceLeaveResult(hres);
- }
- // Add forms/pages from a ANSI IQueryForm iface
- HRESULT CQueryFrame::AddFromIQueryFormA(IQueryFormA* pQueryForm, HKEY hKeyForm)
- {
- HRESULT hres;
- TraceEnter(TRACE_FORMS, "CQueryFrame::AddFromIQueryFormA");
- if ( !pQueryForm )
- ExitGracefully(hres, E_FAIL, "pQueryForm == NULL, failing");
- hres = pQueryForm->Initialize(hKeyForm);
- FailGracefully(hres, "Failed in IQueryFormA::Initialize");
- // Call the form object to add its form and then its pages
- hres = pQueryForm->AddForms(_AddFormsProcA, (LPARAM)_hdsaForms);
- if ( SUCCEEDED(hres) || (hres == E_NOTIMPL) )
- {
- hres = pQueryForm->AddPages(_AddPagesProcA, (LPARAM)_hdsaPages);
- FailGracefully(hres, "Failed in IQueryFormA::AddPages");
- }
- else
- {
- FailGracefully(hres, "Failed when calling IQueryFormA::AddForms");
- }
- hres = S_OK; // success
- exit_gracefully:
- TraceLeaveResult(hres);
- }
- #endif // #ifndef UNICODE
- /*-----------------------------------------------------------------------------
- / Functions for adding query forms/pages
- /----------------------------------------------------------------------------*/
- // CB to add forms to the form DSA.
- HRESULT _AddFormsProc(LPARAM lParam, LPCQFORM pForm)
- {
- HRESULT hres;
- QUERYFORM qf;
- HDSA hdsaForms = (HDSA)lParam;
- TraceEnter(TRACE_FORMS, "_AddFormsProc");
- if ( !pForm || !hdsaForms )
- ExitGracefully(hres, E_INVALIDARG, "Failed to add page pForm == NULL");
- // Allocate and thunk as required
- qf.hdsaPages = NULL; // DSA of pages
- qf.dwFlags = pForm->dwFlags; // flags
- qf.clsidForm = pForm->clsid; // CLSID identifier for this form
- qf.pTitle = NULL; // title used for drop down / title bar
- qf.hIcon = pForm->hIcon; // hIcon passed by caller
- qf.iImage = -1; // image list index of icon
- qf.iForm = 0; // visible index of form in control
- qf.iPage = 0; // currently selected page on form
- if ( !Str_SetPtr(&qf.pTitle, pForm->pszTitle) )
- ExitGracefully(hres, E_OUTOFMEMORY, "Failed to copy form title string");
- // Allocate the DSA if one doesn't exist yet, then add in the form
- // structure as required.
- if ( -1 == DSA_AppendItem(hdsaForms, &qf) )
- ExitGracefully(hres, E_FAIL, "Failed to add form to the form DSA");
- hres = S_OK; // success
- exit_gracefully:
- if ( FAILED(hres) )
- _FreeQueryForm(&qf);
- TraceLeaveResult(hres);
- }
- // CB to add pages to the page DSA.
- HRESULT _AddPagesProc(LPARAM lParam, REFCLSID clsidForm, LPCQPAGE pPage)
- {
- HRESULT hres;
- QUERYFORMPAGE qfp;
- HDSA hdsaPages = (HDSA)lParam;
- TraceEnter(TRACE_FORMS, "_AddPagesProc");
- if ( !pPage || !hdsaPages )
- ExitGracefully(hres, E_INVALIDARG, "Failed to add page pPage == NULL");
- // copy the pPage structure for us to pass to the PAGEPROC later, nb: we
- // use the cbStruct field to indicate the size of blob we must copy.
- Trace(TEXT("pPage->cbStruct == %d"), pPage->cbStruct);
- qfp.pPage = (LPCQPAGE)LocalAlloc(LPTR, pPage->cbStruct);
- if ( !qfp.pPage )
- ExitGracefully(hres, E_OUTOFMEMORY, "Failed to allocate copy of page structure");
- Trace(TEXT("Copying structure qfp.pPage %08x, pPage %08x"), qfp.pPage, pPage);
- CopyMemory(qfp.pPage, pPage, pPage->cbStruct); // copy the page structure
- #ifdef UNICODE
- qfp.fPageIsANSI = FALSE;
- #else
- qfp.fPageIsANSI = TRUE;
- #endif
- //qfp.pPage = NULL;
- qfp.clsidForm = clsidForm;
- qfp.pPageProc = pPage->pPageProc;
- qfp.lParam = pPage->lParam;
- qfp.hwndPage = NULL;
- _CallPageProc(&qfp, CQPM_INITIALIZE, 0, 0);
- if ( -1 == DSA_AppendItem(hdsaPages, &qfp) )
- ExitGracefully(hres, E_FAIL, "Failed to add the form to the DSA");
- hres = S_OK; // succcess
- exit_gracefully:
- if ( FAILED(hres) )
- _FreeQueryFormPage(&qfp);
- TraceLeaveResult(hres);
- }
- // Add forms/pages from a UNICODE IQueryForm iface
- HRESULT CQueryFrame::AddFromIQueryForm(IQueryForm* pQueryForm, HKEY hKeyForm)
- {
- HRESULT hres;
- TraceEnter(TRACE_FORMS, "CQueryFrame::AddFromIQueryForm");
- if ( !pQueryForm )
- ExitGracefully(hres, E_FAIL, "pQueryForm == NULL, failing");
- hres = pQueryForm->Initialize(hKeyForm);
- FailGracefully(hres, "Failed in IQueryFormW::Initialize");
- // Call the form object to add its form and then its pages
- hres = pQueryForm->AddForms(_AddFormsProc, (LPARAM)_hdsaForms);
- if ( SUCCEEDED(hres) || (hres == E_NOTIMPL) )
- {
- hres = pQueryForm->AddPages(_AddPagesProc, (LPARAM)_hdsaPages);
- FailGracefully(hres, "Failed in IQueryForm::AddPages");
- }
- else
- {
- FailGracefully(hres, "Failed when calling IQueryForm::AddForms");
- }
- hres = S_OK; // success
- exit_gracefully:
- TraceLeaveResult(hres);
- }
- #ifdef UNICODE
- #define ADD_FROM_IQUERYFORM AddFromIQueryFormW
- #else
- #define ADD_FROM_IQUERYFORM AddFromIQueryFormA
- #endif
- /*-----------------------------------------------------------------------------
- / CQueryFrame::GatherForms
- / ------------------------
- / Enumerate all the query forms for the given query handler and build
- / the DPA containing the list of them. Once we have done this we
- / can then populate the control at some more convientent moment.
- /
- / When gathering we first hit the "handler", then the "Forms" sub-key
- / trying to load all the InProc servers that provide forms. We build
- / list of hidden, never shown etc.
- /
- / In:
- / -
- / Out:
- / HRESULT
- /----------------------------------------------------------------------------*/
- HRESULT _AddPageToForm(LPQUERYFORM pQueryForm, LPQUERYFORMPAGE pQueryFormPage, BOOL fClone)
- {
- HRESULT hres;
- QUERYFORMPAGE qfp;
- LPCQPAGE pPage;
- TraceEnter(TRACE_FORMS, "_AddPageToForm");
- TraceAssert(pQueryForm);
- TraceAssert(pQueryFormPage);
- // ensure that we have a page DSA for this form object
- if ( !pQueryForm->hdsaPages )
- {
- TraceMsg("Creating a new page DSA for form");
- pQueryForm->hdsaPages = DSA_Create(SIZEOF(QUERYFORMPAGE), 4);
- if ( !pQueryForm->hdsaPages )
- ExitGracefully(hres, E_OUTOFMEMORY, "*** No page DSA on form object ***");
- }
- if ( !fClone )
- {
- // Moving this page structure to the one associated with the query form,
- // therefore just ensure that the form has a DSA for pages and just
- // insert an item at the header (yes, we add the pages in reverse).
- Trace(TEXT("Adding page %08x to form %s"), pQueryFormPage, pQueryForm->pTitle);
- if ( -1 == DSA_InsertItem(pQueryForm->hdsaPages, 0, pQueryFormPage) )
- ExitGracefully(hres, E_FAIL, "Failed to copy page to form page DSA");
- }
- else
- {
- LPCQPAGE pPage = pQueryFormPage->pPage;
- // Copying the page structure (it must be global), therefore clone
- // the QUERYFORMPAGE strucutre and the CQPAGE into a new allocation
- // and insert that into the page DSA.
- Trace(TEXT("Cloning page %08x to form %s"), pQueryFormPage, pQueryForm->pTitle);
- CopyMemory(&qfp, pQueryFormPage, SIZEOF(QUERYFORMPAGE));
- qfp.pPage = (LPCQPAGE)LocalAlloc(LPTR, pPage->cbStruct);
- if ( !qfp.pPage )
- ExitGracefully(hres, E_OUTOFMEMORY, "Failed to allocate copy of page structure");
- Trace(TEXT("Copying structure qfp.pPage %08x, pPage %08x"), qfp.pPage, pPage);
- CopyMemory(qfp.pPage, pPage, pPage->cbStruct); // copy the page structure
- _CallPageProc(&qfp, CQPM_INITIALIZE, 0, 0);
- if ( -1 == DSA_AppendItem(pQueryForm->hdsaPages, &qfp) )
- {
- _FreeQueryFormPage(&qfp);
- ExitGracefully(hres, E_FAIL, "Failed to copy page to form DSA");
- }
- }
- hres = S_OK; // success
- exit_gracefully:
- TraceLeaveResult(hres);
- }
- HRESULT CQueryFrame::GatherForms(VOID)
- {
- HRESULT hres;
- IQueryForm* pQueryForm = NULL;
- HKEY hKeyForms = NULL;
- TCHAR szBuffer[MAX_PATH];
- INT i, iPage, iForm;
- RECT rect;
- DWORD cbStruct;
- TC_ITEM tci;
- TraceEnter(TRACE_FORMS, "CQueryFrame::GatherForms");
- // Construct DSA's so we can store the forms and pages as required.
- _hdsaForms = DSA_Create(SIZEOF(QUERYFORM), 4);
- _hdsaPages = DSA_Create(SIZEOF(QUERYFORMPAGE), 4);
- if ( !_hdsaForms || !_hdsaPages )
- ExitGracefully(hres, E_OUTOFMEMORY, "Failed to create DSA's for storing pages/forms");
- // First check the IQueryHandler to see if it supports IQueryForm, if it does
- // then call it to add its objects. Note that we don't bother with ANSI/UNICODE
- // at this point as the handler is assumed to be built the same the
- // the query framework.
- if ( SUCCEEDED(_pQueryHandler->QueryInterface(IID_IQueryForm, (LPVOID*)&pQueryForm)) )
- {
- hres = AddFromIQueryForm(pQueryForm, NULL);
- FailGracefully(hres, "Failed when calling AddFromIQueryForm on handlers IQueryForm iface)");
- }
- // now attempt to build the list of forms and pages from the registered form
- // extensions. These are declared under the handlers CLSID in the registry,
- // under the sub-key "Forms".
- if ( ERROR_SUCCESS != RegOpenKeyEx(_hkHandler, c_szForms, NULL, KEY_READ, &hKeyForms) )
- {
- TraceMsg("No 'Forms' sub-key found, therefore skipping");
- }
- else
- {
- // Enumerate all the keys in the "Forms" key, these are assumed to be a list of
- // the form handlers.
- for ( i = 0 ; TRUE ; i++ )
- {
- cbStruct = SIZEOF(szBuffer);
- if ( ERROR_SUCCESS != RegEnumKeyEx(hKeyForms, i, szBuffer, &cbStruct, NULL, NULL, NULL, NULL) )
- {
- TraceMsg("RegEnumKeyEx return's false, therefore stopping eunmeration");
- break;
- }
- GetForms(hKeyForms, szBuffer);
- }
- }
- // Now tally the form/page information together and remove duplicates and attach the pages
- // to forms, take special note of the global pages. As all forms will now be in the
- // DSA we can check for a zero count and we don't have to worry about the order
- // in which the the forms and pages were added.
- if ( !DSA_GetItemCount(_hdsaForms) || !DSA_GetItemCount(_hdsaPages) )
- ExitGracefully(hres, E_FAIL, "Either the forms or pages DSA is empty");
- for ( iPage = DSA_GetItemCount(_hdsaPages) ; --iPage >= 0 ; )
- {
- LPQUERYFORMPAGE pQueryFormPage = (LPQUERYFORMPAGE)DSA_GetItemPtr(_hdsaPages, iPage);
- TraceAssert(pQueryFormPage);
- Trace(TEXT("iPage %d (of %d)"), iPage, DSA_GetItemCount(_hdsaPages));
- if ( !(pQueryFormPage->pPage->dwFlags & CQPF_ISGLOBAL) )
- {
- LPQUERYFORM pQueryForm = FindQueryForm(pQueryFormPage->clsidForm);
- TraceAssert(pQueryForm);
- TraceGUID("Adding page to form:", pQueryFormPage->clsidForm);
- if ( pQueryForm )
- {
- hres = _AddPageToForm(pQueryForm, pQueryFormPage, FALSE);
- FailGracefully(hres, "Failed when adding page to form");
- if ( !DSA_DeleteItem(_hdsaPages, iPage) )
- TraceMsg("**** Failed to remove page from global DSA ****");
- }
- }
- }
- for ( iPage = DSA_GetItemCount(_hdsaPages) ; --iPage >= 0 ; )
- {
- LPQUERYFORMPAGE pQueryFormPage = (LPQUERYFORMPAGE)DSA_GetItemPtr(_hdsaPages, iPage);
- TraceAssert(pQueryFormPage);
- if ( (pQueryFormPage->pPage->dwFlags & CQPF_ISGLOBAL) )
- {
- Trace(TEXT("Adding global page to %d forms"), DSA_GetItemCount(_hdsaForms));
- for ( iForm = 0 ; iForm < DSA_GetItemCount(_hdsaForms); iForm++ )
- {
- LPQUERYFORM pQueryForm = (LPQUERYFORM)DSA_GetItemPtr(_hdsaForms, iForm);
- TraceAssert(pQueryForm);
- if ( !(pQueryForm->dwFlags & CQFF_NOGLOBALPAGES) )
- {
- hres = _AddPageToForm(pQueryForm, pQueryFormPage, TRUE);
- FailGracefully(hres, "Failed when adding global page to form");
- }
- }
- _FreeQueryFormPage(pQueryFormPage);
- if ( !DSA_DeleteItem(_hdsaPages, iPage) )
- TraceMsg("**** Failed to remove page from global DSA ****");
- }
- }
- // Walk the list of forms, rmeoving the ones which have no pages assocaited with
- // them, we don't need these around confusing the world around us. Note that
- // we walk backwards through the list removing.
- //
- // Also remove the optional forms we don't want to ehw orld to see
- for ( iForm = DSA_GetItemCount(_hdsaForms) ; --iForm >= 0 ; )
- {
- LPQUERYFORM pQueryForm = (LPQUERYFORM)DSA_GetItemPtr(_hdsaForms, iForm);
- TraceAssert(pQueryForm);
- Trace(TEXT("pQueryForm %08x (%s), pQueryForm->hdsaPages %08x (%d)"),
- pQueryForm,
- pQueryForm->pTitle,
- pQueryForm->hdsaPages,
- pQueryForm->hdsaPages ? DSA_GetItemCount(pQueryForm->hdsaPages):0);
- if ( !pQueryForm->hdsaPages
- || !DSA_GetItemCount(pQueryForm->hdsaPages )
- || ((pQueryForm->dwFlags & CQFF_ISOPTIONAL) && !(_pOpenQueryWnd->dwFlags & OQWF_SHOWOPTIONAL)) )
- {
- TraceGUID("Removing form: ", pQueryForm->clsidForm);
- _FreeQueryForm(pQueryForm);
- DSA_DeleteItem(_hdsaForms, iForm);
- }
- }
- if ( !DSA_GetItemCount(_hdsaForms ) )
- ExitGracefully(hres, E_FAIL, "!!!!! No forms registered after page/form fix ups !!!!!");
- // The pages have been attached to the forms so we can now attempt to create the
- // form/page objects.
- _szForm.cx = 0;
- _szForm.cy = 0;
- tci.mask = TCIF_TEXT;
- tci.pszText = TEXT("");
- tci.cchTextMax = 0;
- TabCtrl_InsertItem(_hwndFrame, 0, &tci); // tabctrl needs at least one item so we can compute sizes
- for ( iForm = 0 ; iForm < DSA_GetItemCount(_hdsaForms); iForm++ )
- {
- LPQUERYFORM pQueryForm = (LPQUERYFORM)DSA_GetItemPtr(_hdsaForms, iForm);
- TraceAssert(pQueryForm);
- // Create each of the modeless page dialoges that we show to allow the user
- // to edit the search criteria. We also grab the size and modify the
- // form informaiton we have so that the default size of the dialog can be
- // correctly computed.
- for ( iPage = 0 ; iPage < DSA_GetItemCount(pQueryForm->hdsaPages); iPage++ )
- {
- LPQUERYFORMPAGE pQueryFormPage = (LPQUERYFORMPAGE)DSA_GetItemPtr(pQueryForm->hdsaPages, iPage);
- TraceAssert(pQueryFormPage);
- #ifdef UNICODE
- if ( pQueryFormPage->fPageIsANSI )
- {
- pQueryFormPage->hwndPage = CreateDialogParamA(pQueryFormPage->pPageA->hInstance,
- MAKEINTRESOURCEA(pQueryFormPage->pPageA->idPageTemplate),
- _hwnd,
- pQueryFormPage->pPageA->pDlgProc,
- (LPARAM)pQueryFormPage->pPage);
- }
- else
- #endif
- {
- pQueryFormPage->hwndPage = CreateDialogParam(pQueryFormPage->pPage->hInstance,
- MAKEINTRESOURCE(pQueryFormPage->pPage->idPageTemplate),
- _hwnd,
- pQueryFormPage->pPage->pDlgProc,
- (LPARAM)pQueryFormPage->pPage);
- }
- if ( !pQueryFormPage->hwndPage )
- ExitGracefully(hres, E_FAIL, "Failed to create query form page");
- GetRealWindowInfo(pQueryFormPage->hwndPage, &rect, NULL);
- TabCtrl_AdjustRect(_hwndFrame, TRUE, &rect);
- _szForm.cx = max(rect.right-rect.left, _szForm.cx);
- _szForm.cy = max(rect.bottom-rect.top, _szForm.cy);
- // flush the form parameters
- _CallPageProc(pQueryFormPage, CQPM_CLEARFORM, 0, 0);
- // Call the page with CQPM_SETDEFAULTPARAMETERS with the
- // OPENQUERYWINDOW structure. wParam is TRUE/FALSE indiciating if
- // the form is the default one, and therefore if the pFormParam is
- // valid.
- _CallPageProc(pQueryFormPage, CQPM_SETDEFAULTPARAMETERS,
- (WPARAM)((_pOpenQueryWnd->dwFlags & OQWF_DEFAULTFORM) &&
- IsEqualCLSID(_pOpenQueryWnd->clsidDefaultForm, pQueryFormPage->clsidForm)),
- (LPARAM)_pOpenQueryWnd);
- }
- // If the form has an hIcon then lets ensure that we add that to the form image
- // list, any failure here is non-fatal, in that we will just skip that forms
- // icon in the list (rather than barfing)
- if ( pQueryForm->hIcon )
- {
- if ( !_himlForms )
- _himlForms = ImageList_Create(COMBOEX_IMAGE_CX, COMBOEX_IMAGE_CY, 0, 4, 1);
- if ( _himlForms )
- {
- pQueryForm->iImage = ImageList_AddIcon(_himlForms, pQueryForm->hIcon);
- TraceAssert(pQueryForm->iImage >= 0);
- }
- DestroyIcon(pQueryForm->hIcon);
- pQueryForm->hIcon = NULL;
- }
- }
- hres = S_OK; // success
- exit_gracefully:
- DoRelease(pQueryForm);
- if ( hKeyForms )
- RegCloseKey(hKeyForms);
- TraceLeaveResult(hres);
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::GetForms
- / ---------------------
- / Given a HKEY to the forms list and the value name for the form we want
- / to add, query for the form information add add the form objects
- / to the master list.
- /
- / In:
- / hKeyForms = HKEY for the {CLSID provider}Forms key
- / pName -> key value to query for
- /
- / Out:
- / VOID
- /----------------------------------------------------------------------------*/
- HRESULT CQueryFrame::GetForms(HKEY hKeyForms, LPTSTR pName)
- {
- HRESULT hres;
- HKEY hKeyForm = NULL;
- TCHAR szQueryFormCLSID[GUIDSTR_MAX+1];
- DWORD dwFlags;
- DWORD dwSize;
- IUnknown* pUnknown = NULL;
- IQueryForm* pQueryForm = NULL;
- #ifdef UNICODE
- IQueryFormA* pQueryFormA = NULL;
- #endif
- CLSID clsidForm;
- BOOL fIncludeForms = FALSE;
- TraceEnter(TRACE_FORMS, "CQueryFrame::_GetForms");
- Trace(TEXT("pName %s"), pName);
- if ( ERROR_SUCCESS != RegOpenKeyEx(hKeyForms, pName, NULL, KEY_READ, &hKeyForm) )
- ExitGracefully(hres, E_UNEXPECTED, "Failed to open the form key");
- // Read the flags and try to determine if we should invoke this form object.
- dwSize = SIZEOF(dwFlags);
- if ( ERROR_SUCCESS != RegQueryValueEx(hKeyForm, c_szFlags, NULL, NULL, (LPBYTE)&dwFlags, &dwSize) )
- {
- TraceMsg("No flags, defaulting to something sensible");
- dwFlags = QUERYFORM_CHANGESFORMLIST;
- }
- Trace(TEXT("Forms flag is %08x"), dwFlags);
- // should be invoke this form object?
- //
- // - if dwFlags has QUERYFORM_CHANGESFORMSLIST, or
- // - if dwFlags has QUERYFORM_CHANGESOPTFORMLIST and we are showing optional forms, or
- // - neither set and the form object supports the requested form
- if ( !(dwFlags & QUERYFORM_CHANGESFORMLIST) )
- {
- if ( (dwFlags & QUERYFORM_CHANGESOPTFORMLIST) &&
- (_pOpenQueryWnd->dwFlags & OQWF_SHOWOPTIONAL) )
- {
- TraceMsg("Form is optional, are we are showing optional forms");
- fIncludeForms = TRUE;
- }
- else
- {
- // OK, so it either didn't update the form list, or wasn't marked as optional,
- // so lets check to see if it supports the form the user has requested, if not
- // then don't bother loading this guy.
- if ( _pOpenQueryWnd->dwFlags & OQWF_DEFAULTFORM )
- {
- TCHAR szBuffer[GUIDSTR_MAX+32];
- HKEY hkFormsSupported;
- TraceMsg("Checking for supported form");
- if ( ERROR_SUCCESS == RegOpenKeyEx(hKeyForm, TEXT("Forms Supported"), NULL, KEY_READ, &hkFormsSupported) )
- {
- TraceMsg("Form has a 'Supported Forms' sub-key");
- GetStringFromGUID(_pOpenQueryWnd->clsidDefaultForm, szQueryFormCLSID, ARRAYSIZE(szQueryFormCLSID));
- Trace(TEXT("Checking for: %s"), szQueryFormCLSID);
- if ( ERROR_SUCCESS == RegQueryValueEx(hkFormsSupported, szQueryFormCLSID, NULL, NULL, NULL, NULL) )
- {
- TraceMsg("Query form is in supported list");
- fIncludeForms = TRUE;
- }
- RegCloseKey(hkFormsSupported);
- }
- else
- {
- TraceMsg("No forms supported sub-key, so loading form object anyway");
- fIncludeForms = TRUE;
- }
- }
- }
- }
- else
- {
- TraceMsg("Form updates form list");
- fIncludeForms = TRUE;
- }
- // if fIncludeForms is TRUE, then the checks above succeeded and we are including forms
- // from this object (identified by pName), so we must now get the CLSID of the object
- // we are invoking and use its IQueryForm interface to add the forms that we want.
- if ( fIncludeForms )
- {
- // get the form object CLSID, having parse it, then CoCreate it adding the forms.
- dwSize = SIZEOF(szQueryFormCLSID);
- if ( ERROR_SUCCESS != RegQueryValueEx(hKeyForm, c_szCLSID, NULL, NULL, (LPBYTE)szQueryFormCLSID, &dwSize) )
- ExitGracefully(hres, E_UNEXPECTED, "Failed to read the CLSID of the form");
- Trace(TEXT("szQueryFormCLSID: %s"), szQueryFormCLSID);
- if ( !GetGUIDFromString(szQueryFormCLSID, &clsidForm) )
- ExitGracefully(hres, E_UNEXPECTED, "Fialed to parse the string as a GUID");
- // we now have the CLISD of the form object, so we must attempt to CoCreate it, we try for
- // the current build type (eg UNICODE) and then fall back to ANSI if thats not supported,
- // so we can support ANSI query form objects on a UNICODE platform.
- hres = CoCreateInstance(clsidForm, NULL, CLSCTX_INPROC_SERVER, IID_IUnknown, (void**)&pUnknown);
- FailGracefully(hres, "Failed to CoCreate the form object");
- if ( SUCCEEDED(pUnknown->QueryInterface(IID_IQueryForm, (LPVOID*)&pQueryForm)) )
- {
- hres = AddFromIQueryForm(pQueryForm, hKeyForm);
- FailGracefully(hres, "Failed when adding forms from specified IQueryForm iface");
- }
- #ifdef UNICODE
- else if ( SUCCEEDED(pUnknown->QueryInterface(IID_IQueryFormA, (LPVOID*)&pQueryFormA)) )
- {
- hres = AddFromIQueryFormA(pQueryFormA, hKeyForms);
- FailGracefully(hres, "(ANSI) Failed when adding forms from specified IQueryForm iface");
- }
- #endif
- else
- {
- ExitGracefully(hres, E_UNEXPECTED, "Form object doesn't support IQueryForm(A/W)");
- }
- }
- hres = S_OK;
- exit_gracefully:
- if ( hKeyForm )
- RegCloseKey(hKeyForm);
- DoRelease(pUnknown);
- DoRelease(pQueryForm);
- #ifdef UNICODE
- DoRelease(pQueryFormA);
- #endif
- TraceLeaveResult(hres);
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::PopulateFormControl
- / ---------------------------------
- / Enumerate all the query forms for the given query handler and build
- / the DPA containing the list of them. Once we have done this we
- / can then populate the control at some more convientent moment.
- /
- / When gathering we first hit the "handler", then the "Forms" sub-key
- / trying to load all the InProc servers that provide forms. We build
- / list of hidden, never shown etc.
- /
- / In:
- / fIncludeHidden = list forms marked as hidden in control
- /
- / Out:
- / VOID
- /----------------------------------------------------------------------------*/
- HRESULT CQueryFrame::PopulateFormControl(BOOL fIncludeHidden)
- {
- HRESULT hres;
- COMBOBOXEXITEM cbi;
- LPQUERYFORM pQueryForm;
- INT i, iForm;
- TraceEnter(TRACE_FORMS, "CQueryFrame::PopulateFormControl");
- Trace(TEXT("fIncludeHidden: %d"), fIncludeHidden);
- // list which forms within the control
- if ( !_hdsaForms )
- ExitGracefully(hres, E_FAIL, "No forms to list");
- ComboBox_ResetContent(_hwndLookFor); // remove all items from that control
- for ( i = 0, iForm = 0 ; iForm < DSA_GetItemCount(_hdsaForms); iForm++ )
- {
- LPQUERYFORM pQueryForm = (LPQUERYFORM)DSA_GetItemPtr(_hdsaForms, iForm);
- TraceAssert(pQueryForm);
- // filter out those forms that are not of interest to this instance of the
- // dialog.
- if ( ((pQueryForm->dwFlags & CQFF_ISOPTIONAL) && !fIncludeHidden) ||
- (pQueryForm->dwFlags & CQFF_ISNEVERLISTED) )
- {
- Trace(TEXT("Hiding form: %s"), pQueryForm->pTitle);
- continue;
- }
- // now add the form to the control, including the image if there is an image
- // specified.
- cbi.mask = CBEIF_TEXT|CBEIF_LPARAM;
- cbi.iItem = i++;
- cbi.pszText = pQueryForm->pTitle;
- cbi.cchTextMax = lstrlen(pQueryForm->pTitle);
- cbi.lParam = iForm;
- if ( pQueryForm->iImage >= 0 )
- {
- Trace(TEXT("Form has an image %d"), pQueryForm->iImage);
- cbi.mask |= CBEIF_IMAGE|CBEIF_SELECTEDIMAGE;
- cbi.iImage = pQueryForm->iImage;
- cbi.iSelectedImage = pQueryForm->iImage;
- }
- pQueryForm->iForm = (int)SendMessage(_hwndLookFor, CBEM_INSERTITEM, 0, (LPARAM)&cbi);
- if ( pQueryForm->iForm < 0 )
- {
- Trace(TEXT("Form name: %s"), pQueryForm->pTitle);
- ExitGracefully(hres, E_FAIL, "Failed to add the entry to the combo box");
- }
- }
- hres = S_OK;
- exit_gracefully:
- TraceLeaveValue(hres);
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::SelectForm
- / -----------------------
- / Changes the current form to the one specified as an into the DPA.
- /
- / In:
- / iForm = form to be selected
- /
- / Out:
- / -
- /----------------------------------------------------------------------------*/
- HRESULT CQueryFrame::SelectForm(REFCLSID clsidForm)
- {
- HRESULT hres;
- LPQUERYFORM pQueryForm, pOldQueryForm;
- LPQUERYFORMPAGE pQueryFormPage;
- LPCQPAGE pPage;
- INT nCmdShow = SW_SHOW;
- TCHAR szBuffer[64], szTitle[MAX_PATH];;
- TC_ITEM tci;
- INT i;
- TraceEnter(TRACE_FORMS, "CQueryFrame::SelectForm");
- pQueryForm = FindQueryForm(clsidForm);
- TraceAssert(pQueryForm);
- if ( !pQueryForm )
- ExitGracefully(hres, S_FALSE, "Failed to find the requested form");
- // Change the currently displayed form and change the displayed
- // tabs to correctly indicate this
- if ( (pQueryForm != _pCurrentForm) )
- {
- if ( !OnNewQuery(FALSE) ) // prompt the user
- ExitGracefully(hres, S_FALSE, "Failed to select the new form");
- TabCtrl_DeleteAllItems(_hwndFrame);
- for ( i = 0 ; i < DSA_GetItemCount(pQueryForm->hdsaPages) ; i++ )
- {
- pQueryFormPage = (LPQUERYFORMPAGE)DSA_GetItemPtr(pQueryForm->hdsaPages, i);
- pPage = pQueryFormPage->pPage;
- tci.mask = TCIF_TEXT;
- tci.pszText = pQueryForm->pTitle;
- tci.cchTextMax = MAX_PATH;
- if ( pPage->idPageName &&
- LoadString(pPage->hInstance, pPage->idPageName, szBuffer, ARRAYSIZE(szBuffer)) )
- {
- Trace(TEXT("Loaded page title string %s"), szBuffer);
- tci.pszText = szBuffer;
- }
- TabCtrl_InsertItem(_hwndFrame, i, &tci);
- }
- ComboBox_SetCurSel(_hwndLookFor, pQueryForm->iForm);
- _pCurrentForm = pQueryForm;
- SelectFormPage(pQueryForm, pQueryForm->iPage);
- // Change the dialog title to reflect the new form
- if ( LoadString(GLOBAL_HINSTANCE, IDS_FIND, szBuffer, ARRAYSIZE(szBuffer)) )
- {
- wsprintf(szTitle, szBuffer, pQueryForm->pTitle);
- #if defined(DSUI_DEBUG) && !defined(UNICODE)
- StrCat(szTitle, TEXT(" (ANSI CMNQUERY)"));
- #endif
- SetWindowText(_hwnd, szTitle);
- }
- // Tell the handler that we have changed the form, they can then use this
- // new form name to modify their UI.
- _pQueryHandler->ActivateView(CQRVA_FORMCHANGED, (WPARAM)lstrlen(pQueryForm->pTitle), (LPARAM)pQueryForm->pTitle);
- }
- hres = S_OK;
- exit_gracefully:
- TraceLeaveResult(hres);
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::SelectFormPage
- / ---------------------------
- / Change the currently active page of a query form to the one specified
- / by the index.
- /
- / In:
- / pQueryForm = query form to be changed
- / iForm = form to be selected
- /
- / Out:
- / -
- /----------------------------------------------------------------------------*/
- VOID CQueryFrame::SelectFormPage(LPQUERYFORM pQueryForm, INT iPage)
- {
- LPQUERYFORMPAGE pQueryFormPage;
- RECT rect;
- TraceEnter(TRACE_FORMS, "CQueryFrame::SelectFormPage");
- pQueryFormPage = (LPQUERYFORMPAGE)DSA_GetItemPtr(pQueryForm->hdsaPages, iPage);
- // Have we changed the query form page? If so then display the now dialog
- // hiding the previous one. We call the TabCtrl to find out where we should
- // be placing this new control.
- if ( pQueryFormPage != _pCurrentFormPage )
- {
- // Reflect the change into the tab control
- TabCtrl_SetCurSel(_hwndFrame, iPage);
- pQueryForm->iPage = iPage;
- // Fix the size and visability of the new form
- if ( _pCurrentFormPage )
- ShowWindow(_pCurrentFormPage->hwndPage, SW_HIDE);
- GetRealWindowInfo(_hwndFrame, &rect, NULL);
- TabCtrl_AdjustRect(_hwndFrame, FALSE, &rect);
- SetWindowPos(pQueryFormPage->hwndPage,
- HWND_TOP,
- rect.left, rect.top,
- rect.right - rect.left,
- rect.bottom - rect.top,
- SWP_SHOWWINDOW);
- _pCurrentFormPage = pQueryFormPage;
- }
- TraceLeave();
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::CallFormPages
- / --------------------------
- / Given a query form traverse the array of pages calling each of them
- / with the given message information. If any of the pages return
- / an error code (other than E_NOTIMPL) we bail.
- /
- / In:
- / pQueryForm = query form to call
- / dwFlags = flags indicating which pages to call
- / uMsg, wParam, lParam = parameters for the page
- /
- / Out:
- / HRESULT
- /----------------------------------------------------------------------------*/
- HRESULT CQueryFrame::CallFormPages(LPQUERYFORM pQueryForm, DWORD dwFlags, UINT uMsg, WPARAM wParam, LPARAM lParam)
- {
- HRESULT hres = S_OK;
- INT iPage;
- TraceEnter(TRACE_FORMS, "CQueryFrame::CallFormPages");
- if ( !pQueryForm || !pQueryForm->hdsaPages )
- ExitGracefully(hres, E_FAIL, "No pQueryForm || pQueryForm->hdsaPages == NULL");
- Trace(TEXT("pQueryForm %08x, dwFlags %08x"), pQueryForm, dwFlags);
- Trace(TEXT("uMsg %08x, wParam %08x, lParam %08x"), uMsg, wParam, lParam);
- Trace(TEXT("%d pages to call"), DSA_GetItemCount(pQueryForm->hdsaPages));
- // Call each page in turn if it matches the filter we have been given for calling
- // down. If a page returns S_FALSE or a FAILURE then we exit the loop. If the
- // failure however is E_NOTIMPL then we ignore.
- for ( iPage = 0 ; iPage < DSA_GetItemCount(pQueryForm->hdsaPages); iPage++ )
- {
- LPQUERYFORMPAGE pQueryFormPage = (LPQUERYFORMPAGE)DSA_GetItemPtr(pQueryForm->hdsaPages, iPage);
- TraceAssert(pQueryFormPage);
- if ( ( (pQueryFormPage->fPageIsANSI) && (dwFlags & CALLFORMPAGES_ANSI)) ||
- ( !(pQueryFormPage->fPageIsANSI) && (dwFlags & CALLFORMPAGES_UNICODE)) )
- {
- hres = _CallPageProc(pQueryFormPage, uMsg, wParam, lParam);
- if ( FAILED(hres) && (hres != E_NOTIMPL) )
- {
- TraceMsg("PageProc returned a FAILURE");
- break;
- }
- else if ( hres == S_FALSE )
- {
- TraceMsg("PageProc returned S_FALSE, exiting loop");
- break;
- }
- }
- }
- exit_gracefully:
- TraceLeaveResult(hres);
- }
- /*-----------------------------------------------------------------------------
- / CQueryFrame::FindQueryForm
- / --------------------------
- / Given the CLSID for the form return a pointer to its LPQUERYFORM structure,
- / or NULL if not found.
- /
- / In:
- / clsidForm = ID of the form
- /
- / Out:
- / LPQUERYFORM
- /----------------------------------------------------------------------------*/
- LPQUERYFORM CQueryFrame::FindQueryForm(REFCLSID clsidForm)
- {
- LPQUERYFORM pQueryForm = NULL;
- INT i;
- TraceEnter(TRACE_FORMS, "CQueryFrame::FindQueryForm");
- TraceGUID("Form ID", clsidForm);
- for ( i = 0 ; _hdsaForms && (i < DSA_GetItemCount(_hdsaForms)) ; i++ )
- {
- pQueryForm = (LPQUERYFORM)DSA_GetItemPtr(_hdsaForms, i);
- TraceAssert(pQueryForm);
- if ( IsEqualCLSID(clsidForm, pQueryForm->clsidForm) )
- {
- Trace(TEXT("Form is index %d (%08x)"), i, pQueryForm);
- break;
- }
- }
- if ( !_hdsaForms || (i >= DSA_GetItemCount(_hdsaForms)) )
- pQueryForm = NULL;
- TraceLeaveValue(pQueryForm);
- }