optstune.cpp

Go to the documentation of this file.
00001 // $Id: optstune.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 // Implementation of the Tuneups tab of the options dialog box
00100 
00101 /*
00102 
00103 */
00104 
00105 #include "camtypes.h"
00106 //WEBSTER-ranbirr-13/11/96
00107 #ifndef WEBSTER
00108 #include "appprefs.h"
00109 //#include "prefsdlg.h" // dialog/gadget ids
00110 //#include "optsres.h"  // error strings
00111 #include "optstune.h"
00112 //#include "app.h"      // Camelot object - in camtypes.h [AUTOMATICALLY REMOVED]
00113 //#include "units.h"        // units - in camtypes.h [AUTOMATICALLY REMOVED]
00114 //#include "convert.h"  // BytesToString and StringToBytes - in camtypes.h [AUTOMATICALLY REMOVED]
00115 //#include "thumb.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00116 #include "tunemem.h"
00117 //#include "resource.h" // Needs _R(IDS_OK) for InformWarning
00118 //#include "justin2.h"
00119 #include "ophist.h"
00120 
00121 CC_IMPLEMENT_DYNAMIC(TuneTab, OptionsTabs)   
00122 
00123 // This is not compulsory, but you may as well put it in so that the correct version
00124 // of your file can be registered in the .exe
00125 DECLARE_SOURCE("$Revision: 1282 $");
00126 
00127 /* The range of the values allowed in the TuneUps Temporary Workspace field */
00128 #define MAX_TUNEUPS_MEMORY  0x7fff*1024
00129 #define MIN_TUNEUPS_MEMORY  0
00130               
00131 /********************************************************************************************
00132 
00133 >   TuneTab::TuneTab() 
00134 
00135 
00136     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00137     Created:    19/01/95
00138     Inputs:     -   
00139     Outputs:    -
00140     Returns:    -
00141     Purpose:    TuneTab constructor. Creates a non-undoable operation
00142     Errors:     -
00143     SeeAlso:    -
00144 
00145 ********************************************************************************************/
00146 
00147 TuneTab::TuneTab()
00148 {   
00149     // does nothing at present
00150 }            
00151 
00152 /********************************************************************************************
00153 
00154 >   TuneTab::~TuneTab()
00155 
00156 
00157     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00158     Created:    19/01/95
00159     Inputs:     -
00160     Outputs:    -
00161     Returns:    -
00162     Purpose:    TuneTab destructor
00163     Errors:     -
00164     SeeAlso:    -
00165 
00166 ********************************************************************************************/
00167                                                                                 
00168 TuneTab::~TuneTab()
00169 {   
00170 }        
00171 
00172 /********************************************************************************************
00173 
00174 >   BOOL TuneTab::Init()
00175 
00176 
00177     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00178     Created:    19/01/95
00179     Inputs:     -
00180     Outputs:    -
00181     Returns:    True if initialised ok, False if failed.
00182     Purpose:    TuneTab initialisation routine
00183     Errors:     -
00184     SeeAlso:    -
00185 
00186 ********************************************************************************************/
00187                                                                                 
00188 BOOL TuneTab::Init()
00189 {   
00190     CurrentTempMemValue=0;
00191     return TRUE;
00192 }        
00193 
00194 /******************************************************************************************
00195 
00196 >   CDlgResID TuneTab::GetPageID()()
00197 
00198     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00199     Created:    19/01/95
00200     Inputs:     -
00201     Outputs:    -
00202     Returns:    The dialog ID of this tab section.    
00203     Purpose:    Allows the options dialog code to determine the dialog ID of this section.
00204     Errors:     -
00205     SeeAlso:    -
00206 
00207 ******************************************************************************************/
00208 
00209 CDlgResID TuneTab::GetPageID()
00210 {
00211     return _R(IDD_OPTSTAB_TUNE);
00212 }
00213 
00214 /******************************************************************************************
00215 
00216 >   BOOL TuneTab::IsDocumentOption()
00217 
00218     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00219     Created:    19/01/95
00220     Inputs:     -
00221     Outputs:    Sound
00222     Returns:    Returns True if this tab is a document option.    
00223     Purpose:    Allows the document options dialog code to determine if this tab belongs
00224                 to the group of document options.
00225     Errors:     -
00226     SeeAlso:    IsProgramOption();
00227 
00228 ******************************************************************************************/
00229 
00230 BOOL TuneTab::IsDocumentOption()
00231 {
00232     return FALSE;   // This tab is not a document option 
00233 }
00234 
00235 /******************************************************************************************
00236 
00237 >   BOOL TuneTab::IsProgramOption()
00238 
00239     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00240     Created:    19/01/95
00241     Inputs:     -
00242     Outputs:    -
00243     Returns:    Returns True if this tab is a program option.     
00244     Purpose:    Allows the program options dialog code to determine if this tab belongs
00245                 to the group of program options.
00246     Errors:     -
00247     SeeAlso:    IsProgramOption();
00248 
00249 ******************************************************************************************/
00250 
00251 BOOL TuneTab::IsProgramOption()
00252 {
00253     return TRUE;    // This tab is a program option 
00254 }
00255 
00256 /******************************************************************************************
00257 
00258 >   BOOL TuneTab::CommitRenderingSection()
00259 
00260     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00261     Created:    19/1/95
00262     Inputs:     -
00263     Outputs:    -
00264     Returns:    True if values in dialog box ok, False otherwise.     
00265     Purpose:    Takes the values in the Tuneups section tab of the options dialog box and
00266                 sets the associated preference values accordingly
00267                 Called when ok is pressed on the dialog box.
00268     Errors:     -
00269     SeeAlso:    -
00270 
00271 ******************************************************************************************/
00272 
00273 BOOL TuneTab::CommitRenderingSection()
00274 {
00275 TRACEUSER( "Neville", _T("TuneTab::CommitRenderingSection\n"));
00276     ERROR2IF(pPrefsDlg == NULL,FALSE,"TuneTab::CommitRenderingSection called with no dialog pointer");
00277 
00278     // Ok has been pressed so take the values from this section of the dialog box
00279     BOOL Valid=FALSE;           // Flag for validity of value
00280 //  BOOL SetOk=TRUE;            // Preference value set ok
00281 //  BOOL ReadOk=TRUE;           // Value read ok from gadget
00282 
00283     // Now the maximum temporary memory available to Gdraw for rendering purposes
00284     UINT32 TempWorkMem = 0;     // Working memory value in bytes
00285 
00286     // Now read the state of the use maximum memory switch, if on then set TempWorkMemory to 0
00287     BOOL UseMaximumMemory = pPrefsDlg->GetLongGadgetValue(_R(IDC_OPTS_USEMAXMEMORY), 0, 1, 0, &Valid);
00288 
00289     // If we actually got a value out of it, set the flag
00290     if (Valid)
00291         TunedMemory::SetMemSizeInfinte(UseMaximumMemory);
00292 
00293 
00294     if (Valid && !UseMaximumMemory)
00295     {
00296         // Use the specified maximum memory value so get the string from the editable field
00297         TempWorkMem = pPrefsDlg->GetMemoryGadgetValue(_R(IDC_OPTS_TEMPWORKMEM),
00298                                                       MIN_TUNEUPS_MEMORY, MAX_TUNEUPS_MEMORY,
00299                                                       _R(IDE_OPTS_BADTEMPWORKMEM), &Valid); 
00300 
00301         // If it is valid, then set the Limited memory manager up
00302         if (Valid)
00303         {
00304             // Set the actual GDraw memory values
00305             INT32 ActualTempWorkMem = TunedMemory::SetLimitedMemSize((INT32)TempWorkMem);
00306 
00307             // If returned value is not the same as the value we gave then there is a
00308             // problem wiht it, we should warn the user and show them this new value as
00309             // a good one ot be using.
00310             if (ActualTempWorkMem != (INT32)TempWorkMem)
00311             {
00312                 // Put this new value in as a hint to the user.
00313                 pPrefsDlg->SetMemoryGadgetValue(_R(IDC_OPTS_TEMPWORKMEM), ActualTempWorkMem);
00314                 // Scold the user and tell them about the value we have placed there.
00315                 String_256 WarnMsg(_R(IDE_OPTS_BADTEMPWORKMEM));    // Invalid value
00316                 WarnMsg += String_32(_R(IDE_OPTS_MINIMUMALLOWED));  // The minimum allowed is 
00317                 String_256 MinAmount;                           // Make a string of the min value
00318                 Convert::BytesToString(&MinAmount, ActualTempWorkMem);
00319                 WarnMsg += MinAmount;
00320                 Error::SetError(0, WarnMsg, 0);
00321                 InformWarning(0, _R(IDS_OK));
00322                 // Make sure we stop the box being oked.
00323                 Valid = FALSE;
00324             }
00325         }
00326     }
00327 
00328     // Something is not as it should be
00329     if (!Valid)
00330         return FALSE;
00331 
00332     // return happy
00333     return TRUE;
00334 }
00335                
00336 /******************************************************************************************
00337 
00338 >   BOOL UndoTab::CommitUndoSection()
00339 
00340     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00341     Created:    20/1/95
00342     Inputs:     -
00343     Outputs:    -
00344     Returns:    True if values in dialog box ok, False otherwise.     
00345     Purpose:    Takes the values in the Undo section tab of the options dialog box and
00346                 sets the associated preference values accordingly
00347                 Called when ok is pressed on the dialog box.
00348     Errors:     -
00349     SeeAlso:    -
00350 
00351 ******************************************************************************************/
00352 
00353 BOOL TuneTab::CommitUndoSection()
00354 {
00355 TRACEUSER( "Neville", _T("TuneTab::CommitUndoSection\n"));
00356     ERROR3IF(pPrefsDlg == NULL, "TuneTab::CommitUndoSection called with no dialog pointer");
00357 
00358     // Ok has been pressed so take the values from this section of the dialog box
00359     BOOL Valid=TRUE;        // Flag for validity of value
00360 //  BOOL State=FALSE;       // Flag for state of button/switch
00361     BOOL SetOk=TRUE;        // Preference value set ok
00362 
00363     // Section = Undo settings
00364 
00365     // Get the currently selected document
00366     Document* pDocument = Document::GetSelected();
00367     if (pDocument != NULL)
00368     {
00369         // Getthe current undo size
00370         UINT32 CurrentSize = pDocument->GetOpHistory().GetSize();
00371         UINT32 CurrentMaxSize = pDocument->GetOpHistory().GetMaxSize();
00372 
00373         // Now read the state of the use maximum memory switch, if on then set TempWorkMemory to 0
00374         BOOL Unlimited = pPrefsDlg->GetLongGadgetValue(_R(IDC_OPTS_UNLIMITEDUNDO), 0, 1, 0, &Valid);
00375 
00376         UINT32 NewMaxUndoSize;
00377         if (Unlimited)
00378         {
00379             // Use the maximum possible value
00380             NewMaxUndoSize = UINT32_MAX;
00381         }
00382         else
00383         {
00384             // Read the value from the editable field limiting the values in the process
00385             NewMaxUndoSize = pPrefsDlg->GetMemoryGadgetValue(_R(IDC_OPTS_MAXUNDOSIZE),
00386                                                              1*1024, UINT32_MAX-1,
00387                                                              _R(IDE_OPTS_INVALIDUNDOSIZE), &Valid);
00388             if (!Valid)
00389                 return FALSE;           // Undo size incorrect, user has been warned already
00390         }
00391 TRACEUSER( "Neville", _T("Current undo size =%d\n"),CurrentSize);
00392 TRACEUSER( "Neville", _T("Current maximum undo size =%d\n"),CurrentMaxSize);
00393 TRACEUSER( "Neville", _T("New maximum undo size =%d\n"),NewMaxUndoSize);
00394         
00395         // If a new size has been entered then try to set this as the new maximum
00396         if (NewMaxUndoSize != CurrentMaxSize)
00397         {
00398             // If the resize means that data will be lost then warn the user and ask for confirmation
00399             // otherwise just set the new limit.
00400             BOOL OkToResize = TRUE;
00401             if (NewMaxUndoSize < CurrentSize)
00402             {
00403                 // Ask user to confirm loss of undo data
00404                 // Warn the user that there is no selection = large export
00405                 ErrorInfo Info;
00406                 Info.ErrorMsg = _R(IDT_OPTS_LOSSOFUNDO);
00407                 Info.Button[0] = _R(IDB_UNDOQUERY_RESIZE);
00408                 Info.Button[1] = _R(IDB_UNDOQUERY_DONTRESIZE);
00409                 if ((ResourceID)AskQuestion(&Info) == _R(IDB_UNDOQUERY_DONTRESIZE))
00410                 {
00411                     // If the user has cancelled just display the current value again
00412                     OkToResize = FALSE;
00413                 }
00414             }
00415         
00416             // If everything is ok then try the resize
00417             if (OkToResize)
00418             {
00419                 SetOk = pDocument->GetOpHistory().SetNewMaxSize(NewMaxUndoSize);
00420                 if (!SetOk)
00421                 {
00422                     // Out of ID's at present so use wrong error message 
00423                     InformError(_R(IDE_OPTS_BADUNDORESIZE));
00424                 
00425                     // Force the update to the old max size value
00426                     OkToResize = FALSE;
00427                 }
00428                 else
00429                 {
00430                     // Mark the document as modified as we have resized it ok
00431                     pDocument->SetModified(TRUE);                   
00432                 }
00433             }
00434 
00435             // If for any reason OkToResize has been set ot FALSE then update the undo size
00436             // field and exit FALSE
00437             if (!OkToResize)
00438             {
00439                 // Restore the MaxSize in dialog field
00440                 //String_256    String;
00441                 // Get current size
00442                 UINT32 MaxUndoSize = pDocument->GetOpHistory().GetMaxSize();
00443                 // Show that value on the dialog box as a memory size
00444                 pPrefsDlg->SetMemoryGadgetValue(_R(IDC_OPTS_MAXUNDOSIZE), MaxUndoSize);
00445 
00446                 return FALSE;
00447             }
00448         }
00449     }
00450     //else
00451     //  ERROR2(FALSE,_R(IDE_OPTS_SETPREF_TUNE));
00452 
00453     return TRUE;
00454 }
00455 
00456 /******************************************************************************************
00457 
00458 >   BOOL TuneTab::CommitSection()
00459 
00460     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00461     Created:    19/1/95
00462     Inputs:     -
00463     Outputs:    -
00464     Returns:    True if values in dialog box ok, False otherwise.     
00465     Purpose:    Takes the values in the Tuneups section tab of the options dialog box and
00466                 sets the associated preference values accordingly
00467                 Called when ok is pressed on the dialog box.
00468     Errors:     -
00469     SeeAlso:    -
00470 
00471 ******************************************************************************************/
00472 
00473 BOOL TuneTab::CommitSection()
00474 {
00475 TRACEUSER( "Neville", _T("TuneTab::CommitSection\n"));
00476     ERROR2IF(pPrefsDlg == NULL,FALSE,"TuneTab::CommitSection called with no dialog pointer");
00477 
00478     BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_TUNE));  // The tune up page identifier
00479     if (!ok)
00480         return TRUE;            // Talk to page failed to return now
00481 
00482     ok = CommitRenderingSection();
00483     if (ok != TRUE)
00484         return ok;              // Something went wrong so return this to caller.
00485     
00486 #ifndef EXCLUDE_GALS
00487     // Section = Gallery cache size
00488 PORTNOTE("other", "Disabled Library Thumbnails preference")
00489 #ifndef EXCLUDE_FROM_XARALX
00490 
00491     BOOL Valid = TRUE; 
00492     INT32 CacheSize = pPrefsDlg->GetLongGadgetValue(_R(IDC_OPTS_CACHESIZE), 1, 99, _R(IDE_OPTS_INVALIDCACHESIZE), &Valid);
00493     if (Valid)
00494     {
00495 TRACEUSER( "Neville", _T("commit gallery cache size='%d'\n"), CacheSize);
00496         BOOL SetOk = Camelot.SetPrefValue(TEXT("Libraries"), TEXT("Thumbnails"), &CacheSize);
00497         ERROR2IF(!SetOk,2,_R(IDE_OPTS_SETPREF_TUNE));
00498         // Tell the galleries and in particular the thumbnail one about the change.     
00499         SGThumbs::ResizeAllThumbCaches(CacheSize);
00500     }
00501     else
00502         return FALSE;           // Cache size incorrect, user has been warned already
00503 #endif
00504 #endif
00505 
00506     ok = CommitUndoSection();
00507     if (ok != TRUE)
00508         return ok;              // Something went wrong so return this to caller.
00509 
00510     // ---------------------------------------------------------------------------------
00511     // Cacheing preferences
00512     {
00513         BOOL SetOk = FALSE;
00514         INT32 State = 0;
00515         BOOL Valid = FALSE;
00516 
00517         State = pPrefsDlg->GetLongGadgetValue(_R(IDC_CHECK_CACHE_ENABLED), 0, 1, 0, &Valid);
00518         if (Valid)
00519             SetOk = Camelot.SetPrefValue(TEXT("Rendering"), TEXT("Cacheing"), &State);
00520 
00521     //  State = pPrefsDlg->GetLongGadgetValue(_R(IDC_EDIT_CACHE_SIZE), 1, 100, 0, &Valid);
00522         String_256 strCachePercent = pPrefsDlg->GetStringGadgetValue(_R(IDC_EDIT_CACHE_SIZE), &Valid);
00523         double dValue = 0;
00524         INT32 Pos = 0;
00525         INT32 iValue = 0;
00526         Convert::ReadNumber(strCachePercent, &Pos, &dValue);    // Allow trailing chars
00527         if (Valid && dValue>=1 && dValue<=100)
00528             iValue = (INT32)dValue;
00529             SetOk = Camelot.SetPrefValue(TEXT("Cache"), TEXT("CacheRAMPercent"), &iValue);
00530 
00531         // Reset the cache size...
00532         CBitmapCache* pCache = Camelot.GetBitmapCache();
00533         if (pCache)
00534         {
00535             pCache->SetMaximumDataSize(pCache->CalcRecommendedMaximumDataSize());
00536             // If the new size if smaller than the old size, things will get
00537             // thrown out of the cache the next time any attempt is made to
00538             // store anything...
00539         }
00540     }
00541 
00542     return TRUE;
00543 }
00544 
00545 /********************************************************************************************
00546 
00547 >   BOOL TuneTab::GreySection()
00548 
00549     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00550     Created:    4/2/95
00551     Inputs:     -
00552     Outputs:    -
00553     Returns:    -
00554     Purpose:    Called when the user has closed all documents 
00555     Errors:     -
00556     SeeAlso:    TuneTab::UngreySection;
00557 
00558 ********************************************************************************************/
00559 
00560 BOOL TuneTab::GreySection()
00561 {
00562 TRACEUSER( "Neville", _T("GreySection in TuneTab section\n"));
00563     ERROR2IF(pPrefsDlg == NULL,FALSE,"TuneTab::GreySection called with no dialog pointer");
00564 
00565     BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_TUNE));  // The TuneTab identifier
00566     if (!ok)
00567         return TRUE;    // Talk to page failed to return now
00568 
00569     // Make sure the information field displaying the name of the current document
00570     // is correct.
00571     String_256  DocumentName(_R(IDT_OPTS_UNDO_INFO)); 
00572     DocumentName += *GetDocumentName();
00573     pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_UNDOINFO), DocumentName);
00574 
00575     // Only update if we are not already grey 
00576     if (GreyStatus == TRUE)
00577         return TRUE;
00578 
00579     // Call our central greying/ungreying function
00580     ok = ChangeControlStatus(FALSE);
00581     
00582     GreyStatus = TRUE;
00583 
00584     return ok;
00585 } 
00586 
00587 /********************************************************************************************
00588 
00589 >   BOOL TuneTab::UngreySection()
00590 
00591     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00592     Created:    4/2/95
00593     Inputs:     -
00594     Outputs:    -
00595     Returns:    -
00596     Purpose:    Called when the user has selected a new document 
00597     Errors:     -
00598     SeeAlso:    TuneTab::UngreySection;
00599 
00600 ********************************************************************************************/
00601 
00602 BOOL TuneTab::UngreySection()
00603 {
00604 TRACEUSER( "Neville", _T("UngreySection in TuneTab section\n"));
00605     ERROR2IF(pPrefsDlg == NULL,FALSE,"TuneTab::UngreySection called with no dialog pointer");
00606 
00607     BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_TUNE));  // The TuneTab identifier
00608     if (!ok)
00609         return TRUE;    // Talk to page failed to return now
00610 
00611     // Make sure the information field displaying the name of the current document
00612     // is correct.
00613     String_256  DocumentName(_R(IDT_OPTS_UNDO_INFO)); 
00614     DocumentName += *GetDocumentName();
00615     pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_UNDOINFO), DocumentName);
00616 
00617     // Only update if we are not already ungrey 
00618     if (GreyStatus == FALSE)
00619         return TRUE;
00620 
00621     // Call our central greying/ungreying function
00622     ok = ChangeControlStatus(TRUE);
00623     
00624     GreyStatus = FALSE;
00625 
00626     return ok;
00627 }
00628 
00629 /********************************************************************************************
00630 
00631 >   BOOL TuneTab::ChangeControlStatus(const BOOL Status)
00632 
00633     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00634     Created:    4/2/95
00635     Inputs:     -
00636     Outputs:    -
00637     Returns:    -
00638     Purpose:    Called to grey/ungrey all controls on this tab. 
00639     Errors:     -
00640     SeeAlso:    TuneTab::GreySection;   TuneTab::UngreySection;
00641 
00642 ********************************************************************************************/
00643 
00644 BOOL TuneTab::ChangeControlStatus(const BOOL Status)
00645 {
00646     // Grey/ungrey the info section
00647 //  pPrefsDlg->EnableGadget(_R(IDC_OPTS_TUNEUPSINFO), Status);
00648 
00649     // GDraw rendering memory section
00650 //  pPrefsDlg->EnableGadget(_R(IDC_OPTS_TUNEGROUP), Status);
00651 //  pPrefsDlg->EnableGadget(_R(IDC_OPTS_MEMREQD), Status);
00652 //  pPrefsDlg->EnableGadget(_R(IDC_OPTS_FULLPAGEMEM), Status);
00653 //  pPrefsDlg->EnableGadget(_R(IDC_OPTS_USEMAXMEMORY), Status);
00654 //  pPrefsDlg->EnableGadget(_R(IDC_OPTS_USELIMITMEM), Status);
00655 //  pPrefsDlg->EnableGadget(_R(IDC_OPTS_MEMLIMITTXT), Status);
00656 //  pPrefsDlg->EnableGadget(_R(IDC_OPTS_TEMPWORKMEM), Status);
00657 
00658 //  pPrefsDlg->EnableGadget(_R(IDC_OPTS_GALLERYGRP), Status);
00659 //  pPrefsDlg->EnableGadget(_R(IDC_OPTS_CACHETXT), Status);
00660 //  pPrefsDlg->EnableGadget(_R(IDC_OPTS_CACHESIZE), Status);
00661 
00662     // Undo section
00663     pPrefsDlg->EnableGadget(_R(IDC_OPTS_UNDOINFO), Status);
00664     pPrefsDlg->EnableGadget(_R(IDC_OPTS_UNDOSIZETXT), Status);
00665     pPrefsDlg->EnableGadget(_R(IDC_OPTS_UNDOSIZE), Status);
00666     pPrefsDlg->EnableGadget(_R(IDC_OPTS_UNLIMITEDUNDO), Status);
00667     pPrefsDlg->EnableGadget(_R(IDC_OPTS_LIMITEDUNDO), Status);
00668     pPrefsDlg->EnableGadget(_R(IDC_OPTS_UNDOLIMITTXT), Status);
00669     pPrefsDlg->EnableGadget(_R(IDC_OPTS_MAXUNDOSIZE), Status);
00670 
00671     return TRUE;
00672 }           
00673 
00674 /********************************************************************************************
00675 
00676 >   BOOL TuneTab::UpdateSection(String_256 *DocumentName)
00677 
00678     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00679     Created:    4/2/95
00680     Inputs:     Name of document
00681     Outputs:    -
00682     Returns:    -
00683     Purpose:    Called when we have switched to a new document and need to update all the 
00684                 controls on this tab. Should only init the tab if the page is present.  
00685                 The document name allows the info field on the tab to be filled in correctly.
00686     Errors:     -
00687     SeeAlso:    TuneTab::GreySection; TuneTab::UngreySection; TuneTab::InitSection;
00688 
00689 ********************************************************************************************/
00690 
00691 BOOL TuneTab::UpdateSection(String_256 *DocumentName)
00692 {
00693 TRACEUSER( "Neville", _T("TuneTab::UpdateSection\n"));
00694     ERROR2IF(pPrefsDlg == NULL,FALSE,"TuneTab::UpdateSection called with no dialog pointer");
00695 
00696     BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_TUNE));  // The TuneTab identifier
00697     if (!ok)
00698         return TRUE;        // page not present
00699 
00700     // Make sure the information field displaying the name of the current document
00701     // is correct.
00702     String_256  DocName(_R(IDT_OPTS_UNDO_INFO)); 
00703     DocName +=  *DocumentName;
00704     pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_UNDOINFO), DocName);
00705 
00706     // Remove any lists that we have created.
00707     //pPrefsDlg->DeleteAllValues(_R(IDC_OPTS_SIZELIST));
00708 
00709     // Call the normal init section code but only the undo is document specific
00710     return InitUndoSection();
00711 }
00712 
00713 /********************************************************************************************
00714 
00715 >   BOOL TuneTab::HandleMsg(DialogMsg* Msg)
00716 
00717     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00718     Created:    19/01/95
00719     Inputs:     -
00720     Outputs:    -
00721     Returns:    -
00722     Purpose:    Handles all the Tuneup options tabs messages 
00723     Errors:     -
00724     SeeAlso:    -
00725 
00726 ********************************************************************************************/
00727 
00728 BOOL TuneTab::HandleMsg(DialogMsg* Msg)
00729 {
00730 TRACEUSER( "Neville", _T("HandleTuneUpMsg\n"));
00731     ERROR2IF(Msg == NULL,FALSE,"TuneTab::Message null message received");
00732     ERROR2IF(pPrefsDlg == NULL,FALSE,"TuneTab::HandleMsg called with no dialog pointer");
00733 
00734     BOOL ok = pPrefsDlg->TalkToPage(_R(IDD_OPTSTAB_TUNE));  // The tune page identifier
00735     if (!ok)
00736         return TRUE;        // no page present = handled message
00737     
00738     switch(Msg->DlgMsg)
00739     {
00740         case DIM_CREATE:    // Initialise controls
00741             GreyStatus = FALSE; // we are ungreyed by default
00742             ok = InitSection();
00743             if (!ok)
00744                 InformError();
00745             break;
00746         case DIM_LFT_BN_CLICKED:
00747             OptionsTabs::SetApplyNowState(TRUE);
00748             if ((Msg->GadgetID == _R(IDC_OPTS_USEMAXMEMORY)) || (Msg->GadgetID == _R(IDC_OPTS_USELIMITMEM)))
00749             {
00750                 BOOL Valid;
00751                 BOOL UseMaximumMemory = pPrefsDlg->GetLongGadgetValue(_R(IDC_OPTS_USEMAXMEMORY), 0, 1, 0, &Valid);
00752                 // If set then grey the editable field and its name text otherwise ungrey
00753                 pPrefsDlg->EnableGadget(_R(IDC_OPTS_MEMLIMITTXT), !UseMaximumMemory);
00754                 pPrefsDlg->EnableGadget(_R(IDC_OPTS_TEMPWORKMEM), !UseMaximumMemory);
00755             }
00756             else if ((Msg->GadgetID ==  _R(IDC_OPTS_UNLIMITEDUNDO)) || (Msg->GadgetID == _R(IDC_OPTS_LIMITEDUNDO)))
00757             {
00758                 BOOL Valid;
00759                 BOOL Unlimited = pPrefsDlg->GetLongGadgetValue(_R(IDC_OPTS_UNLIMITEDUNDO), 0, 1, 0, &Valid);
00760                 // If set then grey the editable field and its name text otherwise ungrey
00761                 pPrefsDlg->EnableGadget(_R(IDC_OPTS_UNDOLIMITTXT), !Unlimited);
00762                 pPrefsDlg->EnableGadget(_R(IDC_OPTS_MAXUNDOSIZE), !Unlimited);
00763             }
00764         case DIM_SELECTION_CHANGED:
00765         case DIM_TEXT_CHANGED:
00766             OptionsTabs::SetApplyNowState(TRUE);
00767             break;
00768         default:
00769             break;
00770     }
00771     return TRUE;
00772 }  
00773 
00774 /******************************************************************************************
00775 
00776 >   BOOL TuneTab::InitRenderingSection()
00777 
00778     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00779     Created:    19/01/95
00780     Inputs:     -
00781     Outputs:    -
00782     Returns:    TRUE if successful, else FALSE
00783     Purpose:    Sets initial values for the GDraw rendering section of the options dialog box.
00784     Errors:     -
00785     SeeAlso:    AppPrefsDlg; OptionsTabs;
00786 
00787 ******************************************************************************************/
00788 
00789 BOOL TuneTab::InitRenderingSection()
00790 {
00791     TRACEUSER( "Neville", _T("TuneTab::InitRenderingSection\n"));
00792     ERROR2IF(pPrefsDlg == NULL,FALSE,"TuneTab::InitRenderingSection called with no dialog pointer");
00793 
00794     BOOL ReadOk = TRUE;     // Flag to say whether the preference value was read ok 
00795     BOOL ok = TRUE;         // Flag for whether value set up ok 
00796 
00797     // The Maximum temporary workspace available to Gdraw
00798     UINT32 TempWorkMem = TunedMemory::GetLimitedMemSize();
00799 //  UINT32 TempWorkMemK = TempWorkMem / 1024;
00800     BOOL UseMaximumMemory = TunedMemory::IsAutomaticMemory();
00801 
00802     // Limit the values                                            
00803     if (TempWorkMem > MAX_TUNEUPS_MEMORY)
00804     {
00805         ReadOk=FALSE;
00806         TRACEUSER( "Neville", _T("value too large, must be < 32M\n"));
00807         // Error - Value too large
00808         ERROR2(2,_R(IDE_OPTS_READPREF_TUNE));
00809     }
00810 
00811     if (ReadOk && (TempWorkMem < MIN_TUNEUPS_MEMORY) && (TempWorkMem != 0) )
00812     {
00813         ReadOk=FALSE;
00814         TRACEUSER( "Neville", _T("value too small - must be 1024 bytes or greater\n"));
00815         // Error - Value too small
00816         ERROR2(2,_R(IDE_OPTS_READPREF_TUNE));
00817     }
00818      
00819     // Find out how much ram is needed for a full screen transparency blit
00820     INT32 FullPageMem = TunedMemory::GetScreenMemSize();
00821     ok = pPrefsDlg->SetMemoryGadgetValue(_R(IDC_OPTS_FULLPAGEMEM), FullPageMem);
00822 
00823     // Format a string to relate the amount of memory put aside
00824     // Display the chosen value in the editable field
00825     pPrefsDlg->SetMemoryGadgetValue(_R(IDC_OPTS_TEMPWORKMEM), TempWorkMem);
00826 
00827     // Set up the use maximum/limited memory radio buttons        
00828     pPrefsDlg->SetLongGadgetValue(_R(IDC_OPTS_USEMAXMEMORY), UseMaximumMemory);
00829     pPrefsDlg->SetLongGadgetValue(_R(IDC_OPTS_USELIMITMEM), !UseMaximumMemory);
00830 
00831     // If set then grey the editable field and its name text
00832     pPrefsDlg->EnableGadget(_R(IDC_OPTS_MEMLIMITTXT), !UseMaximumMemory);
00833     pPrefsDlg->EnableGadget(_R(IDC_OPTS_TEMPWORKMEM), !UseMaximumMemory);
00834         
00835     return TRUE;
00836 }
00837 
00838 /******************************************************************************************
00839 
00840 >   BOOL TuneTab::InitUndoSection()
00841 
00842     Author:     Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com>
00843     Created:    20/1/95
00844     Inputs:     -
00845     Outputs:    -
00846     Returns:    TRUE if successful, else FALSE
00847     Purpose:    Sets initial values for the Undo section of the options dialog box.
00848                 This section includes the:-
00849                 - Unlimited undo memory size switch
00850                 - OR maximum memory allowed for undo system 
00851     Errors:     -
00852     SeeAlso:    AppPrefsDlg; OptionsTabs;
00853 
00854 ******************************************************************************************/
00855 
00856 BOOL TuneTab::InitUndoSection()
00857 {
00858 TRACEUSER( "Neville", _T("TuneTab::InitUndoSection\n"));
00859     ERROR2IF(pPrefsDlg == NULL,FALSE,"TuneTab::InitUndoSection called with no dialog pointer");
00860 
00861 //  BOOL ReadOk = FALSE;    // Flag to say whether the preference value was read ok 
00862 
00863     // Section = Undo settings
00864 
00865     // Set up the display for the current size of the undo buffer.
00866     Document* pDocument = Document::GetSelected();
00867     if (pDocument != NULL)
00868     {
00869         // Get the current undo size
00870         UINT32 UndoSize = pDocument->GetOpHistory().GetSize();
00871         
00872         // Put that size in a string formatted as a memory size value
00873         // and show that on the dialog box
00874         pPrefsDlg->SetMemoryGadgetValue(_R(IDC_OPTS_UNDOSIZE), UndoSize);
00875 
00876         // Now get the currently set maximum size
00877         UINT32 MaxUndoSize = pDocument->GetOpHistory().GetMaxSize();
00878 
00879         OldMaxUndoSize = MaxUndoSize;
00880 
00881         // If set at the maximum size possible then assume unlimited
00882         BOOL Unlimited = FALSE;
00883         if (MaxUndoSize == UINT32_MAX)
00884         {
00885             // If at maximum then we are in the unlimited state     
00886             Unlimited = TRUE;
00887             // Force in a much more sensible value
00888             MaxUndoSize = 256 * 1024;           
00889         }
00890         else
00891             Unlimited = FALSE;
00892 
00893         // Put that size in a string formatted as a memory size value
00894         // and show that on the dialog box
00895         pPrefsDlg->SetMemoryGadgetValue(_R(IDC_OPTS_MAXUNDOSIZE), MaxUndoSize);
00896 
00897         // Set the unlimited/limited radio button states
00898         pPrefsDlg->SetLongGadgetValue(_R(IDC_OPTS_UNLIMITEDUNDO), Unlimited);
00899         pPrefsDlg->SetLongGadgetValue(_R(IDC_OPTS_LIMITEDUNDO), !Unlimited);
00900         
00901         // Grey or ungrey the editable field and its name text accordingly
00902         pPrefsDlg->EnableGadget(_R(IDC_OPTS_UNDOLIMITTXT), !Unlimited);
00903         pPrefsDlg->EnableGadget(_R(IDC_OPTS_MAXUNDOSIZE), !Unlimited);
00904 
00905 TRACEUSER( "Neville", _T("undo size ='%d'\n"),UndoSize);
00906 TRACEUSER( "Neville", _T("max undo size ='%d'\n"),MaxUndoSize);
00907     }
00908     else
00909     {
00910         // Ensure our section is greyed
00911         GreySection();
00912     }
00913 
00914     return TRUE;
00915 }
00916 
00917 /******************************************************************************************
00918 
00919 >   BOOL TuneTab::InitSection()
00920 
00921     Author:     Richard_Millican (Xara Group Ltd) <camelotdev@xara.com>
00922     Created:    19/01/95
00923     Inputs:     -
00924     Outputs:    -
00925     Returns:    TRUE if successful, else FALSE
00926     Purpose:    Sets initial values for the Tuneups section of the options dialog box.
00927     Errors:     -
00928     SeeAlso:    AppPrefsDlg; OptionsTabs;
00929 
00930 ******************************************************************************************/
00931 
00932 BOOL TuneTab::InitSection()
00933 {
00934 TRACEUSER( "Neville", _T("TuneTab::InitSection\n"));
00935     ERROR2IF(pPrefsDlg == NULL,FALSE,"TuneTab::InitSection called with no dialog pointer");
00936 
00937     // Make sure the information field displaying the name of the current document
00938     // is correct.
00939     String_256  DocumentName(_R(IDT_OPTS_UNDO_INFO)); 
00940     DocumentName += *GetDocumentName();
00941     pPrefsDlg->SetStringGadgetValue(_R(IDC_OPTS_UNDOINFO), DocumentName);
00942 
00943     InitRenderingSection();
00944 
00945     // Section = Gallery Cache size
00946 PORTNOTE("other", "Disabled Library Thumbnails preference")
00947 #ifndef EXCLUDE_FROM_XARALX
00948     INT32 CacheSize = 1;
00949     BOOL ReadOk = Camelot.GetPrefValue(TEXT("Libraries"), TEXT("Thumbnails"), &CacheSize);
00950     pPrefsDlg->SetLongGadgetValue(_R(IDC_OPTS_CACHESIZE), CacheSize);
00951     ERROR2IF(!ReadOk,FALSE,_R(IDE_OPTS_READPREF_TUNE));
00952 #endif
00953 
00954     InitUndoSection();
00955     
00956     // --------------------------------------------------------------------------
00957     // Bitmap cacheing
00959     BOOL bCacheingEnabled = FALSE;
00960     Camelot.GetPrefValue(TEXT("Rendering"), TEXT("Cacheing"), &bCacheingEnabled);
00961     pPrefsDlg->SetBoolGadgetSelected(_R(IDC_CHECK_CACHE_ENABLED), bCacheingEnabled);
00962 
00963     INT32 iCacheRAMPercent = 0;
00964     Camelot.GetPrefValue(TEXT("Cache"), TEXT("CacheRAMPercent"), &iCacheRAMPercent);
00965     TCHAR Str[32];
00966     String_32 temp(_R(IDS_PERCENT_FORMAT));
00967     camSnprintf(Str, 32, temp, iCacheRAMPercent);
00968     String_32 PercentStr(Str);
00969     pPrefsDlg->SetStringGadgetValue(_R(IDC_EDIT_CACHE_SIZE), PercentStr);
00970 
00971     CBitmapCache* pCache = GetApplication()->GetBitmapCache();
00972     if (pCache)
00973     {
00974         // This value should really be rounded!
00975         INT32 iCacheUsagePercent = ((UINT64)pCache->GetCurrentDataSize()*100)/pCache->GetMaximumDataSize();
00976 
00977         TCHAR Str[32];
00978         String_32 temp(_R(IDS_PERCENT_OF_FORMAT));
00979         String_32 strCacheSize;
00980         Convert::BytesToString(&strCacheSize, (UINT32)pCache->GetMaximumDataSize());
00981         camSnprintf(Str, 32, temp, iCacheUsagePercent, (TCHAR*)strCacheSize);
00982         String_32 PercentStr(Str);
00983         pPrefsDlg->SetStringGadgetValue(_R(IDC_EDIT_CURRENTCACHE), PercentStr);
00984 
00985 //      pPrefsDlg->SetLongGadgetValue(_R(IDC_PROGRESS_CACHEUSAGE), iCacheUsagePercent);     // TODO: Should be percentage
00986     }
00987 
00988     return TRUE;
00989 }
00990 
00991 #endif //webster

Generated on Sat Nov 10 03:46:21 2007 for Camelot by  doxygen 1.4.4