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

📄 notessettings.cpp

📁 funambol windows mobile plugin source code, the source code is taken from the funambol site
💻 CPP
字号:
/*
 * Copyright (C) 2003-2007 Funambol, Inc
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 2 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY, TITLE, NONINFRINGEMENT or FITNESS FOR A PARTICULAR
 * PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 * 02111-1307  USA
 */

// notes are not supported on smartphone



#include "stdafx.h"
#include "ui.h"
#include "NotesSettings.h"
#include "NotesSettingsAdvanced.h"
#include "ExploreFolders.h"

#include "comutil.h"
#include "pim/clientsettings.h"
#include "pim/Maincpp.h"
#include "tpcshell.h"



// CNotesSettings dialog

IMPLEMENT_DYNAMIC(CNotesSettings, CDialog)
#if defined(WIN32_PLATFORM_PSPC)
CNotesSettings::CNotesSettings(CWnd* pParent /*=NULL*/)
: CDialog(CNotesSettings::IDD, pParent)
{

}
#endif

CNotesSettings::~CNotesSettings()
{
}

void CNotesSettings::DoDataExchange(CDataExchange* pDX)
{
    CDialog::DoDataExchange(pDX);
#if defined(WIN32_PLATFORM_PSPC)
    DDX_Control(pDX, IDC_NOTES_SYNCTYPE, lstSyncType );
    DDX_Control(pDX, IDC_NOTES_LINK_ADVANCED, linkAdvanced);
    DDX_Control(pDX, IDC_NOTES_LINK_CHOOSE, linkChoose);
#endif

}


BEGIN_MESSAGE_MAP(CNotesSettings, CDialog)
    #if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
        ON_WM_SIZE()
    #endif
    #if defined(WIN32_PLATFORM_PSPC)
//        ON_COMMAND(ID_MENU_FOLDER, &CNotesSettings::OnMenuFolder)
        ON_BN_CLICKED(IDC_NOTES_LINK_ADVANCED, &CNotesSettings::OnBnClickedNotesLinkAdvanced)
        ON_BN_CLICKED(IDC_NOTES_LINK_CHOOSE, &CNotesSettings::OnBnClickedNotesLinkChoose)
    #endif
    ON_WM_CTLCOLOR()
END_MESSAGE_MAP()


// CNotesSettings message handlers

BOOL CNotesSettings::OnInitDialog(){
  #if defined(WIN32_PLATFORM_PSPC)
    CString s1;

    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_NOTES_SETTINGS);
    SetWindowText(s1);
    CDialog::OnInitDialog();

    ZeroMemory(&dlgCommandBar, sizeof(SHMENUBARINFO));
    dlgCommandBar.cbSize = sizeof(SHMENUBARINFO);
    dlgCommandBar.hwndParent = this->GetSafeHwnd();
    dlgCommandBar.dwFlags = SHCMBF_HMENU;
    dlgCommandBar.nToolBarId = IDM_OKCANCEL;
    dlgCommandBar.hInstRes = getLocalizationUtils()->getLocaleResource();
    dlgCommandBar.nBmpId = 0;
    dlgCommandBar.cBmpImages = 0;
    if(!SHCreateMenuBar(&dlgCommandBar)){
        TRACE(_T("Cannot create command bar!"));
        return FALSE;
    }

   // read string resources
   s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_SETTCOMM_SYNCTYPE1);	lstSyncType.AddString(s1);
   s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_SETTCOMM_SYNCTYPE2);	lstSyncType.AddString(s1);
   s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_SETTCOMM_SYNCTYPE3);	lstSyncType.AddString(s1);

    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_SYNCTYPE); SetDlgItemText(IDC_NOTES_STATIC_SYNCTYPE,s1);
    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_FOLDER_TO_SYNC); SetDlgItemText(IDC_NOTES_STATIC_FOLDERTOSYNC,s1);
    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_ADVANCED_SETTINGS); linkAdvanced.setText(s1);

    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_CHOOSE); linkChoose.setText(s1);

    // set font
    LOGFONT lf;
    memset(&lf, 0, sizeof(LOGFONT));
    HFONT hFont = (HFONT) GetStockObject(SYSTEM_FONT);
    GetObject(hFont, sizeof lf, &lf);
    lf.lfWeight = FW_BOLD;
    lf.lfHeight +=FONT_HEIGHT_OFFSET;
    VERIFY(fontBold.CreateFontIndirect(&lf));

    GetDlgItem(IDC_NOTES_STATIC_SYNCTYPE)->SetFont(&fontBold);
    GetDlgItem(IDC_NOTES_STATIC_FOLDERTOSYNC)->SetFont(&fontBold);

    // set ppc header
    #if defined(WIN32_PLATFORM_PSPC)
        s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_NOTES_SETTINGS); SetDlgItemText(IDC_HEADER_STATIC, s1);
        GetDlgItem(IDC_HEADER_STATIC)->SetFont(&fontBold);
    #endif

    // read from the registry
    WindowsSyncSourceConfig* ssconf = getRegConfig()->getWinSyncSourceConfig("note");
    CString s3; int pos=0;

    pos = SynctypeReg2UI(ssconf->getSync());
	lstSyncType.SetCurSel(pos);

    #if defined(WIN32_PLATFORM_WFSP)
		// override back key
		LPARAM lparam = MAKELPARAM(SHMBOF_NODEFAULT | SHMBOF_NOTIFY,
			SHMBOF_NODEFAULT | SHMBOF_NOTIFY);
		::SendMessage(dlgCommandBar3, SHCMBM_OVERRIDEKEY, VK_TBACK, lparam);
    #endif

    s3 = ssconf->getSyncDir().c_str();
    if (s3 == "") {
        // default
        LPTSTR dir= new WCHAR[256];
        SHGetSpecialFolderPath(NULL, dir, CSIDL_PERSONAL, FALSE);
        s3 = CString(dir);
        s3+="\\notes";
        delete [] dir;
    }

    folder = s3;
    SetDlgItemText(IDC_NOTES_STATIC_FOLDER,s3);

    lstSyncType.SetFocus();
  #endif

  return FALSE;  // set focus to listbox
}


