bmpprefs.cpp

Go to the documentation of this file.
00001 // $Id: bmpprefs.cpp 1530 2006-07-25 15:25:13Z luke $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 // 
00099 // BmpPrefs.cpp
00100 //
00101 // This file implements the dialogue box that allows the user to set the export bitmaps
00102 // preferences.
00103 
00104 /*
00105 */
00106 
00107 #include "camtypes.h"
00108 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 //#include "spread.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 #include "page.h"
00111 #include "layer.h"
00112 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00113 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00114 //#include "dlgtypes.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00115 //#include "resource.h"
00116 #include "bmpprefs.h"
00117 //#include "bmpres.h"       // general bitmap filter based resources
00118 //#include "accures.h"  // general Accusoft dll resources
00119 //#include "simon.h"
00120 //#include "dialogop.h" // DialogOp header - in camtypes.h [AUTOMATICALLY REMOVED]
00121 #include "dlgmgr.h"     // Dialog manager class
00122 //#include "msg.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00123 //#include "rikdlg.h"       // _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER)
00124 #include "osrndrgn.h"
00125 #include "grndrgn.h"    // for max bitmap width function
00126 #include "bitfilt.h"    // BaseBitmapFilter 
00127 //#include "justin2.h"
00128 //#include "units.h"        // for pixel units - in camtypes.h [AUTOMATICALLY REMOVED]
00129 //#include "will3.h"
00130 //#include "reshlpid.h"
00131 #include "makebmp.h"
00132 #include "helpuser.h"
00133 //#include "accuflts.h" // PNG and TI-GIFF filter types
00134 //#include "xshelpid.h"
00135 //#include "filtrres.h" // _R(IDS_BMPPREFS_DPITOOSMALL) _R(IDS_BMPPREFS_DPITOOBIG)
00136 #include "exjpeg.h"
00137 #include "bmpfiltr.h"
00138 #include "pngfiltr.h"
00139 #ifndef WEBSTER
00140 //#include "extfilts.h"
00141 #endif //WEBSTER
00142 //#include "simon.h"
00143 #include "impexpop.h"   // BitmapExportParam
00144 #include "fileutil.h"
00145 //#include "bmpsdlg.h"  // BmpDlgParam
00146 //#include "cxfrec.h"       // for CXaraFileRecord - in camtypes.h [AUTOMATICALLY REMOVED]
00147 #include "ngprop.h"     // for the NamedExportProp::m_fApplyNotExport flag.
00148 //#include "bmpreres.h" // for _R(IDS_PREVIEW_APPLY)
00149 //#include "registry.h"
00150 //#include "desnotes.h"
00151 #include "bmpalint.h"   // for BitmapExportPaletteInterface::InvalidateSortedPalette()
00152 //#include "oilfltrs.h" // for the find filter fn - in camtypes.h [AUTOMATICALLY REMOVED]
00153 #include "slicehelper.h"
00154 #include "fillattr2.h"
00155 
00156 // This is not compulsory, but you may as well put it in so that the correct version
00157 // of your file can be registered in the .exe
00158 DECLARE_SOURCE("$Revision: 1530 $");
00159 
00160 // An implement to match the Declare in the .h file.
00161 // If you have many classes, it is recommended to place them all together, here at the start of the file
00162 PORTNOTE("other","Removed BmpPrefsDlg - derived from DialogOp")
00163 #ifndef EXCLUDE_FROM_XARALX
00164 CC_IMPLEMENT_DYNCREATE(BmpPrefsDlg, DialogOp)
00165 CC_IMPLEMENT_DYNCREATE(JPEGExportPrefsDialog, BmpPrefsDlg)
00166 CC_IMPLEMENT_DYNCREATE(PhotoCDDlg, DialogOp)
00167 #endif
00168 
00169 CC_IMPLEMENT_DYNCREATE(BitmapExportOptions, OpParam)
00170 CC_IMPLEMENT_MEMDUMP(PhotoCDDlgParam, OpParam)
00171 
00172 // This will get Camelot to display the filename and linenumber of any memory allocations
00173 // that are not released at program exit
00174 #define new CAM_DEBUG_NEW
00175 #define OPTION_ONE 0
00176 #define OPTION_FOUR 4
00177 
00178 TCHAR OPTOKEN_JPGPREFSDLG[] = _T("JPGPrefsDlg");
00179 
00180 /********************************************************************************************
00181 
00182     Preference: DefaultExportFilterPath
00183     Section:    Filters
00184     Range:      Any old rubbish really
00185     Purpose:    The path to default to when opening the Export File dialog
00186 
00187 ********************************************************************************************/ 
00188 // String_256 BitmapExportOptions::g_DefaultPath;
00189 
00190 /********************************************************************************************
00191 
00192     Preference: HTMLToClipboard
00193     Section:    Filters
00194     Range:      FALSE, ranging all the way to TRUE
00195     Purpose:    Whether we should put an HTML tag on the clipboard. FALSE by default.
00196 
00197 ********************************************************************************************/ 
00198 BOOL BitmapExportOptions::ms_fPutHTMLTagOnClipboard = FALSE;
00199 TCHAR BitmapExportOptions::ms_strPutHTMLTagOnClipboard[]
00200                                             = _T("Filters\\PutHTMLTagOnClipboard");
00201 BOOL BitmapExportOptions::ms_IsBackGroundTransparent = TRUE;
00202 ANTIALIASING BitmapExportOptions::ms_Antialiasing = MINIMISE_VISIBLE_AA;
00203 BOOL BitmapExportOptions::ms_bSeparateLayerFiles = FALSE;
00204 
00205 
00206 
00207 /********************************************************************************************
00208 >   BitmapExportOptions::BitmapExportOptions()
00209 
00210     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00211     Created:    29/10/96
00212     Purpose:    Default constructor.
00213     See Also:   BaseBitmapFilter::CreateBitmapOptions()
00214 ********************************************************************************************/
00215 
00216 BitmapExportOptions::BitmapExportOptions() :
00217     m_SelectionType(SELECTION),         // BaseBitmapFilter uses these...
00218     m_OutputSize(0, 0),                 // And initialise the output size
00219     m_PixelOutputSize(0, 0),
00220     m_FilterID(INVALID),
00221     m_pBmpDlgParam(0),
00222     m_bSeparateLayerFiles(FALSE),
00223     m_bTempFileFlag(FALSE),
00224     m_NumColsInPalette(0),
00225     m_UseSystemColours(FALSE),
00226     m_fPutHTMLTagOnClipboard(ms_fPutHTMLTagOnClipboard), // default HTML to clipboard
00227     m_bValid(FALSE),                    // Always use this...
00228     m_DPI(0),
00229     m_Depth(0),
00230     m_TransparencyIndex(-1),            // WEBSTER - markn 5/2/97 - no transparent colour
00231     m_DialogID(0),                      // BmpPrefsDlg uses these...
00232     m_pFilterName(0),
00233     m_bTempFileExported(FALSE),         // export preview uses this
00234     m_Antialiasing(MINIMISE_VISIBLE_AA) // Always start with the highest quality option
00235 {
00236     m_Palette.NumberOfColours = 0;
00237     memset(&(m_Palette.Data), 0, sizeof(ExtendedPaletteEntry)*256);
00238 PORTNOTE("DesignNotes", "Removed use of DesignNotes")
00239 #if !defined(EXCLUDE_FROM_XARALX)
00240     m_UseDesignNotes = GetRegistryFlagForDesignNotes();
00241 #else
00242     m_UseDesignNotes = FALSE;
00243 #endif
00244     m__pLogicalPalette = NULL;
00245     m__NumberOfColoursUserRequested = 256;
00246     m__UseBrowserPalette = FALSE;
00247     m__UseSystemColoursInPalette = FALSE;
00248     m__UseWebSnapPalette = 0;
00249     m__UsePrimarySnapPalette = 1;
00250     m__PaletteIsValid = FALSE;
00251     m__BackgroundIsTransparent = TRUE;
00252     m__pPaletteOptimiser = NULL;
00253     m__HavePrimedOptimier = FALSE;
00254     m__TempFileMatchesExportOptions = FALSE;
00255     m_bCMYK = FALSE;
00256 }
00257 
00258 
00259 
00260 /********************************************************************************************
00261 >   BitmapExportOptions::BitmapExportOptions(const CDlgResID DialogID, 
00262                                         const FilterType FilterID, StringBase* pFilterName)
00263 
00264     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00265     Created:    29/10/96
00266     Purpose:    Allows options in the bitmap export dialog to be freely passed around
00267     See Also:   BaseBitmapFilter::CreateBitmapOptions()
00268 ********************************************************************************************/
00269 
00270 BitmapExportOptions::BitmapExportOptions(
00271                                 const CDlgResID DialogID, 
00272                                 const FilterType FilterID,
00273                                 const StringBase* pFilterName) :
00274     m_SelectionType(SELECTION),         // BaseBitmapFilter uses these...
00275     m_OutputSize(0, 0),                 // And initialise the output size
00276     m_PixelOutputSize(0, 0),
00277     m_FilterID(FilterID),
00278     m_pBmpDlgParam(0),
00279     m_bSeparateLayerFiles(FALSE),
00280     m_bTempFileFlag(FALSE),
00281     m_NumColsInPalette(0),
00282     m_UseSystemColours(FALSE),
00283     m_fPutHTMLTagOnClipboard(ms_fPutHTMLTagOnClipboard), // default HTML to clipboard
00284     m_bValid(FALSE),                    // Always use this...
00285     m_DPI(0),
00286     m_Depth(0),
00287     m_TransparencyIndex(-1),            // WEBsTER - markn 5/2/97 - no transparent colour
00288     m_DialogID(DialogID),               // BmpPrefsDlg uses these...
00289     m_pFilterName(pFilterName),
00290     m_bTempFileExported(FALSE),         // export preview uses this
00291     m_Antialiasing(MINIMISE_VISIBLE_AA) // Always start with the highest quality option
00292 {
00293     m_Palette.NumberOfColours = 0;
00294     memset(&(m_Palette.Data), 0, sizeof(ExtendedPaletteEntry)*256);
00295 PORTNOTE("DesignNotes", "Removed use of DesignNotes")
00296 #if !defined(EXCLUDE_FROM_XARALX)
00297     m_UseDesignNotes = GetRegistryFlagForDesignNotes();
00298 #else
00299     m_UseDesignNotes = FALSE;
00300 #endif
00301     m__pLogicalPalette = NULL;
00302     m__NumberOfColoursUserRequested = 256;
00303     m__UseBrowserPalette = FALSE;
00304     m__UseSystemColoursInPalette = FALSE;
00305     m__UseWebSnapPalette = 0;
00306     m__UsePrimarySnapPalette = 1;
00307     m__PaletteIsValid = FALSE;
00308     m__BackgroundIsTransparent = TRUE;
00309     m__pPaletteOptimiser = NULL;
00310     m__HavePrimedOptimier = FALSE;
00311     m__TempFileMatchesExportOptions = FALSE;
00312     m_bCMYK = FALSE;
00313 }
00314 
00315 // distructor to release any claimed memory
00316 BitmapExportOptions::~BitmapExportOptions()
00317 {
00318     // the export options manages the logical palette so this is deleted when the export options are deleted
00319     if (m__pLogicalPalette)
00320     {
00321         delete m__pLogicalPalette;
00322         m__pLogicalPalette = NULL;
00323     }
00324 
00325     // the cache for the palette optimiser which holds the stats on the image
00326     if (m__pPaletteOptimiser)
00327     {
00328         delete m__pPaletteOptimiser;
00329         m__pPaletteOptimiser = NULL;
00330     }
00331 }
00332 
00333 /********************************************************************************************
00334 >   BitmapExportOptions* BitmapExportOptions::MakeCopy()
00335 
00336     Author:     Stefan_Stoykov (Xara Group Ltd) <camelotdev@xara.com>
00337     Created:    19/05/97
00338     Purpose:    Makes a copy object of this object
00339     See Also:   BitmapExportOptions::CopyFrom()
00340 ********************************************************************************************/
00341 
00342 BitmapExportOptions* BitmapExportOptions::MakeCopy()
00343 {
00344     // Get the runtime class info on this object
00345     CCRuntimeClass* pCCRuntimeClass = GetRuntimeClass();
00346 
00347     // Create another object of the same type
00348     BitmapExportOptions* p = (BitmapExportOptions*) pCCRuntimeClass->CreateObject();
00349     if (p != 0)
00350     {
00351         // clear the exported file flag to prevent attempts to delete any temp files
00352         p->m_bTempFileExported = FALSE;
00353 
00354         // copy the contents accross
00355         p->CopyFrom(this);
00356     }
00357     
00358     return p;
00359 }
00360 
00361 
00362 
00363 /********************************************************************************************
00364 >   virtual BOOL BitmapExportOptions::CopyFrom(BitmapExportOptions* pOther) 
00365     Author:     Stefan_Stoykov (Xara Group Ltd) <camelotdev@xara.com>
00366     Created:    19/05/97
00367     Inputs:     pOther - the other BitmapExportOptions object to copy the data from
00368     Purpose:    Sets the contents of this object from the passed object
00369     See Also:   BitmapExportOptions::MakeCopy()
00370     Returns:    TRUE if pOther is of the same type as 'this' else FALSE (this is
00371                 a silly thing to return but the functions in derived classes kind of
00372                 require this now so it is a bit difficult to change)
00373 ********************************************************************************************/
00374 BOOL BitmapExportOptions::CopyFrom(BitmapExportOptions* pOther) 
00375 {
00376     if (pOther == 0)
00377         return FALSE;
00378 
00379     // Copy all the data items that can be copied for any type of BitmapExportOptions
00380     
00381     m_SelectionType                 = pOther->m_SelectionType;
00382     m_fPutHTMLTagOnClipboard        = pOther->m_fPutHTMLTagOnClipboard;
00383     m_Antialiasing                  = pOther->m_Antialiasing;
00384     m_UseDesignNotes                = pOther->m_UseDesignNotes;
00385     m_bSeparateLayerFiles           = pOther->m_bSeparateLayerFiles;
00386     m_bTempFileFlag                 = pOther->m_bTempFileFlag;
00387 
00388 
00389     if (IS_SAME_CLASS(pOther, this))
00390     {
00391         // Only copy these if we are copying from a class that is of the
00392         // same type
00393         
00394         m_OutputSize                = pOther->m_OutputSize;
00395         m_PixelOutputSize           = pOther->m_PixelOutputSize;
00396         m_FilterID                  = pOther->m_FilterID;
00397         m_pBmpDlgParam              = pOther->m_pBmpDlgParam;       
00398         m_NumColsInPalette          = pOther->m_NumColsInPalette;
00399         m_UseSystemColours          = pOther->m_UseSystemColours;
00400         m_TransparencyIndex         = pOther->m_TransparencyIndex;
00401         m_DialogID                  = pOther->m_DialogID;
00402         m_pFilterName               = pOther->m_pFilterName;
00403         m_bValid                    = pOther->m_bValid;
00404         m_bTempFileExported         = pOther->m_bTempFileExported;
00405         m_TempPath                  = pOther->m_TempPath;
00406         m_Depth                     = pOther->m_Depth; // move to derived classes
00407 
00408         // Added to stop the name gallery killing itself on export
00409         m_DPI                       = pOther->m_DPI;
00410 
00411         // It should be safe to copy the following for any file type but I have not tested this
00412         // so I am only copying them if they are of the same type for now - Jonathan.
00413 
00414         // smfix new ones added
00415         m__NumberOfColoursUserRequested = pOther->m__NumberOfColoursUserRequested;
00416         m__UseBrowserPalette            = pOther->m__UseBrowserPalette;
00417         m__UseSystemColoursInPalette    = pOther->m__UseSystemColoursInPalette;
00418         m__UseWebSnapPalette            = pOther->m__UseWebSnapPalette;
00419         m__UsePrimarySnapPalette        = pOther->m__UsePrimarySnapPalette;
00420         m__BackgroundIsTransparent      = pOther->m__BackgroundIsTransparent;
00421 
00422         // Also need to copy all the palette information over.  It should also be safe to copy
00423         // this but again, I have not tested this so I am going for the safe option - Jonathan.
00424         CopyPaletteInformationFrom(pOther);
00425         return TRUE;
00426     }
00427     else
00428     {
00429         return FALSE;
00430     }
00431 };
00432 
00433 
00434 
00435 /******************************************************************************************
00436 
00437 >   BOOL BitmapExportOptions::FileTypeChangeCopyFrom(BitmapExportOptions *pOther)
00438 
00439     Author:     Alex_Price (Xara Group Ltd) <camelotdev@xara.com>
00440 
00441     Created:    15/10/99
00442 
00443     Inputs:     pOther - A BitmapExportOptions object we want to make a copy of.
00444 
00445     Returns:    -
00446 
00447     Purpose:    Copies the information from the BitmapExportOptions object
00448                 passed in as the argument to the palette object in this class.
00449 
00450 ******************************************************************************************/
00451 
00452 BOOL BitmapExportOptions::FileTypeChangeCopyFrom(BitmapExportOptions *pOther)
00453 {
00454     m_SelectionType     = pOther->m_SelectionType;
00455     m_OutputSize        = pOther->m_OutputSize;
00456     m_PixelOutputSize   = pOther->m_PixelOutputSize;
00457     m_pBmpDlgParam      = pOther->m_pBmpDlgParam;       
00458     m_NumColsInPalette  = pOther->m_NumColsInPalette;
00459     m_UseSystemColours  = pOther->m_UseSystemColours;
00460     m_DPI               = pOther->m_DPI;
00461     m_Depth             = pOther->m_Depth;
00462     m_TransparencyIndex = pOther->m_TransparencyIndex;
00463     m_DialogID          = pOther->m_DialogID;
00464     m_bValid            = pOther->m_bValid;
00465     m_bTempFileExported = pOther->m_bTempFileExported;
00466     m_TempPath          = pOther->m_TempPath;
00467     m_fPutHTMLTagOnClipboard    = pOther->m_fPutHTMLTagOnClipboard;
00468     m_Antialiasing      = pOther->m_Antialiasing;
00469     m_UseDesignNotes    = pOther->m_UseDesignNotes;
00470     m_bSeparateLayerFiles = pOther->m_bSeparateLayerFiles;
00471     m_bTempFileFlag     = pOther->m_bTempFileFlag;
00472 
00473     // smfix new ones added
00474     m__NumberOfColoursUserRequested =   pOther->m__NumberOfColoursUserRequested;
00475     m__UseBrowserPalette =              pOther->m__UseBrowserPalette;
00476     m__UseSystemColoursInPalette =      pOther->m__UseSystemColoursInPalette;
00477     m__UseWebSnapPalette =              pOther->m__UseWebSnapPalette;
00478     m__UsePrimarySnapPalette =          pOther->m__UsePrimarySnapPalette;
00479     m__BackgroundIsTransparent =        pOther->m__BackgroundIsTransparent;
00480 
00481     // Also need to copy all the palette information over.
00482     CopyPaletteInformationFrom( pOther );
00483 
00484     return TRUE;
00485 }
00486 
00487 
00488 /******************************************************************************************
00489 >   void BitmapExportOptions::CopyPaletteInformationFrom( BitmapExportOptions* pOther )
00490     Author:     Alex_Price (Xara Group Ltd) <camelotdev@xara.com>
00491     Created:    13/08/99
00492     Inputs:     pOther - A BitmapExportOptions object we want to make a copy of.
00493     Purpose:    Copies the palette information from the BitmapExportOptions object
00494                 passed in as the argument to the palette object in this class.
00495 ******************************************************************************************/
00496 void BitmapExportOptions::CopyPaletteInformationFrom( BitmapExportOptions* pOther )
00497 {
00498     //  The first few times that this function is called, the palette passed in
00499     //  is uninitialised. If this is the case, then just make our palette a default one.
00500     if( ( pOther->m_Palette.NumberOfColours > 256 ) || ( pOther->m_Palette.NumberOfColours < 0 ) )
00501     {
00502         m_Palette.NumberOfColours = 0;
00503 
00504         INT32 i = 0;
00505         for( i=0; i < 256; i++ )
00506         {
00507             m_Palette.Data[ i ].Red                 = 0;
00508             m_Palette.Data[ i ].Green               = 0;
00509             m_Palette.Data[ i ].Blue                = 0;
00510             m_Palette.Data[ i ].Flags               = 0;
00511         }
00512         //  Finished here, so return.
00513         return;
00514     }
00515 
00516     //  Simply copy the entire palette over from pOther.
00517     m_Palette.NumberOfColours   = pOther->m_Palette.NumberOfColours;
00518 
00519     INT32 i = 0;
00520     INT32 Colours = m_Palette.NumberOfColours;
00521     Colours = max( 256, Colours );
00522     for( i=0; i < Colours; i++ )
00523     {
00524         m_Palette.Data[ i ].Red                 = ( pOther->m_Palette ).Data[ i ].Red;
00525         m_Palette.Data[ i ].Green               = ( pOther->m_Palette ).Data[ i ].Green;
00526         m_Palette.Data[ i ].Blue                = ( pOther->m_Palette ).Data[ i ].Blue;
00527         m_Palette.Data[ i ].Flags               = ( pOther->m_Palette ).Data[ i ].Flags;
00528     }
00529 
00530     // delete our old logical palette if we had one
00531     if (m__pLogicalPalette)
00532     {
00533         delete m__pLogicalPalette;
00534         m__pLogicalPalette = NULL;
00535     }
00536 
00537     // our copy is valid if the original is valid
00538     m__PaletteIsValid = pOther->IsPaletteValid();
00539 
00540     // copy the logical palette data if it was valid
00541     if (m__PaletteIsValid)
00542     {
00543         m__pLogicalPalette = (LOGPALETTE * ) new BYTE[sizeof(LOGPALETTE) + ( sizeof(PALETTEENTRY) * 256 )];
00544 
00545         memcpy(m__pLogicalPalette, pOther->GetLogicalPalette(), sizeof(LOGPALETTE) + ( sizeof(PALETTEENTRY) * 256 ));
00546     }
00547 
00548 }
00549 
00550 
00551 
00552 /******************************************************************************************
00553 >   ExtendedPalette& BitmapExportOptions::GetPalette()
00554     Author:     Alex_Price (Xara Group Ltd) <camelotdev@xara.com>
00555     Created:    13/08/99
00556     Returns:    The palette object of this class.
00557     Purpose:    Gives the calling function a copy of this class's palette.
00558 ******************************************************************************************/
00559 ExtendedPalette* BitmapExportOptions::GetPalette()
00560 {
00561     return &m_Palette;
00562 }
00563 
00564 
00565 /********************************************************************************************
00566 
00567 >   BOOL BitmapExportOptions::IsValid() const
00568 
00569     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00570     Created:    29/10/96
00571     Returns:    TRUE if this BitmapExportOptions object is valid for use in a subsequent
00572                 export operation.
00573                 FALSE otherwise
00574     Purpose:    Determines whether or not the values contained in this object are valid or
00575                 whether the user has cancelled the export: using MarkValid() & MarkInvalid()
00576                 will state the veracity of this fact.
00577 
00578 ********************************************************************************************/
00579 BOOL BitmapExportOptions::IsValid() const
00580 {
00581     return m_bValid;
00582 }
00583 
00584 
00585 void BitmapExportOptions::MarkInvalid()
00586 {
00587     m_bValid = FALSE;
00588 }
00589 
00590 
00591 void BitmapExportOptions::MarkValid()
00592 {
00593     m_bValid = TRUE;
00594 }
00595 
00596 
00597 /********************************************************************************************
00598 
00599 >   virtual BOOL BitmapExportOptions::RetrieveDefaults()
00600 
00601     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00602     Created:    29/10/96
00603     Returns:    TRUE if successful
00604                 FALSE otherwise
00605     Purpose:    Retrieves defaults for accessible members from preferences 
00606     See Also:   BitmapExportOptions::SetAsDefaults()
00607 
00608 ********************************************************************************************/
00609 BOOL BitmapExportOptions::RetrieveDefaults()
00610 {
00611     SetDPI(BMPFilter::GetDefaultExportDPI());
00612     SetDepth(BMPFilter::GetDefaultExportDepth());
00613 
00614     SetPutHTMLTagOnClipboard(ms_fPutHTMLTagOnClipboard);
00615     m__BackgroundIsTransparent = ms_IsBackGroundTransparent;
00616     m_Antialiasing = ms_Antialiasing;
00617     m_bSeparateLayerFiles = ms_bSeparateLayerFiles;
00618 
00619     return TRUE;
00620 }
00621 
00622 
00623 /********************************************************************************************
00624 
00625 >   virtual BOOL BitmapExportInfo::SetAsDefaults() const
00626 
00627     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00628     Created:    29/10/96
00629     Purpose:    Sets the current options as preferences which may be retrieved by a
00630                 subsequent RetrieveDefaults()
00631     See Also:   BitmapExportOptions::RetrieveDefaults()
00632 
00633 ********************************************************************************************/
00634 BOOL BitmapExportOptions::SetAsDefaults() const
00635 {
00636     BMPFilter::SetDefaultExportDPI(GetDPI());
00637     BMPFilter::SetDefaultExportDepth(GetDepth());
00638 
00639     ms_fPutHTMLTagOnClipboard=m_fPutHTMLTagOnClipboard;
00640     ms_IsBackGroundTransparent = m__BackgroundIsTransparent;
00641     ms_Antialiasing = m_Antialiasing;
00642     ms_bSeparateLayerFiles = m_bSeparateLayerFiles;
00643 
00644     return TRUE;
00645 }
00646 
00647 /********************************************************************************************
00648 
00649 >   static BOOL BitmapExportOptions::Declare()
00650 
00651     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00652     Created:    22/7/97
00653     Returns:    TRUE if successfully declared preferences
00654                 FALSE otherwise
00655                 Purpose:    Declares our base class preferences
00656 
00657 ********************************************************************************************/
00658 BOOL BitmapExportOptions::Declare()
00659 {
00660     if (Camelot.DeclareSection(_T("Filters"), 10))
00661     {
00662         Camelot.DeclarePref( NULL, ms_strPutHTMLTagOnClipboard, &ms_fPutHTMLTagOnClipboard, FALSE, TRUE );
00663     }
00664 
00665     return TRUE;
00666 }
00667 
00668 
00669 
00670 /********************************************************************************************
00671 >   virtual BOOL BitmapExportOptions::Write(CXaraFileRecord* pRec)
00672 
00673     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00674     Created:    21/2/00
00675     Inputs:     pRec    ---     record to write
00676     Returns:    TRUE if successful.
00677     Purpose:    Writes this object to the given record.
00678     SeeAlso:    BitmapExportOptions::Read
00679 ********************************************************************************************/
00680 
00681 BOOL BitmapExportOptions::Write(CXaraFileRecord* pRec)
00682 {
00683     INT16 Packed = 0x0000;
00684 
00685     if (m_Antialiasing) Packed += 1;
00686     if (m__BackgroundIsTransparent) Packed += 2;
00687     if (m__UseBrowserPalette) Packed += 4;
00688 
00689     INT16 AmountOfPrimarySnap = (m__UsePrimarySnapPalette & 15) << 4;
00690     Packed += AmountOfPrimarySnap;
00691 
00692     INT16 AmountOfWebSnap = (m__UseWebSnapPalette & 0xff) << 8;
00693     Packed += AmountOfWebSnap;
00694 
00695     UINT32 PackedRequestedColours = m__NumberOfColoursUserRequested;
00696 
00697     // Write out every user-definable data member.  Note that as we save only
00698     // the lowest byte of a bool, we double-not them to ensure they are saved
00699     // out only as either 0 or 1.
00700     if (!pRec->WriteINT16((INT16) m_SelectionType) ||
00701         !pRec->WriteCoord((const DocCoord&) m_OutputSize) ||
00702         !pRec->WriteCoord((const DocCoord&) m_PixelOutputSize) ||
00703         !pRec->WriteUINT32((UINT32) m_FilterID) ||
00704         !pRec->WriteBYTE((BYTE) !!m_UseDesignNotes) ||
00705         !pRec->WriteUINT32(PackedRequestedColours) ||
00706         !pRec->WriteBYTE((BYTE) !!m__UseSystemColoursInPalette) ||
00707         !pRec->WriteBYTE((BYTE) !!m_fPutHTMLTagOnClipboard) ||
00708         !pRec->WriteDOUBLE((double) m_DPI) ||
00709         !pRec->WriteUINT32((UINT32) m_Depth) ||
00710         !pRec->WriteINT32(m_TransparencyIndex) ||
00711         !pRec->WriteUINT32((UINT32) m_DialogID) ||
00712         !pRec->WriteINT16(Packed) || // was m_Antialiasing but I have now packed this data to fit in the new stuff
00713         !pRec->WriteINT32(m_Palette.NumberOfColours) ||
00714         !pRec->WriteUnicode(m_pFilterName ? ((LPTSTR) (LPCTSTR) *m_pFilterName) : (LPTSTR) _T("")))
00715             return FALSE;
00716 
00717     // Write out the palette.
00718     BYTE Dummy = 0;
00719     ExtendedPaletteEntry* peEnd = &m_Palette.Data[min(m_Palette.NumberOfColours, 256)];
00720     for (ExtendedPaletteEntry* pe = m_Palette.Data; pe < peEnd; pe++)
00721     {
00722         DWORD PackedPreEditedColours = pe->PreEditedRed + (pe->PreEditedGreen << 8) + (pe->PreEditedBlue << 16);
00723         if (!pRec->WriteBYTE(pe->Red) ||
00724             !pRec->WriteBYTE(pe->Green) ||
00725             !pRec->WriteBYTE(pe->Blue) ||
00726             !pRec->WriteBYTE(Dummy) ||
00727             !pRec->WriteINT32((INT32)PackedPreEditedColours) || // used to be popularity but there should be no clash
00728             !pRec->WriteINT32(pe->Flags))
00729                 return FALSE;
00730     }
00731 
00732     return TRUE;
00733 }
00734 
00735 
00736 
00737 /********************************************************************************************
00738 >   virtual BOOL BitmapExportOptions::Read(CXaraFileRecord* pRec)
00739 
00740     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00741     Created:    21/2/00
00742     Inputs:     pRec    ---     record to read
00743     Returns:    TRUE if successful.
00744     Purpose:    Reads this object from the given record.
00745     SeeAlso:    BitmapExportOptions::Write
00746 ********************************************************************************************/
00747 
00748 BOOL BitmapExportOptions::Read(CXaraFileRecord* pRec)
00749 {
00750     // Make sure these bools are preset to zero as we only saved their
00751     // least significant byte.
00752     m_UseDesignNotes = m_UseSystemColours = m_fPutHTMLTagOnClipboard = FALSE;
00753 
00754     INT16 Packed = 0;
00755     UINT32 PackedRequestedColours = 0;
00756 
00757     // Read in every user-definable data member.
00758     String_256 strFilterName;
00759     if (!pRec->ReadINT16((INT16*) &m_SelectionType) ||
00760         !pRec->ReadCoord((DocCoord*) &m_OutputSize) ||
00761         !pRec->ReadCoord((DocCoord*) &m_PixelOutputSize) ||
00762         !pRec->ReadUINT32((UINT32*) &m_FilterID) ||
00763         !pRec->ReadBYTEtoBOOL(&m_UseDesignNotes) ||
00764         !pRec->ReadUINT32((UINT32*) &PackedRequestedColours) ||
00765         !pRec->ReadBYTEtoBOOL(&m__UseSystemColoursInPalette) ||
00766         !pRec->ReadBYTEtoBOOL(&m_fPutHTMLTagOnClipboard) ||
00767         !pRec->ReadDOUBLE((double*) &m_DPI) ||
00768         !pRec->ReadUINT32((UINT32*) &m_Depth) ||
00769         !pRec->ReadINT32(&m_TransparencyIndex) ||
00770         !pRec->ReadUINT32((UINT32*) &m_DialogID) ||
00771         !pRec->ReadINT16((INT16*) &Packed) ||
00772         !pRec->ReadINT32((INT32*) &m_Palette.NumberOfColours) ||
00773         !pRec->ReadUnicode(&strFilterName))
00774             return FALSE;
00775 
00776     // unpack the packed varibale to get the smfix data
00777     if (Packed & 1)
00778         m_Antialiasing = MINIMISE_VISIBLE_AA;
00779     else
00780         m_Antialiasing = MAINTAIN_SCREEN_AA;
00781 
00782     m__BackgroundIsTransparent = Packed & 2;
00783     m__UseBrowserPalette = Packed & 4;
00784     m__UsePrimarySnapPalette = (Packed >> 4) & 15;
00785     m__UseWebSnapPalette = (Packed >> 8) & 0xff;
00786 
00787     m__NumberOfColoursUserRequested = PackedRequestedColours;
00788 
00789     // Read in the palette.
00790     BYTE Dummy = 0;
00791     INT32 DummyPopularity = 0;
00792     ExtendedPaletteEntry* peEnd = &m_Palette.Data[min(m_Palette.NumberOfColours, 256)];
00793     for (ExtendedPaletteEntry* pe = m_Palette.Data; pe < peEnd; pe++)
00794     {
00795         if (!pRec->ReadBYTE(&pe->Red) ||
00796             !pRec->ReadBYTE(&pe->Green) ||
00797             !pRec->ReadBYTE(&pe->Blue) ||
00798             !pRec->ReadBYTE(&Dummy) ||
00799             !pRec->ReadINT32((INT32*) &DummyPopularity) ||
00800             !pRec->ReadINT32((INT32*) &pe->Flags))
00801                 return FALSE;
00802 
00803         // unpack the pre-edited colours
00804         DWORD PackedPreEditedColours = DummyPopularity;
00805         pe->PreEditedRed = (PackedPreEditedColours && 0xff);
00806         pe->PreEditedGreen = ((PackedPreEditedColours >> 8) && 0xff);
00807         pe->PreEditedBlue = ((PackedPreEditedColours >> 16) && 0xff);
00808     }
00809 
00810     if (m_DPI == 0)
00811     {
00812         TRACE( _T("DPI not set in export options in the .xar file - setting it to 96.0\n"));
00813         m_DPI = 96.0;
00814     }
00815 
00816 
00817     // Fix up the filter name string (for some brain-damaged reason this bears
00818     // little relation to the saved-out filter ID).
00819     if (strFilterName.IsEmpty())
00820         strFilterName.Load(GetFilterNameStrID());
00821 
00822     for (Filter* pf = Filter::GetFirst(); pf != 0; pf = Filter::GetNext(pf))
00823         if (pf->FilterName == strFilterName)
00824         {
00825             // Success.
00826             m_pFilterName = &pf->FilterName;
00827             return TRUE;
00828         }
00829     
00830     // Couldn't find the filter with the given name.
00831     TRACE( _T("BitmapExportOptions::Read: can't find %s filter\n"), (LPCTSTR) strFilterName);
00832     return FALSE;
00833 }
00834 
00835 
00836 
00837 /********************************************************************************************
00838 >   const StringBase* BitmapExportOptions::GetFilterName() const
00839 
00840     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00841     Created:    29/10/96
00842     Returns:    The name of the filter associated with this BitmapExportOptions object
00843     Purpose:    Allows the export dialog to display the filter name in its title bar
00844 ********************************************************************************************/
00845 
00846 const StringBase* BitmapExportOptions::GetFilterName() const
00847 {
00848     return m_pFilterName;
00849 }
00850 
00851 
00852 /********************************************************************************************
00853 
00854   > void BitmapExportOptions::SetPathName(PathName *pTempPath)
00855 
00856     Author:     Stefan_Stoykov (Xara Group Ltd) <camelotdev@xara.com>
00857     Created:    1/7/96
00858     Inputs:     pTempPath - path name of a temporary file
00859     Returns:    None
00860     Purpose:    Allows the export options to keep the path to a temporary file, created 
00861                 during bitmap preview, so the export function can simply rename this to 
00862                 create the final exported file.
00863 
00864 ********************************************************************************************/
00865 void BitmapExportOptions::SetPathName(PathName *pTempPath)
00866 {
00867     // set the flag, to indicate that we have a temp file, but only if the path name is not null
00868     m_bTempFileExported = (pTempPath != NULL);
00869 
00870     if (m_bTempFileExported)
00871     {
00872         // remember the new path
00873         m_TempPath = *pTempPath;
00874     }
00875 }
00876 
00877     
00878 /********************************************************************************************
00879 
00880 >   BOOL BitmapExportOptions::SetDPI(const DPI& Dpi)
00881 
00882     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00883     Created:    29/10/96
00884     Inputs:     Dpi : The dpi of the bitmap to be exported
00885     Returns:    TRUE if the operation was successful
00886                 FALSE otherwise
00887     Purpose:    Support function to set up information for the ensuing export
00888     See Also:   GetDpi()
00889 
00890 ********************************************************************************************/
00891 BOOL BitmapExportOptions::SetDPI(const DPI& Dpi)
00892 {
00893     if (m_DPI != Dpi)
00894         BitmapSourceHasChanged(); // flush cache
00895 
00896     m_DPI = Dpi;
00897     return TRUE;
00898 }
00899 
00900 
00901 /********************************************************************************************
00902 
00903 >   DPI BitmapExportOptions::GetDPI() const
00904 
00905     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00906     Created:    29/10/96
00907     Returns:    The desired dpi of the bitmap to export
00908     Purpose:    Support function to obtain bitmap info
00909 
00910 ********************************************************************************************/
00911 DPI BitmapExportOptions::GetDPI() const
00912 {
00913     return m_DPI;
00914 }
00915 
00916 
00917 /********************************************************************************************
00918 
00919 >   void BitmapExportOptions::SetSelectionType(const SelectionType& Sel)
00920 
00921     Author:     Simon_Knight (Xara Group Ltd) <camelotdev@xara.com>
00922     Created:    long while ago - modified sjk 10/12/00
00923     Purpose:    sets the the item(s) being exported eg selection, page, drawing, etc
00924 
00925 ********************************************************************************************/
00926 void BitmapExportOptions::SetSelectionType(const SelectionType& Sel)
00927 {
00928     if (m_SelectionType != Sel)
00929         BitmapSourceHasChanged(); // flush cache
00930     m_SelectionType = Sel;
00931 }
00932 
00933 /********************************************************************************************
00934 
00935 >   void BitmapExportOptions::SetAntiAliasing( ANTIALIASING aa )
00936 
00937     Author:     Simon_Knight (Xara Group Ltd) <camelotdev@xara.com>
00938     Created:    long while ago - modified sjk 10/12/00
00939     Purpose:    Sets the anti-aliasing on the export bitmap
00940 
00941 ********************************************************************************************/
00942 void BitmapExportOptions::SetAntiAliasing( ANTIALIASING aa )
00943 {
00944     if (m_Antialiasing != aa)
00945         BitmapSourceHasChanged(); // flush cache
00946     m_Antialiasing = aa;
00947 }
00948 
00949 
00950 /********************************************************************************************
00951 
00952 >   BMP_DEPTH BitmapExportOptions::GetDepth() const
00953 
00954     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00955     Created:    29/10/96
00956     Returns:    The desired depth of the bitmap to export
00957     Purpose:    Support function to obtain bitmap options
00958 
00959 ********************************************************************************************/
00960 BMP_DEPTH BitmapExportOptions::GetDepth() const
00961 {
00963     // THIS IS JUST FOR TESTING! WHEN THE BITMAP COPY DIALOG GETS IT`s OWN 32BPP BUTTON
00964     // THEN THIS MUST BE REMOVED!!!!!!!
00965     //  I've change '>1' to '>=1' below, otherwise the 2 colour optimised palette
00966     //  is not available.
00967     if( m_Depth >= 1 )
00968     {
00969         return m_Depth;
00970     }
00971     else
00972     {
00973         return 32;
00974     }
00975 }
00976 
00977 
00978 /********************************************************************************************
00979 
00980 >   BOOL BitmapExportOptions::SetDepth(const BMP_DEPTH& Depth)
00981 
00982     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
00983     Created:    29/10/96
00984     Inputs:     Depth : The depth of the bitmap to be exported
00985     Returns:    TRUE if the operation was successful
00986                 FALSE otherwise
00987     Purpose:    Support function to set up information for the ensuing export
00988     See Also:   GetDepth()
00989 
00990 ********************************************************************************************/
00991 BOOL BitmapExportOptions::SetDepth(const BMP_DEPTH& Depth)
00992 {
00993     if (m_Depth != Depth)
00994     {
00995         InvalidatePalette();
00996 
00997         // sjk bodge if we did have two colours moving up sometimes needs to regather the stats
00998         if (m_Depth == 1)
00999             BitmapSourceHasChanged();
01000     }
01001 
01002     m_Depth = Depth;
01003     return TRUE;
01004 }
01005 
01006 
01007 /********************************************************************************************
01008 
01009 >   void BitmapExportOptions::SetBitmapExportParam(BitmapExportParam* pParam)
01010     Author:     Ranbir_Rana (Xara Group Ltd) <camelotdev@xara.com>
01011     Created:    05/01/96
01012     Inputs:     PParam - Allows us to to save a reference to a BmpDlgParam, in
01013                 the BitmapExportOptions.
01014     Returns:    -
01015     Purpose:    -
01016     See Also:   -
01017 
01018 ********************************************************************************************/
01019 
01020 BOOL BitmapExportOptions::SetBitmapExportParam(BitmapExportParam* pParam)
01021 {
01022     ERROR2IF(pParam == NULL,FALSE,"pParam is NULL");
01023     m_pBmpDlgParam=pParam->GetBmpDlgParam();
01024 
01025     if(m_pBmpDlgParam == NULL)
01026         return FALSE;
01027 
01028     return TRUE;
01029 }
01030 
01031 
01032 BOOL BitmapExportOptions::IsClipToPage()
01033 {
01034     if( m_SelectionType == PAGE )
01035         return TRUE;
01036     else
01037         return FALSE;
01038 }
01039 
01040 
01041 BOOL BitmapExportOptions::IsCMYK()
01042 {
01043     return m_bCMYK;
01044 }
01045 
01046 void BitmapExportOptions::SetCMYK(BOOL SetIt)
01047 {
01048     m_bCMYK = SetIt;
01049 }
01050 
01051 
01052 /********************************************************************************************
01053 
01054 >   BOOL BitmapExportOptions::CanExportSeparateLayers()
01055 
01056     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
01057     Created:    05/04/2004
01058     Inputs:     -
01059     Returns:    -
01060     Purpose:    -
01061     See Also:   -
01062 
01063 ********************************************************************************************/
01064 
01065 BOOL BitmapExportOptions::CanExportSeparateLayers()
01066 {
01067     return (GetSeparateLayerFiles() && GetTempFileFlag()==FALSE && (GetFilterNameStrID()==_R(IDN_FILTERNAME_GIF) || GetFilterNameStrID()==_R(IDS_FILTERNAME_PNG)));
01068 }
01069 
01070 
01071 
01072 PORTNOTE("other", "Removed export dlgs");
01073 #if !defined(EXCLUDE_FROM_XARALX)
01074 
01075 /*******************************************************************************************/
01076 PhotoCDDlgParam * PhotoCDDlg::pParams = NULL;   // Data passing class
01077 
01078 // Set up the dialog box details stored as statics in the class
01079 CDlgResID BmpPrefsDlg::IDD = _R(IDD_EXPORTBMPOPTS); // default dialog box id
01080 const CDlgMode BmpPrefsDlg::Mode = MODAL;       // This dialog is modal
01081 
01082 const CDlgMode PhotoCDDlg::Mode = MODAL;        // This dialog is modal
01083 
01084 // Tiff compression types we can cope with. Cannot use the Accusoft types as these are not
01085 // contiguous and hence would not correspond to items in a list
01086 //enum TiffTypes {UNCOMPRESSED_TIFF, LZW_TIFF, HUFFMAN_TIFF, G3FAX_TIFF, G4FAX_TIFF,
01087 //              PACKBITS_TIFF, TWODENCODING_TIFF };
01088 
01089 // Andy Hills, 05-09-00
01090 // The above enum is only applicable for 1bpp TIFF export.
01091 // The options are different for 4/8/24 bpp.
01092 
01093 // The values correspond to the positions of the respective compression types
01094 // in the drop-down list.
01095 // This will have to make do until someone does a vast re-write of the 
01096 // TIFF export options code!
01097 
01098 // Note that LZW_TIFF and HUFFMAN_TIFF are at the same position:
01099 // this is because they don't actually appear at the same time.
01100 // For 1bpp, the options are { uncompressed, huffman, g3 ... }
01101 // For 8ppp, the options are { uncompressed, lzw }
01102 
01103 #define UNCOMPRESSED_TIFF 0
01104 #define LZW_TIFF 1
01105 #define HUFFMAN_TIFF 1
01106 #define G3FAX_TIFF 2
01107 #define G4FAX_TIFF 3
01108 #define PACKBITS_TIFF 4
01109 #define TWODENCODING_TIFF 5
01110 
01111 
01112 // BODGE: We get some bad pixel cropping on some images if we use doubles. So limit the doubles to
01113 // fixed values until these problems are fixed.
01114 // Hence the conversion of GetDoubleGadgetValues into GetLongGadgetValues.
01115 static const double D_MAXDPI = 3000.0;
01116 static const INT32 MAXDPI = 3000;
01117 
01118 // Height of extra bit at the bottom of the dialogue with the Animation options
01119 static const INT32 ANIMATION_EXTRABIT  = 76;
01120 static const INT32 NUMCOLS_EXTRABIT   = 56;
01121 static const INT32 NUMCOLS_GROUP_SHIFT = 80;
01122 
01123 // WEBSTER - markn 24/1/97
01124 // The number of system colours added when the "Add system colours" switch is on
01125 // (28 because there are 27 Gavin primary colours (which includes most of the windows colour)
01126 // plus one windows colour that isn't a Gavin primary)
01127 static const INT32 NUM_SYS_COLS = 28;
01128 
01129 
01130 /******************************************************************************************
01131 
01132 >   BmpPrefsDlg::BmpPrefsDlg(): DialogOp(BmpPrefsDlg::IDD, BmpPrefsDlg::Mode) 
01133 
01134     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01135     Created:    28/08/94
01136     Purpose:    BmpPrefsDlg constructor. Creates a non-undoable operation
01137 
01138 ******************************************************************************************/
01139 
01140 BmpPrefsDlg::BmpPrefsDlg(): DialogOp(BmpPrefsDlg::IDD, BmpPrefsDlg::Mode) 
01141 {
01142     m_pOptions = NULL;
01143 
01144     Width       = 0;
01145     Height      = 0;
01146     PixelWidth  = 0;
01147     PixelHeight = 0;
01148     Dpi         = 96.0;
01149 
01150     LastBppSelected = 0;
01151 
01152     RecalculatingPixels = FALSE;
01153     RecalculatingXDpi   = FALSE;
01154     RecalculatingYDpi   = FALSE;
01155 
01156     m_bDpiSupported = FALSE;
01157     m_bLockAspect   = FALSE;
01158     IsDelayMany = FALSE;            
01159     IsDelayDefault = FALSE;     
01160     HasDelayChanged = FALSE;
01161     HasRestoreChanged = FALSE;
01162     IsManyDisplayed = FALSE;
01163     DisplayMany = FALSE;
01164     LoopCheckBoxEnabled = TRUE;
01165 }
01166 
01167 
01168 /******************************************************************************************
01169 
01170 >   SelectionType BmpPrefsDlg::GetSelection(BmpPrefsDlg* pBmpPrefs) 
01171 
01172 
01173     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01174     Created:    22/3/95
01175     Inputs:     -
01176     Outputs:    -
01177     Returns:    Selection, Drawing or Spread.
01178     Purpose:    Works out what the current selection/spread/drawing state is.
01179     Errors:     -
01180     SeeAlso:    -
01181 
01182 ******************************************************************************************/
01183 
01184 SelectionType BmpPrefsDlg::GetSelection()
01185 {
01186     // Get the state of the selection, drawing or spread buttons
01187     BOOL Valid = FALSE;
01188 
01189     // If opening specification was a bitmap then nothing doing
01190     if (GetOptions()->GetSelectionType() == ABITMAP)
01191         return ABITMAP;
01192 
01193     if (GetOptions()->GetSelectionType() == SOMEBITMAPS)
01194         return SOMEBITMAPS;
01195 
01196     SelectionType FoundSelection = DRAWING;
01197     
01198     BOOL ExportDrawing = GetLongGadgetValue(_R(IDC_BMPOPTS_DRAWING), 0, 1, 0, &Valid);
01199     // Use the state on entry to dictate the possible output values.
01200     if (GetOptions()->GetSelectionType() == SELECTION)
01201     {
01202         // If selection present then choose between Selection or Drawing
01203         if (ExportDrawing)
01204             FoundSelection = DRAWING;
01205         else        
01206             FoundSelection = SELECTION;
01207     }
01208     else
01209     {
01210         // Graham 24/7/97: If no selection, then set DRAWING automatically
01211         FoundSelection = DRAWING;       
01212     }
01213     
01214     // return what was found to the caller
01215     return FoundSelection;
01216 }   
01217 
01218 /******************************************************************************************
01219 
01220 >   void    BmpPrefsDlg::RecalculateSize(BmpPrefsDlg* pBmpPrefs)
01221 
01222     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01223     Created:    22/3/95
01224     Inputs:     -
01225     Outputs:    -
01226     Returns:    -
01227     Purpose:    Calculates the size of the selection/spread/drawing and fills in the width
01228                 and height fields accordingly. It then calculates the pixel size and/or dpi.
01229     Errors:     -
01230     SeeAlso:    -
01231 
01232 ******************************************************************************************/
01233 
01234 void    BmpPrefsDlg::RecalculateSize()
01235 {    
01236     // Get the state of the selection, drawing or spread buttons
01237     SelectionType FoundSelection = GetSelection();
01238 
01239     // Construct our spread/drawing/selection size rectangle
01240     ClipRect;
01241     ClipRect.MakeEmpty(); 
01242 
01243     if (FoundSelection == ABITMAP)
01244     {
01245         // Show only the PixelWidth of the bitmap, size in units is irrelevent
01246         BaseBitmapFilter::GetSizeOfBitmap(&PixelWidth, &PixelHeight);
01247 
01248         RecalculatingPixels = TRUE;  // flag no updates to dpi field from RecalculateDpiFromX, Y
01249         
01250         SetLongGadgetValue(_R(IDC_BMPOPTS_XPIXELS), PixelWidth);
01251         SetLongGadgetValue(_R(IDC_BMPOPTS_YPIXELS), PixelHeight);
01252 
01253         // WEBSTER - markn 5/2/97
01254         // Taken out the X & Y size gadgets
01255 #ifndef WEBSTER
01256         SetStringGadgetValue(_R(IDC_BMPOPTS_XSIZE), &String_8("-"));
01257         SetStringGadgetValue(_R(IDC_BMPOPTS_YSIZE), &String_8("-"));
01258         EnableGadget(_R(IDC_BMPOPTS_XSIZE), FALSE);
01259         EnableGadget(_R(IDC_BMPOPTS_YSIZE), FALSE);
01260 #endif // WEBSTER
01261         EnableGadget(_R(IDC_BMPOPTS_XPIXELS), FALSE);
01262         EnableGadget(_R(IDC_BMPOPTS_YPIXELS), FALSE);
01263 
01264         RecalculatingPixels = FALSE;     // flag no updates to dpi field from RecalculateDpiFromX, Y
01265 
01266         // We need a DPI to work with, so we'll just use the default pixel unit size
01267         DocUnitList* pDocUnitList = DocUnitList::GetCurrentDocUnitList();
01268         ERROR3IF(pDocUnitList == NULL, "BmpPrefsDlg::RecalculateSize() - no pDocUnitList!")
01269         Unit* pPixelUnit = pDocUnitList->FindUnit(PIXELS);
01270         ERROR3IF(pPixelUnit == NULL, "BmpPrefsDlg::RecalculateSize() - no pixel units!")
01271         Unit* pInchUnit = pDocUnitList->FindUnit(INCHES);
01272         ERROR3IF(pInchUnit == NULL, "BmpPrefsDlg::RecalculateSize() - no inch units!")
01273         double newDpi = (pPixelUnit->GetMillipoints()>0) ? pInchUnit->GetMillipoints() / pPixelUnit->GetMillipoints() : 96.0;
01274         Dpi = (INT32)newDpi;
01275         GetOptions()->SetDPI(newDpi);
01276     
01277         ClipRect.lo = DocCoord(0,0);
01278         ClipRect.hi = DocCoord(PixelWidth * (INT32)newDpi, PixelHeight * (INT32)newDpi);
01279 
01280         Width = ClipRect.Width();   
01281         Height = ClipRect.Height(); 
01282 
01283         // All work is now complete so exit
01284         return;
01285     }   
01286 
01287     if (FoundSelection == SOMEBITMAPS)
01288     {
01289         // Setup size of animation frames
01290         ClipRect.lo = DocCoord(0,0);
01291         ClipRect.hi = DocCoord(GetOptions()->GetOutputSize().x, GetOptions()->GetOutputSize().y);
01292     }   
01293 
01294     // Find the application and selected document 
01295     Application* pApplication = GetApplication();
01296     Document* pDocument = Document::GetSelected();
01297     Spread* pSpread = NULL;
01298 
01299     // As long as we have an application and a selected document then go and work out
01300     // the rectangles
01301     if (pApplication && pDocument && FoundSelection != ABITMAP  && FoundSelection != SOMEBITMAPS)
01302     {
01303         // First, check if there is a selection present. ClipRect should be empty if not.
01304         SelRange* pSelection = pApplication->FindSelection();
01305         if (pSelection)
01306         {
01307             // Get the bounding rectangle for the selection
01308             ClipRect = pSelection->GetBoundingRect();
01309 
01310             // Work out the parent spread by finding the first node in the selection
01311             Node* pNode = pSelection->FindFirst();
01312             // if there is a first node then just find the parent spread
01313             // otherwise just use the first spread in the document
01314             if (pNode)
01315                 pSpread = pNode->FindParentSpread();
01316             else
01317                 pSpread = pDocument->FindFirstSpread();
01318         }
01319 
01320         if (pSpread)
01321         {
01322             switch (FoundSelection)
01323             {
01324                 case ABITMAP:
01325                     ERROR3IF(TRUE, "BmpPrefsDlg::RecalculateSize() - This should have already been taken care of")
01326                     // This should have already been taken care of
01327                     break;
01328                 case SELECTION:
01329                     // This should have already been taken care of
01330                     break;
01331                 case SPREAD:
01332                 {
01333                     // Work out the size of the rectangle encompassing the spread,
01334                     // using the same function that the bitmap export code uses.
01335                     ERROR3("Selection == Spread!");
01336 
01337                     ClipRect = BaseBitmapFilter::GetSizeOfSpread(pSpread);
01338                     //break;
01339                 }
01340                 
01341                 default:
01342                 {
01343                     // Work out the size of the rectangle encompassing the drawing, (visible 
01344                     // layers only), using the same function that the bitmap export code
01345                     // uses.
01346                     ClipRect = BaseBitmapFilter::GetSizeOfDrawing(pSpread);
01347                     break;
01348                 }
01349             } // End switch
01350         }
01351     }
01352 
01353     // Graeme 25/7/00 - If our clip rectangle is less than the minimum export size,
01354     // resize the clipping rectangle to encompass the entire page.
01355     if ( ClipRect.IsEmpty() ||
01356          ClipRect.Width() < BaseBitmapFilter::MinExportSize ||
01357          ClipRect.Height() < BaseBitmapFilter::MinExportSize )
01358     {
01359         // Set the ClipRect to be the size of the spread.
01360         ClipRect = pSpread->FindFirstPageInSpread ()->GetPageRect ();
01361     }   
01362 
01363     // Work out the size of this rectangle encompassing the speread/drawing/selection
01364     // in Millipoints and store these in the class variables for later reuse
01365     Width = ClipRect.Width();   
01366     Height = ClipRect.Height(); 
01367 
01368     // Work out what the current units we should be displaying in
01369     DocUnitList* pDocUnitList = NULL;
01370     UnitType CurrentPageUnits = MILLIMETRES;
01371     if (pDocument)
01372     {
01373         pDocUnitList = pDocument->GetDocUnitList();
01374         if (pDocUnitList)
01375             CurrentPageUnits = pDocUnitList->GetPageUnits();
01376     }
01377     
01378     // WEBSTER - markn 5/2/97
01379     // Taken out the X & Y size gadgets
01380     #ifndef WEBSTER
01381     if (m_bDpiSupported)
01382     {
01383         SetUnitGadgetValue(_R(IDC_BMPOPTS_XSIZE), CurrentPageUnits, Width, FALSE, -1);
01384         SetUnitGadgetValue(_R(IDC_BMPOPTS_YSIZE), CurrentPageUnits, Height, FALSE, -1);
01385     }
01386     else
01387     {
01388         SetStringGadgetValue(_R(IDC_BMPOPTS_XSIZE), &String_8("-"));
01389         SetStringGadgetValue(_R(IDC_BMPOPTS_YSIZE), &String_8("-"));
01390     }
01391     #endif // WEBSTER
01392     
01393     // Work out what this size is in pixels and fill in the editable fields
01394     RecalculatePixels();
01395 }
01396 
01397 /******************************************************************************************
01398 
01399 >   void    BmpPrefsDlg::RecalculatePixels()
01400 
01401     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01402     Created:    22/3/95
01403     Inputs:     -
01404     Outputs:    -
01405     Returns:    -
01406     Purpose:    Takes the size of the selection/spread/drawing and calculates the size that
01407                 this will be in pixels given the current dpi field.
01408     Errors:     -
01409     SeeAlso:    -
01410 
01411 ******************************************************************************************/
01412 
01413 void    BmpPrefsDlg::RecalculatePixels()
01414 {    
01415 
01416     // If the RecalculateDpiFromX() or RecalculateDpiFromY() functions are setting the
01417     // values then make sure we do not update the values as well. 
01418     if (RecalculatingXDpi || RecalculatingYDpi)
01419         return;
01420 
01421     // Now work out the pixel sizes which this will correspond to at the current dpi setting
01422     PixelWidth = 0; 
01423     PixelHeight = 0;    
01424     Dpi = 0;
01425     BOOL Valid = 0;         // Flag for validity of value
01426 
01427     // Get the dpi value from the resolution combo box, with no error reporting
01428     // Don't change the current values if the dpi is wrong
01429     if (!m_bDpiSupported)
01430     {
01431         Dpi = GetOptions()->GetDPI();
01432         Valid = TRUE;
01433     }
01434     else
01435     {
01436         Dpi = (double)GetLongGadgetValue(_R(IDC_BMPOPTS_RES), 5, MAXDPI, NULL ,&Valid);
01437     }
01438     
01439     if ( Valid ) 
01440     {
01441         // This is the calculation that we are effectively doing
01442         // Use 0.5 so that we are forced to round up to the next pixel, if possible
01443         //PixelWidth = (INT32)(((Width * Dpi)/72000) + 0.5);
01444         //PixelHeight = (INT32)(((Height * Dpi)/72000) + 0.5);
01445         // but use the same code that the bitmap code will use so that we are consistent
01446         Matrix Identity;    // default construction is an identity matrix
01447         WinRect Rect = OSRenderRegion::BitmapDocRectToWin( Identity, ClipRect, Dpi );
01448         PixelWidth = Rect.Width();
01449         PixelHeight = Rect.Height();
01450 
01451         // More of a safety net here.
01452         if (PixelWidth < 0)
01453             PixelWidth = 0;
01454         if (PixelHeight < 0)
01455             PixelHeight = 0;
01456 
01457         RecalculatingPixels = TRUE;  // flag no updates to dpi field from RecalculateDpiFromX, Y
01458         
01459         SetLongGadgetValue(_R(IDC_BMPOPTS_XPIXELS), PixelWidth);
01460         SetLongGadgetValue(_R(IDC_BMPOPTS_YPIXELS), PixelHeight);
01461         
01462         RecalculatingPixels = FALSE;     // flag no updates to dpi field from RecalculateDpiFromX, Y
01463     }
01464     else
01465     {
01466         RecalculatingPixels = TRUE;  // flag no updates to dpi field from RecalculateDpiFromX, Y
01467 
01468         // There is a problem with the dpi so blank the pixel width/height fields 
01469         SetStringGadgetValue(_R(IDC_BMPOPTS_XPIXELS), &String_8(""));
01470         SetStringGadgetValue(_R(IDC_BMPOPTS_YPIXELS), &String_8(""));
01471 
01472         RecalculatingPixels = FALSE;     // flag no updates to dpi field from RecalculateDpiFromX, Y
01473     }
01474 }
01475 
01476 /******************************************************************************************
01477 
01478 >   void    BmpPrefsDlg::RecalculateDpiFromX()
01479 
01480     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01481     Created:    22/3/95
01482     Inputs:     -
01483     Outputs:    -
01484     Returns:    -
01485     Purpose:    Takes the size of the selection/spread/drawing and the size in the pixel
01486                 width field and calculates a new current dpi from this.
01487     Errors:     -
01488     SeeAlso:    -
01489 
01490 ******************************************************************************************/
01491 
01492 void    BmpPrefsDlg::RecalculateDpiFromX()
01493 {    
01494     // If the RecalculatePixels() function is setting the values then make sure we
01495     // do not update the values as well. 
01496     if (RecalculatingPixels || RecalculatingYDpi)
01497         return;
01498 
01499     // Now work out the pixel sizes which this will correspond to at the current dpi setting
01500     // Get the x and y pixel sizes from the editable fields, with no error reporting
01501     // Use 9 as minimum so that when deleting, the dpi is not blanked when down to one digit
01502     BOOL Valid = FALSE; // Flag for validity of value
01503     PixelWidth = GetLongGadgetValue(_R(IDC_BMPOPTS_XPIXELS), 9, INT32_MAX, NULL ,&Valid);
01504 
01505     if ( Valid ) 
01506     {
01507         RecalculatingXDpi = TRUE;
01508 
01509         double Resolution = (Width>0) ? ((double) PixelWidth * 72000.0) / ((double) Width) : 96.0;
01510 
01511         // A bit of a safety net here
01512         if ((Resolution < 5.0) || (Resolution > D_MAXDPI))
01513         {
01514             // There is a problem with the x pixels field so blank the pixel height
01515             // and dpi fields 
01516             SetStringGadgetValue(_R(IDC_BMPOPTS_YPIXELS), &String_8(""));
01517             if (m_bDpiSupported)
01518             {
01519                 SetStringGadgetValue(_R(IDC_BMPOPTS_RES), &String_8(""), FALSE, -1);
01520             }
01521         }
01522         else
01523         {
01524             // Use 0.5 so that we are forced to round up to the next dpi, if possible
01525             INT32 b_dpi = (INT32)(Resolution + 0.5);
01526             Dpi = b_dpi; //Resolution;
01527             if (m_bDpiSupported)
01528             {
01529                 //SetDoubleGadgetValue(_R(IDC_BMPOPTS_RES), Dpi, FALSE, -1);
01530                 SetLongGadgetValue(_R(IDC_BMPOPTS_RES), (INT32)Dpi, FALSE, -1);
01531             }
01532 
01533             // Given the new dpi, recalculate the y pixels
01534             // This is once again the calculation we are doing
01535             // INT32 PixelHeight = (INT32)(((Height * Dpi)/72000) + 0.5);
01536             // but using the same code that wil be used for exporting
01537             Matrix Identity;    // default construction is an identity matrix
01538             WinRect Rect = OSRenderRegion::BitmapDocRectToWin( Identity, ClipRect, Dpi );
01539             PixelHeight = Rect.Height();
01540             SetLongGadgetValue(_R(IDC_BMPOPTS_YPIXELS), PixelHeight);
01541         }
01542                 
01543         RecalculatingXDpi = FALSE;
01544     }
01545     else
01546     {
01547         RecalculatingXDpi = TRUE;
01548 
01549         // There is a problem with the x pixels field so blank the pixel height
01550         // and dpi fields 
01551         SetStringGadgetValue(_R(IDC_BMPOPTS_YPIXELS), &String_8(""));
01552         if (m_bDpiSupported)
01553         {
01554             SetStringGadgetValue(_R(IDC_BMPOPTS_RES), &String_8(""), FALSE, -1);
01555         }
01556 
01557         RecalculatingXDpi = FALSE;
01558     }
01559 }
01560 
01561 /******************************************************************************************
01562 
01563 >   void    BmpPrefsDlg::RecalculateDpiFromY()
01564 
01565     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01566     Created:    22/3/95
01567     Inputs:     -
01568     Outputs:    -
01569     Returns:    -
01570     Purpose:    Takes the size of the selection/spread/drawing and the size in the pixel
01571                 height field and calculates a new current dpi from this.
01572     Errors:     -
01573     SeeAlso:    -
01574 
01575 ******************************************************************************************/
01576 
01577 void    BmpPrefsDlg::RecalculateDpiFromY()
01578 {    
01579     // If the RecalculatePixels() function is setting the values then make sure we
01580     // do not update the values as well. 
01581     if (RecalculatingPixels || RecalculatingXDpi)
01582         return;
01583 
01584     // Now work out the pixel sizes which this will correspond to at the current dpi setting
01585     // Get the x and y pixel sizes from the editable fields, with no error reporting
01586     // Use 9 as minimum so that when deleting, the dpi is not blanked when down to one digit
01587     BOOL Valid = FALSE;     // Flag for validity of value
01588     PixelHeight = GetLongGadgetValue(_R(IDC_BMPOPTS_YPIXELS), 9, INT32_MAX, NULL ,&Valid);
01589 
01590     if ( Valid ) 
01591     {
01592         RecalculatingYDpi = TRUE;
01593         
01594         double Resolution = (Height>0) ? ((double) PixelHeight * 72000.0) / ((double) Height) : 96.0;
01595 
01596         // A bit of a safety net here
01597         if ((Resolution < 5.0) || (Resolution > D_MAXDPI))
01598         {
01599             // There is a problem with the y pixels field so blank the pixel width
01600             // and dpi fields 
01601             SetStringGadgetValue(_R(IDC_BMPOPTS_XPIXELS), &String_8(""));
01602             if (m_bDpiSupported)
01603             {
01604                 SetStringGadgetValue(_R(IDC_BMPOPTS_RES), &String_8(""), FALSE, -1);
01605             }
01606         }
01607         else
01608         {
01609             // Use 0.5 so that we are forced to round up to the next dpi, if possible
01610             INT32 b_dpi = (INT32)(Resolution + 0.5);
01611             Dpi = b_dpi; //Resolution;
01612             {
01613                 //SetDoubleGadgetValue(_R(IDC_BMPOPTS_RES), Dpi, FALSE, -1);
01614                 SetLongGadgetValue(_R(IDC_BMPOPTS_RES), (INT32)Dpi, FALSE, -1);
01615             }
01616             
01617             // Given the new dpi, recalculate the y pixels
01618             // This is once again the calculation we are doing
01619             // INT32 PixelWidth = (INT32)(((Width * Dpi)/72000) + 0.5);
01620             // but using the same code that wil be used for exporting
01621             Matrix Identity;    // default construction is an identity matrix
01622             WinRect Rect = OSRenderRegion::BitmapDocRectToWin( Identity, ClipRect, Dpi );
01623             PixelWidth = Rect.Width();
01624             SetLongGadgetValue(_R(IDC_BMPOPTS_XPIXELS), PixelWidth);
01625         }
01626 
01627         RecalculatingYDpi = FALSE;
01628     }
01629     else
01630     {
01631         RecalculatingYDpi = TRUE;
01632 
01633         // There is a problem with the y pixels field so blank the pixel width
01634         // and dpi fields 
01635         SetStringGadgetValue(_R(IDC_BMPOPTS_XPIXELS), &String_8(""));
01636         if (m_bDpiSupported)
01637         {
01638             SetStringGadgetValue(_R(IDC_BMPOPTS_RES), &String_8(""), FALSE, -1);
01639         }
01640 
01641         RecalculatingYDpi = FALSE;
01642     }
01643 }
01644 
01645 /******************************************************************************************
01646 
01647 >   void    BmpPrefsDlg::SetBPPButtons(GadgetID ButtonClicked,BOOL CheckNumColValueRange)
01648 
01649     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
01650     Created:    24/08/94
01651     Inputs:     the id of the clicked radio button
01652                 CheckNumColValueRange = TRUE if the value in the num col ed field should be checked. (added for WEBSTER - markn 1/2/97)
01653     Outputs:    -
01654     Returns:    -
01655     Purpose:    Sets all other radio buttons in the group off
01656     Errors:     -
01657     SeeAlso:    -
01658 
01659 ******************************************************************************************/
01660 
01661 void BmpPrefsDlg::SetBPPButtons(CGadgetID ButtonClicked,BOOL CheckNumColValueRange)
01662 {    
01663     BitmapExportOptions* pOptions = GetOptions();
01664     if (pOptions == NULL)
01665     {
01666         ERROR3("pOptions == NULL");
01667         return;
01668     }
01669 
01670     // WEBSTER - markn 23/1/97
01671     SetLongGadgetValue(ButtonClicked, TRUE);
01672 
01673     BOOL EnablePalette = FALSE;
01674 
01675     // If either 8, 4 or 1 bpp clicked then enable the Palette and Dithering Options
01676     if ( ButtonClicked == _R(IDC_BMPOPTS_8BPP) || ButtonClicked == _R(IDC_BMPOPTS_4BPP)  || ButtonClicked == _R(IDC_BMPOPTS_1BPP))
01677         EnablePalette = TRUE;
01678 
01679     EnableGadget(_R(IDC_BMPOPTS_PAL_STD), EnablePalette);
01680     EnableGadget(_R(IDC_BMPOPTS_PAL_OPT), EnablePalette);
01681     EnableGadget(_R(IDC_BMPOPTS_NODITHER),  EnablePalette);
01682     EnableGadget(_R(IDC_BMPOPTS_DIFFUSION), EnablePalette);
01683 
01684     if (EnablePalette)
01685     {
01686         BOOL Valid = 0;
01687         if ( GetLongGadgetValue(_R(IDC_BMPOPTS_PAL_OPT), 0, 1, 0, &Valid) )
01688             EnableGadget(_R(IDC_BMPOPTS_ORDDITHER), FALSE);
01689         else
01690             EnableGadget(_R(IDC_BMPOPTS_ORDDITHER), TRUE);
01691     }
01692     else
01693         EnableGadget(_R(IDC_BMPOPTS_ORDDITHER), FALSE);
01694 
01695     // WEBSTER - markn 17/1/97
01696     // Only update for relevant filters
01697     if (pOptions->UseSpecificNumColsInPalette())
01698         UpdateNumColoursGroup(CheckNumColValueRange);   // New parameter - WEBSTER - markn 1/2/97
01699 
01700     if (pOptions->GetFilterType() == MAKE_BITMAP_FILTER)
01701     {
01702         // Disable transparency button in same circustances as
01703         // the palette buttons are disabled
01704         EnableGadget(_R(IDC_BMPOPTS_TRANSPARENT), EnablePalette);
01705 
01706         // If we're greying out the button, turn off the transparency flag too
01707         // so that we take no notice of it when it's grey
01708         if (!EnablePalette)
01709         {
01710             SetLongGadgetValue(_R(IDC_BMPOPTS_TRANSPARENT), 0);
01711         }
01712         else
01713         {
01714             MaskedFilterExportOptions* pMaskOptions = (MaskedFilterExportOptions*)pOptions;
01715             ERROR3IF(!pMaskOptions->IS_KIND_OF(MaskedFilterExportOptions), "pMaskOptions isn't");
01716 
01717             SetLongGadgetValue(_R(IDC_BMPOPTS_TRANSPARENT), pMaskOptions->WantTransparent());
01718         }
01719     }
01720 
01721     // Cope with the transparency button on a PNG options dialog box    
01722     if (pOptions->GetFilterType() == PNG) 
01723     {
01724         PNGExportOptions* pPNGOptions = (PNGExportOptions*)pOptions;
01725         ERROR3IF(!pPNGOptions->IS_KIND_OF(PNGExportOptions), "pPNGOptions isn't");
01726         // Now enable or disable the transparency if we are in the wrong bpp mode
01727         // Transparency only available in 8 bpp mode or less
01728         BOOL Enable = FALSE;
01729         if ( ButtonClicked == _R(IDC_BMPOPTS_8BPP) || ButtonClicked == _R(IDC_BMPOPTS_4BPP) ||
01730              ButtonClicked == _R(IDC_BMPOPTS_1BPP) )
01731             Enable = TRUE;
01732 
01733         // Enable should be True if 8bpp or 4bpp or 1bpp button is On and False if not 
01734         EnableGadget(_R(IDC_BMPOPTS_TRANSPARENT), Enable);
01735         if (!Enable)
01736         {
01737             SetLongGadgetValue(_R(IDC_BMPOPTS_TRANSPARENT), 0);
01738         }
01739         else
01740         {
01741             SetLongGadgetValue(_R(IDC_BMPOPTS_TRANSPARENT), pPNGOptions->WantTransparent());
01742         }
01743     }
01744 
01745     // WEBSTER - markn 23/1/97
01746     // Compression group always hidden in Webster
01747     #ifndef WEBSTER
01748     // Cope with the compression buttons on a BMP options dialog box    
01749     if (pOptions->GetFilterType() == BMP_UNCOMPRESSED) 
01750     {
01751         // Now enable or disable the switches that are dependent on the 8 bpp switch 
01752         // RLE compression switch, only available in 8 bpp mode or 4 bpp
01753         BOOL Enable = FALSE;
01754         if ( ButtonClicked == _R(IDC_BMPOPTS_8BPP) || ButtonClicked == _R(IDC_BMPOPTS_4BPP) )
01755             Enable = TRUE;
01756 
01757         // Enable should be True if 8bpp or 4bpp button is On and False if not 
01758         // Present only on the BMP export dialog box
01759         EnableGadget(_R(IDC_BMPOPTS_COMPRESS), Enable);     // main group icon
01760         EnableGadget(_R(IDC_BMPOPTS_RLE), Enable);
01761         EnableGadget(_R(IDC_BMPOPTS_RGB), Enable);
01762     }
01763     #endif // WEBSTER
01764 
01765     // Cope with the compression buttons on a TIFF options dialog box   
01766     // Enable should be True if 8bpp or 4bpp button is On and False if not 
01767     if (pOptions->GetFilterType() == TIFF_UNCOMPRESSED) 
01768     {
01769     //WEBSTER-Martin-06/01/97
01770 #ifndef WEBSTER
01771         TIFFExportOptions* pTIFFOptions = (TIFFExportOptions*)pOptions;
01772         ERROR3IF(!pTIFFOptions->IS_KIND_OF(TIFFExportOptions), "pTIFFOptions isn't");
01773     
01774         // Now enable or disable the compression options depending upon the BPP
01775         BOOL bEnableLZW = FALSE;
01776         BOOL bEnableMonoCompression = FALSE;
01777 
01778         if ( ButtonClicked == _R(IDC_BMPOPTS_1BPP))
01779             bEnableMonoCompression = TRUE;
01780 
01781         if ( ButtonClicked == _R(IDC_BMPOPTS_24BPP) || ButtonClicked == _R(IDC_BMPOPTS_8BPP) || ButtonClicked == _R(IDC_BMPOPTS_CMYK) )
01782             bEnableLZW = TRUE;
01783 
01784 
01785         // Cannot grey items in the list so we need to change the list itself.
01786         // But only change it if we need to. Check last state and see if we have changed.
01787         // from 1bpp or to 1bpp.
01788         if ( /*
01789             (LastBppSelected == _R(IDC_BMPOPTS_1BPP) && ButtonClicked != _R(IDC_BMPOPTS_1BPP)) ||
01790             (LastBppSelected != _R(IDC_BMPOPTS_1BPP) && ButtonClicked == _R(IDC_BMPOPTS_1BPP))
01791            */ TRUE )
01792         {
01793             // So, set up the list of available TIFF compressions. Must be the same as the list
01794             // in TiffTypes.
01795             //TiffTypes CompressionType = (TiffTypes)GetSelectedValueIndex(_R(IDC_BMPOPTS_TIFF));
01796             
01797             // Andy Hills, 05-09-00
01798             // We can't use TiffTypes to determine the selection.
01799             // This is because the list of compression types changes between bpp settings.
01800             // Instead we will call the new function GetTIFFCompressionSelection
01801             // which works out which compression type is selected.
01802             // We need to tell it which bpp is selected.
01803 
01804             INT32 nBPP;
01805             switch( ButtonClicked )
01806             {
01807             case _R(IDC_BMPOPTS_1BPP):  nBPP=1;     break;
01808             case _R(IDC_BMPOPTS_4BPP):  nBPP=4;     break;
01809             case _R(IDC_BMPOPTS_8BPP):  nBPP=8;     break;
01810             case _R(IDC_BMPOPTS_24BPP): nBPP=24;    break;
01811             case _R(IDC_BMPOPTS_CMYK):  nBPP=32;    break;
01812             default:
01813                 ERROR3( "BmpPrefsDlg::SetBPPButtons - invalid bpp obtained" );
01814             }
01815             
01816             INT32 CompressionType = GetTIFFCompressionSelection(nBPP);
01817 
01818             // First delete all present items
01819             DeleteAllValues(_R(IDC_BMPOPTS_TIFF));
01820             // Set up the default value in the editable field
01821             BOOL ok = SetLongGadgetValue(_R(IDC_BMPOPTS_TIFF), pTIFFOptions->GetCompression(), FALSE, -1);
01822 
01823             // Set all the basic options (i.e. no compression)
01824             SetStringGadgetValue(_R(IDC_BMPOPTS_TIFF), &String_32(_R(IDN_TIFF_NONE)));
01825 
01826             // Andy Hills, 16-08-00: re-added LZW export
01827             if (bEnableLZW)
01828             {
01829                 // 8 / 24-bit, so enable LZW
01830                 SetStringGadgetValue(_R(IDC_BMPOPTS_TIFF), &String_32(_R(IDN_TIFF_LZW)));
01831             }
01832 
01833             if (bEnableMonoCompression)
01834             {
01835                 // 1bpp so allow all options (except LZW)
01836                 SetStringGadgetValue(_R(IDC_BMPOPTS_TIFF), &String_32(_R(IDN_TIFF_HUFFMAN)));
01837                 SetStringGadgetValue(_R(IDC_BMPOPTS_TIFF), &String_32(_R(IDN_TIFF_G3FAX)));
01838                 SetStringGadgetValue(_R(IDC_BMPOPTS_TIFF), &String_32(_R(IDN_TIFF_G4FAX)));
01839                 SetStringGadgetValue(_R(IDC_BMPOPTS_TIFF), &String_32(_R(IDN_TIFF_PACKBITS)));
01840                 //SetStringGadgetValue(_R(IDC_BMPOPTS_TIFF), &String_32(_R(IDN_TIFF_2DENCODING)));
01841             }
01842 
01843             SetComboListLength(_R(IDC_BMPOPTS_TIFF));
01844 
01845             // Select the correct item again
01846 
01847             if( nBPP == 1 && LastBppSelected != _R(IDC_BMPOPTS_1BPP) && LastBppSelected )
01848             {
01849                 // changing to 1bpp
01850                 // --> set compression to NONE
01851                 ok = SetTIFFCompressionSelection( TIFF_UNCOMPRESSED, nBPP );
01852                 
01853                 // We should ALWAYS be able to select UNCOMPRESSED
01854                 ERROR3IF( (!ok), "BmpPrefsDlg::SetBPPButtons - could not select uncompressed" );
01855             }
01856             else if( nBPP >= 8 && 
01857                 (LastBppSelected == _R(IDC_BMPOPTS_1BPP) || LastBppSelected == _R(IDC_BMPOPTS_4BPP)) )
01858             {
01859                 // changing to 8/24bpp (from 1/4bpp)
01860                 // --> set compression to LZW
01861                 ok = SetTIFFCompressionSelection( TIFF_LZW, nBPP );
01862                 
01863                 // We should ALWAYS be able to select LZW from 8/24 bpp
01864                 ERROR3IF( (!ok), "BmpPrefsDlg::SetBPPButtons - could not select LZW" );
01865             }
01866             else
01867             {
01868                 // otherwise, just leave compression as it is
01869                 ok = SetTIFFCompressionSelection( CompressionType, nBPP );
01870                 
01871                 // if the previously selected compression is now disabled, select NONE
01872                 if( ! ok )
01873                 {
01874                     //SetSelectedValueIndex(_R(IDC_BMPOPTS_TIFF), _R(IDN_TIFF_NONE));
01875                     ok = SetTIFFCompressionSelection( TIFF_UNCOMPRESSED, nBPP );
01876                     
01877                     // We should ALWAYS be able to select UNCOMPRESSED
01878                     ERROR3IF( (!ok), "BmpPrefsDlg::SetBPPButtons - could not select uncompressed" );
01879                 }
01880             }
01881         }
01882     
01883         // Update the last button to be the one just selected
01884         LastBppSelected = ButtonClicked;
01885 #endif //WEBSTER
01886     }
01887 }
01888 
01889 /******************************************************************************************
01890 
01891 >   void BmpPrefsDlg::SetPaletteButtons(GadgetID ButtonClicked)
01892 
01893     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01894     Created:    29/05/96
01895     Inputs:     the id of the clicked radio button
01896     Outputs:    -
01897     Returns:    -
01898     Purpose:    Sets all other radio buttons in the group off
01899     Errors:     -
01900     SeeAlso:    -
01901 
01902 ******************************************************************************************/
01903 
01904 void BmpPrefsDlg::SetPaletteButtons(CGadgetID ButtonClicked)
01905 {    
01906     if ( ButtonClicked == _R(IDC_BMPOPTS_PAL_OPT) )
01907     {
01908         BOOL Valid = 0;
01909         if ( GetLongGadgetValue(_R(IDC_BMPOPTS_ORDDITHER), 0, 1, 0, &Valid) )
01910         {
01911             SetLongGadgetValue(_R(IDC_BMPOPTS_ORDDITHER), FALSE);
01912             SetLongGadgetValue(_R(IDC_BMPOPTS_DIFFUSION), TRUE);
01913         }
01914 
01915         SetLongGadgetValue(_R(IDC_BMPOPTS_PAL_OPT), TRUE);
01916         
01917         EnableGadget(_R(IDC_BMPOPTS_ORDDITHER), FALSE);
01918 
01919         // WEBSTER - markn 17/1/97
01920         // Update num colours group
01921         UpdateNumColoursGroup(FALSE);
01922     }
01923     else
01924     {
01925         SetLongGadgetValue(_R(IDC_BMPOPTS_PAL_STD), TRUE);
01926             
01927         EnableGadget(_R(IDC_BMPOPTS_ORDDITHER), TRUE);
01928 
01929         // WEBSTER - markn 17/1/97
01930         UpdateNumColoursGroup(FALSE);
01931     }
01932 }
01933 
01934 /******************************************************************************************
01935 
01936 >   void BmpPrefsDlg::SetDitherButtons(GadgetID ButtonClicked)
01937 
01938     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
01939     Created:    29/05/96
01940     Inputs:     the id of the clicked radio button
01941     Outputs:    -
01942     Returns:    -
01943     Purpose:    Sets all other radio buttons in the group off
01944     Errors:     -
01945     SeeAlso:    -
01946 
01947 ******************************************************************************************/
01948 
01949 void BmpPrefsDlg::SetDitherButtons(CGadgetID ButtonClicked)
01950 {    
01951 }
01952 
01953 
01954 /******************************************************************************************
01955 
01956 >   TIFF_COMPRESSION BmpPrefsDlg::GetTIFFCompressionSelection( INT32 nBPP )
01957 
01958     Author:     Andy_Hills (Xara Group Ltd) <camelotdev@xara.com>
01959     Created:    05/09/00
01960     Inputs:     nBPP        Currently selected bits-per-pixel
01961     Outputs:    
01962     Returns:    The currently selected compression type.
01963     Purpose:    This function has been added because no allowances have been
01964                 made for the fact that the compression options list is
01965                 different for each BPP setting.
01966     Errors:     Returns -1 on failure.
01967     SeeAlso:    SetBPPButtons
01968 
01969 ******************************************************************************************/
01970 
01971 TIFF_COMPRESSION BmpPrefsDlg::GetTIFFCompressionSelection( INT32 nBPP )
01972 {
01973     // Get the state of the TIFF compression selection combo box
01974     TIFF_COMPRESSION Compression;
01975     INT32 nIndex = GetSelectedValueIndex(_R(IDC_BMPOPTS_TIFF));
01976 
01977     if( nBPP == 1 )
01978     {
01979         switch ( nIndex )
01980         {
01981             case TWODENCODING_TIFF: Compression = TIFF_2D;              break;
01982             case PACKBITS_TIFF:     Compression = TIFF_PACK;            break;
01983             case HUFFMAN_TIFF:      Compression = TIFF_HUFFMAN;         break;
01984             case G3FAX_TIFF:        Compression = TIFF_G3_FAX;          break;
01985             case G4FAX_TIFF:        Compression = TIFF_G4_FAX;          break;
01986             default:                
01987             case UNCOMPRESSED_TIFF: Compression = TIFF_UNCOMPRESSED;    break;
01988         }
01989     }
01990     else if( nBPP==8 || nBPP==24 || nBPP==32 )
01991     {
01992         switch ( nIndex )
01993         {
01994             case LZW_TIFF:          Compression = TIFF_LZW;             break;
01995             default:                
01996             case UNCOMPRESSED_TIFF: Compression = TIFF_UNCOMPRESSED;    break;
01997         }
01998     }
01999     else if( nBPP == 4 )
02000     {
02001         Compression = TIFF_UNCOMPRESSED;
02002     }
02003     else
02004     {
02005         ERROR2( -1, "BmpPrefsDlg::GetTIFFCompressionSelection - invalid nBPP" );
02006     }
02007     
02008     return Compression;
02009 }
02010 
02011 
02012 /******************************************************************************************
02013 
02014 >   BOOL BmpPrefsDlg::SetTIFFCompressionSelection( TIFF_COMPRESSION Compression, INT32 nBPP )
02015 
02016     Author:     Andy_Hills (Xara Group Ltd) <camelotdev@xara.com>
02017     Created:    05/09/00
02018     Inputs:     Compression     Desired compression setting
02019                 nBPP            Currently selected bits-per-pixel
02020     Outputs:    
02021     Returns:    TRUE on success
02022     Purpose:    This function has been added because no allowances have been
02023                 made for the fact that the compression options list is
02024                 different for each BPP setting.
02025     Errors:     Returns FALSE on failure
02026                 e.g. if the specified compression type is not available with the current
02027                 bpp setting.
02028     SeeAlso:    SetBPPButtons
02029 
02030 ******************************************************************************************/
02031 
02032 BOOL BmpPrefsDlg::SetTIFFCompressionSelection( TIFF_COMPRESSION Compression, INT32 nBPP )
02033 {
02034     if( nBPP == 1 )
02035     {
02036         if
02037         (
02038             Compression != TIFF_2D &&
02039             Compression != TIFF_PACK &&
02040             Compression != TIFF_HUFFMAN &&
02041             Compression != TIFF_G3_FAX &&
02042             Compression != TIFF_G4_FAX &&
02043             Compression != TIFF_UNCOMPRESSED
02044         ) return FALSE;
02045     }
02046     else if( nBPP==8 || nBPP==24 || nBPP==32 )
02047     {
02048         if
02049         (
02050             Compression != TIFF_LZW &&
02051             Compression != TIFF_UNCOMPRESSED
02052         ) return FALSE;
02053     }
02054     else if( nBPP == 4 )
02055     {
02056         if
02057         (
02058             Compression != TIFF_UNCOMPRESSED
02059         ) return FALSE;
02060     }
02061     else
02062     {
02063         ERROR2( -1, "BmpPrefsDlg::GetTIFFCompressionSelection - invalid nBPP" );
02064     }
02065     
02066     // look up the index of the compression type
02067     INT32 nIndex;
02068     switch ( Compression )
02069     {
02070         case TIFF_UNCOMPRESSED: nIndex = UNCOMPRESSED_TIFF; break;
02071         case TIFF_LZW:          nIndex = LZW_TIFF;          break;
02072         case TIFF_HUFFMAN:      nIndex = HUFFMAN_TIFF;      break;
02073         case TIFF_G3_FAX:       nIndex = G3FAX_TIFF;        break;
02074         case TIFF_G4_FAX:       nIndex = G4FAX_TIFF;        break;
02075         case TIFF_PACK:         nIndex = PACKBITS_TIFF;     break;
02076         case TIFF_2D:           nIndex = TWODENCODING_TIFF; break;
02077         default:                nIndex = UNCOMPRESSED_TIFF; break;
02078     }
02079 
02080     // Actually select the compression type.
02081     return SetSelectedValueIndex(_R(IDC_BMPOPTS_TIFF), nIndex);
02082 }
02083 
02084 
02085 /******************************************************************************************
02086 
02087 >   BOOL BmpPrefsDlg::CommitDialogValues(BmpPrefsDlg* pBmpPrefs)
02088 
02089     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02090     Created:    03/10/94
02091     Inputs:     pointer to the dialogue box
02092     Outputs:    -
02093     Returns:    True if values in dialog box ok, False otherwise.     
02094     Purpose:    Takes the values in the dialog box and sets the return values accordingly
02095                 Called when ok is pressed on the dialog box.
02096     Errors:     -
02097     SeeAlso:    -
02098 
02099 ******************************************************************************************/
02100 
02101 BOOL BmpPrefsDlg::CommitDialogValues()
02102 {
02103     BitmapExportOptions* pOptions = GetOptions();
02104     ERROR2IF(pOptions == NULL, FALSE, "BmpPrefsDlg::CommitDialogValues called after duff initialisation?!");
02105 
02106     // Ok has been pressed so take the values and set up the static values so that the
02107     // caller can access them
02108 
02109     BOOL Valid = 0; // Flag for validity of value
02110 
02111     //Added by Graham 27/5/97
02112     //First, let's set the pixel width and height into our OutputSize option
02113     pOptions->SetPixelOutputSize(PixelWidth, PixelHeight);
02114 
02115     // Although the file format may not support DPI, BaseBitmapFilter::PrepareToExport doesn't support
02116     // anything else. Since we may want to stretch the selection, we therefore need to supply a bogus dpi
02117     // based on the desired export size. dpi supporting formats can follow the mess...
02118     if (m_bDpiSupported)
02119     {
02120         // Get the dpi value from the resolution combo box
02121         // Minimum of 5dpi as anything lower causes major problems.  
02122         //double Value = GetDoubleGadgetValue(_R(IDC_BMPOPTS_RES), 5.0, D_MAXDPI, _R(IDS_BMPPREFS_INVALIDDPI) ,&Valid);
02123         double Value = (double)GetLongGadgetValue(_R(IDC_BMPOPTS_RES), 5, MAXDPI, _R(IDS_BMPPREFS_INVALIDDPI) ,&Valid);
02124         if (Valid) 
02125         {
02126             // If returned value in range then set the new default
02127             pOptions->SetDPI(Value);
02128         }
02129         else
02130             return FALSE;
02131 
02132         RecalculatePixels();
02133     }
02134     else
02135     {
02136         double Resolution = (Width>0) ? ((double) PixelWidth * 72000.0) / ((double) Width) : 96.0;
02137         // A bit of a safety net here
02138         if (Resolution < 5.0)
02139         {
02140             // User has set an illegal state so warn them about it.
02141             InformError(_R(IDS_BMPPREFS_DPITOOSMALL));
02142             //Dpi = 0;
02143             return FALSE;
02144         }
02145         else if (Resolution > D_MAXDPI)
02146         {
02147             // User has set an illegal state so warn them about it.
02148             InformError(_R(IDS_BMPPREFS_DPITOOBIG));
02149             //Dpi = 0;
02150             return FALSE;
02151         }
02152         else
02153         {
02154             INT32 b_dpi = (INT32)(Resolution + 0.5);
02155             Dpi = b_dpi; //Resolution;
02156         }
02157         pOptions->SetDPI(Dpi);
02158     }
02159 
02160     // Get the output depth from the bpp radio buttons
02161     BOOL State = 0;
02162     UINT32 Depth = 24;
02163     if ( GetLongGadgetValue(_R(IDC_BMPOPTS_CMYK), 0, 1, 0, &Valid) )
02164     {
02165         pOptions->SetCMYK(TRUE);
02166         Depth = 32;
02167     }
02168     else if ( GetLongGadgetValue(_R(IDC_BMPOPTS_24BPP), 0, 1, 0, &Valid) )
02169         Depth = 24;
02170     else if ( GetLongGadgetValue(_R(IDC_BMPOPTS_8BPP), 0, 1, 0, &Valid) )
02171         Depth = 8;
02172     else if ( GetLongGadgetValue(_R(IDC_BMPOPTS_4BPP), 0, 1, 0, &Valid) )
02173         Depth = 4;
02174     else if ( GetLongGadgetValue(_R(IDC_BMPOPTS_1BPP), 0, 1, 0, &Valid) )
02175         Depth = 1;
02176     pOptions->SetDepth(Depth);
02177 
02178     // WEBSTER - markn 17/1/97
02179     // NOTE! This can change the Depth value set earlier in this function
02180     if (!SetNumColoursInPalette(pOptions))
02181         return FALSE;
02182 
02183     // Get the Palette setting from the radio buttons
02184     PALETTE Palette = PAL_STANDARD;
02185     if ( GetLongGadgetValue(_R(IDC_BMPOPTS_PAL_OPT), 0, 1, 0, &Valid) )
02186     {
02187         TRACEUSER( "Will", _T("Optimised Palette selected\n"));
02188         Palette = PAL_OPTIMISED;
02189     }
02190 
02191     // Get the dither type from the radio buttons
02192     DITHER DitherType = XARADITHER_ERROR_DIFFUSION;
02193     if ( GetLongGadgetValue(_R(IDC_BMPOPTS_NODITHER), 0, 1, 0, &Valid) )
02194         DitherType = XARADITHER_NONE;
02195     else if ( GetLongGadgetValue(_R(IDC_BMPOPTS_ORDDITHER), 0, 1, 0, &Valid) )
02196         DitherType = XARADITHER_ORDERED_GREY;
02197     else if ( GetLongGadgetValue(_R(IDC_BMPOPTS_DIFFUSION), 0, 1, 0, &Valid) )
02198         DitherType = XARADITHER_ERROR_DIFFUSION;
02199 
02200     TRACEUSER( "Will", _T("Dither %d selected\n"), DitherType);
02201 
02202     // Check that we have not gone over our GDraw limits for pixel width
02203     // Pixel height should not be so much of a problem as we will strip the export. 
02204 
02205     // This cast is here because PixelWidth is a signed number (for some odd reason)
02206     if ((DWORD) PixelWidth > GRenderRegion::GetMaxBitmapWidth() ||
02207         (DWORD) PixelWidth < 1 || (DWORD) PixelHeight < 1 )
02208     {
02209         // There is a problem so warn the user that the value is incorrect
02210         String_256 WarnMsg;
02211 
02212         WarnMsg.MakeMsg(_R(IDE_BMP_BADPIXELWIDTH), GRenderRegion::GetMaxBitmapWidth());
02213         Error::SetError(0, WarnMsg, 0);
02214         InformWarning(0, _R(IDS_OK));
02215         return FALSE; 
02216     }
02217 
02218     // Mostly the compression fields change according to the filter type in use
02219     switch ( pOptions->GetFilterType() ) 
02220     {
02221         case TIFF_UNCOMPRESSED:
02222         {
02223             //WEBSTER-Martin-03/01/97
02224 #ifndef WEBSTER
02225             TIFFExportOptions* pTIFFOptions = (TIFFExportOptions*)pOptions;
02226             ERROR3IF(!pTIFFOptions->IS_KIND_OF(TIFFExportOptions), "pTIFFOptions isn't");
02227 
02228             // Get the state of the TIFF compression selection combo box
02229             TIFF_COMPRESSION Compression = GetTIFFCompressionSelection(Depth);
02230             ERROR2IF( (Compression==-1), FALSE, "BmpPrefsDlg::CommitDialogValues - invalid compresion type" );
02231             pTIFFOptions->SetCompression(Compression);
02232 
02233 //Mark Howitt, 27/10/97. We need to setup both the Dither & Palette for the TIFF Options, as well as
02234 //                       the Accusoft DitherToUse variable to ensure proper functionality.
02235             pTIFFOptions->SetDither(DitherType);
02236             pTIFFOptions->SetPalette(Palette);
02237             AccusoftFilters::SetDitherToUse(DitherType);
02238 
02239 #endif //WEBSTER
02240             break;
02241         }
02242         case PNG:
02243         {
02244             PNGExportOptions* pPNGOptions = (PNGExportOptions*)pOptions;
02245             ERROR3IF(!pPNGOptions->IS_KIND_OF(PNGExportOptions), "pPNGOptions isn't");
02246 
02247             // GIF radio buttons used to hold the transparent/interlaced settings
02248             BOOL Interlace = GetLongGadgetValue(_R(IDC_BMPOPTS_INTERLACED), 0, 1, 0, &Valid);
02249             BOOL Transparent = GetLongGadgetValue(_R(IDC_BMPOPTS_TRANSPARENT), 0, 1, 0, &Valid);
02250             // Transparency is not available at present
02251             // Only if we are exporting as a 32bpp bitmap.
02252             if (Valid)
02253             {
02254                 //pPNGOptions->SetMakeTransparent(Transparent);
02255                 pPNGOptions->SetMakeInterlaced(Interlace);
02256 
02257                 // WEBSTER - markn 5/2/97
02258                 // If the user has deselected Transparent, then make sure the cached index is set to -1
02259                 if (!Transparent)
02260                     pPNGOptions->SetTransparencyIndex(-1);
02261             }
02262             pPNGOptions->SetDither(DitherType);
02263 //          pPNGOptions->SetPalette(Palette);
02264             break;
02265         }
02266 
02267         case MAKE_BITMAP_FILTER:
02268         {
02269             MakeBitmapExportOptions* pMkBOptions = (MakeBitmapExportOptions*)pOptions;
02270             ERROR3IF(!pMkBOptions->IS_KIND_OF(MakeBitmapExportOptions), "pMkBOptions isn't");
02271 
02272             pMkBOptions->SetDither(DitherType);
02273 //          pMkBOptions->SetPalette(Palette);
02274 
02275             // radio buttons used to hold the transparent/interlaced settings
02276             BOOL Interlace = GetLongGadgetValue(_R(IDC_BMPOPTS_INTERLACED), 0, 1, 0, &Valid);
02277             BOOL Transparent = GetLongGadgetValue(_R(IDC_BMPOPTS_TRANSPARENT), 0, 1, 0, &Valid);
02278             //pMkBOptions->SetMakeTransparent(Transparent);
02279             pMkBOptions->SetMakeInterlaced(Interlace);
02280 
02281             break;
02282         }
02283         case TI_GIF:
02284         case TI_GIF_ANIM:
02285         {
02286             GIFExportOptions* pGIFOptions = (GIFExportOptions*)pOptions;
02287             ERROR3IF(!pGIFOptions->IS_KIND_OF(GIFExportOptions), "pGIFOptions isn't");
02288                                     
02289             pGIFOptions->SetDither(DitherType);
02290 //          pGIFOptions->SetPalette(Palette);
02291 
02292             // GIF radio buttons used to hold the transparent/interlaced settings
02293             BOOL Interlace = GetLongGadgetValue(_R(IDC_BMPOPTS_INTERLACED), 0, 1, 0, &Valid);
02294             BOOL Transparent = GetLongGadgetValue(_R(IDC_BMPOPTS_TRANSPARENT), 0, 1, 0, &Valid);
02295             //pGIFOptions->SetMakeTransparent(Transparent);
02296             pGIFOptions->SetMakeInterlaced(Interlace);
02297 
02298             // WEBSTER - markn 5/2/97
02299             // If the user has deselected Transparent, then make sure the cached index is set to -1
02300             if (!Transparent)
02301                 pGIFOptions->SetTransparencyIndex(-1);
02302 
02303             if (pOptions->GetFilterType() == TI_GIF)
02304             {
02305                 HideGadget(_R(IDC_ANIMOPTS_LOOP), TRUE);    
02306                 HideGadget(_R(IDC_ANIMOPTS_DELAY), TRUE);   
02307                 HideGadget(_R(IDC_ANIMOPTS_ITERATIONS), TRUE);
02308                 HideGadget(_R(IDC_ANIMOPTS_REMOVAL), TRUE); 
02309             }
02310 
02311             if (pOptions->GetFilterType() == TI_GIF_ANIM)
02312             {
02313                 UINT32 List = 0;
02314                 BmpDlgParam* pBmpDlgParam = pOptions->GetBmpDlgParam();
02315                                     
02316                 if (pBmpDlgParam != NULL)
02317                 {
02318                     KernelBitmap** pListOfBitmaps = pBmpDlgParam->GetBitmapList();
02319                     List = pBmpDlgParam->GetListSize();
02320 
02321                     ERROR3IF(pListOfBitmaps == NULL && List > 0, "Where Have Our Bitmaps Gone?");
02322                     
02323                     if(pListOfBitmaps != NULL)
02324                     {
02325                         pGIFOptions->SetBitmapList(pListOfBitmaps);
02326                         pGIFOptions->SetListSize(List);
02327                     }
02328                 }
02329                 
02330                 // Get the Animation Delay details.
02331                 if (HasDelayChanged)
02332                 {
02333                      CENTISECONDS Delay = GetLongGadgetValue(_R(IDC_ANIMOPTS_DELAY), 0, 65535, _R(IDS_BMPPREFS_INVALIDDELAY) ,&Valid);
02334                                      
02335                     if (Valid)
02336                     {
02337                         pBmpDlgParam->SetAnimDelay(Delay);
02338                         pBmpDlgParam->SetAreDelayValuesSame(TRUE);
02339 
02340                         UINT32 ListSize = pGIFOptions->GetListSize();
02341                         KernelBitmap** pListOfBitmaps = pGIFOptions->GetBitmapList();
02342 
02343                         ERROR3IF(pListOfBitmaps == NULL && ListSize > 0,"Do what");
02344 
02345                         // A new delay value has been set, store it in the bitmaps.
02346             
02347                         if (pListOfBitmaps != NULL)
02348                         {
02349                             while (ListSize > 0)
02350                             {
02351                                 KernelBitmap* pBitmap = pListOfBitmaps[--ListSize] ;    
02352 
02353                                 if(pBitmap != NULL)
02354                                 {
02355                                     pBitmap->SetDelay(pBmpDlgParam->GetAnimDelay());
02356                                 }
02357                             }
02358                         }
02359                     }
02360                     else
02361                         return FALSE;   
02362                 }
02363         
02364                 // Get the Animation Restore details.
02365                 if (HasRestoreChanged)
02366                 {
02367                     INT32 Restore  = GetSelectedValueIndex(_R(IDC_ANIMOPTS_REMOVAL));
02368                                 
02369                     if(Restore != OPTION_FOUR)
02370                     {
02371                         pBmpDlgParam->SetRestoreType((GIFDisposalMethod) Restore);
02372                         pBmpDlgParam->SetSameRestoreType(TRUE);
02373                         UINT32 ListSize = pGIFOptions->GetListSize();
02374 
02375                         KernelBitmap** pListOfBitmaps = pGIFOptions->GetBitmapList();
02376                         ERROR3IF(pListOfBitmaps == NULL && ListSize > 0,"Do what");
02377 
02378                         // A new Restore type has been entered, store it in the bitmaps.
02379                         if (pListOfBitmaps != NULL)
02380                         {
02381                             while (ListSize > 0)
02382                             {
02383                                 KernelBitmap* pKernelBitmap = pListOfBitmaps[--ListSize] ;  
02384 
02385                                 if (pKernelBitmap != NULL)
02386                                 {
02387                                     OILBitmap* pOILBitmap = pKernelBitmap->GetActualBitmap();
02388 
02389                                     if (pOILBitmap != NULL)
02390                                     {
02391                                         pOILBitmap->SetAnimationRestoreType(pBmpDlgParam->GetRestoreType());
02392     
02393                                     }
02394                                 }
02395                             }
02396                         }
02397                     }
02398                 }
02399                 // Get the Animation Loop details.
02400                 BOOL Value = GetBoolGadgetSelected(_R(IDC_ANIMOPTS_LOOP));
02401                 INT32 Loop = GetLongGadgetValue(_R(IDC_ANIMOPTS_ITERATIONS), 0, 65535, _R(IDS_BMPPREFS_INVALIDLOOP) ,&Valid);
02402                 if (Valid)
02403                 {
02404                     pGIFOptions->SetAnimationLoopCount(Loop, Value);
02405                 }
02406                 else
02407                     return FALSE;   
02408 
02409             }
02410             break;
02411         }
02412 
02413         case BMP_UNCOMPRESSED:
02414         {
02415             BMPExportOptions* pBMPOptions = (BMPExportOptions*)pOptions;
02416             ERROR3IF(!pBMPOptions->IS_KIND_OF(BMPExportOptions), "pBMPOptions isn't");
02417 
02418             // WEBSTER - markn 23/1/97
02419             // Can't do RLE without Accusoft
02420             #ifndef WEBSTER
02421             // Get the state of the compression buttons but only allowed in 4 and 8 bpp modes
02422             BMP_COMPRESSION Compression;
02423             State = GetLongGadgetValue(_R(IDC_BMPOPTS_RLE), 0, 1, 0, &Valid);
02424             if (State && (Depth == 4 || Depth == 8))
02425                 Compression = BMP_RLE;      // button on
02426             else
02427                 Compression = BMP_RGB;  // button off
02428 
02429             if (Valid)
02430             {
02431                 pBMPOptions->SetCompression(Compression);
02432             }
02433             #endif // WEBSTER
02434 
02435             pBMPOptions->SetCompression(BMP_RGB);
02436 
02437             pBMPOptions->SetDither(DitherType);
02438             pBMPOptions->SetPalette(Palette);
02439             break;
02440         }
02441 
02442         // The remaining AccusoftOnes:
02443         case WPG:
02444         case PHOTOCD:
02445         case IFF_ILBM:
02446         case XWD:
02447         case DCX:
02448         case PCX:
02449         case PICT:
02450         case RAST:
02451         case PHOTOSHOP:
02452         case TARGA:
02453         case MACPAINT:
02454         case MSP:
02455         {
02456             //WEBSTER-Martin-03/01/97
02457 #ifndef WEBSTER
02458             AccusoftExportOptions* pAccyOptions = (AccusoftExportOptions*)pOptions;
02459             ERROR3IF(!pAccyOptions->IS_KIND_OF(AccusoftExportOptions), "pAccyOptions isn't");
02460         
02461             pAccyOptions->SetDither(DitherType);
02462             pAccyOptions->SetPalette(Palette);
02463 #endif //WEBSTER
02464             break;
02465         }
02466             
02467         default:
02468             // At present, only BMP and TIFFs can change the compression type.
02469             // Just us mice here
02470             break;
02471     }
02472 
02473     // Get the state of the selection, drawing or spread buttons
02474     SelectionType FoundSelection = GetSelection();
02475     pOptions->SetSelectionType(FoundSelection);
02476 
02477     return TRUE;
02478 }
02479 
02480 
02481 /******************************************************************************************
02482 
02483 >   MsgResult BmpPrefsDlg::Message(CDlgMessage DlgMsg, CGadgetID Gadget) 
02484 
02485 
02486     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02487     Created:    28/08/94
02488     Inputs:     -
02489     Outputs:    -
02490     Returns:    -
02491     Purpose:    Handles all the bitmap preferences dialog's messages
02492     Errors:     -
02493     SeeAlso:    -
02494 
02495 ******************************************************************************************/
02496 
02497 MsgResult BmpPrefsDlg::Message(Msg* Message)
02498 {
02499     if (IS_OUR_DIALOG_MSG(Message))
02500     {
02501         DialogMsg* Msg = (DialogMsg*) Message;
02502         MsgResult Result;
02503         BOOL EndDialog = FALSE;     // TRUE if we should quit the dialog
02504 
02505         BitmapExportOptions* pOptions = GetOptions();
02506         ERROR3IF(pOptions == NULL, "BmpPrefsDlg::Message - Parameters not been set up");
02507 
02508         // Should now handle the required messages that we respond to
02509         switch (Msg->DlgMsg)
02510         {
02511             case DIM_CREATE:
02512                 {
02513                     // Make sure the updating variable is set to something sensible
02514                     RecalculatingPixels = FALSE;
02515                     RecalculatingXDpi = FALSE;
02516                     RecalculatingYDpi = FALSE;
02517 
02518                     // As it is a modal dialog box we are sent a message to say the dialog box
02519                     // is being created, so we have a chance to set the initial control values
02520                     // JPEG export has a special dialog box, all others use the same one 
02521                     InitDialog();
02522                     HasDelayChanged = FALSE;
02523                     HasRestoreChanged = FALSE;
02524                 }
02525             break;
02526 
02527             case DIM_COMMIT:
02528                 {
02529                     // (ok) accept all changes that the user has made to the settings
02530                     // brackets make the ok local to this case 
02531                     // JPEG export has a special dialog box, all others use the same one 
02532                     BOOL ok;
02533                     ok = CommitDialogValues();
02534                     if (ok)
02535                     {
02536                         // Values found ok so quit dialogue then go ahead and export
02537                         GetOptions()->MarkValid();          // Flag ok used
02538                         EndDialog = TRUE;               // Flag to close and end
02539                     }
02540                 }
02541             break;
02542 
02543             case DIM_CANCEL:
02544                 // Cancel all changes that the user has made to the settings
02545                 GetOptions()->MarkInvalid();            // Flag cancel used
02546                 EndDialog = TRUE;                       // Flag to close and end
02547             break;
02548 
02549             case DIM_LISTDROPPED:
02550                 {
02551                     
02552                     HasRestoreChanged = TRUE;
02553 
02554                     if(IsManyDisplayed)
02555                     {
02556                         DeleteAllValues(_R(IDC_ANIMOPTS_REMOVAL));  
02557                         SetStringGadgetValue(_R(IDC_ANIMOPTS_REMOVAL), _R(IDS_RESTORE_NOTHING));
02558                         SetStringGadgetValue(_R(IDC_ANIMOPTS_REMOVAL), _R(IDS_RESTORE_LEAVEASIS));
02559                         SetStringGadgetValue(_R(IDC_ANIMOPTS_REMOVAL), _R(IDS_RESTORE_BACKGROUND));
02560                         SetStringGadgetValue(_R(IDC_ANIMOPTS_REMOVAL), _R(IDS_RESTORE_PREVIOUS));
02561                         SetStringGadgetValue(_R(IDC_ANIMOPTS_REMOVAL), _R(IDS_MANY));
02562                         SetSelectedValueIndex(_R(IDC_ANIMOPTS_REMOVAL), OPTION_FOUR);
02563                         SetComboListLength(_R(IDC_ANIMOPTS_REMOVAL));
02564                         IsManyDisplayed = FALSE;
02565                     }
02566                 }
02567             break;
02568 
02569             case DIM_LFT_BN_CLICKED:
02570 
02571                 // If they clicked on a "help" button then invoke the help system for this dialog.
02572                 if (Msg->GadgetID == _R(ID_CC_HELP_BUTTON))
02573                 {
02574                     UINT32 HelpID = GetFilterHelpID(GetOptions()->GetFilterType());
02575 
02576                     if (HelpID > 0)
02577                     {
02578                         // Invoke the help system and mark this message as completely processed.
02579                         HelpUserTopic(HelpID);
02580                         return DLG_EAT_IF_HUNGRY(Msg);
02581                     }
02582                 }
02583                 // A control on the dialog box has been clicked...
02584                 switch (Msg->GadgetID)
02585                 {
02586                     if (pOptions->GetFilterType() != JPEG)
02587                     {
02588                         // Uses a generic routine which checks to see if the chosen option means
02589                         // that other options become greyed or ungreyed
02590                         // case _R(IDC_BMPOPTS_32BPP): // 32 bpp case no longer exists. Why? Some spappy reason or other.
02591                         case _R(IDC_BMPOPTS_CMYK):
02592                         case _R(IDC_BMPOPTS_24BPP):
02593                         case _R(IDC_BMPOPTS_8BPP):
02594                         case _R(IDC_BMPOPTS_4BPP):
02595                         case _R(IDC_BMPOPTS_1BPP):
02596                             SetBPPButtons(Msg->GadgetID,TRUE);
02597                         break;
02598 
02599                         case _R(IDC_BMPOPTS_PAL_STD):
02600                         case _R(IDC_BMPOPTS_PAL_OPT):
02601                             SetPaletteButtons(Msg->GadgetID);
02602                         break;
02603 
02604                         case _R(IDC_BMPOPTS_NODITHER):
02605                         case _R(IDC_BMPOPTS_ORDDITHER):
02606                         case _R(IDC_BMPOPTS_DIFFUSION):
02607                             SetDitherButtons(Msg->GadgetID);
02608                         break;
02609                         case _R(IDC_ANIMOPTS_LOOP):
02610                         {
02611                             BOOL Value = GetBoolGadgetSelected(_R(IDC_ANIMOPTS_LOOP));
02612                             if (Value)
02613                             {
02614                                 SetLoopCheckBox(TRUE);
02615                                 SetBmpPrefsDlgState();
02616                             }
02617                             else
02618                             {
02619                                 SetLoopCheckBox(FALSE);
02620                                 SetBmpPrefsDlgState();
02621                             }
02622                         }
02623                         break;
02624                     }
02625                     // All other buttons should take care of themselves
02626                     // Apart from if the user changes the selection/spread/drawing buttons
02627                     // we must go and recalculate the sizes and resolution on display.  
02628                     case _R(IDC_BMPOPTS_DRAWING):
02629                     case _R(IDC_BMPOPTS_SELECT):
02630                         RecalculateSize();
02631                     break;
02632                 }
02633             break; // DIM_LFT_BN_CLICKED        
02634 
02635             case DIM_SELECTION_CHANGED:
02636                 // A control on the dialog box has been typed in...
02637                 switch (Msg->GadgetID)
02638                 {
02639                     case _R(IDC_BMPOPTS_RES):
02640                         RecalculatePixels();
02641                     break;
02642                 }
02643             break; // DIM_SELECTION_CHANGED     
02644 
02645             case DIM_TEXT_CHANGED:
02646                 // A control on the dialog box has been typed in...
02647                 switch (Msg->GadgetID)
02648                 {
02649                     case _R(IDC_BMPOPTS_RES):
02650                         RecalculatePixels();
02651                     break;
02652                     case _R(IDC_BMPOPTS_XPIXELS):
02653                         RecalculateDpiFromX();
02654                     break;
02655                     case _R(IDC_BMPOPTS_YPIXELS):
02656                         RecalculateDpiFromY();
02657                     break;
02658                     case _R(IDC_ANIMOPTS_DELAY):
02659                         HasDelayChanged = TRUE;
02660                     break;
02661                 }
02662             break; // DIM_TEXT_CHANGED      
02663 
02664         }
02665 
02666         // Allow the base class access to the message, it will do the
02667         // DLG_EAT_IF_HUNGRY(Msg) for us
02668         // Must do this before the Close and End
02669         Result = DialogOp::Message(Message);
02670 
02671         // End dialog here
02672         if (EndDialog) 
02673         {
02674             Close();                // Hide the dialog box
02675             End();                  // Finish the operation
02676         }
02677 
02678         // The message was for our dialog box so return that we have handled it, if necessary
02679         //return (DLG_EAT_IF_HUNGRY(Msg)); 
02680         return Result;
02681     }
02682 
02683     return DialogOp::Message(Message); 
02684 }
02685 
02686 /******************************************************************************************
02687 
02688 >   UINT32 BmpPrefsDlg::GetFilterHelpID(UINT32 FilterType)
02689 
02690     Author:     Will_Cowling (Xara Group Ltd) <camelotdev@xara.com>
02691     Created:    11/7/96
02692     Inputs:     -
02693     Outputs:    -
02694     Returns:    -
02695     Purpose:    Gets the Help Topic associated with the specified bitmap filter.
02696     Errors:     -
02697     SeeAlso:    -
02698 
02699 ******************************************************************************************/
02700 
02701 UINT32 BmpPrefsDlg::GetFilterHelpID(UINT32 FilterType)
02702 {
02703     UINT32 HelpID = 0;
02704 
02705     switch (FilterType)
02706     {
02707         case MAKE_BITMAP_FILTER:
02708             HelpID = _R(IDH_Command_Create_Bitmap_Copy);
02709             break;
02710 
02711         case JPEG:
02712             HelpID = _R(IDH_Dialog_Bitmap_Export_JPEG);
02713             break;
02714 
02715         case GIF:
02716         case TI_GIF:
02717             HelpID = _R(IDH_Dialog_Bitmap_Export_GIF);
02718             break;
02719 
02720         case TI_GIF_ANIM:
02721             HelpID = _R(IDH_Dialog_Bitmap_Export_Animated_GIF);
02722             break;
02723 
02724         case BMP_COMPRESSED:
02725         case BMP_UNCOMPRESSED:
02726             HelpID = _R(IDH_Dialog_Bitmap_Export_BMP);
02727             break;
02728     }
02729 
02730     return HelpID;
02731 }
02732 
02733 /******************************************************************************************
02734 
02735 >   OpState BmpPrefsDlg::GetState(String_256*, OpDescriptor*)
02736 
02737     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02738     Created:    23/08/94
02739     Inputs:     -
02740     Outputs:    -
02741     Returns:    -
02742     Purpose:    BmpPrefsDlg GetState method
02743     Errors:     -
02744     SeeAlso:    -
02745 
02746 ******************************************************************************************/
02747 
02748 OpState BmpPrefsDlg::GetState(String_256*, OpDescriptor*)
02749 {    
02750     OpState OpSt;
02751     return(OpSt);
02752 }
02753 
02754 
02755 /******************************************************************************************
02756 
02757 >   BOOL BmpPrefsDlg::Init()
02758 
02759     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02760     Created:    23/08/94
02761     Inputs:     -
02762     Outputs:    -
02763     Returns:    -
02764     Purpose:    BmpPrefsDlg Init method
02765     Errors:     -
02766     SeeAlso:    -
02767 
02768 ******************************************************************************************/
02769 
02770 BOOL BmpPrefsDlg::Init()
02771 {
02772     BOOL InitOK;
02773 
02774     InitOK = RegisterOpDescriptor(
02775                                 0,                  /* Tool ID */
02776                                 _R(IDS_BMPPREFSDLG),
02777                                 CC_RUNTIME_CLASS(BmpPrefsDlg),
02778                                 OPTOKEN_BMPPREFSDLG,
02779                                 GetState,
02780                                 0,                  /* help ID */
02781                                 0,                  /* bubble help */
02782                                 0,                  /* resource ID */
02783                                 0                   /* control ID */
02784                                 );
02785 
02786     if (InitOK)
02787     {
02788         InitOK = RegisterOpDescriptor(
02789                                 0,                  /* Tool ID */
02790                                 _R(IDS_BMPPREFSDLG),
02791                                 CC_RUNTIME_CLASS(JPEGExportPrefsDialog),
02792                                 OPTOKEN_JPGPREFSDLG,
02793                                 GetState,
02794                                 0,                  /* help ID */
02795                                 0,                  /* bubble help */
02796                                 0,                  /* resource ID */
02797                                 0                   /* control ID */
02798                                 );
02799     }
02800     return (InitOK);
02801 }
02802 
02803 
02804 
02805 /******************************************************************************************
02806 
02807 >   static BOOL BmpPrefsDlg::InvokeDialog(BitmapExportOptions* pExportOptions)
02808 
02809     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
02810     Created:    07/11/96
02811     Inputs:     pointer to some export options
02812     Returns:    True if Ok used or False if Cancel used.
02813     Purpose:    How to invoke or start a BmpPrefsDlg box.
02814 
02815 ******************************************************************************************/
02816 BOOL BmpPrefsDlg::InvokeDialog(BitmapExportOptions* pExportOptions)
02817 {
02818     ERROR2IF(pExportOptions == NULL, FALSE, "pExportOptions NULL");
02819     ERROR3IF(!pExportOptions->IS_KIND_OF(BitmapExportOptions), "pExportOptions isn't");
02820 
02821     IDD = pExportOptions->GetDialogType();
02822 
02823     OpDescriptor *OpDesc;
02824     if (IDD == _R(IDD_EXPORTJPEGOPTS))
02825         OpDesc = OpDescriptor::FindOpDescriptor(OPTOKEN_JPGPREFSDLG);
02826     else
02827         OpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(BmpPrefsDlg));
02828 
02829 
02830     if (OpDesc == NULL)
02831     {
02832         ERROR3("BmpPrefsDlg::InvokeDialog is unable to find the BmpPrefsDlg OpDescriptor");
02833         pExportOptions->MarkInvalid();
02834     }
02835     else
02836     {
02837         OpDesc->Invoke((OpParam *)pExportOptions);
02838     }
02839 
02840     return pExportOptions->IsValid();
02841 }
02842 
02843 
02844 
02845 /********************************************************************************************
02846 
02847 >   BOOL BmpPrefsDlg::Create()
02848 
02849     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02850     Created:    23/08/94
02851     Inputs:     -
02852     Outputs:    -
02853     Returns:    TRUE if successful, else FALSE
02854     Purpose:    BmpPrefsDlg create method 
02855     Errors:     -
02856     SeeAlso:    -
02857 
02858 ********************************************************************************************/
02859 
02860        
02861 BOOL BmpPrefsDlg::Create()
02862 {                            
02863     if (DialogOp::Create())
02864     { 
02865         // Set the initial control values 
02866         // Dialog now Modal so set up happens in the message handler
02867         //InitDialog(this);
02868 
02869         return TRUE; 
02870     }
02871     else
02872     {
02873         return FALSE; 
02874     }
02875 }
02876 
02877 
02878 
02879 
02880 /******************************************************************************************
02881 
02882 >   void BmpPrefsDlg::Do(OpDescriptor*)
02883 
02884     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02885     Created:    23/08/94
02886     Inputs:     -
02887     Outputs:    -
02888     Returns:    -
02889     Purpose:    Creates then opens the dialog in response to a request from the user.
02890     Errors:     -
02891     SeeAlso:    -
02892 
02893 ******************************************************************************************/
02894 
02895 void BmpPrefsDlg::Do(OpDescriptor*)
02896 {
02897     BOOL ok;
02898     
02899     // Force the dialog box to be created, as it is modal it will be opened via a message
02900     ok = Create();
02901 
02902     if ( !ok )
02903     {
02904         // Could not create the dialog box so call inform error 
02905         InformError();
02906         End();         // End the operation 
02907     }
02908 }
02909 
02910 /******************************************************************************************
02911 
02912 >   void BmpPrefsDlg::DoWithParam(OpDescriptor*)
02913 
02914     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02915     Created:    23/08/94
02916     Inputs:     -
02917     Outputs:    -
02918     Returns:    -
02919     Purpose:    Creates then opens the dialog in response to a request from the user and
02920                 allows values to be passed in and returned to the caller via the
02921                 BmpPrefsDlgParam class.
02922     Errors:     -
02923     SeeAlso:    -
02924 
02925 ******************************************************************************************/
02926 
02927 void BmpPrefsDlg::DoWithParam(OpDescriptor*, OpParam* pParam)
02928 {
02929     if (pParam == NULL)
02930     {
02931         ERROR3("BmpPrefsDlg::DoWithParam - NULL Args");
02932         return;
02933     }
02934 
02935     // Use the OpParam that has been passed in to us
02936     ERROR3IF(!pParam->IS_KIND_OF(BitmapExportOptions), "pParam isn't");
02937     m_pOptions = (BitmapExportOptions*) pParam;
02938 
02939     BOOL ok;
02940     
02941     // Force the dialog box to be created, as it is modal it will be opened via a message
02942     ok = Create();
02943 
02944     if ( !ok )
02945     {
02946         // Could not create the dialog box so call inform error 
02947         InformError();
02948         End();         // End the operation 
02949     }
02950 }
02951 
02952 
02953 /******************************************************************************************
02954 
02955 >   BOOL BmpPrefsDlg::SetUpResolutionList()
02956 
02957     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
02958     Created:    23/03/95
02959     Inputs:     -
02960     Outputs:    -
02961     Returns:    TRUE if successful, else FALSE
02962     Purpose:    Sets up the initial values in the resolution/dpi combo box. 
02963     Errors:     -
02964     SeeAlso:    -
02965 
02966 ******************************************************************************************/
02967 
02968 BOOL BmpPrefsDlg::SetUpResolutionList()
02969 {
02970     if (!m_bDpiSupported)
02971     {
02972         SetStringGadgetValue(_R(IDC_BMPOPTS_RES), &String_8(" -"), FALSE, -1);
02973         return TRUE;
02974     }
02975 
02976     // First, set up the resolution combo box
02977     // Set up the default value in the editable field
02978     SetLongGadgetValue(_R(IDC_BMPOPTS_RES), (INT32)GetOptions()->GetDPI(), FALSE, -1);
02979     // Set up the list
02980     SetLongGadgetValue(_R(IDC_BMPOPTS_RES), 50);
02981     SetLongGadgetValue(_R(IDC_BMPOPTS_RES), 75);
02982     SetLongGadgetValue(_R(IDC_BMPOPTS_RES), 96);
02983     SetLongGadgetValue(_R(IDC_BMPOPTS_RES), 100);
02984     SetLongGadgetValue(_R(IDC_BMPOPTS_RES), 150);
02985     SetLongGadgetValue(_R(IDC_BMPOPTS_RES), 200);
02986     SetLongGadgetValue(_R(IDC_BMPOPTS_RES), 250);
02987     SetLongGadgetValue(_R(IDC_BMPOPTS_RES), 300);
02988     SetComboListLength(_R(IDC_BMPOPTS_RES));
02989     
02990     return TRUE;
02991 }   
02992 
02993 /******************************************************************************************
02994 
02995 >   BOOL BmpPrefsDlg::SetBmpPrefsDlgState()
02996 
02997     Author:     Ranbir_Rana (Xara Group Ltd) <camelotdev@xara.com> 
02998     Created:    21/01/97
02999     Inputs:     -
03000     Outputs:    -
03001     Returns:    TRUE if successful, else FALSE.
03002     Purpose:    This will be called When the "loop continuously" switch is turned off.
03003                 It will grey/ungrey the "Loop" ed field. 
03004     Errors:     
03005     SeeAlso:    -
03006 
03007 ******************************************************************************************/
03008 BOOL BmpPrefsDlg::SetBmpPrefsDlgState()
03009 {
03010     BitmapExportOptions* pOptions = GetOptions();
03011     ERROR2IF(pOptions == NULL, FALSE, "pOptions is NULL");
03012     
03013     // The "loop continuously" switch is on.
03014     if (GetLoopCheckBox())
03015     {
03016         // Grey the Loop ed field.
03017         EnableGadget(_R(IDC_ANIMOPTS_ITERATIONS), FALSE);
03018     }
03019 
03020     // The "loop continuously" switch is off. 
03021     if (!GetLoopCheckBox())
03022     {
03023         GIFExportOptions* pGIFOptions = (GIFExportOptions*)pOptions;
03024         ERROR3IF(!pGIFOptions->IS_KIND_OF(GIFExportOptions), "pGIFOptions isn't");
03025 
03026         // Ungrey the Loop ed field.    
03027         EnableGadget(_R(IDC_ANIMOPTS_ITERATIONS), TRUE);
03028         SetLongGadgetValue(_R(IDC_ANIMOPTS_ITERATIONS), pGIFOptions->GetAnimationLoopCount());
03029     }
03030     return TRUE;
03031 }
03032 
03033 /******************************************************************************************
03034 
03035 >   BOOL BmpPrefsDlg::InitDialog()
03036 
03037     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from Neville)
03038     Created:    23/08/94
03039     Inputs:     pointer to the dialog box
03040     Returns:    TRUE if successful, else FALSE
03041     Purpose:    Sets initial dialog values 
03042 
03043 ******************************************************************************************/
03044 BOOL BmpPrefsDlg::InitDialog()
03045 {
03046     BitmapExportOptions* pOptions = GetOptions();
03047     ERROR2IF(pOptions == NULL, FALSE, "pOptions NULL");
03048 
03049     if (pOptions->GetFilterType() != MAKE_BITMAP_FILTER)
03050     {
03051         // Set up the title of the dialog box according to the passed in string which
03052         // is the name of the filter plus export bitmap options.
03053         String_256 Temp = *(pOptions->GetFilterName());
03054         Temp += String_256(_R(IDN_EXPORTBMPOPTS));
03055 
03056         SetTitlebarName(&Temp); 
03057     }
03058 
03059     // Default to a locked aspect ratio
03060     m_bLockAspect = TRUE;
03061 
03062     // Now set up the bits per pixel radio buttons
03063     // The various filters require different controls, most just require bits disabling
03064     // such as the bpp switches available
03065     UINT32 Depth = pOptions->GetDepth();
03066     BOOL bYoDither  = FALSE;
03067     PALETTE Palette;    // maybe want this pileo'sh'
03068     DITHER Dither;  // maybe want this pileo'sh'
03069 
03070     // WEBSTER - markn 23/1/97
03071     // Hide these in Webster
03072 #ifdef WEBSTER
03073     HideGadget(_R(IDC_BMPOPTS_TIFF), TRUE);     // Hide the TIFF compression selection 
03074     HideGadget(_R(IDC_BMPOPTS_RLE), TRUE);      // Hide the BMP rgb compression
03075     HideGadget(_R(IDC_BMPOPTS_RGB), TRUE);      // Hide the BMP rle compression
03076     HideGadget(_R(IDC_BMPOPTS_COMPRESS), TRUE); // Hide the compression group
03077 #endif // WEBSTER
03078 
03079     // WEBSTER - markn 17/1/97
03080     // Display the 'number of colours in palette' group and extend the dlg if necessary
03081     // but only for export options of the correct type
03082     InitNumColoursGroup(pOptions);
03083 
03084     // oh ye virtuals
03085     switch ( pOptions->GetFilterType() ) 
03086     {
03087         case TIFF_UNCOMPRESSED:
03088         {
03089             //WEBSTER-Martin-03/01/97
03090 #ifndef WEBSTER
03091             BOOL ok;
03092             TIFFExportOptions* pTIFFOptions = (TIFFExportOptions*)pOptions;
03093             ERROR3IF(!pTIFFOptions->IS_KIND_OF(TIFFExportOptions), "pTIFFOptions isn't");
03094 
03095             // Make sure we show the correct compression selection field
03096             HideGadget(_R(IDC_BMPOPTS_TIFF), FALSE);    // Show the TIFF compression selection 
03097             HideGadget(_R(IDC_BMPOPTS_RLE), TRUE);      // Hide the BMP rgb compression
03098             HideGadget(_R(IDC_BMPOPTS_RGB), TRUE);      // Hide the BMP rle compression
03099             HideGadget(_R(IDC_BMPOPTS_COMPRESS), FALSE);// Show the compression group
03100 
03101             // Check for illegal case of the the depth for this filter type
03102 //          if (Depth == 32)
03103 //              Depth = 24;
03104 
03105             HideGadget(_R(IDC_BMPOPTS_32BPP), TRUE);
03106 
03107             // Convert the Accusoft ID's into their equivalent list item numbers
03108             // If 1bpp then omit the 1bpp compression types to 1bpp images only.
03109             INT32 TiffCompression = pTIFFOptions->GetCompression();
03110 
03111             // Set up the TIFF compression types list
03112             // Now the resolution combo box and hence the default value in the editable field
03113             ok = SetLongGadgetValue(_R(IDC_BMPOPTS_TIFF), pTIFFOptions->GetCompression(), FALSE, -1);
03114             // Set up the list of available TIFF compressions. Must be the same as the list
03115             // in TiffTypes.
03116             // Assusoft seem to imply they support lots of save options but in fact they do not!
03117             SetStringGadgetValue(_R(IDC_BMPOPTS_TIFF), &String_32(_R(IDN_TIFF_NONE)));
03118             
03119             if( Depth==8 || Depth==24 || Depth==32 )
03120             {
03121                 SetStringGadgetValue(_R(IDC_BMPOPTS_TIFF), &String_32(_R(IDN_TIFF_LZW)));
03122             }
03123 
03124             // Only allow the next options if 1bpp is selected as otherwise not appropriate
03125             if (Depth == 1)
03126             {
03127                 // 1bpp export so enable these 1bpp compression types
03128                 SetStringGadgetValue(_R(IDC_BMPOPTS_TIFF), &String_32(_R(IDN_TIFF_HUFFMAN)));
03129                 SetStringGadgetValue(_R(IDC_BMPOPTS_TIFF), &String_32(_R(IDN_TIFF_G3FAX)));
03130                 SetStringGadgetValue(_R(IDC_BMPOPTS_TIFF), &String_32(_R(IDN_TIFF_G4FAX)));
03131                 SetStringGadgetValue(_R(IDC_BMPOPTS_TIFF), &String_32(_R(IDN_TIFF_PACKBITS)));
03132             }
03133             else
03134             {
03135                 // Anything but 1bpp export.
03136                 // Must ensure that only a valid compression type is allowed
03137                 //if (TiffCompression != UNCOMPRESSED_TIFF && TiffCompression != LZW_TIFF)
03138                 //  TiffCompression = LZW_TIFF;
03139             }
03140             SetComboListLength(_R(IDC_BMPOPTS_TIFF));
03141 
03142             ok = SetTIFFCompressionSelection( TiffCompression, Depth );
03143 
03144             // if the previously selected compression is now disabled, select NONE
03145             if( ! ok )
03146             {
03147                 ok = SetTIFFCompressionSelection( TIFF_UNCOMPRESSED, Depth );
03148                 
03149                 // We should ALWAYS be able to select UNCOMPRESSED
03150                 ERROR3IF( (!ok), "BmpPrefsDlg::InitDialog - could not select uncompressed" );
03151             }
03152 
03153             Palette = pTIFFOptions->GetPalette();
03154             Dither = pTIFFOptions->GetDither();
03155             bYoDither = TRUE;
03156 
03157             m_bDpiSupported = TRUE;
03158 #endif //WEBSTER
03159             break;
03160         }
03161         case PNG:
03162         {
03163             PNGExportOptions* pPNGOptions = (PNGExportOptions*)pOptions;
03164             ERROR3IF(!pPNGOptions->IS_KIND_OF(PNGExportOptions), "pPNGOptions isn't");
03165             // 1, 4, 8, 24 and 32 bpp
03166 
03167             // WEBSTER - markn 23/1/97
03168             // Compression group always hidden in Webster
03169             #ifndef WEBSTER
03170             HideGadget(_R(IDC_BMPOPTS_TIFF), TRUE);     // Hide the TIFF compression selection 
03171             HideGadget(_R(IDC_BMPOPTS_RLE), TRUE);      // Hide the BMP rgb compression
03172             HideGadget(_R(IDC_BMPOPTS_RGB), TRUE);      // Hide the BMP rle compression
03173             HideGadget(_R(IDC_BMPOPTS_COMPRESS), TRUE); // Hide the compression group
03174             #endif // WEBSTER
03175 
03176             HideGadget(_R(IDC_BMPOPTS_CMYK), TRUE);
03177             EnableGadget(_R(IDC_BMPOPTS_32BPP), FALSE);
03178 
03179             // We will use the special PNG radio buttons for interlaced and transparent.
03180             // These are hidden by default.
03181             // Now set up the list
03182             // Must correspond to the order PNG .. PNG_TRANSINTER defined in accuflts.h
03183             // Translate the compression type into the transparency and interlace states.
03184             BOOL Transparent = pPNGOptions->WantTransparent();
03185             BOOL Interlace   = pPNGOptions->WantInterlaced();
03186             // If we are at the deeper colour depths then transparency is not allowed
03187             if (Depth == 24 || Depth == 32)
03188                 Transparent = FALSE;
03189             HideGadget(_R(IDC_BMPOPTS_GIFTYPE), FALSE);
03190             HideGadget(_R(IDC_BMPOPTS_TRANSPARENT), FALSE);
03191             HideGadget(_R(IDC_BMPOPTS_INTERLACED), FALSE);
03192             EnableGadget(_R(IDC_BMPOPTS_GIFTYPE), TRUE);
03193             EnableGadget(_R(IDC_BMPOPTS_INTERLACED), TRUE);
03194             SetLongGadgetValue(_R(IDC_BMPOPTS_TRANSPARENT), Transparent);
03195             SetLongGadgetValue(_R(IDC_BMPOPTS_INTERLACED), Interlace);
03196 
03197 //          Palette = pPNGOptions->GetPalette();
03198             Dither = pPNGOptions->GetDither();
03199             bYoDither = TRUE;
03200 
03201             m_bDpiSupported = TRUE;
03202             break;
03203         }
03204         case GIF:
03205         case TI_GIF:
03206         case TI_GIF_ANIM:
03207         {
03208             GIFExportOptions* pGIFOptions = (GIFExportOptions*)pOptions;
03209             ERROR3IF(!pGIFOptions->IS_KIND_OF(GIFExportOptions), "pGIFOptions isn't");
03210 
03211             // 4 8 bpp only
03212             // WEBSTER - markn 23/1/97
03213             // Compression group always hidden in Webster
03214             #ifndef WEBSTER
03215             HideGadget(_R(IDC_BMPOPTS_TIFF), TRUE);     // Hide the TIFF compression selection 
03216             HideGadget(_R(IDC_BMPOPTS_RLE), TRUE);      // Hide the BMP rle compression
03217             HideGadget(_R(IDC_BMPOPTS_RGB), TRUE);      // Hide the BMP rgb compression
03218             HideGadget(_R(IDC_BMPOPTS_COMPRESS), TRUE); // Hide the compression group
03219             #endif // WEBSTER
03220 
03221             m_bDpiSupported = FALSE;
03222 
03223             // Check for illegal case of the the depth for this filter type
03224             if (Depth == 32 || Depth == 24)
03225                 Depth = 8;
03226             // Disable all illegal bpp buttons
03227             HideGadget(_R(IDC_BMPOPTS_CMYK), TRUE);
03228             EnableGadget(_R(IDC_BMPOPTS_32BPP), FALSE);
03229             EnableGadget(_R(IDC_BMPOPTS_24BPP), FALSE);
03230 
03231             // We will use the special GIF radio buttons for interlaced and transparent.
03232             // These are hidden by default.
03233             // But only if our special GIF filter.
03234             if (pOptions->GetFilterType() == TI_GIF ||
03235                 pOptions->GetFilterType() == TI_GIF_ANIM)
03236             {
03237                 // Now set up the list
03238                 // Must correspond to the order TI_GIF .. TI_GIF_TRANSINTER defined in accuflts.h
03239                 // Translate the compression type into the transparency and interlace states.
03240 
03241                 BOOL Transparent = pGIFOptions->WantTransparent();
03242                 BOOL Interlace   = pGIFOptions->WantInterlaced();
03243                 HideGadget(_R(IDC_BMPOPTS_GIFTYPE), FALSE);
03244                 HideGadget(_R(IDC_BMPOPTS_TRANSPARENT), FALSE);
03245                 HideGadget(_R(IDC_BMPOPTS_INTERLACED), FALSE);
03246                 EnableGadget(_R(IDC_BMPOPTS_GIFTYPE), TRUE);
03247                 EnableGadget(_R(IDC_BMPOPTS_INTERLACED), TRUE);
03248                 EnableGadget(_R(IDC_BMPOPTS_TRANSPARENT), TRUE);
03249 
03250                 SetLongGadgetValue(_R(IDC_BMPOPTS_TRANSPARENT), Transparent);
03251                 SetLongGadgetValue(_R(IDC_BMPOPTS_INTERLACED), Interlace);
03252             }
03253             if (pOptions->GetFilterType() == TI_GIF_ANIM)
03254             {
03255                 HideGadget(_R(IDC_ANIMOPTS_ANIMGROUP) , FALSE);     // Un-hide the Animation Group
03256                 HideGadget(_R(IDC_ANIMOPTS_REMOVAL)   , FALSE);
03257                 HideGadget(_R(IDC_ANIMOPTS_DELAYFOR)  , FALSE);
03258                 HideGadget(_R(IDC_ANIMOPTS_CS)        , FALSE);
03259                 HideGadget(_R(IDC_ANIMOPTS_LOOPTEXT)  , FALSE);
03260                 HideGadget(_R(IDC_ANIMOPTS_DELAY)     , FALSE);
03261                 HideGadget(_R(IDC_ANIMOPTS_ITERATIONS), FALSE);
03262                 HideGadget(_R(IDC_ANIMOPTS_TIMES)     , FALSE);
03263                 HideGadget(_R(IDC_ANIMOPTS_LOOP)      , FALSE);
03264                 HideGadget(_R(IDC_ANIMOPTS_RESTORE)   , FALSE);
03265 
03266                 // Unlock the aspect ratio
03267                 m_bLockAspect = FALSE;
03268 
03269                 // ************************************************
03270                 // This is Oily code.  Should be replaced with Dialogue Manager function call
03271                 // Extend the dialogue height, so we can see the animation options
03272 
03273                 WINDOWPLACEMENT Place;
03274                 Place.length = sizeof(WINDOWPLACEMENT);
03275                 if (GetWindowPlacement((HWND)WindowID, &Place))
03276                 {
03277                     Place.rcNormalPosition.bottom = Place.rcNormalPosition.bottom + (ANIMATION_EXTRABIT);
03278                     SetWindowPlacement((HWND)WindowID, &Place);
03279                 }
03280 
03281                 // Added for Webster RanbirR 11\02\97
03282                 BmpDlgParam* pBmpDlgParam = pOptions->GetBmpDlgParam();
03283                 if (pBmpDlgParam == NULL)
03284                     return FALSE;
03285 
03286                 // Go through our list of bitmaps, to find if any are Transparent.
03287 
03288                 // Get a list of our selected bitmaps.
03289                 UINT32 ListSize =  pBmpDlgParam->GetListSize();
03290                 KernelBitmap** pList = pBmpDlgParam->GetBitmapList();
03291                 BOOL Transparent = FALSE;
03292                 INT32 Index=0;
03293 
03294                 // Added for Webster - RanbirR 11\02\97
03295                 // Are any of our bitmaps Transparent ?
03296                 while (ListSize > 0)
03297                 {
03298                     KernelBitmap* pKernelBitmap = pList[--ListSize];
03299 
03300                     if (pKernelBitmap != NULL)
03301                     {
03302                         // Is this bitmap Transparent.
03303                         if(pKernelBitmap->GetTransparencyIndex(&Index))
03304                             Transparent = TRUE;
03305                     }
03306                 }
03307 
03308                 HideGadget(_R(IDC_BMPOPTS_TRANSPARENT), FALSE);
03309                 EnableGadget(_R(IDC_BMPOPTS_TRANSPARENT), TRUE);
03310                 SetLongGadgetValue(_R(IDC_BMPOPTS_TRANSPARENT), Transparent);
03311 
03312                 if (pBmpDlgParam->GetAreDelayValuesSame())
03313                 {
03314                     SetLongGadgetValue(_R(IDC_ANIMOPTS_DELAY), pBmpDlgParam->GetAnimDelay());   
03315                     IsDelayMany=FALSE;
03316                 }
03317                 else
03318                 {
03319                     SetStringGadgetValue(_R(IDC_ANIMOPTS_DELAY), _R(IDS_MANY)); 
03320                     IsDelayMany=TRUE;
03321                 }
03322                 
03323                 if (pBmpDlgParam->GetSameRestoreType())
03324                 {
03325                     SetStringGadgetValue(_R(IDC_ANIMOPTS_REMOVAL), &String_32(_R(IDS_RESTORE_NOTHING)));
03326                     SetStringGadgetValue(_R(IDC_ANIMOPTS_REMOVAL), &String_32(_R(IDS_RESTORE_LEAVEASIS)));
03327                     SetStringGadgetValue(_R(IDC_ANIMOPTS_REMOVAL), &String_32(_R(IDS_RESTORE_BACKGROUND)));
03328                     SetStringGadgetValue(_R(IDC_ANIMOPTS_REMOVAL), &String_32(_R(IDS_RESTORE_PREVIOUS)));
03329                     SetComboListLength(_R(IDC_ANIMOPTS_REMOVAL));
03330                     SetSelectedValueIndex(_R(IDC_ANIMOPTS_REMOVAL), pBmpDlgParam->GetRestoreType());
03331                 }
03332                 else
03333                 {
03334                     SetStringGadgetValue (_R(IDC_ANIMOPTS_REMOVAL), _R(IDS_MANY));
03335                     SetSelectedValueIndex(_R(IDC_ANIMOPTS_REMOVAL), OPTION_ONE);
03336                     IsManyDisplayed = TRUE;
03337                 }
03338         
03339                 SetLongGadgetValue(_R(IDC_ANIMOPTS_ITERATIONS), pGIFOptions->GetAnimationLoopCount());
03340                 EnableGadget(_R(IDC_ANIMOPTS_ITERATIONS), FALSE);
03341                 SetBoolGadgetSelected(_R(IDC_ANIMOPTS_LOOP), TRUE);
03342 
03343             }
03344 
03345 //          Palette = pGIFOptions->GetPalette();
03346             Dither = pGIFOptions->GetDither();
03347             bYoDither = TRUE;
03348 
03349             break;
03350         }
03351         case MAKE_BITMAP_FILTER:
03352         {
03353             MakeBitmapExportOptions* pMkBOptions = (MakeBitmapExportOptions*)pOptions;
03354             ERROR3IF(!pMkBOptions->IS_KIND_OF(MakeBitmapExportOptions), "pMkBOptions isn't");
03355             // 1 4 8 24 bpp
03356             HideGadget(_R(IDC_BMPOPTS_CMYK), TRUE);
03357             EnableGadget(_R(IDC_BMPOPTS_32BPP), FALSE);
03358             HideGadget(_R(IDC_BMPOPTS_CREATEOPTS), FALSE);
03359             HideGadget(_R(IDC_BMPOPTS_GIFTYPE), TRUE);
03360             // WEBSTER - markn 23/1/97
03361             // Compression group always hidden in Webster
03362             #ifndef WEBSTER
03363             HideGadget(_R(IDC_BMPOPTS_TIFF), TRUE);     // Hide the TIFF compression selection 
03364             HideGadget(_R(IDC_BMPOPTS_RLE), TRUE);      // Hide the BMP rle compression
03365             HideGadget(_R(IDC_BMPOPTS_RGB), TRUE);      // Hide the BMP rgb compression
03366             HideGadget(_R(IDC_BMPOPTS_COMPRESS), TRUE); // Hide the compression group
03367             #endif // WEBSTER
03368             
03369             HideGadget(_R(IDC_ANIMOPTS_LOOP), TRUE);    
03370             HideGadget(_R(IDC_ANIMOPTS_DELAY), TRUE);   
03371             HideGadget(_R(IDC_ANIMOPTS_ITERATIONS), TRUE);
03372             HideGadget(_R(IDC_ANIMOPTS_REMOVAL), TRUE); 
03373 
03374             HideGadget(_R(IDC_TIMES_STATIC),TRUE);  
03375             HideGadget(_R(IDC_RESTORE_STATIC),TRUE);
03376 
03377             m_bDpiSupported = TRUE;
03378 
03379             // We will use the special GIF radio buttons for interlaced and transparent.
03380             // These are hidden by default.
03381 
03382             String_256 Temp(_R(IDS_MAKEBMPOPTS));
03383             SetTitlebarName(&Temp); 
03384 
03385             SetStringGadgetValue(IDOK, &String_32(_R(IDS_CREATEBMP)));
03386             SetStringGadgetValue(_R(IDC_BMPOPTS_SAVEAREA), &String_32(_R(IDS_CREATEFROM)));
03387 
03388             // Now set up the list
03389             // Must correspond to the order TI_GIF .. TI_GIF_TRANSINTER defined in outptgif.h
03390             // Translate the compression type into the transparency and interlace states.
03391             BOOL Transparent = pMkBOptions->WantTransparent();
03392             BOOL Interlace   = FALSE;
03393             HideGadget(_R(IDC_BMPOPTS_TRANSPARENT), FALSE);
03394             HideGadget(_R(IDC_BMPOPTS_INTERLACED), TRUE);
03395             EnableGadget(_R(IDC_BMPOPTS_INTERLACED), FALSE);
03396             EnableGadget(_R(IDC_BMPOPTS_TRANSPARENT), TRUE);
03397 
03398             SetLongGadgetValue(_R(IDC_BMPOPTS_TRANSPARENT), Transparent);
03399 
03400 //          Palette = pMkBOptions->GetPalette();
03401             Dither = pMkBOptions->GetDither();
03402             bYoDither = TRUE;
03403             break;
03404         }
03405         case WPG:
03406             // 1 4 8 bpp only
03407             // WEBSTER - markn 23/1/97
03408             // Compression group always hidden in Webster
03409             #ifndef WEBSTER
03410             HideGadget(_R(IDC_BMPOPTS_TIFF), TRUE);     // Hide the TIFF compression selection 
03411             HideGadget(_R(IDC_BMPOPTS_RLE), TRUE);      // Hide the BMP rgb compression
03412             HideGadget(_R(IDC_BMPOPTS_RGB), TRUE);      // Hide the BMP rle compression
03413             HideGadget(_R(IDC_BMPOPTS_COMPRESS), TRUE); // Hide the compression group
03414             #endif // WEBSTER
03415 
03416             // Check for illegal case of the the depth for this filter type
03417             if (Depth == 32 || Depth == 24)
03418                 Depth = 8;
03419             m_bDpiSupported = FALSE;
03420             // Disable all illegal bpp buttons
03421             HideGadget(_R(IDC_BMPOPTS_CMYK), TRUE);
03422             EnableGadget(_R(IDC_BMPOPTS_32BPP), FALSE);
03423             EnableGadget(_R(IDC_BMPOPTS_24BPP), FALSE);
03424 
03425             //WEBSTER-Martin-06/01/97
03426             #ifndef WEBSTER
03427             Palette = ((AccusoftExportOptions*)pOptions)->GetPalette();
03428             Dither = ((AccusoftExportOptions*)pOptions)->GetDither();
03429             #endif //WEBSTER
03430             bYoDither = TRUE;
03431 
03432             break;
03433         case PHOTOCD:
03434             // 24 bpp only
03435             // WEBSTER - markn 23/1/97
03436             // Compression group always hidden in Webster
03437             #ifndef WEBSTER
03438             HideGadget(_R(IDC_BMPOPTS_TIFF), TRUE);     // Hide the TIFF compression selection 
03439             HideGadget(_R(IDC_BMPOPTS_RLE), TRUE);      // Hide BMP rgb compression
03440             HideGadget(_R(IDC_BMPOPTS_RGB), TRUE);      // Hide BMP rle compression
03441             HideGadget(_R(IDC_BMPOPTS_COMPRESS), TRUE); // Hide compression group
03442             #endif // WEBSTER
03443 
03444             // Check for illegal case of the the depth for this filter type
03445             if (Depth != 24)
03446                 Depth = 24;
03447             // Disable all illegal bpp buttons
03448             HideGadget(_R(IDC_BMPOPTS_CMYK), TRUE);
03449             EnableGadget(_R(IDC_BMPOPTS_8BPP), FALSE);
03450             EnableGadget(_R(IDC_BMPOPTS_4BPP), FALSE);
03451             EnableGadget(_R(IDC_BMPOPTS_1BPP), FALSE);
03452             m_bDpiSupported = TRUE;
03453             break;
03454         case IFF_ILBM:
03455         case XWD:
03456         case DCX:
03457         case PCX:
03458         case PICT:
03459             // 1 4 8 24 bpp
03460             // WEBSTER - markn 23/1/97
03461             // Compression group always hidden in Webster
03462             #ifndef WEBSTER
03463             HideGadget(_R(IDC_BMPOPTS_TIFF), TRUE);     // Hide the TIFF compression selection 
03464             HideGadget(_R(IDC_BMPOPTS_RLE), TRUE);      // Hide BMP rgb compression
03465             HideGadget(_R(IDC_BMPOPTS_RGB), TRUE);      // Hide BMP rle compression
03466             HideGadget(_R(IDC_BMPOPTS_COMPRESS), TRUE); // Hide compression group
03467             #endif // WEBSTER
03468 
03469             // Check for illegal case of the the depth for this filter type
03470             if (Depth == 32)
03471                 Depth = 24;
03472             // Disable all illegal bpp buttons
03473             HideGadget(_R(IDC_BMPOPTS_CMYK), TRUE);
03474             EnableGadget(_R(IDC_BMPOPTS_32BPP), FALSE);
03475             m_bDpiSupported = FALSE;
03476 
03477             //WEBSTER-Martin-06/01/97
03478             #ifndef WEBSTER
03479             Palette = ((AccusoftExportOptions*)pOptions)->GetPalette();
03480             Dither = ((AccusoftExportOptions*)pOptions)->GetDither();
03481             #endif // WEBSTER
03482             bYoDither = TRUE;
03483             break;
03484 
03485         case RAST:
03486         case PHOTOSHOP:
03487             // 1 8 24 bpp
03488             // WEBSTER - markn 23/1/97
03489             // Compression group always hidden in Webster
03490             #ifndef WEBSTER
03491             HideGadget(_R(IDC_BMPOPTS_TIFF), TRUE);     // Hide the TIFF compression selection 
03492             HideGadget(_R(IDC_BMPOPTS_RLE), TRUE);      // Hide BMP rgb compression
03493             HideGadget(_R(IDC_BMPOPTS_RGB), TRUE);      // Hide BMP rle compression
03494             HideGadget(_R(IDC_BMPOPTS_COMPRESS), TRUE); // Hide compression group
03495             #endif // WEBSTER
03496 
03497             // Check for illegal case of the the depth for this filter type
03498             if (Depth == 32 || Depth == 4)
03499                 Depth = 24;
03500             // Disable all illegal bpp buttons
03501             HideGadget(_R(IDC_BMPOPTS_CMYK), TRUE);
03502             EnableGadget(_R(IDC_BMPOPTS_32BPP), FALSE);
03503             EnableGadget(_R(IDC_BMPOPTS_4BPP), FALSE);
03504             m_bDpiSupported = FALSE;
03505 
03506             //WEBSTER-Martin-06/01/97
03507             #ifndef WEBSTER
03508             Palette = ((AccusoftExportOptions*)pOptions)->GetPalette();
03509             Dither = ((AccusoftExportOptions*)pOptions)->GetDither();
03510             #endif // WEBSTER
03511             bYoDither = TRUE;
03512 
03513             break;
03514         case TARGA:
03515             // 8 24 bpp
03516             // WEBSTER - markn 23/1/97
03517             // Compression group always hidden in Webster
03518             #ifndef WEBSTER
03519             HideGadget(_R(IDC_BMPOPTS_TIFF), TRUE);     // Hide the TIFF compression selection 
03520             HideGadget(_R(IDC_BMPOPTS_RLE), TRUE);      // Hide BMP rgb compression
03521             HideGadget(_R(IDC_BMPOPTS_RGB), TRUE);      // Hide BMP rle compression
03522             HideGadget(_R(IDC_BMPOPTS_COMPRESS), TRUE); // Hide compression group
03523             #endif // WEBSTER
03524 
03525             // Check for illegal case of the the depth for this filter type
03526             if (Depth == 32  || Depth == 4 || Depth == 1)
03527                 Depth = 24;
03528             // Disable all illegal bpp buttons
03529             HideGadget(_R(IDC_BMPOPTS_CMYK), TRUE);
03530             EnableGadget(_R(IDC_BMPOPTS_32BPP), FALSE);
03531             EnableGadget(_R(IDC_BMPOPTS_4BPP), FALSE);
03532             EnableGadget(_R(IDC_BMPOPTS_1BPP), FALSE);
03533             m_bDpiSupported = FALSE;
03534 
03535             //WEBSTER-Martin-06/01/97
03536             #ifndef WEBSTER
03537             Palette = ((AccusoftExportOptions*)pOptions)->GetPalette();
03538             Dither = ((AccusoftExportOptions*)pOptions)->GetDither();
03539             #endif // WEBSTER
03540             bYoDither = TRUE;
03541             break;
03542 
03543         case MACPAINT:
03544         case MSP:
03545             // 1bpp only
03546             return FALSE;
03547             break;
03548         case BMP_UNCOMPRESSED:
03549         {
03550             BMPExportOptions* pBMPOptions = (BMPExportOptions*)pOptions;
03551             ERROR3IF(!pBMPOptions->IS_KIND_OF(BMPExportOptions), "pBMPOptions isn't");
03552 
03553             // WEBSTER - markn 23/1/97
03554             // Compression group always hidden in Webster
03555             #ifndef WEBSTER
03556             HideGadget(_R(IDC_BMPOPTS_TIFF), TRUE);     // Hide the TIFF compression selection 
03557             HideGadget(_R(IDC_BMPOPTS_RLE), FALSE);     // Show the BMP rgb compression
03558             HideGadget(_R(IDC_BMPOPTS_RGB), FALSE);     // Show the BMP rle compression
03559             HideGadget(_R(IDC_BMPOPTS_COMPRESS), FALSE);// Show the compression group
03560 
03561             // Now set up the other buttons according to the values set in the variables
03562             if (pBMPOptions->GetCompression())
03563                 SetLongGadgetValue(_R(IDC_BMPOPTS_RLE), TRUE);
03564             else
03565                 SetLongGadgetValue(_R(IDC_BMPOPTS_RGB), TRUE);
03566             #endif // WEBSTER
03567 
03568             // Check for illegal case of the the depth for this filter type
03569             if ( Depth == 16 )
03570                 Depth = 24;
03571             EnableGadget(_R(IDC_BMPOPTS_32BPP), FALSE);
03572             HideGadget(_R(IDC_BMPOPTS_CMYK), FALSE);
03573             Palette = pBMPOptions->GetPalette();
03574             Dither = pBMPOptions->GetDither();
03575             bYoDither = TRUE;
03576 
03577             m_bDpiSupported = TRUE;
03578             break;
03579         }
03580         default:
03581             return FALSE;
03582     }
03583 
03584     // Override the Export button if being invoked from the Name gallery.
03585     if (NamedExportProp::m_fApplyNotExport)
03586         SetStringGadgetValue(IDOK, &String(_R(IDS_PREVIEW_APPLY)));
03587 
03588     // If the default depth's not supported give a sensible one
03589     if (Depth != pOptions->GetDepth())
03590     {
03591         pOptions->SetDepth(Depth);
03592     }
03593 
03594     if (!m_bDpiSupported)                           // Doesn't support dpi...
03595     {
03596         // and ensure that its always the number of dpi as defined by a pixel unit
03597         DocUnitList* pDocUnitList = DocUnitList::GetCurrentDocUnitList();
03598         ERROR3IF(pDocUnitList == NULL, "BmpPrefsDlg::InitDialog() - no pDocUnitList!")
03599         Unit* pPixelUnit = pDocUnitList->FindUnit(PIXELS);
03600         ERROR3IF(pPixelUnit == NULL, "BmpPrefsDlg::InitDialog() - no pixel units!")
03601         Unit* pInchUnit = pDocUnitList->FindUnit(INCHES);
03602         ERROR3IF(pInchUnit == NULL, "BmpPrefsDlg::InitDialog() - no inch units!")
03603         double newDpi = (pPixelUnit->GetMillipoints()>0) ? pInchUnit->GetMillipoints() / pPixelUnit->GetMillipoints() : 96.0;
03604         Dpi = (INT32)newDpi;
03605         pOptions->SetDPI(newDpi);
03606 
03607         // Now, set up the resolution combo box
03608         SetUpResolutionList();
03609 
03610         // so disallow changes to dpi field
03611         EnableGadget(_R(IDC_BMPOPTS_RES), FALSE);
03612         EnableGadget(_R(IDC_BMPOPTS_DPI), FALSE);
03613     }
03614     else
03615     {
03616         // Now, set up the resolution combo box
03617         SetUpResolutionList();
03618     }
03619 
03620     // blooooody classes!!!! foookin virtuals!!!
03621     InitDepthRadioGroup();
03622     InitSelectionRadioGroup();
03623     if (bYoDither)
03624     {
03625         InitPaletteRadioGroup(Palette);
03626         InitDitherRadioGroup(Dither);       // GetDitherGadget()->Init()???
03627     }
03628 
03629     // Make sure that size fields are displaying the values correctly
03630     RecalculateSize();
03631 
03632     if (m_bDpiSupported)
03633     {
03634         // Start off with input focus in the dpi field
03635         SetKeyboardFocus(_R(IDC_BMPOPTS_RES));
03636     }
03637     else
03638     {
03639         // Start off with input focus in the x pixel size
03640         SetKeyboardFocus(_R(IDC_BMPOPTS_XPIXELS));
03641     }
03642 
03643     return TRUE;
03644 }
03645 
03646 /******************************************************************************************
03647 
03648 >   void BmpPrefsDlg::InitNumColoursGroup(BitmapExportOptions* pOptions)
03649 
03650     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
03651     Created:    17/1/97
03652     Inputs:     pOptions = The options for this bitmap export
03653     Returns:    -
03654     Purpose:    Inits the "number of colour in palette" group in the bitmap export dlg
03655 
03656                 NOTE: If the options don't allow a specific number of colours to be show,
03657                 then this function will hide them instead
03658 
03659                 Introduced in WEBSTER
03660 
03661 ******************************************************************************************/
03662 
03663 void BmpPrefsDlg::InitNumColoursGroup(BitmapExportOptions* pOptions)
03664 {
03665     if (pOptions == NULL)
03666         return;
03667 
03668     // Don't show these options if we can't support a specific number of colours
03669     if (!pOptions->UseSpecificNumColsInPalette())
03670     {
03671         HideNumColoursGroup();
03672         return;
03673     }
03674 
03675     INT32 Gadgets[] = { _R(IDC_BMPOPTS_NUMCOLS_GROUP),
03676                         _R(IDC_BMPOPTS_NUMCOLS_EDIT),
03677                         _R(IDC_BMPOPTS_NUMCOLS_SYSCOLS),
03678                         _R(IDC_BMPOPTS_NUMCOLS_EDITTEXT),
03679                         0};
03680 
03681     // ************************************************
03682     // This is Oily code.  Should be replaced with Dialogue Manager function call
03683     // It moves the numcols gadgets into the correct place on the dialog and
03684     // extends the dialog so you can see them.  Lovely!
03685 
03686     {
03687         INT32 Index = 0;
03688         for (Index = 0;Gadgets[Index] != 0;Index++)
03689         {
03690             HWND hGadget = GetDlgItem((HWND)WindowID, (INT32)Gadgets[Index]);
03691             RECT MoveRect;
03692             POINT TopLeft;
03693 
03694             if (GetWindowRect(hGadget, &MoveRect))
03695             {
03696                 TopLeft.x = MoveRect.left;      // Convert TopLeft coord into client coords
03697                 TopLeft.y = MoveRect.top;
03698                 ScreenToClient((HWND)WindowID, &TopLeft);
03699                 TopLeft.y -= NUMCOLS_GROUP_SHIFT;
03700 
03701                 SetWindowPos(hGadget, NULL,
03702                                 TopLeft.x, TopLeft.y, 0, 0,
03703                                 SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER);
03704             }
03705         }
03706 
03707         for (Index = 0;Gadgets[Index] != 0;Index++)
03708             HideGadget(Gadgets[Index],FALSE);
03709 
03710         WINDOWPLACEMENT Place;
03711         Place.length = sizeof(WINDOWPLACEMENT);
03712         if (GetWindowPlacement((HWND)WindowID, &Place))
03713         {
03714             Place.rcNormalPosition.bottom = Place.rcNormalPosition.bottom + (NUMCOLS_EXTRABIT);
03715             SetWindowPlacement((HWND)WindowID, &Place);
03716         }
03717     }
03718 
03719     // Init the gadgets
03720     INT32 NumCols = 0;
03721     BOOL UseSysCols = TRUE;
03722     NumCols     = pOptions->GetNumColsInPalette();
03723     UseSysCols  = pOptions->GetUseSystemColours();
03724 
03725     // Adjust in case we added the system colours
03726     if (UseSysCols)
03727         NumCols -= NUM_SYS_COLS;
03728   
03729     SetLongGadgetValue(_R(IDC_BMPOPTS_NUMCOLS_EDIT),NumCols);
03730     SetBoolGadgetSelected(_R(IDC_BMPOPTS_NUMCOLS_SYSCOLS),UseSysCols);
03731 }
03732 
03733 /******************************************************************************************
03734 
03735 >   void BmpPrefsDlg::HideNumColoursGroup()
03736 
03737     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
03738     Created:    17/1/97
03739     Inputs:     -
03740     Returns:    -
03741     Purpose:    Hides the "number of colour in palette" group in the bitmap export dlg
03742 
03743                 Introduced in WEBSTER
03744 
03745 ******************************************************************************************/
03746 
03747 void BmpPrefsDlg::HideNumColoursGroup()
03748 {
03749     HideGadget(_R(IDC_BMPOPTS_NUMCOLS_EDIT)    ,TRUE);
03750     HideGadget(_R(IDC_BMPOPTS_NUMCOLS_SYSCOLS) ,TRUE);
03751     HideGadget(_R(IDC_BMPOPTS_NUMCOLS_GROUP)   ,TRUE);
03752     HideGadget(_R(IDC_BMPOPTS_NUMCOLS_EDITTEXT),TRUE);
03753 }
03754 
03755 /******************************************************************************************
03756 
03757 >   void BmpPrefsDlg::UpdateNumColoursGroup(BOOL CheckValueRange)
03758 
03759     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
03760     Created:    17/1/97
03761     Inputs:     CheckNumColValueRange = TRUE if the value in the num col ed field should be range checked.
03762     Returns:    -
03763     Purpose:    Enables/disables the "number of colour in palette" group in the bitmap export dlg
03764 
03765                 It also makes sure that the number in the ed field is in range
03766 
03767                 Introduced in WEBSTER
03768 
03769 ******************************************************************************************/
03770 
03771 void BmpPrefsDlg::UpdateNumColoursGroup(BOOL CheckValueRange)
03772 {
03773     BOOL OptPal = GetBoolGadgetSelected(_R(IDC_BMPOPTS_PAL_OPT));
03774     BOOL Bpp8   = GetBoolGadgetSelected(_R(IDC_BMPOPTS_8BPP));
03775     BOOL Bpp4   = GetBoolGadgetSelected(_R(IDC_BMPOPTS_4BPP));
03776 
03777     EnableGadget(_R(IDC_BMPOPTS_NUMCOLS_EDIT)    ,OptPal && (Bpp8 || Bpp4));
03778     EnableGadget(_R(IDC_BMPOPTS_NUMCOLS_EDITTEXT),OptPal && (Bpp8 || Bpp4));
03779     EnableGadget(_R(IDC_BMPOPTS_NUMCOLS_SYSCOLS) ,OptPal && Bpp8);          // 8 bpp only
03780     EnableGadget(_R(IDC_BMPOPTS_NUMCOLS_GROUP)   ,TRUE);                    // Always show group
03781 
03782     // Check that the value in the ed string is not out of range
03783     if ((Bpp8 || Bpp4))
03784     {
03785         BOOL SystemColours = (Bpp8 && GetBoolGadgetSelected(_R(IDC_BMPOPTS_NUMCOLS_SYSCOLS)));
03786         UINT32 Max = 256;
03787         UINT32 Min = 2;
03788         if (Bpp4)
03789             Max = 16;
03790 
03791         // If we are adding system colours, then the smallest number the user can enter is 0
03792         if (SystemColours)
03793             Min = 0;
03794 
03795         // Slight bodge fix here - changed so that every time the user changes the bpp, it resets
03796         // the number of colours to the max colours available
03797         // Comment this line out if you don't want this functionality
03798         if (CheckValueRange)
03799             Min = Max;
03800 
03801         UINT32 NumCols = GetLongGadgetValue(_R(IDC_BMPOPTS_NUMCOLS_EDIT), Min, Max);
03802         if (NumCols > Max)  NumCols = Max;
03803         if (NumCols < Min)  NumCols = Min;
03804         SetLongGadgetValue(_R(IDC_BMPOPTS_NUMCOLS_EDIT),NumCols);
03805     }
03806 }
03807 
03808 /******************************************************************************************
03809 
03810 >   BOOL BmpPrefsDlg::SetNumColoursInPalette(BitmapExportOptions* pOptions)
03811 
03812     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
03813     Created:    17/1/97
03814     Inputs:     pOptions = ptr to the export options to use
03815     Returns:    -
03816     Purpose:    Extracts the number of colours in palette & the system colours switch data
03817                 from the relevant gadgets, and stuffs the data in pOptions.
03818 
03819                 Introduced in WEBSTER
03820 
03821 ******************************************************************************************/
03822 
03823 BOOL BmpPrefsDlg::SetNumColoursInPalette(BitmapExportOptions* pOptions)
03824 {
03825     // Don't bother unless the user wants an optimised palette
03826     if (!GetBoolGadgetSelected(_R(IDC_BMPOPTS_PAL_OPT)))
03827         return TRUE;
03828 
03829     // Only do this for filters that support this feature
03830     if (pOptions != NULL && pOptions->UseSpecificNumColsInPalette())
03831     {
03832         // Set the default values for an 8bpp bitmap
03833         UINT32 MaxNumCols = 256;
03834         UINT32 MinNumCols = 2;
03835         BOOL SystemColours = GetBoolGadgetSelected(_R(IDC_BMPOPTS_NUMCOLS_SYSCOLS));
03836         UINT32 Depth = pOptions->GetDepth();
03837         BOOL Valid;
03838 
03839         // 4bpp has a max num colours of 16, and can't include the system colours
03840         if (Depth == 4)
03841         {
03842             MaxNumCols = 16;
03843             SystemColours = FALSE;
03844         }
03845 
03846         // If we are adding system colours, then the smallest number the user can enter is 0
03847         if (SystemColours)
03848             MinNumCols = 0;
03849 
03850         UINT32 NumCols = GetLongGadgetValue(_R(IDC_BMPOPTS_NUMCOLS_EDIT), MinNumCols, MaxNumCols, 0, &Valid);
03851 
03852         if (!Valid)
03853         {
03854             // Only report an err message in 8bpp & 4bpp modes
03855             if ((Depth == 8) || (Depth == 4))
03856             {
03857                 String_256 ErrMsg;
03858                 ErrMsg.MakeMsg(_R(IDS_BMPPREFS_NUMCOLSWRONG),MinNumCols,MaxNumCols);
03859                 Error::SetError(0,ErrMsg,0);
03860                 InformError();
03861                 return FALSE;
03862             }
03863             NumCols = MaxNumCols;
03864         }
03865 
03866         // If the user wants to add the system colours, then we need to increase the number of 
03867         // total colours to create
03868 
03869         // The number of sys colours is either NUM_SYS_COLS, or 0 if the switch is off
03870         UINT32 NumSysCols = NUM_SYS_COLS;
03871         if (!SystemColours)
03872             NumSysCols = 0;
03873 
03874         NumCols += NumSysCols;
03875         if (NumCols > MaxNumCols)
03876             NumCols = MaxNumCols;
03877 
03878         // Are we to include a transparent colour?
03879         UINT32 NumTransparentCols = 0;
03880         if (GetBoolGadgetSelected(_R(IDC_BMPOPTS_TRANSPARENT)))
03881             NumTransparentCols = 1;
03882 
03883         // Can we reduce the number of bpp automatically?
03884         // Do it only for optimised palettes
03885         if (Depth == 8)
03886         {
03887             // If the total number of colours is 16 or less, choose 4bpp
03888             if (NumCols <= (16-NumTransparentCols))
03889                 GetOptions()->SetDepth(4);
03890 
03891             // If the total number of colours is 2 or less, choose 1bpp
03892             if (NumCols <= (2-NumTransparentCols))
03893                 GetOptions()->SetDepth(1);
03894         }
03895 
03896         pOptions->SetNumColsInPalette(NumCols);
03897         pOptions->SetUseSystemColours(SystemColours);
03898     }
03899 
03900     return TRUE;
03901 }
03902 
03903 void BmpPrefsDlg::InitDepthRadioGroup()
03904 {
03905     // Set up the Bits per pixel buttons
03906     // Filtered above for illegal cases
03907     switch ( GetOptions()->GetDepth() ) 
03908     {
03909         case 1:
03910             SetBPPButtons(_R(IDC_BMPOPTS_1BPP),FALSE);
03911             SetLongGadgetValue(_R(IDC_BMPOPTS_1BPP), TRUE);
03912             LastBppSelected = _R(IDC_BMPOPTS_1BPP);
03913             break;
03914         case 4:
03915             SetBPPButtons(_R(IDC_BMPOPTS_4BPP),FALSE);
03916             SetLongGadgetValue(_R(IDC_BMPOPTS_4BPP), TRUE);
03917             LastBppSelected = _R(IDC_BMPOPTS_4BPP);
03918             break;
03919         case 8:
03920             SetBPPButtons(_R(IDC_BMPOPTS_8BPP),FALSE);
03921             SetLongGadgetValue(_R(IDC_BMPOPTS_8BPP), TRUE);
03922             LastBppSelected = _R(IDC_BMPOPTS_8BPP);
03923             break;
03924         case 24:
03925             SetBPPButtons(_R(IDC_BMPOPTS_24BPP),FALSE);
03926             SetLongGadgetValue(_R(IDC_BMPOPTS_24BPP), TRUE);
03927             LastBppSelected = _R(IDC_BMPOPTS_24BPP);
03928             break;
03929         default:
03930             SetBPPButtons(_R(IDC_BMPOPTS_CMYK),FALSE);
03931             SetLongGadgetValue(_R(IDC_BMPOPTS_CMYK), TRUE);
03932             LastBppSelected = _R(IDC_BMPOPTS_CMYK);
03933             break;
03934     }
03935 }
03936 
03937 
03938 void BmpPrefsDlg::InitPaletteRadioGroup(const PALETTE& Palette)
03939 {
03940 // WEBSTER - markn 17/1/97
03941 // Calls SetPaletteButtons() to do the hard work now.
03942 
03943     switch (Palette)
03944     {
03945         case PAL_OPTIMISED:
03946             SetPaletteButtons(_R(IDC_BMPOPTS_PAL_OPT));
03947             break;
03948 
03949         case PAL_STANDARD:
03950             SetPaletteButtons(_R(IDC_BMPOPTS_PAL_STD));
03951             break;
03952 
03953         default:
03954             TRACE( _T("Non-standard palette set"));
03955             break;
03956     }
03957 }
03958 
03959 
03960 void BmpPrefsDlg::InitDitherRadioGroup(const DITHER& DitherType)
03961 {
03962     // Set up the dithering selection radio buttons
03963     switch (DitherType)
03964     {
03965         case XARADITHER_NONE:
03966             SetLongGadgetValue(_R(IDC_BMPOPTS_NODITHER), TRUE);
03967             break;
03968 
03969         case XARADITHER_ORDERED_GREY:
03970             SetLongGadgetValue(_R(IDC_BMPOPTS_ORDDITHER), TRUE);
03971             break;
03972 
03973         case XARADITHER_ERROR_DIFFUSION:
03974             SetLongGadgetValue(_R(IDC_BMPOPTS_DIFFUSION), TRUE);
03975             break;
03976 
03977         default:
03978             SetLongGadgetValue(_R(IDC_BMPOPTS_DIFFUSION), TRUE);
03979             break;
03980     }
03981 
03982     if (GetOptions()->GetSelectionType() == ABITMAP)
03983     {
03984         // If we are outputing a bitmap directly, then we
03985         // don't need the palette and dithering options
03986         EnableGadget(_R(IDC_BMPOPTS_NODITHER), FALSE);
03987         EnableGadget(_R(IDC_BMPOPTS_ORDDITHER), FALSE);
03988         EnableGadget(_R(IDC_BMPOPTS_DIFFUSION), FALSE);
03989         EnableGadget(_R(IDC_BMPOPTS_PAL_STD), FALSE);
03990         EnableGadget(_R(IDC_BMPOPTS_PAL_OPT), FALSE);
03991     }
03992 }
03993 
03994 
03995     // Set up the save spread/selection radio buttons
03996     // If selection is True then enable the spread/selection/drawing buttons otherwise
03997     // disable the selection button and allow choice between spread or drawing, drawing
03998     // being the default.
03999 void BmpPrefsDlg::InitSelectionRadioGroup()
04000 {
04001     //  Always disable this button.
04002     EnableGadget(_R(IDC_BMPOPTS_SPREAD), FALSE);
04003 
04004     // Set up the save spread/selection radio buttons
04005     if (GetOptions()->GetFilterType() == MAKE_BITMAP_FILTER ||
04006         GetOptions()->GetFilterType() == TI_GIF_ANIM)
04007     {
04008         SetLongGadgetValue(_R(IDC_BMPOPTS_SELECT), TRUE);
04009         // Disable all buttons
04010         EnableGadget(_R(IDC_BMPOPTS_SELECT), FALSE);
04011         EnableGadget(_R(IDC_BMPOPTS_DRAWING), FALSE);
04012     }
04013     else
04014     {
04015         // The drawing option is always available.
04016         EnableGadget(_R(IDC_BMPOPTS_DRAWING), TRUE);
04017 
04018         // If selection is True then enable the spread/selection/drawing buttons otherwise
04019         // disable the selection button and allow choice between spread or drawing, drawing
04020         // being the default.
04021         switch (GetOptions()->GetSelectionType())
04022         {
04023             case SELECTION:
04024                 // If selection present then choose export selection by default
04025                 SetLongGadgetValue(_R(IDC_BMPOPTS_SELECT), TRUE);
04026 
04027                 // Selection present, so enable that button.
04028                 EnableGadget(_R(IDC_BMPOPTS_SELECT), TRUE);
04029                 break;
04030 
04031             default:
04032                 // If no selection present then choose export drawing by default        
04033                 SetLongGadgetValue(_R(IDC_BMPOPTS_DRAWING), TRUE);
04034 
04035                 // No selection present, so let all options be used
04036                 EnableGadget(_R(IDC_BMPOPTS_SELECT), FALSE);
04037                 break;
04038         }
04039     }
04040 
04041     // Finally, smash it over the head with a bodge to disable the whole
04042     // group of gadgets when being invoked from the Name gallery.
04043     if (NamedExportProp::m_fApplyNotExport)
04044     {
04045         EnableGadget(_R(IDC_BMPOPTS_SAVEAREA), FALSE);
04046         EnableGadget(_R(IDC_BMPOPTS_SELECT), FALSE);
04047         EnableGadget(_R(IDC_BMPOPTS_DRAWING), FALSE);
04048         EnableGadget(_R(IDC_BMPOPTS_SPREAD), FALSE);
04049     }
04050 }
04051 
04052 
04053 /******************************************************************************************
04054 
04055 >   BitmapExportOptions* BmpPrefsDlg::GetOptions() const
04056 
04057     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
04058     Created:    23/11/96
04059     Returns:    A pointer to the BitmapExportOptions to be filled in by this dialog
04060     Purpose:    Helper function
04061 
04062 ******************************************************************************************/
04063 BitmapExportOptions* BmpPrefsDlg::GetOptions() const
04064 {
04065     return m_pOptions;
04066 }
04067 
04068 /******************************************************************************************
04069 *** Photo CD import options dialog box
04070 ******************************************************************************************/
04071 
04072 
04073 
04074 /******************************************************************************************
04075 
04076 >   BOOL PhotoCDDlg::InvokeDialog(UINT32 * Page) 
04077     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
04078     Created:    23/11/94
04079     Inputs:     Number of image pages available in the file
04080     Outputs:    Chosen page from the selection of pages
04081     Returns:    True if Ok used or False if Cancel used.
04082     Purpose:    How to invoke or start a PhotoCDDlg box.
04083     Errors:     -
04084     SeeAlso:    -
04085 
04086 ******************************************************************************************/
04087 
04088 BOOL PhotoCDDlg::InvokeDialog(UINT32 * Page)
04089 {
04090     // Params is defined to be the PhotoCDDlgParams class to nicely encapsulate
04091     // all the parameters that we need to pass back and forth.
04092     PhotoCDDlgParam Params(*Page);
04093     pParams = &Params;          // Save a reference to the params for use in the dialog code
04094 
04095     Params.ImageNumber = 0;     // Set default page to be zero
04096     Params.PhotoCDOk = FALSE;   // Ensure ok is False by default
04097 
04098     OpDescriptor *OpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(PhotoCDDlg));
04099 
04100     ERROR3IF(OpDesc == NULL,"PhotoCDDlg::InvokeDialog is unable to find the PhotoCDDlg OpDescriptor");
04101 
04102     if (OpDesc != NULL)
04103         OpDesc->Invoke((OpParam *)&Params);
04104 
04105     // If ok used then alter the page to the one that the user has chosen
04106     if (Params.PhotoCDOk)
04107         *Page = Params.ImageNumber;
04108 
04109     return Params.PhotoCDOk;
04110 }
04111 
04112 /******************************************************************************************
04113 
04114 >   PhotoCDDlg::PhotoCDDlg(): DialogOp(PhotoCDDlg::IDD, PhotoCDDlg::Mode) 
04115 
04116     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
04117     Created:    23/11/94
04118     Inputs:     -
04119     Outputs:    -
04120     Returns:    -
04121     Purpose:    PhotoCDDlg constructor. Creates a non-undoable operation
04122     Errors:     -
04123     SeeAlso:    -
04124 
04125 ******************************************************************************************/
04126 
04127 PhotoCDDlg::PhotoCDDlg(): DialogOp(PhotoCDDlg::IDD, PhotoCDDlg::Mode) 
04128 {
04129     // At present, do nothing.
04130 }
04131 
04132 /******************************************************************************************
04133 
04134 >   BOOL PhotoCDDlg::CommitDialogValues(BmpPrefsDlg* pBmpPrefs)
04135 
04136     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
04137     Created:    23/11/94
04138     Inputs:     pointer to the dialogue box
04139     Outputs:    -
04140     Returns:    True if values in dialog box ok, False otherwise.     
04141     Purpose:    Takes the values in the dialog box and sets the return values accordingly
04142                 Called when ok is pressed on the dialog box.
04143     Errors:     -
04144     SeeAlso:    -
04145 
04146 ******************************************************************************************/
04147 
04148 BOOL PhotoCDDlg::CommitDialogValues(PhotoCDDlg* pPhotoCDPrefs)
04149 {
04150     ERROR3IF(pParams == NULL, "PhotoCDDlg::CommitDialogValues called after duff initialisation?!");
04151 
04152     // Ok has been pressed so take the values and set up the static values so that the
04153     // caller can access them
04154 
04155     // Get the image that the user has chosen from the radio buttons
04156     BOOL Valid = 0;     // Flag for validity of value
04157     BOOL State = 0;
04158     UINT32 Page = 0;
04159     State = GetLongGadgetValue(_R(IDC_PHOTOCD_BASE), 0, 1, 0, &Valid);
04160     if (State)
04161         Page = 0;
04162     State = GetLongGadgetValue(_R(IDC_PHOTOCD_BASEDIV4), 0, 1, 0, &Valid);
04163     if (State)
04164         Page = 1;
04165     State = GetLongGadgetValue(_R(IDC_PHOTOCD_BASEDIV16), 0, 1, 0, &Valid);
04166     if (State)
04167         Page = 2;
04168     State = GetLongGadgetValue(_R(IDC_PHOTOCD_BASE4), 0, 1, 0, &Valid);
04169     if (State)
04170         Page = 3;
04171     State = GetLongGadgetValue(_R(IDC_PHOTOCD_BASE16), 0, 1, 0, &Valid);
04172     if (State)
04173         Page = 4;
04174     pParams->ImageNumber = Page;
04175 
04176     return TRUE;
04177 }
04178 
04179 
04180 /******************************************************************************************
04181 
04182 >   MsgResult PhotoCDDlg::Message(CDlgMessage DlgMsg, CGadgetID Gadget) 
04183 
04184 
04185     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
04186     Created:    28/08/94
04187     Inputs:     -
04188     Outputs:    -
04189     Returns:    -
04190     Purpose:    Handles all the photocd import options dialog's messages
04191     Errors:     -
04192     SeeAlso:    -
04193 
04194 ******************************************************************************************/
04195 
04196 MsgResult PhotoCDDlg::Message(Msg* Message)
04197 {
04198     ERROR3IF(pParams == NULL, "PhotoCDDlg::Message - Parameters not been set up");
04199 
04200     if (IS_OUR_DIALOG_MSG(Message))
04201     {
04202         DialogMsg* Msg = (DialogMsg*)Message;
04203 
04204         MsgResult Result;
04205 
04206         // Main handler for dialog type messages
04207         BOOL EndDialog = FALSE;                     // TRUE if we should quit the dialog
04208 
04209         // Should now handle the required messages that we respond to
04210         switch (Msg->DlgMsg)
04211         {
04212             case DIM_CREATE:
04213                 // As it is a modal dialog box we are sent a message to say the dialog box
04214                 // is being created, so we have a chance to set the initial control values.
04215                 InitDialog(this);
04216             break;
04217 
04218             case DIM_COMMIT:
04219                 // (ok) accept all changes that the user has made to the settings
04220                 // brackets make the ok local to this case 
04221                 {
04222                     BOOL ok;
04223                     ok = CommitDialogValues(this);
04224                     if (ok)
04225                     {
04226                         // Values found ok so quit dialogue then go ahead and export
04227                         pParams->PhotoCDOk = TRUE;          // Flag ok used
04228                         EndDialog = TRUE;
04229                     }
04230                 }
04231             break;
04232 
04233             case DIM_CANCEL:
04234                 // Cancel all changes that the user has made to the settings
04235                 pParams->PhotoCDOk = FALSE;             // Flag cancel used
04236                 EndDialog = TRUE;
04237             break;
04238         }
04239 
04240         // Allow the base class access to the message, it will do the
04241         // DLG_EAT_IF_HUNGRY(Msg) for us
04242         // Must do this before the Close and End
04243         Result = DialogOp::Message(Message);
04244 
04245         // End dialog here
04246         if (EndDialog) 
04247         {
04248             Close();                // Hide the dialog box
04249             End();                  // Finish the operation
04250         }
04251 
04252         // The message was for our dialog box so return that we have handled it, if necessary
04253         return Result;
04254     }
04255     return DialogOp::Message(Message); 
04256 }
04257 
04258 /******************************************************************************************
04259 
04260 >   OpState PhotoCDDlg::GetState(String_256*, OpDescriptor*)
04261 
04262     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
04263     Created:    23/11/94
04264     Inputs:     -
04265     Outputs:    -
04266     Returns:    -
04267     Purpose:    PhotoCDDlg GetState method
04268     Errors:     -
04269     SeeAlso:    -
04270 
04271 ******************************************************************************************/
04272 
04273 OpState PhotoCDDlg::GetState(String_256*, OpDescriptor*)
04274 {    
04275     OpState OpSt;
04276     return(OpSt);
04277 }
04278 
04279 
04280 /******************************************************************************************
04281 
04282 >   BOOL PhotoCDDlg::Init()
04283 
04284     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
04285     Created:    23/11/94
04286     Inputs:     -
04287     Outputs:    -
04288     Returns:    -
04289     Purpose:    PhotoCDDlg Init method
04290     Errors:     -
04291     SeeAlso:    -
04292 
04293 ******************************************************************************************/
04294 
04295 BOOL PhotoCDDlg::Init()
04296 {
04297     BOOL InitOK;
04298 
04299     InitOK = RegisterOpDescriptor(
04300                                 0,                  /* Tool ID */
04301                                 _R(IDS_PHOTOCDDLG),
04302                                 CC_RUNTIME_CLASS(PhotoCDDlg),
04303                                 OPTOKEN_PHOTOCDDLG,
04304                                 GetState,
04305                                 0,                  /* help ID */
04306                                 0,                  /* bubble help */
04307                                 0,                  /* resource ID */
04308                                 0                   /* control ID */
04309                                 );
04310 
04311     return (InitOK);
04312 }
04313 
04314 
04315 /********************************************************************************************
04316 
04317 >   BOOL PhotoCDDlg::Create()
04318 
04319     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
04320     Created:    23/11/94
04321     Inputs:     -
04322     Outputs:    -
04323     Returns:    TRUE if successful, else FALSE
04324     Purpose:    PhotoCDDlg create method 
04325     Errors:     -
04326     SeeAlso:    -
04327 
04328 ********************************************************************************************/
04329        
04330 BOOL PhotoCDDlg::Create()
04331 {                            
04332     if (DialogOp::Create())
04333     { 
04334         // Set the initial control values 
04335         // Dialog now Modal so set up happens in the message handler
04336         //InitDialog(this);
04337 
04338         return TRUE; 
04339     }
04340     else
04341     {
04342         return FALSE; 
04343     }
04344 }
04345 
04346 /******************************************************************************************
04347 
04348 >   void PhotoCDDlg::Do(OpDescriptor*)
04349 
04350     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
04351     Created:    23/11/94
04352     Inputs:     -
04353     Outputs:    -
04354     Returns:    -
04355     Purpose:    Creates then opens the dialog in response to a request from the user.
04356     Errors:     -
04357     SeeAlso:    -
04358 
04359 ******************************************************************************************/
04360 
04361 void PhotoCDDlg::Do(OpDescriptor*)
04362 {
04363     ERROR3("PhotoCDDlg::Do called when should be using DoWithParam!");
04364     End();         // End the operation 
04365 }
04366 
04367 /******************************************************************************************
04368 
04369 >   void PhotoCDDlg::DoWithParam(OpDescriptor*)
04370 
04371     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
04372     Created:    23/11/94
04373     Inputs:     -
04374     Outputs:    -
04375     Returns:    -
04376     Purpose:    Creates then opens the dialog in response to a request from the user and
04377                 allows values to be passed in and returned to the caller via the
04378                 PhotoCDDlgParam class.
04379     Errors:     -
04380     SeeAlso:    -
04381 
04382 ******************************************************************************************/
04383 
04384 void PhotoCDDlg::DoWithParam(OpDescriptor*, OpParam* Param)
04385 {
04386     ERROR3IF(Param == NULL, "PhotoCDDlg::DoWithParam - NULL Param passed in");
04387 
04388     // Use the OpParam that has been passed in to us
04389     PhotoCDDlgParam * BmpDlgParam = (PhotoCDDlgParam *) Param;
04390 
04391     BOOL ok;
04392     
04393     // Force the dialog box to be created, as it is modal it will be opened via a message
04394     ok = Create();
04395 
04396     if ( !ok )
04397     {
04398         // Could not create the dialog box so call inform error 
04399         InformError();
04400         End();         // End the operation 
04401     }
04402 }
04403 
04404 
04405 /******************************************************************************************
04406 
04407 >   BOOL PhotoCDDlg::InitDialog(PhotoCDDlg* pBmpPrefs)
04408 
04409     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
04410     Created:    23/11/94
04411     Inputs:     pointer to the dialog box
04412     Outputs:    -
04413     Returns:    TRUE if successful, else FALSE
04414     Purpose:    Sets initial dialog values 
04415     Errors:     -
04416     SeeAlso:    -
04417 
04418 ******************************************************************************************/
04419 
04420 BOOL PhotoCDDlg::InitDialog(PhotoCDDlg* pBmpPrefs)
04421 {
04422     ERROR3IF(pParams == NULL, "PhotoCDDlg::InitDialog called after duff initialisation?!");
04423 
04424     // Check how many pages were found and if necessary whether to grey some of the
04425     // buttons
04426     // Bodge the Base16 so that ungreys using same condition as the Base4 as once again
04427     // Accusoft are lying and tell us 4 images instead of 5.
04428     EnableGadget(_R(IDC_PHOTOCD_BASE16),    (pParams->NumberOfPages > 3)); //4));
04429     EnableGadget(_R(IDC_PHOTOCD_BASE4),     (pParams->NumberOfPages > 3));
04430     EnableGadget(_R(IDC_PHOTOCD_BASEDIV16), (pParams->NumberOfPages > 2));
04431     EnableGadget(_R(IDC_PHOTOCD_BASEDIV4),  (pParams->NumberOfPages > 1));
04432     EnableGadget(_R(IDC_PHOTOCD_BASE),      (pParams->NumberOfPages > 0));
04433 
04434     switch (pParams->ImageNumber)
04435     {
04436         case 4:
04437             SetLongGadgetValue(_R(IDC_PHOTOCD_BASE16), TRUE);    
04438             break;
04439         case 3:
04440             SetLongGadgetValue(_R(IDC_PHOTOCD_BASE4), TRUE);    
04441             break;
04442         case 2:
04443             SetLongGadgetValue(_R(IDC_PHOTOCD_BASEDIV16), TRUE);
04444             break;
04445         case 1:
04446             SetLongGadgetValue(_R(IDC_PHOTOCD_BASEDIV4), TRUE); 
04447             break;
04448         case 0:
04449         default:
04450             SetLongGadgetValue(_R(IDC_PHOTOCD_BASE), TRUE);     
04451             break;
04452     }
04453 
04454     return TRUE;
04455 }
04456 
04457 
04458 /******************************************************************************************
04459 
04460 >   JPEGExportPrefsDialog::JPEGExportPrefsDialog()
04461 
04462     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
04463     Created:    28/11/96
04464     Purpose:    JPEGExportPrefsDialog constructor.
04465 
04466 ******************************************************************************************/
04467 
04468 JPEGExportPrefsDialog::JPEGExportPrefsDialog(): BmpPrefsDlg() 
04469 {
04470     m_OriginalSourcePresent = FALSE;
04471 }
04472 
04473 
04474 /******************************************************************************************
04475 
04476 >   virtual BOOL JPEGExportPrefsDialog::InitDialog()
04477 
04478     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from Neville)
04479     Created:    23/08/94
04480     Inputs:     pointer to the BmpPrefs
04481     Outputs:    
04482     Returns:    TRUE if successful, else FALSE
04483     Purpose:    Sets initial dialog values 
04484     Errors:     -
04485     SeeAlso:    -
04486 
04487 ******************************************************************************************/
04488 BOOL JPEGExportPrefsDialog::InitDialog()
04489 {
04490     JPEGExportOptions* pOptions = (JPEGExportOptions*)GetOptions();
04491     ERROR2IF(pOptions == NULL,FALSE, "BmpPrefsDlg::InitJPEGDialog called after duff initialisation?!");
04492 
04493     // Set up the title of the dialog box according to the passed in string which
04494     // is the name of the filter plus export bitmap options.
04495     String_256 Temp = *(pOptions->GetFilterName());
04496     Temp += String_256(_R(IDN_EXPORTBMPOPTS));
04497 
04498     SetTitlebarName(&Temp); 
04499 
04500     // Is this already a compressed JPEG? 
04501     
04502     pOptions->SetJPEGPresentAndSelected(FALSE);
04503 
04504     KernelBitmap* pKernelBitmap = pOptions->GetKernelBitmap();
04505 
04506     if (pKernelBitmap != NULL)
04507     {
04508         BitmapSource* pSource = NULL;
04509         BaseBitmapFilter* pDummyFilter;
04510 
04511         pOptions->SetJPEGPresentAndSelected(pKernelBitmap->GetOriginalSource(&pSource, &pDummyFilter));
04512     }
04513 
04514     if (pOptions->GetJPEGPresentAndSelected())
04515     {
04516         SetBoolGadgetSelected(_R(IDC_JPEG_ORIGINAL), TRUE);
04517 
04518         // Disable the other gadgets/
04519 //      EnableGadget(_R(IDC_BMPOPTS_SPREAD), FALSE);
04520         EnableGadget(_R(IDC_BMPOPTS_DRAWING), FALSE);
04521         EnableGadget(_R(IDC_BMPOPTS_SELECT), FALSE);
04522         EnableGadget(_R(IDC_JPGOPTS_PROGRESSIVE), FALSE);
04523 
04524         // Set the range of the slider control plus a step value of 1
04525         SetGadgetRange(_R(IDC_BMPOPTS_QUALITY), 0, 100, 1);
04526         SetGadgetBitmaps(_R(IDC_BMPOPTS_QUALITY), _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER));
04527         SetLongGadgetValue(_R(IDC_BMPOPTS_QUALITY), 0);
04528         EnableGadget(_R(IDC_BMPOPTS_QUALITY), FALSE);
04529 
04530         EnableGadget(_R(IDC_BMPOPTS_RES), FALSE);
04531         EnableGadget(_R(IDC_BMPOPTS_XPIXELS), FALSE);
04532         EnableGadget(_R(IDC_BMPOPTS_YPIXELS), FALSE);
04533         // WEBSTER - markn 5/2/97
04534         // Taken out the X & Y size gadgets
04535 #ifndef WEBSTER
04536         SetStringGadgetValue(_R(IDC_BMPOPTS_XSIZE), &String_8("-"));
04537         SetStringGadgetValue(_R(IDC_BMPOPTS_YSIZE), &String_8("-"));
04538         EnableGadget(_R(IDC_BMPOPTS_XSIZE), FALSE);
04539         EnableGadget(_R(IDC_BMPOPTS_YSIZE), FALSE);
04540 #endif // WEBSTER
04541         EnableGadget(_R(IDC_BMPOPTS_PERCENT), FALSE);
04542     }
04543     else
04544     {
04545         // Disable the "Use Original Source" control.
04546         EnableGadget(_R(IDC_JPEG_ORIGINAL), FALSE);
04547 
04548         // Flag that DPI is supported by JPEGs
04549         m_bDpiSupported = TRUE;
04550 
04551         // First, set up the resolution combo box
04552         SetUpResolutionList();
04553     
04554         // Set up the quality slider and percentage display
04555         INT32 Quality = pOptions->GetQuality(); // Default Quality
04556         // Check that value is not bigger than maximum allowed
04557         if (Quality > 100)
04558             Quality = 100;
04559 
04560         // Set the range of the slider control plus a step value of 1
04561         SetGadgetRange(_R(IDC_BMPOPTS_QUALITY), 0, 100, 1);
04562         SetGadgetBitmaps(_R(IDC_BMPOPTS_QUALITY), _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER));
04563         SetLongGadgetValue(_R(IDC_BMPOPTS_QUALITY), 100 - Quality);
04564         SetBoolGadgetSelected(_R(IDC_JPGOPTS_PROGRESSIVE), pOptions->DoAsProgressive());
04565     
04566         // Set the percentage string
04567         TCHAR Str[32];
04568         String_32 jcf(_R(IDS_PERCENT_FORMAT));
04569         camSprintf(Str, jcf, Quality);
04570         String_32 PercentStr(Str);
04571         SetStringGadgetValue(_R(IDC_BMPOPTS_PERCENT), &PercentStr);
04572 
04573         InitSelectionRadioGroup();
04574     
04575         // Make sure that size fields are displaying the values correctly
04576         RecalculateSize();
04577     }
04578 
04579         return TRUE;
04580 }
04581 
04582 
04583 /******************************************************************************************
04584 
04585 >   void JPEGExportPrefsDialog::SetJPEGDlgState()
04586 
04587     Author:     Ranbir_Rana (Xara Group Ltd) <camelotdev@xara.com> (from Neville)
04588     Created:    21/01/97
04589     Inputs:     -
04590     Outputs:    -
04591     Returns:    -
04592     Purpose:    This will be called to set JPEG dlg controls if the user decides 
04593                 not to export using the the Origianl JPEG image.
04594     Errors:     -
04595     SeeAlso:    -
04596 
04597 ******************************************************************************************/
04598 void JPEGExportPrefsDialog::SetJPEGDlgState()
04599 {
04600     JPEGExportOptions* pOptions = (JPEGExportOptions*)GetOptions();
04601     ERROR3IF(pOptions == NULL, "pOptions is NULL");
04602 
04603     if (pOptions->GetJPEGPresentAndSelected())
04604     {
04605         SetBoolGadgetSelected(_R(IDC_JPEG_ORIGINAL), TRUE);
04606 
04607         // Disable the other gadgets.
04608 //      EnableGadget(_R(IDC_BMPOPTS_SPREAD), FALSE);
04609         EnableGadget(_R(IDC_BMPOPTS_DRAWING), FALSE);
04610         EnableGadget(_R(IDC_BMPOPTS_SELECT), FALSE);
04611         EnableGadget(_R(IDC_JPGOPTS_PROGRESSIVE), FALSE);
04612         EnableGadget(_R(IDC_BMPOPTS_QUALITY), FALSE);
04613         EnableGadget(_R(IDC_BMPOPTS_RES), FALSE);
04614 
04615         EnableGadget(_R(IDC_BMPOPTS_XPIXELS), FALSE);
04616         EnableGadget(_R(IDC_BMPOPTS_YPIXELS), FALSE);
04617         // WEBSTER - markn 5/2/97
04618         // Taken out the X & Y size gadgets
04619 #ifndef WEBSTER
04620         SetStringGadgetValue(_R(IDC_BMPOPTS_XSIZE), &String_8("-"));
04621         SetStringGadgetValue(_R(IDC_BMPOPTS_YSIZE), &String_8("-"));
04622         EnableGadget(_R(IDC_BMPOPTS_XSIZE), FALSE);
04623         EnableGadget(_R(IDC_BMPOPTS_YSIZE), FALSE);
04624 #endif // WEBSTER
04625         EnableGadget(_R(IDC_BMPOPTS_PERCENT), FALSE);
04626     }
04627     else
04628     {
04629         // Enbale the quality & progress controls.
04630         EnableGadget(_R(IDC_BMPOPTS_QUALITY), TRUE);
04631         EnableGadget(_R(IDC_JPGOPTS_PROGRESSIVE), TRUE);
04632         EnableGadget(_R(IDC_BMPOPTS_PERCENT), TRUE);
04633 
04634         // Flag that DPI is supported by JPEGs
04635         m_bDpiSupported = TRUE;
04636 
04637         // First, set up the resolution combo box
04638         SetUpResolutionList();
04639     
04640         // Set up the quality slider and percentage display
04641         INT32 Quality = pOptions->GetQuality(); // Default Quality
04642         // Check that value is not bigger than maximum allowed
04643         if (Quality > 100)
04644             Quality = 100;
04645 
04646         // Set the range of the slider control plus a step value of 1
04647         SetGadgetRange(_R(IDC_BMPOPTS_QUALITY), 0, 100, 1);
04648         SetGadgetBitmaps(_R(IDC_BMPOPTS_QUALITY), _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER));
04649         SetLongGadgetValue(_R(IDC_BMPOPTS_QUALITY), 100 - Quality);
04650         SetBoolGadgetSelected(_R(IDC_JPGOPTS_PROGRESSIVE), pOptions->DoAsProgressive());
04651     
04652         // Set the percentage string
04653         TCHAR Str[32];
04654         String_32 jcf(_R(IDS_PERCENT_FORMAT));
04655         camSprintf(Str, jcf, Quality);
04656         String_32 PercentStr(Str);
04657         SetStringGadgetValue(_R(IDC_BMPOPTS_PERCENT), &PercentStr);
04658 
04659         InitSelectionRadioGroup();
04660     
04661         // Make sure that size fields are displaying the values correctly
04662         RecalculateSize();
04663     }
04664 };
04665 
04666 /******************************************************************************************
04667 
04668 >   virtual MsgResult JPEGExportPrefsDialog::Message(Msg* Message)
04669 
04670     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com>
04671     Created:    12/11/96
04672     Inputs:     See DialogOp for interface details
04673     Purpose:    Handles JPEG dialog specific messages
04674 
04675 ******************************************************************************************/
04676 MsgResult JPEGExportPrefsDialog::Message(Msg* pMessage)
04677 {
04678     ERROR3IF(GetOptions() == NULL, "BmpPrefsDlg::Message - GetOptions() NULL");
04679 
04680     if (IS_OUR_DIALOG_MSG(pMessage))
04681     {
04682         DialogMsg* pMsg = (DialogMsg*)pMessage;
04683         ERROR3IF(!pMsg->IS_KIND_OF(DialogMsg), "pMsg isn't");
04684 
04685         // Should now handle the required messages that we respond to
04686         switch (pMsg->DlgMsg)
04687         {
04688             case DIM_SLIDER_POS_CHANGING:
04689                 // special message for the JPEG qualty control
04690                 // Messages to all the controls, handled individually
04691                 switch (pMsg->GadgetID)
04692                 {
04693                     case _R(IDC_BMPOPTS_QUALITY):
04694                     {
04695                         // Find the current quality scroller's position
04696                         TCHAR Str[32];
04697                         BOOL Valid;
04698                         INT32 Result = GetLongGadgetValue(_R(IDC_BMPOPTS_QUALITY), 0, 100, 0, &Valid);
04699                         Result = 100 - Result;
04700 
04701                         // Build the Percentage string and set it
04702                         String_32 jcf(_R(IDS_PERCENT_FORMAT));
04703                         wsprintf(Str, jcf, (INT32) Result);
04704                         String_32 PercentStr(Str);
04705                         SetStringGadgetValue(_R(IDC_BMPOPTS_PERCENT), &PercentStr);
04706                     }
04707                     break;
04708                 }
04709             break; // DIM_SLIDER_POS_CHANGING       
04710             
04711             case DIM_LFT_BN_CLICKED:
04712                 {
04713                     switch (pMsg->GadgetID)
04714                     {
04715                         case _R(IDC_JPEG_ORIGINAL):
04716                         {
04717                             BOOL Value = GetBoolGadgetSelected(_R(IDC_JPEG_ORIGINAL));
04718                             if (Value)
04719                             {
04720                                 JPEGExportOptions::SetJPEGPresentAndSelected(TRUE);
04721                                 SetJPEGDlgState();
04722                             }
04723                             else
04724                             {
04725                                 JPEGExportOptions::SetJPEGPresentAndSelected(FALSE);
04726                                 SetJPEGDlgState();
04727                             }
04728                         }
04729                         break;
04730                     }
04731                     break;
04732                 }
04733                 break; //DIM_LFT_BN_CLICKED
04734 
04735                 case DIM_CANCEL:
04736                 {
04737                     // The Export has been cancelled, 
04738                     // set our KernelBitmap pointer to NULL.
04739                     JPEGExportOptions::SetKernelBitmap(NULL);
04740                 }
04741                 break;  // DIM_CANCEL
04742         }
04743     }
04744     return BmpPrefsDlg::Message(pMessage);
04745 }
04746 
04747 
04748 /********************************************************************************************
04749 
04750 >   virtual BOOL JPEGExportPrefsDialog::CommitDialogValues()
04751 
04752     Author:     Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> (from Neville)
04753     Created:    03/10/94
04754     Inputs:     pointer to the options to commit
04755     Outputs:    -
04756     Returns:    True if values in dialog box ok, False otherwise.     
04757     Purpose:    Takes the values in the dialog box and sets the return values accordingly
04758                 Called when ok is pressed on the dialog box.
04759     Errors:     -
04760     SeeAlso:    BmpPrefsDlg::CommitDialogValues;
04761 
04762 ********************************************************************************************/
04763 BOOL JPEGExportPrefsDialog::CommitDialogValues()
04764 {
04765     JPEGExportOptions* pOptions = (JPEGExportOptions*)GetOptions();
04766     ERROR3IF(pOptions == NULL, "JPEGExportPrefsDialog::CommitDialogValues called after duff initialisation?!");
04767 
04768     //Added by Graham 27/5/97
04769     //First, let's set the pixel width and height into our OutputSize option
04770     pOptions->SetPixelOutputSize(PixelWidth, PixelHeight);
04771 
04772     // We only want new values, if the "Use Origianl JPEG image" switvh is OFF.
04773     if (!pOptions->GetJPEGPresentAndSelected())
04774     {
04775         // Ok has been pressed so take the values and set up the static values so that the
04776         // caller can access them
04777 
04778         BOOL Valid = 0; // Flag for validity of value
04779         BOOL State = 0; // Flag for reading the state of gadgets
04780 
04781         // Get the dpi value from the resolution combo box 
04782         // Minimum of 5dpi as anything lower causes major problems.  
04783         INT32 Value = GetLongGadgetValue(_R(IDC_BMPOPTS_RES), 5, MAXDPI, _R(IDS_BMPPREFS_INVALIDDPI) ,&Valid);
04784         if ( Valid) 
04785         {
04786             // If returned value in range then set the new default
04787             pOptions->SetDPI(Value);
04788         }
04789         else
04790             return FALSE; 
04791 
04792         // Check that we have not gone over our GDraw limit for pixel width
04793         // Pixel height should not be so much of a problem as we will strip the export. 
04794         RecalculatePixels();
04795         if ((DWORD) PixelWidth > GRenderRegion::GetMaxBitmapWidth() ||
04796             (DWORD) PixelWidth < 1 || (DWORD) PixelHeight < 1 )
04797         {
04798             // There is a problem so warn the user that the value is incorrect
04799             String_256 WarnMsg;
04800 
04801             WarnMsg.MakeMsg(_R(IDE_BMP_BADPIXELWIDTH), GRenderRegion::GetMaxBitmapWidth());
04802             Error::SetError(0, WarnMsg, 0);
04803             InformWarning(0, _R(IDS_OK));
04804             return FALSE; 
04805         }
04806 
04807         // Get quality slider value
04808         State = GetLongGadgetValue(_R(IDC_BMPOPTS_QUALITY), 0, 100, 0, &Valid);
04809         if (Valid)
04810         {
04811             // Return compression to caller
04812             pOptions->SetQuality(100 - State);
04813         }
04814             
04815         // Work out what is currently selected
04816         SelectionType FoundSelection = GetSelection();
04817         pOptions->SetSelectionType(FoundSelection);
04818 
04819         // Get whether a progressive file is wanted or not
04820         State = GetBoolGadgetSelected(_R(IDC_JPGOPTS_PROGRESSIVE), 0, &Valid);
04821         if (Valid)
04822         {
04823             pOptions->SetMakeProgressive(State);
04824         }
04825     }
04826         return TRUE;
04827 }
04828 
04829 
04830 DocRect RandomSelection::GetSize()          { return DocRect(0,0,0,0); }
04831 DocRect SingleBitmapSelection::GetSize()    { return DocRect(0,0,0,0); }
04832 DocRect MultipleBitmapSelection::GetSize()  { return DocRect(0,0,0,0); }
04833 DocRect SpreadSelection::GetSize()          { return BaseBitmapFilter::GetSizeOfSpread(m_pSpread); }
04834 DocRect DrawingSelection::GetSize()         { return BaseBitmapFilter::GetSizeOfDrawing(m_pSpread); }
04835 
04836 #endif
04837 
04838 
04839 
04840 /**************************************************************************************************
04841 Access functions add on 20/10/00 for use by the palette optimiser sjk
04842 // SMFIX
04843 
04844   All added in the cpp file so we can breakpoint on them nicely
04845 **************************************************************************************************/
04846  // is the palette in this export object completely valid and perfect?
04847 BOOL BitmapExportOptions::IsPaletteValid()
04848 {
04849     return m__PaletteIsValid;
04850 }
04851 
04852 void BitmapExportOptions::InvalidatePalette()
04853 {
04854     m__PaletteIsValid = FALSE;
04855     SetTempFileMatchesExportOptions(FALSE);
04856     BitmapExportPaletteInterface::InvalidateSortedPalette();
04857 }
04858 
04859 void BitmapExportOptions::SetTransparencyIndex(INT32 TransparencyIndex)
04860 {
04861     if (m_TransparencyIndex != TransparencyIndex)
04862         SetTempFileMatchesExportOptions(FALSE);
04863     m_TransparencyIndex = TransparencyIndex; 
04864 }
04865 
04866 void BitmapExportOptions::SetBackgroundTransparency(BOOL t)
04867 {
04868     if (m__BackgroundIsTransparent != t)
04869         InvalidatePalette();
04870     m__BackgroundIsTransparent = t;
04871 }
04872 
04873 
04874 INT32   BitmapExportOptions::GetNumberOfUserRequestedColours()
04875 {
04876     return m__NumberOfColoursUserRequested;
04877 }
04878 
04879 void BitmapExportOptions::SetNumberOfUserRequestedColours(INT32 n)
04880 {
04881     if (m__NumberOfColoursUserRequested != n)
04882         InvalidatePalette();
04883     m__NumberOfColoursUserRequested = n;
04884 }
04885 
04886 BOOL BitmapExportOptions::IsUsingBrowserPalette()
04887 {
04888     return m__UseBrowserPalette;
04889 }
04890 
04891 void BitmapExportOptions::SetToUseBrowserPalette(BOOL SetIt)
04892 {
04893     if (m__UseBrowserPalette != SetIt)
04894     {
04895         m__UseBrowserPalette = SetIt;
04896         InvalidatePalette();
04897     }
04898 }
04899 
04900 BOOL BitmapExportOptions::IsUsingSystemPalette()
04901 {
04902     return m__UseSystemColoursInPalette;
04903 }
04904 
04905 void BitmapExportOptions::SetToUseSystemPalette(BOOL SetIt)
04906 {
04907     if (m__UseSystemColoursInPalette != SetIt)
04908     {
04909         m__UseSystemColoursInPalette = SetIt;
04910         InvalidatePalette();
04911     }
04912 }
04913 
04914 INT32 BitmapExportOptions::GetWebSnapPaletteAmount()
04915 {
04916     return m__UseWebSnapPalette;
04917 }
04918 
04919 void BitmapExportOptions::SetWebSnapPaletteAmount(INT32 SetIt)
04920 {
04921     if (m__UseWebSnapPalette != SetIt)
04922     {
04923         m__UseWebSnapPalette = SetIt;
04924         InvalidatePalette();
04925     }
04926 }
04927 
04928 INT32 BitmapExportOptions::GetPrimarySnapPaletteAmount()
04929 {
04930     return m__UsePrimarySnapPalette;
04931 }
04932 
04933 void BitmapExportOptions::SetPrimarySnapPaletteAmount(INT32 SetIt)
04934 {
04935     if (m__UsePrimarySnapPalette != SetIt)
04936     {
04937         m__UsePrimarySnapPalette = SetIt;
04938         InvalidatePalette();
04939     }
04940 }
04941 
04942 
04943 // create palette Optimiser
04944 BOOL BitmapExportOptions::CreatePaletteOptimiser()
04945 {
04946     if (m__pPaletteOptimiser == NULL)
04947     {
04948         m__HavePrimedOptimier = FALSE;
04949         m__pPaletteOptimiser = new PaletteOptimiser();
04950 
04951         ERROR2IF(m__pPaletteOptimiser == NULL, FALSE, "Low on memory, couldn't create palette optimiser");
04952 
04953         m__pPaletteOptimiser->Initialise();
04954 
04955         return TRUE; // we created a new one
04956     }
04957 
04958     return FALSE; // we kept the old one
04959 }
04960 
04961 // flush the palette optimiser if the bitmap source pixels have changed
04962 // since this will affect the stats that were fed into it
04963 void BitmapExportOptions::BitmapSourceHasChanged()
04964 {
04965     m__HavePrimedOptimier = FALSE;
04966     if (m__pPaletteOptimiser != NULL)
04967         delete m__pPaletteOptimiser;
04968 
04969     m__pPaletteOptimiser = NULL;
04970     InvalidatePalette(); // the palette we are holding will be wrong too
04971 }
04972 
04973 // feed the optimiser with stats from the image
04974 void BitmapExportOptions::GatherPaletteStats(const RGBQUAD* pBitmap, UINT32 nSize )
04975 {
04976     if (m__pPaletteOptimiser)
04977     {
04978         m__pPaletteOptimiser->AddStats(pBitmap, nSize);
04979     }
04980 }
04981 
04982 
04983 // fills in a logical palette from the stored extended palette
04984 LOGPALETTE * BitmapExportOptions::GetLogicalPalette()
04985 {
04986     ERROR3IF(!m__PaletteIsValid, "Palette not validated");
04987 
04988     // the logical palette is valid and current
04989     if (m__pLogicalPalette)
04990         return m__pLogicalPalette;
04991 
04992     // build a logical palette based on the extended palette
04993     // calling functions can read and use this data, but they should not delete it
04994     // the logical palette is managed by the export options
04995     m__pLogicalPalette = (LOGPALETTE * ) new BYTE[sizeof(LOGPALETTE) + ( sizeof(PALETTEENTRY) * 256 )];
04996     if (m__pLogicalPalette == NULL)
04997         return NULL;
04998 
04999     // pick a colour to duplicate for deleted colours to be
05000 //  INT32 OptimisedCommonColour = m_Palette.NumberOfColours-1;
05001 
05002     m__pLogicalPalette->palNumEntries = m_Palette.NumberOfColours;
05003     m__pLogicalPalette->palVersion = 0x300;
05004     INT32 i = 0;
05005     for( ; i < m__pLogicalPalette->palNumEntries; i++ )
05006     {
05007         m__pLogicalPalette->palPalEntry[ i ].peRed = m_Palette.Data[ i ].Red;
05008         m__pLogicalPalette->palPalEntry[ i ].peGreen = m_Palette.Data[ i ].Green;           
05009         m__pLogicalPalette->palPalEntry[ i ].peBlue = m_Palette.Data[ i ].Blue;
05010         BOOL NonRenderable = (m_Palette.Data[i].Flags & (DELETED_COLOUR | TRANSPARENT_COLOUR));
05011         m__pLogicalPalette->palPalEntry[ i ].peFlags = NonRenderable ? 255 : 0;
05012     }
05013 
05014     return m__pLogicalPalette;
05015 }
05016 
05017 // swap the current colours in the palette for the 
05018 BOOL BitmapExportOptions::SwapEditedColoursInLogicalPalette()
05019 {
05020     if (!m__pLogicalPalette)
05021         return FALSE;
05022 
05023     BOOL DidASwap = FALSE;
05024     for( INT32 i = 0; i < m__pLogicalPalette->palNumEntries; i++ )
05025     {
05026         if (m_Palette.Data[ i ].Flags & LOCKED_COLOUR)
05027         {
05028             BYTE t;
05029             t = m_Palette.Data[ i ].Red;
05030             m_Palette.Data[ i ].Red = m_Palette.Data[ i ].PreEditedRed;
05031             m_Palette.Data[ i ].PreEditedRed = t;
05032             m__pLogicalPalette->palPalEntry[ i ].peRed = m_Palette.Data[ i ].Red;
05033 
05034             t = m_Palette.Data[ i ].Green;
05035             m_Palette.Data[ i ].Green = m_Palette.Data[ i ].PreEditedGreen;
05036             m_Palette.Data[ i ].PreEditedGreen = t;
05037             m__pLogicalPalette->palPalEntry[ i ].peGreen = m_Palette.Data[ i ].Green;
05038 
05039             t = m_Palette.Data[ i ].Blue;
05040             m_Palette.Data[ i ].Blue = m_Palette.Data[ i ].PreEditedBlue;
05041             m_Palette.Data[ i ].PreEditedBlue = t;
05042             m__pLogicalPalette->palPalEntry[ i ].peBlue = m_Palette.Data[ i ].Blue;
05043 
05044             DidASwap = TRUE;
05045         }
05046     }
05047 
05048     return DidASwap;
05049 }
05050 
05051 // find the next locked colour in the extended palette
05052 // returns the index of the palette entry or -1 if not found
05053 // starts looking from entry pos+1
05054 INT32 BitmapExportOptions::FindNextLockedColour(INT32 pos)
05055 {
05056     pos++;
05057     while (pos < m_Palette.NumberOfColours)
05058     {
05059         if (m_Palette.Data[pos].Flags & LOCKED_COLOUR || m_Palette.Data[pos].Flags & DELETED_COLOUR)
05060             return pos;
05061 
05062         pos++;
05063     }
05064     return -1;
05065 }
05066 
05067 
05068 // This is the function which creates the optimal palette
05069 // It is passed in a ptr to the palette optimiser which has been initiallised and has gathered stats
05070 // on each strip of the bitmap.
05071 // This function then looks at what locked colours the user has set and the other palette
05072 // options the user wants and gives all these to the optimiser.
05073 // It then tries to recreate the options extended palette (including locked colours) from the
05074 // logical palette that the optimiser returns.
05075 // It sets its internal logical palette up and sets the ValidPalette flag to being valid.
05076 void BitmapExportOptions::CreateValidPalette()
05077 {
05078     ASSERT(m__pPaletteOptimiser);
05079 
05080     // tell the export dlg palette ctrl that a new palette is on the horizon
05081     BitmapExportPaletteInterface::InvalidateSortedPalette();
05082 
05083     // delete our old logical palette if we had one
05084     if (m__pLogicalPalette)
05085     {
05086         delete m__pLogicalPalette;
05087         m__pLogicalPalette = NULL;
05088     }
05089 
05090     // allocate space for a logical palette
05091     m__pLogicalPalette = (LOGPALETTE * ) new BYTE[sizeof(LOGPALETTE) + ( sizeof(PALETTEENTRY) * 256 )];
05092     if (m__pLogicalPalette == NULL)
05093         return;
05094     INT32 NewFlags[256];
05095     BYTE EditedColours[256][3];
05096     INT32 BackGroundTransp = m__BackgroundIsTransparent? 1: 0;
05097 
05098     // init the flags for the new palette
05099     memset(&NewFlags, 0, sizeof(INT32)*256);
05100     // init the edited colours for the new palette
05101     memset(&EditedColours, 0, 3*256);
05102 
05103     INT32 i = 0;
05104     // count the locked colours that we had in the last palette,
05105     // these are still the same locked colours for the new palette 
05106     // as the flags would have been removed if they were no longer required
05107     m__pPaletteOptimiser->RemoveLockedColours();
05108     INT32 LockedColours = 0;
05109     for (i = 0; i < m_Palette.NumberOfColours; i++)
05110     {
05111         if (m_Palette.Data[i].Flags & LOCKED_COLOUR || m_Palette.Data[i].Flags & DELETED_COLOUR) // found a locked colour?
05112         {
05113             // add it as a locked colour to the palette
05114             m__pPaletteOptimiser->AddLockedColour(m_Palette.Data[i].Red, m_Palette.Data[i].Green, m_Palette.Data[i].Blue);
05115             // count the locked colours so far
05116             LockedColours++;
05117         }
05118     }
05119     // how many colours can we fit in the palette
05120     INT32 MaxColoursInPalette = 256;
05121     if (m_Depth == 4)
05122         MaxColoursInPalette = 16;
05123     else if (m_Depth == 1)
05124         MaxColoursInPalette = 2;
05125 
05126     MaxColoursInPalette = max(2, min(MaxColoursInPalette, m__NumberOfColoursUserRequested));
05127 
05128     // work out how many spare colours we have within the user defined restraint
05129     // once we have kept these locked colours and have account for the transparency
05130 //  INT32 NoOfColoursToOptimise = MaxColoursInPalette - LockedColours - BackGroundTransp;
05131 
05132     m__pPaletteOptimiser->SnapToBrowserPalette(m__UseWebSnapPalette);
05133     m__pPaletteOptimiser->SnapToPrimaries(m__UsePrimarySnapPalette);
05134     m__pPaletteOptimiser->AddSystemColours((m__UseSystemColoursInPalette == TRUE));
05135     m__pPaletteOptimiser->UseBrowserPalette((m__UseBrowserPalette == TRUE));
05136 
05137     // tell the optimiser that we have finished gathering the stats
05138     //if (!m__HavePrimedOptimier) // can I get away with putting this optimisation back gav?
05139     {
05140         m__pPaletteOptimiser->GenPalette(max(2,MaxColoursInPalette - BackGroundTransp));
05141         m__HavePrimedOptimier = TRUE;
05142     }
05143 
05144     m__pLogicalPalette->palNumEntries = MaxColoursInPalette;
05145     m__pLogicalPalette->palVersion = 0x300;
05146 
05147     // get the optimised palette from the optimser
05148     /*BOOL JustBmpColours =*/ m__pPaletteOptimiser->GetPalette( m__pLogicalPalette, max(2,MaxColoursInPalette - BackGroundTransp));
05149 
05150 //  if (JustBmpColours)
05151 //      TRACE( _T("Just bmp colours\n"));
05152 //  else
05153 //      TRACE( _T("fully optimised colours\n"));
05154 
05155     // reset the flags in the new palette from the locked/deleted colours we had in the old palette
05156     // they may not be in the new palette, but they are LIKELY to be there
05157     INT32 index = -1;
05158     while ((index = FindNextLockedColour(index)) != -1) // find the next locked colour
05159     {
05160         // does this match in the palette
05161         for (i = 0; i < m__pLogicalPalette->palNumEntries; i++)
05162             if (NewFlags[i] == 0 &&
05163                 m_Palette.Data[index].Red   == m__pLogicalPalette->palPalEntry[ i ].peRed &&
05164                 m_Palette.Data[index].Green == m__pLogicalPalette->palPalEntry[ i ].peGreen &&
05165                 m_Palette.Data[index].Blue  == m__pLogicalPalette->palPalEntry[ i ].peBlue
05166                 )
05167             {
05168                 NewFlags[i] = m_Palette.Data[index].Flags;
05169                 EditedColours[i][0] = m_Palette.Data[index].PreEditedRed;
05170                 EditedColours[i][1] = m_Palette.Data[index].PreEditedGreen;
05171                 EditedColours[i][2] = m_Palette.Data[index].PreEditedBlue;
05172                 break;
05173             }
05174     }
05175 
05176     // special case for 1 colour - dont mix them up
05177     if (MaxColoursInPalette - BackGroundTransp == 1)
05178     {
05179         m_Palette.NumberOfColours = m__pLogicalPalette->palNumEntries = 2;
05180         // bias against the background colour and use the other colour if 
05181         // the background colour is more predominant
05182         DocColour dcol = Page::GetPageColour();
05183         INT32 bgr = 255, bgg = 255, bgb = 255;
05184 
05185         // the above call the GetPageColour doesn't work very well
05186         // this code gets it better if the spread and the layer exist
05187         Spread* pSelSpread = Document::GetSelectedSpread();
05188         if (pSelSpread)
05189         {
05190             Layer * pLayer = pSelSpread->FindFirstPageBackgroundLayer();
05191             if (pLayer)
05192             {
05193                 Node * pNode = SliceHelper::FindNextOfClass(pLayer, pLayer, CC_RUNTIME_CLASS(AttrFlatColourFill));
05194                 if (pNode)
05195                     dcol = *(((AttrFlatFill *)pNode)->GetStartColour());
05196             }
05197         }
05198 
05199         dcol.GetRGBValue(&bgr,&bgg,&bgb);
05200 
05201         // pick which of the two colours to use
05202         if (BackGroundTransp && 
05203             (m__pLogicalPalette->palPalEntry[ 0 ].peRed == (BYTE)bgr || m__pLogicalPalette->palPalEntry[ 0 ].peRed == (BYTE)bgr-1) &&
05204             (m__pLogicalPalette->palPalEntry[ 0 ].peGreen == (BYTE)bgg || m__pLogicalPalette->palPalEntry[ 0 ].peGreen == (BYTE)bgg-1) &&
05205             (m__pLogicalPalette->palPalEntry[ 0 ].peBlue == (BYTE)bgb || m__pLogicalPalette->palPalEntry[ 0 ].peBlue == (BYTE)bgb-1))
05206         {
05207             m__pLogicalPalette->palPalEntry[ 0 ].peRed = m__pLogicalPalette->palPalEntry[ 1 ].peRed;
05208             m__pLogicalPalette->palPalEntry[ 0 ].peGreen = m__pLogicalPalette->palPalEntry[ 1 ].peGreen;
05209             m__pLogicalPalette->palPalEntry[ 0 ].peBlue = m__pLogicalPalette->palPalEntry[ 1 ].peBlue;
05210         }
05211     }
05212     else if (MaxColoursInPalette == 2) // special case for two colour none transp
05213     {
05214         // make it black and white
05215         m__pLogicalPalette->palPalEntry[ 0 ].peRed = 0;
05216         m__pLogicalPalette->palPalEntry[ 0 ].peGreen = 0;
05217         m__pLogicalPalette->palPalEntry[ 0 ].peBlue = 0;
05218         m__pLogicalPalette->palPalEntry[ 0 ].peFlags = 0;
05219         m__pLogicalPalette->palPalEntry[ 1 ].peRed = 255;
05220         m__pLogicalPalette->palPalEntry[ 1 ].peGreen = 255;
05221         m__pLogicalPalette->palPalEntry[ 1 ].peBlue = 255;
05222         m__pLogicalPalette->palPalEntry[ 1 ].peFlags = 0;
05223     }
05224 
05225     // make room for transp as the first colour
05226     // by moving the other colours up
05227     if (BackGroundTransp)
05228     {
05229         // add the background colour to the palette which is one more colour in there
05230         if (m__pLogicalPalette->palNumEntries <  MaxColoursInPalette)
05231             m__pLogicalPalette->palNumEntries++;
05232 
05233         // move all the colours up a place
05234         for (INT32 i = m__pLogicalPalette->palNumEntries-1; i > 0; i--)
05235         {
05236             m__pLogicalPalette->palPalEntry[ i ].peRed = m__pLogicalPalette->palPalEntry[ i-1 ].peRed;
05237             m__pLogicalPalette->palPalEntry[ i ].peGreen = m__pLogicalPalette->palPalEntry[ i-1 ].peGreen;
05238             m__pLogicalPalette->palPalEntry[ i ].peBlue = m__pLogicalPalette->palPalEntry[ i-1 ].peBlue;
05239             NewFlags[i] = NewFlags[i-1];
05240             EditedColours[i][0] = EditedColours[i-1][0];
05241             EditedColours[i][1] = EditedColours[i-1][1];
05242             EditedColours[i][2] = EditedColours[i-1][2];
05243         }
05244 
05245         // the transp coluor is white 255,255,255
05246         m__pLogicalPalette->palPalEntry[ 0 ].peRed = 255;
05247         m__pLogicalPalette->palPalEntry[ 0 ].peGreen = 255;
05248         m__pLogicalPalette->palPalEntry[ 0 ].peBlue = 255;
05249 
05250         NewFlags[0] = TRANSPARENT_COLOUR;
05251         SetTransparencyIndex(0);
05252     }
05253     else
05254     {
05255         // we dont have background transparancy but do we have any other colour that is
05256         // set to being transparent?
05257         INT32 TranspIndex = -1; // the default no transp
05258         // find a transp marker in the new flags
05259         for (i = 0; i < m__pLogicalPalette->palNumEntries && TranspIndex == -1; i++)
05260         {
05261             if (NewFlags[i] & TRANSPARENT_COLOUR)
05262                 TranspIndex = i;
05263 
05264         }
05265         // set the transp index
05266         SetTransparencyIndex(TranspIndex);
05267     }
05268 
05269     // the palette is now valid
05270     m__PaletteIsValid = TRUE;
05271 
05272     // set the number of colours in the extended palette to match those in the new palette that
05273     // the optimiser returned to us
05274     m_Palette.NumberOfColours = m__pLogicalPalette->palNumEntries;
05275 
05276     // fill in the extended palette from the logical palette that is now optimal for this export
05277     for (i = 0; i < 256; i++)
05278     {
05279         m_Palette.Data[i].Red = m__pLogicalPalette->palPalEntry[ i ].peRed;
05280         m_Palette.Data[i].Green = m__pLogicalPalette->palPalEntry[ i ].peGreen;
05281         m_Palette.Data[i].Blue = m__pLogicalPalette->palPalEntry[ i ].peBlue;
05282         m_Palette.Data[i].Flags = NewFlags[i];
05283         m_Palette.Data[i].PreEditedRed = EditedColours[i][0];
05284         m_Palette.Data[i].PreEditedGreen = EditedColours[i][1];
05285         m_Palette.Data[i].PreEditedBlue = EditedColours[i][2];
05286 
05287         if (i >= m__pLogicalPalette->palNumEntries || 
05288             (m_Palette.Data[i].Flags & (DELETED_COLOUR | TRANSPARENT_COLOUR)))
05289             m__pLogicalPalette->palPalEntry[ i ].peFlags = 255; // meaning dont display this colour
05290         else
05291             m__pLogicalPalette->palPalEntry[ i ].peFlags = 0; // meaning do display this colour
05292     }
05293 
05294 }
05295 
05296 
05297 // This pairs with the function above and creates a valid palette from a known
05298 // logical palette where one colour can be marked as transparent
05299 void BitmapExportOptions::CreateValidPalette(LOGPALETTE * pPal, INT32 TranspIndex)
05300 {
05301     // tell the export dlg palette ctrl that a new palette is on the horizon
05302     BitmapExportPaletteInterface::InvalidateSortedPalette();
05303     // delete our old logical palette if we had one
05304     if (m__pLogicalPalette)
05305     {
05306         delete m__pLogicalPalette;
05307         m__pLogicalPalette = NULL;
05308     }
05309 
05310     m__PaletteIsValid = (pPal != NULL);
05311 
05312     if (!m__PaletteIsValid)
05313         return;
05314 
05315     // copy the logical palette data if it was valid
05316     m__pLogicalPalette = (LOGPALETTE * ) new BYTE[sizeof(LOGPALETTE) + ( sizeof(PALETTEENTRY) * 256 )];
05317 
05318     if (m__pLogicalPalette == NULL)
05319     {
05320         InvalidatePalette();
05321         return;
05322     }
05323 
05324     m__pLogicalPalette->palVersion = 0x300;
05325 
05326     // set the number of colours in the extended palette to match those in the new palette passed in
05327     m_Palette.NumberOfColours = m__pLogicalPalette->palNumEntries = pPal->palNumEntries;
05328     // fill in the extended palette from the new logical palette from the logical palette passed in
05329     for (INT32 i = 0; i < pPal->palNumEntries; i++)
05330     {
05331         m_Palette.Data[i].Red = pPal->palPalEntry[ i ].peRed;
05332         m_Palette.Data[i].Green = pPal->palPalEntry[ i ].peGreen;
05333         m_Palette.Data[i].Blue = pPal->palPalEntry[ i ].peBlue;
05334         m_Palette.Data[i].Flags = 0; // no flags set this will loose any locked colours etc as these are not part of a logical palette
05335 
05336         m__pLogicalPalette->palPalEntry[ i ].peRed = m_Palette.Data[i].Red;
05337         m__pLogicalPalette->palPalEntry[ i ].peGreen = m_Palette.Data[i].Green;
05338         m__pLogicalPalette->palPalEntry[ i ].peBlue = m_Palette.Data[i].Blue;
05339         m__pLogicalPalette->palPalEntry[ i ].peFlags = 0;
05340     }
05341 
05342     if (TranspIndex >= 0 && TranspIndex < pPal->palNumEntries)
05343     {
05344         m_Palette.Data[TranspIndex].Flags = TRANSPARENT_COLOUR;
05345         m__pLogicalPalette->palPalEntry[ TranspIndex ].peFlags = 255;
05346         SetTransparencyIndex(TranspIndex);
05347     }
05348 }
05349 
05350 // this likewise sets the extended palette to a preset browser palette
05351 // which is only used in the creation of a global palette for all animated frames
05352 void BitmapExportOptions::CreateValidBrowserPalette(BOOL WantTransp)
05353 {
05354     // tell the export dlg palette ctrl that a new palette is on the horizon
05355     BitmapExportPaletteInterface::InvalidateSortedPalette();
05356     // delete our old logical palette if we had one
05357     if (m__pLogicalPalette)
05358     {
05359         delete m__pLogicalPalette;
05360         m__pLogicalPalette = NULL;
05361     }
05362 
05363     m__PaletteIsValid = TRUE;
05364 
05365     // copy the logical palette data if it was valid
05366     m__pLogicalPalette = (LOGPALETTE * ) new BYTE[sizeof(LOGPALETTE) + ( sizeof(PALETTEENTRY) * 256 )];
05367 
05368     if (m__pLogicalPalette == NULL)
05369     {
05370         InvalidatePalette();
05371         return;
05372     }
05373 
05374     m__pLogicalPalette->palVersion = 0x300;
05375 
05376     // set the number of colours in the extended palette to match those in the new palette passed in
05377     m_Palette.NumberOfColours = m__pLogicalPalette->palNumEntries = WantTransp ? 217 : 216;
05378     // fill in the extended palette from the new logical palette from the logical palette passed in
05379 
05380     m_Palette.Data[0].Red = 255 ;
05381     m_Palette.Data[0].Green = 255;
05382     m_Palette.Data[0].Blue = 255;
05383     m_Palette.Data[0].Flags = WantTransp ? TRANSPARENT_COLOUR : 0;
05384     m__pLogicalPalette->palPalEntry[ 0 ].peRed = m_Palette.Data[0].Red;
05385     m__pLogicalPalette->palPalEntry[ 0 ].peGreen = m_Palette.Data[0].Green;
05386     m__pLogicalPalette->palPalEntry[ 0 ].peBlue = m_Palette.Data[0].Blue;
05387     m__pLogicalPalette->palPalEntry[ 0 ].peFlags = WantTransp ? 255 : 0;
05388 
05389     SetTransparencyIndex(WantTransp ? 0 : -1);
05390     
05391     INT32 i = 1;
05392     for (INT32 r = 0; r < 256; r += 51)
05393         for (INT32 g = 0; g < 256; g += 51)
05394             for (INT32 b = 0; b < 256; b += 51)
05395             {
05396                 m_Palette.Data[i].Red = r ;
05397                 m_Palette.Data[i].Green = g;
05398                 m_Palette.Data[i].Blue = b;
05399                 m_Palette.Data[i].Flags = 0; // no flags set this will loose any locked colours etc as these are not part of a logical palette
05400 
05401                 m__pLogicalPalette->palPalEntry[ i ].peRed = m_Palette.Data[i].Red;
05402                 m__pLogicalPalette->palPalEntry[ i ].peGreen = m_Palette.Data[i].Green;
05403                 m__pLogicalPalette->palPalEntry[ i ].peBlue = m_Palette.Data[i].Blue;
05404                 m__pLogicalPalette->palPalEntry[ i ].peFlags = 0;
05405                 i++;
05406             }
05407 }
05408 
05409 /***************************************************************************************
05410     Author:     Mark_Howitt (Xara Group Ltd) <camelotdev@xara.com>
05411     Created:    28/11/00
05412     Returns:    TRUE if supported or FALSE if not!
05413     Purpose:    Return true if the current filter allows palette info
05414 
05415 ******************************************************************************************/
05416 BOOL BitmapExportOptions::GetSupportsPalette()
05417 {
05418     // Set up the return variable
05419     BOOL Supported = FALSE;
05420     UINT32 FilterStrID = GetFilterNameStrID();
05421 
05422     // We can only use palettes with Bitmaps of 8 BPP or less, so quick check first!
05423     if(m_Depth <= 8)
05424     {
05425         // Find out what Filter Type we are
05426         Supported = (FilterStrID == _R(IDN_FILTERNAME_GIF) || FilterStrID == _R(IDT_FILTERNAME_BMP) || FilterStrID == _R(IDS_FILTERNAME_PNG));
05427     }
05428 
05429     return Supported;
05430 }
05431 
05432 /******************************************************************************************
05433 
05434   > DWORD BitmapExportOptions::GetSupportedDithers()
05435 
05436     Author:     Mark_Howitt (Xara Group Ltd) <camelotdev@xara.com>
05437     Created:    28/11/00
05438     Returns:    ENUM of the avaliable dither types, 0 if dithering not supported
05439     Purpose:    Returns the allowed dither types the current filter supports.
05440 
05441 ******************************************************************************************/
05442 DWORD BitmapExportOptions::GetSupportedDithers()
05443 {
05444     // Set up the return variable
05445     DWORD Supported = 0;
05446     UINT32 FilterStrID = GetFilterNameStrID();
05447 
05448     // We can only use palettes with Bitmaps of 8 BPP or less, so quick check first!
05449     if(m_Depth <= 8)
05450     {
05451         // Find out what Filter Type we are
05452 //      switch (FilterStrID)
05453 //      {
05454 //      case _R(IDN_FILTERNAME_GIF):
05455 //      case _R(IDS_FILTERNAME_PNG):
05456 //      case _R(IDT_FILTERNAME_BMP):
05457         if (FilterStrID==_R(IDN_FILTERNAME_GIF) || FilterStrID==_R(IDS_FILTERNAME_PNG) || FilterStrID==_R(IDT_FILTERNAME_BMP))
05458             {
05459                 Supported |= ERROR_DITHER;
05460 
05461                 if (m__UseBrowserPalette && m_Depth != 4)
05462                     Supported |= ORDERED_DITHER;
05463 
05464 //              break;
05465             }
05466 //      case _R(IDS_JPG_EXP_FILTERNAME):
05467 //      default:
05468 //          break; // Not supported so don`t do anything!
05469 //      }
05470     }
05471 
05472     return Supported;
05473 }
05474 
05475 /******************************************************************************************
05476 
05477   > DWORD BitmapExportOptions::GetSupportedColourDepths()
05478 
05479     Author:     Mark_Howitt (Xara Group Ltd) <camelotdev@xara.com>
05480     Created:    28/11/00
05481     Returns:    BitField value of the avaliable colours allowed
05482     Purpose:    Returns the all the colour depths the current filter supports.
05483 
05484 ******************************************************************************************/
05485 DWORD BitmapExportOptions::GetSupportedColourDepths()
05486 {
05487     // Set up the return variable
05488     DWORD Supported = 0;
05489     UINT32 FilterStrID = GetFilterNameStrID();
05490 
05491     if(FilterStrID == _R(IDN_FILTERNAME_GIF))
05492         Supported = (COLOUR_2 | COLOUR_16 | COLOUR_256 );
05493     else if(FilterStrID == _R(IDT_FILTERNAME_BMP))
05494         Supported = (COLOUR_2 | COLOUR_16 | COLOUR_256 | COLOUR_24BIT);
05495     else if(FilterStrID == _R(IDS_FILTERNAME_PNG))
05496         Supported = (COLOUR_2 | COLOUR_16 | COLOUR_256 | COLOUR_24BIT | COLOUR_32BIT);
05497     else if (FilterStrID == _R(IDS_JPG_EXP_FILTERNAME))
05498         Supported = COLOUR_24BIT;
05499     else
05500         // Anything else gets a choice of all types
05501         Supported = (COLOUR_2 | COLOUR_16 | COLOUR_256 | COLOUR_24BIT | COLOUR_32BIT);
05502 
05503     return Supported;
05504 }
05505 
05506 /******************************************************************************************
05507 
05508   > BOOL BitmapExportOptions::SupportsTransparency()
05509 
05510     Author:     Mark_Howitt (Xara Group Ltd) <camelotdev@xara.com>
05511     Created:    28/11/00
05512     Returns:    TRUE if Supported else FALSE!
05513     Purpose:    Used to see if the current filter allows transparencies.
05514 
05515 ******************************************************************************************/
05516 BOOL BitmapExportOptions::GetSupportsTransparency()
05517 {
05518     // Set up the return variable
05519     BOOL Supported = FALSE;
05520     UINT32 FilterStrID = GetFilterNameStrID();
05521 
05522     // We can only use Transparency with Bitmaps of 8 BPP or less, so quick check first!
05523     if(m_Depth <= 8)
05524     {
05525         Supported = (FilterStrID == _R(IDN_FILTERNAME_GIF) || FilterStrID == _R(IDS_FILTERNAME_PNG));
05526     }
05527 
05528     return Supported;
05529 }
05530 
05531 /******************************************************************************************
05532 
05533   > DWORD BitmapExportOptions::GetInterlaceType()
05534 
05535     Author:     Mark_Howitt (Xara Group Ltd) <camelotdev@xara.com>
05536     Created:    28/11/00
05537     Returns:    TRUE if supported or FALSE if not!
05538     Purpose:    Return true if the current filter allows palette info
05539 
05540 ******************************************************************************************/
05541 DWORD BitmapExportOptions::GetInterlaceType()
05542 {
05543     // Set up the return variable
05544     DWORD Supported = 0;
05545     UINT32 FilterStrID = GetFilterNameStrID();
05546 
05547     if(FilterStrID == _R(IDN_FILTERNAME_GIF))
05548         Supported = GIF_INTERLACE;
05549     else if(FilterStrID == _R(IDS_FILTERNAME_PNG))
05550         Supported = PNG_INTERLACE;
05551     else if(FilterStrID == _R(IDS_JPG_EXP_FILTERNAME))
05552         Supported = JPG_PROGRESSIVE;
05553 
05554     return Supported;
05555 }
05556 
05557 
05558 /******************************************************************************************
05559 
05560   > BaseBitmapFilter * BitmapExportOptions::FindBitmapFilterForTheseExportOptions()
05561 
05562     Author:     Simon_Knight (Xara Group Ltd) <camelotdev@xara.com>
05563     Created:    4/12/00
05564     Returns:    ptr to a filter that can be used to export using these export options
05565 
05566 ******************************************************************************************/
05567 BaseBitmapFilter * BitmapExportOptions::FindBitmapFilterForTheseExportOptions()
05568 {
05569     // get the name this filter thinks it is
05570     const StringBase * pFilterName = GetFilterName();
05571     String_256 PreferedFiltersName = "";
05572     
05573     // check this ptr can be NULL
05574     if (pFilterName)
05575         PreferedFiltersName = *(GetFilterName());
05576 
05577     // fill it with the name that the export options thinks should be using the options
05578     // if the filters name hasn't been put in
05579     if (PreferedFiltersName.IsEmpty() || GetFilterNameStrID() == _R(IDT_FILTERNAME_BMP)) // bodge for _R(IDT_FILTERNAME_BMP) since the program is using multiple strings for this filter BMP/Windows bitmaps
05580     {
05581         PreferedFiltersName.Load(GetFilterNameStrID());
05582     }
05583 
05584 
05585     Filter *pFilter = Filter::GetFirst();
05586     while (pFilter != NULL)
05587     {
05588         // If we are filtering for bitmap filters then check that if a Bpp has been
05589         // specified that the bitmap filter can cope with that.
05590         FilterFlags Flags = pFilter->GetFlags();
05591         if (Flags.CanExport && pFilter->IsKindOf(CC_RUNTIME_CLASS(BaseBitmapFilter)))
05592         {
05593             BaseBitmapFilter* pBitmapFilter = (BaseBitmapFilter*)pFilter;
05594             if (PreferedFiltersName.CompareTo(pFilter->pOILFilter->FilterName, FALSE) == 0)
05595                 return pBitmapFilter;
05596         }
05597         // Try the next filter
05598         pFilter = Filter::GetNext(pFilter);
05599     }
05600 
05601     return NULL;
05602 }
05603 
05604 /**************************************************************************************************
05605 End of Access functions add on 20/10/00 for use by the palette optimiser sjk
05606 **************************************************************************************************/

Generated on Sat Nov 10 03:44:29 2007 for Camelot by  doxygen 1.4.4