?? mainfrm.cpp.svn-base
字號:
case ArticleView:
if (m_wndArticleView.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE;
if (m_wndBanner.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE;
if (m_wndEnclosureBar.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE;
if (m_wndInfoBar.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo)) return TRUE;
break;
}
if (m_wndUpdateBar.OnCmdMsg(nID, nCode, pExtra, pHandlerInfo))
return TRUE;
// otherwise, do default handling
return CFrameWnd::OnCmdMsg(nID, nCode, pExtra, pHandlerInfo);
}
BOOL CMainFrame::DestroyWindow() {
LOG0(1, "CMainFrame::DestroyWindow()");
Downloader.Terminate();
if (m_wndUpdateBar.IsUpdating())
m_wndUpdateBar.OnStop();
// wait for saving thread to terminate
if (SiteList.GetCount() > 0) {
AddSiteToSave(Config.ActSiteIdx);
if (HSaveSitesThread != NULL)
WaitForSingleObject(HSaveSitesThread, INFINITE);
}
SetEvent(HTerminate);
if (HPreloadThread != NULL) WaitForSingleObject(HPreloadThread, INFINITE);
if (HSyncItemsThread != NULL) WaitForSingleObject(HSyncItemsThread, INFINITE);
prssrNotificationRemove();
//
Config.SaveUI();
return CFrameWnd::DestroyWindow();
}
void CMainFrame::SwitchToView(CWnd *pOldActiveView, CWnd *pNewView) {
int nSwitchChildID = pNewView->GetDlgCtrlID();
pNewView->SetDlgCtrlID(AFX_IDW_PANE_FIRST);
pOldActiveView->SetDlgCtrlID(nSwitchChildID);
// Show the newly active view and hide the inactive view.
pNewView->ShowWindow(SW_SHOW);
pOldActiveView->ShowWindow(SW_HIDE);
// Connect the newly active view to the document,
// and disconnect the inactive view
// SetActiveView(pNewView);
RecalcLayout();
}
void CMainFrame::SetupSummaryView() {
View = SummaryView;
Config.MainView = MAIN_VIEW_SUMMARY_VIEW;
ShowControlBar(&m_wndTopBar, FALSE, FALSE);
m_wndTopBar.EnableSortButton(FALSE);
// hide article view controls
ShowControlBar(&m_wndBanner, FALSE, FALSE);
ShowControlBar(&m_wndEnclosureBar, FALSE, FALSE);
ShowControlBar(&m_wndInfoBar, FALSE, FALSE);
// menu bar
BOOL fSuccess;
SHMENUBARINFO mbi = { 0 };
mbi.cbSize = sizeof(mbi);
mbi.dwFlags = SHCMBF_HMENU;
mbi.nToolBarId = IDR_SUMMARYVIEW;
mbi.hInstRes = AfxGetInstanceHandle();
mbi.hwndParent = GetSafeHwnd();
fSuccess = SHCreateMenuBar(&mbi);
::DestroyWindow(m_hwndCmdBar);
m_hwndCmdBar = mbi.hwndMB;
}
void CMainFrame::SetupFeedView() {
View = FeedView;
Config.MainView = MAIN_VIEW_FEED_LIST;
ShowControlBar(&m_wndTopBar, TRUE, FALSE);
m_wndTopBar.EnableSortButton();
UpdateSort();
// hide article view controls
ShowControlBar(&m_wndBanner, FALSE, FALSE);
ShowControlBar(&m_wndEnclosureBar, FALSE, FALSE);
ShowControlBar(&m_wndInfoBar, FALSE, FALSE);
// menu bar
BOOL fSuccess;
SHMENUBARINFO mbi = { 0 };
mbi.cbSize = sizeof(mbi);
mbi.dwFlags = SHCMBF_HMENU;
mbi.nToolBarId = IDR_MAINFRAME;
mbi.hInstRes = AfxGetInstanceHandle();
mbi.hwndParent = GetSafeHwnd();
fSuccess = SHCreateMenuBar(&mbi);
::DestroyWindow(m_hwndCmdBar);
m_hwndCmdBar = mbi.hwndMB;
// modify menu for flagged folder
if (Config.ActSiteIdx == SITE_FLAGGED) {
TBBUTTON tb;
::SendMessage(m_hwndCmdBar, TB_GETBUTTON, 1, (LPARAM) &tb);
HMENU hMenu = (HMENU) tb.dwData;
CString sText;
sText.LoadString(IDS_MARK_ALL_UNFLAGGED);
::InsertMenu(hMenu, 1, MF_STRING | MF_ENABLED | MF_BYPOSITION, ID_TOOLS_MAKRASUNFLAGGED, sText);
}
}
void CMainFrame::SetupArticleView() {
View = ArticleView;
Config.MainView = MAIN_VIEW_ARTICLE;
ShowControlBar(&m_wndTopBar, FALSE, FALSE);
m_wndTopBar.EnableSortButton(FALSE);
// show article view controls
ShowControlBar(&m_wndBanner, TRUE, FALSE);
ShowControlBar(&m_wndEnclosureBar, FALSE, FALSE); // initially hidden
ShowControlBar(&m_wndInfoBar, FALSE, FALSE); // initially hidden
// menu bar
BOOL fSuccess;
SHMENUBARINFO mbi = { 0 };
mbi.cbSize = sizeof(mbi);
mbi.dwFlags = SHCMBF_HMENU;
mbi.nToolBarId = IDR_ARTICLE;
mbi.hInstRes = AfxGetInstanceHandle();
mbi.hwndParent = GetSafeHwnd();
fSuccess = SHCreateMenuBar(&mbi);
::DestroyWindow(m_hwndCmdBar);
m_hwndCmdBar = mbi.hwndMB;
}
void CMainFrame::SwitchView(EView view) {
if (View == view)
return;
switch (view) {
case SummaryView:
SwitchToView(&m_wndFeedView, &m_wndSummaryView);
SetupSummaryView();
m_wndSummaryView.SetFocus();
break;
case FeedView:
if (View == ArticleView)
SwitchToView(&m_wndArticleView, &m_wndFeedView);
else
SwitchToView(&m_wndSummaryView, &m_wndFeedView);
SetupFeedView();
m_wndFeedView.SetFocus();
break;
case ArticleView:
SwitchToView(&m_wndFeedView, &m_wndArticleView);
SetupArticleView();
m_wndArticleView.SetFocus();
break;
}
Config.SaveUI();
}
///
void CMainFrame::OnSize(UINT nType, int cx, int cy) {
LOG3(1, "CMainFrame::OnSize(%d, %d, %d)", nType, cx, cy);
CFrameWnd::OnSize(nType, cx, cy);
}
LRESULT CMainFrame::OnHibernate(WPARAM wParam, LPARAM lParam) {
// TODO: save session to XML file
return 0;
}
BOOL CMainFrame::CheckCachePresence() {
LOG0(3, "CMainFrame::CheckCachePresence()");
if (DirectoryExists(Config.CacheLocation))
return TRUE;
else
return FALSE;
}
void CMainFrame::LoadSites() {
LOG0(1, "CMainFrame::LoadSites()");
m_wndTopBar.EnableWindow(FALSE);
CWaitCursor wait;
Loading = TRUE;
SetTopBarText(IDS_LOADING, TOPBAR_IMAGE_LOADING);
LoadSiteList(SiteList);
// int ret = LoadSiteList();
// LOG1(1, "LoadSiteList() = %d", ret);
// load favicons
m_ilIcons.SetImageCount(TOPBAR_IMAGE_COUNT + SiteList.GetCount());
for (int i = 0; i < SiteList.GetCount(); i++) {
CSiteItem *si = SiteList.GetAt(i);
LoadFaviconForSite(i, si);
}
// insert items to summary view
m_wndSummaryView.SetImageList(&m_ilIcons);
m_wndSummaryView.SetRedraw(FALSE);
m_wndSummaryView.InsertSites(&SiteList);
m_wndSummaryView.SetRedraw(TRUE);
m_wndSummaryView.Invalidate();
//
if (SiteList.GetCount() > 0) {
// ActSiteIdx is out out the range -> activate the summary view
if (Config.ActSiteIdx < -2 || Config.ActSiteIdx >= SiteList.GetCount()) {
Config.ActSiteIdx = 0;
SwitchView(SummaryView);
}
else {
CSiteItem *si;
if (Config.ActSiteIdx == SITE_UNREAD) si = &UnreadItems;
else if (Config.ActSiteIdx == SITE_FLAGGED) si = &FlaggedItems;
else si = SiteList.GetAt(Config.ActSiteIdx);
if (View == FeedView || View == ArticleView) {
if (Config.ActSiteIdx >= -2 && Config.ActSiteIdx < SiteList.GetCount()) {
SelectSite(Config.ActSiteIdx);
PreloadSite(Config.ActSiteIdx);
}
else {
// TODO: switch to summary view
}
}
if (View == ArticleView) {
if (si->Feed != NULL) {
// CString s;
// s.Format(_T("%d/%d"), Config.ActFeedItem, si->Feed->GetItemCount());
// s.Format(_T("%d/%d"), Config.ActFeedItem, 10);
// AfxMessageBox(s);
// LOG2(1, "%d, %p", Config.ActFeedItem, si);
if (Config.ActFeedItem >= 0 && Config.ActFeedItem < si->Feed->GetItemCount()) {
m_wndFeedView.OpenItem(si->Feed->GetItem(Config.ActFeedItem));
}
else {
// switch to feed view
SwitchView(FeedView);
SelectSite(Config.ActSiteIdx);
}
}
}
}
}
Loading = FALSE;
m_wndTopBar.EnableWindow();
UpdateTopBar();
// to update command bar
PostMessage(WM_CANCELMODE);
if (!CheckCachePresence())
m_wndUpdateBar.ShowError(IDS_CACHE_NOT_AVAILABLE);
}
//
void CMainFrame::SetTopBarText(UINT nID, int nIconIdx) {
LOG2(5, "CMainFrame::SetTopBarText(%d, %d)", nID, nIconIdx);
CString strText;
strText.LoadString(nID);
SetTopBarText(strText, nIconIdx);
}
void CMainFrame::SetTopBarText(const CString &strText, int nIconIdx) {
LOG2(5, "CMainFrame::SetTopBarText(%S, %d)", strText, nIconIdx);
m_wndTopBar.SetText(strText);
m_wndTopBar.SetImageIdx(nIconIdx);
m_wndTopBar.Invalidate();
m_wndTopBar.UpdateWindow();
}
void CMainFrame::UpdateTopBar() {
LOG0(5, "CMainFrame::UpdateTopBar()");
if (SiteList.GetRoot()->GetCount() == 0) {
}
else {
if (View == FeedView) {
// update site label
if (Config.ActSiteIdx >= 0 && Config.ActSiteIdx < SiteList.GetCount()) {
CSiteItem *si = SiteList.GetAt(Config.ActSiteIdx);
int unreadCount = si->GetUnreadCount();
CDC *pDC = GetDC();
CString strTitle = GetNumberItemText(pDC, si->Name, unreadCount, GetSystemMetrics(SM_CXSCREEN) - CX_ICON);
ReleaseDC(pDC);
if (si->Status == CSiteItem::Ok)
SetTopBarText(strTitle, si->ImageIdx);
else
SetTopBarText(strTitle, TOPBAR_IMAGE_ERROR);
}
else if (Config.ActSiteIdx == SITE_UNREAD) {
SetTopBarText(GetUnreadItem(), TOPBAR_IMAGE_FOLDER);
}
else if (Config.ActSiteIdx == SITE_FLAGGED) {
SetTopBarText(GetFlaggedItem(), TOPBAR_IMAGE_FOLDER);
}
}
}
}
void CMainFrame::OnTopBarClick(NMHDR* pNMHDR, LRESULT* pResult) {
LOG0(3, "CMainFrame::OnTopBarClick()");
NMTOOLBAR *ntb = (NMTOOLBAR *) pNMHDR;
if (ntb->iItem == IDC_ACT_SITE) {
OnOpenSiteList();
}
else if (ntb->iItem == IDC_SORT_BUTTON) {
OnSortChange();
}
*pResult = 0;
}
void CMainFrame::FillMenuWithSites(HMENU hMenu, CSiteList *siteList, CSiteItem *parent) {
LOG1(5, "CMainFrame::FillMenuWithSites( , , %p)", parent);
if (parent == NULL)
return;
if (parent->Type == CSiteItem::Site) {
int siteIdx = siteList->GetIndexOf(parent);
int unreadCount = parent->GetUnreadCount();
CDC *pDC = GetDC();
CString strSiteTitle = GetNumberItemText(pDC, parent->Name, unreadCount, GetSystemMetrics(SM_CXSCREEN) - CX_ICON);
ReleaseDC(pDC);
AppendMenu(hMenu, MF_ENABLED | MF_STRING, ID_MENU_SITE_BASE + siteIdx, strSiteTitle);
if (View == FeedView && Config.ActSiteIdx == siteIdx) {
CheckMenuRadioItem(hMenu, ID_MENU_SITE_BASE, ID_MENU_SITE_BASE + 1000, ID_MENU_SITE_BASE + siteIdx, MF_BYCOMMAND);
}
}
else {
HMENU hSubMenu = CreatePopupMenu();
if (parent->SubItems.GetCount() > 0) {
POSITION pos = parent->SubItems.GetHeadPosition();
while (pos != NULL) {
CSiteItem *si = parent->SubItems.GetNext(pos);
FillMenuWithSites(hSubMenu, siteList, si);
}
}
else {
// empty group
CString sEmpty;
sEmpty.LoadString(IDS_EMPTY);
AppendMenu(hSubMenu, MF_GRAYED | MF_STRING, -1, sEmpty);
}
CDC *pDC = GetDC();
int unreadCount = parent->GetUnreadCount();
CString strGroupTitle = GetNumberItemText(pDC, parent->Name, unreadCount, GetSystemMetrics(SM_CXSCREEN) - CX_ICON);
ReleaseDC(pDC);
AppendMenu(hMenu, MF_POPUP, (UINT) hSubMenu, strGroupTitle);
}
}
CString CMainFrame::GetUnreadItem() {
CSiteItem *root = SiteList.GetRoot();
int unreadCount = root->GetUnreadCount();
CString strUnread;
strUnread.LoadString(IDS_UNREAD);
CDC *pDC = GetDC();
CString str = GetNumberItemText(pDC, strUnread, unreadCount, GetSystemMetrics(SM_CXSCREEN) - CX_ICON);
ReleaseDC(pDC);
return str;
}
CString CMainFrame::GetFlaggedItem() {
CSiteItem *root = SiteList.GetRoot();
int flaggedCount = root->GetFlaggedCount();
CString strFlagged;
strFlagged.LoadString(IDS_FLAGGED);
CDC *pDC = GetDC();
CString str = GetNumberItemText(pDC, strFlagged, flaggedCount, GetSystemMetrics(SM_CXSCREEN) - CX_ICON);
ReleaseDC(pDC);
return str;
}
void CMainFrame::OnOpenSiteList() {
LOG0(3, "CMainFrame::OnOpenSiteList()");
if (SiteList.GetCount() > 0) {
// close other possibly opened menu
ReleaseCapture();
SendMessage(WM_CANCELMODE);
SiteMenuOpened = TRUE;
HMENU hMenu = CreatePopupMenu();
CSiteItem *root = SiteList.GetRoot();
// root->ReadItemCountsFromCache();
FillMenuWithSites(hMenu, &SiteList, root);
HMENU hRootMenu = GetSubMenu(hMenu, 0);
int siteCount = SiteList.GetCount();
::AppendMenu(hRootMenu, MF_SEPARATOR, -1, NULL);
::AppendMenu(hRootMenu, MF_ENABLED | MF_STRING, ID_MENU_SITE_BASE + SITE_UNREAD, GetUnreadItem());
::AppendMenu(hRootMenu, MF_ENABLED | MF_STRING, ID_MENU_SITE_BASE + SITE_FLAGGED, GetFlaggedItem());
if (View == FeedView && (Config.ActSiteIdx == SITE_UNREAD || Config.ActSiteIdx == SITE_FLAGGED)) {
CheckMenuRadioItem(hRootMenu, ID_MENU_SITE_BASE - 2, ID_MENU_SITE_BASE + 1000, ID_MENU_SITE_BASE + Config.ActSiteIdx, MF_BYCOMMAND);
}
CRect rcItem;
m_wndTopBar.GetWindowRect(&rcItem);
TrackPopupMenuEx(hRootMenu, TPM_RIGHTALIGN, rcItem.left, rcItem.bottom - 1, GetSafeHwnd(), NULL);
SiteMenuOpened = FALSE;
DestroyMenu(hMenu);
}
else {
// no sites in list, start Site Manager
OnToolsSiteManager();
}
}
void CMainFrame::OnSiteSelected(UINT nID) {
LOG0(3, "CMainFrame::OnSiteSelected()");
int nSite = nID - ID_MENU_SITE_BASE;
if (Config.ActSiteIdx != nSite)
AddSiteToSave(Config.ActSiteIdx);
if (View == SummaryView) {
Config.ActSiteIdx = nSite;
SwitchView(FeedView);
SelectSite(nSite);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -