00001 // $Id: uielem.cpp 751 2006-03-31 15:43: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 00101 #include "camtypes.h" 00102 //#include "dialogop.h" 00103 #include "gadget.h" 00104 #include "uielem.h" 00105 //#include "tmpltdlg.h" 00106 00107 00108 /************************************************************************************** 00109 00110 > class VisibleListItemPtr : public ListItem 00111 00112 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00113 Created: 15/10/96 00114 00115 Purpose: Provides a container element for a visible list 00116 00117 **************************************************************************************/ 00118 class VisibleListItemPtr : public ListItem 00119 { 00120 public: 00121 VisibleListItemPtr(VisibleListItem& Item) : m_Item(Item) {} 00122 virtual ~VisibleListItemPtr() { delete &m_Item; } 00123 00124 VisibleListItem& GetEntry() const { return m_Item; } 00125 private: 00126 VisibleListItem& m_Item; 00127 }; 00128 00129 00130 // Place any IMPLEMENT type statements here 00131 CC_IMPLEMENT_MEMDUMP(UserInterface, CC_CLASS_MEMDUMP); 00132 CC_IMPLEMENT_MEMDUMP(VisibleListItem, UserInterface); 00133 CC_IMPLEMENT_MEMDUMP(VisibleList, UserInterface); 00134 00135 00136 // We want better memory tracking 00137 // Declare smart memory handling in Debug builds 00138 #define new CAM_DEBUG_NEW 00139 00140 #define ENSURE_KIND(pInstance, Class) ERROR3IF(!pInstance->IS_KIND_OF(Class), #pInstance" is not kind of "#Class); 00141 00142 // Functions follow 00143 00144 00145 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 00146 // V I S I B L E L I S T I T E R A T O R 00147 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 00148 00149 00150 00151 00152 00153 /******************************************************************************************* 00154 00155 > VisibleListIterator::VisibleListIterator( List& Container, 00156 VisibleListItemPtr* const pPointer, 00157 INT32* IndexesOfItemsToReturn = NULL) 00158 00159 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00160 Created: 09/06/97 00161 00162 Purpose: This constructor provides two variants of a VisibleListIterator: 00163 1. Returns all entries in the given list. 00164 2. Returns only those items whose indexes are contained in the given INT32 00165 array. 00166 (These should probably be two separate classes) 00167 00168 Inputs: Container: The container of VisibleListItemPtr's 00169 pPointer: The item in the container with which the iteration will begin 00170 IndexesOfItemsToReturn: An array of INT32's, representing indexes of items in 00171 the Container (starting from 0, in ascending order and 00172 terminated by -1) 00173 00174 *******************************************************************************************/ 00175 VisibleListIterator::VisibleListIterator(List& Container, VisibleListItemPtr* const pPointer, 00176 INT32* IndexesOfItemsToReturn) : 00177 m_VisibleListItemPtr(pPointer), 00178 m_Container(Container), 00179 m_IndexesOfItemsToReturn(IndexesOfItemsToReturn), 00180 m_IndexInIndex(0) 00181 { 00182 if (IndexesOfItemsToReturn != NULL) 00183 { 00184 m_VisibleListItemPtr = (VisibleListItemPtr*)m_Container.FindItem(LISTPOS(m_IndexesOfItemsToReturn[0])); 00185 } 00186 } 00187 00188 00189 /******************************************************************************************* 00190 00191 > VisibleListIterator::~VisibleListIterator() 00192 00193 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00194 Created: 09/06/97 00195 00196 Purpose: Provides a destructor to delete any array given in the constructor. 00197 00198 *******************************************************************************************/ 00199 VisibleListIterator::~VisibleListIterator() 00200 { 00201 if (m_IndexesOfItemsToReturn != NULL) 00202 { 00203 delete [] m_IndexesOfItemsToReturn; 00204 } 00205 } 00206 00207 00208 00209 /******************************************************************************************* 00210 00211 > VisibleListIterator::VisibleListIterator(const VisibleListIterator& Other) 00212 const VisibleListIterator& VisibleListIterator::operator=(const VisibleListIterator& Other) 00213 00214 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00215 Created: 09/06/97 00216 00217 Purpose: Warns that these have not been implemented (but a destructor has) 00218 00219 *******************************************************************************************/ 00220 VisibleListIterator::VisibleListIterator(const VisibleListIterator& Other) : 00221 m_Container(Other.m_Container) 00222 { 00223 ERROR3("VisibleListIterator - copy constructor unimplemented\n"); 00224 } 00225 00226 00227 const VisibleListIterator& VisibleListIterator::operator=(const VisibleListIterator& Other) 00228 { 00229 ERROR3("VisibleListIterator - assignment operator not implemented\n"); 00230 00231 return *this; 00232 } 00233 00234 00235 /******************************************************************************************* 00236 00237 > VisibleListIterator& VisibleListIterator::operator++() 00238 00239 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00240 Created: 09/06/97 00241 00242 Purpose: Moves on the iterator to the next entry in the VisibleList 00243 00244 Returns: An iterator pointing at the next entry. 00245 00246 *******************************************************************************************/ 00247 VisibleListIterator& VisibleListIterator::operator++() 00248 { 00249 if (m_IndexesOfItemsToReturn == NULL) 00250 { 00251 m_VisibleListItemPtr = (VisibleListItemPtr*)m_Container.GetNext(m_VisibleListItemPtr); 00252 } 00253 else 00254 { 00255 ++m_IndexInIndex; 00256 if (m_IndexesOfItemsToReturn[m_IndexInIndex] == -1) 00257 { 00258 m_VisibleListItemPtr = NULL; 00259 } 00260 else 00261 { 00262 m_VisibleListItemPtr = (VisibleListItemPtr*)m_Container.FindItem(LISTPOS(m_IndexesOfItemsToReturn[m_IndexInIndex])); 00263 } 00264 } 00265 00266 return *this; 00267 } 00268 00269 00270 /******************************************************************************************* 00271 00272 > VisibleListIterator& VisibleListIterator::operator--() 00273 00274 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00275 Created: 09/06/97 00276 00277 Purpose: Moves the iterator to the previous entry in the VisibleList 00278 00279 Returns: An iterator pointing at the next entry. 00280 00281 *******************************************************************************************/ 00282 VisibleListIterator& VisibleListIterator::operator --() 00283 { 00284 if (m_IndexesOfItemsToReturn == NULL) 00285 { 00286 m_VisibleListItemPtr = (VisibleListItemPtr*)m_Container.GetPrev(m_VisibleListItemPtr); 00287 } 00288 else 00289 { 00290 if (m_IndexInIndex == 0) 00291 { 00292 m_VisibleListItemPtr = NULL; 00293 } 00294 else 00295 { 00296 --m_IndexInIndex; 00297 m_VisibleListItemPtr = (VisibleListItemPtr*)m_Container.FindItem(LISTPOS(m_IndexesOfItemsToReturn[m_IndexInIndex])); 00298 } 00299 } 00300 00301 return *this; 00302 } 00303 00304 00305 /******************************************************************************************* 00306 00307 > BOOL VisibleListIterator::operator!=(const VisibleListIterator& Other) 00308 00309 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00310 Created: 09/06/97 00311 00312 Purpose: Enables us to determine when an iteration has finished, a la 00313 while (Iterator != Container.End()) 00314 00315 Returns: TRUE if the iterator's are pointing at different VisibleListEntry's 00316 FALSE if they're the same 00317 00318 *******************************************************************************************/ 00319 BOOL VisibleListIterator::operator!=(const VisibleListIterator& Other) 00320 { 00321 return m_VisibleListItemPtr != Other.m_VisibleListItemPtr; 00322 } 00323 00324 00325 /******************************************************************************************* 00326 00327 > VisibleListItem& VisibleListIterator::operator*() 00328 00329 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00330 Created: 09/06/97 00331 00332 Purpose: Allows us to get at the VisibleListItem pointed to by this iterator. 00333 00334 Returns: A reference to the VisibleListItem 00335 00336 Errors: ERROR2's if the iterator's gone off the end of the container. 00337 00338 *******************************************************************************************/ 00339 VisibleListItem& VisibleListIterator::operator*() 00340 { 00341 ERROR3IF(m_VisibleListItemPtr == NULL, "NULL Member"); 00342 00343 return m_VisibleListItemPtr->GetEntry(); 00344 } 00345 00346 00347 00348 00349 00350 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 00351 // V I S I B L E L I S T 00352 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 00353 00354 00355 00356 00357 00358 00359 /******************************************************************************************* 00360 00361 > VisibleList::~VisibleList() 00362 00363 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00364 Created: 09/06/97 00365 00366 Purpose: Virtual destructor clears its lists 00367 00368 *******************************************************************************************/ 00369 VisibleList::~VisibleList() 00370 { 00371 DeleteAllEntries(); 00372 } 00373 00374 00375 /******************************************************************************************* 00376 00377 > virtual BOOL VisibleList::Display(DialogOp& Dialog) 00378 virtual BOOL VisibleList::Interact(DialogOp& Dialog) 00379 virtual void VisibleList::Hide() 00380 00381 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00382 Created: 09/06/97 00383 00384 Purpose: Hmm.. haven't quite decided what these should do. 00385 How about: 00386 Display - show disabled 00387 Interact - show enabled 00388 Hide - remove from sight 00389 00390 *******************************************************************************************/ 00391 BOOL VisibleList::Display(DialogOp& Dialog) 00392 { 00393 return TRUE; 00394 } 00395 00396 00397 BOOL VisibleList::Interact(DialogOp& Dialog) 00398 { 00399 return TRUE; 00400 } 00401 00402 void VisibleList::Hide() 00403 { 00404 } 00405 00406 00407 BOOL VisibleList::Display(ListControl& Control) 00408 { 00409 m_pUIElement = &Control; 00410 Control.Disable(); 00411 // should display the entries we have and InsertEntry, etc. only update if we've 00412 // got a UIElement, but for now we'll insist on a display before InsertEntry, etc. 00413 return TRUE; 00414 } 00415 00416 00417 BOOL VisibleList::Interact(ListControl& Control) 00418 { 00419 BOOL Ok = Display(Control); 00420 Control.Enable(); 00421 return Ok; 00422 } 00423 00424 00425 /******************************************************************************************* 00426 00427 > List& VisibleList::GetContainer() 00428 00429 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00430 Created: 09/06/97 00431 00432 Purpose: Support function to exposeget the VisibleList's innards 00433 00434 *******************************************************************************************/ 00435 List& VisibleList::GetContainer() 00436 { 00437 return m_Container; 00438 } 00439 /******************************************************************************************* 00440 00441 > BOOL VisibleList::InsertEntry(VisibleListItem& EntryToInsert) 00442 00443 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00444 Created: 09/06/97 00445 00446 Purpose: Inserts an entry into a visible list 00447 00448 Returns: FALSE if it fails 00449 00450 *******************************************************************************************/ 00451 BOOL VisibleList::InsertEntry(VisibleListItem& EntryToInsert) 00452 { 00453 BOOL Success = TRUE; // return this 00454 00455 // Find the entry to insert after & its index 00456 BOOL Found = FALSE; 00457 INT32 Index = 0; 00458 VisibleListItemPtr* pItemToInsertBefore = NULL; 00459 00460 VisibleListItemPtr* pCurrentItem = (VisibleListItemPtr*)m_Container.GetHead(); 00461 while (pCurrentItem != NULL && !Found) 00462 { 00463 if (!(EntryToInsert > pCurrentItem->GetEntry())) 00464 { 00465 pItemToInsertBefore = pCurrentItem; 00466 Found = TRUE; 00467 } 00468 else 00469 { 00470 ++Index; 00471 pCurrentItem = (VisibleListItemPtr*)m_Container.GetNext(pCurrentItem); 00472 } 00473 } 00474 00475 // Create a new pointer to the given entry and put it in the container 00476 VisibleListItemPtr* pNewItem = NULL; 00477 if (Success) 00478 { 00479 pNewItem = new VisibleListItemPtr(EntryToInsert); 00480 Success = (pNewItem != NULL); 00481 } 00482 00483 if (Success) 00484 { 00485 if (!Found) 00486 { 00487 m_Container.AddTail(pNewItem); 00488 } 00489 else 00490 { 00491 Success = (m_Container.InsertBefore(pItemToInsertBefore, pNewItem) != NULL); 00492 } 00493 } 00494 00495 // Add a text entry for the VisibleListItem in the UI Element (if it's there) 00496 if (Success && m_pUIElement != NULL) 00497 { 00498 String_64 ListText; 00499 EntryToInsert.GetText(ListText); 00500 if (!Found) 00501 { 00502 Success = m_pUIElement->AddItem(ListText); 00503 } 00504 else 00505 { 00506 Success = m_pUIElement->InsertItem(ListText, Index); 00507 } 00508 } 00509 00510 // tidy up any mess if it goes wrong 00511 if (!Success) 00512 { 00513 delete pNewItem; 00514 pNewItem = NULL; 00515 } 00516 00517 return Success; 00518 } 00519 00520 00521 /******************************************************************************************* 00522 00523 > virtual VisibleListItem& VisibleList::GetEntryAt(UINT32 Index) 00524 00525 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00526 Created: 09/06/97 00527 00528 Purpose: Support function to get the Index'th entry in the list 00529 00530 Returns: The VisibleListItem at the given Index 00531 00532 *******************************************************************************************/ 00533 VisibleListItem& VisibleList::GetEntryAt(UINT32 Index) 00534 { 00535 VisibleListItemPtr* const pEntry = (VisibleListItemPtr*)GetContainer().FindItem(LISTPOS(Index)); 00536 if (pEntry == NULL) 00537 { 00538 ERROR2RAW("NULL member"); 00539 } 00540 00541 return pEntry->GetEntry(); 00542 } 00543 00544 00545 /******************************************************************************************* 00546 00547 > virtual BOOL VisibleList::DeleteEntryAtIndex(UINT32 Index) 00548 00549 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00550 Created: 09/06/97 00551 00552 Purpose: Deletes the Index'th entry in this list 00553 00554 Returns: FALSE if it fails 00555 00556 *******************************************************************************************/ 00557 BOOL VisibleList::DeleteEntryAtIndex(UINT32 Index) 00558 { 00559 BOOL Success = TRUE; // return this 00560 00561 //#ifdef _DEBUG 00562 // String_256 ListText = m_pUIElement->GetText(pText) _R(IDC_TMLPTDLG_USED), &Success, 00563 // Index); 00564 // VisibleListItem* pItem = pEntryToDelete->GetEntry(); 00565 00566 // ASSERT(ListText == pEntryToDelete->GetText()); 00567 00568 VisibleListItemPtr* pEntryToDelete = (VisibleListItemPtr*)m_Container.FindItem(LISTPOS(Index)); 00569 Success = (pEntryToDelete != NULL); 00570 00571 if (Success) 00572 { 00573 Success = (m_Container.RemoveItem(pEntryToDelete) != NULL); 00574 } 00575 00576 if (Success) 00577 { 00578 delete pEntryToDelete; 00579 pEntryToDelete = NULL; 00580 } 00581 00582 // Remove the entry from the display if it's there 00583 if (Success && m_pUIElement != NULL) 00584 { 00585 Success = m_pUIElement->DeleteItemAtIndex(Index); 00586 } 00587 00588 00589 return Success; 00590 } 00591 00592 00593 /******************************************************************************************* 00594 00595 > virtual BOOL VisibleList::DeleteAllEntries() 00596 00597 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00598 Created: 09/06/97 00599 00600 Purpose: Deletes all the entries in this list 00601 00602 Returns: FALSE if it fails 00603 00604 *******************************************************************************************/ 00605 BOOL VisibleList::DeleteAllEntries() 00606 { 00607 BOOL DeletedAllEntries = TRUE; 00608 00609 m_Container.DeleteAll(); 00610 00611 if (m_pUIElement != NULL) 00612 { 00613 DeletedAllEntries = m_pUIElement->DeleteAllItems(); 00614 } 00615 00616 return DeletedAllEntries; 00617 } 00618 00619 00620 /******************************************************************************************* 00621 00622 > virtual BOOL VisibleList::DeleteSelectedEntries() 00623 00624 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00625 Created: 09/06/97 00626 00627 Purpose: Deletes the selected entries in this list 00628 00629 Returns: FALSE if it fails 00630 00631 *******************************************************************************************/ 00632 BOOL VisibleList::DeleteSelectedEntries() 00633 { 00634 ENSURE_NOT_NULL(m_pUIElement); 00635 00636 // Delete the selected argument from the used list and copy it to the available list 00637 INT32* pIndexes = NULL; 00638 BOOL Success = m_pUIElement->GetSelectedIndexes(&pIndexes); 00639 00640 UINT32 ArrayIndex = 0; 00641 UINT32 EntriesDeleted = 0; 00642 while (Success && pIndexes[ArrayIndex] != -1) 00643 { 00644 const UINT32 IndexOfEntryToDelete = pIndexes[ArrayIndex] - EntriesDeleted; 00645 Success = DeleteEntryAtIndex(IndexOfEntryToDelete); 00646 00647 ++EntriesDeleted; 00648 ++ArrayIndex; 00649 } 00650 00651 if (pIndexes != NULL) 00652 { 00653 delete pIndexes; 00654 pIndexes = NULL; 00655 } 00656 00657 return Success; 00658 } 00659 00660 00661 /******************************************************************************************* 00662 00663 > UINT32 VisibleList::GetNumberOfEntries() const 00664 00665 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00666 Created: 09/06/97 00667 00668 Purpose: Determines how much space you would need for the whole list were you 00669 building an array. 00670 00671 Returns: The Number of Entries 00672 00673 *******************************************************************************************/ 00674 UINT32 VisibleList::GetNumberOfEntries() const 00675 { 00676 return UINT32(m_Container.GetCount()); 00677 } 00678 00679 00680 /******************************************************************************************* 00681 00682 > UINT32 VisibleList::GetNumberOfSelectedEntries() const 00683 00684 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00685 Created: 09/06/97 00686 00687 Purpose: Determines if there's a selection 00688 00689 Returns: The Number of Entries Selected 00690 00691 *******************************************************************************************/ 00692 UINT32 VisibleList::GetNumberOfSelectedEntries() const 00693 { 00694 UINT32 NumberOfSelectedEntries = 0; 00695 00696 if (m_pUIElement != NULL) 00697 { 00698 NumberOfSelectedEntries = m_pUIElement->GetNumberOfSelectedItems(); 00699 } 00700 00701 return NumberOfSelectedEntries; 00702 } 00703 00704 00705 /******************************************************************************************* 00706 00707 > VisibleListItem* VisibleList::GetFirstSelectedEntry() const 00708 00709 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00710 Created: 09/06/97 00711 00712 Purpose: Gets the VisibleListItem that's selected in this list 00713 00714 Returns: NULL if there isn't one (or the list isn't visible) 00715 00716 *******************************************************************************************/ 00717 VisibleListItem* VisibleList::GetFirstSelectedEntry() const 00718 { 00719 VisibleListItem* pSelectedEntry = NULL; // return this 00720 00721 INT32 SelectedIndex = 0; 00722 00723 if (m_pUIElement != NULL && m_pUIElement->GetFirstSelectedIndex(&SelectedIndex)) 00724 { 00725 VisibleListItemPtr* pEntryPtr = (VisibleListItemPtr*)m_Container.FindItem(LISTPOS(SelectedIndex)); 00726 if (pEntryPtr != NULL) 00727 { 00728 pSelectedEntry = &pEntryPtr->GetEntry(); 00729 } 00730 } 00731 00732 return pSelectedEntry; 00733 } 00734 00735 00736 00737 /******************************************************************************************* 00738 00739 > void VisibleList::RemoveSelection() 00740 00741 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00742 Created: 09/06/97 00743 00744 Purpose: Deselects any entries in this list 00745 00746 *******************************************************************************************/ 00747 void VisibleList::RemoveSelection() 00748 { 00749 VOID_ENSURE_NOT_NULL(m_pUIElement); 00750 00751 m_pUIElement->DeselectAll(); 00752 } 00753 00754 00755 /******************************************************************************************* 00756 00757 > virtual VisibleListIterator VisibleList::Begin() 00758 00759 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00760 Created: 09/06/97 00761 00762 Purpose: Returns an iterator so you can run through all the entries in this list 00763 00764 *******************************************************************************************/ 00765 VisibleListIterator VisibleList::Begin() 00766 { 00767 return VisibleListIterator(m_Container, (VisibleListItemPtr*)m_Container.GetHead()); 00768 } 00769 00770 00771 /******************************************************************************************* 00772 00773 > virtual VisibleListIterator VisibleList::BeginOfEnd() 00774 00775 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00776 Created: 09/06/97 00777 00778 Purpose: Returns an iterator so you can back through all the entries in this list 00779 00780 *******************************************************************************************/ 00781 VisibleListIterator VisibleList::BeginOfEnd() 00782 { 00783 return VisibleListIterator(m_Container, (VisibleListItemPtr*)m_Container.GetTail()); 00784 } 00785 00786 00787 /******************************************************************************************* 00788 00789 > virtual const VisibleListIterator& VisibleList::End() 00790 00791 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00792 Created: 09/06/97 00793 00794 Purpose: So you know when to stop iterating use this 'cos it marks the end of this 00795 list. 00796 00797 *******************************************************************************************/ 00798 const VisibleListIterator& VisibleList::End() const 00799 { 00800 // doesn't matter about which list it's in 00801 List list; 00802 static const VisibleListIterator TheEnd( list, NULL ); 00803 00804 return TheEnd; 00805 } 00806 00807 00808 00809 /******************************************************************************************* 00810 00811 > VisibleListIterator VisibleList::SelectionBegin() 00812 00813 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00814 Created: 09/06/97 00815 00816 Purpose: Returns an iterator so you can run through the selected entries in this list 00817 00818 *******************************************************************************************/ 00819 VisibleListIterator VisibleList::SelectionBegin() 00820 { 00821 ERROR2IF(m_pUIElement == NULL, End(), "NULL Member"); 00822 00823 INT32* pIndexes = NULL; 00824 if (m_pUIElement->GetSelectedIndexes(&pIndexes)) 00825 { 00826 return VisibleListIterator(m_Container, (VisibleListItemPtr*)m_Container.GetHead(), pIndexes); 00827 } 00828 else 00829 { 00830 return End(); 00831 } 00832 } 00833 00834 00835 00836 00837 00838 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 00839 // E D I T A B L E T E X T 00840 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 00841 00842 00843 00844 00845 00846 00847 /******************************************************************************************** 00848 00849 > EditableText::EditableText(const StringBase& TextString) 00850 00851 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00852 Created: 09/06/97 00853 00854 Purpose: Provides the user with a string that they can edit and we can retrieve 00855 00856 Notes: This was taken from MSJ, but is not complete, so be careful. In particular, 00857 1. The interface for Display, etc. is not clarified, (what goes in, what comes 00858 out). 00859 2. Notification is not used properly. 00860 00861 The following code kicks out: 00862 00863 warning C4355: 'this' : used in base member initializer list. 00864 00865 Normally, it would be dangerous for the contained-object 00866 constructor to access the container class because the contained 00867 objects are initialized before the container is initialized. 00868 We don't do that here, and it's convenient to pass a pointer 00869 to the container at construction time, so turn off the warning. 00870 00871 ********************************************************************************************/ 00872 #pragma warning( disable : 4355 ) 00873 00874 EditableText::EditableText(const StringBase& TextString) : 00875 m_Watcher(this), 00876 m_pUIElement(NULL), 00877 m_String(TextString) 00878 { 00879 } 00880 00881 #pragma warning( default : 4355 ) 00882 00883 00884 /******************************************************************************************** 00885 00886 > EditableText::~EditableText() 00887 00888 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00889 Created: 09/06/97 00890 00891 Purpose: Ensures the text in the control / gadget is empty 00892 00893 ********************************************************************************************/ 00894 EditableText::~EditableText() 00895 { 00896 if (m_pUIElement != NULL) 00897 { 00898 m_pUIElement->UpdateText(NullString); 00899 } 00900 } 00901 00902 00903 /******************************************************************************************** 00904 00905 > EditableText::EditableText(const EditableText& Other) 00906 const EditableText& EditableText::operator=(const EditableText& Other) 00907 00908 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00909 Created: 09/06/97 00910 00911 Purpose: Warns that these members are unimplemented (destructor is though) 00912 00913 ********************************************************************************************/ 00914 #pragma warning( disable : 4355 ) 00915 00916 EditableText::EditableText(const EditableText& Other) : 00917 m_Watcher(this) 00918 { 00919 ERROR3("EditableText - copy constructor unimplemented\n"); 00920 } 00921 00922 #pragma warning( default : 4355 ) 00923 00924 00925 const EditableText& EditableText::operator=(const EditableText& Other) 00926 { 00927 ERROR3("EditableText - assignment operator not implemented\n"); 00928 00929 return *this; 00930 } 00931 00932 00933 /******************************************************************************************** 00934 00935 > const EditableText& EditableText::operator=(const StringBase& NewString) 00936 00937 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00938 Created: 09/06/97 00939 00940 Purpose: Puts the given text into the UIElement 00941 00942 ********************************************************************************************/ 00943 const EditableText& EditableText::operator=(const StringBase& NewString) 00944 { 00945 m_String = NewString; 00946 00947 Notify(&m_Watcher); 00948 00949 return *this; 00950 } 00951 00952 00953 /******************************************************************************************** 00954 00955 > EditableText::operator const StringBase&() 00956 00957 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00958 Created: 09/06/97 00959 00960 Purpose: Pretends this EditableText is a StringBase, so it can be assigned and stuff 00961 00962 ********************************************************************************************/ 00963 EditableText::operator const StringBase&() 00964 { 00965 if (m_pUIElement != NULL) 00966 { 00967 m_pUIElement->RetrieveText(&m_String); 00968 } 00969 00970 return m_String; 00971 } 00972 00973 00974 /******************************************************************************************** 00975 00976 > void EditableText::Observer::Notify(Notifier* const pSender) 00977 00978 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 00979 Created: 09/06/97 00980 00981 Purpose: Embedded object catches Notifications (doesn't do anything en ce moment, so 00982 don't use Notify 00983 00984 ********************************************************************************************/ 00985 void EditableText::Observer::Notify(Notifier* const pSender) 00986 { 00987 // This function is a friend of class Text, a pointer 00988 // to which is in the owner field; It's called when the 00989 // String base class changes. Note that we have to turn 00990 // notify off in whichever object is being updated. Otherwise, 00991 // we'll just end up back here. 00992 00993 EditableText* const pText = (EditableText*)(pSender); 00994 if (pText != NULL) 00995 { 00996 // String base class was changed, transfer the new value 00997 // to the display. 00998 TextControl* const pUI = pText->m_pUIElement; 00999 if (pUI != NULL) 01000 { 01001 pUI->NotifyOff(); 01002 pUI->UpdateText(*m_pTheTextObject); // modify the string 01003 pUI->NotifyOn(); 01004 } 01005 } 01006 else // User changed the TextControl, copy new value to 01007 { // the string base class of the associated text object. 01008 01009 TextControl* pUI = (TextControl*)(pSender); 01010 ASSERT(pUI != NULL); 01011 01012 pUI->NotifyOff(); // prevent string from notifying us 01013 pUI->RetrieveText(&m_pTheTextObject->m_String); 01014 pUI->NotifyOn(); // re-enable notification 01015 } 01016 } 01017 01018 01019 /******************************************************************************************** 01020 01021 > BOOL EditableText::Display(TextControl& Control) 01022 01023 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01024 Created: 09/06/97 01025 01026 Purpose: Displays this EditableText in the given TextControl. 01027 01028 Notes: This interface may very well change. At present there's one of these taking 01029 a DialogOp (inherited from UserInterface) which does nothing. 01030 There's also an Interact function missing: should it just enable the 01031 control? 01032 01033 ********************************************************************************************/ 01034 BOOL EditableText::Display(TextControl& Control) 01035 { 01036 m_pUIElement = &Control; 01037 Control.UpdateText(m_String); 01038 01039 return TRUE; 01040 } 01041 01042 01043 /******************************************************************************************** 01044 01045 > void EditableText::Hide() 01046 01047 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01048 Created: 09/06/97 01049 01050 Purpose: Ensures the Text in the control is the text inside this EditableText object. 01051 01052 Notes: This interface may very well change. 01053 At present the control is emptied and disabled: should it disappear 01054 completely? 01055 01056 ********************************************************************************************/ 01057 void EditableText::Hide() 01058 { 01059 if (m_pUIElement != NULL) 01060 { 01061 m_pUIElement->RetrieveText(&m_String); 01062 m_pUIElement->UpdateText(NullString); 01063 m_pUIElement->Disable(); 01064 m_pUIElement = NULL; 01065 } 01066 } 01067 01068 01069 01070 01071 01072 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 01073 // V I S I B L E L A B E L 01074 // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // 01075 01076 01077 01078 01079 01080 01081 /******************************************************************************************** 01082 01083 > VisibleLabel::VisibleLabel(const StringBase& TextString) 01084 01085 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01086 Created: 09/06/97 01087 01088 Purpose: Provides the user with a label so they can see what's what. And it allows us 01089 to re-label things. 01090 01091 Notes: This is very much like EditableText: should it be the same? 01092 The original MSJ version had a read-only EditableText object. 01093 01094 ********************************************************************************************/ 01095 #pragma warning( disable : 4355 ) 01096 VisibleLabel::VisibleLabel(const StringBase& TextString) : 01097 m_Watcher(this), 01098 m_pUIElement(NULL), 01099 m_String(TextString) 01100 { 01101 } 01102 #pragma warning( default : 4355 ) 01103 01104 01105 01106 /******************************************************************************************** 01107 01108 > VisibleLabel::~VisibleLabel() 01109 01110 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01111 Created: 09/06/97 01112 01113 Purpose: Provides the user with a label so they can see what's what. And it allows us 01114 to re-label things. 01115 01116 Notes: This is very much like EditableText: should it be the same? 01117 The original MSJ version had a read-only EditableText object. 01118 01119 ********************************************************************************************/ 01120 VisibleLabel::~VisibleLabel() 01121 { 01122 if (m_pUIElement != NULL) 01123 { 01124 m_pUIElement->UpdateText(NullString); 01125 } 01126 } 01127 01128 01129 /******************************************************************************************** 01130 01131 > const VisibleLabel& VisibleLabel::operator=(const StringBase& NewString) 01132 01133 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01134 Created: 09/06/97 01135 01136 Purpose: Presents the given text to the user. 01137 01138 ********************************************************************************************/ 01139 const VisibleLabel& VisibleLabel::operator=(const StringBase& NewString) 01140 { 01141 m_String = NewString; 01142 01143 Notify(&m_Watcher); 01144 01145 return *this; 01146 } 01147 01148 01149 /******************************************************************************************** 01150 01151 > VisibleLabel::operator const StringBase&() const 01152 01153 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01154 Created: 09/06/97 01155 01156 Purpose: Pretends this VisibleLabel is a StringBase, so it can be assigned and stuff 01157 01158 ********************************************************************************************/ 01159 VisibleLabel::operator const StringBase&() const 01160 { 01161 return m_String; 01162 } 01163 01164 01165 /******************************************************************************************** 01166 01167 > void VisibleLabel::Observer::Notify(Notifier* const pSender) 01168 01169 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01170 Created: 09/06/97 01171 01172 Purpose: Embedded object catches Notifications (doesn't do anything en ce moment, so 01173 don't use Notify 01174 01175 ********************************************************************************************/ 01176 void VisibleLabel::Observer::Notify(Notifier* const pSender) 01177 { 01178 // This function is a friend of class Text, a pointer 01179 // to which is in the owner field; It's called when the 01180 // String base class changes. Note that we have to turn 01181 // notify off in whichever object is being updated. Otherwise, 01182 // we'll just end up back here. 01183 01184 // ENSURE_KIND(pSender, VisibleLabel); 01185 VisibleLabel* const pText = (VisibleLabel*)(pSender); 01186 if (pText != NULL) 01187 { 01188 // String base class was changed, transfer the new value 01189 // to the display. 01190 StaticTextControl* const pUI = pText->m_pUIElement; 01191 if (pUI != NULL) 01192 { 01193 pUI->NotifyOff(); 01194 pUI->RetrieveText(&m_pTheTextObject->m_String); 01195 pUI->NotifyOn(); 01196 } 01197 } 01198 else // User changed the TextControl, copy new value to 01199 { // the string base class of the associated text object. 01200 01201 StaticTextControl* pUI = (StaticTextControl*)(pSender); 01202 ASSERT(pUI != NULL); 01203 01204 pUI->NotifyOff(); // prevent string from notifying us 01205 pUI->UpdateText(*m_pTheTextObject); // modify the string 01206 pUI->NotifyOn(); // re-enable notification 01207 } 01208 } 01209 01210 01211 /******************************************************************************************** 01212 01213 > BOOL VisibleLabel::Display(DialogOp& Dialog) 01214 01215 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01216 Created: 09/06/97 01217 01218 Purpose: Displays this VisibleLabel slightly bodgily in the given (Template)Dialog, 01219 but doesn't enable it. 01220 01221 Notes: This interface may very well change. At present there's one of these taking 01222 a DialogOp (inherited from UserInterface) which does nothing. 01223 There's also an Interact function missing: should it just enable the 01224 control? 01225 01226 ********************************************************************************************/ 01227 BOOL VisibleLabel::Display(DialogOp& Dialog) 01228 { 01229 PORTNOTETRACE("dialog","VisibleLabel::Display - do nothing"); 01230 #ifndef EXCLUDE_FROM_XARALX 01231 ERROR3IF(!((&Dialog)->IS_KIND_OF(TemplateDialog)), "Dialog isn't kind of TemplateDialog"); 01232 01233 TemplateDialog& BetterBeThisDialog = (TemplateDialog&)Dialog; 01234 01235 m_pUIElement = &(BetterBeThisDialog.GetParamHintControl()); 01236 01237 m_pUIElement->UpdateText(m_String); 01238 #endif 01239 return TRUE; 01240 } 01241 01242 01243 /******************************************************************************************** 01244 01245 > virtual BOOL VisibleLabel::Interact(DialogOp& Dialog) 01246 01247 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01248 Created: 09/06/97 01249 01250 Purpose: Displays this VisibleLabel slightly bodgily in the given (Template)Dialog 01251 and enables it (otherwise it's grey) 01252 01253 Notes: This interface may very well change. At present there's one of these taking 01254 a DialogOp (inherited from UserInterface) which does nothing. 01255 There's also an Interact function missing: should it just enable the 01256 control? 01257 01258 ********************************************************************************************/ 01259 BOOL VisibleLabel::Interact(DialogOp& Dialog) 01260 { 01261 BOOL Ok = Display(Dialog); 01262 01263 if (Ok && m_pUIElement != NULL) 01264 { 01265 m_pUIElement->Enable(); 01266 } 01267 01268 return Ok; 01269 } 01270 01271 01272 /******************************************************************************************** 01273 01274 > void VisibleLabel::Hide() 01275 01276 Author: Colin_Barfoot (Xara Group Ltd) <camelotdev@xara.com> 01277 Created: 09/06/97 01278 01279 Purpose: Removes this VisibleLabel from the Dialog given in Display() or Interact() 01280 01281 Notes: This interface may very well change. 01282 At present the control is emptied and disabled: should it disappear 01283 completely? 01284 01285 ********************************************************************************************/ 01286 void VisibleLabel::Hide() 01287 { 01288 if (m_pUIElement != NULL) 01289 { 01290 m_pUIElement->UpdateText(NullString); 01291 m_pUIElement->Disable(); 01292 m_pUIElement = NULL; 01293 } 01294 } 01295