/*---------------------------------------------------------------------------------------------- Perform whatever action is appropriate when the use clicks on a hot link ----------------------------------------------------------------------------------------------*/ STDMETHODIMP VwBaseVc::DoHotLinkAction(BSTR bstrData, ISilDataAccess * psda) { BEGIN_COM_METHOD; ChkComArgPtrN(ptss); if (BstrLen(bstrData) > 0 && bstrData[0] == kodtExternalPathName) { StrAppBuf strbFile(bstrData + 1); if (::UrlIs(strbFile.Chars(), URLIS_URL)) { // If it's a URL launch whatever it means. ::ShellExecute(NULL, L"open", strbFile.Chars(), NULL, NULL, SW_SHOWNORMAL); return S_OK; } if (AfApp::Papp()) { AfMainWnd * pafw = AfApp::Papp()->GetCurMainWnd(); if (pafw && pafw->GetLpInfo()) pafw->GetLpInfo()->MapExternalLink(strbFile); AfApp::LaunchHL(NULL, _T("open"), strbFile.Chars(), NULL, NULL, SW_SHOW); } } return S_OK; END_COM_METHOD(g_fact, IID_IVwViewConstructor); }
/*---------------------------------------------------------------------------------------------- This method checks for duplicates in list names. If the given name exists then return true. @param pszName name to check to see if it exists. @return True if name already exists. ----------------------------------------------------------------------------------------------*/ bool ListsPropDlg::CheckName(const achar * pszName) { AfMainWnd * pafw = MainWindow(); AssertPtr(pafw); AfLpInfo * plpi = pafw->GetLpInfo(); AssertPtr(plpi); Vector<HVO> & vhvo = plpi->GetPsslIds(); AfDbInfoPtr qdbi = plpi->GetDbInfo(); AssertPtr(qdbi); IOleDbEncapPtr qode; qdbi->GetDbAccess(&qode); StrAnsi sta; int i; StrUni stuIds; int cv = vhvo.Size(); Assert(cv); ComBool fIsNull; ComBool fMoreRows; ULONG cbSpaceTaken; IOleDbCommandPtr qodc; const int kcchBuffer = MAX_PATH; OLECHAR rgchName[kcchBuffer]; HVO hvo; StrUni stu; for (i = 0; i < cv; ++i) { hvo = vhvo[i]; stu.Format(L"exec GetOrderedMultiTxt '%d', %d", hvo, kflidCmMajorObject_Name); CheckHr(qode->CreateCommand(&qodc)); CheckHr(qodc->ExecCommand(stu.Bstr(), knSqlStmtStoredProcedure)); CheckHr(qodc->GetRowset(0)); CheckHr(qodc->NextRow(&fMoreRows)); Assert(fMoreRows); // This proc should always return something. CheckHr(qodc->GetColValue(1, reinterpret_cast <BYTE *>(rgchName), kcchBuffer * isizeof(OLECHAR), &cbSpaceTaken, &fIsNull, 2)); sta = rgchName; if (hvo != m_hvoObj && sta.Equals(pszName)) return false; } return true; }
/*---------------------------------------------------------------------------------------------- Make the root box. ----------------------------------------------------------------------------------------------*/ void TssEdit::MakeRoot(IVwGraphics * pvg, ILgWritingSystemFactory * pwsf, IVwRootBox ** pprootb) { AssertPtr(pvg); AssertPtrN(pwsf); AssertPtr(pprootb); *pprootb = NULL; IVwRootBoxPtr qrootb; qrootb.CreateInstance(CLSID_VwRootBox); CheckHr(qrootb->SetSite(this)); HVO hvo = khvoString; int frag = kfrString; // Set up a new view constructor. ComBool fRTL = FALSE; IWritingSystemPtr qws; Assert(pwsf == m_qwsf.Ptr()); CheckHr(pwsf->get_EngineOrNull(m_wsBase, &qws)); if (qws) CheckHr(qws->get_RightToLeft(&fRTL)); TssEditVcPtr qtevc; qtevc.Attach(NewObj TssEditVc(this, m_nEditable, m_fShowTags, fRTL)); CheckHr(m_qcda->putref_WritingSystemFactory(pwsf)); CheckHr(qrootb->putref_DataAccess(m_qcda)); AfMainWnd * pafw = MainWindow(); AssertPtrN(pafw); AfStylesheet * pss = NULL; AfLpInfo * plpi = pafw->GetLpInfo(); if (plpi) { pss = plpi->GetAfStylesheet(); // This allows it to receive updates to style defns. pafw->RegisterRootBox(qrootb); } IVwViewConstructor * pvvc = qtevc; CheckHr(qrootb->SetRootObjects(&hvo, &pvvc, &frag, pss, 1)); *pprootb = qrootb.Detach(); }
/*---------------------------------------------------------------------------------------------- Handle notifications. @param ctid Identifier of the common control sending the message. @param pnmh Pointer to an NMHDR structure containing notification code and additional info. @param lnRet Value to be returned to system windows send message call. @return True if the notification has been handled, otherwise false. ----------------------------------------------------------------------------------------------*/ bool TssEdit::OnNotifyChild(int id, NMHDR * pnmh, long & lnRet) { AssertPtr(pnmh); if (SuperClass::OnNotifyChild(id, pnmh, lnRet)) return true; bool fToolTip = HasToolTip(); HWND hwndParent = ::GetParent(m_hwnd); if (fToolTip && pnmh->code == TTN_POP) { // Wait 1/2 second after the tooltip disappears before resetting the text on the // status bar. ::SetTimer(hwndParent, knToolTipTimer, 500, NULL); return true; } else if (fToolTip && pnmh->code == TTN_SHOW) { // This flag keeps the tooltip from recursively appearing and crashing the program. static bool s_fIgnore = false; if (!s_fIgnore) { // If another tooltip shows up in the 1/2 second time interval set above, cancel // the timer, so the status bar doesn't get changed back to the idle string. ::KillTimer(hwndParent, knToolTipTimer); // Create a new notification message and forward it to the parent in order to get // the default response for a normal tooltip (which is currently defined in // AfMainWnd::OnNotifyChild). NMTTDISPINFO nmtdi; nmtdi.hdr.hwndFrom = (HWND)id; nmtdi.hdr.code = TTN_GETDISPINFO; nmtdi.hdr.idFrom = ::GetDlgCtrlID((HWND)id); *nmtdi.szText = 0; ::SendMessage(::GetParent(m_hwnd), WM_NOTIFY, nmtdi.hdr.idFrom, (LPARAM)&nmtdi); // Update the status bar here rather than above after ::KillTimer() so that the // string for the new command is already set. AfMainWnd * pafw = MainWindow(); AssertPtr(pafw); AfStatusBar * pstat = pafw->GetStatusBarWnd(); if (pstat) pstat->DisplayHelpText(); if (*nmtdi.szText) { // Now we have the text for the control, so update the text in the tooltip. TOOLINFO ti = { isizeof(ti) }; ti.hwnd = (HWND)id; ti.uId = (uint)ti.hwnd; ti.lpszText = nmtdi.szText; ::SendMessage(pnmh->hwndFrom, TTM_UPDATETIPTEXT, 0, (LPARAM)&ti); // This is required so the tooltip gets resized properly. s_fIgnore = true; ::SendMessage(pnmh->hwndFrom, TTM_UPDATE, 0, 0); s_fIgnore = false; return true; } } } return false; }
/*---------------------------------------------------------------------------------------------- This is the method for displaying the name of a single reference. This view shows the name for an RnGenericRec consisting of the type of record, hyphen, title, hyphen, creation date. "Subevent - Fishing for pirana - 3/22/2001" @param pvwenv Pointer to the view environment. @param hvo The id of the object we are displaying. @param frag Identifies the part of the view we are currently displaying. @return HRESULT indicating success (S_OK), or failure (E_FAIL). ----------------------------------------------------------------------------------------------*/ STDMETHODIMP CleRecVc::Display(IVwEnv * pvwenv, HVO hvo, int frag) { BEGIN_COM_METHOD; ChkComArgPtr(pvwenv); Assert(false); // Is this needed for poss lists? switch (frag) { case kfrRefName: case kfrListName: { SmartBstr bstrClass = L"UnLoaded"; ITsStringPtr qtss; ITsStringPtr qtssTitle; // Make sure data is loaded. LoadDataFor(pvwenv, hvo, frag); AfMainWnd * pafw = AfApp::Papp()->GetCurMainWnd(); AssertPtr(pafw); AfLpInfo * plpi = pafw->GetLpInfo(); AssertPtr(plpi); AfDbInfo * pdbi = plpi->GetDbInfo(); AssertPtr(pdbi); #define HYPERLINK_CHANGE #ifdef HYPERLINK_CHANGE // Update the string with the new object. GUID uid; if (!pdbi->GetGuidFromId(hvo, uid)) ReturnHr(E_FAIL); StrUni stuData; OLECHAR * prgchData; // Make large enough for a guid plus the type character at the start. stuData.SetSize(isizeof(GUID) / isizeof(OLECHAR) + 1, &prgchData); *prgchData = kodtNameGuidHot; memmove(prgchData + 1, &uid, isizeof(uid)); ITsPropsFactoryPtr qtpf; ITsPropsBldrPtr qtpb; ITsTextPropsPtr qttp; ITsStrFactoryPtr qtsf; qtpf.CreateInstance(CLSID_TsPropsFactory); CheckHr(qtpf->GetPropsBldr(&qtpb)); CheckHr(qtpb->SetIntPropValues(ktptWs, ktpvDefault, pdbi->UserWs())); CheckHr(qtpb->SetStrPropValue(ktptObjData, stuData.Bstr())); CheckHr(qtpb->GetTextProps(&qttp)); qtsf.CreateInstance(CLSID_TsStrFactory); OLECHAR chObj = kchObject; CheckHr(qtsf->MakeStringWithPropsRgch(&chObj, 1, qttp, &qtss)); CheckHr(pvwenv->OpenSpan()); // REVIEW KenZ(RandyR) Whey are DN flids in this app? int flid = kflidRnGenericRec_Title; CheckHr(pvwenv->NoteDependency(&hvo, &flid, 1)); CheckHr(pvwenv->AddString(qtss)); // The class name. CheckHr(pvwenv->CloseSpan()); #else // !HYPERLINK_CHANGE int clid; HVO hvoOwn; int64 ntim; int ws = pdbi->UserWs(); ISilDataAccessPtr qsda; CheckHr(pvwenv->get_DataAccess(&qsda)); AssertPtr(qsda); CheckHr(qsda->get_IntProp(hvo, kflidCmObject_Class, &clid)); CheckHr(qsda->get_ObjectProp(hvo, kflidCmObject_Owner, &hvoOwn)); // REVIEW KenZ(RandyR) Whey are DN flids in this app? CheckHr(qsda->get_TimeProp(hvo, kflidRnGenericRec_DateCreated, &ntim)); CheckHr(qsda->get_StringProp(hvo, kflidRnGenericRec_Title, &qtssTitle)); int stid; // Sharon! Not needed? // if (clid == kclidRnEvent) // { // if (plpi->GetRnId() == hvoOwn) // stid = kstidEvent; // else // stid = kstidSubevent; // } // else if (clid == kclidRnAnalysis) // { // if (plpi->GetRnId() == hvoOwn) // stid = kstidAnalysis; // else // stid = kstidSubanalysis; // } StrUni stu(stid); StrUni stuSep(kstidSpHyphenSp); ITsStrFactoryPtr qtsf; qtsf.CreateInstance(CLSID_TsStrFactory); CheckHr(qtsf->MakeStringRgch(stu.Chars(), stu.Length(), ws, &qtss)); CheckHr(pvwenv->OpenSpan()); CheckHr(pvwenv->AddString(qtss)); // The class name. CheckHr(qtsf->MakeStringRgch(stuSep.Chars(), stuSep.Length(), ws, &qtss)); CheckHr(pvwenv->AddString(qtss)); // The separator //CheckHr(pvwenv->AddString(qtssTitle)); // The title. // The following gives the title of the owning object instead of the ref. CheckHr(pvwenv->AddStringProp(kflidRnGenericRec_Title, this)); // The title. CheckHr(pvwenv->AddString(qtss)); // The separator // Leave the date blank if a date doesn't exist. if (ntim) { // Convert the date to a system date. SilTime tim = ntim; SYSTEMTIME stim; stim.wYear = (unsigned short) tim.Year(); stim.wMonth = (unsigned short) tim.Month(); stim.wDay = (unsigned short) tim.Date(); // Then format it to a time based on the current user locale. char rgchDate[50]; // Tuesday, August 15, 2000 mardi 15 août 2000 ::GetDateFormat(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &stim, NULL, rgchDate, 50); stu = rgchDate; CheckHr(qtsf->MakeStringRgch(stu.Chars(), stu.Length(), ws, &qtss)); CheckHr(pvwenv->AddString(qtss)); // The date. } CheckHr(pvwenv->CloseSpan()); #endif // HYPERLINK_CHANGE break; } } return S_OK; END_COM_METHOD(g_fact2, IID_IVwViewConstructor) }
/*---------------------------------------------------------------------------------------------- Load the data needed to display this view. In this case, we need to load the class, owner (so we can tell whether it is a subitem), the title, and create date. If all of these are already in the cache, don't reload it. @param pvwenv Pointer to the view environment. @param hvo The id of the object we are displaying. @param frag Identifies the part of the view we are currently displaying. @return HRESULT indicating success (S_OK), or failure (E_FAIL). ----------------------------------------------------------------------------------------------*/ STDMETHODIMP CleRecVc::LoadDataFor(IVwEnv * pvwenv, HVO hvo, int frag) { BEGIN_COM_METHOD; ChkComArgPtr(pvwenv); Assert(false); // TODO: rework StrUni stuSql; ISilDataAccessPtr qsda; CheckHr(pvwenv->get_DataAccess(&qsda)); bool fLoaded = false; int clid; CheckHr(qsda->get_IntProp(hvo, kflidCmObject_Class, &clid)); if (clid) { HVO hvoOwn; CheckHr(qsda->get_ObjectProp(hvo, kflidCmObject_Owner, &hvoOwn)); if (hvoOwn) { int64 tim; // REVIEW KenZ(RandyR) Whey are DN flids in this app? CheckHr(qsda->get_TimeProp(hvo, kflidRnGenericRec_DateCreated, &tim)); if (tim) { ITsStringPtr qtss; CheckHr(qsda->get_StringProp(hvo, kflidRnGenericRec_Title, &qtss)); if (qtss) { int cch; CheckHr(qtss->get_Length(&cch)); if (cch) fLoaded = true; } } } } if (!fLoaded) { // If any field is missing from the cache, load everything. IDbColSpecPtr qdcs; IVwOleDbDaPtr qda; CheckHr(qsda->QueryInterface(IID_IVwOleDbDa, (void**)&qda)); stuSql.Format(L"select id, Class$, Owner$, DateCreated, Title, Title_Fmt " L"from RnGenericRec_ " L"where id = %d", hvo); qdcs.CreateInstance(CLSID_DbColSpec); CheckHr(qdcs->Push(koctBaseId, 0, 0, 0)); CheckHr(qdcs->Push(koctInt, 1, kflidCmObject_Class, 0)); CheckHr(qdcs->Push(koctObj, 1, kflidCmObject_Owner, 0)); // REVIEW KenZ(RandyR) Whey are DN flids in this app? CheckHr(qdcs->Push(koctTime, 1, kflidRnGenericRec_DateCreated, 0)); CheckHr(qdcs->Push(koctString, 1, kflidRnGenericRec_Title, 0)); CheckHr(qdcs->Push(koctFmt, 1, kflidRnGenericRec_Title, 0)); AfMainWnd * pafw = AfApp::Papp()->GetCurMainWnd(); AssertPtr(pafw); AfStatusBar * pstbr = pafw->GetStatusBarWnd(); AssertPtr(pstbr); bool fProgBar = pstbr->IsProgressBarActive(); if (!fProgBar) { StrApp strMsg(kstidStBar_LoadingData); pstbr->StartProgressBar(strMsg.Chars(), 0, 70, 1); } // Execute the query and store results in the cache. CheckHr(qda->Load(stuSql.Bstr(), qdcs, hvo, 0, pstbr, NULL)); if (!fProgBar) pstbr->EndProgressBar(); } return S_OK; END_COM_METHOD(g_fact2, IID_IVwViewConstructor) }
/*---------------------------------------------------------------------------------------------- Non-virtual window proc to call standard message handlers. All handlers should be virtual. WARNING: This method is also called for dialogs. @param wm Windows message identifier. @param wp First message parameter. @param lp Second message parameter. @param lnRet Value to be returned to the system. (return value for window procedure) @return true to prevent the message from being sent to other windows. ----------------------------------------------------------------------------------------------*/ bool AfWnd::FWndProcPre(uint wm, WPARAM wp, LPARAM lp, long & lnRet) { AssertObj(this); bool fRet; switch (wm) { case WM_SYSCOLORCHANGE: // In an ActiveX control we may have no Papp(). // It's a bit unusual to be handling a command in that situation, but it can happen. if (!AfApp::Papp()) return false; // Push a color change command and enqueue a command indicating that we're done // processing color change messages. // NOTE: We get one of these per top level window. AfApp::Papp()->PushCid(kcidColorChange, this, wp, lp); AfApp::Papp()->EnqueueCid(kcidEndColorChange, this, wp, lp); return false; case WM_SETTINGCHANGE: // In an ActiveX control we may have no Papp(). // It's a bit unusual to be handling a command in that situation, but it can happen. if (!AfApp::Papp()) return false; // Push a color setting command and enqueue a command indicating that we're done // processing setting change messages. // NOTE: We may get many of these per top level window. AfApp::Papp()->PushCid(kcidSettingChange, this, wp, lp); AfApp::Papp()->EnqueueCid(kcidEndSettingChange, this, wp, lp); return false; case WM_MEASUREITEM: // Handle menu items. if (!wp && AfApp::GetMenuMgr(&m_pmum)->OnMeasureItem((MEASUREITEMSTRUCT *)lp)) return true; return OnMeasureChildItem((MEASUREITEMSTRUCT *)lp); case WM_DRAWITEM: // Handle menu items. if (!wp && AfApp::GetMenuMgr(&m_pmum)->OnDrawItem((DRAWITEMSTRUCT *)lp)) return true; return OnDrawChildItem((DRAWITEMSTRUCT *)lp); case WM_INITMENUPOPUP: // LOWORD(lp) specifies the zero-based relative position of the menu item that opens the // drop-down menu or submenu. // HIWORD(lp) If the menu is the window menu, this is TRUE; otherwise, it is FALSE. if (HIWORD(lp) == 0) // Ignore system menus. { AfApp::GetMenuMgr(&m_pmum)->ExpandMenuItems((HMENU)wp, LOWORD(lp)); } return OnInitMenuPopup((HMENU)wp, LOWORD(lp), HIWORD(lp) != 0); case WM_MENUSELECT: if (!lp && HIWORD(wp) == 0xFFFF) { // Menu was closed if it had been open. AfApp::GetMenuMgr(&m_pmum)->OnMenuClose(); AfMainWnd * pafw = MainWindow(); if (pafw) pafw->SetContextInfo(NULL, MakePoint(0)); } return OnMenuSelect((int)LOWORD(wp), (UINT)HIWORD(wp), (HMENU)lp); case WM_MENUCHAR: lnRet = AfApp::GetMenuMgr(&m_pmum)->OnMenuChar((achar)LOWORD(wp), (HMENU)lp); return lnRet != 0; case WM_PAINT: return OnPaint((HDC)wp); case WM_SIZE: fRet = OnSize(wp, LOWORD(lp), HIWORD(lp)); OnClientSize(); return fRet; case WM_COMMAND: return OnCommand(LOWORD(wp), HIWORD(wp), (HWND)lp); case WM_NOTIFY: return OnNotifyChild(wp, (NMHDR *)lp, lnRet); case WM_SETFOCUS: return OnSetFocus(); case WM_CONTEXTMENU: return OnContextMenu((HWND)wp, MakePoint(lp)); } // Keep passing the message. return false; }