⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dboxview.cpp

📁 Password Safe Password Safe is a password database utility. Users can keep their passwords securely
💻 CPP
📖 第 1 页 / 共 3 页
字号:
	case IDYES:	  rc2 = Save();	  if (rc2 != PWScore::SUCCESS)            return;	case IDNO:	  ClearClipboard();	  app.m_pMainWnd = NULL;	  break;	}    }  else    {      if (prefs->GetPref(PWSprefs::BoolPrefs::DontAskMinimizeClearYesNo))	ClearClipboard();      app.m_pMainWnd = NULL;    }  ClearData();  //Store current filename for next time...  prefs->SetPref(PWSprefs::StringPrefs::CurrentFile, m_core.GetCurFile());  prefs->SetPref(PWSprefs::StringPrefs::CurrentBackup, m_currbackup);  CDialog::OnOK();}voidDboxMain::OnCancel(){   OnOK();}void DboxMain::UpdateListItemTitle(int lindex, const CString &newTitle){  m_ctlItemList.SetItemText(lindex, 0, newTitle);}void DboxMain::UpdateListItemUser(int lindex, const CString &newName){  m_ctlItemList.SetItemText(lindex, 1, newName);} // Find in m_pwlist entry with same title and user name as the i'th entry in m_ctlItemListPOSITION DboxMain::Find(int i){  CItemData *ci = (CItemData *)m_ctlItemList.GetItemData(i);  ASSERT(ci != NULL);  const CMyString curGroup = ci->GetGroup();  const CMyString curTitle = m_ctlItemList.GetItemText(i, 0);  const CMyString curUser = m_ctlItemList.GetItemText(i, 1);  return Find(curGroup, curTitle, curUser);}#if defined(POCKET_PC)  #if (POCKET_PC_VER == 2000)    #define PWS_CDECL	__cdecl  #else    #define PWS_CDECL  #endif#else  #define PWS_CDECL#endif// for qsort in FindAllstatic int PWS_CDECL compint(const void *a1, const void *a2){  // since we're sorting a list of indices, v1 == v2 should never happen.  const int v1 = *(int *)a1, v2 = *(int *)a2;  ASSERT(v1 != v2);  return (v1 < v2) ? -1 : (v1 > v2) ? 1 : 0;}#undef PWS_CDECL/* * Finds all entries in m_pwlist that contain str in title, user, group or notes * field, returns their sorted indices in m_listctrl via indices, which is * assumed to be allocated by caller to DboxMain::GetNumEntries() ints. * FindAll returns the number of entries that matched. */intDboxMain::FindAll(const CString &str, BOOL CaseSensitive, int *indices){  ASSERT(!str.IsEmpty());  ASSERT(indices != NULL);  POSITION listPos = m_core.GetFirstEntryPosition();  CMyString curtitle, curuser, curnotes, curgroup, savetitle;  CMyString listTitle;  CString searchstr(str); // Since str is const, and we might need to MakeLower  int retval = 0;  if (!CaseSensitive)    searchstr.MakeLower();  while (listPos != NULL)  {      const CItemData &curitem = m_core.GetEntryAt(listPos);      savetitle = curtitle = curitem.GetTitle(); // savetitle keeps orig case      curuser =  curitem.GetUser();      curnotes = curitem.GetNotes();      curgroup = curitem.GetGroup();      if (!CaseSensitive) {          curtitle.MakeLower();          curuser.MakeLower();          curnotes.MakeLower();	  curgroup.MakeLower();      }      if (::strstr(curtitle, searchstr) ||	  ::strstr(curuser, searchstr) ||	  ::strstr(curnotes, searchstr) ||	  ::strstr(curgroup, searchstr)) {	// Find index in displayed list	DisplayInfo *di = (DisplayInfo *)curitem.GetDisplayInfo();	ASSERT(di != NULL);	int li = di->list_index;	ASSERT(CMyString(m_ctlItemList.GetItemText(li, 0)) == savetitle);	// add to indices, bump retval	indices[retval++] = li;      } // match found in m_pwlist      m_core.GetNextEntry(listPos);  }  // Sort indices  if (retval > 1)    ::qsort((void *)indices, retval, sizeof(indices[0]), compint);  return retval;}//Checks and sees if everything works and something is selectedBOOLDboxMain::SelItemOk(){   CItemData *ci = getSelectedItem();   if (ci == NULL)     return FALSE;   else     return TRUE;}BOOL DboxMain::SelectEntry(int i, BOOL MakeVisible){  BOOL retval;  if (m_ctlItemList.IsWindowVisible()) {    retval = m_ctlItemList.SetItemState(i,					LVIS_FOCUSED | LVIS_SELECTED,					LVIS_FOCUSED | LVIS_SELECTED);    if (MakeVisible) {      m_ctlItemList.EnsureVisible(i, FALSE);    }  } else { //Tree view active    CItemData *ci = (CItemData *)m_ctlItemList.GetItemData(i);    ASSERT(ci != NULL);    DisplayInfo *di = (DisplayInfo *)ci->GetDisplayInfo();    ASSERT(di != NULL);    ASSERT(di->list_index == i);    retval = m_ctlItemTree.SelectItem(di->tree_item);    if (MakeVisible) {// Following needed to show selection when Find dbox has focus. Ugh.      m_ctlItemTree.SetItemState(di->tree_item,				 TVIS_DROPHILITED | TVIS_SELECTED,				 TVIS_DROPHILITED | TVIS_SELECTED);    }  }  return retval;}//Updates m_ctlItemList and m_ctlItemTree from m_pwlist// updates of windows suspended untill all data is in.voidDboxMain::RefreshList(){  if (! m_windowok)    return;#if defined(POCKET_PC)  HCURSOR		waitCursor = app.LoadStandardCursor( IDC_WAIT );#endif  // can't use LockWindowUpdate 'cause only one window at a time can be locked  m_ctlItemList.SetRedraw( FALSE );  m_ctlItemTree.SetRedraw( FALSE );  m_ctlItemList.DeleteAllItems();  m_ctlItemTree.DeleteAllItems();  LVCOLUMN lvColumn;  lvColumn.mask = LVCF_WIDTH;  bool bPasswordColumnShowing = m_ctlItemList.GetColumn(3, &lvColumn)? true: false;  if (m_bShowPasswordInList && !bPasswordColumnShowing) {    m_ctlItemList.InsertColumn(3, _T("Password"));    CRect rect;    m_ctlItemList.GetClientRect(&rect);    m_ctlItemList.SetColumnWidth(3,				 PWSprefs::GetInstance()->				 GetPref(PWSprefs::IntPrefs::Column4Width,					 rect.Width() / 4));  }  else if (!m_bShowPasswordInList && bPasswordColumnShowing) {    PWSprefs::GetInstance()->SetPref(PWSprefs::IntPrefs::Column4Width,				     lvColumn.cx);    m_ctlItemList.DeleteColumn(3);  }  POSITION listPos = m_core.GetFirstEntryPosition();#if defined(POCKET_PC)  SetCursor( waitCursor );#endif  while (listPos != NULL) {    CItemData &ci = m_core.GetEntryAt(listPos);    DisplayInfo *di = (DisplayInfo *)ci.GetDisplayInfo();    if (di != NULL)      di->list_index = -1; // easier, but less efficient, to delete di    insertItem(ci);    m_core.GetNextEntry(listPos);  }  m_ctlItemList.SortItems(CompareFunc, (LPARAM)this);#if defined(POCKET_PC)  SetCursor( NULL );#endif  // re-enable and force redraw!  m_ctlItemList.SetRedraw( TRUE ); m_ctlItemList.Invalidate();  m_ctlItemTree.SetRedraw( TRUE ); m_ctlItemTree.Invalidate();  FixListIndexes(m_ctlItemList);  //Setup the selection  if (m_ctlItemList.GetItemCount() > 0 && getSelectedItem() < 0) {    SelectEntry(0);  }}voidDboxMain::OnSize(UINT nType,                 int cx,                 int cy) //Note that onsize runs before InitDialog (Gee, I love MFC){  CDialog::OnSize(nType, cx, cy);  // {kjp} Only SIZE_RESTORED is supported on Pocket PC.#if !defined(POCKET_PC)  if (nType == SIZE_MINIMIZED)    {      PWSprefs *prefs = PWSprefs::GetInstance();      m_ctlItemList.DeleteAllItems();      m_ctlItemTree.DeleteAllItems();      if (prefs->GetPref(PWSprefs::BoolPrefs::DontAskMinimizeClearYesNo))	ClearClipboard();      if (prefs->GetPref(PWSprefs::BoolPrefs::DatabaseClear)) {	bool dontask = prefs->GetPref(PWSprefs::BoolPrefs::DontAskSaveMinimize);	bool doit = true;	  if ((m_core.IsChanged()) && !dontask) {	      CRemindSaveDlg remindDlg(this);	      int rc = remindDlg.DoModal();	      if (rc == IDOK)		{		}	      else if (rc == IDCANCEL)		{		  doit = FALSE;		}	    }	  if (doit && (m_existingrestore == FALSE)) 	    {	      if ( m_core.IsChanged() ) // only save if changed                OnSave();	      ClearData();	      m_needsreading = true;	    }	}	 if (PWSprefs::GetInstance()->	    GetPref(PWSprefs::BoolPrefs::UseSystemTray))	  {      		  app.m_TrayIcon.SetMenuDefaultItem(ID_MENUITEM_UNMINIMIZE, FALSE);		  ShowWindow(SW_HIDE);	  }     }  else if (!m_bSizing && nType == SIZE_RESTORED)	// gets called even when just resizing window    {#endif	  app.m_TrayIcon.SetMenuDefaultItem(ID_MENUITEM_MINIMIZE, FALSE);      if ((m_needsreading)          && (m_existingrestore == FALSE)          && (m_windowok))	{	  m_existingrestore = TRUE;	  CMyString passkey;	  int rc, rc2;	  CMyString temp;	  rc = GetAndCheckPassword(m_core.GetCurFile(), passkey);	  switch (rc)	    {	    case PWScore::SUCCESS:	      rc2 = m_core.ReadCurFile(passkey);#if !defined(POCKET_PC)	      m_title = _T("Password Safe - ") + m_core.GetCurFile();#endif	      break; 	    case PWScore::CANT_OPEN_FILE:	      temp =		m_core.GetCurFile()		+ "\n\nCannot open database. It likely does not exist."		+ "\nA new database will be created.";	      MessageBox(temp, _T("File open error."), MB_OK|MB_ICONWARNING);	    case TAR_NEW:	      rc2 = New();	      break;	    case TAR_OPEN:	      rc2 = Open();	      break;	    case PWScore::WRONG_PASSWORD:	      rc2 = PWScore::NOT_SUCCESS;	      break;	    default:	      rc2 = PWScore::NOT_SUCCESS;	      break;	    }	  if (rc2 == PWScore::SUCCESS)	    {	      m_needsreading = false;	      m_existingrestore = FALSE;		  startLockCheckTimer();	      RefreshList();	    }	  else	    {	      m_needsreading = TRUE;	      m_existingrestore = FALSE;	      ShowWindow( SW_MINIMIZE );	      return;	    }	}      RefreshList();#if !defined(POCKET_PC)    }#endif  if (m_windowok) {    // And position the control bars    CRect rect;    RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0);    RepositionBars(AFX_IDW_CONTROLBAR_FIRST, AFX_IDW_CONTROLBAR_LAST, 0, reposQuery, &rect);    m_ctlItemList.MoveWindow(&rect, TRUE);    m_ctlItemTree.MoveWindow(&rect, TRUE);  }  m_bSizing = false;}static bool ExtractURL(const CMyString &instr, CMyString &outurl){  // Extract first instance of (http|https|ftp)://[^ \t\r\n]+  int left = instr.Find(_T("http://"));  if (left == -1)    left = instr.Find(_T("https://"));  if (left == -1)    left = instr.Find(_T("ftp://"));  if (left == -1) {    outurl = _T("");    return false;  } else {    CString url(instr);    url = url.Mid(left); // throw out everything left of URL    int right = url.FindOneOf(_T(" \t\r\n"));    if (right != -1) {      url = url.Left(right);          }    outurl = CMyString(url);    return true;  }}// Called when right-click is invoked in the client area of the window.voidDboxMain::OnContextMenu(CWnd *, CPoint point) {#if defined(POCKET_PC)    const DWORD dwTrackPopupFlags = TPM_LEFTALIGN;#else    const DWORD dwTrackPopupFlags = TPM_LEFTALIGN | TPM_RIGHTBUTTON;#endif    CPoint local = point;    int item = -1;    CItemData *itemData = NULL;    CMenu menu;    if (m_ctlItemList.IsWindowVisible())    {        // currently in flattened list view.        m_ctlItemList.ScreenToClient(&local);        item = m_ctlItemList.HitTest(local);        if (item < 0)            return; // right click on empty list        itemData = (CItemData *)m_ctlItemList.GetItemData(item);        int rc = SelectEntry(item);        if (rc == LB_ERR) {            return; // ? is this possible ?        }        m_ctlItemList.SetFocus();    } else {        // currently in tree view        ASSERT(m_ctlItemTree.IsWindowVisible());        m_ctlItemTree.ScreenToClient(&local);        HTREEITEM ti = m_ctlItemTree.HitTest(local);        if (ti != NULL) {            itemData = (CItemData *)m_ctlItemTree.GetItemData(ti);            if (itemData != NULL) {                // right-click was on an item (LEAF)                DisplayInfo *di = (DisplayInfo *)itemData->GetDisplayInfo();                ASSERT(di != NULL);                ASSERT(di->tree_item == ti);                item = di->list_index;                m_ctlItemTree.SelectItem(ti); // So that OnEdit gets the right one            } else {                // right-click was on a group (NODE)                m_ctlItemTree.SelectItem(ti);                 if (menu.LoadMenu(IDR_POPGROUP)) {                    CMenu* pPopup = menu.GetSubMenu(0);                    ASSERT(pPopup != NULL);                    m_TreeViewGroup = CMyString(m_ctlItemTree.GetGroup(ti));                    pPopup->TrackPopupMenu(dwTrackPopupFlags, point.x, point.y, this); // use this window for commands                }            }        } else {            // not over anything            if (menu.LoadMenu(IDR_POPTREE)) {                CMenu* pPopup = menu.GetSubMenu(0);                ASSERT(pPopup != NULL);                pPopup->TrackPopupMenu(dwTrackPopupFlags, point.x, point.y, this); // use this window for commands            }        }        m_ctlItemTree.SetFocus();    } // tree view handling

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -