stdbars.cpp

Go to the documentation of this file.
00001 // $Id: stdbars.cpp 1608 2006-07-29 20:34:08Z 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 #include "camtypes.h"
00100 
00101 DECLARE_SOURCE("$Revision: 1608 $");
00102 
00103 #include "stdbars.h"
00104 #include "statline.h"
00105 //#include "ops.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00106 #include "camelot.h"
00107 
00108 CC_IMPLEMENT_DYNCREATE(StandardBar, DialogOp)
00109 
00110 #define new CAM_DEBUG_NEW
00111 
00112 
00113 /********************************************************************************************
00114 
00115 >   class StandardBarMsg: public Msg
00116 
00117     Author:     Alex Bligh <alex@alex.org.uk>
00118     Created:    17/01/2006
00119     Purpose:    A tiny message local to the standard bar class
00120     SeeAlso:    -
00121 
00122 ********************************************************************************************/
00123 
00124 class StandardBarMsg: public Msg
00125 {
00126     CC_DECLARE_DYNAMIC(StandardBarMsg);
00127 
00128 public:
00129 
00130     enum StandardBarMsgType
00131     {
00132         HELLO,          // See if one exists
00133         CLOSE,          // Close one
00134         LAST
00135     };
00136 
00137     StandardBarMsgType m_MsgType;   // The message type
00138     OpDescriptor* m_pOpDescriptor;  // A pointer to the operation, can be NULL 
00139 
00140     StandardBarMsg(OpDescriptor* pOpDescriptor, StandardBarMsgType MsgType)
00141       : m_MsgType(MsgType), m_pOpDescriptor(pOpDescriptor)
00142         { /* empty */ }
00143 };
00144 
00145 CC_IMPLEMENT_DYNAMIC(StandardBarMsg, Msg);
00146 
00147 /********************************************************************************************
00148 
00149 >   static OpState StandardBar::GetState(String_256*, OpDescriptor*)
00150 
00151     Author:     Alex_Bligh <alex@alex.org.uk>
00152     Created:    17/01/2006
00153     Inputs:     (ignored)
00154     Outputs:    -
00155     Returns:    OpState
00156     Purpose:    GetState method
00157     Errors:     -
00158     SeeAlso:    -
00159 
00160 This needs to manually grey the OpDesc when there is a particular instance up. We have
00161 to use this because there legitimately more than one instance of this class about.
00162 
00163 ********************************************************************************************/
00164 
00165 OpState StandardBar::GetState(String_256*, OpDescriptor* pOpDesc)
00166 {
00167     // Note this is a STATIC method, else life would be far too easy
00168     OpState state;  
00169 
00170     // We can only send a message if at least one of our class exists (who knows why)
00171     if (MessageHandler::MessageHandlerExists(CC_RUNTIME_CLASS(StandardBar)))
00172     {
00173         // Send all message handlers of our class a message
00174         // For some reason we have to send it to all DialogOps - apparently we can't broadcast to a subclass
00175         MsgResult m = (BROADCAST_TO_CLASS(StandardBarMsg(pOpDesc, StandardBarMsg::HELLO), DialogOp));
00176         if (m != OK) state.Ticked=TRUE;
00177     }
00178     return state;
00179 }
00180 
00181 /********************************************************************************************
00182 
00183 >   static void StandardBar::BroadcastClose(OpDescriptor* pOpDesc)
00184 
00185     Author:     Alex_Bligh <alex@alex.org.uk>
00186     Created:    04-Mar-2006
00187     Inputs:     pOpDesc - opDescriptor of the standard bar type to close
00188     Outputs:    -
00189     Returns:    OpState
00190     Purpose:    GetState method
00191     Errors:     -
00192     SeeAlso:    -
00193 
00194 Close all StandardBars with the given OpDescriptor
00195 
00196 ********************************************************************************************/
00197 
00198 void StandardBar::BroadcastClose(OpDescriptor* pOpDesc)
00199 {
00200     if (MessageHandler::MessageHandlerExists(CC_RUNTIME_CLASS(StandardBar)))
00201     {
00202         // Send all message handlers of our class a message
00203         // For some reason we have to send it to all DialogOps - apparently we can't broadcast to a subclass
00204         BROADCAST_TO_CLASS(StandardBarMsg(pOpDesc, StandardBarMsg::CLOSE), DialogOp);
00205     }
00206 }
00207 
00208 /********************************************************************************************
00209 
00210 >   MsgResult StandardBar::Message( Msg* Message)
00211 
00212     Author:     Alex_Bligh <alex@alex.org.uk>
00213     Created:    17/01/2006
00214     Inputs:     Msg - pointer to message
00215     Outputs:    -
00216     Returns:    MsgResult
00217     Purpose:    Standard Message processor
00218     Errors:     -
00219     SeeAlso:    -
00220 
00221 This doesn't need to do much as the bitmap button controls handle their own clicks
00222 
00223 ********************************************************************************************/
00224 
00225 MsgResult StandardBar::Message( Msg* Msg)
00226 {
00227     if (Msg->IsKindOf(CC_RUNTIME_CLASS(StandardBarMsg)))
00228     {
00229         StandardBarMsg * pMsg = ((StandardBarMsg *)(Msg));
00230 
00231         // If we're already got one, EAT the message. Else OK, so pass on.
00232         if (pMsg->m_MsgType == StandardBarMsg::HELLO)
00233             return (pMsg->m_pOpDescriptor == m_pOpDesc)?EAT_MSG:OK;
00234         else if (pMsg->m_MsgType == StandardBarMsg::CLOSE)
00235         {
00236             if (pMsg->m_pOpDescriptor == m_pOpDesc)
00237             {
00238                 Close(); // Hide the dialog
00239                 m_pOpDesc = NULL; // zap out OpDescriptor pointer
00240                 End();
00241                 return OK;
00242             }
00243         }
00244         else
00245             return OK; // who knows what that is all about...
00246     }
00247 
00248     DialogMsg* DMsg = (DialogMsg*)Msg;
00249 
00250     if (IS_OUR_DIALOG_MSG(Msg))
00251     {
00252         // Handle ok button
00253         if ((DMsg->DlgMsg == DIM_COMMIT) || (DMsg->DlgMsg == DIM_CANCEL))
00254         {
00255             Close(); // Hide the dialog
00256             m_pOpDesc = NULL; // zap out OpDescriptor pointer
00257             End();
00258             return OK;
00259         }
00260     }
00261     
00262     return DialogOp::Message(Msg);
00263 }
00264 
00265 
00266 /********************************************************************************************
00267 
00268 >   static BOOL StandardBar::Init()
00269 
00270     Author:     Alex_Bligh <alex@alex.org.uk>
00271     Created:    17/01/2006
00272     Inputs:     -
00273     Outputs:    -
00274     Returns:    TRUE if successful
00275     Purpose:    Show the bar (when invoked)
00276     Errors:     -
00277     SeeAlso:    -
00278 
00279 ********************************************************************************************/
00280 
00281 BOOL StandardBar::Init()
00282 {
00283 
00284 // Note we can't use the "String for only one copy" feature because we allow multiple instances
00285 // of this class, provided they are all for different bars (sigh).
00286 #define RegisterStandardBarOpDescriptor(class, name) \
00287     (RegisterOpDescriptor( \
00288                         0, \
00289                         _R(IDS_BUTTBAR_M_ ## name ),                /*NORESOURCEFIX*/ \
00290                         CC_RUNTIME_CLASS(class), \
00291                         _T("IDD_BUTTBAR_") _T(#name),       /* Use Dialog ID as Optoken */  /*NORESOURCEFIX*/ \
00292                         class::GetState,                    /* GetState                 */ \
00293                         0,                                  /* help ID                  */ \
00294                         _R(IDBBL_BAR_ ## name),             /* Bubble help              */  /*NORESOURCEFIX*/ \
00295                         0,                                  /* Resource ID              */ \
00296                         _R(IDC_BTN_BAR_ ## name),           /* Control ID               */  /*NORESOURCEFIX*/ \
00297                         SYSTEMBAR_EDIT,                     /* Bar ID                   */ \
00298                         TRUE,                               /* Recieve system messages  */ \
00299                         FALSE,                              /* Smart duplicate operation*/ \
00300                         TRUE,                               /* Clean operation          */ \
00301                         0,                                  /* No vertical counterpart  */ \
00302                         0,                                  /* String for one copy only */ \
00303 /*                      _R(IDS_BAR_ ## name ## _ONE),          String for one copy only */  /*NORESOURCEFIX*/ \
00304                         0,                                  /* Auto state flags         */ \
00305                         TRUE                                /* Tickable                 */ \
00306                     ))
00307 
00308     return (
00309             RegisterStandardBarOpDescriptor(StandardBar, GENERAL) &&
00310             RegisterStandardBarOpDescriptor(StandardBar, IMAGESETTING) &&
00311             RegisterStandardBarOpDescriptor(StandardBar, WINDOW) &&
00312             RegisterStandardBarOpDescriptor(StandardBar, ARRANGE) &&
00313             RegisterStandardBarOpDescriptor(StandardBar, EDIT) &&
00314             RegisterStandardBarOpDescriptor(StandardBar, FILE) &&
00315             RegisterStandardBarOpDescriptor(StandardBar, GALLERIES) &&
00316             RegisterStandardBarOpDescriptor(StandardBar, STANDARD) &&
00317             RegisterStandardBarOpDescriptor(StandardBar, TOOLBAR) &&
00318             RegisterStandardBarOpDescriptor(StandardBar, ANIMATION) &&
00319             RegisterStandardBarOpDescriptor(StandardBar, FEATHER) &&
00320             RegisterStandardBarOpDescriptor(StatusLine, STATUS) &&
00321             TRUE);
00322 
00323 }
00324 
00325 /********************************************************************************************
00326 
00327 >   void StandardBar::Create(ResourceID dlg)
00328 
00329     Author:     Alex_Bligh <alex@alex.org.uk>
00330     Created:    17/01/2006
00331     Inputs:     dlg - Resource ID of dialog to use
00332     Outputs:    -
00333     Returns:    -
00334     Purpose:    Show the bar (when invoked)
00335     Errors:     -
00336     SeeAlso:    -
00337 
00338 ********************************************************************************************/
00339 
00340 BOOL StandardBar::Create(ResourceID dlg)
00341 {
00342     DlgResID = dlg; // Fortunately nothing needs this earlier
00343 
00344     // A quick hack to make the toolbar dock vertically
00345     m_Vertical = (dlg == _R(IDD_BUTTBAR_TOOLBAR))?TRUE:FALSE;
00346 
00347     if (DialogOp::Create())
00348     {
00349         // Set up  your gadgets here
00350 
00351         return TRUE;
00352     }
00353     else return FALSE;
00354 }
00355 
00356 /********************************************************************************************
00357 
00358 >   void StandardBar::Do(OpDescriptor* pOpDesc)
00359 
00360     Author:     Alex_Bligh <alex@alex.org.uk>
00361     Created:    17/01/2006
00362     Inputs:     pOpDesc - pointer to the OpDescriptor
00363     Outputs:    -
00364     Returns:    -
00365     Purpose:    Show or hide the bar (when invoked)
00366     Errors:     -
00367     SeeAlso:    -
00368 
00369 ********************************************************************************************/
00370 
00371 
00372 void StandardBar::Do(OpDescriptor* pOpDesc)
00373 {
00374     // First translate the bitmap button ID (which we use to determine which opdescriptor invoked
00375     // us) into a dialog ID
00376 
00377     ResourceID dlg = CamResource::GetResourceID((const TCHAR *)(pOpDesc->Token));
00378 
00379     if (dlg)
00380     {
00381         String_256 dummy;
00382         if (!GetState(&dummy,pOpDesc).Ticked)
00383         {
00384             m_pOpDesc = pOpDesc; // For identifying the OpDescriptor
00385             Create(dlg);
00386             Open();
00387         }
00388         else
00389         {
00390             StandardBar::BroadcastClose(pOpDesc);
00391             End(); // End this Op - The above won't do it because m_pOpDesc is NULL
00392         }
00393     }
00394 }
00395 
00396 

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