home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / winfe / edtrcdll / src / imgcnvdl.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  7.3 KB  |  276 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. /* imgcnvdl.cpp*/
  20. /* new dialog box class derived from Troy Chevalier's CDialog class*/
  21.  
  22. // CImageConversionDialog.cpp : implementation file
  23. //
  24.  
  25. #include "stdafx.h"
  26. #include "edtrcdll.h"//to get g_instance
  27. #include "platform.h"
  28. #include "edtdlgs.h"
  29. #include "imgcnvdl.h"
  30. #include <assert.h>
  31. #include "windowsx.h"
  32. #include "xp_help.h"
  33.  
  34. int LOADDS 
  35. CImageConversionDialog::DoModal()
  36. {
  37.     return CDialog::DoModal(m_parent);
  38. }
  39.  
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CImageConversionDialog dialog
  42.  
  43.  
  44. CImageConversionDialog::CImageConversionDialog(HWND pParent /*=NULL*/)
  45. :CDialog(g_instance,IDD_FECONVERTIMAGE),m_parent(pParent)
  46. {
  47.     m_Doutputimagetype=0;
  48.     m_Doptionarraycount=0;
  49.     m_filenamelock=FALSE;
  50.     m_listboxindex=0;
  51.     m_wfeiface=NULL;
  52. }
  53.  
  54. void
  55. CImageConversionDialog::setListBoxChange(int p_index)
  56. {
  57.     if (checkLock())
  58.         return;//someone has modified the filename by hand do NOT TOUCH
  59.     if ((p_index<0)||(p_index>=(int)m_Doptionarraycount))
  60.     {
  61.         assert(FALSE);
  62.         return;
  63.     }
  64.     attachExtention(m_outfilevalue,m_Doptionarray[p_index].m_pfileextention);
  65. }
  66.  
  67.  
  68. void
  69. CImageConversionDialog::attachExtention(CString &p_string,const CString &p_ext)
  70. {
  71.     CString t_string(p_string);
  72.     int t_index=t_string.ReverseFind('.');
  73.     if ((t_index>0)&&((t_string.GetLength()-t_index)<5))//trying to avoid file names of c:\fred.stuff\hi
  74.     {
  75.         t_string=t_string.Mid(0,t_index);
  76.         p_string=t_string;
  77.     }
  78.     p_string+='.';
  79.     p_string+=p_ext;
  80.  
  81. }
  82.  
  83. BOOL
  84. CImageConversionDialog::OnCommand(int id, HWND hwndCtl, UINT notifyCode)
  85. {
  86.     CString t_teststring;
  87.     if (id==IDC_NETHELP)
  88.     {
  89.         if (m_wfeiface)
  90.             m_wfeiface->WinHelp(HELP_IMAGE_CONVERSION);
  91.     }
  92.  
  93.     switch (notifyCode)
  94.     {
  95.     case LBN_SELCHANGE:
  96.         {
  97.         DoTransfer(TRUE);
  98.         setListBoxChange(m_listboxindex);
  99.         DoTransfer(FALSE);
  100.         return TRUE;
  101.         break;
  102.         }
  103.     case EN_CHANGE :
  104.         {
  105.             DoTransfer(TRUE);
  106.             if (m_listboxindex<0) //too early
  107.                 return TRUE;
  108.             attachExtention(m_oldstring,m_Doptionarray[m_listboxindex].m_pfileextention);
  109.             if (strcmp(m_oldstring,m_outfilevalue)) //if non 0 returns then it is different!
  110.                 m_filenamelock=TRUE;
  111.             else
  112.                 m_filenamelock=FALSE;
  113.             return TRUE;
  114.         break;
  115.         }
  116.     default:
  117.         break;
  118.     }
  119.     return CDialog::OnCommand(id, hwndCtl,notifyCode);
  120. }
  121.  
  122. BOOL
  123. CImageConversionDialog::DoTransfer(BOOL bSaveAndValidate)
  124. {
  125.     EditFieldTransfer(IDC_OUTFILE,m_outfilevalue,bSaveAndValidate);
  126.     ListBoxTransfer(IDC_CONVERTLIST,m_listboxindex,bSaveAndValidate);
  127.     return TRUE;//no validation
  128. }
  129.  
  130.  
  131.  
  132. /////////////////////////////////////////////////////////////////////////////
  133. // CImageConversionDialog message handlers
  134.  
  135. BOOL CImageConversionDialog::InitDialog() 
  136. {
  137.     CDialog::InitDialog();
  138.     //init listbox
  139.     HWND t_wnd;
  140.     t_wnd=GetDlgItem(m_hwndDlg,IDC_CONVERTLIST);
  141.     if(!t_wnd)
  142.         return FALSE;
  143.     CString t_string;
  144.     for (DWORD i=0;i<m_Doptionarraycount;i++)
  145.     {
  146.         t_string=m_Doptionarray[i].m_pencodername;
  147.         t_string+=" (.";
  148.         t_string+=m_Doptionarray[i].m_pfileextention;
  149.         t_string+=')';
  150.         if (m_Doptionarray[i].m_builtin)
  151.             t_string+=" (Built-in)";
  152.         else 
  153.             t_string+=" (Plug-in)";
  154.         ListBox_AddString(t_wnd,t_string);
  155.     }
  156.     ListBox_SetCurSel(t_wnd,m_Doutputimagetype);
  157.     // TODO: Add extra initialization here
  158.     m_outfilevalue=m_Doutfilename1;
  159.     m_oldstring=m_outfilevalue;//initialize m_oldstring to be the same so m_filenamelock remains false BEFORE you put on the extention!
  160.     SetFocus(t_wnd);//set focus on the listbox
  161.     setListBoxChange(m_Doutputimagetype);
  162.     DoTransfer(FALSE);
  163.     return TRUE;  // return TRUE unless you set the focus to a control
  164.                   // EXCEPTION: OCX Property Pages should return FALSE
  165. }
  166.  
  167. void CImageConversionDialog::OnOK() 
  168. {
  169.     // TODO: Add extra validation here
  170.     DoTransfer(TRUE);
  171.     m_Doutfilename1=m_outfilevalue;
  172.  
  173.     HWND t_wnd;
  174.     t_wnd=GetDlgItem(m_hwndDlg,IDC_CONVERTLIST);
  175.     m_Doutputimagetype=ListBox_GetCurSel(t_wnd);
  176.     assert(LB_ERR!=m_Doutputimagetype);
  177.     EndDialog(m_hwndDlg,IDOK);
  178. }
  179.  
  180. void CImageConversionDialog::OnCancel() 
  181. {
  182.     // TODO: Add extra cleanup here
  183.     
  184.     EndDialog(m_hwndDlg,IDCANCEL);
  185. }
  186.  
  187.  
  188. void LOADDS 
  189. CImageConversionDialog::setOutputFileName1(const char *p_string)
  190. {
  191.     m_Doutfilename1=p_string;
  192. }
  193.  
  194.  
  195. //////////////////////////////////////////////////////
  196. //JPEG OPTIONS DIALOG
  197. //////////////////////////////////////////////////////
  198.  
  199.  
  200. #define J_LOWQUALITY 25
  201. #define J_MEDQUALITY 75
  202. #define J_HIGHQUALITY 100
  203.  
  204. int LOADDS 
  205. CJpegOptionsDialog::DoModal()
  206. {
  207.     return CDialog::DoModal(m_parent);
  208. }
  209.  
  210. /////////////////////////////////////////////////////////////////////////////
  211. // CJpegOptionsDialog dialog
  212.  
  213.  
  214. CJpegOptionsDialog::CJpegOptionsDialog(HWND pParent /*=NULL*/)
  215. :CDialog(g_instance,IDD_FEJPEGOPTIONS),m_parent(pParent)
  216. {
  217.     m_Doutputquality=0;
  218. }
  219.  
  220.  
  221. BOOL
  222. CJpegOptionsDialog::OnCommand(int id, HWND hwndCtl, UINT notifyCode)
  223. {
  224.     return CDialog::OnCommand(id, hwndCtl,notifyCode);
  225. }
  226.  
  227. BOOL
  228. CJpegOptionsDialog::DoTransfer(BOOL bSaveAndValidate)
  229. {
  230.     RadioButtonTransfer(IDC_QUALITY3,m_outputquality,bSaveAndValidate);
  231.     return TRUE;//no validation
  232. }
  233.  
  234.  
  235.  
  236. /////////////////////////////////////////////////////////////////////////////
  237. // CJpegOptionsDialog message handlers
  238.  
  239. BOOL CJpegOptionsDialog::InitDialog() 
  240. {
  241.     CDialog::InitDialog();
  242.     
  243.     // TODO: Add extra initialization here
  244.     m_outputquality=0;
  245.     if (m_Doutputquality<=J_LOWQUALITY)//33
  246.         m_outputquality=2;
  247.     else if (m_Doutputquality<=J_MEDQUALITY)//66
  248.         m_outputquality=1;
  249.     else 
  250.         m_outputquality=0;//100
  251.     DoTransfer(FALSE);
  252.     return TRUE;  // return TRUE unless you set the focus to a control
  253.                   // EXCEPTION: OCX Property Pages should return FALSE
  254. }
  255.  
  256. void CJpegOptionsDialog::OnOK() 
  257. {
  258.     // TODO: Add extra validation here
  259.     DoTransfer(TRUE);
  260.     if (2==m_outputquality)
  261.         m_Doutputquality=J_LOWQUALITY;
  262.     if (1==m_outputquality)
  263.         m_Doutputquality=J_MEDQUALITY;
  264.     if (0==m_outputquality)
  265.         m_Doutputquality=J_HIGHQUALITY;
  266.     EndDialog(m_hwndDlg,IDOK);
  267. }
  268.  
  269. void CJpegOptionsDialog::OnCancel() 
  270. {
  271.     // TODO: Add extra cleanup here
  272.     
  273.     EndDialog(m_hwndDlg,IDCANCEL);
  274. }
  275.  
  276.