exagal.cpp

Go to the documentation of this file.
00001 // $Id: exagal.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 // An example gallery - implementation
00099 
00100 /*
00101 */
00102 
00103 
00104 #include "camtypes.h"
00105 
00106 //#include "alex.h"
00107 //#include "ensure.h" - in camtypes.h [AUTOMATICALLY REMOVED]
00108 #include "exagal.h"
00109 //#include "jason.h"            // For JCWTRACE
00110 #include "oilfiles.h"
00111 //#include "resource.h"
00112 
00113 // Jason's personal trace variant - only spews debug for him
00114 #define JCWTRACE if(IsUserName("Jason")) TRACE
00115 
00116 // This is not compulsory, but you may as well put it in so that the correct version
00117 // of your file can be registered in the .exe
00118 DECLARE_SOURCE("$Revision: 1282 $");
00119 
00120 
00121 
00122 #if FALSE
00123     // Galleries (as opposed to supergalleries) are now defunct
00124 
00125 
00126 CC_IMPLEMENT_DYNCREATE(ExampleGallery, Gallery)
00127 
00128 // This will get Camelot to display the filename and linenumber of any memory allocations
00129 // that are not released at program exit
00130 #define new CAM_DEBUG_NEW
00131 
00132 
00133 
00134 /********************************************************************************************
00135 
00136 >   ExampleGallery::ExampleGallery() : Gallery()
00137 
00138     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00139     Created:    13/7/94
00140     Purpose:    Example Gallery constructor
00141 
00142 ********************************************************************************************/
00143 
00144 ExampleGallery::ExampleGallery() : Gallery()
00145 {
00146 JCWTRACE( _T("\nExample gallery constructed\n"));
00147 }
00148 
00149 
00150 
00151 /********************************************************************************************
00152 
00153 >   virtual BOOL ExampleGallery::PreCreate(void)
00154 
00155     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00156     Created:    18/7/94
00157     Returns:    TRUE if it is successful; FALSE to abort creation of the window
00158                 FALSE => ERROR1
00159 
00160     Purpose:    Example Gallery PreCreate handler
00161 
00162     Notes:      This method is called whenever the gallery window is about to be
00163                 created.
00164                 At this point, the gallery should set up data structures - it is
00165                 *essential* that DisplayList is set up by the end of this method.
00166                 (As it is used in the creation of the window)
00167                 Note that you cannot AddItemToDisplay etc in this method, as 
00168                 although the display list exists, the related window controls
00169                 do not yet exist, and ENSURE failures will result.
00170 
00171 ********************************************************************************************/
00172 
00173 BOOL ExampleGallery::PreCreate(void)
00174 {
00175     if (GetCurrentDisplayList() == NULL)
00176     {
00177         OrderedList *NewDisplayList = new OrderedList;
00178         SelectDisplayList(NewDisplayList);
00179     }
00180 
00181     return(GetCurrentDisplayList() != NULL);
00182 }
00183 
00184 
00185 
00186 /********************************************************************************************
00187 
00188 >   virtual BOOL ExampleGallery::PostCreate(void)
00189 
00190     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00191     Created:    18/7/94
00192     Returns:    TRUE if it is successful; FALSE to abort creation of the window
00193 
00194     Purpose:    Example Gallery PostCreate handler
00195 
00196     Notes:      This method is called whenever the gallery window is created, AFTER
00197                 the window has been brought into existence.
00198                 At this point (and henceforth), the gallery can add items to]
00199                 the DisplayList, etc. as the display controls now exist.
00200 
00201 ********************************************************************************************/
00202 
00203 BOOL ExampleGallery::PostCreate(void)
00204 {
00205     if (GetCurrentDisplayList() == NULL)
00206         return(FALSE);
00207 
00208     // VERY Naughty! But should be safe as a quick test
00209     for (INT32 i = 1; i <= 20; i++)
00210         AddItemToDisplay((ListItem *)i);
00211 
00212     return(TRUE);
00213 }
00214 
00215 
00216 
00217 /********************************************************************************************
00218 
00219 >   MsgResult ExampleGallery::Message(Msg* Message) 
00220 
00221     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00222     Created:    13/7/94
00223     Inputs:     Message- The message to handle
00224 
00225     Purpose:    Example Gallery dialog message handler
00226 
00227     Notes:      This should generally only process GalleryMsg messages and things
00228                 like DocChagingMsg messages which might affect what list you want
00229                 your gallery to display. All unprocessed messages must be passed
00230                 down to the base class Gallery::Message method
00231 
00232 ********************************************************************************************/
00233 
00234 MsgResult ExampleGallery::Message(Msg* Message) 
00235 {
00236 
00237     // Note that all Dialogue messages should have been handled by the base class
00238     // message handler. Unless we're being antisocial, all we should have to
00239     // process here are the GalleryMsg messages.
00240 
00241 JCWTRACE( _T("\nExample gallery message handler\n"));
00242 
00243 #if FALSE
00244     if (MESSAGE_IS_A(Message, GalleryMsg))
00245     {
00246         GalleryMsg *Msg = (GalleryMsg *) Message;
00247 
00248         switch(Msg->State)
00249         {
00250         }
00251 
00252         return(OK);     // Don't try to go recursive with messages from the base class!
00253     }
00254 #endif
00255 
00256     return(Gallery::Message(Message));
00257 }    
00258 
00259 
00260 
00261 /***********************************************************************************************
00262 
00263 >   BOOL ExampleGallery::DoRedrawAnItem(ListItem *Item, BOOL Large, UINT32 DisplayMode);
00264 
00265     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00266     Created:    12/7/94
00267     Inputs:     Item - The item to be redrawn
00268                 Large - TRUE for large mode, FALSE for small mode redraw
00269                 DisplayMode - derived gallery defined display mode index which
00270                 determines how the item is redrawn (icon only, name only, full info)
00271 
00272     Returns:    TRUE if it redraws successfully
00273     Purpose:    Redraws a display list item. MUST be overridden by derived class
00274                 (it would be pure virtual but for DYNCREATE)
00275 
00276 ***********************************************************************************************/
00277 
00278 BOOL ExampleGallery::DoRedrawAnItem(ListItem *Item, BOOL Large, UINT32 DisplayMode)
00279 {
00280     // Draws a listitem displaying a "Example"!
00281     return(TRUE);
00282 }
00283 
00284 
00285 
00286 /***********************************************************************************************
00287 
00288 >   BOOL ExampleGallery::PrepareToDelete(void)
00289 
00290     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00291     Created:    12/7/94
00292     Purpose:    Scans the current Gallery selection. Possibly asks the user for
00293                 confirmation about the delete. Possibly adjusts the selection as
00294                 appropriate. Then returns a value to indicate whether the remaining
00295                 selection should be deleted.
00296     SeeAlso:    ExampleGallery::DoDeleteSelection
00297 
00298 ***********************************************************************************************/
00299  
00300 BOOL ExampleGallery::PrepareToDelete(void)
00301 {
00302     // Scans the selection, changing it if necessary, and returns TRUE if
00303     // it is OK to delete the resulting selection. The gallery base class 
00304     // happily handles things like the selection now being empty.
00305 
00306     // eg
00307     //  SequenceItem *Jobby = FindFirstSelected();
00308     //  while (Jobby)
00309     //  {
00310     //      // Don't allow deletion if any of the items in the selection can't be deleted
00311     //      if ( ((MyItemType *) FindRealItem(Jobby))->CantBeDeleted() )
00312     //          return(FALSE);
00313     //      Jobby = FindNextSelected(Jobby);
00314     //  }
00315 
00316     return(TRUE);
00317 }
00318 
00319 
00320 
00321 /***********************************************************************************************
00322 
00323 >   BOOL ExampleGallery::DoDeleteSelection(void)
00324 
00325     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00326     Created:    12/7/94
00327     Purpose:    FORCIBLY deletes the current gallery selection. B y the time this function
00328                 is called, PrepareToDelete has made sure that it is safe to continue.
00329                 This must simply invoke a forced delete upon the selection.
00330     SeeAlso:    ExampleGallery::PrepareToDelete
00331 
00332 ***********************************************************************************************/
00333  
00334 BOOL ExampleGallery::DoDeleteSelection(void)
00335 {
00336     // Force-deletes anything still remaining in the selection
00337     // returns TRUE if successful
00338 
00339     // eg
00340     //  SequenceItem *Jobby = FindFirstSelected();
00341     //  while (Jobby)
00342     //  {
00343     //      MyListOfExamples->DeleteItem(FindRealItem(Jobby));
00344     //      Jobby = FindNextSelected(Jobby);
00345     //  }
00346 
00347     return(TRUE);
00348 }
00349 
00350 
00351 
00352 /***********************************************************************************************
00353 
00354 >   ListItem *ExampleGallery::DoCreateNewItem(ListItem *BasedOn)
00355 
00356     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00357     Created:    20/7/94
00358     Inputs:     BasedOn - The real item on which the new item should be based
00359                 (this should copy/clone the given item). If BasedOn==NULL then
00360                 you should read the attributes for the current document selection
00361                 and clone the relevant attribute if one is available. If all else
00362                 fails, create a new item based on some default settings.
00363 
00364     Returns:    NULL if it fails to create a new item, else a pointer to the new
00365                 item
00366 
00367     Purpose:    This function is meant to be overridden in derived classes
00368                 It creates a new item and adds it to the Gallery DisplayList
00369                 The item may be created by cloning/deriving/basing-on the
00370                 selected item, depending on the type of Gallery concerned.
00371 
00372     Notes:      Note that the Gallery base class handles addition of the item
00373                 to the display list, and probably also redefinition of the item
00374                 directly after creation.
00375 
00376 ***********************************************************************************************/
00377 
00378 ListItem *ExampleGallery::DoCreateNewItem(ListItem *BasedOn)
00379 {
00380     return(NULL);
00381 }
00382 
00383 
00384 
00385 /***********************************************************************************************
00386 
00387 >   void ExampleGallery::DoApplyItem(ListItem *ItemToApply)
00388 
00389     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00390     Created:    20/7/94
00391     Inputs:     ItemToApply - The real item which should be applied to the document
00392                 selection in an appropriate manner. If there is no doc selection,
00393                 then you should set the docs default creation attributes instead
00394 
00395     Purpose:    This function is meant to be overridden in derived classes
00396                 It applies the selected item to the document in whatever way
00397                 is appropriate to its particular data item type. 
00398 
00399 ***********************************************************************************************/
00400 
00401 void ExampleGallery::DoApplyItem(ListItem *ItemToApply)
00402 {
00403 }
00404 
00405 
00406 
00407 /***********************************************************************************************
00408 
00409 >   BOOL ExampleGallery::DoRedefineItem(ListItem *ItemToRedefine)
00410 
00411     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00412     Created:    20/7/94
00413 
00414     Inputs:     ItemToRedefine - The item which should be redefined.
00415 
00416     Returns:    TRUE if the item was changed (or if you're not sure)
00417                 FALSE if the item definitely was not changed (to save us
00418                 re-sorting and drawing the displayed list)
00419 
00420     Purpose:    This function is meant to be overridden in derived classes
00421                 It allows the user to 'redefine' the item in some way, using
00422                 an item editor (such as a colour picker, for example)
00423 
00424 ***********************************************************************************************/
00425 
00426 BOOL ExampleGallery::DoRedefineItem(ListItem *ItemToRedefine)
00427 {
00428     return(TRUE);
00429 }
00430 
00431 
00432 
00433 
00434 /***********************************************************************************************
00435 
00436 >   virtual StringBase *ExampleGallery::GetItemText(ListItem *TheItem)
00437 
00438     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00439     Created:    19/7/94
00440     Returns:    NULL, or a pointer to the item's text
00441 
00442     Purpose:    STAGE 1 - SIMPLE GALLERY IMPLEMENTATION
00443 
00444                 This method is overridden by derived galleries to provide text
00445                 for each displayed item. This will not be used once user-redraw
00446                 has been implemented, but is used for the time being.
00447 
00448 ***********************************************************************************************/
00449 
00450 StringBase *ExampleGallery::GetItemText(ListItem *TheItem)
00451 {
00452     return(NULL);
00453 }
00454 
00455 
00456 
00457 /***********************************************************************************************
00458 
00459 >   virtual void ExampleGallery::SortModeHasBeenChanged(BOOL SetDerivedSortsToo)
00460 
00461     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00462     Created:    29/7/94
00463     Inputs:     SetDerivedSortsToo - If FALSE, only the base gallery class' Display List
00464                 sort mode should be changed. If TRUE, then any other things that can
00465                 depend upon this sort mode should also be updated (e.g. ColourGallery
00466                 will update the colour bar sortmode if this is TRUE).
00467 
00468     Purpose:    Called when the GalleryDisplayDlg has chnaged the gallery DisplayList
00469                 SortMode array to a new sort. The gallery will cause a re-sort and
00470                 update of its list display.
00471 
00472     Notes:      The base class functionality MUST be provided in derived classes. Thus,
00473                 you should call the base class method from any derived version.
00474                 If SetDerivedSorts == FALSE, derived methods probably should do nothing.
00475                 Otherwise, you should copy the DisplayList->SortMode array into any other
00476                 SortModes you may have for external entities such as the colour bar, and
00477                 cause them to update themselves for the new sort too.
00478 
00479 ***********************************************************************************************/
00480  
00481 
00482 void ExampleGallery::SortModeHasBeenChanged(BOOL SetDerivedSortsToo)
00483 {
00484     // We *MUST* call the base class version of this function
00485     Gallery::SortModeHasBeenChanged(SetDerivedSortsToo);
00486 
00487     // This function should probaby do nothing if SetDerivedSortsToo == FALSE
00488     // It is called to say that the DisplayList->SortMode (array of sort keys
00489     // defining the displayed order of items) has been changed, so if you
00490     // depend on this sort mode for anything (other than the basic DisplayList
00491     // dependency, which the base class handles) you should update it now.
00492 
00493 
00494     if (SetDerivedSortsToo)
00495     {
00496         // See the colour gallery version of this for an example of use.
00497         // Probably, you'll want to copy the SortMode array into another similar 
00498         // array (probably stored in an extra member varaible in your derived
00499         // OrderedList Display List), and then cause the users of that sort mode
00500         // to update themselves to suit.
00501     }
00502 }
00503 
00504 
00505 
00506 /***********************************************************************************************
00507 
00508 >   BOOL ExampleGallery::DoSetDisplayModes(GalleryDisplayDlg *TheDialogue)
00509 
00510     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00511     Created:    29/7/94
00512     Inputs:     TheDialogue - The Gallery Display dialogue to call
00513                 SetDisplayModeName for.
00514 
00515     Returns:    TRUE if the gallery has a choice of display modes, 
00516                 FALSE if not (in which case the combo box list is greyed)
00517 
00518     Purpose:    This derived function is called by the base class when the
00519                 GallerySortDlg is opened. It is a request from the gallery
00520                 for you to fill in the list of available display modes. e.g
00521                 you may provide icon-only, name-only, icon-and-name, full info
00522                 modes for displaying the gallery items.
00523 
00524                 For each mode you support, call SetDisplayModeName to add it to
00525                 the list. Return TRUE when you're done.
00526 
00527                 If you don't support anything other than one display mode, then you
00528                 should just return FALSE (the base class default does this for you)
00529 
00530     SeeAlso:    GalleryDisplayDlg::SetDisplayModeName; ExampleGallery::DoDisplayModeChange
00531 
00532 ***********************************************************************************************/
00533 
00534 BOOL ExampleGallery::DoSetDisplayModes(GalleryDisplayDlg *TheDialogue)
00535 {
00536     // Example:
00537     // String_64 Text(_R(IDS_DISPLAY_NAMES_ONLY));
00538     // TheDialogue->SetDisplayModeName(Text);
00539 
00540     // ****
00541 
00542     return(FALSE);      // By default, the gallery will have no choice of modes
00543 }
00544 
00545 
00546 
00547 /***********************************************************************************************
00548 
00549 >   void ExampleGallery::DoDisplayModeChange(UINT32 NewDisplayMode)
00550 
00551     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00552     Created:    29/7/94
00553     Inputs:     NewDisplayMode - this number is an index [0..MaxDisplayModes] into
00554                 the list of display names you gave in DoSetDisplayModes
00555     Returns:    -
00556 
00557     Purpose:    This function probably won't be needed, but it is called if the
00558                 display mode is changed in the gallery display dialogue. You may
00559                 want to cache new values or something before the next time your
00560                 redraw code is called, in which case this is the place to do it.
00561 
00562     SeeAlso:    GalleryDisplayDlg::SetDisplayModeName; ExampleGallery::DoSetDisplayModes
00563 
00564 ***********************************************************************************************/
00565 
00566 void ExampleGallery::DoDisplayModeChange(UINT32 NewDisplayMode)
00567 {
00568     // By default, no action is taken for display mode changes
00569 }
00570 
00571 
00572 
00573 /***********************************************************************************************
00574 
00575 >   void ExampleGallery::DoShowMenu(void)
00576 
00577     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00578     Created:    29/7/94
00579     Inputs:     -
00580     Returns:    -
00581 
00582     Purpose:    Creates and shows your gallery-specific menu.
00583                 This is in reaction to clicking the gallery menu button - you should
00584                 pop up a menu under the pointer. How to do this is a complete mystery
00585                 to me! I guess the menu items should be connected to actions via the
00586                 standard Op system, so this is the only call the Gallery provides
00587                 for you.
00588 
00589 ***********************************************************************************************/
00590 
00591 void ExampleGallery::DoShowMenu(void)
00592 {
00593     // By default, no menu is shown
00594 }
00595 
00596 
00597 
00598 /***********************************************************************************************
00599 
00600 >   virtual BOOL ExampleGallery::SetAlsoButton(String_64 *TextToPutIn)
00601 
00602     Author:     Jason_Williams (Xara Group Ltd) <camelotdev@xara.com>
00603     Created:    29/7/94
00604     Inputs:     -
00605     Outputs:    TextToPutIn - Fill this in with the text you want on the
00606                 'also' option button
00607     Returns:    TRUE if it wants an 'also' button, FALSE if not
00608 
00609     Purpose:    If your gallery sort mode can also be applied to other entities
00610                 (e.g. the Colour Gallery display mode can also be applied to the
00611                 colour bar) then return TRUE from this function after filling in
00612                 the text parameter with a string (e.g. "Also apply this sort to
00613                 the colour bar"
00614 
00615                 If you want more control than this, you'll need to override the
00616                 GalleryDisplayDlg class and get your hands dirty.
00617 
00618                 By default (if you don't override this method) there is no button
00619 
00620     SeeAlso:    ExampleGallery::SortModeHasBeenChanged
00621 
00622 ***********************************************************************************************/
00623 
00624 BOOL ExampleGallery::SetAlsoButton(String_64 *TextToPutIn)
00625 {
00626     return(FALSE);      // By default, Galleries do not support an 'also' button
00627 }
00628 
00629 
00630 #endif
00631 
00632 

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