00001 // $Id: sgbase.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 // SGTEMPLATE.cpp - TEMPLATE SuperGallery classes - TEMPLATESGallery and SGDisplayTEMPLATE 00100 00101 // You must do the following things: 00102 // 1 Copy this file into your own code file, and screw that up, not this! ;-) 00103 // 2 Strip back the topmost line to say '// #Header#' (where # are dollar signs), and 00104 // clean up the log comments below to just '#Log#' (# are dollars again). 00105 // 3 Change the #include marked below to include your new header file 00106 // 3 Do a GLOBAL, CASE SENSITIVE replace of 'TEMPLATE' with your gallery name (eg 'Bitmap') 00107 // 4 Do a CASE SENSITIVE replace of 'DATATYPE' with your gallery type (eg 'KernelBitmap') 00108 // (This means a DisplayItem will hold a (KernelBitmap *) pointer, etc - search for 00109 // DATATYPE before replacing to see what I mean) 00110 // 5 Do a global CASE SENSITIVE replace of 'AUTHOR' with your name 00111 // 6 Update bars.ini 00112 // 7 Remember to add this new file to all.lst and kernel.mak 00113 // 8 Delete these instructional comment lines 00114 // 9 Take a look at the 'TO DO' comments to see what code you should fill in, and then 00115 // go back and try instruction 8 again, becaus eyou've obviously skipped it! ;-) 00116 00117 00118 /* 00119 */ 00120 00121 00122 DECLARE_SOURCE("$Revision: 1282 $"); 00123 00124 00125 #include "camtypes.h" 00126 00127 //#include "app.h" // For GetApplication() - in camtypes.h [AUTOMATICALLY REMOVED] 00128 //#include "galstr.h" 00129 #include "sgbase.h" // **** INCLUDE YOUR HEADER HERE! **** 00130 00131 #include "ccdc.h" // For render-into-dialogue support 00132 //#include "fillval.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00133 #include "grnddib.h" 00134 00135 //#include "richard2.h" // For _R(IDS_SGBASE_)... example resource strings - remove this after making your own... 00136 00137 // Implement the dynamic class bits... 00138 CC_IMPLEMENT_DYNCREATE(TEMPLATESGallery, SuperGallery) 00139 CC_IMPLEMENT_DYNAMIC(SGDisplayDATATYPE, SGDisplayItem) 00140 CC_IMPLEMENT_DYNCREATE(OpDisplayTEMPLATEGallery, Operation); 00141 00142 00143 // This line mustn't go before any CC_IMPLEMENT_... macros 00144 #define new CAM_DEBUG_NEW 00145 00146 00147 00148 00149 /*********************************************************************************************** 00150 00151 > SGDisplayDATATYPE::SGDisplayDATATYPE() 00152 00153 Author: Unattributed (Xara Group Ltd) <camelotdev@xara.com> 00154 Created: 27/1/95 (base generated in sgbase.cpp) 00155 00156 Purpose: SGDisplayDATATYPE constructor 00157 DON'T call this constructor. It ERROR3's. Call the other constructor 00158 00159 ***********************************************************************************************/ 00160 00161 SGDisplayDATATYPE::SGDisplayDATATYPE() 00162 { 00163 ERROR3("Illegal call on default SGDisplayDATATYPE constructor - call the other one!"); 00164 TheDATATYPE = NULL; 00165 } 00166 00167 00168 00169 /*********************************************************************************************** 00170 00171 > SGDisplayDATATYPE::SGDisplayDATATYPE(DATATYPE *DATATYPEToDisplay) 00172 00173 Author: Unattributed (Xara Group Ltd) <camelotdev@xara.com> 00174 Created: 27/1/95 (base generated in sgbase.cpp) 00175 00176 Inputs: DATATYPEToDisplay - The DATATYPE this item will display 00177 00178 Purpose: SGDisplayDATATYPE constructor 00179 00180 ***********************************************************************************************/ 00181 00182 SGDisplayDATATYPE::SGDisplayDATATYPE(DATATYPE *DATATYPEToDisplay) 00183 { 00184 ERROR3IF(DATATYPEToDisplay == NULL, 00185 "SGDisplayDATATYPE - trying to construct me with a NULL parameter is bad"); 00186 00187 TheDATATYPE = DATATYPEToDisplay; 00188 } 00189 00190 00191 00192 /*********************************************************************************************** 00193 00194 > virtual void SGDisplayDATATYPE::CalculateMyRect(SGFormatInfo *FormatInfo, 00195 SGMiscInfo *MiscInfo) 00196 00197 Author: Unattributed (Xara Group Ltd) <camelotdev@xara.com> 00198 Created: 27/1/95 (base generated in sgbase.cpp) 00199 00200 Inputs: FormatInfo - The formatting info from which to calculate my position/size 00201 MiscInfo - As usual, the useful misc info struct 00202 00203 Outputs: member variable FormatRect - is returned filled in with the size/position of 00204 this DATATYPE item's display area. This is dependent upon the current display 00205 mode and format state 00206 00207 FormatInfo will be updated as a result of the formatting operation 00208 00209 Purpose: Shared code for DATATYPE items to calculate where they will appear in the 00210 grand scheme of things 00211 00212 Notes: DATATYPEs supply only one display mode ("full info") 00213 00214 Scope: private (for use of SGDisplayDATATYPE class only) 00215 00216 ***********************************************************************************************/ 00217 00218 void SGDisplayDATATYPE::CalculateMyRect(SGFormatInfo *FormatInfo, SGMiscInfo *MiscInfo) 00219 { 00220 INT32 XSize = SG_InfiniteWidth; 00221 INT32 YSize = SG_DefaultLargeIcon; 00222 00223 // TO DO 00224 // Fill in code to calculate the size you need for your display item, in millipoints. 00225 // Use the SG_ constants defined in sgtree.h where possible, to retain gallery consistency 00226 // This may depend upon the current display mode, as in: 00227 // switch(MiscInfo->DisplayMode) 00228 // { 00229 // case 0: // Large icons mode 00230 // XSize = SG_InfiniteWidth; 00231 // YSize = 100000; 00232 // } 00233 00234 CalculateFormatRect(FormatInfo, MiscInfo, XSize, YSize); 00235 } 00236 00237 00238 00239 /******************************************************************************************** 00240 00241 > virtual void SGDisplayDATATYPE::GetNameText(String_256 *Result) 00242 00243 Author: Unattributed (Xara Group Ltd) <camelotdev@xara.com> 00244 Created: 9/3/95 (base generated in sgbase.cpp) 00245 00246 Outputs: On exit, the string pointed at by Result will contain either a blank 00247 string, or the name text associated with this item (if any) 00248 00249 Purpose: To determine a name string for this node. Generally, this is used for 00250 a simple mechanism which searches for display items whose names match 00251 given search parameters in some way. It is also used in libraries to 00252 provide default redraw methods. 00253 00254 Notes: **** TO DO **** 00255 Modify this method to return the correct text. You may also want to 00256 add an override for the GetFullInfoText() method if you can provide 00257 a full-info display mode. 00258 00259 SeeAlso: SGDisplayNode::GetNameText 00260 00261 ********************************************************************************************/ 00262 00263 void SGDisplayDATATYPE::GetNameText(String_256 *Result) 00264 { 00265 ERROR3IF(Result == NULL, "Illegal NULL param"); 00266 00267 *Result = _R(IDS_SGBASE_EXAMPLE_TEXT); // TEXT("Example Item"); 00268 } 00269 00270 00271 00272 /*********************************************************************************************** 00273 00274 > virtual void SGDisplayDATATYPE::HandleRedraw(SGRedrawInfo *RedrawInfo, 00275 SGFormatInfo *FormatInfo) 00276 00277 Author: Unattributed (Xara Group Ltd) <camelotdev@xara.com> 00278 Created: 27/1/95 (base generated in sgbase.cpp) 00279 00280 Inputs: RedrawInfo - The information on the kernel-rendered redraw area 00281 FormatInfo - The formatting information structure 00282 00283 member variable FormatRect should be set up (before calling this method) 00284 to be the rectangle in which to draw this item 00285 00286 Purpose: SGDisplayDATATYPE item redraw method - removed from the main HandleEvent 00287 method merely to make the code tidier. 00288 00289 Notes: **** TO DO **** This template method will draw an item as a red splodge 00290 with a constant text string ("Example Item") next to it. You need to replace 00291 this with proper redraw code. To see how different display modes are done 00292 take a look at the bitmap, layer, and colour supergalleries. 00293 00294 VERY IMPORTANT: The rendering must be enclosed by calls to StartRendering 00295 and StopRendering, to ensure that rendering works properly (in the future 00296 we may change the redraw system to use a GRenderRegion for each individual 00297 item, rather than one global one for the window, for which these calls will 00298 be essential) 00299 00300 Scope: private 00301 00302 ***********************************************************************************************/ 00303 00304 void SGDisplayDATATYPE::HandleRedraw(SGRedrawInfo *RedrawInfo, SGMiscInfo *MiscInfo) 00305 { 00306 // First, inform the system that we are about to start rendering this item 00307 StartRendering(RedrawInfo, MiscInfo); 00308 00309 DocRect MyRect(FormatRect); // Get my redraw position from the cached FormatRect 00310 00311 RenderRegion *Renderer = RedrawInfo->Renderer; 00312 00313 INT32 OnePixel = (INT32) DevicePixels(MiscInfo, 1); 00314 INT32 TwoPixels = (INT32) DevicePixels(MiscInfo, 2); 00315 00316 Renderer->SetLineWidth(0); 00317 Renderer->SetLineColour(RedrawInfo->Transparent); 00318 00319 // First, render the icon at the left end of our rectangle 00320 DocRect IconRect(MyRect); 00321 IconRect.hi.x = IconRect.lo.x + IconRect.Height(); // Make it a square 00322 MyRect.lo.x = IconRect.hi.x + TwoPixels; // And exclude it from 'MyRect' 00323 00324 // Redraw the icon 00325 GridLockRect(MiscInfo, &IconRect); // Ensure it maps exactly to specific pixels 00326 IconRect.Inflate(-OnePixel, -OnePixel); // Leave a bit of space around the edge 00327 00328 Renderer->SetFillColour(DocColour(COLOUR_RED)); 00329 Renderer->DrawRect(&IconRect); 00330 00331 GridLockRect(MiscInfo, &MyRect); // Ensure the new 'MyRect' is pixel-grid-aligned 00332 00333 // Set up the colours for rendering our text, and fill the background if selected 00334 if (Flags.Selected) 00335 { 00336 // Fill the entire background with the 'selected' colour, so we don't 00337 // get gaps between bits of text or uneven rectangles in multiple selections 00338 Renderer->SetFillColour(RedrawInfo->SelBackground); 00339 Renderer->DrawRect(&MyRect); 00340 Renderer->SetFixedSystemTextColours(&RedrawInfo->SelForeground, &RedrawInfo->SelBackground); 00341 } 00342 else 00343 Renderer->SetFixedSystemTextColours(&RedrawInfo->Foreground, &RedrawInfo->Background); 00344 00345 MyRect.lo.x += SG_GapBeforeText; // Leave a small gap before text begins 00346 00347 // And render the text 00348 String_256 MyText; 00349 GetNameText(&MyText); 00350 Renderer->DrawFixedSystemText(&MyText, MyRect); 00351 00352 // Finally, inform the system that we have completed rendering this item 00353 StopRendering(RedrawInfo, MiscInfo); 00354 } 00355 00356 00357 00358 /*********************************************************************************************** 00359 00360 > virtual BOOL SGDisplayDATATYPE::HandleEvent(SGEventType EventType, void *EventInfo, 00361 SGMiscInfo *MiscInfo) 00362 00363 Author: Unattributed (Xara Group Ltd) <camelotdev@xara.com> 00364 Created: 27/1/95 (base generated in sgbase.cpp) 00365 00366 Inputs: EventType - An enumerated value describing what type of event is to be processed 00367 00368 EventInfo - A structure describing the event (may be NULL). The exact thing 00369 pointed at by this pointer depends upon the event type: 00370 00371 MonoOn 00372 SGEVENT_FORMAT NULL 00373 SGEVENT_REDRAW (SGRedrawInfo *) 00374 SGEVENT_BGREDRAW NULL 00375 SGEVENT_BGFLUSH NULL - May have NULL MiscInfo 00376 SGEVENT_MOUSECLICK (SGMouseInfo *) 00377 SGEVENT_DRAGSTARTED (DragMessage *) 00378 SGEVENT_CLAIMPOINT (SGMouseInfo *) 00379 SGEVENT_THUMBMSG (ThumbMessage *) - May have NULL MiscInfo 00380 MonoOff 00381 00382 Use the provided SGDisplayNode::Get[Format]Info() inlines to retrieve this 00383 information - they provide useful error/type checking, and hide the cast 00384 00385 MiscInfo - almost always provided. Contains a few useful bits of info that may be 00386 needed for all event types. This may be null for special event types (see sgtree.h 00387 for the enum and information on which ones may pass NULL MiscInfo - currently 00388 this is _THUMBMSG and _BGFLUSH, neither of which should concern you - so as long 00389 as you only reference MiscInfo once you know the event type, you will be safe) 00390 00391 Outputs: FormatInfo is updated as appropriate 00392 00393 Returns: TRUE if the event was handled successfully 00394 FALSE if it was not 00395 00396 Purpose: Handles a SuperGallery DisplayTree event 00397 00398 Notes: This overrides the pure virtual SGDisplayNode::HandleEvent method 00399 00400 A node need not handle a specific event - if it does not handle it, it 00401 should return by calling the base class HandleEvent method, so that 00402 default actions for new/unknown events can be supplied by the base class. 00403 00404 Redraw and Formatting handlers should never return TRUE, as this will 00405 prevent the event from continuing through the tree. 00406 00407 Non-leaf-nodes must call SGDisplayNode::GiveEventToMyChildren in order 00408 to pass the event dow the tree. THIS node is a leaf-node, so it doesn't. 00409 00410 SeeAlso: SGDisplayNode::HandleEvent; SGDisplayItem::HandleEvent 00411 00412 ***********************************************************************************************/ 00413 00414 BOOL SGDisplayDATATYPE::HandleEvent(SGEventType EventType, void *EventInfo, 00415 SGMiscInfo *MiscInfo) 00416 { 00417 switch (EventType) 00418 { 00419 case SGEVENT_FORMAT: 00420 { 00421 SGFormatInfo *FormatInfo = GetFormatInfo(EventType, EventInfo); 00422 CalculateMyRect(FormatInfo, MiscInfo); // Cache our FormatRect for later use 00423 } 00424 break; 00425 00426 00427 case SGEVENT_REDRAW: 00428 { 00429 DocRect MyRect(FormatRect); // Rely on FormatRect being cached from above 00430 SGRedrawInfo *RedrawInfo = GetRedrawInfo(EventType, EventInfo); 00431 00432 if (IMustRedraw(RedrawInfo)) // only redraw if we intersect the clip rect 00433 HandleRedraw(RedrawInfo, MiscInfo); 00434 } 00435 break; // exit and return FALSE to pass the redraw event on 00436 00437 00438 case SGEVENT_MOUSECLICK: 00439 { 00440 SGMouseInfo *Mouse = GetMouseInfo(EventType, EventInfo); 00441 00442 if (FormatRect.ContainsCoord(Mouse->Position)) 00443 { 00444 // Test for drag... **** !!!! ToDo !!!! **** 00445 // DefaultDragHandler(Mouse, MiscInfo); 00446 00447 // No drag, so move on to normal selection click handling 00448 DefaultClickHandler(Mouse, MiscInfo); 00449 00450 return(TRUE); // Claim this event - nobody else can own this click 00451 } 00452 } 00453 break; 00454 00455 default: 00456 // Let the base class handle any events we don't know about. 00457 // This includes things like hit testing (CLAIMPOINT) etc 00458 return(SGDisplayItem::HandleEvent(EventType, EventInfo, MiscInfo)); 00459 } 00460 00461 // Default return value: We do not claim this event, so it will be passed on to others 00462 return(FALSE); 00463 } 00464 00465 00466 00467 00468 00469 00470 00471 00472 00473 00474 00475 00476 00477 00478 00479 00480 /******************************************************************************************** 00481 00482 > TEMPLATESGallery::TEMPLATESGallery() 00483 00484 Author: Unattributed (Xara Group Ltd) <camelotdev@xara.com> 00485 Created: 27/1/95 (base generated in sgbase.cpp) 00486 Purpose: TEMPLATESGallery default constructor 00487 00488 ********************************************************************************************/ 00489 00490 TEMPLATESGallery::TEMPLATESGallery() 00491 { 00492 } 00493 00494 00495 00496 /******************************************************************************************** 00497 00498 > TEMPLATESGallery::~TEMPLATESGallery() 00499 00500 Author: Unattributed (Xara Group Ltd) <camelotdev@xara.com> 00501 Created: 27/1/95 (base generated in sgbase.cpp) 00502 Purpose: TEMPLATESGallery destructor. 00503 00504 ********************************************************************************************/ 00505 00506 TEMPLATESGallery::~TEMPLATESGallery() 00507 { 00508 } 00509 00510 00511 00512 /******************************************************************************************** 00513 00514 > void TEMPLATESGallery::CreateNewSubtree(Document *ParentDoc, SGDisplayGroup *ExistingGroup) 00515 00516 Author: Unattributed (Xara Group Ltd) <camelotdev@xara.com> 00517 Created: 27/1/95 (base generated in sgbase.cpp) 00518 00519 Inputs: ParentDoc - The document to create a display subtree for 00520 ExistingGroup - NULL (creates a new group for this document), or 00521 a pointer to the existing group-node for this document (in which case 00522 it clears all displayitems from the group and rebuilds it in place - this 00523 stops the display group moving around the tree at random!) 00524 00525 Purpose: Internal call. This takes the DATATYPE list of the given document and 00526 creates a DisplayTree subtree from it. This subtree is then added to 00527 the DisplayTree. Note that this does not force a redraw of the list - 00528 after making this call, you should also call ForceRedrawOfList 00529 00530 Notes: Passing in a NULL parent document pointer results in an ERROR3 - 00531 the function returns without doing anything in retail builds 00532 00533 SeeAlso: SuperGallery::ForceRedrawOfList 00534 00535 ********************************************************************************************/ 00536 00537 void TEMPLATESGallery::CreateNewSubtree(Document *ParentDoc, SGDisplayGroup *ExistingGroup) 00538 { 00539 ERROR3IF(ParentDoc == NULL, "TEMPLATESGallery::CreateNewSubtree - NULL parameter passed in"); 00540 if (ParentDoc == NULL) 00541 return; 00542 00543 SGDisplayGroup *DisplayDocument; 00544 SGDisplayDATATYPE *DisplayDATATYPE; 00545 00546 if (ExistingGroup != NULL) 00547 { 00548 ERROR3IF(ExistingGroup->GetParentDocument() != ParentDoc, 00549 "This group is not for that document! What's going down, dude?"); 00550 DisplayDocument = ExistingGroup; // Use existing group 00551 DisplayDocument->DestroySubtree(FALSE); // Wipe any existing DATATYPE display items 00552 } 00553 else 00554 { 00555 DisplayDocument = new SGDisplayGroup(this, ParentDoc,NULL); // Create new Group 00556 00557 if (DisplayDocument == NULL) // Total failure - abort 00558 return; 00559 00560 DisplayTree->AddItem(DisplayDocument); // Add new group to tree 00561 } 00562 00563 00564 // **** TO DO **** 00565 // Fill in some code here to generate SGDisplayDATATYPEs to be displayed. 00566 // e.g: (in PSEUDO code!! ;-) 00567 // 00568 // DATATYPE *Ptr = ParentDoc->GetDATATYPEList()->GetHead(); 00569 // while (Ptr != NULL) 00570 // { 00571 // DisplayDATATYPE = new SGDisplayDATATYPE(Ptr); 00572 // if (DisplayDATATYPE != NULL) 00573 // DisplayDocument->AddItem(DisplayDATATYPE); 00574 // 00575 // Ptr = ParentDoc->GetDATATYPEList()->GetNext(); 00576 // } 00577 // 00578 // 00579 // Default : create a few items to display 00580 // NOTE: The pointer faked up to pass in to the constructor will cause the thing 00581 // to blow up if you start actually trying to USE the data item! Replace this at 00582 // earliest convenience with proper tree construction code. 00583 for (INT32 Bob = 0; Bob < 7; Bob++) 00584 { 00585 DisplayDATATYPE = new SGDisplayDATATYPE( (DATATYPE *) 0xcdcdcdcd ); 00586 if (DisplayDATATYPE != NULL) 00587 DisplayDocument->AddItem(DisplayDATATYPE); 00588 } 00589 } 00590 00591 00592 00593 /******************************************************************************************** 00594 00595 > BOOL TEMPLATESGallery::PreCreate(void) 00596 00597 Author: Unattributed (Xara Group Ltd) <camelotdev@xara.com> 00598 Created: 27/1/95 (base generated in sgbase.cpp) 00599 00600 Returns: TRUE if the Gallery initialised successfully 00601 FALSE if it should not be opened due to a failure to initialise 00602 00603 Purpose: The TEMPLATESGallery PreCreate handler. This overrides the base class 00604 PreCreate function. It is called at the very beginning of the 00605 SuperGallery::Create method, before the window has been created. 00606 00607 Notes: As this is called before the window is open, it must not attempt to touch 00608 any of the button gadgets in the window, or force redraws, etc. Also, 00609 events cannot be passed to the tree, as the tree formatting relies on 00610 knowing the window size - however, the tree will be reformatted and 00611 redrawn automatically when the window is opened - this will happen shortly. 00612 00613 ********************************************************************************************/ 00614 00615 BOOL TEMPLATESGallery::PreCreate(void) 00616 { 00617 // If there isn't already one, create a DisplayTree 00618 if (DisplayTree == NULL) 00619 { 00620 DisplayTree = new SGDisplayRootScroll(this); // New root node, with a scrollbar 00621 if (DisplayTree == NULL) 00622 return(FALSE); 00623 } 00624 00625 00626 // **** TO DO **** 00627 // You may not need to adjust the following, but note that it re-creates the entire 00628 // display tree from scratch whenever the gallery window is opened - if this is 00629 // unsuitable for your needs, you'll have to change it (e.g. you could make it only 00630 // do it if the DisplayTree has not already been created, above) 00631 00632 // And for each document already present, create a display subtree (possibly replacing 00633 // a previous displaytree for it if we had one earlier) 00634 Document *ParentDoc = (Document *) GetApplication()->Documents.GetTail(); 00635 while (ParentDoc != NULL) 00636 { 00637 // Find the existing subtree, if any 00638 SGDisplayGroup *ParentGroup = DisplayTree->FindSubtree(this, ParentDoc, NULL); 00639 00640 // Create a new subtree, replacing the old one if possible 00641 CreateNewSubtree(ParentDoc, ParentGroup); 00642 00643 ParentDoc = (Document *) GetApplication()->Documents.GetPrev(ParentDoc); 00644 } 00645 00646 return(TRUE); 00647 } 00648 00649 00650 00651 /******************************************************************************************** 00652 00653 > virtual BOOL TEMPLATESGallery::ApplyAction(SGActionType Action) 00654 00655 Author: Unattributed (Xara Group Ltd) <camelotdev@xara.com> 00656 Created: 27/1/95 (base generated in sgbase.cpp) 00657 00658 Inputs: Action - Indicates what action to apply 00659 00660 Returns: TRUE to indicate successful handling of the action, or 00661 FALSE to indicate failure 00662 00663 Purpose: Applies certain conventional gallery actions (usually associated with 00664 gallery buttons, for new, edit, delete, etc) 00665 00666 SeeAlso: SGActionType 00667 00668 ********************************************************************************************/ 00669 00670 BOOL TEMPLATESGallery::ApplyAction(SGActionType Action) 00671 { 00672 // No display tree? Better forget about it then! 00673 if (DisplayTree == NULL) 00674 return(FALSE); 00675 00676 // Determine useful info - this is usually needed for most actions, so always get it 00677 Document *SelectedDoc = Document::GetSelected(); 00678 SGDisplayGroup *DocumentGroup = DisplayTree->FindSubtree(this, SelectedDoc, NULL); 00679 SGDisplayDATATYPE *FirstSelected = NULL; 00680 00681 if (DocumentGroup != NULL) 00682 FirstSelected = (SGDisplayDATATYPE *) DocumentGroup->FindNextSelectedItem(NULL); 00683 00684 // Now, process the action TO DO! - see Colour gallery for examples 00685 switch(Action) 00686 { 00687 case SGACTION_CREATE: 00688 TRACE( _T("Unimplemented feature executed in TEMPLATE gallery")); 00689 break; 00690 00691 case SGACTION_APPLY: 00692 TRACE( _T("Unimplemented feature executed in TEMPLATE gallery")); 00693 break; 00694 00695 case SGACTION_REDEFINE: 00696 TRACE( _T("Unimplemented feature executed in TEMPLATE gallery")); 00697 break; 00698 00699 case SGACTION_EDIT: 00700 TRACE( _T("Unimplemented feature executed in TEMPLATE gallery")); 00701 break; 00702 00703 case SGACTION_DELETE: 00704 TRACE( _T("Unimplemented feature executed in TEMPLATE gallery")); 00705 break; 00706 00707 case SGACTION_DISPLAYMODECHANGED: 00708 TRACE( _T("Unimplemented feature executed in TEMPLATE gallery")); 00709 break; 00710 00711 default: 00712 return(FALSE); 00713 } 00714 00715 return(TRUE); 00716 } 00717 00718 00719 00720 /******************************************************************************************** 00721 00722 > virtual MsgResult TEMPLATESGallery::Message(Msg* Message) 00723 00724 Author: Unattributed (Xara Group Ltd) <camelotdev@xara.com> 00725 Created: 27/1/95 (base generated in sgbase.cpp) 00726 Inputs: Message - The message to handle 00727 00728 Purpose: A standard message handler, really. 00729 00730 Notes: Any messages that this does not handle must be passed down to the 00731 SuperGallery base class message handler. 00732 00733 NOTE WELL that the SuperGallery base class handler does some funky things 00734 for us - see SuperGallery::Message - such as deleting our display subtree 00735 for any document which dies (which, uncannily, would explain why they go 00736 away like that when you close documents ;-), and shading the gallery when 00737 there are no documents present. [To override this behaviour in these cases, 00738 you should respond to the message, and return OK rather than calling the 00739 base class message handler] 00740 00741 SeeAlso: SuperGallery::Message 00742 00743 ********************************************************************************************/ 00744 00745 MsgResult TEMPLATESGallery::Message(Msg* Message) 00746 { 00747 if (IS_OUR_DIALOG_MSG(Message)) 00748 { 00749 DialogMsg* Msg = (DialogMsg*)Message; 00750 00751 switch (Msg->DlgMsg) 00752 { 00753 case DIM_CREATE: 00754 SGInit::UpdateGalleryButton(OPTOKEN_DISPLAYTEMPLATEGALLERY, TRUE); 00755 break; 00756 00757 case DIM_CANCEL: 00758 SGInit::UpdateGalleryButton(OPTOKEN_DISPLAYTEMPLATEGALLERY, FALSE); 00759 break; 00760 } 00761 00762 return(SuperGallery::Message(Message)); 00763 } 00764 00765 // If we have no displaytree, then we have not been shown, or something terrible has 00766 // happened, so we don't bother handling any of these messages. 00767 if (DisplayTree == NULL) 00768 return(SuperGallery::Message(Message)); 00769 00770 00771 // **** TO DO **** 00772 // Just another note: Most galleries ignore most messages when closed (!IsVisible()) 00773 // This means that they must re-create themselves properly to get back up to date 00774 // when they are opened - this is done in the PostCreate handler. If you wish to 00775 // respond to messages to keep up to date while closed, you should address the 00776 // default code in the PostCreate handler as well. 00777 00778 if (IsVisible() && MESSAGE_IS_A(Message, DocChangingMsg)) 00779 { 00780 DocChangingMsg *TheMsg = (DocChangingMsg *) Message; 00781 00782 switch ( TheMsg->State ) 00783 { 00784 case DocChangingMsg::DocState::BORN: // New document - add to display tree 00785 { 00786 INT32 Extent = GetDisplayExtent(); // Remember previous list extent 00787 00788 CreateNewSubtree(TheMsg->pChangingDoc); // Add a subtree for this doc 00789 ShadeGallery(FALSE); // Unshade the gallery 00790 00791 InvalidateCachedFormat(); // And redraw what is necessary 00792 RedrawEverythingBelow(-Extent); 00793 } 00794 break; // Pass this message on to the base class as well 00795 } 00796 } 00797 00798 return(SuperGallery::Message(Message)); 00799 } 00800 00801 00802 00803 00804 00805 00806 00807 00808 00809 00810 00811 00812 00813 00814 00815 00816 /******************************************************************************************** 00817 00818 > BOOL OpDisplayTEMPLATEGallery::Init() 00819 00820 Author: Unattributed (Xara Group Ltd) <camelotdev@xara.com> 00821 Created: 9/2/95 (base generated in sgbase.cpp) 00822 Inputs: - 00823 Outputs: - 00824 Returns: TRUE if the operation could be successfully initialised 00825 FALSE if no more memory could be allocated 00826 00827 Purpose: OpDisplayTEMPLATEGallery initialiser method 00828 Errors: ERROR will be called if there was insufficient memory to allocate the 00829 operation. 00830 SeeAlso: - 00831 00832 ********************************************************************************************/ 00833 00834 BOOL OpDisplayTEMPLATEGallery::Init() 00835 { 00836 00837 // **** TO DO **** 00838 // Ensure the IDS_ OPTOKEN_ and IDBBL_ constants are available and correct 00839 // You should really also uppercase these constant names. 00840 00841 return (RegisterOpDescriptor( 00842 0, 00843 _R(IDS_DISPLAY_TEMPLATE_GALLERY), 00844 CC_RUNTIME_CLASS(OpDisplayTEMPLATEGallery), 00845 OPTOKEN_DISPLAYTEMPLATEGALLERY, 00846 OpDisplayTEMPLATEGallery::GetState, 00847 0, /* help ID */ 00848 _R(IDBBL_DISPLAY_TEMPLATE_GALLERY), 00849 0 /* bitmap ID */)); 00850 } 00851 00852 /******************************************************************************************** 00853 00854 > OpState OpDisplayTEMPLATEGallery::GetState(String_256*, OpDescriptor*) 00855 00856 Author: Unattributed (Xara Group Ltd) <camelotdev@xara.com> 00857 Created: 9/2/95 (base generated in sgbase.cpp) 00858 Inputs: - 00859 Outputs: - 00860 Returns: The state of the OpDisplayTEMPLATEGallery operation 00861 Purpose: For finding the OpDisplayTEMPLATEGallery's state. 00862 Errors: - 00863 SeeAlso: - 00864 00865 ********************************************************************************************/ 00866 00867 OpState OpDisplayTEMPLATEGallery::GetState(String_256* UIDescription, OpDescriptor*) 00868 { 00869 OpState OpSt; 00870 00871 // If the gallery is currenty open, then the menu item should be ticked 00872 DialogBarOp* pDialogBarOp = FindGallery(); 00873 if (pDialogBarOp != NULL) 00874 OpSt.Ticked = pDialogBarOp->IsVisible(); 00875 00876 // If there are no open documents, you can't toggle the gallery 00877 OpSt.Greyed = (Document::GetSelected() == NULL); 00878 return(OpSt); 00879 } 00880 00881 00882 00883 /******************************************************************************************** 00884 00885 > void OpDisplayTEMPLATEGallery::Do(OpDescriptor*) 00886 00887 Author: Unattributed (Xara Group Ltd) <camelotdev@xara.com> 00888 Created: 9/2/95 (base generated in sgbase.cpp) 00889 Inputs: - 00890 Outputs: - 00891 Returns: - 00892 Purpose: Displays the TEMPLATEs gallery 00893 Updates the button state for this Op (the button sticks down while the 00894 gallery is open) 00895 Errors: - 00896 SeeAlso: - 00897 00898 ********************************************************************************************/ 00899 00900 void OpDisplayTEMPLATEGallery::Do(OpDescriptor*) 00901 { 00902 DialogBarOp *pDialogBarOp = FindGallery(); 00903 00904 if (pDialogBarOp != NULL) 00905 { 00906 // Toggle the visible state of the gallery window 00907 pDialogBarOp->SetVisibility( !pDialogBarOp->IsVisible() ); 00908 00909 // And update the gallery button state 00910 SGInit::UpdateGalleryButton(OPTOKEN_DISPLAYTEMPLATEGALLERY, pDialogBarOp->IsVisible()); 00911 } 00912 00913 End(); 00914 } 00915 00916 00917 00918 /******************************************************************************************** 00919 00920 > static DialogBarOp *OpDisplayTEMPLATEGallery::FindGallery(void) 00921 00922 Author: Unattributed (Xara Group Ltd) <camelotdev@xara.com> 00923 Created: 9/2/95 (base generated in sgbase.cpp) 00924 00925 Returns: NULL or a pointer to the TEMPLATE gallery instance 00926 00927 Purpose: Finds the TEMPLATE gallery class instance 00928 00929 Notes: The bars system always keeps one TEMPLATE gallery alive for us. 00930 If one is not found, this usually indicates that it can't be found 00931 in bars.ini: Check that the 'Name' string *exactly* matches the 00932 title string given in bars.ini. 00933 Also check that bars.ini indicates the bar is of the TEMPLATESGallery class 00934 00935 ********************************************************************************************/ 00936 00937 DialogBarOp *OpDisplayTEMPLATEGallery::FindGallery(void) 00938 { 00939 String_32 Name = _R(IDS_SGBASE_TEMPLATE_GALLERY); //"TEMPLATE gallery"; 00940 DialogBarOp* pDialogBarOp = DialogBarOp::FindDialogBarOp(Name); 00941 00942 if (pDialogBarOp != NULL) 00943 { 00944 if (pDialogBarOp->GetRuntimeClass() == CC_RUNTIME_CLASS(TEMPLATESGallery)) 00945 return(pDialogBarOp); 00946 00947 ERROR3("Got the TEMPLATE gallery but it's not of the TEMPLATESGallery class"); 00948 } 00949 else 00950 { 00951 ERROR3("Can't find the TEMPLATE gallery in bars.ini!\n"); 00952 } 00953 00954 return(NULL); 00955 } 00956