tool.cpp

Go to the documentation of this file.
00001 // $Id: tool.cpp 1535 2006-07-25 16:50:32Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 
00099 /*
00100 */
00101 
00102 // Handles lists of Tools loaded from Modules
00103 
00104 #include "camtypes.h"
00105 #include "toollist.h"
00106 //#include "ensure.h"
00107 //#include "mainfrm.h"
00108 //#include "errors.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 //#include "tool.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 //#include "opdesc.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00111 #include "dlgmgr.h"
00112 //#include "bars.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00113 //#include "basebar.h"
00114 //#include "ink.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00115 #include "keypress.h"
00116 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00117 #include "blobs.h"
00118 #include "toolmsg.h"
00119 #include "usercord.h"
00120 
00121 #define SELECTED TRUE
00122 #define DESELECTED FALSE
00123 
00124 CC_IMPLEMENT_DYNAMIC(ToolsCurrentAttrGroupChangedMsg, Msg);
00125 
00126 
00127 /********************************************************************************************
00128 
00129 >   class TempToolItem : public ListItem
00130 
00131     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00132     Created:    8/12/94
00133     Purpose:    Item that represent a temp tool selection
00134     Errors:     -
00135     SeeAlso:    Tool::ActivateTemporaryTool(), Tool::DeactivateTemporaryTool()
00136 
00137 
00138 ********************************************************************************************/
00139 
00140 class TempToolItem : public ListItem
00141 {
00142 CC_DECLARE_MEMDUMP(TempToolItem)
00143 public:
00144     TempToolItem() { pTempTool = pPrevTool = NULL; }
00145 
00146     Tool*   GetTempTool()                   { return pTempTool; }
00147     void    SetTempTool(Tool* pThisTool)    { pTempTool = pThisTool; }
00148 
00149     Tool*   GetPrevTool()                   { return pPrevTool; }
00150     void    SetPrevTool(Tool* pThisTool)    { pPrevTool = pThisTool; }
00151 
00152 private:
00153     Tool* pTempTool;
00154     Tool* pPrevTool;
00155 };
00156 
00157 
00158 //-------------------------------------------------------------
00159 
00160 /********************************************************************************************
00161 
00162 >   class ToolSwitch : public ListItem
00163 
00164     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00165     Created:    30/8/94
00166     Purpose:    Holds a key press that will temporarily switch to another tool
00167     Errors:     -
00168     SeeAlso:    -
00169 
00170 ********************************************************************************************/
00171 
00172 class ToolSwitch : public ListItem
00173 {
00174 CC_DECLARE_MEMDUMP(ToolSwitch)
00175 
00176 public:
00177     ToolSwitch(Tool* pThisTool,KeyPress* pKeyPress,BOOL FromFile);
00178     ~ToolSwitch();
00179 
00180     Tool*       pTool;              // The tool
00181     KeyPress*   pKeyPress;          // The key press that will activate the tool
00182 
00183     BOOL        Temp        : 1;    // TRUE if this switch is temporary
00184     BOOL        DefFromFile : 1;    // TRUE if defined from a file
00185 
00186     static ToolSwitch* pCurrentToolSwitch;
00187 };
00188 
00189 // The ToolSwitch that is currently active
00190 ToolSwitch* ToolSwitch::pCurrentToolSwitch = NULL;
00191 
00192 // List of all the tool switching key combinations for all the tools
00193 List ToolSwitchList;
00194 
00195 
00196 /********************************************************************************************
00197 
00198 >   ToolSwitch::ToolSwitch(Tool* pThisTool, KeyPress* pThisKeyPress, BOOL FromFile)
00199 
00200     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00201     Created:    30/8/94
00202     Inputs:     pThisTool       = the tool this key press will activate
00203                 pThisKeyPress   = ptr to the key press combination that activates the tool
00204                 FromFile        = TRUE if defined from a file, FALSE if a direct definition (usu. direct from a tool) 
00205     Outputs:    -
00206     Returns:    -
00207     Purpose:    The constructor.  Creates a ToolSwitch object that represents a key press combination
00208                 that invokes the given tool
00209     Errors:     -
00210     SeeAlso:    -
00211 
00212 ********************************************************************************************/
00213 
00214 ToolSwitch::ToolSwitch(Tool* pThisTool, KeyPress* pThisKeyPress, BOOL FromFile)
00215 {
00216     pTool       = pThisTool;
00217     pKeyPress   = pThisKeyPress;
00218     Temp        = FALSE;
00219     DefFromFile = FromFile;
00220 }
00221 
00222 /********************************************************************************************
00223 
00224 >   ToolSwitch::~ToolSwitch()
00225 
00226     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00227     Created:    6/9/94
00228     Inputs:     0
00229     Outputs:    -
00230     Returns:    -
00231     Purpose:    Default destructor.
00232                 Main job is to delete the key press object it constains
00233     Errors:     -
00234     SeeAlso:    -
00235 
00236 ********************************************************************************************/
00237 
00238 ToolSwitch::~ToolSwitch()
00239 {
00240     if (pKeyPress != NULL)
00241     {
00242         delete pKeyPress;
00243         pKeyPress = NULL;
00244     }
00245 }
00246 
00247 //-------------------------------------------------------------
00248 
00249 // Runtime class support for debug builds
00250 CC_IMPLEMENT_MEMDUMP(ToolInfo_v1, CCObject)
00251 CC_IMPLEMENT_MEMDUMP(ToolInfo, ToolInfo_v1)
00252 CC_IMPLEMENT_MEMDUMP(Tool_v1, CCObject)
00253 CC_IMPLEMENT_MEMDUMP(Tool, Tool_v1)
00254 CC_IMPLEMENT_MEMDUMP(ToolSwitch,ListItem)
00255 CC_IMPLEMENT_MEMDUMP(TempToolItem,ListItem);
00256 
00257 
00258 // Declare smart memory handling in Debug builds
00259 #define new CAM_DEBUG_NEW
00260 
00261 
00262 DECLARE_SOURCE("$Revision: 1535 $");
00263 
00264 ToolList *Tool::Tools = NULL;
00265 
00266 Tool*   Tool::Current  = NULL;                  // Pointer to the current tool
00267 //Tool*     Tool::PrevTool = NULL;                  // Pointer to the temporarily deselected tool when a
00268                                                 // tool is temporarily active.
00269 BOOL    Tool::ToolChanging = FALSE;             // TRUE while the current tool is changing
00270 BOOL    Tool::PendingDeactivateTempTool = FALSE;// TRUE while waiting to deactivate the temporary tool after a drag
00271 
00272 List    Tool::TempToolList;                     // Holds a record per stacked temp tool
00273 
00274 UINT32  Tool::InitTool;                         // Used as a pref - maintains current tool id
00275 
00276 
00277 /********************************************************************************************
00278 
00279 >   ToolInfo_v1::ToolInfo_v1()
00280 
00281     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00282     Created:    10/6/94
00283     Inputs:     -
00284     Outputs:    -
00285     Returns:    -
00286     Purpose:    For specifying default tool structure values 
00287     Errors:     -
00288     SeeAlso:    -
00289 
00290 ********************************************************************************************/
00291 
00292 ToolInfo_v1::ToolInfo_v1()
00293 {          
00294     // When specifying current attributes most of the time we will want to add the
00295     // attribute to the NodeRenderableInk current attribute group.
00296     CurrentAttributeGroup = CC_RUNTIME_CLASS(NodeRenderableInk); 
00297 }
00298 
00299 /********************************************************************************************
00300 
00301 >   BOOL Tool::InitToolList()
00302 
00303     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00304     Created:    1/7/93
00305     Inputs:     -
00306     Outputs:    -
00307     Returns:    TRUE if list initialised ok, FALSE otherwise.
00308     Purpose:    Initialise the static ToolList object which holds all tools that the kernel
00309                 knows about.
00310     Errors:     Assert if list is already initialised.
00311 
00312 ********************************************************************************************/
00313 
00314 BOOL Tool::InitToolList()
00315 {
00316     ENSURE(Tools == NULL, "Attempt to initialise the ToolList more than once");
00317     Tools = new ToolList;
00318     return (Tools != NULL);
00319 }
00320 
00321 
00322 
00323 /********************************************************************************************
00324 
00325 >   BOOL Tool::InitTools()
00326 
00327     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00328     Created:    21/6/93
00329     Inputs:     None
00330     Outputs:    None
00331     Returns:    TRUE if OK, FALSE for catastrophic failure
00332     Purpose:    Called at the end of initialisation (as it may well need all other 
00333                 initialisations to have been done) to add Tools and Modules to the Kernel's
00334                 knowledgebase.
00335     Errors:     None
00336     Scope:      Public
00337 
00338 ********************************************************************************************/
00339 
00340 BOOL Tool::InitTools()
00341 {
00342     BOOL Finished;
00343     
00344     do
00345     {
00346         // All the tools have been 'new'ed now. We can now ask them to initialise themselves.
00347         // If they don't want to, they get 'delete'ed.
00348 
00349         ToolListItem *Item = (ToolListItem *) Tools->GetHead();
00350         
00351         Finished = TRUE;
00352         
00353         while (Item != NULL)
00354         {
00355             Tool *Tool = Item->m_pTool;
00356             
00357             // If this tool exists and has not been initialised yet, then try to
00358             // initialise it.  If it initialises ok, set the item's flag, and force
00359             // another scan of the remaining tools in case one of them depends on
00360             // this tool being present.
00361             if( NULL != Tool && 
00362                 !Item->m_fInitialised && 
00363                 Tool->Init() )
00364             {
00365                 Item->m_fInitialised = TRUE;    // Tool initialised ok.
00366                 Finished = FALSE;           // At least one more loop to try
00367             }
00368 
00369             // Try the next tool
00370             Item = (ToolListItem *) Tools->GetNext(Item);
00371         }
00372         
00373     } while (!Finished);
00374 
00375     // Delete any un-initialised tools
00376     ToolListItem *Item = (ToolListItem *) Tools->GetHead();
00377 
00378     while (Item != NULL)
00379     {
00380         ToolListItem *NextItem = (ToolListItem*) Tools->GetNext(Item);
00381 
00382         if ((Item->m_pTool != NULL) && (!Item->m_fInitialised))
00383         {
00384             // the Tool didn't want to play, so remove it
00385             
00386             // we've already got the next item, so its OK to kill the old one
00387 
00388             delete Tools->RemoveItem( Item );               // remove from list & free up
00389         }
00390 
00391         // Try the next tool
00392         Item = NextItem;
00393     }
00394 
00395     
00396     // default to Selector tool in case we cant find a pref
00397     InitTool = TOOLID_SELECTOR;
00398     
00399     // declare a pref
00400     if( Camelot.DeclareSection( _T("InitialTool"), 1 ) )
00401         Camelot.DeclarePref( _T("InitialTool"), _T("InitTool"), &InitTool );
00402                 
00403     return TRUE;                                    // no error return possible at present
00404 }
00405 
00406 
00407 
00408 /********************************************************************************************
00409 >   static void Tool::SelectFirstTool()
00410 
00411     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00412     Created:    9/1/95
00413     Inputs:     -
00414     Outputs:    -
00415     Returns:    -
00416     Purpose:    Selects the tool that is retrieved from the prefs file.
00417                 If no pref is found will default to Selector Tool -
00418                 If the appropriate tool can't be found the first will be used instead
00419     Errors:     -
00420     SeeAlso:    Tool::InitTools
00421 ********************************************************************************************/
00422 
00423 void Tool::SelectFirstTool()
00424 {   
00425 
00426 // look for the initial tool
00427 ToolListItem* pItem = (ToolListItem*) Find(InitTool);
00428 
00429 // if we can't find it go for the first
00430 if(pItem == NULL)
00431     pItem = (ToolListItem*) Tools->GetHead();
00432 
00433 if (pItem != NULL && pItem->m_pTool != NULL) pItem->m_pTool->SetCurrent();
00434 
00435 }
00436 
00437 
00438 
00439 /********************************************************************************************
00440 
00441 >   BOOL Tool::Declare(Tool *NewTool, UINT32 ParentID)
00442 
00443     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00444     Created:    1/7/93
00445     Inputs:     NewTool - Pointer to a new Tool and its ID
00446                 ParentID - Module ID of the module that provides this tool.
00447     Outputs:    None
00448     Returns:    Pointer to new tool list item.
00449     Purpose:    Called by OIL code to declare new tool types.
00450     Errors:     Will return NULL if invalid ID or same tool ID used twice.
00451 
00452 ********************************************************************************************/
00453 
00454 ToolListItem *Tool::Declare(Tool *NewTool, UINT32 ParentID)
00455 {
00456     // Try to add the tool to the kernel's list.
00457     ToolListItem *NewItem = Tools->Add(NewTool, ParentID);
00458     
00459     if (NewItem == NULL)
00460     {
00461         // Tool has invalid ID - print error message and destroy tool.
00462         ToolInfo Info;
00463         NewTool->Describe(&Info);
00464         TRACE( _T("Tool %u is invalid\n"), Info.ID);
00465         delete NewTool;
00466     }
00467     
00468     return NewItem;
00469 }
00470 
00471 
00472 
00473 /********************************************************************************************
00474 
00475 >   static UINT32 Tool::GetNumTools()
00476 
00477     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00478     Created:    13/9/93
00479     Returns:    The number of tools registered with the kernel.
00480     Purpose:    Find out how many tools have registered and initialised successfully.
00481 
00482 ********************************************************************************************/
00483 
00484 UINT32 Tool::GetNumTools()
00485 {
00486     if (Tools == NULL)
00487         return 0;
00488     else
00489         return (UINT32) Tools->GetCount();
00490 }
00491 
00492 
00493 
00494 /********************************************************************************************
00495 
00496 >   Tool *Tool::Find(UINT32 id)
00497 
00498     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00499     Created:    1/7/93
00500     Inputs:     Tool ID
00501     Outputs:    None
00502     Returns:    Pointer to required tool, or NULL if not found.
00503     Purpose:    Anyone can ask about a tool's presence by its ID.
00504     Errors:     None
00505 
00506 ********************************************************************************************/
00507 
00508 ToolListItem *Tool::Find(UINT32 ToolID)
00509 {
00510     // Simple search of list for ID
00511     
00512     ToolListItem *Item = (ToolListItem *) Tools->GetHead();
00513     
00514     while (Item != NULL)
00515     {
00516         if (Item->m_ToolInfo.ID == ToolID)
00517             // Found ID - return pointer to its tool.
00518             return Item;
00519         
00520         Item = (ToolListItem *) Tools->GetNext(Item);
00521     }
00522     
00523     // Not found
00524     return NULL;
00525 }
00526 
00527 
00528 
00529 /********************************************************************************************
00530 
00531 >   Tool* Tool::FindTool(UINT32 id)
00532 
00533     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
00534     Created:    19/11/2004
00535     Inputs:     Tool ID
00536     Outputs:    None
00537     Returns:    Pointer to required tool, or NULL if not found.
00538     Purpose:    Anyone can ask about a tool's presence by its ID.
00539                 But Geez! The caller doesn't want to know about ToolListItems!!!
00540     Errors:     None
00541 
00542 ********************************************************************************************/
00543 
00544 Tool* Tool::FindTool(UINT32 ToolID)
00545 {
00546     ToolListItem* pItem = Find(ToolID);
00547     if (pItem)
00548         return pItem->m_pTool;
00549 
00550     return NULL;
00551 }
00552 
00553 
00554 
00555 /********************************************************************************************
00556 
00557 >   static UINT32 Tool::GetModuleID(UINT32 ToolID)
00558 
00559     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00560     Created:    20/8/93
00561     Inputs:     Tool ID
00562     Outputs:    None
00563     Returns:    Module ID of parent module, or 0 if not found.
00564     Purpose:    Particulary useful for error handling, it allows the owner module ID to be
00565                 determined given just a tool ID.
00566     Errors:     0 if cannot be found.
00567 
00568 ********************************************************************************************/
00569 
00570 UINT32 Tool::GetModuleID(UINT32 ToolID)
00571 {
00572     if ( ToolID == TOOLID_INVALID ) return 0;               // If unknown tool do nothing!
00573 
00574     const ToolListItem *Tool = Tool::Find(ToolID);
00575 
00576     if (Tool)
00577         return Tool->m_ToolInfo.ParentModuleID;             // return ID if found
00578     else
00579         return 0;                                           // 0=not found
00580 }
00581 
00582 /********************************************************************************************
00583 
00584 >   void  Tool::SetButtons(BOOL State) 
00585 
00586     Author:     Chris_Parks (Xara Group Ltd) <camelotdev@xara.com>
00587     Created:    6/6/94
00588     Inputs:     State to set buttons to
00589     Outputs:    None
00590     Returns:    None
00591     Purpose:    Selects/Deselects the buttons associated with this buttons.
00592     Errors:     None
00593 
00594 ********************************************************************************************/
00595 
00596 void  Tool::SetButtons(BOOL State) 
00597 {
00598 #if !defined(EXCLUDE_FROM_RALPH)
00599         String OpToken;
00600         camSnprintf(OpToken, 16, _T("TOOL%u"), GetID());
00601         ToolOpDescriptor* ToolOp = (ToolOpDescriptor *) OpDescriptor::FindOpDescriptor(OpToken);
00602 
00603         // Keep Select state in the OpDescriptor
00604         ToolOp->SetCurrentTool(State);
00605         
00606         List * pGadgetList = new List;
00607         if (pGadgetList == 0)
00608         {
00609             InformError();
00610             return;
00611         }
00612         //Build list of all controls linked to this Op
00613         if (!ToolOp->BuildGadgetList(pGadgetList))
00614         {
00615             TRACEUSER( "Chris", _T("Couldn't build gadget list in Tool::SetCurrent\n"));
00616             delete pGadgetList;
00617             return;
00618         }
00619         ListItem* pListItem = pGadgetList->GetHead();
00620         while (pListItem != NULL)
00621         {
00622             // Set the Select State  of each gadget 
00623             GadgetListItem* pGadgetItem = (GadgetListItem*) pListItem;
00624             pGadgetItem->pDialogOp->SetLongGadgetValue(pGadgetItem->gidGadgetID,
00625                                                             State,
00626                                                             FALSE,
00627                                                             FALSE);
00628             // Do the next control in the list, if any.
00629             pListItem = pGadgetList->GetNext(pListItem);
00630         }
00631 
00632         // Don't forget to delete the list afterwards!
00633         pGadgetList->DeleteAll();
00634         delete pGadgetList;
00635 #endif
00636 }
00637 
00638 /********************************************************************************************
00639 
00640 >   void  Tool::SetCurrent() 
00641 
00642     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
00643     Created:    19/8/93
00644     Inputs:     None
00645     Outputs:    None
00646     Returns:    None
00647     Purpose:    Sets the 'this' tool to be the current tool.
00648     Errors:     None
00649 
00650 ********************************************************************************************/
00651 
00652 void  Tool::SetCurrent() 
00653 {
00654     if(Current == this)
00655     { 
00656         // Ensure the buttons are set right
00657         Current->SetButtons(SELECTED);
00658         return ;
00659     }
00660 
00661     SetToolChangingState(TRUE);
00662     // Deselect current tool
00663  
00664     
00665     if (Current)
00666     {
00667         Current->SetButtons(DESELECTED);
00668         Current->SelectChange(FALSE);
00669         OpDescriptor::RemoveAllAliases();
00670     }
00671 
00672     // Find the CurrentAttributeGroup associated with the Tool we are switching away from
00673     CCRuntimeClass* OldCurrentAttrGroup = NULL; 
00674     if (Current)
00675         OldCurrentAttrGroup = Current->Parent->m_ToolInfo.CurrentAttributeGroup;
00676 
00677     // Select new tool.
00678     Current = this;
00679     
00680      SetButtons(SELECTED);  
00681 
00682     // Inform tool that it has been selected.
00683     SelectChange(TRUE);
00684     
00685     // save ID in preference
00686     InitTool = GetID();
00687 
00688     SetToolChangingState(FALSE);
00689 
00690     TempToolItem* pTempToolItem = (TempToolItem*)TempToolList.GetHead();
00691     if (pTempToolItem != NULL && pTempToolItem->GetTempTool() != Current)
00692         DeleteTempToolList();
00693 
00694     // Finally if the CurrentAttributeGroup has changed then tell people
00695     if (Parent->m_ToolInfo.CurrentAttributeGroup != OldCurrentAttrGroup)
00696     {
00697         BROADCAST_TO_ALL(ToolsCurrentAttrGroupChangedMsg); 
00698     }
00699 }
00700 
00701 
00702 
00703 /********************************************************************************************
00704 
00705 >   void Tool::DeinitTools()
00706 
00707     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
00708     Created:    21/6/93
00709     Inputs:     None
00710     Outputs:    None
00711     Returns:    None
00712     Purpose:    Deletes all allocated tools. Safe to call more than once.
00713     
00714                 Do NOT try to use any tools after calling this.
00715 
00716     Errors:     None
00717 
00718 ********************************************************************************************/
00719 
00720 void Tool::DeinitTools()
00721 {
00722     if (Tools != NULL)
00723     {
00724         // Deselect the current tool, if there is one.
00725         if (Current)
00726         {
00727             Current->SelectChange(FALSE);
00728             Current = 0;
00729         }
00730 
00731         // Delete the tool list.
00732         delete Tools;
00733         Tools = NULL;
00734     }
00735 
00736     ToolSwitchList.DeleteAll();
00737     DeleteTempToolList();
00738 }
00739 
00740 
00741 
00742 /********************************************************************************************
00743 
00744 >   OILTool *Tool::GetOILTool(UINT32 ID)
00745 
00746     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00747     Created:    6/7/93
00748     Inputs:     ID - The ID of the Tool
00749     Outputs:    -
00750     Returns:    Pointer to the OILTool object for this tool.
00751     Purpose:    Given a Tool ID, returns a pointer to the OILTool object associated
00752                 with this tool.
00753     Errors:     Returns NULL if the associated OILTool object does not exist (maybe
00754                 the tool ID is invalid?)
00755     SeeAlso:    ToolListItem
00756 
00757 ********************************************************************************************/
00758 
00759 OILTool *Tool::GetOILTool(UINT32 ID)
00760 {
00761     /*ToolListItem *Item =*/ Find(ID);
00762 //  return Item ? Item->m_pOILTool : NULL;
00763     return NULL;
00764 }
00765 
00766 
00767 /********************************************************************************************
00768 
00769 >   void Tool::ActivateTemporaryTool(Tool *pTempTool)
00770 
00771     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00772     Created:    04/05/94
00773     Inputs:     pTempTool - the tool to be made active.
00774     Purpose:    Temporarily invoke the specified tool.  This is called when the user
00775                 holds down modifier keys to switch tools - this function remembers the
00776                 currently active tool and will switch back to it when you call
00777                 Tool::DeactivateTemporaryTool().
00778                 It is ok to keep calling this without first deactivating the temporary
00779                 tool - the system will correctly remember which tool was originally
00780                 active and restore it when all DeactivateTemporaryTool() is called.
00781     SeeAlso:    Tool::DeactivateTemporaryTool
00782 
00783 ********************************************************************************************/
00784 
00785 void Tool::ActivateTemporaryTool(Tool *pTempTool)
00786 {
00787     // If the current tool is not temporary, then remember it so we can revert
00788     // to it when the user lets go of the hot-keys.
00789 
00790     // NB. We have to make this test so if the user invokes one tool, then another in such
00791     // a way that the original tool si not switched back to inbetween, then things will
00792     // go wrong and we won't return to the original tool.
00793 
00794     TempToolItem* pTempToolItem = new TempToolItem;
00795     if (pTempToolItem != NULL)
00796     {
00797         pTempToolItem->SetPrevTool(Current);
00798         pTempToolItem->SetTempTool(pTempTool);
00799         TempToolList.AddHead(pTempToolItem);
00800 
00801 //      if (PrevTool == NULL)
00802 //          PrevTool = Current;
00803         //Current->SelectChange(FALSE);
00804         // Find the instance of the ToolOpDescriptor
00805         String_64       OpToken;
00806         camSnprintf( OpToken, 64, _T("TOOL%u"), pTempTool->GetID() );
00807         ToolOpDescriptor* ToolOp = (ToolOpDescriptor *) OpDescriptor::FindOpDescriptor(OpToken);
00808 
00809         // Use the OpDescriptor to invoke the tool (i.e. make it become the selected tool)
00810         ToolOp->Invoke();
00811     }
00812 }
00813 
00814 /********************************************************************************************
00815 
00816 >   void Tool::DeactivateTemporaryTool()
00817 
00818     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00819     Created:    04/05/94
00820     Purpose:    Deactivate the temporary tool and restore the original one.
00821     SeeAlso:    void Tool::DeactivateTemporaryTool()
00822 
00823 ********************************************************************************************/
00824 
00825 void Tool::DeactivateTemporaryTool()
00826 {
00827 /*  // Do nothing if we don't have a previous tool
00828     if (PrevTool == NULL) return;
00829 
00830     // If the previous tool is the current one, don't have to do nowt
00831     if (PrevTool == Current) return;
00832 */
00833     TempToolItem* pTempToolItem = (TempToolItem*)TempToolList.RemoveHead();
00834 
00835     // Only do something if we have a temp tool item
00836     if (pTempToolItem != NULL)
00837     {
00838         UINT32 PrevToolID = pTempToolItem->GetPrevTool()->GetID();
00839 
00840         // We don't need this temp tool item any more.
00841         delete pTempToolItem;
00842         pTempToolItem = NULL;
00843 
00844         // Find the instance of the ToolOpDescriptor
00845         String_64       OpToken;
00846         camSnprintf( OpToken, 64, _T("TOOL%u"), PrevToolID );
00847         ToolOpDescriptor* ToolOp = (ToolOpDescriptor *) OpDescriptor::FindOpDescriptor(OpToken);
00848 
00849         // Use the OpDescriptor to invoke the tool (i.e. make it become the selected tool)
00850         ToolOp->Invoke();
00851     }
00852 
00853 
00854     // Not temporary any more
00855 //  PrevTool = NULL;
00856 }
00857 
00858 
00859 /********************************************************************************************
00860 
00861 >   void Tool::DeleteTempToolList()
00862 
00863     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00864     Created:    8/12/94
00865     Returns:    -
00866     Purpose:    This deletes all temp tool items in the list temp tools.
00867                 After this call, the temp tool stacking info is lost.
00868                 This should be called whenever a user selects a new tool directly (i.e. via clicking on
00869                 the tool icon, a hot key, or menu item).
00870     SeeAlso:    Tool::ActivateTemporaryTool; Tool::DeactivateTemporaryTool
00871 
00872 ********************************************************************************************/
00873 
00874 void Tool::DeleteTempToolList()
00875 {
00876     TempToolList.DeleteAll();
00877 }
00878 
00879 /********************************************************************************************
00880 
00881 >   BOOL Tool::IsCurrentToolTemporary()
00882 
00883     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
00884     Created:    04/05/94
00885     Returns:    TRUE if the tool is temporary;
00886                 FALSE if not.
00887     Purpose:    Check to see if the currently active tool is permanently or temporarily
00888                 active. If, e.g. the user is holding down ALT to get the selector tool,
00889                 then this returns TRUE.
00890     SeeAlso:    Tool::ActivateTemporaryTool; Tool::DeactivateTemporaryTool
00891 
00892 ********************************************************************************************/
00893 
00894 /*
00895 BOOL Tool::IsCurrentToolTemporary()
00896 {
00897     // If PrevTool is not NULL, then we are waiting for the user to let go of the
00898     // modifier keys so we can change back to the original tool.
00899     return (PrevTool != NULL);
00900 }
00901 */
00902 
00903 /********************************************************************************************
00904 
00905 >   void Tool::SetToolChangingState(BOOL state)
00906 
00907     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00908     Created:    25/05/94
00909     Inputs:     state - boolean used to set ToolChanging flag
00910     Outputs:    -
00911     Returns:    -
00912     Purpose:    Lets you set the ToolChanging flag
00913     SeeAlso:    -
00914 
00915 ********************************************************************************************/
00916 
00917 void Tool::SetToolChangingState(BOOL state)
00918 {
00919     ToolChanging = state;
00920 }
00921 
00922 /********************************************************************************************
00923 
00924 >   BOOL Tool::IsToolChanging()
00925 
00926     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00927     Created:    25/05/94
00928     Inputs:     -
00929     Outputs:    -
00930     Returns:    TRUE  - tool is in the middle of changing
00931                 FALSE - oh no it's not!
00932     Purpose:    Lets you see the state of the ToolChanging flag
00933     SeeAlso:    -
00934 
00935 ********************************************************************************************/
00936 
00937 BOOL Tool::IsToolChanging()
00938 {
00939     return (ToolChanging);
00940 }
00941 
00942 /********************************************************************************************
00943 
00944 >   static BOOL Tool::SwitchTool(KeyPress* pKeyPress)
00945 
00946     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
00947     Created:    30/8/94
00948     Inputs:     pKeyPress = ptr to the key press that's just occurred
00949     Outputs:    -
00950     Returns:    TRUE  - the key press caused a tool switch, do not pass on
00951                 FALSE - no tool switching, see if anyone else wants it
00952     Purpose:    The place where tool switching takes place.
00953     SeeAlso:    -
00954 
00955 ********************************************************************************************/
00956 
00957 BOOL Tool::SwitchTool(KeyPress* pKeyPress)
00958 {
00959     BOOL Processed = FALSE;
00960 
00961     BOOL DuringADrag = (Operation::GetCurrentDragOp() != NULL);
00962 #if !defined(EXCLUDE_FROM_RALPH) && !defined(EXCLUDE_FROM_XARALX)
00963     DuringADrag = (DuringADrag || BaseBar::IsDragging());
00964 #endif
00965 
00966     ToolSwitch* pToolSwitch = (ToolSwitch*)ToolSwitchList.GetHead();
00967     while (pToolSwitch != NULL && !Processed)
00968     {
00969         // Is it a tool switch key press?
00970         if (*pToolSwitch->pKeyPress == *pKeyPress)
00971         {
00972             // This key press is a tool switch combination for a tool
00973 
00974             // Are we waiting to deactivate the temp tool at the end of a drag?
00975             if (!PendingDeactivateTempTool)
00976             {
00977                 // We are NOT wait to deactivate the temp tool at the end of a drag, so proceed
00978 
00979                 // pTool is the ptr to the tool in question
00980                 Tool* pTool = pToolSwitch->pTool;
00981 
00982                 // Is it a "key down" key press?
00983                 if (pKeyPress->IsPress())
00984                 {
00985                     // It's a "key down" event
00986 
00987                     // Is it the first "key down", or has it auto-repeated?
00988                     if (!pKeyPress->IsRepeat())
00989                     {
00990                         // It's the first press
00991 
00992                         // is it already the current tool?
00993                         if (pTool != Current)
00994                         {
00995                             // We now have the first "key down" of a tool switch for a tool that
00996                             // is NOT the current tool
00997                             
00998                             // is a drag happening?
00999                             if (!DuringADrag)
01000                             {
01001                                 // If we are not doing this during a drag, make it the current tool.
01002                                 // Also, set the Temp flag to FALSE as it may be a permanent change
01003                                 ActivateTemporaryTool(pTool);
01004                                 pToolSwitch->Temp = FALSE;
01005                             }
01006                         }
01007                         else
01008                         {
01009                             // We now have the first "key down" of a tool switch for a tool that
01010                             // IS the current tool
01011                             
01012                             // If we are not dragging, deactivate the tool
01013                             if (!DuringADrag)
01014                                 DeactivateTemporaryTool();
01015                             else
01016                                 // Remember to deactivate the tool after the drag has ended
01017                                 PendingDeactivateTempTool = TRUE;
01018                         }
01019                     }
01020                     else
01021                     {
01022                         // It's an auto-repeated key press
01023 
01024                         // if the switch belongs to the current tool, and is auto-repeated
01025                         // make the switch temporary 
01026                         if (pTool == Current)
01027                             pToolSwitch->Temp = TRUE;
01028                     }
01029                 }
01030                 else
01031                 {
01032                     // It's a "key up" event
01033 
01034                     // Does it belong to the current tool?
01035                     if (pTool == Current)
01036                     {
01037                         // "Key up" on a tool switch for the current tool.
01038                         // If the current tool was selected temporarily, select the previous current tool
01039                         if (pToolSwitch->Temp)
01040                         {
01041                             // If we are not dragging, deactivate the tool
01042                             if (!DuringADrag)
01043                                 DeactivateTemporaryTool();
01044                             else
01045                                 // Remember to deactivate the tool after the drag has ended
01046                                 PendingDeactivateTempTool = TRUE;
01047                         }
01048                     }
01049                 }
01050             }
01051 
01052             // The key press object was a tool switching one, so we have processed the key press
01053             Processed = TRUE;
01054         }
01055 
01056         // Get the next tool switch in the list
01057         pToolSwitch = (ToolSwitch*)ToolSwitchList.GetNext(pToolSwitch);
01058     }
01059 
01060     return Processed;
01061 }
01062 
01063 /********************************************************************************************
01064 
01065 >   static void Tool::EndDrag()
01066 
01067     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01068     Created:    5/9/94
01069     Inputs:     -
01070     Outputs:    -
01071     Returns:    -
01072     Purpose:    This is called when a drag ends
01073     SeeAlso:    ServicePendingToolChange
01074 
01075 ********************************************************************************************/
01076 
01077 void Tool::EndDrag()
01078 {
01079     ServicePendingToolChange();
01080 }
01081 
01082 /********************************************************************************************
01083 
01084 >   static void Tool::OnActivateApp(BOOL bActive)
01085 
01086     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01087     Created:    6/2/96
01088     Inputs:     bActive - this is ignored
01089     Outputs:    -
01090     Returns:    -
01091     Purpose:    This is called when the app's active state changes
01092     SeeAlso:    ServicePendingToolChange
01093 
01094 ********************************************************************************************/
01095 
01096 void Tool::OnActivateApp(BOOL bActive)
01097 {
01098     ServicePendingToolChange();
01099 }
01100 
01101 /********************************************************************************************
01102 
01103 >   static void Tool::ServicePendingToolChange()
01104 
01105     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01106     Created:    6/2/96
01107     Inputs:     -
01108     Outputs:    -
01109     Returns:    -
01110     Purpose:    This is called when a drag ends, or the app's active state changes
01111                 This will deactivate the temporary tool if a deactivate key event was encounted
01112                 during a drag
01113     SeeAlso:    EndDrag(), OnActivateApp()
01114 
01115 ********************************************************************************************/
01116 
01117 void Tool::ServicePendingToolChange()
01118 {
01119     if (PendingDeactivateTempTool)
01120     {
01121         DeactivateTemporaryTool();
01122         PendingDeactivateTempTool = FALSE;
01123     }
01124 }
01125 
01126 /********************************************************************************************
01127 > static void Tool::RemoveDirectRegToolSwitches(Tool* pThisTool)
01128 
01129     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01130     Created:    6/9/94
01131     Inputs:     pThisTool = the tool in question
01132     Outputs:    -
01133     Returns:    -
01134     Purpose:    This goes through the list of registered tool switches and removes all
01135                 switches that belong to the given tool and were defined directly, 
01136                 i.e. ones that were NOT defined via a file
01137     Errors:     -
01138                                                                  
01139 ********************************************************************************************/
01140 
01141 void Tool::RemoveDirectRegToolSwitches(Tool* pThisTool)
01142 {
01143     ToolSwitch* pToolSwitch;
01144     ToolSwitch* pNextToolSwitch = (ToolSwitch*)ToolSwitchList.GetHead();
01145 
01146     while (pNextToolSwitch != NULL)
01147     {
01148         pToolSwitch     = pNextToolSwitch;
01149         pNextToolSwitch = (ToolSwitch*)ToolSwitchList.GetNext(pNextToolSwitch);
01150 
01151         if (pToolSwitch->pTool == pThisTool && !pToolSwitch->DefFromFile)
01152         {
01153             // if this tool switch belongs to the given tool 
01154             // and it was a directly defined one, remove it from
01155             // the list and delete it
01156 
01157             ToolSwitchList.RemoveItem(pToolSwitch);
01158             delete pToolSwitch;
01159         }
01160     }
01161 }
01162 
01163 
01164 //-------------------------------------------------------------------------------------------
01165 //-------------------------------------------------------------------------------------------
01166 //-------------------------------------------------------------------------------------------
01167 //-------------------------------------------------------------------------------------------
01168 //-------------------------------------------------------------------------------------------
01169 
01170 //-------------------------------------------------------------------------------------------
01171 // Empty functions for the default tool.
01172 
01173 /********************************************************************************************
01174 
01175 >   BOOL Tool_v1::Init()
01176 
01177     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
01178     Created:    21/6/93
01179     Inputs:     -
01180     Outputs:    -
01181     Returns:    TRUE if OK, FALSE if tool doesn't want to initialise.
01182     Purpose:    Called after tool's constructor to ask it whether it wants to exist or
01183                 not. Each tool is asked in two passes, so that its existence can depend
01184                 on another tool. If a tool does not want to exist, it should return FALSE,
01185                 when it will be deleted.
01186     Errors:     None
01187 
01188 ********************************************************************************************/
01189 
01190 BOOL Tool_v1::Init()
01191 {
01192     ENSURE(FALSE, "Init called for base tool class!");
01193     return FALSE;                   // Should never try to instantiate a tool base class
01194 }
01195 
01196 
01197 
01198 /********************************************************************************************
01199 
01200 >   Tool_v1::~Tool_v1()
01201 
01202     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
01203     Created:    7/7/93
01204     Inputs:     -
01205     Outputs:    -
01206     Returns:    -
01207     Purpose:    Destroys the tool, performing any clean-up necessary.
01208     Errors:     -
01209     SeeAlso:    -
01210 
01211 ********************************************************************************************/
01212 
01213 Tool_v1::~Tool_v1()
01214 {
01215     // Null destructor
01216 }
01217 
01218 
01219 
01220 /********************************************************************************************
01221 
01222 >   BOOL Tool_v1::Describe(void *Infoptr)
01223 
01224     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
01225     Created:    21/6/93
01226     Inputs:     Pointer to area to recieve info
01227     Outputs:    Info area is updated
01228     Returns:    None
01229     Purpose:    Asks a tool for more information. The pointer points to a struct such as
01230                 ToolInfo_v1 which the tool should fill in. All fields should be filled
01231                 (NULL is OK for char* variables). The type of the pointer is not explicitly
01232                 defined so the structure can evolve while keeping backward compatibility.
01233     Errors:     None
01234 
01235 ********************************************************************************************/
01236 
01237 void Tool_v1::Describe(void *InfoPtr)
01238 {
01239     ENSURE(FALSE, "Describe called for base tool class!");
01240     
01241     // Cast structure into the latest one we understand.
01242     ToolInfo_v1 *Info = (ToolInfo_v1 *) InfoPtr;
01243     
01244     Info->InfoVersion = 1;
01245     
01246     Info->InterfaceVersion = GetToolInterfaceVersion();  // You should always have this line.
01247     
01248     // These are all garbage as we should never try to create one of these...
01249     Info->Version = 1;
01250     Info->ID = TOOLID_INVALID;
01251     Info->TextID = 0;
01252     
01253     // so we never get instantiated
01254     Info->Family = Info->Name = Info->Purpose = Info->Author = NULL;
01255 }
01256 
01257 
01258 
01259 /********************************************************************************************
01260 
01261 >   void Tool_v1::OnClick(DocCoord PointerPos, ClickType Click,
01262                             ClickModifiers Mods, Spread* pSpread)
01263 
01264     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
01265     Created:    2/7/93
01266     Inputs:     Position of click in spread coordinates
01267                 Click type (single, double or drag)
01268                 Modifiers (adjusted, constrained, etc...)
01269                 Pointer to the spread in which the click occurred
01270     Outputs:    None
01271     Returns:    None
01272     Purpose:    This function should be overridden by any tool that wants to receive clicks
01273                 on the document. When DocView receives a click event from the OIL layer it
01274                 finds the current tool and calls this function.
01275     Errors:     None.
01276                                                                  
01277 ********************************************************************************************/
01278 
01279 void Tool_v1::OnClick(DocCoord /*PointerPos*/, ClickType /*Click*/,
01280                         ClickModifiers /*Mods*/, Spread* /*pSpread*/)
01281 {
01282     ENSURE(FALSE, "OnClick called for base tool class!");
01283     
01284     // DO nothing!
01285     // Click not handled by base class!
01286 }
01287 
01288 
01289 
01290 /********************************************************************************************
01291 >   void Tool_v1::OnMouseMove(DocCoord mousepos, Spread* pSpread, ClickModifiers)
01292 
01293     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
01294     Created:    14 Oct 93
01295     Inputs:     Position of the mouse, in spread coordinates
01296                 Pointer to the spread in which the mouse lies.
01297                 Which button/keys are down.
01298     Outputs:    -
01299     Returns:    -
01300     Purpose:    This function should be overridden by any tool that wants to receive mouse
01301                 move messages, when a drag is NOT in progress.  For example, tools can use
01302                 this function to change the mouse cursor as it moves over a "hot spot".  The
01303                 default implementation does nothing.
01304     Errors:     -
01305                                                                  
01306 ********************************************************************************************/
01307 
01308 void Tool_v1::OnMouseMove(DocCoord, Spread*, ClickModifiers)
01309 {
01310     // Do nothing at all, if you like.  It's your tool!
01311 }
01312 
01313 
01314 
01315 /********************************************************************************************
01316 >   BOOL Tool_v1::OnKeyPress(KeyPress* pKeyPress)
01317 
01318     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01319     Created:    30/8/94
01320     Inputs:     pKeyPress = Ptr to a platform-indy key press object
01321     Outputs:    -
01322     Returns:    TRUE  - the key press was processed, so do NOT pass on
01323                 FALSE - not processed, so let others have a bash
01324     Purpose:    This function should be overridden by any tool that wants to process key presses.
01325                 The current tool is the first part of Camelot that gets the chance to process
01326                 a key press, so tools can override all tool-switching and hot-key combinations
01327                 if it needs to.
01328     Errors:     -
01329                                                                  
01330 ********************************************************************************************/
01331 
01332 BOOL Tool_v1::OnKeyPress(KeyPress* pKeyPress)
01333 {
01334     // Return FALSE so the key press gets passed on to others
01335     return FALSE;
01336 }
01337 
01338 
01339 
01340 /********************************************************************************************
01341 >   BOOL Tool_v1::OnIdle()
01342 
01343     Author:     Peter_Arnold (Xara Group Ltd) <camelotdev@xara.com>
01344     Created:    14/09/94
01345     Inputs:     -
01346     Outputs:    -
01347     Returns:    TRUE  - the tool wants more idle events.
01348                 FALSE - no more idle events are required.
01349     Purpose:    This function should be overridden by any tool that wants to do processing
01350                 on idle events.  This processing should be quick (or split into small, quick
01351                 bits).  Once processing is finished FALSE should be returned (although this
01352                 does not guarentee then function will not be called again).
01353     Errors:     -
01354                                                                  
01355 ********************************************************************************************/
01356 
01357 BOOL Tool_v1::OnIdle()
01358 {
01359     // Return FALSE to turn off
01360     return FALSE;
01361 }
01362 
01363 /********************************************************************************************
01364 >   BOOL Tool_v1::GetStatusLineText(String_256* StatusLineText, Spread* pSpread, DocCoord DocPos, ClickModifiers Mods)
01365 
01366     Author:     Ed_Cornes (Xara Group Ltd) <camelotdev@xara.com>
01367     Created:    14/11/94
01368     Returns:    TRUE if returning valid text
01369     Purpose:    Each tool should override this function to return valid status line text
01370 ********************************************************************************************/
01371 
01372 BOOL Tool_v1::GetStatusLineText(String_256* ptext, Spread* pSpread, DocCoord DocPos, ClickModifiers ClickMods)
01373 {
01374     return FALSE;   // defaults to no text
01375 }
01376 
01377 /********************************************************************************************
01378 >   BOOL Tool_v1::RegisterToolSwitch(KeyPress* pKeyPress,BOOL FromFile = FALSE)
01379 
01380     Author:     Mark_Neves (Xara Group Ltd) <camelotdev@xara.com>
01381     Created:    30/8/94
01382     Inputs:     pKeyPress = Ptr to a platform-indy key press object
01383                 FromFile  = TRUE if the tool switch was defined in a file
01384                             FALSE if it's being registered directly
01385     Outputs:    -
01386     Returns:    TRUE  - the key press has been registered for temporary switching to this tool
01387                 FALSE - failed. Either another tool has this combo, or the keypress is invalid
01388 
01389     Purpose:    This allows you to specify a key press that will be used to switch to the tool
01390                 temporarily.  The pKeyPress should be a valid one created by one of its public constructors.
01391 
01392                 If the FromFile flag is TRUE then all registered tool switches for this tool that have been 
01393                 registered directly (i.e. by the tool itself calling this routine with FromFile==FALSE) 
01394                 are deleted.
01395 
01396                 The means that tool switches defined in file take priority over directly defined ones, so
01397                 that in the future we may allow the user to choose which key presses he wants to temp tool
01398                 switching. 
01399                 Also means that a tool can have temp switching codes with defs in a file; useful for third
01400                 party tools who can't get hold of the bound in kernel resource file.
01401     Errors:     -
01402     SeeAlso:    KeyPress::KeyPress
01403                                                                  
01404 ********************************************************************************************/
01405 
01406 BOOL Tool_v1::RegisterToolSwitch(KeyPress* pKeyPress,BOOL FromFile)
01407 {
01408     ENSURE(pKeyPress->IsValid(),"Tool trying to register a tool key switch with an invalid key press object");
01409     if (!pKeyPress->IsValid()) return FALSE;
01410 
01411     Tool* pThisTool = (Tool*)this;
01412 
01413     if (FromFile) Tool::RemoveDirectRegToolSwitches(pThisTool);
01414 
01415     ToolSwitch* pToolSwitch = (ToolSwitch*)ToolSwitchList.GetHead();
01416     while (pToolSwitch != NULL)
01417     {
01418         if (pToolSwitch->pTool == pThisTool)
01419         {
01420             // if this tool switch has already been assigned for this tool, return TRUE
01421             if (*pToolSwitch->pKeyPress == *pKeyPress)
01422             {
01423                 delete pKeyPress;
01424                 return TRUE;
01425             }
01426         }
01427         else
01428         {
01429             // If this tool switch belongs to another tool, return FALSE
01430             if (*pToolSwitch->pKeyPress == *pKeyPress)
01431                 return FALSE;
01432         }
01433 
01434         pToolSwitch = (ToolSwitch*)ToolSwitchList.GetNext(pToolSwitch);
01435     }
01436 
01437     // At this point we know that it is safe to assign the tool switch key press for this tool
01438 
01439     // Make a new tool switch
01440     ToolSwitch* pNewToolSwitch = new ToolSwitch(pThisTool,pKeyPress,FromFile);
01441 
01442     if (pNewToolSwitch != NULL)
01443         ToolSwitchList.AddTail(pNewToolSwitch);
01444 
01445     return (pNewToolSwitch != NULL);
01446 }
01447 
01448 /********************************************************************************************
01449 
01450 >   virtual BOOL Tool_v1::DragFinished(DragEndType HowEnded)
01451 
01452     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
01453     Created:    26/8/94
01454     Inputs:     HowEnded - Describes how the drag ended (an if it was a drag at all really
01455     Returns:    TRUE if it is OK for the operation to finish doing the things that it was
01456                 going to do, or FALSE if the tool wants the operation to stop right now.
01457     Purpose:    Tools that start drag operations can use this function to find out how well
01458                 the drag went if the operation calls this function.
01459 
01460 ********************************************************************************************/
01461 
01462 BOOL Tool_v1::DragFinished(DragEndType HowEnded)
01463 {
01464     // Do nothing in the base class version of this function.
01465     // Just let the operation get on with what it was doing
01466     return TRUE;
01467 }
01468 
01469 /********************************************************************************************
01470 
01471 >   BOOL Tool_v1::IsCurrent() const
01472 
01473     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
01474     Created:    18/10/94
01475     Returns:    TRUE if 'this' is the current tool, FALSE if not.
01476     Purpose:    Centralised way of doing this. Amazing this function didn't exist before.
01477 
01478 ********************************************************************************************/
01479 
01480 BOOL Tool_v1::IsCurrent() const
01481 {
01482     if (Tool::GetCurrent() == this)
01483         return TRUE;
01484     else
01485         return FALSE;
01486 }
01487 
01488 /********************************************************************************************
01489 
01490 >   void Tool_v1::RenderToolBlobs()
01491 
01492     Author:     Rik_Heywood (Xara Group Ltd) <camelotdev@xara.com>
01493     Created:    18/8/93
01494     Purpose:    This function is called in the main drawing loop to get the tool
01495                 to render its blobs (ie the centre of rotation for the rotation
01496                 tool). Since this is the base class version of this function and
01497                 will be called if the tool does not provide its own RenderToolBlobs
01498                 function, then it can be assumed that the tool does not need to 
01499                 draw anything, so it does nothing.
01500     SeeAlso:    DocView::RenderOnTop
01501 
01502 ********************************************************************************************/
01503 
01504 void Tool_v1::RenderToolBlobs(Spread *, DocRect*)
01505 {
01506     // If the tool does not want to draw anything then it need not have a 
01507     // RenderToolBlobs function and this one will be called instead.
01508     // This draws nothing
01509 }
01510 
01511 /********************************************************************************************
01512 
01513 >   void Tool_v1::SelectChange(BOOL IsSelected)
01514 
01515     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
01516     Created:    11/11/93
01517     Inputs:     IsSelected - Indicates whether tool is being selected (TRUE) or
01518                              deselected (FALSE).
01519     Purpose:    Used to inform a tool that it is being selected or deselected.  Default
01520                 behaviour is to do nothing.  A real tool should update the infobar when the 
01521                 tool is selected - this is usually all a tool will do.
01522 
01523 ********************************************************************************************/
01524 
01525 void Tool_v1::SelectChange(BOOL /*IsSelected*/)
01526 {
01527     // Override me!
01528 }
01529 
01530 /********************************************************************************************
01531 
01532 >   void Tool_v1::GetRulerOrigin(Spread* pSpread, UserCoord* pOffsets)
01533 
01534     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
01535     Created:    30/Jun/2006
01536     Inputs:     pSpread - the spread for which the ruler is displayed
01537     Outputs:    pOffsets - the desired origin shift in user space (is initialised to 0,0)
01538     Purpose:    Gives the current tool the chance to change the coordinates
01539                 displayed on the ruler
01540 
01541 ********************************************************************************************/
01542 
01543 void Tool_v1::GetRulerOrigin(Spread* pSpread, UserCoord* pOffsets)
01544 {
01545     // Override me if you want!
01546     // Note that overriding this function implies that you will ensure the redraw of the rulers
01547     // as you enter and leave your tool.
01548 }
01549 
01550 /********************************************************************************************
01551 
01552 >   void Tool_v1::RenderRulerBlobs(RulerBase* pRuler, UserRect& UpdateRect, BOOL IsBackground)
01553 
01554     Author:     Martin Wuerthner <xara@mw-software.com>
01555     Created:    07/07/06
01556     Inputs:     pRuler - the ruler that is currently being redrawn
01557                 UpdateRect - the rectangle to be updated in user coordinates (with the tool
01558                              origin applied)
01559                 IsBackground - whether this is the call before drawing the main blobs
01560                                or the call after rendering the main blobs
01561     Purpose:    Gives the current tool the chance to render additional blobs on the ruler
01562                 Is called twice - once before the standard ruler graphics are rendered
01563                 (to allow additional background to be drawn) and once afterwards
01564 
01565 ********************************************************************************************/
01566 
01567 void Tool_v1::RenderRulerBlobs(RulerBase* pRuler, UserRect& UpdateRect, BOOL IsBackground)
01568 {
01569     // Override me if you want!
01570     // Note that overriding this function implies that you will ensure the redraw of the rulers
01571     // as you enter and leave your tool.
01572 }
01573 
01574 /********************************************************************************************
01575 
01576 >   virtual BOOL Tool_v1::GetRulerStatusLineText(String_256* pText, UserCoord PointerPos, Spread* pSpread,
01577                                                  RulerBase* pRuler)
01578     Author:     Martin Wuerthner <xara@mw-software.com>
01579     Created:    25/07/2006
01580     Inputs:     PointerPos  - user coordinates of click on ruler (relative to origin set by tool)
01581                 pSpread     - pointer to spread upon which click occurred
01582                 pRuler      - pointer to ruler which generated click
01583     Outputs:    pText - status line text set (if return value is TRUE)
01584     Returns:    TRUE if the text has been set
01585     Purpose:    Gives the current tool the chance to change the status line text displayed for the ruler
01586 
01587 ********************************************************************************************/
01588 
01589 BOOL Tool_v1::GetRulerStatusLineText(String_256* pText, UserCoord PointerPos, Spread* pSpread,
01590                                      RulerBase* pRuler)
01591 {
01592     // Override me if you want!
01593     return FALSE;
01594 }
01595 
01596 /********************************************************************************************
01597 
01598 >   virtual BOOL Tool_v1::OnRulerClick( DocCoord PointerPos,
01599                                         ClickType Click,
01600                                         ClickModifiers Mods,
01601                                         Spread* pSpread
01602                                       )
01603     Author:     Phil_Martin (Xara Group Ltd) <camelotdev@xara.com>
01604     Created:    30/Jun/2006
01605     Inputs:     PointerPos  - user coordinates of click on ruler (relative to origin set by tool)
01606                 Click       - Type of click enum
01607                 Mods        - Modifier flags struct
01608                 pSpread     - pointer to spread upon which click occurred
01609                 pRuler      - pointer to ruler which generated click
01610     Outputs:    -
01611     Returns:    TRUE if this click event was handled
01612                 FALSE if not
01613     Purpose:    Gives the current tool the chance to handle ruler clicks in preference
01614                 to other handlers
01615 
01616 ********************************************************************************************/
01617 
01618 BOOL Tool_v1::OnRulerClick( UserCoord PointerPos,
01619                             ClickType Click,
01620                             ClickModifiers Mods,
01621                             Spread* pSpread,
01622                             RulerBase* pRuler
01623                             )
01624 {
01625     // Override me if you want!
01626     return FALSE;
01627 }
01628 
01629 
01630 
01631 
01632 /********************************************************************************************
01633 
01634 >   virtual void Tool_v1::CurrentDocViewChange()
01635 
01636     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
01637     Created:    10/12/93
01638     Inputs:     -
01639     Outputs:    -
01640     Returns:    -
01641     Purpose:    Called for the currently-selected tool when the current DocView changes. 
01642     Errors:     -
01643     SeeAlso:    -
01644 
01645 ********************************************************************************************/
01646 
01647 //void Tool_v1::CurrentDocViewChange()
01648 //{
01649 //  // Override me!
01650 //}
01651 
01652 
01653 
01654 
01655 /********************************************************************************************
01656 
01657 >   virtual void SelectedDocViewChange()
01658 
01659     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
01660     Created:    10/12/93
01661     Inputs:     -
01662     Outputs:    -
01663     Returns:    -
01664     Purpose:    Called when the selected DocView changes, ie. the user has moved the focus
01665                 to another document view window.
01666     Errors:     -
01667     SeeAlso:    -
01668 
01669 ********************************************************************************************/
01670 
01671 //void Tool_v1::SelectedDocViewChange()
01672 //{
01673 //  // Override me!
01674 //}
01675 
01676 
01677 
01678 /********************************************************************************************
01679 
01680 >   void Tool_v1::UpdateInfoBar()
01681 
01682     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
01683     Created:    12/11/93
01684     Purpose:    Allows the Tool to update the info bar according to its internal settings
01685                 and values.  Usually called when the info bar is first created and when a
01686                 new tool becomes selected.
01687 
01688 ********************************************************************************************/
01689 
01690 /* Removed by MarkN 25/7/94
01691 void Tool_v1::UpdateInfoBar()
01692 {
01693 }
01694 */
01695 
01696 
01697 /********************************************************************************************
01698 
01699 >   void Tool_v1::HandleInfoBarMessage(CDlgMessage Message, CGadgetID ID)
01700 
01701     Author:     Tim_Browse (Xara Group Ltd) <camelotdev@xara.com>
01702     Created:    13/11/93
01703     Inputs:     Message - the message (see kernel\dlgtypes.h).
01704                 ID - the ID of the dialog gadget that generated the message.
01705     Purpose:    Allows the tool to handle UI events from the info bar.  It is similar to
01706                 the DialogOp::HandleMessage function.
01707     SeeAlso:    DialogOp::HandleMessage
01708 
01709 ********************************************************************************************/
01710 
01711 // Removed by MarkN 25/7/94
01712 //void Tool_v1::HandleInfoBarMessage(CDlgMessage /* Message*/, CGadgetID /*ID*/)
01713 //{
01714 //}
01715 
01716 
01717 
01718 /********************************************************************************************
01719 
01720 >   static ToolListItem* Tool::GetFirstTool()
01721 
01722     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com> 
01723     Created:    19/8/93
01724     Returns:    A pointer to the first tool if list is not empty and NULL otherwise
01725     Purpose:    returns the first Tool in the list
01726 
01727 ********************************************************************************************/
01728 ToolListItem* Tool::GetFirstTool()  
01729 { 
01730     if (Tool::Tools)
01731         return (ToolListItem*) Tool::Tools->GetHead(); 
01732     else
01733         return NULL;
01734 }
01735 
01736 
01737     
01738 /********************************************************************************************
01739 
01740 >   static ToolListItem* Tool::GetNextTool( ToolListItem* CurrTool )
01741 
01742     Author:     Mario_Shamtani (Xara Group Ltd) <camelotdev@xara.com>
01743     Created:    19/8/93
01744     Inputs:     pointer to last Tool return by GetFirst ot GetNextDescriptor
01745     Returns:    A pointer to the first tool if list is not empty and NULL otherwise
01746     Purpose:    return the next Tool in the list
01747 
01748 ********************************************************************************************/
01749 ToolListItem* Tool::GetNextTool( ToolListItem* CurrTool )
01750 { 
01751     if (Tool::Tools)
01752         return (ToolListItem*) Tool::Tools->GetNext( CurrTool ); 
01753     else
01754         return NULL;
01755 }
01756 
01757 
01758 // these two static functions used to be in-lines. They were'nt commented in there either
01759 
01760 /********************************************************************************************
01761 
01762 >   Tool *Tool::GetCurrent()
01763 
01764     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
01765     Created:    19/10/94
01766     Returns:    A pointer to the current tool, or NULL if there isn't one.
01767     Purpose:    Determine the current tool.
01768     Scope:      Public static
01769 
01770 ********************************************************************************************/
01771 
01772 Tool *Tool::GetCurrent()
01773 {
01774     return Current;
01775 }
01776 
01777 /********************************************************************************************
01778 
01779 >   void Tool::SetNoCurrent()
01780 
01781     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
01782     Created:    19/10/94
01783     Purpose:    Sets no tool as the current tool.
01784     Scope:      Public static
01785 
01786 ********************************************************************************************/
01787 
01788 void Tool::SetNoCurrent()
01789 {
01790     if (Current)
01791     {
01792         Current->SelectChange(FALSE);
01793     }
01794     Current = NULL; 
01795 }
01796 
01797 /********************************************************************************************
01798 
01799 >   UINT32 Tool::GetCurrentID()
01800 
01801     Author:     Andy_Pennell (Xara Group Ltd) <camelotdev@xara.com>
01802     Created:    19/10/94
01803     Returns:    The ID of the current tool, or 0 if none is selected.
01804     Purpose:    Determine the current tool.
01805     Scope:      Public static
01806 
01807 ********************************************************************************************/
01808 
01809 UINT32 Tool::GetCurrentID()
01810 {
01811     if (Current)
01812         return Current->GetID();
01813     else
01814         return 0;
01815 }

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