fimagdlg.cpp

Go to the documentation of this file.
00001 // $Id: fimagdlg.cpp 1282 2006-06-09 09:46:49Z alex $
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 
00100 #include "camtypes.h"
00101 
00102 //#include "app.h"      //For GetApplication::FindSelection - in camtypes.h [AUTOMATICALLY REMOVED]
00103 
00104 #include "fimagdlg.h"
00105 //#include "imagdlg.h"  //Imagemap dialog resources
00106 //#include "resimmap.h" //General imagemap resources
00107 
00108 //#include "dialogop.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 //#include "msg.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 
00111 //#include "winrect.h"  //For WinRect - in camtypes.h [AUTOMATICALLY REMOVED]
00112 #include "osrndrgn.h"   //For OSRenderRegion::BitmapDocRectToWin
00113 #include "bitfilt.h"    //For BaseBitmapFilter::GetSizeOfDrawing
00114 #include "bmpfiltr.h"   //For BMPFilter::GetDefaultExportDPI
00115 #include "strlist.h"    //For class StringListItem
00116 
00117 #include "xshelpid.h"   //For the help ID
00118 
00119 DECLARE_SOURCE("$Revision: 1282 $");
00120 
00121 CC_IMPLEMENT_DYNCREATE(ImagemapDlg, DialogOp)
00122 
00123 #define new CAM_DEBUG_NEW
00124 
00125 // Set up the dialog box details stored as statics in the class
00126 CDlgResID ImagemapDlg::IDD = _R(IDD_EXPORT_IMAGEMAP);
00127 const CDlgMode ImagemapDlg::Mode = MODAL;
00128 
00129 BOOL ImagemapDlg::DontHandleNextMessage=FALSE;
00130 BOOL ImagemapDlg::DialogWasCancelled=FALSE;
00131 
00132 //And our static "Options" member variable
00133 ImagemapFilterOptions ImagemapDlg::ms_Options=ImagemapFilterOptions();      
00134 List* ImagemapDlg::ms_plstNames=NULL;       
00135 
00136 /******************************************************************************************
00137 
00138 >   BOOL ImagemapDlg::InvokeDialog(ImagemapFilterOptions* pifoDefault, List* plstNames) 
00139 
00140 
00141     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00142     Created:    10/4/97
00143     Inputs:     pifoDefault - The options that will be displayed when
00144                              the dialog starts
00145 
00146                 plstNames   - A list of suggested imagemap names that
00147                               will be displayed when the dialog starts.
00148                               May be NULL.
00149 
00150     Outputs:    pifoDefault - The options that the user entered
00151     Returns:    TRUE - OK was pressed
00152                 FALSE - Cancel was pressed
00153     Purpose:    Starts up the Imagemap Export Options dialog box
00154     Errors:     -
00155     SeeAlso:    -
00156 
00157 ******************************************************************************************/
00158 
00159 BOOL ImagemapDlg::InvokeDialog(ImagemapFilterOptions* pifoDefault, List* plstNames) 
00160 {
00161     // Make a local copy of the options
00162     ms_Options=*pifoDefault;
00163     ms_plstNames=plstNames;
00164 
00165     //Say that the dialog wasn't cancelled
00166     DialogWasCancelled=FALSE;
00167 
00168     //Find the dialog's op descriptor
00169     OpDescriptor *OpDesc = OpDescriptor::FindOpDescriptor(CC_RUNTIME_CLASS(ImagemapDlg));
00170 
00171     //And start up the dialog
00172     if (OpDesc != NULL)
00173         OpDesc->Invoke();
00174 
00175     //And return the options we've got back
00176     *pifoDefault=ms_Options;
00177 
00178     return !DialogWasCancelled;
00179 }
00180 
00181 
00182 /******************************************************************************************
00183 
00184 >   ImagemapDlg::ImagemapDlg(): DialogOp(ImagemapDlg::IDD, ImagemapDlg::Mode) 
00185 
00186 
00187     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00188     Created:    10/4/97
00189     Inputs:     -
00190     Outputs:    -
00191     Returns:    -
00192     Purpose:    Default constructor
00193     Errors:     -
00194     SeeAlso:    -
00195 
00196 ******************************************************************************************/
00197 
00198 ImagemapDlg::ImagemapDlg(): DialogOp(ImagemapDlg::IDD, ImagemapDlg::Mode) 
00199 {
00200 
00201 }
00202 
00203 /******************************************************************************************
00204 
00205 >   MsgResult ImagemapDlg::Message(CDlgMessage DlgMsg, CGadgetID Gadget) 
00206 
00207 
00208     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00209     Created:    10/4/97
00210     Inputs:     -
00211     Outputs:    -
00212     Returns:    -
00213     Purpose:    Handles all messages.
00214 
00215                 This function simply maps the message to one of our message handling
00216                 functions below.
00217 
00218     Errors:     -
00219     SeeAlso:    -
00220 
00221 ******************************************************************************************/
00222 
00223 MsgResult ImagemapDlg::Message(Msg* Message)
00224 {
00225     //If the message came from within our dialog 
00226     if (IS_OUR_DIALOG_MSG(Message))
00227     {
00228         //Then cast it into a dialog message and handle it
00229         DialogMsg* Msg = (DialogMsg*)Message;
00230 
00231         //If this flag gets set, we should close the dialog
00232         BOOL EndDialog = FALSE;
00233 
00234         //Now pass the message to a message handling function
00235         switch (Msg->DlgMsg)
00236         {
00237             case DIM_CREATE:
00238                 OnCreate();
00239                 break;
00240 
00241             case DIM_COMMIT:
00242                 OnCommit();
00243                 EndDialog=TRUE;
00244                 break;
00245 
00246             case DIM_CANCEL:
00247                 DialogWasCancelled=TRUE;
00248                 EndDialog = TRUE;
00249                 break;
00250 
00251             case DIM_LFT_BN_CLICKED:
00252                 // A control on the dialog box has been clicked...
00253                 switch (Msg->GadgetID)
00254                 {
00255                     case _R(IDC_IMAGEMAP_AREA_SELECTION):
00256                         OnAreaSelectionClicked();
00257                         break;
00258 
00259                     case _R(IDC_IMAGEMAP_AREA_DRAWING):
00260                         OnAreaDrawingClicked();
00261                         break;
00262                 }
00263                 break;
00264 
00265             case DIM_TEXT_CHANGED:
00266                 // The user has typed in an edit field
00267                 switch (Msg->GadgetID)
00268                 {
00269                     case _R(IDC_IMAGEMAP_WIDTH):
00270                         if (ImagemapDlg::DontHandleNextMessage)
00271                             ImagemapDlg::DontHandleNextMessage=FALSE;
00272                         else
00273                             OnWidthChanged();
00274                         break;
00275 
00276                     case _R(IDC_IMAGEMAP_HEIGHT):
00277                         if (ImagemapDlg::DontHandleNextMessage)
00278                             ImagemapDlg::DontHandleNextMessage=FALSE;
00279                         else
00280                             OnHeightChanged();
00281                         break;
00282                 }
00283                 break;
00284 
00285         }
00286 
00287         //And end the dialog if necessary
00288         if (EndDialog) 
00289         {
00290             Close();        
00291             End();          
00292         }
00293     }
00294 
00295     //Now pass the message down to the base class
00296     return DialogOp::Message(Message); 
00297 }
00298 
00299 /********************************************************************************************
00300 
00301     ImagemapDlg message handling functions
00302 
00303     The following group of functions are called from ImagemapDlg::Message
00304     when a message is received.
00305 
00306     They call other functions which do whatever needs to be done.
00307 
00308 ********************************************************************************************/
00309 
00310 
00311 /********************************************************************************************
00312 
00313     void ImagemapDlg::OnCreate()
00314 
00315     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00316     Created:    10/4/97
00317     Inputs:     -
00318     Outputs:    -
00319     Returns:    -
00320     
00321     Purpose:    Handles a message that the dialog has just been created.
00322 
00323     Errors:     -
00324     SeeAlso:    ImagemapDlg::Message()
00325 
00326 ********************************************************************************************/
00327 
00328 void ImagemapDlg::OnCreate()
00329 {   
00330     //Set up the controls from our ImagemapFilterOptions member variables
00331     SetOptions(ms_Options);
00332 
00333     //Set up our internal member variables
00334     SetMemberVariables(ms_Options);
00335 
00336     //And put the keyboard focus in the Map Name field
00337     SetKeyboardFocus(_R(IDC_IMAGEMAP_MAPNAME));
00338 }
00339 
00340 /********************************************************************************************
00341 
00342     void ImagemapDlg::OnCommit()
00343 
00344     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00345     Created:    10/4/97
00346     Inputs:     -
00347     Outputs:    -
00348     Returns:    -
00349     
00350     Purpose:    Handles a message that the "Export" button has been clicked
00351 
00352     Errors:     -
00353     SeeAlso:    ImagemapDlg::Message()
00354 
00355 ********************************************************************************************/
00356 
00357 void ImagemapDlg::OnCommit()
00358 {   
00359     //Get the values from the dialog box and
00360     //put them into our ImagemapFilterOptions member variable
00361     ms_Options=GetOptions();
00362 }
00363 
00364 /********************************************************************************************
00365 
00366     void ImagemapDlg::OnAreaSelectionClicked()
00367 
00368     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00369     Created:    10/4/97
00370     Inputs:     -
00371     Outputs:    -
00372     Returns:    -
00373     
00374     Purpose:    Handles a message that the "Area for imagemap - Selection" button has
00375                 been clicked.
00376 
00377     Errors:     -
00378     SeeAlso:    ImagemapDlg::Message()
00379 
00380 ********************************************************************************************/
00381 
00382 void ImagemapDlg::OnAreaSelectionClicked()
00383 {   
00384     //Make sure the "Area for imagemap - Drawing" button is off
00385     SetLongGadgetValue(_R(IDC_IMAGEMAP_AREA_DRAWING), FALSE);
00386 
00387     //And set the width and height fields to reflect the width
00388     //and height of the selection scaled by 96 DPI
00389     SetDPI(SELECTION, BMPFilter::GetDefaultExportDPI());
00390 }
00391 
00392 /********************************************************************************************
00393 
00394     void ImagemapDlg::OnAreaDrawingClicked()
00395 
00396     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00397     Created:    10/4/97
00398     Inputs:     -
00399     Outputs:    -
00400     Returns:    -
00401     
00402     Purpose:    Handles a message that the "Area for imagemap - Drawing" button has
00403                 been clicked.
00404 
00405     Errors:     -
00406     SeeAlso:    ImagemapDlg::Message()
00407 
00408 ********************************************************************************************/
00409 
00410 void ImagemapDlg::OnAreaDrawingClicked()
00411 {   
00412     //Make sure the "Area for imagemap - Selection" button is off
00413     SetLongGadgetValue(_R(IDC_IMAGEMAP_AREA_SELECTION), FALSE);
00414 
00415     //And set the width and height fields to reflect the width
00416     //and height of the drawing scaled by 96 DPI
00417     SetDPI(DRAWING, BMPFilter::GetDefaultExportDPI());
00418 }
00419 
00420 /********************************************************************************************
00421 
00422     void ImagemapDlg::OnWidthChanged()
00423 
00424     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00425     Created:    10/4/97
00426     Inputs:     -
00427     Outputs:    -
00428     Returns:    -
00429     
00430     Purpose:    Handles a message that the user has typed in the "Width" field
00431 
00432     Errors:     -
00433     SeeAlso:    ImagemapDlg::Message()
00434 
00435 ********************************************************************************************/
00436 
00437 void ImagemapDlg::OnWidthChanged()
00438 {   
00439     //First we set up a flag to find if the value in the Width field
00440     //is a valid value
00441     BOOL fValid=TRUE;
00442 
00443     //Get the value of the width field and find out the value
00444     //is between 1 and the maximum for a INT32 type
00445     INT32 lWidth = GetLongGadgetValue(_R(IDC_IMAGEMAP_WIDTH), 1, PIXELWIDTH_MAX, NULL ,&fValid);
00446 
00447     //Set the height to zero by default
00448     INT32 lHeight=0;
00449 
00450     //If the width is valid...
00451     if (fValid)
00452     {
00453         //Then get the height by dividing our width by the width height
00454         //ratio, rounding to the nearest integer
00455         lHeight=(INT32) ((lWidth/m_dWidthHeightRatio)+0.5); 
00456     }
00457 
00458     //And set our height into the dialog
00459     ImagemapDlg::DontHandleNextMessage=TRUE;
00460     SetLongGadgetValue(_R(IDC_IMAGEMAP_HEIGHT), lHeight);
00461     
00462 }
00463 
00464 /********************************************************************************************
00465 
00466     void ImagemapDlg::OnHeightChanged()
00467 
00468     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00469     Created:    10/4/97
00470     Inputs:     -
00471     Outputs:    -
00472     Returns:    -
00473     
00474     Purpose:    Handles a message that the user has typed in the "Height" field
00475 
00476     Errors:     -
00477     SeeAlso:    ImagemapDlg::Message()
00478 
00479 ********************************************************************************************/
00480 
00481 void ImagemapDlg::OnHeightChanged()
00482 {   
00483     //First we set up a flag to find if the value in the Height field
00484     //is a valid value
00485     BOOL fValid=TRUE;
00486 
00487     //Get the value of the height field and find out the value
00488     //is between 1 and our maximum pixel width
00489     INT32 lHeight = GetLongGadgetValue(_R(IDC_IMAGEMAP_HEIGHT), 1, PIXELWIDTH_MAX, NULL ,&fValid);
00490 
00491     //Set the width to zero by default
00492     INT32 lWidth=0;
00493 
00494     //If the height is valid...
00495     if (fValid)
00496     {
00497         //Then get the width by multiplying our height by the width height
00498         //ratio, rounding to the nearest integer
00499         lWidth=(INT32) ((lHeight*m_dWidthHeightRatio)+0.5); 
00500     }
00501 
00502     //And set our width into the dialog
00503     ImagemapDlg::DontHandleNextMessage=TRUE;
00504     SetLongGadgetValue(_R(IDC_IMAGEMAP_WIDTH), lWidth);
00505 }
00506 
00507 /********************************************************************************************
00508 
00509     ImagemapDlg toolkit functions
00510 
00511 ********************************************************************************************/
00512 
00513 
00514 /********************************************************************************************
00515 
00516     void ImagemapDlg::SetOptions(ImagemapFilterOptions ifoSet)
00517 
00518     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00519     Created:    10/4/97
00520     Inputs:     ifoSet  The ImagemapFilterOptions to set as current within the dialog
00521     Outputs:    -
00522     Returns:    -
00523     
00524     Purpose:    Sets some ImagemapFilterOptions into the dialog
00525 
00526     Errors:     -
00527     SeeAlso:    ImagemapDlg::Message()
00528 
00529 ********************************************************************************************/
00530 
00531 void ImagemapDlg::SetOptions(ImagemapFilterOptions ifoSet)
00532 {   
00533     //First let's set the options which we should get from ifoSet.
00534     //These are the controls which remember the values which the user set
00535     //for the last export.
00536 
00537     //Set the "save clickable areas as rectangles"
00538     SetLongGadgetValue(_R(IDC_IMAGEMAP_ALLRECTANGLES), ifoSet.m_fAllRectangles);
00539 
00540     //Set the "copy imagemap to clipboard"
00541     SetLongGadgetValue(_R(IDC_IMAGEMAP_CLIPBOARD), ifoSet.m_fClipboard);
00542 
00543     //Set up the "Approximate curves with lines" drop down box
00544     DeleteAllValues(_R(IDC_IMAGEMAP_APPROX));
00545 
00546     SetStringGadgetValue(_R(IDC_IMAGEMAP_APPROX), &String_256(_R(IDS_IMAGEMAP_APPROX_VERYCLOSELY)), FALSE, 0);
00547     SetStringGadgetValue(_R(IDC_IMAGEMAP_APPROX), &String_256(_R(IDS_IMAGEMAP_APPROX_CLOSELY)), FALSE, 1);
00548     SetStringGadgetValue(_R(IDC_IMAGEMAP_APPROX), &String_256(_R(IDS_IMAGEMAP_APPROX_APPROXIMATELY)), FALSE, 2);
00549     SetStringGadgetValue(_R(IDC_IMAGEMAP_APPROX), &String_256(_R(IDS_IMAGEMAP_APPROX_NOTATALL)), FALSE, 3);
00550     
00551     SetComboListLength(_R(IDC_IMAGEMAP_APPROX));
00552 
00553     //And choose the appropriate value
00554     switch (ifoSet.m_ffApprox)
00555     {
00556     case FF_VERYCLOSELY:
00557         SetSelectedValueIndex(_R(IDC_IMAGEMAP_APPROX), 0);
00558         break;
00559 
00560     case FF_CLOSELY:
00561         SetSelectedValueIndex(_R(IDC_IMAGEMAP_APPROX), 1);
00562         break;
00563 
00564     case FF_APPROXIMATELY:
00565         SetSelectedValueIndex(_R(IDC_IMAGEMAP_APPROX), 2);
00566         break;
00567 
00568     default:
00569         ERROR3("ImagemapDlg::SetOptions - invalid flattening factor");
00570     
00571     case FF_NOTATALL:
00572         SetSelectedValueIndex(_R(IDC_IMAGEMAP_APPROX), 3);
00573         break;
00574     
00575         
00576         
00577     }
00578 
00579     //Now, let's set up the remaining controls with default values. These
00580     //controls do not remember their settings between exports
00581 
00582     //The "Map Name" combo box
00583 
00584     //First delete all the values that were previously in this box
00585     DeleteAllValues(_R(IDC_IMAGEMAP_MAPNAME));
00586 
00587     //Have we been passed a list of names to put in the combo box?
00588     if (ms_plstNames)
00589     {
00590         //Yes. So go through them, one by one, putting them into the combo box
00591         StringListItem* psliThis=(StringListItem*) ms_plstNames->GetHead();
00592 
00593         INT32 iListPos=0;
00594 
00595         while (psliThis!=NULL)
00596         {
00597             String_256 strToSet=psliThis->GetString();
00598 
00599             SetStringGadgetValue(_R(IDC_IMAGEMAP_MAPNAME), &strToSet, FALSE, iListPos);
00600 
00601             iListPos++;
00602 
00603             psliThis=(StringListItem*) ms_plstNames->GetNext(psliThis);
00604         }
00605 
00606         //And select the first item
00607         SetSelectedValueIndex(_R(IDC_IMAGEMAP_MAPNAME),0);
00608 
00609     }
00610     else
00611         //No. So simply set a default name into the combo box
00612         SetStringGadgetValue(_R(IDC_IMAGEMAP_MAPNAME), &String_256(_R(IDS_IMAGEMAP_DEFAULTMAPNAME)), FALSE,-1);
00613 
00614 
00615 
00616     SetComboListLength(_R(IDC_IMAGEMAP_MAPNAME));
00617 
00618     //Set the Area For Imagemap radio buttons according to whether there is a selection
00619     //or not
00620     
00621     //Is there a selection?
00622     SelRange* pSelRange=GetApplication()->FindSelection();
00623     
00624     if (pSelRange && !pSelRange->IsEmpty())
00625     {
00626         //Yes. So enable the selection radio button (in case it was disabled before)
00627         EnableGadget(_R(IDC_IMAGEMAP_AREA_SELECTION), TRUE);
00628 
00629         //And select it
00630         SetLongGadgetValue(_R(IDC_IMAGEMAP_AREA_SELECTION), TRUE);
00631         SetLongGadgetValue(_R(IDC_IMAGEMAP_AREA_DRAWING), FALSE);
00632 
00633         //And set the width and height fields to reflect the width
00634         //and height of the selection scaled by 96 DPI
00635         SetDPI(SELECTION, BMPFilter::GetDefaultExportDPI());
00636     }
00637     else
00638     {
00639         //No. So disable the selection radio button
00640         EnableGadget(_R(IDC_IMAGEMAP_AREA_SELECTION), FALSE);
00641 
00642         //And select the drawing radio button
00643         SetLongGadgetValue(_R(IDC_IMAGEMAP_AREA_SELECTION), FALSE);
00644         SetLongGadgetValue(_R(IDC_IMAGEMAP_AREA_DRAWING), TRUE);
00645 
00646         //And set the width and height fields to reflect the width
00647         //and height of the drawing scaled by 96 DPI
00648         SetDPI(DRAWING, BMPFilter::GetDefaultExportDPI());
00649 
00650     }
00651                                     
00652 }
00653 
00654 /********************************************************************************************
00655 
00656     ImagemapFilterOptions ImagemapDlg::GetOptions()
00657 
00658     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00659     Created:    10/4/97
00660     Inputs:     -
00661     Outputs:    The set of Imagemap Filter Options showing in the dialog
00662     Returns:    -
00663     
00664     Purpose:    Gets a set of imagemap filter options from the dialog
00665 
00666     Errors:     -
00667     SeeAlso:    ImagemapDlg::Message()
00668 
00669 ********************************************************************************************/
00670 
00671 ImagemapFilterOptions ImagemapDlg::GetOptions()
00672 {   
00673     //This variable will hold the imagemap filter options to return. Base these options
00674     //on the options we were given
00675     ImagemapFilterOptions ifoGet=ms_Options;
00676 
00677     //Get the map name
00678     ifoGet.m_strName=GetStringGadgetValue(_R(IDC_IMAGEMAP_MAPNAME));
00679 
00680     //Get the "Approximate curves with lines" drop down box
00681     switch (GetSelectedValueIndex(_R(IDC_IMAGEMAP_APPROX)))
00682     {
00683     case 0:
00684         ifoGet.m_ffApprox=FF_VERYCLOSELY;
00685         break;
00686 
00687     case 1:
00688         ifoGet.m_ffApprox=FF_CLOSELY;
00689         break;
00690 
00691     case 2:
00692         ifoGet.m_ffApprox=FF_APPROXIMATELY;
00693         break;
00694 
00695     default:
00696         ERROR3("ImagemapDlg::GetOptions - invalid flattening factor");
00697 
00698     case 3:
00699         ifoGet.m_ffApprox=FF_NOTATALL;
00700         break;
00701 
00702     }
00703 
00704     //Get the Area For Imagemap radio buttons
00705     if (GetLongGadgetValue(_R(IDC_IMAGEMAP_AREA_SELECTION), 0, 1)==1)
00706         ifoGet.m_stExportArea=SELECTION;
00707     else
00708         ifoGet.m_stExportArea=DRAWING;
00709                                                     
00710     //Get the DPI from the Width and Height and the Area For Imagemap
00711     ifoGet.m_dDPI=GetDPI(ifoGet.m_stExportArea);
00712 
00713     //Get the "save clickable areas as rectangles"
00714     ifoGet.m_fAllRectangles=(GetLongGadgetValue(_R(IDC_IMAGEMAP_ALLRECTANGLES), 0, 1)==1);
00715 
00716     //Get the "copy imagemap to clipboard"
00717     ifoGet.m_fClipboard=(GetLongGadgetValue(_R(IDC_IMAGEMAP_CLIPBOARD), 0 ,1)==1);
00718 
00719     //And return our new set of imagemap options
00720     return ifoGet;
00721 }
00722 
00723 /********************************************************************************************
00724 
00725     void ImagemapDlg::SetDPI(SelectionType stExportArea, double dDPI)
00726 
00727     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00728     Created:    11/4/97
00729     Inputs:     stExportArea    The current Area to Export
00730     Outputs:    -
00731     Returns:    -
00732     
00733     Purpose:    Sets the Width and Height fields according to the DPI
00734                 and the Export Area.
00735 
00736     Errors:     -
00737     SeeAlso:    ImagemapDlg::Message()
00738 
00739 ********************************************************************************************/
00740 
00741 void ImagemapDlg::SetDPI(SelectionType stExportArea, double dDPI)
00742 {   
00743     //First we need to get the bounding box of the area to export
00744     DocRect rectBounds=ImagemapFilterOptions::GetSizeOfExportArea(stExportArea);
00745 
00746     //And scale it by the DPI we have been given. The easiest
00747     //way to do this is to use this function
00748     Matrix Identity;
00749     WinRect Rect = OSRenderRegion::BitmapDocRectToWin( Identity, rectBounds, dDPI );
00750 
00751     //Then set the result into the width and height fields
00752     ImagemapDlg::DontHandleNextMessage=TRUE;
00753     SetLongGadgetValue(_R(IDC_IMAGEMAP_WIDTH), Rect.Width());
00754 
00755     ImagemapDlg::DontHandleNextMessage=TRUE;
00756     SetLongGadgetValue(_R(IDC_IMAGEMAP_HEIGHT), Rect.Height());
00757 }
00758 
00759 /********************************************************************************************
00760 
00761     double ImagemapDlg::GetDPI(SelectionType stExportArea)
00762 
00763     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00764     Created:    11/4/97
00765     Inputs:     -
00766     Outputs:    -
00767     Returns:    The DPI based on the Width and Height fields
00768                 and the export area
00769     
00770     Purpose:    Gets the DPI as shown in the dialog box by the Width
00771                 and Height fields.
00772 
00773     Errors:     -
00774     SeeAlso:    ImagemapDlg::Message()
00775 
00776 ********************************************************************************************/
00777 
00778 double ImagemapDlg::GetDPI(SelectionType stExportArea)
00779 {   
00780     //This variable will hold the value to return
00781     //It is 96 by default
00782     double dDPI=BMPFilter::GetDefaultExportDPI();
00783 
00784     //First we need to get the bounding box of the area to export
00785     DocRect rectBounds=ImagemapFilterOptions::GetSizeOfExportArea(stExportArea);
00786 
00787     //So, get the width of the area to export in millipoints
00788     INT32 lMillipointWidth=rectBounds.Width();
00789 
00790     //Now get the value of the width fields, which will be
00791     //the width of the area to export in pixels
00792     INT32 lPixelWidth=GetLongGadgetValue(_R(IDC_IMAGEMAP_WIDTH), rectBounds.Width(), -INT32_MAX, INT32_MAX);
00793 
00794     //Is the width in pixels greater than zero?
00795     if (lPixelWidth>0)
00796     {
00797         //Yes. So get the DPI from the ratio between the pixel height and the pixel width,
00798         //rounded upwards
00799         dDPI=((double) lPixelWidth * 72000.0)/((double) lMillipointWidth);
00800 
00801         //Is that DPI within reasonable bounds?
00802         if (dDPI<0)
00803             dDPI=BMPFilter::GetDefaultExportDPI();
00804 
00805     }
00806 
00807     //And return that value
00808     return dDPI;
00809 }
00810 
00811 /********************************************************************************************
00812 
00813     void ImagemapDlg::SetMemberVariables(ImagemapFilterOptions ifoOptions)
00814 
00815     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00816     Created:    11/4/97
00817     Inputs:     ifoOptions - a set of ImagemapFilterOptions
00818     Outputs:    -
00819     Returns:    -
00820     
00821     Purpose:    Sets up our internal member variables based on the contents
00822                 of ifoOptions.
00823 
00824                 At the moment, this function only sets the width/height ratio
00825                 member variable (which contains the ratio of the width and
00826                 height of the export area).
00827 
00828     Errors:     -
00829     SeeAlso:    ImagemapDlg::Message()
00830 
00831 ********************************************************************************************/
00832 
00833 void ImagemapDlg::SetMemberVariables(ImagemapFilterOptions ifoOptions)
00834 {   
00835     //Get the size of the area to export
00836     DocRect rectExportSize=ImagemapFilterOptions::GetSizeOfExportArea(ifoOptions.m_stExportArea);
00837 
00838     //Then get the ratio of its width and height
00839     m_dWidthHeightRatio=((double) rectExportSize.Width())/((double) rectExportSize.Height());
00840 }
00841 
00842 
00843 
00844 
00845 
00846 
00847 
00848 /******************************************************************************************
00849 
00850 >   static OpState  ImagemapDlg::GetState(String_256*, OpDescriptor*)
00851 
00852     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00853     Created:    10/4/97
00854     Inputs:     -
00855     Outputs:    -
00856     Returns:    -
00857     Purpose:    ImagemapDlg GetState method
00858     Errors:     -
00859     SeeAlso:    -
00860 
00861 ******************************************************************************************/
00862 
00863 OpState ImagemapDlg::GetState(String_256*, OpDescriptor*)
00864 {    
00865     OpState OpSt;
00866     return(OpSt);
00867 }
00868 
00869 
00870 
00871 
00872 /******************************************************************************************
00873 
00874 >   BOOL ImagemapDlg::Init()
00875 
00876     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00877     Created:    10/4/97
00878     Inputs:     -
00879     Outputs:    -
00880     Returns:    -
00881     Purpose:    ImagemapDlg Init method
00882     Errors:     -
00883     SeeAlso:    -
00884 
00885 ******************************************************************************************/
00886 
00887 BOOL ImagemapDlg::Init()
00888 {
00889     BOOL InitOK;
00890 
00891     InitOK = RegisterOpDescriptor(
00892                                 0,                  /* Tool ID */
00893                                 _R(IDS_IMAGEMAPDLG),
00894                                 CC_RUNTIME_CLASS(ImagemapDlg),
00895                                 OPTOKEN_IMAGEMAPDLG,
00896                                 GetState,
00897                                 _R(IDH_Dialog_Image_Map_Export_Options), /* help ID */
00898                                 0,                  /* bubble help */
00899                                 0,                  /* resource ID */
00900                                 0                   /* control ID */
00901                                 );
00902 
00903     return (InitOK);
00904 }
00905 
00906 
00907 /******************************************************************************************
00908 
00909 >   void ImagemapDlg::Do(OpDescriptor*)
00910 
00911     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00912     Created:    11/4/97
00913     Inputs:     -
00914     Outputs:    -
00915     Returns:    -
00916     Purpose:    Creates then opens the dialog in response to a request from the user.
00917     Errors:     -
00918     SeeAlso:    -
00919 
00920 ******************************************************************************************/
00921 
00922 void ImagemapDlg::Do(OpDescriptor*)
00923 {
00924     BOOL ok;
00925     
00926     // Force the dialog box to be created, as it is modal it will be opened via a message
00927     ok = Create();
00928 
00929     if ( !ok )
00930     {
00931         // Could not create the dialog box so call inform error 
00932         InformError();
00933         End();      
00934     }
00935 }
00936 
00937 /******************************************************************************************
00938 
00939 >   void ImagemapDlg::DoWithParam(OpDescriptor*)
00940 
00941     Author:     Graham_Walmsley (Xara Group Ltd) <camelotdev@xara.com>
00942     Created:    11/4/97
00943     Inputs:     -
00944     Outputs:    -
00945     Returns:    -
00946     Purpose:    Creates then opens the dialog in response to a request from the user and
00947                 allows values to be passed in and returned to the caller via the
00948                 ImagemapDlgParam class.
00949     Errors:     -
00950     SeeAlso:    -
00951 
00952 ******************************************************************************************/
00953 
00954 void ImagemapDlg::DoWithParam(OpDescriptor*, OpParam* Param)
00955 {
00956     BOOL ok;
00957     
00958     // Force the dialog box to be created, as it is modal it will be opened via a message
00959     ok = Create();
00960 
00961     if ( !ok )
00962     {
00963         // Could not create the dialog box so call inform error 
00964         InformError();
00965         End();         // End the operation 
00966     }
00967 }

Generated on Sat Nov 10 03:45:19 2007 for Camelot by  doxygen 1.4.4