palmenu.cpp

Go to the documentation of this file.
00001 // $Id: palmenu.cpp 1088 2006-05-16 16:56:32Z luke $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 #include "camtypes.h"
00100 #include "palmenu.h"
00101 //#include "bmpreres.h"
00102 #include "bmpalctrl.h"
00103 #include "bmapprev.h"
00104 
00105 DECLARE_SOURCE("$Revision: 1088 $");
00106 
00107 //  An implementation to match the declaration in the header file.
00108 CC_IMPLEMENT_DYNCREATE(OpPalettePopupCommand, Operation)
00109 
00110 //  Initialise the static variable.
00111 BitmapExportPaletteControl *OpPalettePopupCommand::m_pPaletteControl = 0;
00112 BmapPrevDlg *OpPalettePopupCommand::m_pBmapPrevDlg = 0;
00113 
00114 //  This will get Camelot to display the filename and linenumber of any memory allocations
00115 //  that are not released at program exit
00116 #define new CAM_DEBUG_NEW
00117 
00118 
00119 /******************************************************************************************
00120 >   INT32 PaletteContextMenu :: Build()
00121     Author:     Alex_Price (Xara Group Ltd) <camelotdev@xara.com>
00122     Created:    09/08/99
00123     Inputs:     -
00124     Returns:    TRUE if everything went OK, and FALSE otherwise.
00125     Purpose:    This function builds the menu.
00126 ******************************************************************************************/
00127 BOOL PaletteContextMenu::Build()
00128 {
00129     //  Use this variable to hold the status of the menu build. If it goes FALSE, 
00130     //  then something went wrong.
00131     BOOL ok = TRUE;
00132 
00133     //  Add all the menu items, together with separators.
00134     if( ok ) 
00135         ok = ok && BuildCommand( OPTOKEN_PALETTE_LOCKED );
00136     if( ok ) 
00137         ok = ok && BuildCommand( OPTOKEN_PALETTE_WEB_SAFE );
00138     if( ok )
00139         ok = ok && BuildCommand( OPTOKEN_PALETTE_TRANSPARENT_BACKGROUND );
00140     if( ok ) 
00141         ok = ok && BuildCommand( OPTOKEN_PALETTE_TRANSPARENT, TRUE );
00142 
00143 
00144     if( ok ) 
00145         ok = ok && BuildCommand( OPTOKEN_PALETTE_RESTORE );
00146     if( ok )
00147         ok = ok && BuildCommand( OPTOKEN_PALETTE_DELETE, TRUE);
00148 
00149     if( ok ) 
00150         ok = ok && BuildCommand( OPTOKEN_PALETTE_SYSTEM_COLOURS, TRUE );
00151 
00152     if( ok ) 
00153         ok = ok && BuildCommand( OPTOKEN_PALETTE_SORT_BY_USE );
00154     if( ok ) 
00155         ok = ok && BuildCommand( OPTOKEN_PALETTE_SORT_BY_LUMINANCE );
00156     if( ok ) 
00157         ok = ok && BuildCommand( OPTOKEN_PALETTE_SORT_BY_HUE );
00158 
00159     return ok;
00160 }
00161 
00162     
00163 /******************************************************************************************
00164 
00165 >   static BOOL OpPreviewPopupCommand::InitPolymorphicCommand( TCHAR *OpToken, UINT32 MenuTextID )
00166  
00167     Author:     Alex_Price (Xara Group Ltd) <camelotdev@xara.com>
00168 
00169     Created:    09/08/99
00170 
00171     Inputs:     OpToken - the token of a menu operation
00172                 MenuTextID - the resource string of the menu command.
00173 
00174     Returns:    TRUE if everything went OK, and FALSE otherwise.
00175 
00176     Purpose:    This function registers a menu operation.
00177 
00178 ******************************************************************************************/
00179 
00180 BOOL OpPalettePopupCommand::InitPolymorphicCommand( TCHAR *OpToken, UINT32 MenuTextID )
00181 {
00182     return(RegisterOpDescriptor(0,                                  // Tool ID 
00183                                 MenuTextID,                         // String resource ID
00184                                 CC_RUNTIME_CLASS(OpPalettePopupCommand),// Runtime class
00185                                 OpToken,                            // Token string
00186                                 OpPalettePopupCommand::GetCommandState, // GetState function
00187                                 0,                                  // help ID
00188                                 0,                                  // bubble help
00189                                 0,                                  // resource ID
00190                                 0,                                  // control ID
00191                                 SYSTEMBAR_ILLEGAL,                  // Bar ID
00192                                 FALSE,                              // Receive system messages
00193                                 FALSE,                              // Smart duplicate operation
00194                                 TRUE,                               // Clean operation
00195                                 NULL,                               // No vertical counterpart
00196                                 0,                                  // String for one copy only error
00197                                 DONT_GREY_WHEN_SELECT_INSIDE        // Auto state flags
00198                                 ));
00199 }
00200 
00201 
00202 /******************************************************************************************
00203 >   BOOL OpPalettePopupCommand::Init(BitmapExportPaletteControl *)
00204     Author:     Alex_Price (Xara Group Ltd) <camelotdev@xara.com>
00205     Created:    09/08/99
00206     Inputs:     -
00207     Returns:    TRUE if everything went OK, and FALSE otherwise.
00208     Purpose:    This function registers all the menu operations by calling InitPolymorphicCommand
00209 ******************************************************************************************/
00210 BOOL OpPalettePopupCommand::Init(BitmapExportPaletteControl *pPaletteControl, BmapPrevDlg *pBmapPrevDlg)
00211 {
00212     m_pPaletteControl   = pPaletteControl;
00213     m_pBmapPrevDlg      = pBmapPrevDlg;
00214 
00215     InitPolymorphicCommand( OPTOKEN_PALETTE_LOCKED,                 _R(IDS_MENU_LOCKED) );
00216     InitPolymorphicCommand( OPTOKEN_PALETTE_WEB_SAFE,               _R(IDS_MENU_WEB_SAFE) );
00217     InitPolymorphicCommand( OPTOKEN_PALETTE_TRANSPARENT_BACKGROUND, _R(IDS_MENU_TRANSPARENT_BACK) );
00218     InitPolymorphicCommand( OPTOKEN_PALETTE_TRANSPARENT,            _R(IDS_MENU_TRANSPARENT) );
00219 
00220     InitPolymorphicCommand( OPTOKEN_PALETTE_RESTORE,                _R(IDS_MENU_RESTORE) );
00221     InitPolymorphicCommand( OPTOKEN_PALETTE_DELETE,                 _R(IDS_MENU_DELETE) );
00222 
00223     InitPolymorphicCommand( OPTOKEN_PALETTE_SYSTEM_COLOURS,         _R(IDS_MENU_SYSTEM_COLOURS) );
00224 
00225     InitPolymorphicCommand( OPTOKEN_PALETTE_SORT_BY_USE,            _R(IDS_MENU_SORT_BY_USE) );
00226     InitPolymorphicCommand( OPTOKEN_PALETTE_SORT_BY_LUMINANCE,      _R(IDS_MENU_SORT_BY_LUMINANCE) );
00227     InitPolymorphicCommand( OPTOKEN_PALETTE_SORT_BY_HUE,            _R(IDS_MENU_SORT_BY_HUE) );
00228 
00229     return TRUE;
00230 }               
00231 
00232 
00233 /******************************************************************************************
00234 >   OpState OpPalettePopupCommand::GetCommandState(String_256 *UIDescription, OpDescriptor *pOpDesc)
00235     Author:     Alex_Price (Xara Group Ltd) <camelotdev@xara.com>
00236     Created:    09/08/99
00237     Inputs:     UIDescription - ?
00238                 pOpDesc - ?
00239     Returns:    The state of the OpPreviewPopupCommand operation for the given OpDescriptor
00240     Purpose:    Handles the putting of tick marks, and greying out of menu items in the menu.
00241 ******************************************************************************************/
00242 OpState OpPalettePopupCommand::GetCommandState( String_256 *UIDescription, OpDescriptor *pOpDesc )
00243 {
00244     OpState OpSt;
00245     OpSt.Greyed = FALSE;
00246 
00247     //  Get the properties of the colour under consideration
00248     BOOL bLocked                = m_pPaletteControl->GetSelectedColourLocked();
00249     BOOL bDeleted               = m_pPaletteControl->GetSelectedColourDeleted();
00250     BOOL bWebSafe               = m_pPaletteControl->GetSelectedColourWebSafe();
00251     BOOL bTransparentBackground = BmapPrevDlg::m_pExportOptions->IsBackgroundTransparent();
00252     BOOL bTransparent           = m_pPaletteControl->GetSelectedColourTransparent();
00253     BOOL bSupportsTransp        = BmapPrevDlg::m_pExportOptions->GetSupportsTransparency();
00254 
00255     //  Locked menu item
00256     if( pOpDesc->Token == String_256( OPTOKEN_PALETTE_LOCKED ) )
00257     {
00258         if (bDeleted)
00259             OpSt.Greyed = TRUE;
00260         else if (bLocked)
00261             OpSt.Ticked = TRUE;
00262     }
00263 
00264     //  WebSafe menu item
00265     if( pOpDesc->Token == String_256( OPTOKEN_PALETTE_WEB_SAFE ) )
00266     {
00267         if (bTransparent || bDeleted || bWebSafe)
00268             OpSt.Greyed = TRUE;
00269     }
00270 
00271     //  Background transparent menu item
00272     if( pOpDesc->Token == String_256( OPTOKEN_PALETTE_TRANSPARENT_BACKGROUND ) )
00273     {
00274         if (bDeleted || !bSupportsTransp)
00275             OpSt.Greyed = TRUE;
00276         else if (bTransparentBackground)
00277             OpSt.Ticked = TRUE;
00278     }
00279 
00280     //  Transparent menu item
00281     if( pOpDesc->Token == String_256( OPTOKEN_PALETTE_TRANSPARENT ) )
00282     {
00283         if (bDeleted || !bSupportsTransp)
00284             OpSt.Greyed = TRUE;
00285         else if (bTransparent)
00286             OpSt.Ticked = TRUE;
00287     }
00288 
00289     //  Delete menu item
00290     if( pOpDesc->Token == String_256( OPTOKEN_PALETTE_DELETE ) )
00291     {
00292         if(bDeleted)
00293             OpSt.RemoveFromMenu = TRUE;
00294     }
00295 
00296     //  Restore menu item
00297     if( pOpDesc->Token == String_256( OPTOKEN_PALETTE_RESTORE ) )
00298     {
00299         if(!bDeleted)
00300             OpSt.RemoveFromMenu = TRUE;
00301     }
00302 
00303     //  The 'Sort by...' menu items.
00304     if( pOpDesc->Token == String_256( OPTOKEN_PALETTE_SORT_BY_USE ) )
00305         if (m_pPaletteControl->GetCurrentSortType() == BitmapExportPaletteInterface::SORT_USE)
00306             OpSt.Ticked = TRUE;
00307 
00308     if( pOpDesc->Token == String_256( OPTOKEN_PALETTE_SORT_BY_LUMINANCE ) )
00309         if (m_pPaletteControl->GetCurrentSortType() == BitmapExportPaletteInterface::SORT_LUMINANCE)
00310             OpSt.Ticked = TRUE;
00311 
00312     if( pOpDesc->Token == String_256( OPTOKEN_PALETTE_SORT_BY_HUE ) )
00313         if (m_pPaletteControl->GetCurrentSortType() == BitmapExportPaletteInterface::SORT_HUE)
00314             OpSt.Ticked = TRUE;
00315 
00316     //  Tick it if the 'System Colours' button is pressed in
00317 //  if( ( pOpDesc->Token == String_256( OPTOKEN_PALETTE_SYSTEM_COLOURS ) ))
00318 //      if (BmapPrevDlg::IsU
00319 //              ( m_pDialog->IsSystemColours() ) )
00320 //          OpSt.Ticked = TRUE;
00321 
00322     return OpSt; 
00323 }
00324 
00325 
00326 /******************************************************************************************
00327 
00328 >   virtual void OpPreviewPopupCommand::Do( OpDescriptor* pOpDesc )
00329  
00330     Author:     Alex_Price (Xara Group Ltd) <camelotdev@xara.com>
00331 
00332     Created:    09/08/99
00333 
00334     Inputs:     pOpDesc - ?
00335 
00336     Returns:    -
00337 
00338     Purpose:    Handles the menu selection
00339 
00340 ******************************************************************************************/
00341 
00342 void OpPalettePopupCommand::Do( OpDescriptor* pOpDesc )
00343 {  
00344     ERROR3IF(!m_pPaletteControl,    "Help, I am the palette right click menu and I can't talk to the palette");
00345     ERROR3IF(!m_pBmapPrevDlg,       "Help, I am the palette right click menu and I can't talk to the preview dialog");
00346 
00347     //  Get the token of the item selected by the user.
00348     String_256 s(pOpDesc->Token);
00349 
00350 
00351     if (s.IsIdentical((TCHAR *)OPTOKEN_PALETTE_LOCKED))
00352          m_pPaletteControl->SetSelectedColourToggleLocked();
00353     else if (s.IsIdentical((TCHAR *)OPTOKEN_PALETTE_WEB_SAFE))
00354         m_pPaletteControl->SetSelectedColourWebSafe();
00355     else if (s.IsIdentical((TCHAR *)OPTOKEN_PALETTE_TRANSPARENT_BACKGROUND))
00356     {
00357         BmapPrevDlg::m_pExportOptions->SetBackgroundTransparency(!BmapPrevDlg::m_pExportOptions->IsBackgroundTransparent());
00358         m_pBmapPrevDlg->DoPreview();
00359     }
00360     else if (s.IsIdentical((TCHAR *)OPTOKEN_PALETTE_TRANSPARENT))
00361         m_pPaletteControl->SetSelectedColourToggleTransparent();
00362     else if (s.IsIdentical((TCHAR *)OPTOKEN_PALETTE_DELETE))
00363         m_pPaletteControl->SetSelectedColourToggleDeleted();
00364     else if (s.IsIdentical((TCHAR *)OPTOKEN_PALETTE_RESTORE))
00365         m_pPaletteControl->SetSelectedColourToggleDeleted();
00366     else if (s.IsIdentical((TCHAR *)OPTOKEN_PALETTE_SYSTEM_COLOURS))
00367         BmapPrevDlg::m_pExportOptions->SetToUseSystemPalette(!BmapPrevDlg::m_pExportOptions->IsUsingSystemPalette());
00368     else if (s.IsIdentical((TCHAR *)OPTOKEN_PALETTE_SORT_BY_USE))
00369     {
00370         m_pPaletteControl->SetCurrentSortType(BitmapExportPaletteInterface::SORT_USE);
00371         m_pPaletteControl->RenderSoon();
00372     }
00373     else if (s.IsIdentical((TCHAR *)OPTOKEN_PALETTE_SORT_BY_LUMINANCE))
00374     {
00375         m_pPaletteControl->SetCurrentSortType(BitmapExportPaletteInterface::SORT_LUMINANCE);
00376         m_pPaletteControl->RenderSoon();
00377     }
00378     else if (s.IsIdentical((TCHAR *)OPTOKEN_PALETTE_SORT_BY_HUE))
00379     {
00380         m_pPaletteControl->SetCurrentSortType(BitmapExportPaletteInterface::SORT_HUE);
00381         m_pPaletteControl->RenderSoon();
00382     }
00383 
00384     BmapPrevDlg::m_pExportOptions->InvalidatePalette();
00385     m_pBmapPrevDlg->UpdateCurrentTab();
00386     m_pBmapPrevDlg->DoPreview();
00387 
00388     End();
00389 }
00390 

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