Back to index

lightning-sunbird  0.9+nobinonly
RegMozCtlDlg.cpp
Go to the documentation of this file.
00001 // RegMozCtlDlg.cpp : implementation file
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "RegMozCtl.h"
00006 #include "RegMozCtlDlg.h"
00007 
00008 #ifdef _DEBUG
00009 #define new DEBUG_NEW
00010 #undef THIS_FILE
00011 static char THIS_FILE[] = __FILE__;
00012 #endif
00013 
00015 // CRegMozCtlDlg dialog
00016 
00017 CRegMozCtlDlg::CRegMozCtlDlg(CWnd* pParent /*=NULL*/)
00018        : CDialog(CRegMozCtlDlg::IDD, pParent)
00019 {
00020        //{{AFX_DATA_INIT(CRegMozCtlDlg)
00021        m_szMozillaDir = _T("");
00022        //}}AFX_DATA_INIT
00023        // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
00024        m_hIcon = AfxGetApp()->LoadIcon(IDI_MOZILLA);
00025 
00026        GetCurrentDirectory(1024, m_szMozillaDir.GetBuffer(1024));
00027        m_szMozillaDir.ReleaseBuffer();
00028 }
00029 
00030 void CRegMozCtlDlg::DoDataExchange(CDataExchange* pDX)
00031 {
00032        CDialog::DoDataExchange(pDX);
00033        //{{AFX_DATA_MAP(CRegMozCtlDlg)
00034        DDX_Control(pDX, IDC_TASKLIST, m_cTaskList);
00035        DDX_Text(pDX, IDC_MOZILLADIR, m_szMozillaDir);
00036        //}}AFX_DATA_MAP
00037 }
00038 
00039 BEGIN_MESSAGE_MAP(CRegMozCtlDlg, CDialog)
00040        //{{AFX_MSG_MAP(CRegMozCtlDlg)
00041        ON_WM_PAINT()
00042        ON_WM_QUERYDRAGICON()
00043        ON_BN_CLICKED(IDC_REGISTER, OnRegister)
00044        ON_BN_CLICKED(IDC_UNREGISTER, OnUnregister)
00045        ON_BN_CLICKED(IDC_PICKDIR, OnPickDir)
00046        //}}AFX_MSG_MAP
00047 END_MESSAGE_MAP()
00048 
00050 // CRegMozCtlDlg message handlers
00051 
00052 BOOL CRegMozCtlDlg::OnInitDialog()
00053 {
00054        // Set the icon for this dialog.  The framework does this automatically
00055        //  when the application's main window is not a dialog
00056        SetIcon(m_hIcon, TRUE);                   // Set big icon
00057        SetIcon(m_hIcon, FALSE);           // Set small icon
00058        
00059        // Get values from the registry
00060        TCHAR szValue[1024];
00061        DWORD dwSize = sizeof(szValue) / sizeof(szValue[0]);
00062        CRegKey cKey;
00063        cKey.Create(HKEY_LOCAL_MACHINE, MOZ_CONTROL_REG_KEY);
00064        
00065        memset(szValue, 0, sizeof(szValue));
00066        if (cKey.QueryValue(szValue, MOZ_CONTROL_REG_VALUE_BIN_DIR_PATH, &dwSize) == ERROR_SUCCESS)
00067        {
00068               m_szMozillaDir = CString(szValue);
00069        }
00070 
00071     CDialog::OnInitDialog();
00072 
00073     CRegTask::PopulateTasks(m_cTaskMgr);
00074 
00075        // Add icons to image list
00076 //     m_cImageList.Create(16, 16, ILC_MASK, 0, 5);
00077 //     m_cImageList.Add(AfxGetApp()->LoadIcon(IDI_DOESNTCONTAINIE));
00078 //     m_cImageList.Add(AfxGetApp()->LoadIcon(IDI_CONTAINSIE));
00079 //     m_cImageList.Add(AfxGetApp()->LoadIcon(IDI_CONTAINSMOZILLA));
00080 //     m_cImageList.Add(AfxGetApp()->LoadIcon(IDI_UNKNOWNSTATUS));
00081 
00082        // Associate image list with file list
00083 //     m_cFileList.SetImageList(&m_cImageList, LVSIL_SMALL);
00084 
00085        struct ColumnData
00086        {
00087               TCHAR *sColumnTitle;
00088               int nPercentageWidth;
00089               int nFormat;
00090        };
00091 
00092        ColumnData aColData[] =
00093        {
00094               { _T("Task"), 70, LVCFMT_LEFT },
00095               { _T("Status"),      30, LVCFMT_LEFT }
00096        };
00097 
00098        // Get the size of the file list control and neatly
00099        // divide it into columns
00100 
00101        CRect rcList;
00102        m_cTaskList.GetClientRect(&rcList);
00103 
00104        int nColTotal = sizeof(aColData) / sizeof(aColData[0]);
00105        int nWidthRemaining = rcList.Width();
00106        
00107        for (int nCol = 0; nCol < nColTotal; nCol++)
00108        {
00109               ColumnData *pData = &aColData[nCol];
00110 
00111               int nColWidth = (rcList.Width() * pData->nPercentageWidth) / 100;
00112               if (nCol == nColTotal - 1)
00113               {
00114                      nColWidth = nWidthRemaining;
00115               }
00116               else if (nColWidth > nWidthRemaining)
00117               {
00118                      nColWidth = nWidthRemaining;
00119               }
00120 
00121               m_cTaskList.InsertColumn(nCol, pData->sColumnTitle, pData->nFormat, nColWidth);
00122 
00123               nWidthRemaining -= nColWidth;
00124               if (nColWidth <= 0)
00125               {
00126                      break;
00127               }
00128        }
00129 
00130     for (int i = 0; i < m_cTaskMgr.GetTaskCount(); i++)
00131     {
00132         CRegTask *pTask = m_cTaskMgr.GetTask(i);
00133         m_cTaskList.InsertItem(i, pTask->GetDescription());
00134     }
00135 
00136        return TRUE;  // return TRUE  unless you set the focus to a control
00137 }
00138 
00139 // If you add a minimize button to your dialog, you will need the code below
00140 //  to draw the icon.  For MFC applications using the document/view model,
00141 //  this is automatically done for you by the framework.
00142 
00143 void CRegMozCtlDlg::OnPaint() 
00144 {
00145        if (IsIconic())
00146        {
00147               CPaintDC dc(this); // device context for painting
00148 
00149               SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);
00150 
00151               // Center icon in client rectangle
00152               int cxIcon = GetSystemMetrics(SM_CXICON);
00153               int cyIcon = GetSystemMetrics(SM_CYICON);
00154               CRect rect;
00155               GetClientRect(&rect);
00156               int x = (rect.Width() - cxIcon + 1) / 2;
00157               int y = (rect.Height() - cyIcon + 1) / 2;
00158 
00159               // Draw the icon
00160               dc.DrawIcon(x, y, m_hIcon);
00161        }
00162        else
00163        {
00164               CDialog::OnPaint();
00165        }
00166 }
00167 
00168 // The system calls this to obtain the cursor to display while the user drags
00169 //  the minimized window.
00170 HCURSOR CRegMozCtlDlg::OnQueryDragIcon()
00171 {
00172        return (HCURSOR) m_hIcon;
00173 }
00174 
00175 void CRegMozCtlDlg::OnRegister() 
00176 {
00177        RegisterMozillaControl(TRUE);
00178 }
00179 
00180 void CRegMozCtlDlg::OnUnregister() 
00181 {
00182        RegisterMozillaControl(FALSE);
00183 }
00184 
00185 void CRegMozCtlDlg::RegisterMozillaControl(BOOL bRegister)
00186 {
00187        UpdateData();
00188 
00189     m_cTaskMgr.SetValue(c_szValueBinDirPath, m_szMozillaDir);
00190 
00191     for (int i = 0; i < m_cTaskMgr.GetTaskCount(); i++)
00192     {
00193         CRegTask *pTask = m_cTaskMgr.GetTask(i);
00194         pTask->DoTask();
00195     }
00196 
00197     AfxMessageBox(bRegister ? _T("Register completed") : _T("Unregister completed"));
00198 }
00199 
00200 void CRegMozCtlDlg::OnPickDir() 
00201 {
00202        BROWSEINFO bi;
00203        TCHAR szFolder[MAX_PATH + 1];
00204 
00205        memset(szFolder, 0, sizeof(szFolder));
00206 
00207        memset(&bi, 0, sizeof(bi));
00208        bi.hwndOwner = GetSafeHwnd();
00209        bi.pidlRoot = NULL;
00210        bi.pszDisplayName = szFolder;
00211        bi.lpszTitle = _T("Pick a folder to scan");
00212 
00213        // Open the folder browser dialog
00214        LPITEMIDLIST pItemList = SHBrowseForFolder(&bi);
00215        if (pItemList)
00216        {
00217               IMalloc *pShellAllocator = NULL;
00218               
00219               SHGetMalloc(&pShellAllocator);
00220               if (pShellAllocator)
00221               {
00222                      char szPath[MAX_PATH + 1];
00223 
00224                      if (SHGetPathFromIDList(pItemList, szPath))
00225                      {
00226                             // Chop off the end path separator
00227                             int nPathSize = strlen(szPath);
00228                             if (nPathSize > 0)
00229                             {
00230                                    if (szPath[nPathSize - 1] == '\\')
00231                                    {
00232                                           szPath[nPathSize - 1] = '\0';
00233                                    }
00234                             }
00235 
00236                             m_szMozillaDir = CString(szPath);
00237 
00238                             UpdateData(FALSE);
00239                      }
00240 
00241                      pShellAllocator->Free(pItemList);
00242                      pShellAllocator->Release();
00243               }
00244        }
00245 }
00246 
00247 
00248 CString CRegMozCtlDlg::GetSystemPath()
00249 {
00250        // TODO
00251        return _T("");
00252 }
00253 
00254 BOOL CRegMozCtlDlg::SetSystemPath(const CString &szNewPath)
00255 {
00256        // TODO
00257        return TRUE;
00258 }