la_base.cpp

Go to the documentation of this file.
00001 // $Id: la_base.cpp 1282 2006-06-09 09:46:49Z alex $
00002 /* @@tag:xara-cn@@ DO NOT MODIFY THIS LINE
00003 ================================XARAHEADERSTART===========================
00004  
00005                Xara LX, a vector drawing and manipulation program.
00006                     Copyright (C) 1993-2006 Xara Group Ltd.
00007        Copyright on certain contributions may be held in joint with their
00008               respective authors. See AUTHORS file for details.
00009 
00010 LICENSE TO USE AND MODIFY SOFTWARE
00011 ----------------------------------
00012 
00013 This file is part of Xara LX.
00014 
00015 Xara LX is free software; you can redistribute it and/or modify it
00016 under the terms of the GNU General Public License version 2 as published
00017 by the Free Software Foundation.
00018 
00019 Xara LX and its component source files are distributed in the hope
00020 that it will be useful, but WITHOUT ANY WARRANTY; without even the
00021 implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00022 See the GNU General Public License for more details.
00023 
00024 You should have received a copy of the GNU General Public License along
00025 with Xara LX (see the file GPL in the root directory of the
00026 distribution); if not, write to the Free Software Foundation, Inc., 51
00027 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
00028 
00029 
00030 ADDITIONAL RIGHTS
00031 -----------------
00032 
00033 Conditional upon your continuing compliance with the GNU General Public
00034 License described above, Xara Group Ltd grants to you certain additional
00035 rights. 
00036 
00037 The additional rights are to use, modify, and distribute the software
00038 together with the wxWidgets library, the wxXtra library, and the "CDraw"
00039 library and any other such library that any version of Xara LX relased
00040 by Xara Group Ltd requires in order to compile and execute, including
00041 the static linking of that library to XaraLX. In the case of the
00042 "CDraw" library, you may satisfy obligation under the GNU General Public
00043 License to provide source code by providing a binary copy of the library
00044 concerned and a copy of the license accompanying it.
00045 
00046 Nothing in this section restricts any of the rights you have under
00047 the GNU General Public License.
00048 
00049 
00050 SCOPE OF LICENSE
00051 ----------------
00052 
00053 This license applies to this program (XaraLX) and its constituent source
00054 files only, and does not necessarily apply to other Xara products which may
00055 in part share the same code base, and are subject to their own licensing
00056 terms.
00057 
00058 This license does not apply to files in the wxXtra directory, which
00059 are built into a separate library, and are subject to the wxWindows
00060 license contained within that directory in the file "WXXTRA-LICENSE".
00061 
00062 This license does not apply to the binary libraries (if any) within
00063 the "libs" directory, which are subject to a separate license contained
00064 within that directory in the file "LIBS-LICENSE".
00065 
00066 
00067 ARRANGEMENTS FOR CONTRIBUTION OF MODIFICATIONS
00068 ----------------------------------------------
00069 
00070 Subject to the terms of the GNU Public License (see above), you are
00071 free to do whatever you like with your modifications. However, you may
00072 (at your option) wish contribute them to Xara's source tree. You can
00073 find details of how to do this at:
00074   http://www.xaraxtreme.org/developers/
00075 
00076 Prior to contributing your modifications, you will need to complete our
00077 contributor agreement. This can be found at:
00078   http://www.xaraxtreme.org/developers/contribute/
00079 
00080 Please note that Xara will not accept modifications which modify any of
00081 the text between the start and end of this header (marked
00082 XARAHEADERSTART and XARAHEADEREND).
00083 
00084 
00085 MARKS
00086 -----
00087 
00088 Xara, Xara LX, Xara X, Xara X/Xtreme, Xara Xtreme, the Xtreme and Xara
00089 designs are registered or unregistered trademarks, design-marks, and/or
00090 service marks of Xara Group Ltd. All rights in these marks are reserved.
00091 
00092 
00093       Xara Group Ltd, Gaddesden Place, Hemel Hempstead, HP2 6EX, UK.
00094                         http://www.xara.com/
00095 
00096 =================================XARAHEADEREND============================
00097  */
00098 /*
00099 
00100     Line-attributes combo-box OpDescriptor abstract base class.
00101 
00102 */
00103 
00104 #include "camtypes.h"
00105 //#include "undoop.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00106 //#include "dialogop.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00107 #include "lineattr.h"
00108 //#include "document.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00109 //#include "convert.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00110 #include "attrappl.h"
00111 //#include "mario.h"
00112 //#include "simon.h"
00113 //#include "justin.h"
00114 //#include "bars.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00115 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00116 //#include "selmsg.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00117 //#include "range.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00118 //#include "attrmgr.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00119 //#include "tool.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00120 #include "la_base.h"
00121 
00122 #define new CAM_DEBUG_NEW
00123 
00124 
00125 /********************************************************************************************
00126 >   OpChangeLineAttribOpDesc::OpChangeLineAttribOpDesc(UINT32 nTxtID,
00127                                                        const TCHAR* lpcszToken,
00128                                                        UINT32 nBubbleID,
00129                                                        UINT32 nControlID)
00130     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00131     Created:    3/3/95
00132     Inputs:     -
00133     Outputs:    -
00134     Returns:    -
00135     Purpose:    Simply calls the UndoableOpDescriptor::UndoableOpDescriptor base class
00136     Errors:     -
00137     SeeAlso:    UndoableOpDescriptor::UndoableOpDescriptor
00138 ********************************************************************************************/
00139 
00140 OpChangeLineAttribOpDesc::OpChangeLineAttribOpDesc(UINT32 nTxtID,
00141                                                    const TCHAR* lpcszToken,
00142                                                    UINT32 nBubbleID,
00143                                                    UINT32 nControlID)
00144   : UndoableOpDescriptor(0,
00145                          nTxtID,
00146                          CC_RUNTIME_CLASS(OpApplyAttribToNode),
00147                          (TCHAR*) lpcszToken,
00148                          GetState,
00149                          0,
00150                          nBubbleID,
00151                          0,
00152                          nControlID,
00153                          TRUE,                          // will receive messages
00154                          FALSE,
00155                          FALSE)
00156 {
00157     // Empty.
00158 }
00159 
00160 
00161 
00162 /********************************************************************************************
00163 >   void OpChangeLineAttribOpDesc::SetGadgetText(const String& strGadgetText)
00164 
00165     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00166     Created:    26/4/95
00167     Inputs:     strGadgetText           the text to show in the OpDescriptor's gadgets
00168     Purpose:    Sets the text in the combos associated with this OpDescriptor.
00169 ********************************************************************************************/
00170 
00171 void OpChangeLineAttribOpDesc::SetGadgetText(const String& strGadgetText)
00172 {
00173     // Create a list for the dialogue manager to put gadget ID's on.
00174     List* pGadgetList = new List;
00175     if (pGadgetList == NULL)
00176     {
00177         InformError(_R(IDE_NOMORE_MEMORY));
00178         return;
00179     }
00180 
00181     // Obtain a list of all the combo controls.
00182     if (BuildGadgetList(pGadgetList))
00183     {
00184         // Iterate over each control in the list.
00185         for (GadgetListItem* pGadgetItem = (GadgetListItem*) pGadgetList->GetHead(); 
00186              pGadgetItem != NULL; 
00187              pGadgetItem = (GadgetListItem*) pGadgetList->GetNext(pGadgetItem))
00188         {
00189             // Set each control to display the text.
00190             pGadgetItem->pDialogOp->SetStringGadgetValue(pGadgetItem->gidGadgetID, 
00191                                                             ((String&) strGadgetText),
00192                                                             FALSE, -1);
00193         }
00194 
00195         // Tidy up.
00196         pGadgetList->DeleteAll();
00197     }
00198 
00199     // Deallocate gadget list.
00200     delete pGadgetList;
00201 } 
00202 
00203 
00204 
00205 /********************************************************************************************
00206     BOOL OpChangeLineAttribOpDesc::SetCurrentSelJoin()
00207 
00208     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00209     Created:    10/3/95
00210     Outputs:    -
00211     Returns:    FALSE if we run out of memory etc.
00212     Purpose:    Sets the currently selected line width value. 
00213 
00214                 If no objects are selected, or no selected objects require a join type
00215                 attribute then the current join type attribute for the tool is displayed.
00216 
00217                 If all selected objects (which require a join type) share the same join 
00218                 type attribute then this is displayed.
00219                 
00220                 if the selected objects have more than one join type value then the 
00221                 string 'MANY' is displayed. 
00222 
00223     Errors:     ERROR is set if we run out of memory
00224     Scope:      private
00225     SeeAlso:    -
00226 ********************************************************************************************/
00227 
00228 BOOL OpChangeLineAttribOpDesc::SetCurrentSelectedAttrib()
00229 {
00230     // Nothing to do if no current document.
00231     if (Document::GetCurrent() == NULL)
00232     {
00233 /*      TRACEUSER( "JustinF", _T("No current document in OpChangeLineAttribOpDesc")
00234                              "::SetCurrentSelectedAttrib\n");
00235 */      
00236         // There is no document so blank all gadgets.
00237         SetGadgetText(String(_T("")));
00238         return TRUE;
00239     }
00240 
00241     // Determine if there is a common attribute.
00242     NodeAttribute* pAttr;
00243     SelRange::CommonAttribResult eResult;
00244     eResult = GetApplication()->
00245                  FindSelection()->
00246                      FindCommonAttribute(GetAttribRuntimeClass(), &pAttr);
00247 
00248     // Work out what to put in the combo-box according to the returned result.
00249     UINT32 nTxtID;
00250     switch (eResult)
00251     {
00252         case SelRange::ATTR_COMMON:
00253         case SelRange::ATTR_NONE:
00254         {
00255             // If there isn't an attribute we just return (this logic is copied from the
00256             // line-width combo OpDescriptor code).
00257             if (pAttr == NULL)
00258             {
00259 /*              TRACEUSER( "JustinF", _T("No attribute in OpChangeLineAttribOpDesc")
00260                                      "::SetCurrentSelectedAttrib\n");
00261 */              return TRUE;
00262             }
00263 
00264             // Check for something screwy.
00265             ERROR3IF(pAttr->GetRuntimeClass() != GetAttribRuntimeClass(),
00266                      "Wrong kind of attribute in OpChangeLineAttribOpDesc"
00267                      "::SetCurrentSelectedAttrib");
00268 
00269             // There is, so call the derived class to provide some text.
00270             nTxtID = ConvertAttribToStringID(pAttr);
00271             if (nTxtID == 0)
00272             {
00273                 ERROR3("Unexpected attribute type in OpChangeLineAttribOpDesc"
00274                        "::SetCurrentSelectedAttrib!");
00275                 return FALSE;
00276             }
00277             break; 
00278         }
00279 
00280         case SelRange::ATTR_MANY:
00281             nTxtID = _R(IDS_MANY);
00282             break;
00283 
00284         default:
00285             ERROR3("Unexpected case in OpChangeLineAttribOpDesc::SetCurrentSelectedAttrib!");
00286             return FALSE;
00287     }
00288 
00289     // Set the gadget's text.
00290     SetGadgetText(String(nTxtID));
00291     return TRUE;
00292 }
00293 
00294 
00295 
00296 /********************************************************************************************
00297     virtual void OpChangeLineAttribOpDesc::OnControlCreate(OpDescControlCreateMsg* pCreateMsg);
00298 
00299     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00300     Created:    10/3/95
00301     Inputs:     -
00302     Outputs:    -
00303     Returns:    -
00304     Purpose:    This function is called whenever a combo control associated with the 
00305     `           OpDescriptor gets created. 
00306     Errors:     -
00307     SeeAlso:    -
00308 ********************************************************************************************/
00309 
00310 void OpChangeLineAttribOpDesc::OnControlCreate(OpDescControlCreateMsg* pCreateMsg)
00311 {
00312     // Initialise the combo-box with the join types.
00313     DialogOp* pDlg = pCreateMsg->pDlgOp;                                        
00314     CGadgetID SetGadgetID = pCreateMsg->SetGadgetID;
00315     
00316     // Set each item in the combo-box.
00317     for (INT32 i = 0; ; i++)
00318     {
00319         UINT32 nStringID = GetItemStringID(i);
00320         if (nStringID == 0) break;
00321         pDlg->SetStringGadgetValue(SetGadgetID, String(nStringID));
00322     }
00323     
00324     // Update the current selection within the combo etc.
00325     pDlg->SetComboListLength(SetGadgetID);
00326     SetCurrentSelectedAttrib(); 
00327 }
00328 
00329 
00330 
00331 /********************************************************************************************
00332 >   virtual void OpChangeLineAttribOpDesc::OnSelectionChange(OpDescControlMsg* pSelChangedMsg, 
00333                                                              List* pGadgetList)
00334                                                                             
00335     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00336     Created:    10/3/95
00337     Inputs:     -
00338     Outputs:    -
00339     Returns:    -
00340     Purpose:    This function gets called whenever a selection is made from a combo
00341                 box. It invokes the operation to set the line width.
00342     Errors:     -
00343     SeeAlso:    -
00344 ********************************************************************************************/
00345 
00346 void OpChangeLineAttribOpDesc::OnSelectionChange(OpDescControlMsg* pSelChangedMsg, List*)
00347 {
00348     // Get the relevant fields.
00349     DialogOp* pDlg = pSelChangedMsg->pDlgOp;                                        
00350     CGadgetID idSetGadgetID = pSelChangedMsg->SetGadgetID;
00351 
00352     // Try to get the text entered (or selected) within the combo.
00353     BOOL fValid;
00354     String_256 strEntered = pDlg->GetStringGadgetValue(idSetGadgetID, &fValid, -1);
00355     if (!fValid)
00356     {
00357         TRACEUSER( "JustinF", _T("Invalid text in OpChangeLineAttribOpDesc::OnSelectionChange\n"));
00358         Beep();
00359         SetCurrentSelectedAttrib();
00360         return;
00361     }
00362 
00363     INT32 nItemIndex;
00364     // Compare the string to each item that was placed in the combo list.
00365     for (nItemIndex = 0; ; nItemIndex++)
00366     {
00367         // Ask the derived class to provide the string at the given index position.
00368         UINT32 nTxtID = GetItemStringID(nItemIndex);
00369         
00370         // If there are no more strings then simply reset the combo to the current value.
00371         // The user has entered junk!
00372         if (nTxtID == 0)
00373         {
00374             // This will "recalc" the current value and set it.
00375             Beep();
00376             SetCurrentSelectedAttrib();
00377             return;
00378         }
00379 
00380         // Compare the two strings.  If they match then break out now.
00381         if (strEntered == String_256(nTxtID)) break;
00382     }
00383 
00384     // Obtain the index selected in the combo and pass to the derived class, which will
00385     // create the appropriate attribute.
00386     NodeAttribute* pAttr = GetNewAttrib(nItemIndex);
00387     if (pAttr == NULL)
00388     {
00389         TRACEUSER( "JustinF", _T("Out of memory in OpChangeLineAttribOpDesc")
00390                              "::OnSelectionChange\n");
00391         return;
00392     }
00393 
00394     // Pass it to the attribute manager.
00395     AttributeManager::AttributeSelected(pAttr); 
00396 
00397     // Update all list-boxes.  Note we must do this even if we have just set a new
00398     // attribute, as a SelChanging message will not be always be broadcast.
00399     SetCurrentSelectedAttrib();
00400 }
00401 
00402 
00403 
00404 /********************************************************************************************
00405 >   virtual BOOL OpChangeLineAttribOpDesc::OnSelChangingMsg(SelChangingMsg::SelectionState state)
00406 
00407     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00408     Created:    6/7/94
00409     Inputs:     -
00410     Outputs:    -
00411     Returns:    FALSE if we run out of memory
00412     Purpose:    This gets called when the selection state has changed.
00413     Errors:     -
00414     SeeAlso:    SelChangingMsg
00415 ********************************************************************************************/
00416 /*
00417 // Don't freak Justin. This This fn is replaced by OnCommonAttrsChangedMsg which handles
00418 // all cases when the common attributes should be re-displayed. See the Message.doc file
00419 // for more details if your curious.
00420 BOOL OpChangeLineAttribOpDesc::OnSelChangingMsg(SelChangingMsg::SelectionState state)
00421 {
00422     return (state == SelChangingMsg::SELECTIONCHANGED) ? SetCurrentSelectedAttrib()
00423                                                        : TRUE;
00424 }
00425 */
00426 /********************************************************************************************
00427 
00428 >   virtual BOOL OpChangeLineAttribOpDesc::OnCommonAttrsChangedMsg(SelChangingMsg::SelectionState State)
00429 
00430     Author:     Simon_Maneggio (Xara Group Ltd) <camelotdev@xara.com>
00431     Created:    6/7/94
00432     Returns:    FALSE if we run out of memory
00433     Purpose:    This gets called when the common attributes have changed
00434 
00435 ********************************************************************************************/
00436 
00437 
00438 BOOL OpChangeLineAttribOpDesc::OnCommonAttrsChangedMsg()
00439 {
00440     return (SetCurrentSelectedAttrib());
00441 }
00442 
00443 
00444 
00445 
00446 /********************************************************************************************
00447 >   virtual BOOL OpChangeLineAttribOpDesc::OnDocChangingMsg(Document* pChangingDoc,
00448                                                             DocState State)
00449     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00450     Created:    15/3/95
00451     Inputs:     -
00452     Outputs:    -
00453     Returns:    
00454     Purpose:    To update the selection width combo whenever the document changes
00455     Errors:     -
00456     SeeAlso:    DocChangingMsg
00457 ********************************************************************************************/
00458 
00459 BOOL OpChangeLineAttribOpDesc::OnDocChangingMsg(Document*, DocChangingMsg::DocState)
00460 {
00461     return SetCurrentSelectedAttrib();
00462 }
00463 
00464 
00465 
00466 /********************************************************************************************
00467 >   static OpState OpChangeLineAttribOpDesc::GetState(String_256*, OpDescriptor*); 
00468 
00469     Author:     Justin_Flude (Xara Group Ltd) <camelotdev@xara.com>
00470     Created:    7/3/95
00471     Inputs:     -
00472     Outputs:    -
00473     Returns:    -
00474     Purpose:    Generic GetState function for the OpChangeLineAttribOpDesc and derivatives.
00475     Errors:     -
00476     SeeAlso:    -
00477 ********************************************************************************************/
00478 
00479 OpState OpChangeLineAttribOpDesc::GetState(String_256*, OpDescriptor*)
00480 {
00481     OpState os;
00482     if (Document::GetSelected() == NULL) os.Greyed = TRUE;
00483     return os;
00484 }

Generated on Sat Nov 10 03:45:34 2007 for Camelot by  doxygen 1.4.4