home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / extview.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  6.6 KB  |  233 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  2.  *
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  *
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  *
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. // extview.cpp : implementation file
  20. //
  21.  
  22. #include "stdafx.h"
  23.  
  24. #include "extview.h"
  25.  
  26. #ifdef _DEBUG
  27. #undef THIS_FILE
  28. static char BASED_CODE THIS_FILE[] = __FILE__;
  29. #endif
  30.  
  31. /////////////////////////////////////////////////////////////////////////////
  32. // CExtView dialog
  33.  
  34. CExtView::CExtView(CWnd* pParent /*=NULL*/)
  35.     : CDialog(CExtView::IDD, pParent)
  36. {
  37.     //{{AFX_DATA_INIT(CExtView)
  38.     //}}AFX_DATA_INIT
  39. }
  40.  
  41. void CExtView::DoDataExchange(CDataExchange* pDX)
  42. {
  43.     CDialog::DoDataExchange(pDX);
  44.     //{{AFX_DATA_MAP(CExtView)
  45.     //}}AFX_DATA_MAP
  46. }
  47.  
  48. BEGIN_MESSAGE_MAP(CExtView, CDialog)
  49.     //{{AFX_MSG_MAP(CExtView)
  50.     ON_WM_CREATE()
  51.     ON_BN_CLICKED(IDC_AddSubType, OnClickedAddSubType)
  52.     ON_BN_CLICKED(IDC_LaunchExtViewer, OnClickedLaunchExtViewer)
  53.     ON_BN_CLICKED(IDC_SaveToDisk, OnClickedSaveToDisk)
  54.     ON_BN_CLICKED(IDC_ViewerBrowse, OnClickedViewerBrowse)
  55.     ON_LBN_SELCHANGE(IDC_MIMETYPE, OnSelchangeMimetype)
  56.     ON_LBN_SELCHANGE(IDC_MIMESUBTYPE, OnSelchangeMimesubtype)
  57.     //}}AFX_MSG_MAP
  58. END_MESSAGE_MAP()
  59.  
  60. /////////////////////////////////////////////////////////////////////////////
  61. // CExtView message handlers
  62.  
  63. int CExtView::OnCreate(LPCREATESTRUCT lpCreateStruct)
  64. {
  65.     if (CDialog::OnCreate(lpCreateStruct) == -1)
  66.         return -1;
  67.     
  68.     // TODO: Add your specialized creation code here
  69.     m_netList = cinfo_MasterListPointer();
  70.         
  71.     return 0;
  72. }
  73.  
  74. BOOL CExtView::OnInitDialog() 
  75. {
  76.     CListBox *pMimeList = (CListBox *)GetDlgItem(IDC_MIMETYPE);
  77.  
  78.     // Fill in the possible mime types...
  79.         
  80.     pMimeList->AddString("audio");
  81.     pMimeList->AddString("application");
  82.     pMimeList->AddString("image");
  83.     pMimeList->AddString("text");
  84.     pMimeList->AddString("video");
  85.  
  86.     SetMimeTypeTo("image");  // select image in the mime type box ... will set rest of box up
  87.     SetSubtypeTo("gif");
  88.     return TRUE;
  89. }
  90.  
  91. void CExtView::SetMimeTypeTo(const char * mime_type) {
  92. #ifdef NOT
  93.     CListBox *pMimeList = (CListBox *)GetDlgItem(IDC_MIMETYPE);
  94.     CListBox *pSubtypeList = (CListBox *)GetDlgItem(IDC_MIMESUBTYPE);
  95.     NET_cdataListItem *cd_item;
  96.     char * pSlash;
  97.     CEdit * pDescr = (CEdit *)GetDlgItem(IDC_Description);
  98.     CEdit * pExt = (CEdit *)GetDlgItem(IDC_Extensions);
  99.  
  100.     pMimeList->SelectString(-1,mime_type);
  101.  
  102.     pDescr->SetWindowText(""); // fill in empty description
  103.     pExt->SetWindowText("");  // set empty list
  104.  
  105.     pSubtypeList->ResetContent();
  106.     cd_item = m_netList;  // Get beginning of the list
  107.  
  108.     while (cd_item) {  // iterate through the list
  109.         if (cd_item->ci.type) {  // if it is a mime type
  110.             if (!XP_STRNCMP(cd_item->ci.type,mime_type,4)) {  // we can distinguish the mime types via the
  111.                                                            // first 2 characters but we'll compare 4 to be safe
  112.                 pSlash = XP_STRCHR(cd_item->ci.type,'//');
  113.                 if (pSlash+1) pSubtypeList->AddString(pSlash+1);
  114.             }            
  115.         }
  116.         cd_item = cd_item->next;
  117.     }
  118. #endif
  119. }
  120.  
  121. void CExtView::SetSubtypeTo(const char * sub_type) {
  122. #ifdef NOT
  123.     CListBox *pMimeList = (CListBox *)GetDlgItem(IDC_MIMETYPE);
  124.     CListBox *pSubtypeList = (CListBox *)GetDlgItem(IDC_MIMESUBTYPE);
  125.     CEdit * pDescr = (CEdit *)GetDlgItem(IDC_Description);
  126.     CEdit * pExt = (CEdit *)GetDlgItem(IDC_Extensions);
  127.     CEdit * pExtViewer = (CEdit *)GetDlgItem(IDC_ExternalViewer);
  128.     CButton *pSaveToDisk = (CButton *)GetDlgItem(IDC_SaveToDisk);
  129.  
  130.     NET_cdataListItem *cd_item;
  131.     int iSel = pMimeList->GetCurSel();
  132.     CString csMimeType;
  133.     CString csExtList;
  134.     int idx;
  135.  
  136.     if (!sub_type) return;  // something bad
  137.  
  138.     pSubtypeList->SelectString(-1,sub_type);
  139.  
  140.     pMimeList->GetText(iSel,csMimeType); // get current mime type
  141.     csMimeType+='/';  // add slash
  142.     csMimeType+=sub_type; // add subtype
  143.  
  144.     cd_item = m_netList;  // Get beginning of the list
  145.  
  146.     while (cd_item) {  // iterate through the list
  147.         if (cd_item->ci.type) {  // if it is a mime type
  148.             if (!XP_STRCMP(cd_item->ci.type,(const char *)csMimeType)) {  // is this the type??
  149.                 if (cd_item->ci.desc) 
  150.                     pDescr->SetWindowText(cd_item->ci.desc); // fill in description
  151.                 else pDescr->SetWindowText(""); // fill in empty description
  152.                 for (idx = 0; idx < cd_item->num_exts ; idx++) {
  153.                     if (idx !=0) csExtList+=','; // if not first extension, add a comma
  154.                     if (cd_item->exts[idx]) csExtList+=cd_item->exts[idx]; // if num exts is right this will always work
  155.                 }
  156.                 if (!csExtList.IsEmpty()) 
  157.                     pExt->SetWindowText((const char *)csExtList);
  158.                 else pExt->SetWindowText("");  // set emoty list
  159.                 pSaveToDisk->SetCheck(TRUE);
  160.             }
  161.         }
  162.         cd_item = cd_item->next;
  163.     }
  164.  
  165. #endif
  166. }
  167.  
  168. void CExtView::OnClickedAddSubType()
  169. {
  170.     // TODO: Add your control notification handler code here
  171.     
  172. }
  173.  
  174. void CExtView::OnClickedLaunchExtViewer()
  175. {
  176.     // TODO: Add your control notification handler code here
  177.     
  178. }
  179.  
  180. void CExtView::OnClickedSaveToDisk()
  181. {
  182.     // TODO: Add your control notification handler code here
  183.     
  184. }
  185.  
  186. void CExtView::OnClickedViewerBrowse()
  187. {
  188.     // TODO: Add your control notification handler code here
  189.     
  190. }
  191.  
  192. void CExtView::OnCancel()
  193. {
  194.     // TODO: Add extra cleanup here
  195.     
  196.     CDialog::OnCancel();
  197. }
  198.  
  199. void CExtView::OnOK()
  200. {
  201.     // TODO: Add extra validation here
  202.     
  203.     CDialog::OnOK();
  204. }
  205.  
  206. void CExtView::OnSelchangeMimetype()
  207. {
  208.     CListBox *pMimeList = (CListBox *)GetDlgItem(IDC_MIMETYPE);
  209.  
  210.     if (!pMimeList) return;  // something REAL bad is happening!
  211.  
  212.     int iSel = pMimeList->GetCurSel();
  213.     CString csMimeType;
  214.  
  215.     pMimeList->GetText(iSel,csMimeType); // get mime type user selected     
  216.     SetMimeTypeTo(csMimeType);  // set subtypes based on mime-type    
  217. }
  218.  
  219. void CExtView::OnSelchangeMimesubtype()
  220. {
  221.     // TODO: Add your control notification handler code here
  222.     CListBox *pSubtypeList = (CListBox *)GetDlgItem(IDC_MIMESUBTYPE);
  223.  
  224.     if (!pSubtypeList) return;  // something REAL bad is happening!
  225.  
  226.     int iSel = pSubtypeList->GetCurSel();
  227.     CString csMimeSubtype;
  228.  
  229.     pSubtypeList->GetText(iSel,csMimeSubtype); // get mime subtype user selected     
  230.     SetSubtypeTo(csMimeSubtype);  // set descr/ectensions/ect
  231.     
  232. }
  233.