xarprefs.cpp

Go to the documentation of this file.
00001 // $Id: xarprefs.cpp 1328 2006-06-15 19:23:45Z alex $
00002 // XarPrefs.cpp
00003 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00004 ================================XARAHEADERSTART===========================
00005  
00006                Xara LX, a vector drawing and manipulation program.
00007                     Copyright (C) 1993-2006 Xara Group Ltd.
00008        Copyright on certain contributions may be held in joint with their
00009               respective authors. See AUTHORS file for details.
00010 
00011 LICENSE TO USE AND MODIFY SOFTWARE
00012 ----------------------------------
00013 
00014 This file is part of Xara LX.
00015 
00016 Xara LX is free software; you can redistribute it and/or modify it
00017 under the terms of the GNU General Public License version 2 as published
00018 by the Free Software Foundation.
00019 
00020 Xara LX and its component source files are distributed in the hope
00021 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00022 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00023 See the GNU General Public License for more details.
00024 
00025 You should have received a copy of the GNU General Public License along
00026 with Xara LX (see the file GPL in the root directory of the
00027 distribution); if not, write to the Free Software Foundation, Inc., 51
00028 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00029 
00030 
00031 ADDITIONAL RIGHTS
00032 -----------------
00033 
00034 Conditional upon your continuing compliance with the GNU General Public
00035 License described above, Xara Group Ltd grants to you certain additional
00036 rights. 
00037 
00038 The additional rights are to use, modify, and distribute the software
00039 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00040 library and any other such library that any version of Xara LX relased
00041 by Xara Group Ltd requires in order to compile and execute, including
00042 the static linking of that library to XaraLX. In the case of the
00043 "CDraw" library, you may satisfy obligation under the GNU General Public
00044 License to provide source code by providing a binary copy of the library
00045 concerned and a copy of the license accompanying it.
00046 
00047 Nothing in this section restricts any of the rights you have under
00048 the GNU General Public License.
00049 
00050 
00051 SCOPE OF LICENSE
00052 ----------------
00053 
00054 This license applies to this program (XaraLX) and its constituent source
00055 files only, and does not necessarily apply to other Xara products which may
00056 in part share the same code base, and are subject to their own licensing
00057 terms.
00058 
00059 This license does not apply to files in the wxXtra directory, which
00060 are built into a separate library, and are subject to the wxWindows
00061 license contained within that directory in the file "WXXTRA-LICENSE".
00062 
00063 This license does not apply to the binary libraries (if any) within
00064 the "libs" directory, which are subject to a separate license contained
00065 within that directory in the file "LIBS-LICENSE".
00066 
00067 
00068 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00069 ----------------------------------------------
00070 
00071 Subject to the terms of the GNU Public License (see above), you are
00072 free to do whatever you like with your modifications. However, you may
00073 (at your option) wish contribute them to Xara's source tree. You can
00074 find details of how to do this at:
00075   http://www.xaraxtreme.org/developers/
00076 
00077 Prior to contributing your modifications, you will need to complete our
00078 contributor agreement. This can be found at:
00079   http://www.xaraxtreme.org/developers/contribute/
00080 
00081 Please note that Xara will not accept modifications which modify any of
00082 the text between the start and end of this header (marked
00083 XARAHEADERSTART and XARAHEADEREND).
00084 
00085 
00086 MARKS
00087 -----
00088 
00089 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00090 designs are registered or unregistered trademarks, design-marks, and/or
00091 service marks of Xara Group Ltd. All rights in these marks are reserved.
00092 
00093 
00094       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00095                         http://www.xara.com/
00096 
00097 =================================XARAHEADEREND============================
00098  */
00099 
00100 /*
00101 */
00102 
00103 //
00104 // This file implements the dialogue box that allows the user to set the export native file
00105 // preferences.
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 
00113 #include "webparam.h"
00114 //#include "xardlg.h"
00115 #include "xarprefs.h"
00116 //#include "filtrres.h" // _R(IDS_NativePrefsDlg)
00117 
00118 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00119 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00120 //#include "dlgtypes.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00121 //#include "resource.h"
00122 
00123 //#include "dialogop.h" // DialogOp header - in camtypes.h [AUTOMATICALLY REMOVED]
00124 #include "dlgmgr.h"     // Dialogue manager class
00125 //#include "msg.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00126      
00127 // This is not compulsory, but you may as well put it in so that the correct version
00128 // of your file can be registered in the .exe
00129 DECLARE_SOURCE("$Revision: 1328 $");
00130 
00131 // An implement to match the Declare in the .h file.
00132 CC_IMPLEMENT_DYNCREATE ( NativePrefsDlg, DialogOp )
00133 
00134 // This is necessary to persuade the compiler that we are calling the correct constructor.
00135 const CDlgResID NativeID = _R(IDD_EXPORTNATIVEOPTS);
00136 
00137 // This will get Camelot to display the filename and linenumber of any memory allocations
00138 // that are not released at program exit
00139 #define new CAM_DEBUG_NEW
00140 
00141 /******************************************************************************************
00142 
00143 >   NativePrefsDlg::NativePrefsDlg() : DialogOp ( _R(IDD_EXPORTNATIVEOPTS), MODAL )
00144 
00145     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00146     Created:    1/5/96
00147     Inputs:     -
00148     Outputs:    -
00149     Returns:    -
00150     Purpose:    NativePrefsDlg constructor. Creates a non-undoable operation
00151     Errors:     -
00152     SeeAlso:    -
00153 
00154 ******************************************************************************************/
00155 
00156 NativePrefsDlg::NativePrefsDlg () : DialogOp ( NativeID, MODAL )
00157 {
00158     // The base class does all the work.
00159 }
00160 
00161 /******************************************************************************************
00162 
00163 >   NativePrefsDlg::~NativePrefsDlg()
00164 
00165     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00166     Created:    28/03/2006
00167     Inputs:     -
00168     Outputs:    -
00169     Returns:    -
00170     Purpose:    NativePrefsDlg destructor.
00171     Errors:     -
00172     SeeAlso:    -
00173 
00174 ******************************************************************************************/
00175 
00176 NativePrefsDlg::~NativePrefsDlg ()
00177 {
00178     // The base class does all the work.
00179 }
00180 
00181 /******************************************************************************************
00182 
00183 >   NativePrefsDlg::NativePrefsDlg ( CDlgResID IDD )
00184 
00185     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00186     Created:    25/10/00
00187     Inputs:     IDD - The ID of the dialogue being created.
00188     Purpose:    NativePrefsDlg constructor. Creates a non-undoable operation
00189 
00190 ******************************************************************************************/
00191 
00192 NativePrefsDlg::NativePrefsDlg ( CDlgResID IDD ) : DialogOp ( IDD, MODAL )
00193 {
00194     // The base class does all the work.
00195 }
00196 
00197 /******************************************************************************************
00198 
00199 >   void NativePrefsDlg::DoWithParam(OpDescriptor*)
00200 
00201     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00202     Created:    1/5/96
00203     Inputs:     -
00204     Outputs:    -
00205     Returns:    -
00206     Purpose:    Creates then opens the dialog in response to a request from the user and
00207                 allows values to be passed in and returned to the caller via the
00208                 WebPrefsDlgParam class.
00209     Errors:     -
00210     SeeAlso:    -
00211 
00212 ******************************************************************************************/
00213 
00214 void NativePrefsDlg::DoWithParam(OpDescriptor*, OpParam* Param)
00215 {
00216     ERROR3IF(Param == NULL, "NativePrefsDlg::DoWithParam - NULL Param passed in");
00217 
00218     // Use the OpParam that has been passed in to us
00219     mpParams = (WebPrefsDlgParam *) Param;
00220 
00221     // Call the Do function to finish the job off.
00222     Do ( NULL );
00223 }
00224 
00225 /******************************************************************************************
00226 
00227 >   void NativePrefsDlg::Do(OpDescriptor*)
00228 
00229     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00230     Created:    1/5/96
00231     Inputs:     -
00232     Outputs:    -
00233     Returns:    -
00234     Purpose:    Creates then opens the dialog in response to a request from the user.
00235     Errors:     -
00236     SeeAlso:    -
00237 
00238 ******************************************************************************************/
00239 
00240 void NativePrefsDlg::Do ( OpDescriptor* )
00241 {
00242     BOOL ok;
00243     
00244     // Force the dialog box to be created, as it is modal it will be opened via a message
00245     ok = Create();
00246 
00247     if ( !ok )
00248     {
00249         // Could not create the dialog box so call inform error 
00250         InformError();
00251         End();         // End the operation 
00252     }
00253 }
00254 /******************************************************************************************
00255 
00256 >   BOOL NativePrefsDlg::Init()
00257 
00258     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00259     Created:    1/5/96
00260     Inputs:     -
00261     Outputs:    -
00262     Returns:    -
00263     Purpose:    NativePrefsDlg Init method
00264     Errors:     -
00265     SeeAlso:    -
00266 
00267 ******************************************************************************************/
00268 
00269 BOOL NativePrefsDlg::Init()
00270 {
00271     BOOL InitOK;
00272 
00273     InitOK = RegisterOpDescriptor(
00274                                 0,                  /* Tool ID */
00275                                 _R(IDS_NATIVEPREFSDLG),
00276                                 CC_RUNTIME_CLASS ( NativePrefsDlg ),
00277                                 OPTOKEN_NATIVEPREFSDLG,
00278                                 GetState,
00279                                 0,                  /* help ID */
00280                                 0,                  /* bubble help */
00281                                 0,                  /* resource ID */
00282                                 0                   /* control ID */
00283                                 );
00284 
00285     return (InitOK);
00286 }
00287 
00288 /********************************************************************************************
00289 
00290 >   BOOL NativePrefsDlg::Create()
00291 
00292     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00293     Created:    1/5/96
00294     Inputs:     -
00295     Outputs:    -
00296     Returns:    TRUE if successful, else FALSE
00297     Purpose:    NativePrefsDlg create method 
00298     Errors:     -
00299     SeeAlso:    -
00300 
00301 ********************************************************************************************/
00302        
00303 BOOL NativePrefsDlg::Create ()
00304 {                     
00305     // Pass the responsibility to the baseclass.
00306     return DialogOp::Create ();
00307 }
00308 
00309 /******************************************************************************************
00310 
00311 >   static OpState  NativePrefsDlg::GetState(String_256*, OpDescriptor*)
00312 
00313     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00314     Created:    1/5/96
00315     Inputs:     -
00316     Outputs:    -
00317     Returns:    -
00318     Purpose:    NativePrefsDlg GetState method
00319     Errors:     -
00320     SeeAlso:    -
00321 
00322 ******************************************************************************************/
00323 
00324 OpState NativePrefsDlg::GetState(String_256*, OpDescriptor*)
00325 {    
00326     OpState OpSt;
00327     return(OpSt);
00328 }
00329 
00330 /******************************************************************************************
00331 
00332 >   MsgResult NativePrefsDlg::Message(CDlgMessage DlgMsg, CGadgetID Gadget) 
00333 
00334     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00335     Created:    1/5/96
00336     Inputs:     -
00337     Outputs:    -
00338     Returns:    -
00339     Purpose:    Handles all the web preferences dialog's messages
00340     Errors:     -
00341     SeeAlso:    -
00342 
00343 ******************************************************************************************/
00344 
00345 MsgResult NativePrefsDlg::Message(Msg* Message)
00346 {
00347     if (IS_OUR_DIALOG_MSG(Message) && mpParams)
00348     {
00349         DialogMsg* Msg = (DialogMsg*)Message;
00350 
00351         MsgResult Result;
00352 
00353         // Should now handle the required messages that we respond to
00354         switch (Msg->DlgMsg)
00355         {
00356             case DIM_CREATE:
00357                 {
00358                     InitDialog();
00359                 }
00360             break;
00361 
00362             case DIM_COMMIT:
00363                 {
00364                     // (ok) accept all changes that the user has made to the settings
00365                     // brackets make the ok local to this case 
00366                     BOOL ok;
00367                     ok = CommitDialogValues ();
00368                     if (ok)
00369                     {
00370                         // Values found ok so quit dialogue then go ahead and export
00371                         if ( mpParams != NULL )
00372                         {
00373                             mpParams->SetWebOk( TRUE ); // Flag ok used.
00374                         }
00375                         else
00376                         {
00377                             ERROR3 ( "mpParams is not set!" );
00378                         }
00379 
00380                     }
00381                 }
00382             break;
00383 
00384             case DIM_CANCEL:
00385                 // Cancel all changes that the user has made to the settings
00386                 if ( mpParams != NULL )
00387                 {
00388                     mpParams->SetWebOk(FALSE);          // Flag cancel used
00389                 }
00390                 else
00391                 {
00392                     ERROR3 ( "mpParams is not set!" );
00393                 }
00394 
00395             break;
00396 
00397             default:
00398                 break;
00399         }
00400 
00401         // Allow the base class access to the message, it will do the
00402         // DLG_EAT_IF_HUNGRY(Msg) for us
00403         // Must do this before the Close and End
00404         Result = DialogOp::Message ( Message );
00405 
00406         // The message was for our dialog box so return that we have handled it, if necessary
00407         return Result;
00408     }
00409 
00410     return DialogOp::Message(Message); 
00411 }
00412 
00413 /******************************************************************************************
00414 
00415 >   SelectionType NativePrefsDlg::GetExportSelection ( UINT32 ControlID )
00416 
00417     Author:     Graeme_Sutherland (Xara Group Ltd) <camelotdev@xara.com>
00418     Created:    24/10/00
00419     Inputs:     ControlID       - The ID number of the control being examined.
00420     Returns:    SelectionType   - (DRAWING or SELECTION) Whether to export the entire
00421                                   drawing, or just the selected parts.
00422     Purpose:    Works out what the current export selection state is.
00423 
00424 ******************************************************************************************/
00425 
00426 SelectionType NativePrefsDlg::GetExportSelection ( UINT32 ControlID )
00427 {
00428     // If the dialogue box has had the "Drawing" selection chosen, this function will
00429     // return TRUE, which, in turn, will cause this method to return DRAWING.
00430     BOOL IsValid = FALSE;
00431 
00432     if ( GetLongGadgetValue ( ControlID, 0, 1, 0, &IsValid ) )
00433     {
00434         return DRAWING;
00435     }
00436     else
00437     {
00438         return SELECTION;
00439     }
00440 }   
00441 
00442 /******************************************************************************************
00443 
00444 >   BOOL NativePrefsDlg::CommitDialogValues ()
00445 
00446     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00447     Created:    1/5/96
00448     Inputs:     pointer to the dialogue box
00449     Outputs:    -
00450     Returns:    True if values in dialog box ok, False otherwise.     
00451     Purpose:    Takes the values in the dialog box and sets the return values accordingly
00452                 Called when ok is pressed on the dialog box.
00453     Errors:     -
00454     SeeAlso:    NativePrefsDlg::CommitDialogValues;
00455 
00456 ******************************************************************************************/
00457 
00458 BOOL NativePrefsDlg::CommitDialogValues ()
00459 {
00460     ERROR2IF(mpParams == NULL, FALSE, "NativePrefsDlg::CommitDialogValues called after duff initialisation?!");
00461 
00462     // What export selection has been made?
00463     mpParams->SetExportSel ( GetExportSelection ( _R(IDC_NATIVEOPTS_DRAWING) ) );  
00464 
00465     return TRUE;
00466 }
00467 
00468 /******************************************************************************************
00469 
00470 >   BOOL NativePrefsDlg::InitDialog(NativePrefsDlg* pWebPrefs)
00471 
00472     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00473     Created:    1/5/96
00474     Inputs:     pointer to the dialog box
00475     Outputs:    -
00476     Returns:    TRUE if successful, else FALSE
00477     Purpose:    Sets initial dialog values 
00478     Errors:     -
00479     SeeAlso:    -
00480 
00481 ******************************************************************************************/
00482 
00483 BOOL NativePrefsDlg::InitDialog ()
00484 {
00485     ERROR2IF ( mpParams == NULL, FALSE,
00486                "NativePrefsDlg::InitDialog called after duff initialisation?!" );
00487 
00488     //First, do we have a selection?
00489     Application *pApp = GetApplication();
00490 
00491     ERROR2IF(pApp == NULL, FALSE,"NativePrefsDlg::InitDialog -  no application!");
00492     
00493     SelRange *pRange = pApp->FindSelection();
00494     
00495     ERROR2IF(pRange == NULL, FALSE,"NativePrefsDlg::InitDialog - no selection range!");
00496     DocRect ClipRect = pRange->GetBoundingRect();
00497 
00498     BOOL fThereIsASelection=!ClipRect.IsEmpty();
00499 
00500     //Now, is there a selection?
00501     if (fThereIsASelection)
00502     {
00503         // Yes. So ungrey both the buttons for selecting the nodes to export.
00504         EnableGadget(_R(IDC_NATIVEOPTS_SELECT), TRUE);
00505         EnableGadget(_R(IDC_NATIVEOPTS_DRAWING), TRUE);
00506 
00507         //Now, which of those buttons should be selected?
00508         switch ( mpParams->GetExportSel () )
00509         {
00510         case SELECTION:
00511             // Choose the export pair of buttons.
00512             SetLongGadgetValue(_R(IDC_NATIVEOPTS_SELECT), FALSE);
00513             SetLongGadgetValue(_R(IDC_NATIVEOPTS_DRAWING), TRUE);
00514             break;
00515 
00516         default:
00517         case DRAWING:
00518             // Choose the export pair of buttons.
00519             SetLongGadgetValue(_R(IDC_NATIVEOPTS_SELECT), TRUE);
00520             SetLongGadgetValue(_R(IDC_NATIVEOPTS_DRAWING), FALSE);
00521             break;
00522         }
00523     }
00524     else
00525     {
00526         //No. So grey the SELECTION button and ungrey
00527         //the DRAWING button
00528         EnableGadget(_R(IDC_NATIVEOPTS_SELECT), FALSE);
00529         EnableGadget(_R(IDC_NATIVEOPTS_DRAWING), TRUE);
00530 
00531         // And we must select the DRAWING button for the export area controls.
00532         SetLongGadgetValue(_R(IDC_NATIVEOPTS_SELECT), TRUE);
00533         SetLongGadgetValue(_R(IDC_NATIVEOPTS_DRAWING), FALSE);
00534     }
00535 
00536     return TRUE;
00537 }
00538 

Generated on Sat Nov 10 03:47:23 2007 for Camelot by  doxygen 1.4.4