void CNotesSettings::OnOK()
{
   #if defined(WIN32_PLATFORM_PSPC)
    USES_CONVERSION;
    WindowsSyncSourceConfig* ssconf = getRegConfig()->getWinSyncSourceConfig("note");
    CString s1; int pos=0;
    _bstr_t bst;
    BOOL dirtyFlag = FALSE;

    if(checkStartSync()){
        CDialog::OnOK();
    };

    // save values in registry
    pos = lstSyncType.GetCurSel();
    if(strcmp(ssconf->getSync(), SynctypeUI2Reg(pos)) != 0){
        ssconf->setSync(SynctypeUI2Reg(pos));
        dirtyFlag = TRUE;
    }

    if(folder == _T("")) {
        folder = ssconf->getSyncDir().c_str();
    }
    bst = folder.AllocSysString();
    if(strcmp(T2A(folder), ssconf->getSyncDir().c_str()) != 0){
        ssconf->setSyncDir(T2A(folder));
        dirtyFlag = TRUE;
    }
    // bst.Detach();

    if(dirtyFlag){
        getRegConfig()->setDirty(CS_DIRTY_SOURCE_NOTES);
        getRegConfig()->saveDirty();
    }

    CDialog::OnOK();
 #endif
}

void CNotesSettings::OnMenuFolder()
{
  #if defined(WIN32_PLATFORM_PSPC)
    CExploreFolders wndExplore;
    wndExplore.setIsNotes(true);
    wndExplore.setFolder(folder);

    INT_PTR result = wndExplore.DoModal();
    if (result == IDCHOOSE)
    {
        // user has chosen a new folder
        CString folderToSync = wndExplore.getFolder();
        CString s1("");
        //s1.LoadString(IDS_FOLDER_TO_SYNC);
        s1+=folderToSync;
        this->folder = folderToSync;
        SetDlgItemText(IDC_NOTES_STATIC_FOLDER, s1);
    }
  #endif
}


#if defined(_DEVICE_RESOLUTION_AWARE) && !defined(WIN32_PLATFORM_WFSP)
void CNotesSettings::OnSize(UINT /*nType*/, int /*cx*/, int /*cy*/)
{
    int resId;
    switch(DRA::GetDisplayMode())
    {
    case DRA::Landscape:
        resId = IDD_UI_NOTES_WIDE; break;
    case DRA::Portrait:
        resId = IDD_UI_NOTES; break;
    case DRA::Square:
        resId = IDD_UI_NOTES_SQUARE; break;
    default:
        resId = IDD_UI_NOTES; break;
    };

    DRA::RelayoutDialog( AfxGetInstanceHandle(), this->m_hWnd, MAKEINTRESOURCE(resId));

    // restore label values
    CString s1;

    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_SYNCTYPE); SetDlgItemText(IDC_NOTES_STATIC_SYNCTYPE,s1);
    s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_FOLDER_TO_SYNC); SetDlgItemText(IDC_NOTES_STATIC_FOLDERTOSYNC,s1);

    // set ppc header
    #if defined(WIN32_PLATFORM_PSPC)
        s1.LoadString(getLocalizationUtils()->getLocaleResource(), IDS_NOTES_SETTINGS); SetDlgItemText(IDC_HEADER_STATIC, s1);
    #endif

    s1 = folder;
    SetDlgItemText(IDC_NOTES_STATIC_FOLDER,s1);
}
#endif


void CNotesSettings::OnBnClickedNotesLinkAdvanced(){
  #if defined(WIN32_PLATFORM_PSPC)
    CNotesSettingsAdvanced wndNotesAdvanced;

    INT_PTR result = wndNotesAdvanced.DoModal();
 #endif
}

void CNotesSettings::OnBnClickedNotesLinkChoose(){
    #if defined(WIN32_PLATFORM_PSPC)
        OnMenuFolder();
    #endif
}

HBRUSH CNotesSettings::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor) {
    HBRUSH hbr = CDialog::OnCtlColor(pDC, pWnd, nCtlColor);

    // set ppc header text color
    #if defined(WIN32_PLATFORM_PSPC)
    if(pWnd->GetDlgCtrlID() == IDC_HEADER_STATIC) {
        pDC->SetBkMode(TRANSPARENT);
        pDC->SetTextColor(PPC_HEADER_TEXT_COLOR);
    }
    #endif

    return hbr;
}

⌨️ 快捷键说明

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