home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / cmd / macfe / prefs / CAssortedMediators.cp next >
Encoding:
Text File  |  1998-04-08  |  90.7 KB  |  3,535 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. #include "CAssortedMediators.h"
  20.  
  21.  
  22. extern "C"
  23. {
  24. #include "xp_help.h"
  25. }
  26.  
  27. #include "prefapi.h"
  28. #ifdef MOZ_MAIL_NEWS
  29. #include "CMailNewsContext.h"
  30. #endif
  31. #include "CBrowserWindow.h"
  32. #include "CBrowserContext.h"
  33. #include "InternetConfig.h"
  34. #ifdef MOZ_MAIL_NEWS
  35. #include "CMessageFolder.h"
  36. #endif
  37. #include "UGraphicGizmos.h"
  38. #include "CToolTipAttachment.h"
  39. #include "CValidEditField.h"
  40.  
  41. #include "MPreference.h"
  42. #include "PrefControls.h"
  43.  
  44. //#include "prefwutil.h"
  45. #include "glhist.h"
  46. #include "proto.h"
  47. //#include "meditdlg.h"
  48. #include "macgui.h"
  49. #include "resgui.h"
  50. #include "ufilemgr.h"
  51. #include "uerrmgr.h"
  52. #include "libi18n.h"
  53. #include "abdefn.h"
  54. #include "addrbook.h"
  55.  
  56. #include "np.h"
  57. #include "uapp.h"
  58.  
  59. #include "macutil.h"
  60.  
  61. #include "CSizePopup.h"
  62.  
  63. #include <Sound.h>
  64. #include <UModalDialogs.h>
  65. #include <UNewTextDrawing.h>
  66. #include <LTextColumn.h>
  67. #include <UDrawingUtils.h>
  68. #include <UGAColorRamp.h>
  69. #include <LControl.h>
  70.  
  71.  
  72. #include <LGADialogBox.h>
  73. #include <LGACheckbox.h>
  74. #include <LGARadioButton.h>
  75.  
  76. //#include <QAP_Assist.h>
  77.  
  78.  
  79. //#include <ICAPI.h>
  80. //#include <ICKeys.h>
  81. #include <UCursor.h>
  82. #ifdef MOZ_MAIL_NEWS
  83. #define DEFAULT_NEWS_SERVER_KLUDGE
  84. #ifdef DEFAULT_NEWS_SERVER_KLUDGE
  85.     #include "CMailNewsContext.h"
  86.     #include "CMailProgressWindow.h"
  87. #endif
  88. #endif // MOZ_MAIL_NEWS
  89.  
  90. #pragma mark ---CMIMEListPane---
  91. //======================================
  92. class CMIMEListPane : public LTable, public LCommander, public LBroadcaster
  93. //======================================
  94. {
  95. public:
  96.  
  97.     enum
  98.     {
  99.         class_ID = 'MmLP',
  100.         msg_SelectionChanged = 'Sel╞',    // ioparam = this
  101.         msg_DoubleClick = '2Clk'        // ioparam = this
  102.     };
  103.  
  104.     class PrefCellInfo
  105.     {
  106.         public:
  107.                     PrefCellInfo();
  108.                     PrefCellInfo(CMimeMapper* mapper, CApplicationIconInfo* iconInfo); 
  109.  
  110.         CMimeMapper*    fMapper;            // The mapper from the preference MIME list
  111.         CApplicationIconInfo* fIconInfo;    // Information about icon to draw
  112.     };
  113.  
  114.     // ÑÑ Constructors/destructors/access
  115.  
  116.                         CMIMEListPane(LStream *inStream);
  117.     void                FinishCreateSelf();
  118.     void                 BindCellToApplication(TableIndexT row, CMimeMapper * mapper);
  119.     CApplicationIconInfo* GetAppInfo(CMimeMapper* mapper);
  120.     
  121.     // ÑÑ access
  122. //#if defined(QAP_BUILD)
  123. //    virtual void            QapGetContents(PWCINFO pwc, short *pCount, short max);
  124. //    virtual void            QapGetListInfo(PQAPLISTINFO pInfo);
  125. //    virtual short            QapGetListContents(Ptr pBuf, short index);
  126. //#endif    
  127.  
  128. //    void                SetContainer( CPrefHelpersContain* container) { fContainer = container; }
  129.     void                GetCellInfo(PrefCellInfo& cellInfo, int row);
  130.     void                FreeMappers();
  131.     Boolean                MimeTypeExists(CMimeMapper* mapper);
  132.  
  133.     // ÑÑ Cell selection
  134.     void                DrawCell( const TableCellT& inCell );
  135.     void                SelectCell( const TableCellT& inCell );
  136.     virtual    void        ClickCell(    const TableCellT& inCell,
  137.                                     const SMouseDownEvent& inMouseDown);
  138.  
  139.     // Drawing
  140.     virtual void        DrawSelf();
  141.     virtual void        HiliteCell(const TableCellT &inCell);
  142.     virtual void        UnhiliteCell(const TableCellT &inCell);
  143.             void         ScrollCellIntoFrame(const TableCellT& inCell);
  144.     virtual    void        ActivateSelf();
  145.  
  146.     // Events
  147.     virtual Boolean        HandleKeyPress(const EventRecord &inKeyEvent);
  148.  
  149. protected:
  150.     CApplicationList            mApplList;        // List of application and their icons
  151. //    CPrefHelpersContain*        fContainer;        // Containing view
  152.     Handle                        mNetscapeIcon;    // Icon for Netscape
  153.     Handle                        mPluginIcon;    // Icon for plug-ins
  154. }; // class CMIMEListPane
  155.  
  156.  
  157. #define msg_LaunchRadio        300        // Launch option changed
  158. #define msg_BrowseApp        301        // Pick a new application
  159. #define msg_FileTypePopup     302        // New file type picked
  160. //msg_EditField                        // User typed in a field
  161. #define msg_NewMimeType        303        // New Mime type
  162. #define msg_NewMimeTypeOK    305        // Sent by newMimeType dialog window
  163. //#define msg_ClearCell        306
  164. #define msg_EditMimeType    307        // Edit Mime type
  165. #define msg_DeleteMimeType    308        // Delete Mime type
  166. #define msg_PluginPopup        309        // Pick a plug-in
  167.  
  168. //-----------------------------------
  169. CMIMEListPane::CMIMEListPane(LStream *inStream)
  170. //-----------------------------------
  171. :
  172. //fContainer(nil),
  173. mNetscapeIcon(nil),
  174. mPluginIcon(nil),
  175. LTable(inStream)
  176. {
  177. }
  178.  
  179. //-----------------------------------
  180. void CMIMEListPane::FinishCreateSelf()
  181. //-----------------------------------
  182. {
  183.     SetCellDataSize(sizeof(PrefCellInfo));
  184.     
  185.     for (TableIndexT i = 1; i <= CPrefs::sMimeTypes.GetCount(); i++)    // Insert a row for each mime type
  186.     {
  187.         CMimeMapper * mime;
  188.         CPrefs::sMimeTypes.FetchItemAt(i, &mime);
  189.         ThrowIfNil_(mime);
  190.         if (!mime->IsTemporary())
  191.         {
  192.             CMimeMapper * duplicate = new CMimeMapper(*mime);
  193.             PrefCellInfo cellInfo;
  194.             InsertRows(1, i, &cellInfo);
  195.             BindCellToApplication(i, duplicate);
  196.         }
  197.     }
  198.     
  199.     // Cache a handle to the Navigator application icon
  200.     CApplicationIconInfo* netscapeInfo = mApplList.GetAppInfo(emSignature);
  201.     ThrowIfNil_(netscapeInfo);
  202.     ThrowIfNil_(netscapeInfo->fDocumentIcons);
  203.     mNetscapeIcon = netscapeInfo->fApplicationIcon;
  204.     
  205.     // Cache a handle to the standard plug-in icon
  206.     LArrayIterator iterator(*(netscapeInfo->fDocumentIcons));
  207.     CFileType* fileInfo;
  208.     while (iterator.Next(&fileInfo))
  209.     {
  210.         if (fileInfo->fIconSig == emPluginFile)    
  211.         {
  212.             mPluginIcon = fileInfo->fIcon;
  213.             break;    
  214.         }
  215.     }
  216.  
  217.     LTable::FinishCreateSelf();
  218.  
  219.     // Set latent subcommander of supercommander of supercommander, which is the
  220.     // view that contains the scroller of this table, to table
  221. //    if( GetSuperCommander()->GetSuperCommander() )
  222. //        (GetSuperCommander()->GetSuperCommander())->SetLatentSub(this);
  223.     LCommander::SwitchTarget(this);
  224. }
  225.  
  226.  
  227. CApplicationIconInfo* CMIMEListPane::GetAppInfo(CMimeMapper* mapper)
  228. {
  229.     return mApplList.GetAppInfo(mapper->GetAppSig(), mapper);
  230. }
  231.  
  232. /*
  233. #if defined(QAP_BUILD)
  234. void
  235. CMIMEListPane::QapGetContents(PWCINFO pwc, short *pCount, short max)
  236. {
  237.     QapAddViewItem(pwc, pCount, WT_ASSIST_ITEM, WC_LIST_BOX);
  238. }
  239.  
  240. void
  241. CMIMEListPane::QapGetListInfo(PQAPLISTINFO pInfo)
  242. {
  243.     TableIndexT        outRows, outCols;
  244.     ControlHandle    ctlHandle;
  245.     LScroller        *scroller;
  246.     LStdControl        *VSBar;
  247.     ControlHandle    ctlhVSBar;
  248.     
  249.     if (pInfo == nil)
  250.         return;
  251.         
  252.     scroller     = (LScroller *)((this->GetSuperView())->GetSuperView())->FindPaneByID(12501);
  253.     VSBar        = scroller->GetVScrollbar();
  254.     ctlhVSBar    = VSBar->GetMacControl();
  255.         
  256.     GetTableSize(outRows, outCols);
  257.     
  258.     pInfo->itemCount    = (short)outRows;
  259.     pInfo->topIndex     = (mFrameLocation.v - mImageLocation.v) / mRowHeight;
  260.     pInfo->itemHeight     = mRowHeight;
  261.     pInfo->visibleCount = 8;
  262.     pInfo->vScroll         = nil;
  263.     pInfo->isMultiSel     = false;
  264.     pInfo->isExtendSel     = false;
  265.     pInfo->hasText         = true;
  266. }
  267.  
  268. short
  269. CMIMEListPane::QapGetListContents(Ptr pBuf, short index)
  270. {
  271.     TableCellT        sTblCell, currentCell;
  272.     PrefCellInfo    theData;
  273.     Ptr                pLimit;
  274.     char             str[256];
  275.     short            count = 0, len = 0;
  276.     Uint32            uiSize;
  277.  
  278.     pLimit = pBuf + *(long *)pBuf;
  279.  
  280.     switch (index)
  281.         {
  282.         case QAP_INDEX_ALL:
  283.             sTblCell.row = 1;
  284.             sTblCell.col = 1;
  285.             do
  286.             {
  287.                 GetCellData(sTblCell, (void *)&theData);
  288.                 
  289.                 CStr255 description = theData.fMapper->GetDescription();
  290.                 if (description.IsEmpty())
  291.                     description = theData.fMapper->GetMimeName();
  292.             
  293.                 if (pBuf + 3 >= pLimit)
  294.                     break;
  295.                 
  296.                 count++;
  297.  
  298.                 *(unsigned short *)pBuf = sTblCell.row - 1;
  299.  
  300.                 GetSelectedCell(currentCell);
  301.                 
  302.                 if (currentCell.row == sTblCell.row)
  303.                     *(unsigned short *)pBuf |= 0x8000;
  304.  
  305.                 pBuf += sizeof(short);
  306.         
  307.                 strcpy(str, (char *)description);
  308.                 len = strlen(str) + 1;
  309.     
  310.                 if (pBuf + len >= pLimit)
  311.                     break;
  312.         
  313.                 strcpy(pBuf, str);
  314.                 pBuf += len;
  315.                 sTblCell.row++;
  316.             }
  317.             while (sTblCell.row <= mRows);
  318.             
  319.             break;
  320.             
  321.         case QAP_INDEX_SELECTED:
  322.             GetSelectedCell(sTblCell);
  323.             if (sTblCell.row <= mRows)
  324.             {
  325.                 GetCellData(sTblCell, (void *)&theData);
  326.             
  327.                 CStr255 description = theData.fMapper->GetDescription();
  328.                 if (description.IsEmpty())
  329.                     description = theData.fMapper->GetMimeName();
  330.             
  331.                 if (pBuf + 3 >= pLimit)
  332.                     break;
  333.                 
  334.                 count++;
  335.  
  336.                 *(unsigned short *)pBuf = (sTblCell.row - 1) | 0x8000;
  337.  
  338.                 pBuf += sizeof(short);
  339.         
  340.                 strcpy(str, (char *)description);
  341.                 len = strlen(str) + 1;
  342.     
  343.                 if (pBuf + len >= pLimit)
  344.                     break;
  345.         
  346.                 strcpy(pBuf, str);
  347.                 pBuf += len;
  348.             }
  349.             break;
  350.             
  351.         default:
  352.             sTblCell.row = index + 1;
  353.             sTblCell.col = 1;
  354.             
  355.             if (sTblCell.row <= mRows)
  356.             {
  357.                 GetCellData(sTblCell, (void *)&theData);
  358.                 
  359.                 CStr255 description = theData.fMapper->GetDescription();
  360.                 if (description.IsEmpty())
  361.                     description = theData.fMapper->GetMimeName();
  362.                 
  363.                 if (pBuf + 3 >= pLimit)
  364.                     break;
  365.                     
  366.                 count++;
  367.  
  368.                 *(unsigned short *)pBuf = sTblCell.row - 1;
  369.  
  370.  
  371.                 GetSelectedCell(currentCell);
  372.                     
  373.                 if (currentCell.row == sTblCell.row)
  374.                     *(unsigned short *)pBuf |= 0x8000;
  375.  
  376.  
  377.                 pBuf += sizeof(short);
  378.         
  379.                 strcpy(str, (char *)description);
  380.                 len = strlen(str) + 1;
  381.         
  382.                 if (pBuf + len >= pLimit)
  383.                     break;
  384.             
  385.                 strcpy(pBuf, str);
  386.             }
  387.             break;
  388.         }
  389.     return count;
  390. }
  391. #endif
  392. */
  393.  
  394. // Sets cell data to values of the mapper
  395. void
  396. CMIMEListPane::BindCellToApplication(TableIndexT row, CMimeMapper* mapper)
  397. {
  398.     CApplicationIconInfo* appInfo = GetAppInfo(mapper);
  399.     
  400.     // Now figure out the extensions from the netlib
  401.     PrefCellInfo cellInfo(mapper, appInfo);
  402.     TableCellT cell;
  403.     cell.row = row;
  404.     cell.col = 1;
  405.     SetCellData(cell, &cellInfo);
  406. }
  407.  
  408. void
  409. CMIMEListPane::ActivateSelf()
  410. {
  411.     if (triState_On == mVisible)
  412.     {
  413.         LTable::ActivateSelf();
  414.     }
  415. }
  416.  
  417.  
  418. void
  419. CMIMEListPane::DrawSelf()
  420. {
  421.     RgnHandle localUpdateRgnH = GetLocalUpdateRgn();
  422.     Rect updateRect = (**localUpdateRgnH).rgnBBox;
  423.     DisposeRgn(localUpdateRgnH);
  424.     
  425.     {
  426.         StColorState saveTheColor;
  427.         RGBColor white = { 0xFFFF, 0xFFFF, 0xFFFF};
  428.         RGBBackColor(&white);
  429.         EraseRect(&updateRect);
  430.     }
  431.     
  432.     LTable::DrawSelf();
  433. }
  434.  
  435.  
  436. void CMIMEListPane::HiliteCell(const TableCellT &inCell)
  437. {
  438.     if (triState_On == mVisible)
  439.     {
  440.         StColorState saveTheColor;
  441.         RGBColor white = { 0xFFFF, 0xFFFF, 0xFFFF};
  442.         RGBBackColor(&white);
  443.     
  444.         LTable::HiliteCell(inCell);
  445.     }
  446. }
  447.  
  448.  
  449. void CMIMEListPane::UnhiliteCell(const TableCellT &inCell)
  450. {
  451.     if (triState_On == mVisible)
  452.     {
  453.         StColorState saveTheColor;
  454.         RGBColor white = { 0xFFFF, 0xFFFF, 0xFFFF};
  455.         RGBBackColor(&white);
  456.     
  457.         LTable::UnhiliteCell(inCell);
  458.     }
  459. }
  460.  
  461.  
  462.  
  463. #define offsetTable            7
  464. #define offsetTextTop        15
  465. #define offsetMimeType        (offsetTable + 0)
  466. #define offsetIcon            (offsetTable + 166)
  467. #define offsetHandler        (offsetIcon + 24)
  468. #define widthMimeType        (offsetIcon - offsetMimeType - 5)
  469.  
  470. void CMIMEListPane::DrawCell(const TableCellT    &inCell)
  471. {
  472.     Rect cellFrame;
  473.     
  474.     if (FetchLocalCellFrame(inCell, cellFrame))
  475.     {
  476.         ::PenPat( &(UQDGlobals::GetQDGlobals()->gray) );
  477.         ::MoveTo(cellFrame.left, cellFrame.bottom-1);
  478.         ::LineTo(cellFrame.right, cellFrame.bottom-1);
  479.         ::PenPat( &(UQDGlobals::GetQDGlobals()->black) );
  480.         
  481.         PrefCellInfo cellInfo;
  482.         GetCellData(inCell, &cellInfo);
  483.         UTextTraits::SetPortTextTraits(10000);    // HACK
  484.         
  485.         // Draw mime type
  486.         CStr255 description = cellInfo.fMapper->GetDescription();
  487.         if (description.IsEmpty())
  488.             description = cellInfo.fMapper->GetMimeName();
  489.         short result = ::TruncString(widthMimeType, description, smTruncMiddle);
  490.         ::MoveTo(offsetMimeType, cellFrame.top+offsetTextTop);
  491.         ::DrawString(description);
  492.             
  493.         // Draw the icon
  494.         CMimeMapper::LoadAction loadAction = cellInfo.fMapper->GetLoadAction();
  495.         if (loadAction == CMimeMapper::Launch || loadAction == CMimeMapper::Plugin || loadAction == CMimeMapper::Internal)
  496.         {
  497.             Rect r;
  498.             r.left = offsetIcon;
  499.             r.top = cellFrame.top + 2;
  500.             r.right = r.left + 16;
  501.             r.bottom = r.top + 16;
  502.             
  503.             Handle iconHandle;
  504.             if (loadAction == CMimeMapper::Plugin)
  505.                 iconHandle = mPluginIcon;
  506.             else if (loadAction == CMimeMapper::Internal)
  507.                 iconHandle = mNetscapeIcon;
  508.             else
  509.                 iconHandle = cellInfo.fIconInfo->fApplicationIcon;
  510.             XP_ASSERT(iconHandle);
  511.             
  512.             if (iconHandle)
  513.             {
  514.                 if (loadAction == CMimeMapper::Launch && !(cellInfo.fIconInfo->fApplicationFound))
  515.                     ::PlotIconSuite(&r, atHorizontalCenter, ttDisabled, iconHandle);
  516.                 else
  517.                     ::PlotIconSuite(&r, atHorizontalCenter, ttNone, iconHandle);
  518.             }
  519.         }
  520.             
  521.         // Draw the handler name
  522.         ::MoveTo(offsetHandler, cellFrame.top+offsetTextTop);
  523.         switch (loadAction)
  524.         {
  525.             case CMimeMapper::Save:
  526.                 ::DrawString(*GetString(SAVE_RESID));
  527.                 break;
  528.             case CMimeMapper::Unknown:
  529.                 ::DrawString(*GetString(UNKNOWN_RESID));
  530.                 break;
  531.             case CMimeMapper::Internal:
  532.                 ::DrawString(*GetString(INTERNAL_RESID));
  533.                 break;
  534.             case CMimeMapper::Launch:
  535.                 ::DrawString(cellInfo.fMapper->GetAppName());
  536.                 break;
  537.             case CMimeMapper::Plugin:
  538.                 ::DrawString(cellInfo.fMapper->GetPluginName());
  539.                 break;
  540.         }
  541.     }
  542. }
  543.  
  544.  
  545. // Returns PrefCellInfo for the given cell
  546. void CMIMEListPane::GetCellInfo(PrefCellInfo& cellInfo, int row)
  547. {
  548.     TableCellT    cell;
  549.     cell.row = row;
  550.     cell.col = 1;
  551.     GetCellData(cell, &cellInfo);
  552. }
  553.  
  554. void CMIMEListPane::FreeMappers()
  555. {
  556.     TableCellT    cell;
  557.     cell.col = 1;
  558.     PrefCellInfo cellInfo;
  559.     for (int i=1; i<= mRows; i++)
  560.     {
  561.         cell.row = i;
  562.         GetCellData(cell, &cellInfo);
  563.         delete cellInfo.fMapper;
  564.     }
  565. }
  566.  
  567. Boolean CMIMEListPane::MimeTypeExists(CMimeMapper* mapper)
  568. {
  569.     TableCellT    cell;
  570.     cell.col = 1;
  571.     PrefCellInfo cellInfo;
  572.     for (int i=1; i<= mRows; i++)
  573.     {
  574.         cell.row = i;
  575.         GetCellData(cell, &cellInfo);
  576.         if (cellInfo.fMapper != mapper &&
  577.             cellInfo.fMapper->GetMimeName() == mapper->GetMimeName())
  578.             return true;
  579.     }
  580.     return false;
  581. }
  582.  
  583. //
  584. // Scroll the view as little as possible to move the specified cell
  585. // entirely within the frame.  Currently we only handle scrolling
  586. // up or down a single line (when the selection moves because of
  587. // and arrow key press).
  588. //
  589. void CMIMEListPane::ScrollCellIntoFrame(const TableCellT& inCell)
  590. {
  591.     // Compute bounds of specified cell in image coordinates
  592.     Int32 cellLeft = 0;
  593.     Int32 cellRight = 1;
  594.     Int32 cellBottom = inCell.row * mRowHeight - 2;
  595.     Int32 cellTop = cellBottom - mRowHeight + 2;
  596.  
  597.     if (ImagePointIsInFrame(cellLeft, cellTop) &&
  598.         ImagePointIsInFrame(cellRight, cellBottom))
  599.     {
  600.         return;                // Cell is already within Frame
  601.     }
  602.     else
  603.     {
  604.         if (cellTop + mImageLocation.v < mFrameLocation.v)        
  605.             ScrollImageTo(cellLeft, cellTop, true);                // Scroll up                    
  606.         else                                
  607.             ScrollPinnedImageBy(0, mRowHeight, true);            // Scroll down
  608.     }
  609. }
  610.  
  611. Boolean    CMIMEListPane::HandleKeyPress(const EventRecord &inKeyEvent)
  612. {
  613.     Char16 theChar = inKeyEvent.message & charCodeMask;
  614.     Boolean handled = false;
  615.     
  616.     TableIndexT tableRows;
  617.     TableIndexT tableCols;
  618.     TableCellT currentCell;
  619.     GetSelectedCell(currentCell);
  620.     GetTableSize(tableRows, tableCols);
  621.     
  622.     switch (theChar)
  623.     {
  624.         case char_UpArrow:
  625.             currentCell.row--;
  626.             if (currentCell.row >= 1)
  627.             {
  628.                 SelectCell(currentCell);
  629.                 ScrollCellIntoFrame(currentCell);
  630.             }
  631.             handled = true;
  632.             break;
  633.  
  634.         case char_DownArrow:
  635.             currentCell.row++;
  636.             if (currentCell.row <= tableRows)
  637.             {
  638.                 SelectCell(currentCell);
  639.                 ScrollCellIntoFrame(currentCell);
  640.             }
  641.             handled = true;
  642.             break;
  643.             
  644.         case char_PageUp:
  645.         case char_PageDown:
  646.         case char_Home:
  647.         case char_End:
  648.         default:
  649.             handled = LCommander::HandleKeyPress(inKeyEvent);
  650.     }
  651.     
  652.     return handled;
  653. }
  654.  
  655. // called by table
  656. void CMIMEListPane::SelectCell(const TableCellT &inCell)
  657. {
  658. //    fContainer->SelectCell(inCell);
  659.     LTable::SelectCell(inCell);
  660.     BroadcastMessage(msg_SelectionChanged, this);
  661. }
  662.  
  663. void
  664. CMIMEListPane::ClickCell(const TableCellT &inCell, const SMouseDownEvent& inMouseDown)
  665. {
  666.     LTable::ClickCell(inCell, inMouseDown);
  667.     if (GetClickCount() > 1)
  668.     {
  669.         BroadcastMessage(msg_DoubleClick, this);
  670.     }
  671. }
  672.  
  673.  
  674. CMIMEListPane::PrefCellInfo::PrefCellInfo(CMimeMapper * mapper, CApplicationIconInfo * iconInfo)
  675. {
  676.     fMapper = mapper; 
  677.     fIconInfo = iconInfo;
  678. }
  679.  
  680. CMIMEListPane::PrefCellInfo::PrefCellInfo()
  681. {
  682.     fMapper = NULL;
  683.     fIconInfo = NULL;
  684. }
  685.  
  686. #pragma mark ---CEditMIMEWindow---
  687. //======================================
  688. class CEditMIMEWindow : public LGADialogBox
  689. //======================================
  690. {
  691. public:
  692.     enum { class_ID = 'EMMW' };
  693.     
  694.                                 CEditMIMEWindow(LStream* inStream);
  695.     virtual                     ~CEditMIMEWindow();
  696.  
  697.     virtual void                ListenToMessage(MessageT inMessage, void* ioParam);
  698.             
  699.             void                SetCellInfo(CMIMEListPane::PrefCellInfo&);
  700.             void                SetMimeTable(CMIMEListPane* table)        { mMIMETable = table; }
  701.             CMIMEListPane::PrefCellInfo&
  702.                                 GetCellInfo()                        { return mCellInfo;   }
  703.             Boolean                Modified()                            { return mModified;   }
  704.  
  705. protected:
  706.     virtual void                FinishCreateSelf();
  707.     
  708. private:
  709.             void                SyncAllControls();
  710.             void                SyncTextControls();
  711.             void                SyncRadioControlValues();
  712.             void                SyncInternalControl();
  713.             void                SyncApplicationControls(Boolean mimeTypeChanged);
  714.             void                SyncPluginControls(Boolean mimeTypeChanged);
  715.             void                BuildPluginMenu();
  716.             void                BuildPluginList();
  717.             void                DeletePluginList();
  718.             void                BuildFileTypeMenu();
  719.  
  720.             Boolean                mInitialized;        // Initialized with fCellInfo yet?
  721.             Boolean                mModified;            // Have any MIMEs been modified?
  722.             CMIMEListPane        *mMIMETable;            // Scrolling table of MIME types
  723.             CMIMEListPane::PrefCellInfo
  724.                                 mCellInfo;            // Data for selected item
  725.             char**                mPluginList;        // Null-terminated array of plug-in names
  726.             uint32                mPluginCount;        // Number of plug-ins in array
  727.  
  728.             LGAPopup            *mFileTypePopup;
  729.             LGAPopup            *mPluginPopup;
  730.             CGAEditBroadcaster    *mDescriptionEditField;
  731.             CGAEditBroadcaster    *mTypeEditField;
  732.             CGAEditBroadcaster    *mExtensionEditField;
  733.             LGARadioButton        *mRadioSave;
  734.             LGARadioButton        *mRadioLaunch;
  735.             LGARadioButton        *mRadioInternal;
  736.             LGARadioButton        *mRadioUnknown;
  737.             LGARadioButton        *mRadioPlugin;
  738. //            CFilePicker            *mAppPicker;
  739.             LCaption            *mAppName;
  740.             LButton                *mAppButton;
  741. //            LCaption            *mAppMenuLabel;
  742. }; // class CEditMIMEWindow
  743. enum
  744. {
  745.     eNormalTextTraits = 12003,
  746.     eGrayTextTraits = 12008,
  747.     eDescriptionField = 12507,
  748.     eMIMETypeField,
  749.     eSuffixes,
  750.     eCommunicatorRButton,
  751.     ePluginRButton,
  752.     ePluginPopupMenu,
  753.     eApplicationRButton,
  754.     eApplicationNameCaption,
  755.     eChooseApplicationButton,
  756.     eFileTypePopupMenu,
  757.     eSaveRButton,
  758.     eUnknownRButton
  759. };
  760.  
  761. //-----------------------------------
  762. CEditMIMEWindow::CEditMIMEWindow(LStream* inStream):
  763. //-----------------------------------
  764.     LGADialogBox(inStream),
  765.     mMIMETable(nil),
  766.     mModified(false),
  767.     mInitialized(false),
  768.     mPluginList(nil),
  769.     mPluginCount(0)
  770. {
  771. }
  772.  
  773.  
  774. //-----------------------------------
  775. CEditMIMEWindow::~CEditMIMEWindow()
  776. //-----------------------------------
  777. {
  778.     DeletePluginList();
  779. }
  780.  
  781.  
  782. // ---------------------------------------------------------------------------
  783. // CEditMIMEWindow::FinishCreateSelf:
  784. // Fiddle around with a few of our subviews once they've been created.
  785. // ---------------------------------------------------------------------------
  786. void CEditMIMEWindow::FinishCreateSelf()
  787. {
  788.     // Cache pointers to all the controls
  789.     mFileTypePopup = (LGAPopup *)FindPaneByID(eFileTypePopupMenu);
  790.     XP_ASSERT(mFileTypePopup);
  791.  
  792.     mPluginPopup = (LGAPopup *)FindPaneByID(ePluginPopupMenu);
  793.     XP_ASSERT(mPluginPopup);
  794.  
  795.     mDescriptionEditField = (CGAEditBroadcaster *)FindPaneByID(eDescriptionField);
  796.     XP_ASSERT(mDescriptionEditField);
  797.  
  798.     mTypeEditField = (CGAEditBroadcaster *)FindPaneByID(eMIMETypeField);
  799.     XP_ASSERT(mTypeEditField);
  800.  
  801.     mExtensionEditField = (CGAEditBroadcaster *)FindPaneByID(eSuffixes);
  802.     XP_ASSERT(mExtensionEditField);
  803.  
  804.     mRadioSave = (LGARadioButton *)FindPaneByID(eSaveRButton);
  805.     XP_ASSERT(mRadioSave);
  806.  
  807.     mRadioLaunch = (LGARadioButton *)FindPaneByID(eApplicationRButton);
  808.     XP_ASSERT(mRadioLaunch);
  809.  
  810.     mRadioInternal = (LGARadioButton *)FindPaneByID(eCommunicatorRButton);
  811.     XP_ASSERT(mRadioInternal);
  812.  
  813.     mRadioUnknown = (LGARadioButton *)FindPaneByID(eUnknownRButton);
  814.     XP_ASSERT(mRadioUnknown);
  815.  
  816.     mRadioPlugin = (LGARadioButton *)FindPaneByID(ePluginRButton);
  817.     XP_ASSERT(mRadioPlugin);
  818.  
  819. //    mAppPicker = (CFilePicker *)FindPaneByID(eApplicationFilePicker);
  820. //    XP_ASSERT(mAppPicker);
  821.  
  822.     mAppName = (LCaption *)FindPaneByID(eApplicationNameCaption);        
  823.     XP_ASSERT(mAppName);
  824.  
  825.     mAppButton = (LButton *)FindPaneByID(eChooseApplicationButton); 
  826.     XP_ASSERT(mAppButton);
  827.  
  828. //    mAppMenuLabel = (LCaption *)FindPaneByID(pref8AppMenuLabel);
  829. //    XP_ASSERT(mAppMenuLabel);
  830.  
  831.     // Text fields cannot become broadcasters automatically because
  832.     // LinkListenerToControls expects fields to be descendants of LControl
  833.     // C++ vtable gets messed up
  834.     mDescriptionEditField->AddListener(this);
  835.     mTypeEditField->AddListener(this);
  836.     mExtensionEditField->AddListener(this);
  837.  
  838.     LGADialogBox::FinishCreateSelf();
  839. }
  840.  
  841.  
  842.  
  843. // ---------------------------------------------------------------------------
  844. // CEditMIMEWindow::SetCellInfo:
  845. // After the CPrefHelpersContain creates us it calls this method to provide
  846. // us with the info for the selected cell, which we copy.  We can then 
  847. // synchronize our controls to the data they display.
  848. // ---------------------------------------------------------------------------
  849. void CEditMIMEWindow::SetCellInfo(CMIMEListPane::PrefCellInfo& cellInfo)
  850. {
  851.     mCellInfo = cellInfo;
  852.     SyncAllControls();
  853.     mInitialized = true;
  854. }
  855.  
  856.  
  857. // ---------------------------------------------------------------------------
  858. // CEditMIMEWindow::DeletePluginList:
  859. // Delete the list of plug-ins.
  860. // ---------------------------------------------------------------------------
  861. void CEditMIMEWindow::DeletePluginList()
  862. {
  863.     if (mPluginList)
  864.     {    
  865.         uint32 index = 0;
  866.         
  867.         while (mPluginList[index++])
  868.         {
  869.             free(mPluginList[index]);
  870.         }
  871.         free(mPluginList);
  872.         mPluginList = nil;
  873.     }
  874. }
  875.  
  876.  
  877. // ---------------------------------------------------------------------------
  878. // CEditMIMEWindow::BuildPluginList:
  879. // Build a list of plug-ins for this MIME type.
  880. // ---------------------------------------------------------------------------
  881. void CEditMIMEWindow::BuildPluginList()
  882. {
  883.     // Delete the old list
  884.     DeletePluginList();
  885.     
  886.     // Get the new list from XP code
  887.     mPluginList = NPL_FindPluginsForType(mCellInfo.fMapper->GetMimeName());
  888.  
  889.     // Count how many are in the list
  890.     mPluginCount = 0;
  891.     if (mPluginList)
  892.     {
  893.         while (mPluginList[mPluginCount])
  894.             mPluginCount++;
  895.     }
  896. }
  897.  
  898.  
  899. // ---------------------------------------------------------------------------
  900. // CEditMIMEWindow::BuildPluginMenu:
  901. // Build the plug-in menu from the list of plug-ins available for the current
  902. // MIME type.  We need to redraw the popup if the plug-in list used to be non-
  903. // empty or is non-empty now.  (It's too expensive to try to detect the case
  904. // of the plug-in list getting rebuilt but still containing the same items.)
  905. // ---------------------------------------------------------------------------
  906. void CEditMIMEWindow::BuildPluginMenu()
  907. {
  908.     uint32 oldCount = mPluginCount;
  909.     
  910.     BuildPluginList();
  911.     
  912.     if (oldCount || mPluginCount)
  913.     {
  914.         SetMenuSizeForLGAPopup(mPluginPopup, mPluginCount);
  915.  
  916.         MenuHandle menuH = mPluginPopup->GetMacMenuH();
  917.         uint32 index = 0;
  918.         uint32 desiredValue = 1;        // Default desired value is first item
  919.         while (mPluginList[index])
  920.         {
  921.             SetMenuItemText(menuH, index+1, CStr255(mPluginList[index]));
  922.             ::EnableItem(menuH, index+1);
  923.             if (mCellInfo.fMapper->GetPluginName() == mPluginList[index])
  924.             {
  925.                 desiredValue = index + 1;
  926.             }
  927.             index++;
  928.         }
  929.         
  930.         //
  931.         // If the previously-selected plug-in name is in this list,
  932.         // select it; otherwise just select the first item.
  933.         // If we didn't change the control value, make sure it
  934.         // redraws since the contents of the list have changed.
  935.         //
  936.         uint32 previousValue = mPluginPopup->GetValue();
  937.         if (desiredValue != previousValue)
  938.         {
  939.             mPluginPopup->SetValue(desiredValue);
  940.         }
  941.         else
  942.         {
  943.             mPluginPopup->Refresh();
  944.         }
  945.     }
  946. }
  947.  
  948.  
  949. // ---------------------------------------------------------------------------
  950. // CEditMIMEWindow::BuildFileTypeMenu:
  951. // Build the file-type menu from the list file types in the application info.
  952. // ---------------------------------------------------------------------------
  953. void CEditMIMEWindow::BuildFileTypeMenu()
  954. {
  955.     CApplicationIconInfo* appInfo = mCellInfo.fIconInfo;
  956.     uint32 count = appInfo->GetFileTypeArraySize();
  957.     
  958.     if (count)
  959.     {
  960.         SetMenuSizeForLGAPopup(mFileTypePopup, count);
  961.  
  962.         MenuHandle menuH = mFileTypePopup->GetMacMenuH();
  963.         uint32 index;
  964.         uint32 desiredValue = 1;
  965.         for (index = 1; index <= count; index++)
  966.         {
  967.             CFileType* fileType = appInfo->GetFileType(index);
  968.             SetMenuItemText(menuH, index, CStr255(fileType->fIconSig));
  969.             if (fileType->fIconSig == mCellInfo.fMapper->GetDocType())
  970.             {
  971.                 desiredValue = index;
  972.             }
  973.         }
  974.         
  975.         //
  976.         // If the previously-selected file type is in this list,
  977.         // select it; otherwise just select the first item.
  978.         // If we didn't change the control value, make sure it
  979.         // redraws since the contents of the list have changed.
  980.         //
  981.         uint32 previousValue = mFileTypePopup->GetValue();
  982.         if (desiredValue != previousValue)
  983.         {
  984.             mFileTypePopup->SetValue(desiredValue);
  985.         }
  986.         else
  987.         {
  988.             mFileTypePopup->Refresh();
  989.         }
  990.     }
  991. }
  992.  
  993.  
  994.  
  995. // ---------------------------------------------------------------------------
  996. // CEditMIMEWindow::SyncTextControls:
  997. // Sync the edit text fields with their actual values (only called when
  998. // the window is first created).
  999. // ---------------------------------------------------------------------------
  1000. void CEditMIMEWindow::SyncTextControls()
  1001. {
  1002.     XP_ASSERT(mCellInfo.fMapper != nil);
  1003.  
  1004.     // MIME type
  1005.     CStr255 newValue = mCellInfo.fMapper->GetDescription();
  1006.     mDescriptionEditField->SetDescriptor(newValue);
  1007.  
  1008.     // MIME type
  1009.     newValue = mCellInfo.fMapper->GetMimeName();
  1010.     mTypeEditField->SetDescriptor(newValue);
  1011.     
  1012.     // Extensions
  1013.     newValue = mCellInfo.fMapper->GetExtensions();
  1014.     mExtensionEditField->SetDescriptor(newValue);
  1015. }
  1016.  
  1017.  
  1018. // ---------------------------------------------------------------------------
  1019. // CEditMIMEWindow::SyncRadioControlValues:
  1020. // Sync the radio buttons with their actual values (only called when
  1021. // the window is first created).
  1022. // ---------------------------------------------------------------------------
  1023. void CEditMIMEWindow::SyncRadioControlValues()
  1024. {
  1025.     switch (mCellInfo.fMapper->GetLoadAction())
  1026.     {
  1027.         case CMimeMapper::Save:
  1028.             if (mRadioSave->GetValue() == 0)
  1029.             {
  1030.                 mRadioSave->SetValue(1);
  1031.             }
  1032.             break;
  1033.         case CMimeMapper::Launch:
  1034.             if (mRadioLaunch->GetValue() == 0)
  1035.             {
  1036.                 mRadioLaunch->SetValue(1);
  1037.             }
  1038.             break;
  1039.         case CMimeMapper::Internal:
  1040.             if (mRadioInternal->GetValue() == 0)
  1041.             {
  1042.                 mRadioInternal->SetValue(1);
  1043.             }
  1044.             break;
  1045.         case CMimeMapper::Unknown:
  1046.             if (mRadioUnknown->GetValue() == 0)
  1047.             {
  1048.                 mRadioUnknown->SetValue(1);
  1049.             }
  1050.             break;
  1051.         case CMimeMapper::Plugin:
  1052.             if (mRadioPlugin->GetValue() == 0)
  1053.             {
  1054.                 mRadioPlugin->SetValue(1);
  1055.             }
  1056.             break;
  1057.     }
  1058. }
  1059.  
  1060.  
  1061. // ---------------------------------------------------------------------------
  1062. // CEditMIMEWindow::SyncInternalControl:
  1063. // Sync up the "Use Netscape" radio button when the MIME type changes.
  1064. // ---------------------------------------------------------------------------
  1065. void CEditMIMEWindow::SyncInternalControl()
  1066. {
  1067.     if (CMimeMapper::NetscapeCanHandle(mCellInfo.fMapper->GetMimeName()))
  1068.     {
  1069.         mRadioInternal->Enable();
  1070.     }
  1071.     else
  1072.     {
  1073.         mRadioInternal->Disable();
  1074.         if (mRadioInternal->GetValue() == 1)
  1075.         {
  1076.             mRadioInternal->SetValue(0);
  1077.             mRadioUnknown->SetValue(1);
  1078.         }
  1079.     }
  1080. }
  1081.  
  1082.  
  1083. // ---------------------------------------------------------------------------
  1084. // CEditMIMEWindow::SyncApplicationControls:
  1085. // Sync up the application-related controls when the "Use application" radio
  1086. // button changes state, etc.
  1087. // ---------------------------------------------------------------------------
  1088. void CEditMIMEWindow::SyncApplicationControls(Boolean applicationChanged)
  1089. {
  1090.     if (applicationChanged)
  1091.     {
  1092.         BuildFileTypeMenu();
  1093.     }
  1094.     Boolean enableAppControls = (mCellInfo.fMapper->GetLoadAction() == CMimeMapper::Launch);
  1095.  
  1096.     //
  1097.     // Application name
  1098.     //
  1099.     ResIDT oldTraits = mAppName->GetTextTraitsID();
  1100.     if (enableAppControls)
  1101.     {
  1102.         mAppName->SetTextTraitsID(eNormalTextTraits);            // Normal
  1103.     }
  1104.     else    
  1105.     {
  1106.         mAppName->SetTextTraitsID(eGrayTextTraits);            // Dimmed
  1107.     }
  1108.     if (applicationChanged)
  1109.     {
  1110.         mAppName->SetDescriptor(mCellInfo.fMapper->GetAppName());
  1111.     }
  1112.     else if (oldTraits != mAppName->GetTextTraitsID())
  1113.     {
  1114.         mAppName->Refresh();
  1115.     }
  1116.     //
  1117.     // Application pick button
  1118.     //
  1119.     if (enableAppControls)
  1120.     {
  1121.         mAppButton->Enable();
  1122.     }
  1123.     else
  1124.     {
  1125.         mAppButton->Disable();
  1126.     }
  1127.     //
  1128.     // Popup label
  1129.     //
  1130. //    oldTraits = mAppMenuLabel->GetTextTraitsID();
  1131. //    if (enableAppControls)
  1132. //    {
  1133. //        mAppMenuLabel->SetTextTraitsID(10000);        // Normal
  1134. //    }
  1135. //    else
  1136. //    {
  1137. //        mAppMenuLabel->SetTextTraitsID(10003);        // Dimmed
  1138. //    }
  1139. //    if (oldTraits != mAppMenuLabel->GetTextTraitsID())
  1140. //    {
  1141. //        mAppMenuLabel->Refresh();
  1142. //    }
  1143.     //
  1144.     // Popup enabled state
  1145.     //
  1146.     if (enableAppControls && mCellInfo.fIconInfo->GetFileTypeArraySize() > 0)
  1147.     {
  1148.         mFileTypePopup->Enable();
  1149.     }
  1150.     else
  1151.     {
  1152.         mFileTypePopup->Disable();
  1153.     }
  1154.     //
  1155.     // File type
  1156.     //
  1157.     if (mRadioLaunch->GetValue() == 1)
  1158.     {
  1159.         uint32 item = mFileTypePopup->GetValue();
  1160.         XP_ASSERT(item > 0);
  1161.         CFileType* fileType = mCellInfo.fIconInfo->GetFileType(item);
  1162.         if (fileType)
  1163.         {
  1164.             mCellInfo.fMapper->SetDocType(fileType->fIconSig);
  1165.         }
  1166.     }
  1167. }
  1168.  
  1169.  
  1170. // ---------------------------------------------------------------------------
  1171. // CEditMIMEWindow::SyncPluginControls:
  1172. // Sync up the plugin-related controls when the "Use plugin" radio
  1173. // button changes state or the MIME type changes.
  1174. // ---------------------------------------------------------------------------
  1175. void CEditMIMEWindow::SyncPluginControls(Boolean mimeTypeChanged)
  1176. {
  1177.     if (mimeTypeChanged)
  1178.     {
  1179.         BuildPluginMenu();
  1180.     }
  1181.     //
  1182.     // Plug-in radio button enabled state
  1183.     //
  1184.     if (mPluginCount > 0)
  1185.     {
  1186.         mRadioPlugin->Enable();
  1187.     }
  1188.     else
  1189.     {
  1190.         mRadioPlugin->Disable();
  1191.         if (mRadioPlugin->GetValue() == 1)
  1192.         {
  1193. //            mRadioPlugin->SetValue(0);
  1194.             mRadioUnknown->SetValue(1);
  1195.             mCellInfo.fMapper->SetLoadAction(CMimeMapper::Unknown);
  1196.             mModified = true;
  1197.         }
  1198.     }
  1199.  
  1200.     //
  1201.     // Plug-in popup control enabled state
  1202.     //
  1203.     CMimeMapper* mapper = mCellInfo.fMapper;
  1204.     CMimeMapper::LoadAction loadAction = mapper->GetLoadAction();
  1205.     if (loadAction == CMimeMapper::Plugin && mPluginCount > 0)
  1206. //    if (fCellInfo.fMapper->GetLoadAction() == CMimeMapper::Plugin && fPluginCount > 0)
  1207.     {
  1208.         mPluginPopup->Enable();
  1209.     }
  1210.     else
  1211.     {
  1212.         mPluginPopup->Disable();
  1213.     }    
  1214.     //
  1215.     // Plug-in name
  1216.     //
  1217.     if (mRadioPlugin->GetValue() == 1)
  1218.     {
  1219.         uint32 item = mPluginPopup->GetValue();    
  1220.         XP_ASSERT(item > 0);    
  1221.         if (mPluginList && item > 0 && item <= mPluginCount)
  1222.         {
  1223.             char* plugin = mPluginList[item - 1];        // Menu is 1-based, list is 0-based
  1224.             if (plugin)
  1225.                 mCellInfo.fMapper->SetPluginName(plugin);
  1226.         }
  1227.     }
  1228.     
  1229. }
  1230.  
  1231. //-----------------------------------
  1232. void CEditMIMEWindow::SyncAllControls()
  1233. // Set up the controls in the dialog box (before it's visible) with the
  1234. // information from the currently selected cell.
  1235. //-----------------------------------
  1236. {
  1237.     SyncTextControls();
  1238.     SyncRadioControlValues();
  1239.     SyncInternalControl();
  1240.     SyncApplicationControls(true);
  1241.     SyncPluginControls(true);
  1242. }
  1243.  
  1244.  
  1245. //-----------------------------------
  1246. void CEditMIMEWindow::ListenToMessage(MessageT inMessage, void */*ioParam*/)
  1247. // Process a message from the MIME types dialog
  1248. //-----------------------------------
  1249. {
  1250.     if (!mInitialized)
  1251.     {
  1252.         return;
  1253.     }    
  1254.     switch (inMessage)
  1255.     {
  1256.         // Pick a handler
  1257.         case eSaveRButton:
  1258.             if (mRadioSave->GetValue() == 1)
  1259.             {
  1260.                 mCellInfo.fMapper->SetLoadAction(CMimeMapper::Save);
  1261.             }
  1262.             mModified = TRUE;
  1263.             break;
  1264.         case eApplicationRButton:
  1265.             if (mRadioLaunch->GetValue() == 1)
  1266.             {
  1267.                 mCellInfo.fMapper->SetLoadAction(CMimeMapper::Launch);
  1268.             }
  1269.             SyncApplicationControls(false);
  1270.             mModified = TRUE;
  1271.             break;
  1272.         case eCommunicatorRButton:
  1273.             if (mRadioInternal->GetValue() == 1)
  1274.             {
  1275.                 mCellInfo.fMapper->SetLoadAction(CMimeMapper::Internal);
  1276.             }
  1277.             mModified = TRUE;
  1278.             break;
  1279.         case eUnknownRButton:
  1280.             if (mRadioUnknown->GetValue() == 1)
  1281.             {
  1282.                 mCellInfo.fMapper->SetLoadAction(CMimeMapper::Unknown);
  1283.             }
  1284.             mModified = TRUE;
  1285.             break;
  1286.         case ePluginRButton:
  1287.             if (mRadioPlugin->GetValue() == 1)
  1288.             {
  1289.                 mCellInfo.fMapper->SetLoadAction(CMimeMapper::Plugin);
  1290.             }
  1291.             SyncPluginControls(false);
  1292.             mModified = TRUE;
  1293.             break;
  1294.         // Pick a new application
  1295.         case eChooseApplicationButton:    
  1296.         {        
  1297.             StandardFileReply reply;
  1298.             CFilePicker::DoCustomGetFile(reply, CFilePicker::Applications, FALSE);    // Pick app
  1299.             if (reply.sfGood)
  1300.             {
  1301.                 // set mappers properties from the app
  1302.                 FInfo finderInfo;
  1303.                 OSErr err = FSpGetFInfo(&reply.sfFile, &finderInfo);    
  1304.                 mCellInfo.fMapper->SetAppSig(finderInfo.fdCreator);
  1305.                 mCellInfo.fMapper->SetAppName(reply.sfFile.name);
  1306.                 mCellInfo.fIconInfo = mMIMETable->GetAppInfo(mCellInfo.fMapper);
  1307.                 SyncApplicationControls(true);        // App changed
  1308.                 mModified = TRUE;
  1309.             }
  1310.             break;
  1311.         }
  1312.  
  1313.         // Change the file type
  1314.         case eFileTypePopupMenu:    
  1315.         {
  1316.             SyncApplicationControls(false);
  1317.             mModified = TRUE;        
  1318.             break;
  1319.         }
  1320.  
  1321.         // Change the plug-in
  1322.         case ePluginPopupMenu:
  1323.         {
  1324.             SyncPluginControls(false);
  1325.             mModified = TRUE;        
  1326.             break;
  1327.         }
  1328.  
  1329.         // Edit some text
  1330.         case msg_EditField:
  1331.         {
  1332.             CStr255 newText;
  1333.  
  1334.             // Commit description
  1335.             mDescriptionEditField->GetDescriptor(newText);
  1336.             mCellInfo.fMapper->SetDescription(newText);
  1337.             
  1338.             // Commit type
  1339.             mTypeEditField->GetDescriptor(newText);
  1340.             if (newText != mCellInfo.fMapper->GetMimeName())
  1341.             {
  1342.                 mCellInfo.fMapper->SetMimeType(newText);
  1343.                 SyncPluginControls(true);        // Plug-in choices depend on MIME type
  1344.                 SyncInternalControl();            // "Use Netscape" radio depends on MIME type
  1345.             }
  1346.             
  1347.             // Commit the extensions
  1348.             mExtensionEditField->GetDescriptor(newText);
  1349.             mCellInfo.fMapper->SetExtensions(newText);
  1350.  
  1351.             mModified = TRUE;
  1352.             break;
  1353.         }
  1354.  
  1355.         case msg_OK:
  1356.             break;
  1357.         case msg_Cancel:
  1358.             break;
  1359.         default:
  1360.             break;
  1361.     }    
  1362. }
  1363.  
  1364. #pragma mark ---CEditFieldControl---
  1365. //======================================
  1366. class CEditFieldControl : public LGAEditField
  1367. //======================================
  1368. {
  1369.     // Note: This is not derived from LControl! It has control in the
  1370.     // name because it broadcasts when the user changes its contents.
  1371.  
  1372.     public:
  1373.         enum
  1374.         {
  1375.             class_ID = 'edtC',
  1376.             msg_ChangedText = 'TxtC'
  1377.         };
  1378.         virtual                ~CEditFieldControl() {}
  1379.                             CEditFieldControl(LStream *inStream) :
  1380.                                               LGAEditField(inStream)
  1381.                                               {}
  1382.         virtual void        UserChangedText();
  1383. }; // class CEditFieldControl
  1384.  
  1385. //-----------------------------------
  1386. void CEditFieldControl::UserChangedText()
  1387. //-----------------------------------
  1388. {
  1389.     BroadcastMessage(msg_ChangedText, this);
  1390. }
  1391.  
  1392. //======================================
  1393. #pragma mark --CAppearanceMainMediator---
  1394. //======================================
  1395.  
  1396. enum
  1397. {
  1398.     eBrowserBox = 12001,
  1399.     eMailBox,
  1400.     eNewsBox,
  1401.     eEditorBox,
  1402.     eConferenceBox,
  1403.     eCalendarBox,
  1404.     eNetcasterBox,
  1405.     ePicturesAndTextRButton,
  1406.     eShowToolTipsBox,
  1407.     ePicturesOnlyRButton,
  1408.     eTextOnlyRButton,
  1409.     eDesktopPatternBox
  1410. };
  1411.  
  1412. //-----------------------------------
  1413. CAppearanceMainMediator::CAppearanceMainMediator(LStream*)
  1414. //-----------------------------------
  1415. :    CPrefsMediator(class_ID)
  1416. {
  1417. }
  1418.  
  1419. //-----------------------------------
  1420. void CAppearanceMainMediator::LoadPrefs()
  1421. //-----------------------------------
  1422. {
  1423.     const OSType kConferenceAppSig = 'Ncq╣';
  1424.     FSSpec fspec;
  1425.     if (CFileMgr::FindApplication(kConferenceAppSig, fspec) != noErr)
  1426.     {
  1427.         LGACheckbox* checkbox = (LGACheckbox *)FindPaneByID(eConferenceBox);
  1428.         XP_ASSERT(checkbox);
  1429.         checkbox->SetValue(false);
  1430.         // disable the control
  1431.         checkbox->Disable();    
  1432.     }
  1433.  
  1434.     const OSType kCalendarAppSig = 'NScl';
  1435.     if (CFileMgr::FindApplication(kCalendarAppSig, fspec) != noErr)
  1436.     {
  1437.         LGACheckbox* checkbox = (LGACheckbox *)FindPaneByID(eCalendarBox);
  1438.         XP_ASSERT(checkbox);
  1439.         checkbox->SetValue(false);
  1440.         // disable the control
  1441.         checkbox->Disable();    
  1442.     }
  1443.  
  1444.     if (!FE_IsNetcasterInstalled())
  1445.     {
  1446.         LGACheckbox* checkbox = (LGACheckbox *)FindPaneByID(eNetcasterBox);
  1447.         XP_ASSERT(checkbox);
  1448.         checkbox->SetValue(false);
  1449.         // disable the control
  1450.         checkbox->Disable();
  1451.     }
  1452. }
  1453.  
  1454. void CAppearanceMainMediator::WritePrefs()
  1455. {
  1456.     // this pref will not take effect immediately unless we tell the CToolTipAttachment
  1457.     // class to make it so
  1458.     LGACheckbox    *theBox = (LGACheckbox *)FindPaneByID(eShowToolTipsBox);
  1459.     XP_ASSERT(theBox);
  1460.     CToolTipAttachment::Enable(theBox->GetValue());
  1461. }
  1462.  
  1463. enum
  1464. {
  1465.     eCharSetMenu = 12101,
  1466.     ePropFontMenu,
  1467.     ePropSizeMenu,
  1468.     eFixedFontMenu,
  1469.     eFixedSizeMenu,
  1470.     eAlwaysOverrideRButton,
  1471.     eQuickOverrideRButton,
  1472.     eNeverOverrideRButton
  1473. };
  1474.  
  1475.  
  1476. //-----------------------------------
  1477. CAppearanceFontsMediator::CAppearanceFontsMediator(LStream*)
  1478. //-----------------------------------
  1479. :    CPrefsMediator(class_ID)
  1480. ,    mEncodings(nil)
  1481. {
  1482. }
  1483.  
  1484. int
  1485. CAppearanceFontsMediator::GetSelectEncMenuItem()
  1486. {
  1487.     LGAPopup *encMenu = (LGAPopup *)FindPaneByID(eCharSetMenu);
  1488.     XP_ASSERT(encMenu);
  1489.     return encMenu->GetValue();
  1490. }
  1491.  
  1492. void
  1493. CAppearanceFontsMediator::UpdateEncoding(PaneIDT changedMenuID)
  1494. {
  1495.     Int32    selectedEncMenuItem = GetSelectEncMenuItem();
  1496.     XP_ASSERT(selectedEncMenuItem <= mEncodingsCount);
  1497.  
  1498.     if (changedMenuID == ePropFontMenu || changedMenuID == eFixedFontMenu)
  1499.     {
  1500.         LGAPopup *changedMenu = (LGAPopup *)FindPaneByID(changedMenuID);
  1501.         XP_ASSERT(changedMenu);
  1502.         int    changedMenuValue = changedMenu->GetValue();
  1503.         CStr255    itemString;
  1504.         ::GetMenuItemText(changedMenu->GetMacMenuH(), changedMenuValue, itemString);
  1505.         if (changedMenuID == ePropFontMenu)
  1506.         {
  1507.             mEncodings[selectedEncMenuItem - 1].mPropFont = itemString;
  1508.         }
  1509.         else
  1510.         {
  1511.             mEncodings[selectedEncMenuItem - 1].mFixedFont = itemString;
  1512.         }
  1513.     }
  1514.     else if (changedMenuID == ePropSizeMenu || changedMenuID == eFixedSizeMenu)
  1515.     {
  1516.         CSizePopup *sizeMenu = (CSizePopup *)FindPaneByID(changedMenuID);
  1517.         XP_ASSERT(sizeMenu);
  1518.         if (changedMenuID == ePropSizeMenu)
  1519.         {
  1520.             mEncodings[selectedEncMenuItem - 1].mPropFontSize = sizeMenu->GetFontSize();
  1521.         }
  1522.         else
  1523.         {
  1524.             mEncodings[selectedEncMenuItem - 1].mFixedFontSize = sizeMenu->GetFontSize();
  1525.         }
  1526.     }
  1527. }
  1528.  
  1529.  
  1530. void
  1531. CAppearanceFontsMediator::UpdateMenus()
  1532. {
  1533.     Int32    selectedEncMenuItem = GetSelectEncMenuItem();
  1534.     XP_ASSERT(selectedEncMenuItem <= mEncodingsCount);
  1535.  
  1536.     CSizePopup *propSizeMenu = (CSizePopup *)FindPaneByID(ePropSizeMenu);
  1537.     XP_ASSERT(propSizeMenu);
  1538.     propSizeMenu->SetFontSize(mEncodings[selectedEncMenuItem - 1].mPropFontSize);
  1539.     if (mEncodings[selectedEncMenuItem - 1].mPropFontSizeLocked)
  1540.     {
  1541.         propSizeMenu->Disable();
  1542.     }
  1543.     else
  1544.     {
  1545.         propSizeMenu->Enable();
  1546.     }
  1547.     CSizePopup *fixedSizeMenu = (CSizePopup *)FindPaneByID(eFixedSizeMenu);
  1548.     XP_ASSERT(fixedSizeMenu);
  1549.     fixedSizeMenu->SetFontSize(mEncodings[selectedEncMenuItem - 1].mFixedFontSize);
  1550.     if (mEncodings[selectedEncMenuItem - 1].mFixedFontSizeLocked)
  1551.     {
  1552.         fixedSizeMenu->Disable();
  1553.     }
  1554.     else
  1555.     {
  1556.         fixedSizeMenu->Enable();
  1557.     }
  1558.  
  1559.     Str255    fontName;
  1560.     LGAPopup *propFontMenu = (LGAPopup *)FindPaneByID(ePropFontMenu);
  1561.     XP_ASSERT(propFontMenu);
  1562.     if (!SetLGAPopupToNamedItem(propFontMenu, mEncodings[selectedEncMenuItem - 1].mPropFont))
  1563.     {
  1564.         GetFontName(applFont, fontName);
  1565.         if (!SetLGAPopupToNamedItem(propFontMenu, fontName))
  1566.         {
  1567.             propFontMenu->SetValue(1);
  1568.         }
  1569.     }
  1570.     propSizeMenu->MarkRealFontSizes(propFontMenu);
  1571.     if (mEncodings[selectedEncMenuItem - 1].mPropFontLocked)
  1572.     {
  1573.         propFontMenu->Disable();
  1574.     }
  1575.     else
  1576.     {
  1577.         propFontMenu->Enable();
  1578.     }
  1579.  
  1580.     LGAPopup *fixedFontMenu = (LGAPopup *)FindPaneByID(eFixedFontMenu);
  1581.     XP_ASSERT(fixedFontMenu);
  1582.     if (!SetLGAPopupToNamedItem(fixedFontMenu, mEncodings[selectedEncMenuItem - 1].mFixedFont))
  1583.     {
  1584.         GetFontName(applFont, fontName);
  1585.         if (!SetLGAPopupToNamedItem(fixedFontMenu, fontName))
  1586.         {
  1587.             fixedFontMenu->SetValue(1);
  1588.         }
  1589.     }
  1590.     fixedSizeMenu->MarkRealFontSizes(fixedFontMenu);
  1591.     if (mEncodings[selectedEncMenuItem - 1].mFixedFontLocked)
  1592.     {
  1593.         fixedFontMenu->Disable();
  1594.     }
  1595.     else
  1596.     {
  1597.         fixedFontMenu->Enable();
  1598.     }
  1599. }
  1600.  
  1601.  
  1602. void
  1603. CAppearanceFontsMediator::SetEncodingWithPref(Encoding& enc)
  1604. {
  1605.     char *propFontTemplate = "intl.font%hu.prop_font";
  1606.     char *fixedFontTemplate = "intl.font%hu.fixed_font";
  1607.     char *propFontSizeTemplate = "intl.font%hu.prop_size";
  1608.     char *fixedFontSizeTemplate = "intl.font%hu.fixed_size";
  1609.     char prefBuffer[255];
  1610.     char fontNameBuffer[32];
  1611.     int    bufferLength;
  1612.     int32    fontSize;
  1613.  
  1614.     sprintf(prefBuffer, propFontTemplate, enc.mCSID);
  1615.     bufferLength = 32;
  1616.     PREF_GetCharPref(prefBuffer, fontNameBuffer, &bufferLength);
  1617.     enc.mPropFont = fontNameBuffer;
  1618.     enc.mPropFontLocked = PREF_PrefIsLocked(prefBuffer);
  1619.  
  1620.     sprintf(prefBuffer, fixedFontTemplate, enc.mCSID);
  1621.     bufferLength = 32;
  1622.     PREF_GetCharPref(prefBuffer, fontNameBuffer, &bufferLength);
  1623.     enc.mFixedFont = fontNameBuffer;
  1624.     enc.mFixedFontLocked = PREF_PrefIsLocked(prefBuffer);
  1625.  
  1626.     sprintf(prefBuffer, propFontSizeTemplate, enc.mCSID);
  1627.     PREF_GetIntPref(prefBuffer, &fontSize);
  1628.     enc.mPropFontSize = fontSize;
  1629.     enc.mPropFontSizeLocked = PREF_PrefIsLocked(prefBuffer);
  1630.  
  1631.     sprintf(prefBuffer, fixedFontSizeTemplate, enc.mCSID);
  1632.     PREF_GetIntPref(prefBuffer, &fontSize);
  1633.     enc.mFixedFontSize = fontSize;
  1634.     enc.mFixedFontSizeLocked = PREF_PrefIsLocked(prefBuffer);
  1635. }
  1636.  
  1637. void
  1638. CAppearanceFontsMediator::ReadEncodings(Handle hndl)
  1639. {
  1640.     unsigned short    numberEncodings;
  1641.     
  1642.     LHandleStream    stream(hndl);
  1643.                 
  1644.     stream.ReadData(&numberEncodings, sizeof(unsigned short));
  1645.     XP_ASSERT(numberEncodings > 0);
  1646.     mEncodingsCount = numberEncodings;
  1647.     mEncodings    = new Encoding[numberEncodings];
  1648.     XP_ASSERT(mEncodings != nil);
  1649.     for(int i = 0; i < numberEncodings; i++)
  1650.     {
  1651.         CStr31            EncodingName;
  1652.         CStr31            PropFont;
  1653.         CStr31            FixedFont;
  1654.         unsigned short    PropFontSize;
  1655.         unsigned short    FixedFontSize;
  1656.         unsigned short    CSID;
  1657.         unsigned short  FallbackFontScriptID;
  1658.         unsigned short    TxtrButtonResID;
  1659.         unsigned short    TxtrTextFieldResID;    
  1660.         
  1661.         stream.ReadData(&EncodingName,    sizeof( CStr31));
  1662.         stream.ReadData(&PropFont,         sizeof( CStr31));
  1663.         stream.ReadData(&FixedFont,         sizeof( CStr31));
  1664.         stream.ReadData(&PropFontSize,     sizeof( unsigned short));
  1665.         stream.ReadData(&FixedFontSize,     sizeof( unsigned short));
  1666.         stream.ReadData(&CSID,             sizeof( unsigned short));
  1667.         stream.ReadData(&FallbackFontScriptID, sizeof( unsigned short));
  1668.         stream.ReadData(&TxtrButtonResID, sizeof( unsigned short));
  1669.         stream.ReadData(&TxtrTextFieldResID, sizeof( unsigned short));
  1670.  
  1671.         mEncodings[i].mLanguageGroup = EncodingName;
  1672.         mEncodings[i].mCSID = CSID;
  1673.         mEncodings[i].mPropFont = PropFont;
  1674.         mEncodings[i].mFixedFont = FixedFont;
  1675.         mEncodings[i].mPropFontSize = PropFontSize;
  1676.         mEncodings[i].mFixedFontSize = FixedFontSize;
  1677.         SetEncodingWithPref(mEncodings[i]);
  1678.     }
  1679. }
  1680.  
  1681. void
  1682. CAppearanceFontsMediator::LoadEncodings()
  1683. {
  1684.     Handle hndl;
  1685.     ::UseResFile(LMGetCurApRefNum());
  1686.     hndl = ::Get1Resource(FENC_RESTYPE,FNEC_RESID);
  1687.     if (hndl)
  1688.     {
  1689.         if (!*hndl)
  1690.         {
  1691.             ::LoadResource(hndl);
  1692.         }
  1693.         if (*hndl)
  1694.         {
  1695.             ::DetachResource(hndl);
  1696.             ThrowIfResError_();
  1697.             ReadEncodings(hndl);
  1698.             DisposeHandle(hndl);
  1699.         }
  1700.     }
  1701. }
  1702.  
  1703.  
  1704. void
  1705. CAppearanceFontsMediator::PopulateEncodingsMenus(PaneIDT menuID)
  1706. {
  1707.     if (!mEncodings)
  1708.     {
  1709.         LoadEncodings();
  1710.     }
  1711.     LGAPopup *theMenu = (LGAPopup *)FindPaneByID(menuID);
  1712.     XP_ASSERT(theMenu);
  1713.     for (int i = 0; i < mEncodingsCount; ++i)
  1714.     {
  1715.         MenuHandle    menuH = theMenu->GetMacMenuH();
  1716.         AppendMenu(menuH, "\pabc");
  1717.         SetMenuItemText(menuH, i + 1, mEncodings[i].mLanguageGroup);
  1718.     }
  1719.     theMenu->SetMaxValue(mEncodingsCount);
  1720.     theMenu->SetValue(1);
  1721. }
  1722.  
  1723. void
  1724. CAppearanceFontsMediator::SetPrefWithEncoding(const Encoding& enc)
  1725. {
  1726.     char *propFontTemplate = "intl.font%hu.prop_font";
  1727.     char *fixedFontTemplate = "intl.font%hu.fixed_font";
  1728.     char *propFontSizeTemplate = "intl.font%hu.prop_size";
  1729.     char *fixedFontSizeTemplate = "intl.font%hu.fixed_size";
  1730.     char prefBuffer[255];
  1731.  
  1732.     if (!enc.mPropFontLocked)
  1733.     {
  1734.         sprintf(prefBuffer, propFontTemplate, enc.mCSID);
  1735.         PREF_SetCharPref(prefBuffer, (char *)enc.mPropFont);
  1736.     }
  1737.  
  1738.     if (!enc.mFixedFontLocked)
  1739.     {
  1740.         sprintf(prefBuffer, fixedFontTemplate, enc.mCSID);
  1741.         PREF_SetCharPref(prefBuffer, (char *)enc.mFixedFont);
  1742.     }
  1743.  
  1744.     if (!enc.mPropFontSizeLocked)
  1745.     {
  1746.         sprintf(prefBuffer, propFontSizeTemplate, enc.mCSID);
  1747.         PREF_SetIntPref(prefBuffer, enc.mPropFontSize);
  1748.     }
  1749.  
  1750.     if (!enc.mFixedFontSizeLocked)
  1751.     {
  1752.         sprintf(prefBuffer, fixedFontSizeTemplate, enc.mCSID);
  1753.         PREF_SetIntPref(prefBuffer, enc.mFixedFontSize);
  1754.     }
  1755. }
  1756.  
  1757. void
  1758. CAppearanceFontsMediator::WriteEncodingPrefs()
  1759. {
  1760.     for(int i = 0; i < mEncodingsCount; i++)
  1761.     {
  1762.         SetPrefWithEncoding(mEncodings[i]);
  1763.     }
  1764. }
  1765.  
  1766.  
  1767. Int16
  1768. CAppearanceFontsMediator::GetFontSize(LGAPopup* whichPopup)
  1769. {
  1770.     Str255        sizeString;
  1771.     Int32        fontSize = 12;
  1772.     MenuHandle    sizeMenu;
  1773.     short        menuSize;
  1774.     short        inMenuItem;
  1775.     
  1776.     sizeMenu = whichPopup->GetMacMenuH();
  1777.     menuSize = CountMItems(sizeMenu);
  1778.     inMenuItem = whichPopup->GetValue();
  1779.     
  1780.     GetMenuItemText(sizeMenu, inMenuItem, sizeString);
  1781.     
  1782.     myStringToNum(sizeString, &fontSize);
  1783.     return fontSize;
  1784. }
  1785.  
  1786. void
  1787. CAppearanceFontsMediator::FontMenuChanged(PaneIDT changedMenuID)
  1788. {
  1789.     CSizePopup    *sizePopup =
  1790.             (CSizePopup *)FindPaneByID(ePropFontMenu == changedMenuID ?
  1791.                                             ePropSizeMenu :
  1792.                                             eFixedSizeMenu);
  1793.     XP_ASSERT(sizePopup);
  1794.     LGAPopup    *fontPopup = (LGAPopup *)FindPaneByID(changedMenuID);
  1795.     XP_ASSERT(fontPopup);
  1796.     sizePopup->MarkRealFontSizes(fontPopup);
  1797.     UpdateEncoding(changedMenuID);
  1798. }
  1799.  
  1800. void
  1801. CAppearanceFontsMediator::SizeMenuChanged(PaneIDT changedMenuID)
  1802. {
  1803.     UpdateEncoding(changedMenuID);
  1804. }
  1805.  
  1806. void
  1807. CAppearanceFontsMediator::ListenToMessage(MessageT inMessage, void *ioParam)
  1808. {
  1809.     switch (inMessage)
  1810.     {
  1811.         case eCharSetMenu:
  1812.             UpdateMenus();
  1813.             break;
  1814.         case msg_ChangeFontSize:
  1815.             break;
  1816.         case ePropFontMenu:
  1817.         case eFixedFontMenu:
  1818.             FontMenuChanged(inMessage);
  1819.             break;
  1820.         case ePropSizeMenu:
  1821.         case eFixedSizeMenu:
  1822.             SizeMenuChanged(inMessage);
  1823.             break;
  1824.         default:
  1825.             CPrefsMediator::ListenToMessage(inMessage, ioParam);
  1826.             break;
  1827.     }
  1828. }
  1829.  
  1830. void
  1831. CAppearanceFontsMediator::LoadPrefs()
  1832. {
  1833.     PopulateEncodingsMenus(eCharSetMenu);
  1834.     UpdateMenus();                                
  1835. }
  1836.  
  1837. void
  1838. CAppearanceFontsMediator::WritePrefs()
  1839. {
  1840.     WriteEncodingPrefs();
  1841. }
  1842.  
  1843. enum
  1844. {
  1845.     eForegroundColorButton = 12201,
  1846.     eBackgroundColorButton,
  1847.     eUnvisitedColorButton,
  1848.     eVisitedColorButton,
  1849.     eUnderlineLinksBox,
  1850.     eUseDefaultButton,
  1851.     eOverrideDocColors
  1852. };
  1853.  
  1854. CAppearanceColorsMediator::CAppearanceColorsMediator(LStream*)
  1855. :    CPrefsMediator(class_ID)
  1856. {
  1857. }
  1858.  
  1859. void
  1860. CAppearanceColorsMediator::ListenToMessage(MessageT inMessage, void *ioParam)
  1861. {
  1862.     switch (inMessage)
  1863.     {
  1864.         case eUseDefaultButton:
  1865.             UseDefaults();
  1866.             break;
  1867.         default:
  1868.             CPrefsMediator::ListenToMessage(inMessage, ioParam);
  1869.             break;
  1870.     }
  1871. }
  1872.  
  1873. void
  1874. CAppearanceColorsMediator::UseDefaults()
  1875. {
  1876.     ReadDefaultPref(eForegroundColorButton);
  1877.     ReadDefaultPref(eUnvisitedColorButton);
  1878.     ReadDefaultPref(eVisitedColorButton);
  1879.     ReadDefaultPref(eBackgroundColorButton);
  1880. }
  1881.  
  1882. enum
  1883. {
  1884.     eBlankPageRButton = 12301,
  1885.     eHomePageRButton,
  1886.     eLastPageRButton,
  1887.     eHomePageTextEditBox,
  1888.     eHomePageChooseButton,
  1889.     eExpireAfterTextEditBox,
  1890.     eExpireNowButton,
  1891.     eUseCurrentButton
  1892. };
  1893.  
  1894.  
  1895. CBrowserMainMediator::CBrowserMainMediator(LStream*)
  1896. :    CPrefsMediator(class_ID)
  1897. ,    mHomePageURLLocked(false)
  1898. ,    mCurrentURL(nil)
  1899. {
  1900. }
  1901.  
  1902. void
  1903. CBrowserMainMediator::ListenToMessage(MessageT inMessage, void *ioParam)
  1904. {
  1905.     switch (inMessage)
  1906.     {
  1907. //        case msg_ControlClicked:
  1908. //            break;
  1909.         case eHomePageChooseButton:
  1910.             SetEditFieldWithLocalFileURL(eHomePageTextEditBox, mHomePageURLLocked);
  1911.             // do whatever it takes to find a home page file
  1912.             break;
  1913.         case eExpireNowButton:
  1914.             // do whatever it takes to expire links
  1915.             ExpireNow();
  1916.             break;
  1917.         case eUseCurrentButton:
  1918.             // do whatever it takes to find the current page
  1919.             if (mCurrentURL && *mCurrentURL)
  1920.             {
  1921.                 LStr255    pURL(mCurrentURL);
  1922.                 LEditField    *theField =
  1923.                     (LEditField *)FindPaneByID(eHomePageTextEditBox);
  1924.                 XP_ASSERT(theField);
  1925.                 theField->SetDescriptor(pURL);
  1926.                 theField->SelectAll();
  1927.             }
  1928.             break;
  1929.         default:
  1930.             CPrefsMediator::ListenToMessage(inMessage, ioParam);
  1931.             break;
  1932.     }
  1933. }
  1934.  
  1935. void
  1936. CBrowserMainMediator::ExpireNow()
  1937. {
  1938.     StPrepareForDialog    prepare;
  1939.     short    response = ::CautionAlert(eExpireNowButton, NULL);
  1940.     if (1 == response)
  1941.     {
  1942.         GH_ClearGlobalHistory();
  1943.         XP_RefreshAnchors();
  1944.     }
  1945. }
  1946.  
  1947. Boolean
  1948. CBrowserMainMediator::ExpireDaysValidationFunc(CValidEditField *daysTilExpire)
  1949. {
  1950.     Boolean        result;
  1951.     result = ConstrainEditField(daysTilExpire, EXPIRE_MIN, EXPIRE_MAX);
  1952.     if (!result)
  1953.     {
  1954.         StPrepareForDialog    prepare;
  1955.         ::StopAlert(1064, NULL);
  1956.     }
  1957.     return result;
  1958. }
  1959.  
  1960. void
  1961. CBrowserMainMediator::LoadMainPane()
  1962. {
  1963.     CPrefsMediator::LoadMainPane();
  1964.     SetValidationFunction(eExpireAfterTextEditBox, ExpireDaysValidationFunc);
  1965. }
  1966.  
  1967. void
  1968. CBrowserMainMediator::UpdateFromIC()
  1969. {
  1970.     SetEditFieldsWithICPref(kICWWWHomePage, eHomePageTextEditBox);
  1971.     URLChoosingButtons(!UseIC() && !mHomePageURLLocked);
  1972. }
  1973.  
  1974. void
  1975. CBrowserMainMediator::URLChoosingButtons(Boolean enable)
  1976. {
  1977.     LButton    *currentURLButton = (LButton *)FindPaneByID(eUseCurrentButton);
  1978.     XP_ASSERT(currentURLButton);
  1979.     LButton    *chooseURLButton = (LButton *)FindPaneByID(eHomePageChooseButton);
  1980.     XP_ASSERT(chooseURLButton);
  1981.     if (enable)
  1982.     {
  1983.         currentURLButton->Enable();
  1984.         chooseURLButton->Enable();
  1985.     }
  1986.     else
  1987.     {
  1988.         currentURLButton->Disable();
  1989.         chooseURLButton->Disable();
  1990.     }
  1991. }
  1992.  
  1993. //-----------------------------------
  1994. void CBrowserMainMediator::LoadPrefs()
  1995. //-----------------------------------
  1996. {
  1997.     mHomePageURLLocked = PaneHasLockedPref(eHomePageTextEditBox);
  1998.     if (!mHomePageURLLocked)    // If locked we don't need the current url.
  1999.     {
  2000.         URLChoosingButtons(true);
  2001.         CWindowMediator    *mediator = CWindowMediator::GetWindowMediator();
  2002.         CBrowserWindow    *browserWindow =
  2003.             (CBrowserWindow    *)mediator->FetchTopWindow(WindowType_Browser);
  2004.         if (browserWindow)
  2005.         {
  2006.             CNSContext    *context = browserWindow->GetWindowContext();
  2007.             mCurrentURL = XP_STRDUP(context->GetCurrentURL());
  2008.         }
  2009.     }
  2010.     else
  2011.     {
  2012.         URLChoosingButtons(false);
  2013.     }
  2014.     LButton    *currentURLButton = (LButton *)FindPaneByID(eUseCurrentButton);
  2015.     XP_ASSERT(currentURLButton);
  2016.     if (mHomePageURLLocked || (!mCurrentURL) || (!(*mCurrentURL)))
  2017.         currentURLButton->Disable();
  2018.     else
  2019.         currentURLButton->Enable();
  2020. }
  2021.  
  2022. //-----------------------------------
  2023. void CBrowserMainMediator::WritePrefs()
  2024. //-----------------------------------
  2025. {
  2026. }
  2027.  
  2028. enum
  2029. {
  2030.     eBuiltInLanguageStringResID = 5028,
  2031.     eBuiltInLanguageCodeResID = 5029,
  2032.     eLanguageList = 12401,
  2033.     eAddLanguageButton,
  2034.     eDeleteLanguageButton,
  2035.     eAddLanguageList,
  2036.     eAddLanguageOtherEditField,
  2037.     eAddLanguageDialogID = 12004
  2038. };
  2039.  
  2040.  
  2041.  
  2042. CBrowserLanguagesMediator::CBrowserLanguagesMediator(LStream*)
  2043. :    CPrefsMediator(class_ID)
  2044. ,    mLanguagesLocked(false)
  2045. ,    mBuiltInCount(0)
  2046. ,    mLanguageStringArray(nil)
  2047. ,    mLangaugeCodeArray(nil)
  2048. {
  2049. }
  2050.  
  2051. CBrowserLanguagesMediator::~CBrowserLanguagesMediator()
  2052. {
  2053.     int i;
  2054.     if (mLanguageStringArray)
  2055.     {
  2056.         for (i = 0; i < mBuiltInCount; ++i)
  2057.         {
  2058.             if (mLanguageStringArray[i])
  2059.             {
  2060.                 XP_FREE(mLanguageStringArray[i]);
  2061.             }
  2062.         }
  2063.         XP_FREE(mLanguageStringArray);
  2064.     }
  2065.     if (mLangaugeCodeArray)
  2066.     {
  2067.         for (i = 0; i < mBuiltInCount; ++i)
  2068.         {
  2069.             if (mLangaugeCodeArray[i])
  2070.             {
  2071.                 XP_FREE(mLangaugeCodeArray[i]);
  2072.             }
  2073.         }
  2074.         XP_FREE(mLangaugeCodeArray);
  2075.     }
  2076. }
  2077.  
  2078. char *
  2079. CBrowserLanguagesMediator::GetLanguageDisplayString(    const char *languageCode)
  2080. {
  2081.     char    *result;
  2082.     int        i;
  2083.     for (i = 0; i < mBuiltInCount; ++i)
  2084.     {
  2085.         if (!strcmp(languageCode, mLangaugeCodeArray[i]))
  2086.         {
  2087.             const    char *    const    formatString = "%s [%s]";
  2088.             int    newStringLength =    strlen(mLangaugeCodeArray[i]) +
  2089.                                     strlen(mLanguageStringArray[i]) +
  2090.                                     strlen(formatString) -
  2091.                                     4;    // the two "%s"s in the format string
  2092.             result = (char *)XP_ALLOC(newStringLength + 1);
  2093.             sprintf(result, formatString, mLanguageStringArray[i], mLangaugeCodeArray[i]);
  2094.             break;
  2095.         }
  2096.     }
  2097.     if (i == mBuiltInCount)    // then we didn't find a match
  2098.     {
  2099.         result = (char *)XP_ALLOC(strlen(languageCode) + 1);
  2100.         strcpy(result, languageCode);
  2101.     }
  2102.     return result;
  2103. }
  2104.  
  2105. void
  2106. CBrowserLanguagesMediator::SetLanguageListWithPref(    const char *prefName,
  2107.                                                         PaneIDT    languageListID,
  2108.                                                         Boolean    &locked)
  2109. {
  2110.     locked = PREF_PrefIsLocked(prefName);
  2111.     CDragOrderTextList    *languageList =
  2112.                 (CDragOrderTextList *)FindPaneByID(languageListID);
  2113.     XP_ASSERT(languageList);
  2114.  
  2115.     char    *theString;
  2116.     int        prefResult = PREF_CopyCharPref(prefName, &theString);
  2117.     if (prefResult == PREF_NOERROR && theString != nil)
  2118.     {
  2119.         TableIndexT    rowNumber = 0;
  2120.         char    *languageCode;
  2121.         char    *strtokFirstParam = theString;
  2122.         #pragma warn_possunwant off
  2123.         while (languageCode = strtok(strtokFirstParam, ", "))
  2124.         #pragma warn_possunwant reset
  2125.         {
  2126.             char    *display = GetLanguageDisplayString(languageCode);
  2127.             Str255    pDisplay;
  2128.             strtokFirstParam = nil;
  2129.             BlockMoveData(display, &pDisplay[1], pDisplay[0] = strlen(display));
  2130.             languageList->InsertRows(1, rowNumber++, pDisplay, sizeof(Str255), false);
  2131.             XP_FREE(display);
  2132.         }
  2133.         XP_FREE(theString);
  2134.         languageList->Refresh();
  2135.     }
  2136.     if (locked)
  2137.     {
  2138.         LButton    *button =
  2139.                 (LButton *)FindPaneByID(eAddLanguageButton);
  2140.         XP_ASSERT(button);
  2141.         button->Disable();
  2142.         button = (LButton *)FindPaneByID(eDeleteLanguageButton);
  2143.         XP_ASSERT(button);
  2144.         button->Disable();
  2145.         languageList->LockOrder();
  2146.     }
  2147. }
  2148.  
  2149. char *
  2150. CBrowserLanguagesMediator::AppendLanguageCode(    const char *originalString,
  2151.                                                     const char *stringToAdd)
  2152. {
  2153.     int        originalLength = originalString ? strlen(originalString) : 0;
  2154.     int        lengthToAdd;
  2155.     char    *occur = strchr(stringToAdd, '[');
  2156.     char    *occurRight;
  2157.     if (occur)
  2158.     {
  2159.         ++occur;
  2160.         occurRight = strchr(occur, ']');
  2161.         if (occurRight)
  2162.         {
  2163.             lengthToAdd = occurRight - occur;
  2164.         }
  2165.     }
  2166.     else
  2167.     {
  2168.         lengthToAdd = strlen(stringToAdd);
  2169.     }
  2170.     char    *result = nil;
  2171.     if (originalLength || lengthToAdd)
  2172.     {
  2173.         const    char *    const junctionString = ", ";
  2174.         result = (char *)XP_ALLOC(    originalLength +
  2175.                                     lengthToAdd +
  2176.                                     strlen(junctionString) + 1);
  2177.         result[0] = '\0';
  2178.         if (originalLength)
  2179.         {
  2180.             strcpy(result, originalString);
  2181.             strcat(result, junctionString);
  2182.         }
  2183.         if (lengthToAdd)
  2184.         {
  2185.             const char    *source = occur ? occur : stringToAdd;
  2186.             strncat(result, source, lengthToAdd);
  2187.         }
  2188.     }
  2189.     return result;
  2190. }
  2191.  
  2192. void CBrowserLanguagesMediator::SetPrefWithLanguageList(const char *prefName,
  2193.                                                         PaneIDT    /*languageListID*/,
  2194.                                                         Boolean    locked)
  2195. {
  2196.     if (!locked)
  2197.     {
  2198.         char    *prefString = nil;
  2199.         CDragOrderTextList *languageList =
  2200.                 (CDragOrderTextList *)FindPaneByID(eLanguageList);
  2201.         XP_ASSERT(languageList);
  2202.         TableIndexT    rows, cols;
  2203.         languageList->GetTableSize(rows, cols);
  2204.  
  2205.         STableCell    iCell(1, 1);
  2206.         for (int i = 0; i < rows; ++i)
  2207.         {
  2208.             Str255    languageStr;
  2209.             Uint32    dataSize = sizeof(Str255);
  2210.             languageList->GetCellData(iCell, languageStr, dataSize);
  2211.             ++iCell.row;
  2212.             languageStr[languageStr[0] + 1] = '\0';    // &languageStr[1] is now a C string
  2213.             char    *temp = prefString;
  2214.             prefString = AppendLanguageCode(prefString, (char *)&languageStr[1]);
  2215.             if (temp)
  2216.             {
  2217.                 XP_FREE(temp);
  2218.             }
  2219.         }
  2220.  
  2221.         // only set if different than current
  2222.         char    terminator = '\0';
  2223.         char    *currentValue;
  2224.  
  2225.         int        prefResult = PREF_CopyCharPref(prefName, ¤tValue);
  2226.         if (prefResult != PREF_NOERROR)
  2227.         {
  2228.             currentValue = &terminator;
  2229.         }
  2230.         if (prefResult != PREF_NOERROR || strcmp(currentValue, prefString))
  2231.         {
  2232.             PREF_SetCharPref(prefName, prefString);
  2233.             XP_FREE(prefString);
  2234.         }
  2235.         if (currentValue && (currentValue != &terminator))
  2236.         {
  2237.             XP_FREE(currentValue);
  2238.         }
  2239.     }
  2240. }
  2241.  
  2242. void
  2243. CBrowserLanguagesMediator::UpdateButtons(LTextColumn *languageList)
  2244. {
  2245.     if (!mLanguagesLocked)
  2246.     {
  2247.         if (!languageList)
  2248.         {
  2249.             languageList = (CDragOrderTextList *)FindPaneByID(eLanguageList);
  2250.             XP_ASSERT(languageList);
  2251.         }
  2252.         STableCell        currentCell;
  2253.         currentCell = languageList->GetFirstSelectedCell();
  2254.         LButton    *button =
  2255.                 (LButton *)FindPaneByID(eDeleteLanguageButton);
  2256.         XP_ASSERT(button);
  2257.         if (currentCell.row)
  2258.         {
  2259.             button->Enable();
  2260.         }
  2261.         else
  2262.         {
  2263.             button->Disable();
  2264.         }
  2265.     }
  2266. }
  2267.  
  2268. void
  2269. CBrowserLanguagesMediator::FillAddList(LTextColumn *list)
  2270. {
  2271.     int i;
  2272.     for (i = 0; i < mBuiltInCount; ++i)
  2273.     {
  2274.         char    *displayString;
  2275.         const    char *    const    formatString = "%s [%s]";
  2276.         int    newStringLength =    strlen(mLangaugeCodeArray[i]) +
  2277.                                 strlen(mLanguageStringArray[i]) +
  2278.                                 strlen(formatString) -
  2279.                                 4;    // the two "%s"s in the format string
  2280.         displayString = (char *)XP_ALLOC(newStringLength + 1);
  2281.         sprintf(displayString, formatString, mLanguageStringArray[i], mLangaugeCodeArray[i]);
  2282.         Str255        pDisplayString;
  2283.         BlockMoveData(displayString, &pDisplayString[1], newStringLength);
  2284.         XP_FREE(displayString);
  2285.         pDisplayString[0] = newStringLength;
  2286.         list->InsertRows(1, i, &pDisplayString, sizeof(pDisplayString), false);
  2287.     }
  2288. }
  2289.  
  2290.  
  2291. Boolean
  2292. CBrowserLanguagesMediator::GetNewLanguage(char *&newLanguage)
  2293. {
  2294.     Boolean    result;
  2295.  
  2296.     StDialogHandler    handler(eAddLanguageDialogID, sWindow->GetSuperCommander());
  2297.     LWindow            *dialog = handler.GetDialog();
  2298.  
  2299.     mAddLanguageList =
  2300.         (LTextColumn *)dialog->FindPaneByID(eAddLanguageList);
  2301.     XP_ASSERT(mAddLanguageList);
  2302.     CEditFieldControl    *theField =
  2303.         (CEditFieldControl *)dialog->FindPaneByID(eAddLanguageOtherEditField);
  2304.     XP_ASSERT(theField);
  2305.  
  2306.     mOtherTextEmpty = true;
  2307.  
  2308.     mAddLanguageList->AddListener(&handler);
  2309.     theField->AddListener(this);
  2310.  
  2311.     FillAddList(mAddLanguageList);
  2312.     MessageT message = msg_Nothing;
  2313.     do
  2314.     {
  2315.         message = handler.DoDialog();
  2316.         if ('2sel' == message)
  2317.         {
  2318.             theField->SetDescriptor("\p");
  2319.             mOtherTextEmpty = true;
  2320.             message = msg_OK;
  2321.         }
  2322.         if (msg_Nothing != message &&
  2323.             msg_OK != message  &&
  2324.             msg_Cancel != message)
  2325.         {
  2326.             message = msg_Nothing;
  2327.         }
  2328.     } while (msg_Nothing == message);
  2329.  
  2330.     if (msg_OK == message)
  2331.     {
  2332.         Str255    newLanguageName;
  2333.         theField->GetDescriptor(newLanguageName);
  2334.         int        newLanguageNameSize = newLanguageName[0];
  2335.         if (newLanguageNameSize)
  2336.         {
  2337.             newLanguage = (char *)XP_ALLOC(newLanguageNameSize + 1);
  2338.             BlockMoveData(&newLanguageName[1], newLanguage, newLanguageNameSize);
  2339.             newLanguage[newLanguageNameSize] = '\0';
  2340.             result = true;
  2341.         }
  2342.         else
  2343.         {
  2344.             STableCell    selectedCell = mAddLanguageList->GetFirstSelectedCell();
  2345.             Str255        selectedLanguage;
  2346.             if (selectedCell.row)
  2347.             {
  2348.                 long    dataSize = sizeof(selectedLanguage);
  2349.                 mAddLanguageList->GetCellData(selectedCell, selectedLanguage, dataSize);
  2350.                 newLanguage = (char *)XP_ALLOC(selectedLanguage[0] + 1);
  2351.                 BlockMoveData(&selectedLanguage[1], newLanguage, selectedLanguage[0]);
  2352.                 newLanguage[selectedLanguage[0]] = '\0';
  2353.                 result = true;
  2354.             }
  2355.             else
  2356.             {
  2357.                 result = false;
  2358.             }
  2359.         }
  2360.     }
  2361.     else
  2362.     {
  2363.         result = false;
  2364.     }
  2365.     return result;
  2366. }
  2367.  
  2368. Boolean
  2369. CBrowserLanguagesMediator::GetNewUniqueLanguage(char *&newLanguage)
  2370. {
  2371.     Boolean    result = GetNewLanguage(newLanguage);
  2372.     if (result)
  2373.     {
  2374.         char    *tempString = newLanguage;
  2375.         newLanguage = GetLanguageDisplayString(tempString);
  2376.         XP_FREE(tempString);
  2377.  
  2378.         CDragOrderTextList *languageList =
  2379.                 (CDragOrderTextList *)FindPaneByID(eLanguageList);
  2380.         XP_ASSERT(languageList);
  2381.         TableIndexT    rows, cols;
  2382.         languageList->GetTableSize(rows, cols);
  2383.  
  2384.         STableCell    iCell(1, 1);
  2385.         for (int i = 0; i < rows; ++i)
  2386.         {
  2387.             Str255    languageStr;
  2388.             Uint32    dataSize = sizeof(Str255);
  2389.             languageList->GetCellData(iCell, languageStr, dataSize);
  2390.             ++iCell.row;
  2391.             LStr255    pNewLangage(newLanguage);
  2392.             if (!pNewLangage.CompareTo(languageStr))    // we already have this lanuage
  2393.             {
  2394.                 result = false;
  2395.                 XP_FREE(newLanguage);
  2396.                 break;
  2397.             }
  2398.         }
  2399.     }
  2400.     return result;
  2401. }
  2402.  
  2403.  
  2404. void
  2405. CBrowserLanguagesMediator::ListenToMessage(MessageT inMessage, void *ioParam)
  2406. {
  2407.     switch (inMessage)
  2408.     {
  2409.         case CEditFieldControl::msg_ChangedText:
  2410.             Str255    languageStr;
  2411.             ((CEditFieldControl *)ioParam)->GetDescriptor(languageStr);
  2412.             if ((mOtherTextEmpty && languageStr[0]) ||    // The value of mOtherTextEmpty
  2413.                 (!mOtherTextEmpty && !languageStr[0]))    // needs to change.
  2414.             {
  2415. //                STableCell    selected = mAddLanguageList->GetFirstSelectedCell();
  2416. //                if (selected.row)
  2417. //                {
  2418.                     if (mOtherTextEmpty)
  2419.                     {
  2420.                         mOtherTextEmpty = false;
  2421.                         mAddLanguageList->Deactivate();
  2422.                     }
  2423.                     else
  2424.                     {
  2425.                         mOtherTextEmpty = true;
  2426.                         mAddLanguageList->Activate();
  2427.                     }
  2428. //                }
  2429.             }
  2430.             break;
  2431.         case eSelectionChanged:
  2432.             UpdateButtons((CDragOrderTextList *)ioParam);
  2433.             break;
  2434.         case eAddLanguageButton:
  2435.             XP_ASSERT(!mLanguagesLocked);
  2436.             char    *newLanguage;
  2437.             if (GetNewUniqueLanguage(newLanguage))
  2438.             {
  2439.                 CDragOrderTextList *languageList =
  2440.                         (CDragOrderTextList *)FindPaneByID(eLanguageList);
  2441.                 XP_ASSERT(languageList);
  2442.                 STableCell        currentCell;
  2443.                 currentCell = languageList->GetFirstSelectedCell();
  2444.                 TableIndexT    insertAfter = currentCell.row;
  2445.                 if (!insertAfter)
  2446.                 {
  2447.                     // add it at the end
  2448.                     TableIndexT    cols;
  2449.                     languageList->GetTableSize(insertAfter, cols);
  2450.                 }
  2451.                 LStr255    pNewLanguage(newLanguage);
  2452.                 languageList->InsertRows(    1,
  2453.                                             insertAfter,
  2454.                                             pNewLanguage,
  2455.                                             sizeof(Str255),
  2456.                                             true);
  2457.                 if (newLanguage)
  2458.                 {
  2459.                     XP_FREE(newLanguage);
  2460.                 }
  2461.                 UpdateButtons(languageList);
  2462.             }
  2463.             break;
  2464.         case eDeleteLanguageButton:
  2465.             XP_ASSERT(!mLanguagesLocked);
  2466.             CDragOrderTextList *languageList =
  2467.                     (CDragOrderTextList *)FindPaneByID(eLanguageList);
  2468.             XP_ASSERT(languageList);
  2469.             STableCell        currentCell;
  2470.             currentCell = languageList->GetFirstSelectedCell();
  2471.             languageList->RemoveRows(1, currentCell.row, true);
  2472.             UpdateButtons(languageList);
  2473.             break;
  2474.         default:
  2475.             CPrefsMediator::ListenToMessage(inMessage, ioParam);
  2476.             break;
  2477.     }
  2478. }
  2479.  
  2480.  
  2481. void
  2482. CBrowserLanguagesMediator::LoadBuiltInArrays()
  2483. {
  2484.     // I guess we can tell how many strings are in a string list from the first
  2485.     // two bytes of the resource. Is this documented?
  2486.     short    **countHandle = (short **)GetResource('STR#', eBuiltInLanguageStringResID);
  2487.     XP_ASSERT(countHandle);
  2488.     mBuiltInCount = **countHandle;
  2489.     mLanguageStringArray = (char **)XP_ALLOC(mBuiltInCount * sizeof(char *));
  2490.     mLangaugeCodeArray = (char **)XP_ALLOC(mBuiltInCount * sizeof(char *));
  2491.     int i;
  2492.     for (i = 0; i < mBuiltInCount; ++i)
  2493.     {
  2494.         Str255    builtInString; Str255    builtInCode;
  2495.  
  2496.         ::GetIndString(builtInString, eBuiltInLanguageStringResID, i + 1);
  2497.         ::GetIndString(builtInCode, eBuiltInLanguageCodeResID, i + 1);
  2498.         mLanguageStringArray[i] = (char *)XP_ALLOC(builtInString[0] + 1);
  2499.         mLangaugeCodeArray[i] = (char *)XP_ALLOC(builtInCode[0] + 1);
  2500.         ::BlockMoveData(&builtInString[1], mLanguageStringArray[i], (Size)builtInString[0]);
  2501.         ::BlockMoveData(&builtInCode[1], mLangaugeCodeArray[i], (Size)builtInCode[0]);
  2502.         mLanguageStringArray[i][builtInString[0]] = '\0';
  2503.         mLangaugeCodeArray[i][builtInCode[0]] = '\0';
  2504.     }
  2505. }
  2506.  
  2507. //-----------------------------------
  2508. void CBrowserLanguagesMediator::LoadMainPane()
  2509. //-----------------------------------
  2510. {
  2511.     CPrefsMediator::LoadMainPane();
  2512.     CDragOrderTextList *languageList =
  2513.             (CDragOrderTextList *)FindPaneByID(eLanguageList);
  2514.     XP_ASSERT(languageList);
  2515.     languageList->AddListener(this);
  2516.     UpdateButtons(languageList);
  2517. }
  2518.  
  2519. //-----------------------------------
  2520. void CBrowserLanguagesMediator::LoadPrefs()
  2521. //-----------------------------------
  2522. {
  2523.     LoadBuiltInArrays();
  2524.     SetLanguageListWithPref("intl.accept_languages",
  2525.                             eLanguageList,
  2526.                             mLanguagesLocked);
  2527. }
  2528.  
  2529. //-----------------------------------
  2530. void CBrowserLanguagesMediator::WritePrefs()
  2531. //-----------------------------------
  2532. {
  2533.     SetPrefWithLanguageList("intl.accept_languages",
  2534.                             eLanguageList,
  2535.                             mLanguagesLocked);
  2536. }
  2537.  
  2538. enum
  2539. {
  2540.     eEditTypeDialogResID = 12008,
  2541.     eHelperScroller = 12501,
  2542.     eHelperTable,
  2543.     eHelperNewButton,
  2544.     eHelperEditButton,
  2545.     eHelperDeleteButton,
  2546.     eDownloadFilePicker
  2547. };
  2548.  
  2549. CBrowserApplicationsMediator::CBrowserApplicationsMediator(LStream*)
  2550. :    CPrefsMediator(class_ID)
  2551. ,    mModified(false)
  2552. ,    mMIMETable(nil)
  2553. {
  2554. }
  2555.  
  2556. void
  2557. CBrowserApplicationsMediator::EditMimeEntry()
  2558. {
  2559. //    StBlockingDialogHandler    theHandler(eEditTypeDialogResID, this);
  2560.     StDialogHandler    theHandler(eEditTypeDialogResID, sWindow->GetSuperCommander());
  2561.     CEditMIMEWindow* theDialog = (CEditMIMEWindow*)theHandler.GetDialog();
  2562.     XP_ASSERT(theDialog);
  2563.     UReanimator::LinkListenerToControls(theDialog, theDialog, eEditTypeDialogResID);
  2564.     theDialog->SetMimeTable(mMIMETable);
  2565.     
  2566.     // Get the info that the dialog should display
  2567.     CMIMEListPane::PrefCellInfo cellInfo;
  2568.     TableCellT    cellToEdit;
  2569.     mMIMETable->GetSelectedCell(cellToEdit);
  2570.     mMIMETable->GetCellData(cellToEdit, &cellInfo);
  2571.     
  2572.     // Make a copy of the info to edit
  2573.     CMIMEListPane::PrefCellInfo newInfo;
  2574.     newInfo.fMapper = new CMimeMapper(*cellInfo.fMapper); 
  2575.     newInfo.fIconInfo = cellInfo.fIconInfo;
  2576.     theDialog->SetCellInfo(newInfo);
  2577.  
  2578.     // Let the user have at it...
  2579.     theDialog->Show();
  2580.     MessageT theMessage = msg_Nothing;    
  2581.     while ((theMessage != msg_Cancel) && (theMessage != msg_OK))
  2582.     {
  2583.         theMessage = theHandler.DoDialog();
  2584.         
  2585.         if (theMessage == msg_OK &&
  2586.             cellInfo.fMapper->GetMimeName() != newInfo.fMapper->GetMimeName() &&
  2587.             mMIMETable->MimeTypeExists(newInfo.fMapper))
  2588.         {
  2589.             ErrorManager::PlainAlert(mPREFS_DUPLICATE_MIME);
  2590.             theMessage = msg_Nothing;
  2591.         }
  2592.         // The CEditMIMEWindow will handle all other messages
  2593.     }
  2594.     
  2595.     // Process the munged data as appropriate
  2596.     if (theMessage == msg_OK && theDialog->Modified())
  2597.     {
  2598.         delete cellInfo.fMapper;                            // Delete the old mapper
  2599.         newInfo = theDialog->GetCellInfo();                    // Get the edited info
  2600.         mMIMETable->SetCellData(cellToEdit, &newInfo);        // Write the edited info into the table
  2601.         mModified = TRUE;                                    // Remember that something changed
  2602.         mMIMETable->Refresh();                                // Let table sync to the new data
  2603.     }
  2604.     else
  2605.     {
  2606.         delete newInfo.fMapper;                                // Delete the changed but discarded mapper
  2607.         newInfo.fMapper = NULL;
  2608.     }    
  2609. }
  2610.  
  2611. void
  2612. CBrowserApplicationsMediator::NewMimeEntry()
  2613. {
  2614. //    StBlockingDialogHandler    theHandler(eEditTypeDialogResID, this);
  2615.     StDialogHandler    theHandler(eEditTypeDialogResID, sWindow->GetSuperCommander());
  2616.     CEditMIMEWindow* theDialog = (CEditMIMEWindow *)theHandler.GetDialog();
  2617.     XP_ASSERT(theDialog);
  2618.     UReanimator::LinkListenerToControls(theDialog, theDialog, eEditTypeDialogResID);
  2619.     theDialog->SetMimeTable(mMIMETable);
  2620.     
  2621.     // Create a new default mapper and put it in the table
  2622.     CStr255 emptyType = "";
  2623.     CMimeMapper* newMapper = CPrefs::CreateDefaultUnknownMapper(emptyType, FALSE);
  2624.     ThrowIfNil_(newMapper);
  2625.     ThrowIfNil_(mMIMETable);
  2626.     CMIMEListPane::PrefCellInfo cellInfo;
  2627.     mMIMETable->InsertRows(1, 0, &cellInfo);
  2628.     mMIMETable->BindCellToApplication(1, newMapper);
  2629.  
  2630.     TableCellT newCell;
  2631.     newCell.row = newCell.col = 1;
  2632.     mMIMETable->GetCellData(newCell, &cellInfo);
  2633.     theDialog->SetCellInfo(cellInfo);
  2634.     
  2635.     // Let the user have at it...
  2636.     theDialog->Show();
  2637.     MessageT theMessage = msg_Nothing;    
  2638.     while ((theMessage != msg_Cancel) && (theMessage != msg_OK))
  2639.     {
  2640.         theMessage = theHandler.DoDialog();
  2641.         
  2642.         if (theMessage == msg_OK && mMIMETable->MimeTypeExists(cellInfo.fMapper))
  2643.         {
  2644.             ErrorManager::PlainAlert(mPREFS_DUPLICATE_MIME);
  2645.             theMessage = msg_Nothing;
  2646.         }
  2647.         // The CEditMimeWindow will handle all other messages
  2648.     }
  2649.     
  2650.     // Process the munged data as appropriate
  2651.     CMIMEListPane::PrefCellInfo newInfo = theDialog->GetCellInfo();
  2652.     if (theMessage == msg_OK && theDialog->Modified())
  2653.     {
  2654.         mModified = TRUE;                                // Remember that something changed
  2655.         mMIMETable->SetCellData(newCell, &newInfo);        // Write the edited info into the table
  2656.         mMIMETable->SelectCell(newCell);                // Select the new cell
  2657.         mMIMETable->ScrollImageTo(0, 0, TRUE);
  2658.         mMIMETable->Refresh();                            // Let table sync to the new data
  2659.     }
  2660.     else
  2661.     {
  2662.         delete newInfo.fMapper;                            // Delete the discarded mapper
  2663.         mMIMETable->RemoveRows(1, newCell.row);            // Remove the row added to the table
  2664.     }    
  2665. }
  2666.  
  2667. void
  2668. CBrowserApplicationsMediator::DeleteMimeEntry()
  2669. {
  2670.     if (ErrorManager::PlainConfirm((const char*) GetCString(DELETE_MIMETYPE)))
  2671.     {
  2672.         XP_ASSERT(mMIMETable);
  2673.         TableCellT cellToDelete;
  2674.         mMIMETable->GetSelectedCell(cellToDelete);
  2675.         PrefCellInfo cellInfo;
  2676.         mMIMETable->GetCellData(cellToDelete, &cellInfo);
  2677.         
  2678.         // Instead of freeing the item, add it to a list of deleted mime types
  2679.         // and at commit time, delete the items from xp pref storage.
  2680.         mDeletedTypes.LArray::InsertItemsAt(1, LArray::index_Last, &cellInfo.fMapper);
  2681.         
  2682.         mModified = TRUE;
  2683.         
  2684.         mMIMETable->RemoveRows(1, cellToDelete.row);
  2685.  
  2686.         // We want to select the cell immediately after the deleted one. It just so
  2687.         // happens that its coordinates are now (after deleting), what the cell to
  2688.         // delete was before. So we just need to select cellToDelete. However, if
  2689.         // there is no cell after the deleted cell (it was the last one), then we
  2690.         // just select the last one.
  2691.         TableIndexT    rows, columns;
  2692.         mMIMETable->GetTableSize(rows, columns);
  2693.         cellToDelete.row = cellToDelete.row > rows? rows: cellToDelete.row;
  2694.         mMIMETable->ScrollCellIntoFrame(cellToDelete);
  2695.         mMIMETable->SelectCell(cellToDelete);
  2696.         mMIMETable->Refresh();
  2697.     }
  2698. }
  2699.  
  2700. void
  2701. CBrowserApplicationsMediator::ListenToMessage(MessageT inMessage, void *ioParam)
  2702. {
  2703.     switch (inMessage)
  2704.     {
  2705.         case eHelperDeleteButton:
  2706.             DeleteMimeEntry();
  2707.             break;
  2708.         case eHelperNewButton:
  2709.             NewMimeEntry();
  2710.             break;
  2711.         case eHelperEditButton:
  2712.         case CMIMEListPane::msg_DoubleClick:
  2713.             EditMimeEntry();
  2714.             break;
  2715.         case CMIMEListPane::msg_SelectionChanged:
  2716.             LButton    *deleteButton = (LButton *)FindPaneByID(eHelperDeleteButton);
  2717.             XP_ASSERT(deleteButton);
  2718.             LButton    *editButton = (LButton *)FindPaneByID(eHelperEditButton);
  2719.             XP_ASSERT(editButton);
  2720.  
  2721.             XP_ASSERT(ioParam);
  2722.             CMIMEListPane    *mimeTable = (CMIMEListPane *)ioParam;
  2723.             TableCellT    cell;
  2724.             mimeTable->GetSelectedCell(cell);
  2725.             Boolean inactive;
  2726.             if (cell.row > 0)
  2727.             {
  2728.                 PrefCellInfo cellInfo;
  2729.                 mimeTable->GetCellData(cell, &cellInfo);
  2730.  
  2731.                 inactive = CMimeMapper::NetscapeCanHandle(cellInfo.fMapper->GetMimeName());
  2732.                 editButton->Enable();
  2733.             }
  2734.             else
  2735.             {
  2736.                 inactive = true;
  2737.                 editButton->Disable();
  2738.             }
  2739.             if (inactive)
  2740.                 deleteButton->Disable();
  2741.             else    
  2742.                 deleteButton->Enable();
  2743.             break;
  2744.         default:
  2745.             CPrefsMediator::ListenToMessage(inMessage, ioParam);
  2746.             break;
  2747.     }
  2748. }
  2749.  
  2750. void
  2751. CBrowserApplicationsMediator::LoadMainPane()
  2752. {
  2753.     CPrefsMediator::LoadMainPane();
  2754.     mMIMETable = (CMIMEListPane *)FindPaneByID(eHelperTable);
  2755.     XP_ASSERT(mMIMETable);
  2756.     mMIMETable->AddListener(this);
  2757.     TableCellT    currentCell= {1, 1};        // This has to be done after
  2758.     mMIMETable->SelectCell(currentCell);    // mMIMETable->AddListener(); to set the buttons.
  2759. }
  2760.  
  2761. void
  2762. CBrowserApplicationsMediator::WritePrefs()
  2763. {
  2764.     if (mModified)
  2765.     {
  2766.         CPrefs::sMimeTypes.DeleteAll(FALSE);
  2767.         XP_ASSERT(mMIMETable);
  2768.         TableIndexT rows, cols;
  2769.         mMIMETable->GetTableSize(rows, cols);
  2770.         for (int i = 1; i <= rows; i++)
  2771.         {
  2772.             CMIMEListPane::PrefCellInfo cellInfo;
  2773.             mMIMETable->GetCellInfo(cellInfo, i);
  2774.             
  2775.             cellInfo.fMapper->WriteMimePrefs();
  2776.             CMimeMapper* mapper = new CMimeMapper(*cellInfo.fMapper);
  2777.             CPrefs::sMimeTypes.InsertItemsAt(1, LArray::index_Last, &mapper);
  2778.         }
  2779.         for (Int32 i = 1; i <= mDeletedTypes.GetCount(); i++)
  2780.         {
  2781.             CMimeMapper* mapper;
  2782.             mDeletedTypes.FetchItemAt(i, &mapper);
  2783.             PREF_DeleteBranch(mapper->GetBasePref());
  2784.         }
  2785.     }
  2786. }
  2787.  
  2788.  
  2789. enum
  2790. {
  2791.     eAuthorNameEditField = 13201,
  2792.     eAutoSaveCheckBox,
  2793.     eAutoSaveIntervalEditField,
  2794.     eNewDocTemplateURLEditField,
  2795.     eRestoreDefaultButton,
  2796.     eChooseLocalFileButton,
  2797.     eUseHTMLSourceEditorBox,
  2798.     eHTMLSourceEditorFilePicker,
  2799.     eUseImageEditorBox,
  2800.     eImageEditorFilePicker
  2801. };
  2802.  
  2803. #ifdef EDITOR
  2804.  
  2805. CEditorMainMediator::CEditorMainMediator(LStream*)
  2806. :    CPrefsMediator(class_ID)
  2807. ,    mNewDocURLLocked(false)
  2808. {
  2809. }
  2810.  
  2811. void
  2812. CEditorMainMediator::ListenToMessage(MessageT inMessage, void *ioParam)
  2813. {
  2814.     switch (inMessage)
  2815.     {
  2816.         case eUseHTMLSourceEditorBox:
  2817.             CFilePicker *fPicker =
  2818.                     (CFilePicker *)FindPaneByID(eHTMLSourceEditorFilePicker);
  2819.             XP_ASSERT(fPicker);
  2820.             if (!fPicker->WasSet() && *(Int32 *)ioParam)
  2821.             {    // If the user has clicked the checkbox and the file picker is not set
  2822.                 // then we may want to trigger the file picker
  2823.                 if (mNeedsPrefs)
  2824.                 {
  2825.                     // If mNeedsPrefs, then we are setting up the pane. If the picker
  2826.                     // is not set (can happen if the app file was physically deleted),
  2827.                     // then we need to unset the "use" check box.
  2828.                     LGACheckbox *checkbox =
  2829.                             (LGACheckbox *)FindPaneByID(inMessage);
  2830.                     XP_ASSERT(checkbox);
  2831.                     checkbox->SetValue(false);
  2832.                 }
  2833.                 else
  2834.                 {
  2835.                     fPicker->ListenToMessage(msg_Browse, nil);
  2836.                     if (!fPicker->WasSet())
  2837.                     {    // If the file picker is still unset, that means that the user
  2838.                         // cancelled the file browse so we don't want the checkbox set.
  2839.                         LGACheckbox *checkbox =
  2840.                                 (LGACheckbox *)FindPaneByID(inMessage);
  2841.                         XP_ASSERT(checkbox);
  2842.                         checkbox->SetValue(false);
  2843.                     }
  2844.                 }
  2845.             }
  2846.             break;
  2847.         case eUseImageEditorBox:
  2848.             fPicker = (CFilePicker *)FindPaneByID(eImageEditorFilePicker);
  2849.             XP_ASSERT(fPicker);
  2850.             if (!fPicker->WasSet() && *(Int32 *)ioParam)
  2851.             {    // If the user has clicked the checkbox and the file picker is not set
  2852.                 // then we may want to trigger the file picker
  2853.                 if (mNeedsPrefs)
  2854.                 {
  2855.                     // If mNeedsPrefs, then we are setting up the pane. If the picker
  2856.                     // is not set (can happen if the app file was physically deleted),
  2857.                     // then we need to unset the "use" check box.
  2858.                     LGACheckbox *checkbox =
  2859.                             (LGACheckbox *)FindPaneByID(inMessage);
  2860.                     XP_ASSERT(checkbox);
  2861.                     checkbox->SetValue(false);
  2862.                 }
  2863.                 else
  2864.                 {
  2865.                     fPicker->ListenToMessage(msg_Browse, nil);
  2866.                     if (!fPicker->WasSet())
  2867.                     {    // If the file picker is still unset, that means that the user
  2868.                         // cancelled the file browse so we don't want the checkbox set.
  2869.                         LGACheckbox *checkbox =
  2870.                                 (LGACheckbox *)FindPaneByID(inMessage);
  2871.                         XP_ASSERT(checkbox);
  2872.                         checkbox->SetValue(false);
  2873.                     }
  2874.                 }
  2875.             }
  2876.             break;
  2877.         case msg_FolderChanged:
  2878.             PaneIDT    checkBoxID;
  2879.             switch (((CFilePicker *)ioParam)->GetPaneID())
  2880.             {
  2881.                 case eHTMLSourceEditorFilePicker:
  2882.                     checkBoxID = eUseHTMLSourceEditorBox;
  2883.                     break;
  2884.                 case eImageEditorFilePicker:
  2885.                     checkBoxID = eUseImageEditorBox;
  2886.                     break;
  2887.             }
  2888.             LGACheckbox *checkbox = (LGACheckbox *)FindPaneByID(checkBoxID);
  2889.             XP_ASSERT(checkbox);
  2890.             checkbox->SetValue(true);
  2891.             break;
  2892.         case eChooseLocalFileButton:
  2893.             SetEditFieldWithLocalFileURL(    eNewDocTemplateURLEditField,
  2894.                                             mNewDocURLLocked);
  2895.             break;
  2896.         case eRestoreDefaultButton:
  2897.             RestoreDefaultURL();
  2898.             break;
  2899.         default:
  2900.             CPrefsMediator::ListenToMessage(inMessage, ioParam);
  2901.             break;
  2902.     }
  2903. }
  2904.  
  2905. void
  2906. CEditorMainMediator::RestoreDefaultURL()
  2907. {
  2908.     ReadDefaultPref(eNewDocTemplateURLEditField);
  2909. }
  2910.  
  2911. Boolean
  2912. CEditorMainMediator::SaveIntervalValidationFunc(CValidEditField *saveInterval)
  2913. {
  2914.     // If the checkbox isn't set then this value is really
  2915.     // ignored, so I will only put up the alert if the checkbox
  2916.     // is set, but I will force a valid value in any case.
  2917.  
  2918.     Boolean        result = true;
  2919.  
  2920.     // force valid value
  2921.     if (1 > saveInterval->GetValue())
  2922.     {
  2923.         int32    newInterval = 10;
  2924.         PREF_GetDefaultIntPref("editor.auto_save_delay", &newInterval);
  2925.         saveInterval->SetValue(newInterval);
  2926.         saveInterval->SelectAll();
  2927.         result = false;
  2928.     }
  2929.     if (!result)    // if the value is within the range, who cares
  2930.     {
  2931.         // Check for the check box...
  2932.         // We are assuming that the checkbox is a sub of the field's superview.
  2933.         LView    *superView = saveInterval->GetSuperView();
  2934.         XP_ASSERT(superView);
  2935.         LGACheckbox    *checkbox =
  2936.                 (LGACheckbox *)superView->FindPaneByID(eAutoSaveCheckBox);
  2937.         XP_ASSERT(checkbox);
  2938.         if (checkbox->GetValue())
  2939.         {
  2940.             StPrepareForDialog    prepare;
  2941.             ::StopAlert(1067, NULL);
  2942.         }
  2943.         else
  2944.         {
  2945.             result = true;    // go ahead and let them switch (after correcting the value)
  2946.                             // if the checkbox isn't set
  2947.         }
  2948.     }
  2949.     return result;
  2950. }
  2951.  
  2952. //-----------------------------------
  2953. void CEditorMainMediator::LoadMainPane()
  2954. //-----------------------------------
  2955. {
  2956.     CPrefsMediator::LoadMainPane();
  2957.     SetValidationFunction(eAutoSaveIntervalEditField, SaveIntervalValidationFunc);
  2958. }
  2959.  
  2960. #endif // EDITOR
  2961.  
  2962. enum
  2963. {
  2964.     eMaintainLinksBox = 13401,
  2965.     eKeepImagesBox,
  2966.     ePublishLocationField,
  2967.     eBrowseLocationField
  2968. };
  2969.  
  2970. enum
  2971. {
  2972.     eOnlineRButton = 13501,
  2973.     eOfflineRButton,
  2974.     eAskMeRButton
  2975. };
  2976.  
  2977. enum
  2978. {
  2979.     eImagesBox = 13901,
  2980.     eJaveBox,
  2981.     eJavaScriptBox,
  2982.     eStyleSheetBox,
  2983.     eAutoInstallBox,
  2984.     eFTPPasswordBox,
  2985.     eCookieAlwaysRButton,
  2986.     eCookieOriginatingServerRButton,
  2987.     eCookieNeverRButton,
  2988.     eCookieWarningBox
  2989. };
  2990.  
  2991. enum
  2992. {
  2993.     eDiskCacheEditField = 14101,
  2994.     eClearDiskCacheButton,
  2995.     eOncePerSessionRButton,
  2996.     eEveryUseRButton,
  2997.     eNeverRButton,
  2998.     eCacheLocationFilePicker
  2999. };
  3000.  
  3001. CAdvancedCacheMediator::CAdvancedCacheMediator(LStream*)
  3002. :    CPrefsMediator(class_ID)
  3003. {
  3004. }
  3005.  
  3006. void CAdvancedCacheMediator::ListenToMessage(MessageT inMessage, void *ioParam)
  3007. {
  3008.     switch (inMessage)
  3009.     {
  3010.         case eClearDiskCacheButton:
  3011.             ClearDiskCacheNow();
  3012.             break;
  3013.         default:
  3014.             CPrefsMediator::ListenToMessage(inMessage, ioParam);
  3015.             break;
  3016.     }
  3017. }
  3018.  
  3019. void CAdvancedCacheMediator::ClearDiskCacheNow()
  3020. {
  3021.     int32 originalDiskCacheSize;    // in Kbytes
  3022.     PREF_GetIntPref("browser.cache.disk_cache_size", &originalDiskCacheSize);
  3023.     if (originalDiskCacheSize)    // if the current cache size is zero then do nothing
  3024.     {
  3025.         UDesktop::Deactivate();
  3026.         short    response = ::CautionAlert(eClearDiskCacheButton, NULL);    
  3027.         UDesktop::Activate();
  3028.         if (1 == response)
  3029.         {
  3030.             TrySetCursor(watchCursor);
  3031.             
  3032.             // This is the approved way to clear the cache
  3033.             PREF_SetIntPref("browser.cache.disk_cache_size", 0);
  3034.             PREF_SetIntPref("browser.cache.disk_cache_size", originalDiskCacheSize);
  3035.             
  3036.             ::SetCursor( &UQDGlobals::GetQDGlobals()->arrow );
  3037.         }
  3038.     }
  3039. }
  3040.  
  3041. enum
  3042. {
  3043.     eManualProxyDialogResID = 12006,
  3044.     eDirectConnectRButton = 14201,
  3045.     eManualRButton,
  3046.     eViewProxyConfigButton,
  3047.     eAutoProxyConfigRButton,
  3048.     eConfigURLTextBox,
  3049.     eReloadButton,
  3050.     eFTPEditField,
  3051.     eFTPPortEditField,
  3052.     eGopherEditField,
  3053.     eGopherPortEditField,
  3054.     eHTTPEditField,
  3055.     eHTTPPortEditField,
  3056.     eSSLEditField,
  3057.     eSSLPortEditField,
  3058.     eWAISEditField,
  3059.     eWAISPortEditField,
  3060.     eNoProxyEditField,
  3061.     eSOCKSEditField,
  3062.     eSOCKSPortEditField
  3063. };
  3064.  
  3065. CAdvancedProxiesMediator::Protocol::Protocol():
  3066. mProtocolServer(nil),
  3067. mServerLocked(false),
  3068. mProtocolPort(0),
  3069. mPortLocked(false)
  3070. {
  3071. }
  3072.  
  3073. CAdvancedProxiesMediator::Protocol::Protocol(const Protocol& original):
  3074. mProtocolServer(nil),
  3075. mServerLocked(original.mServerLocked),
  3076. mProtocolPort(original.mProtocolPort),
  3077. mPortLocked(original.mPortLocked)
  3078. {
  3079.     if (original.mProtocolServer)
  3080.     {
  3081.         mProtocolServer = XP_STRDUP(original.mProtocolServer);
  3082.     }
  3083.     // else set to nil above
  3084. }
  3085.  
  3086. CAdvancedProxiesMediator::Protocol::~Protocol()
  3087. {
  3088.     if (mProtocolServer)
  3089.     {
  3090.         XP_FREE(mProtocolServer);
  3091.     }
  3092. }
  3093.  
  3094. void
  3095. CAdvancedProxiesMediator::Protocol::LoadFromPref(const char *serverPrefName,
  3096.                                                     const char *portPrefName)
  3097. {
  3098.     mServerLocked    = PREF_PrefIsLocked(serverPrefName);
  3099.     mPortLocked        = PREF_PrefIsLocked(portPrefName);
  3100.     PREF_CopyCharPref(serverPrefName, &mProtocolServer);
  3101.     PREF_GetIntPref(portPrefName, &mProtocolPort);
  3102. }
  3103.  
  3104. void
  3105. CAdvancedProxiesMediator::Protocol::WriteToPref(    const char *serverPrefName,
  3106.                                                     const char *portPrefName)
  3107. {
  3108.     if (!mServerLocked)
  3109.     {
  3110.         char    *currentStringValue = nil;
  3111.         PREF_CopyCharPref(serverPrefName, ¤tStringValue);
  3112.         if (!currentStringValue || strcmp(currentStringValue, mProtocolServer))
  3113.         {
  3114.             PREF_SetCharPref(serverPrefName, mProtocolServer);
  3115.         }
  3116.         if (currentStringValue)
  3117.         {
  3118.             XP_FREE(currentStringValue);
  3119.         }
  3120.     }
  3121.     if (!mPortLocked)
  3122.     {
  3123.         int32    currentIntValue;
  3124.         currentIntValue = mProtocolPort + 1;    // anything != mCheckInterval
  3125.         PREF_GetIntPref(portPrefName, ¤tIntValue);
  3126.         if (currentIntValue != mProtocolPort)
  3127.         {
  3128.             PREF_SetIntPref(portPrefName, mProtocolPort);
  3129.         }
  3130.     }
  3131. }
  3132.  
  3133. void
  3134. CAdvancedProxiesMediator::Protocol::PreEdit(    LView *dialog,
  3135.                                                 ResIDT serverEditID,
  3136.                                                 ResIDT portEditID)
  3137. {
  3138.     LEditField        *server =
  3139.                         (LEditField *)dialog->FindPaneByID(serverEditID);
  3140.     XP_ASSERT(server);
  3141.     if (mProtocolServer)
  3142.     {
  3143.         LStr255    protocolServerPStr(mProtocolServer);
  3144.         server->SetDescriptor(protocolServerPStr);
  3145.         server->SelectAll();
  3146.     }
  3147.     if (mServerLocked)
  3148.     {
  3149.         server->Disable();
  3150.     }
  3151.     LEditField *port =
  3152.                     (LEditField *)dialog->FindPaneByID(portEditID);
  3153.     XP_ASSERT(port);
  3154.     port->SetValue(mProtocolPort);
  3155.     port->SelectAll();
  3156.     if (mPortLocked)
  3157.     {
  3158.         port->Disable();
  3159.     }
  3160. }
  3161.  
  3162. void
  3163. CAdvancedProxiesMediator::Protocol::PostEdit(LView *dialog,
  3164.                                                 ResIDT serverEditID,
  3165.                                                 ResIDT portEditID)
  3166. {
  3167.     LEditField        *server =
  3168.                         (LEditField *)dialog->FindPaneByID(serverEditID);
  3169.     XP_ASSERT(server);
  3170.     Str255    fieldValue;
  3171.     if (!mServerLocked)
  3172.     {
  3173.         server->GetDescriptor(fieldValue);
  3174.         int        stringLength = fieldValue[0];
  3175.         char    *serverString = (char *)XP_ALLOC(stringLength + 1);
  3176.         if (serverString)
  3177.         {
  3178.             strncpy(serverString, (char *)&fieldValue[1], stringLength + 1);
  3179.             serverString[stringLength] = '\0';
  3180.             if (mProtocolServer)
  3181.             {
  3182.                 XP_FREE(mProtocolServer);
  3183.             }
  3184.             mProtocolServer = serverString;
  3185.         }
  3186.     }
  3187.     LEditField *port =
  3188.                     (LEditField *)dialog->FindPaneByID(portEditID);
  3189.     XP_ASSERT(port);
  3190.     if (!mPortLocked)
  3191.     {
  3192.         mProtocolPort = port->GetValue();
  3193.     }
  3194. }
  3195.  
  3196.  
  3197.  
  3198. CAdvancedProxiesMediator::ManualProxy::ManualProxy():
  3199. mNoProxyList(nil),
  3200. mNoProxyListLocked(false)
  3201. {
  3202. }
  3203.  
  3204. CAdvancedProxiesMediator::ManualProxy::ManualProxy(const ManualProxy& original):
  3205. mFTP(original.mFTP),
  3206. mGopher(original.mGopher),
  3207. mHTTP(original.mHTTP),
  3208. mSSL(original.mSSL),
  3209. mWAIS(original.mWAIS),
  3210. mNoProxyList(nil),
  3211. mNoProxyListLocked(original.mNoProxyListLocked),
  3212. mSOCKS(original.mSOCKS)
  3213. {
  3214.     if (original.mNoProxyList)
  3215.     {
  3216.         mNoProxyList = XP_STRDUP(original.mNoProxyList);
  3217.     }
  3218.     // else set to nil above
  3219. }
  3220.  
  3221. CAdvancedProxiesMediator::ManualProxy::~ManualProxy()
  3222. {
  3223.     XP_FREEIF(mNoProxyList);
  3224. }
  3225.  
  3226. void
  3227. CAdvancedProxiesMediator::ManualProxy::LoadPrefs()
  3228. {
  3229.     mFTP.LoadFromPref("network.proxy.ftp", "network.proxy.ftp_port");
  3230.     mGopher.LoadFromPref("network.proxy.gopher", "network.proxy.gopher_port");
  3231.     mHTTP.LoadFromPref("network.proxy.http", "network.proxy.http_port");
  3232.     mWAIS.LoadFromPref("network.proxy.wais", "network.proxy.wais_port");
  3233.     mSSL.LoadFromPref("network.proxy.ssl", "network.proxy.ssl_port");
  3234.  
  3235.     mNoProxyListLocked        = PREF_PrefIsLocked("network.proxy.no_proxies_on");
  3236.     PREF_CopyCharPref("network.proxy.no_proxies_on", &mNoProxyList);
  3237.  
  3238.     mSOCKS.LoadFromPref("network.hosts.socks_server", "network.hosts.socks_serverport");
  3239. }
  3240.  
  3241. void
  3242. CAdvancedProxiesMediator::ManualProxy::WritePrefs()
  3243. {
  3244.     mFTP.WriteToPref("network.proxy.ftp", "network.proxy.ftp_port");
  3245.     mGopher.WriteToPref("network.proxy.gopher", "network.proxy.gopher_port");
  3246.     mHTTP.WriteToPref("network.proxy.http", "network.proxy.http_port");
  3247.     mWAIS.WriteToPref("network.proxy.wais", "network.proxy.wais_port");
  3248.     mSSL.WriteToPref("network.proxy.ssl", "network.proxy.ssl_port");
  3249.  
  3250.     char    *currentStringValue = nil;
  3251.     if (!mNoProxyListLocked)
  3252.     {
  3253.         PREF_CopyCharPref("network.proxy.no_proxies_on", ¤tStringValue);
  3254.         if (!currentStringValue || strcmp(currentStringValue, mNoProxyList))
  3255.         {
  3256.             PREF_SetCharPref("network.proxy.no_proxies_on", mNoProxyList);
  3257.         }
  3258.         if (currentStringValue)
  3259.         {
  3260.             XP_FREE(currentStringValue);
  3261.         }
  3262.     }
  3263.     mSOCKS.WriteToPref("network.hosts.socks_server", "network.hosts.socks_serverport");
  3264. }
  3265.  
  3266.  
  3267. Boolean
  3268. CAdvancedProxiesMediator::ManualProxy::EditPrefs()
  3269. {
  3270.     Boolean    result = false;
  3271.  
  3272.     StDialogHandler    handler(eManualProxyDialogResID, nil);
  3273.     LWindow            *dialog = handler.GetDialog();
  3274.  
  3275.     mFTP.PreEdit(dialog, eFTPEditField, eFTPPortEditField);
  3276.     mGopher.PreEdit(dialog, eGopherEditField, eGopherPortEditField);
  3277.     mHTTP.PreEdit(dialog, eHTTPEditField, eHTTPPortEditField);
  3278.     mSSL.PreEdit(dialog, eSSLEditField, eSSLPortEditField);
  3279.     mWAIS.PreEdit(dialog, eWAISEditField, eWAISPortEditField);
  3280.  
  3281.     LEditField        *noProxy =
  3282.                         (LEditField *)dialog->FindPaneByID(eNoProxyEditField);
  3283.     XP_ASSERT(noProxy);
  3284.     if (mNoProxyList)
  3285.     {
  3286.         LStr255    noProxyPStr(mNoProxyList);
  3287.         noProxy->SetDescriptor(noProxyPStr);
  3288.         noProxy->SelectAll();
  3289.     }
  3290.     if (mNoProxyListLocked)
  3291.     {
  3292.         noProxy->Disable();
  3293.     }
  3294.  
  3295.     mSOCKS.PreEdit(dialog, eSOCKSEditField, eSOCKSPortEditField);
  3296.  
  3297.     // Run the dialog
  3298.     MessageT message = msg_Nothing;
  3299.     do
  3300.     {
  3301.         message = handler.DoDialog();
  3302.         if (msg_Nothing != message && msg_OK != message  && msg_Cancel != message)
  3303.         {
  3304.             message = msg_Nothing;
  3305.         }
  3306.     } while (msg_Nothing == message);
  3307.  
  3308.     if (msg_OK == message)
  3309.     {
  3310.         result = true;
  3311.         // read all the controls back to the struct
  3312.  
  3313.         mFTP.PostEdit(dialog, eFTPEditField, eFTPPortEditField);
  3314.         mGopher.PostEdit(dialog, eGopherEditField, eGopherPortEditField);
  3315.         mHTTP.PostEdit(dialog, eHTTPEditField, eHTTPPortEditField);
  3316.         mSSL.PostEdit(dialog, eSSLEditField, eSSLPortEditField);
  3317.         mWAIS.PostEdit(dialog, eWAISEditField, eWAISPortEditField);
  3318.  
  3319.         Str255    fieldValue;
  3320.         if (!mNoProxyListLocked)
  3321.         {
  3322.             noProxy->GetDescriptor(fieldValue);
  3323.             int        stringLength = fieldValue[0];
  3324.             char    *noProxyString = (char *)XP_ALLOC(stringLength + 1);
  3325.             if (noProxyString)
  3326.             {
  3327.                 strncpy(noProxyString, (char *)&fieldValue[1], stringLength + 1);
  3328.                 noProxyString[stringLength] = '\0';
  3329.                 if (mNoProxyList)
  3330.                 {
  3331.                     XP_FREE(mNoProxyList);
  3332.                 }
  3333.                 mNoProxyList = noProxyString;
  3334.             }
  3335.         }
  3336.         mSOCKS.PostEdit(dialog, eSOCKSEditField, eSOCKSPortEditField);
  3337.     }
  3338.     else
  3339.     {
  3340.         result = false;
  3341.     }
  3342.     return result;
  3343. }
  3344.  
  3345.  
  3346. CAdvancedProxiesMediator::CAdvancedProxiesMediator(LStream*)
  3347. :    CPrefsMediator(class_ID)
  3348. ,    mManualProxy(nil)
  3349. {
  3350. }
  3351.  
  3352. void
  3353. CAdvancedProxiesMediator::ListenToMessage(MessageT inMessage, void *ioParam)
  3354. {
  3355.     switch (inMessage)
  3356.     {
  3357.         case msg_ControlClicked:
  3358.             break;
  3359.         case eViewProxyConfigButton:
  3360.             LGARadioButton    *theButton = (LGARadioButton *)FindPaneByID(eManualRButton);
  3361.             XP_ASSERT(theButton);
  3362.             if (!theButton->GetValue())
  3363.             {
  3364.                 theButton->SetValue(true);
  3365.             }
  3366.             ManualProxy    *tempManualProxy;
  3367.             if (!mManualProxy)
  3368.             {
  3369.                 tempManualProxy = new ManualProxy;
  3370.                 tempManualProxy->LoadPrefs();
  3371.             }
  3372.             else
  3373.             {
  3374.                 tempManualProxy = new ManualProxy(*mManualProxy);
  3375.             }
  3376.             if (tempManualProxy->EditPrefs())
  3377.             {
  3378.                 if (mManualProxy)
  3379.                 {
  3380.                     delete mManualProxy;
  3381.                 }
  3382.                 mManualProxy = tempManualProxy;
  3383.             }
  3384.             else
  3385.             {
  3386.                 delete tempManualProxy;
  3387.             }
  3388.             break;
  3389.         case eReloadButton:
  3390.             LEditField    *theField = (LEditField *)FindPaneByID(eConfigURLTextBox);
  3391.             XP_ASSERT(theField);
  3392.             Str255    fieldValue;
  3393.             theField->GetDescriptor(fieldValue);
  3394.             int        stringLength = fieldValue[0];
  3395.             char    *prefString = (char *)XP_ALLOC(stringLength + 1);
  3396.             XP_ASSERT(prefString);
  3397.             strncpy(prefString, (char *)&fieldValue[1], stringLength);
  3398.             prefString[stringLength] = '\0';
  3399.             NET_SetProxyServer(PROXY_AUTOCONF_URL, prefString);
  3400.             NET_ReloadProxyConfig(nil);    // The context is unused in the function.
  3401.             XP_FREE(prefString);
  3402.             break;
  3403.         default:
  3404.             CPrefsMediator::ListenToMessage(inMessage, ioParam);
  3405.             break;
  3406.     }
  3407. }
  3408.  
  3409. //-----------------------------------
  3410. void CAdvancedProxiesMediator::WritePrefs()
  3411. //-----------------------------------
  3412. {
  3413.     if (mManualProxy)
  3414.         mManualProxy->WritePrefs();
  3415. }
  3416.  
  3417. #ifdef MOZ_MAIL_NEWS
  3418. enum
  3419. {
  3420.     eMessageSizeLimitBox = 13801,
  3421.     eMessageSizeLimitEditField,
  3422.     eKeepByDaysRButton,
  3423.     eKeepDaysEditField,
  3424.     eKeepAllRButton,
  3425.     eKeepByCountRButton,
  3426.     eKeepCountEditField,
  3427.     eKeepOnlyUnreadBox,
  3428.     eCompactingBox,
  3429.     eCompactingEditField
  3430. };
  3431.  
  3432. CAdvancedDiskSpaceMediator::CAdvancedDiskSpaceMediator(LStream*)
  3433. :    CPrefsMediator(class_ID)
  3434. {
  3435. }
  3436.  
  3437. void
  3438. CAdvancedDiskSpaceMediator::ListenToMessage(MessageT inMessage, void *ioParam)
  3439. {
  3440.     switch (inMessage)
  3441.     {
  3442. //        case eNewsMessagesMoreButton:
  3443. //            break;
  3444.         default:
  3445.             CPrefsMediator::ListenToMessage(inMessage, ioParam);
  3446.             break;
  3447.     }
  3448. }
  3449.  
  3450. // static
  3451. Boolean
  3452. CAdvancedDiskSpaceMediator::DiskSpaceValidationFunc(CValidEditField *editField)
  3453. {
  3454.     Boolean okeyDokey = true;
  3455.  
  3456.     // force valid value
  3457.     if (1 > editField->GetValue())
  3458.     {
  3459.         const char *prefName = nil;
  3460.         PaneIDT    controllingPaneID;
  3461.         switch (editField->GetPaneID())
  3462.         {
  3463.             case eMessageSizeLimitEditField:
  3464.                 controllingPaneID = eMessageSizeLimitBox;
  3465.                 prefName = "mail.max_size";
  3466.                 break;
  3467.             case eKeepDaysEditField:
  3468.                 controllingPaneID = eKeepByDaysRButton;
  3469.                 prefName = "news.keep.days";
  3470.                 break;
  3471.             case eKeepCountEditField:
  3472.                 controllingPaneID = eKeepByCountRButton;
  3473.                 prefName = "news.keep.count";
  3474.                 break;
  3475.             case eCompactingEditField:
  3476.                 controllingPaneID = eCompactingBox;
  3477.                 prefName = "mail.purge_threshhold";
  3478.                 break;
  3479.             default:
  3480.                 break;    // XP_ASSERT()?
  3481.         }
  3482.         LControl* controllingPane = nil;
  3483.         if (controllingPaneID)
  3484.             controllingPane =
  3485.             (LControl *)((editField->GetSuperView())->FindPaneByID(controllingPaneID));
  3486.         XP_ASSERT(controllingPane);
  3487.         int32 newValue;
  3488.         PREF_GetDefaultIntPref(prefName, &newValue);
  3489.         editField->SetValue(newValue);
  3490.         editField->SelectAll();
  3491.         okeyDokey = (controllingPane->GetValue() == 0);
  3492.     }
  3493.     if (!okeyDokey)
  3494.     {                                            // If the value is within the range, or
  3495.         StPrepareForDialog prepare;                // the control is not on, who cares?
  3496.         ::StopAlert(1067, NULL);
  3497.     }
  3498.     return okeyDokey;
  3499. }
  3500.  
  3501. //-----------------------------------
  3502. void CAdvancedDiskSpaceMediator::LoadMainPane()
  3503. //-----------------------------------
  3504. {
  3505.     CPrefsMediator::LoadMainPane();
  3506.     SetValidationFunction(eMessageSizeLimitEditField, DiskSpaceValidationFunc);
  3507.     SetValidationFunction(eKeepDaysEditField, DiskSpaceValidationFunc);
  3508.     SetValidationFunction(eKeepCountEditField, DiskSpaceValidationFunc);
  3509.     SetValidationFunction(eCompactingEditField, DiskSpaceValidationFunc);
  3510. }
  3511.  
  3512. #endif // MOZ_MAIL_NEWS
  3513.  
  3514. //-----------------------------------
  3515. void UAssortedPrefMediators::RegisterViewClasses()
  3516. //-----------------------------------
  3517. {
  3518.     RegisterClass_(CEditFieldControl);
  3519.  
  3520.     RegisterClass_( CEditMIMEWindow);
  3521.     RegisterClass_( CMIMEListPane);
  3522.     RegisterClass_(CColorButton);
  3523.     RegisterClass_( CFilePicker);
  3524.  
  3525.     RegisterClass_(COtherSizeDialog);
  3526.     RegisterClass_(CSizePopup);
  3527.     
  3528.     RegisterClass_( CGAEditBroadcaster);
  3529.     RegisterClass_(CValidEditField);
  3530.     RegisterClass_( LCicnButton);
  3531. //    RegisterClass_( 'sbox', (ClassCreatorFunc)OneClickLListBox::CreateOneClickLListBox );
  3532.     RegisterClass_(OneRowLListBox);    // added by ftang
  3533.     UPrefControls::RegisterPrefControlViews();
  3534. } // CPrefsDialog::RegisterViewClasses
  3535.