00001 // $Id: prevwdlg.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 // A simple Dialog That does some Gavin Rendering into itself 00099 00100 /* 00101 */ 00102 00103 #include "camtypes.h" 00104 #include "prevwdlg.h" 00105 00106 #include "ccdc.h" // specific #includes needed for kernel-rendered dialogues 00107 #include "dlgcol.h" // DialogColourInfo 00108 //#include "fillval.h" 00109 #include "grnddib.h" 00110 00111 //#include "prevwres.h" 00112 #include "impexpop.h" // BitmapExportParam 00113 #include "nodebmp.h" // NodeBitmap 00114 //#include "gifutil.h" // GDM_BACKTOBACK 00115 #include "dlgview.h" // DialogView 00116 00117 //#include "rikdlg.h" // _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER) 00118 //#include "app.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00119 #include "ctrlhelp.h" 00120 //#include "docvmsg.h" - in camtypes.h [AUTOMATICALLY REMOVED] 00121 00122 //#include "spread.h" // GetFirstFrameLayer() - in camtypes.h [AUTOMATICALLY REMOVED] 00123 00124 //#include "xshelpid.h" //For the help ID 00125 00126 // This is not compulsory, but you may as well put it in so that the correct version 00127 // of your file can be registered in the .exe 00128 DECLARE_SOURCE("$Revision: 1282 $"); 00129 00130 // An implement to match the Declare in the .h file. 00131 // If you have many classes, it is recommended to place them all together, here at the start of the file 00132 CC_IMPLEMENT_DYNCREATE(AnimatedBitmapItem, ListItem) 00133 CC_IMPLEMENT_DYNCREATE(PreviewDialog, DialogOp) 00134 00135 // This will get Camelot to display the filename and linenumber of any memory allocations 00136 // that are not released at program exit 00137 #define new CAM_DEBUG_NEW 00138 00139 00140 // Set the static vars of the render dialog 00141 const CDlgMode PreviewDialog::Mode = MODELESS; 00142 const UINT32 PreviewDialog::IDD = _R(IDD_PREVIEWDIALOG); 00143 BOOL PreviewDialog::m_AnimationPropertiesChanged = FALSE; 00144 00145 typedef struct 00146 { 00147 CGadgetID Gadget; // Gadget ID 00148 UINT32 BubbleID; //Bubble help ID for this gadget 00149 } GadgetBubbleHelp; 00150 00151 00152 // If extra controls are added to the Preview dialog and 00153 // they require Bubble help, add them to this table. 00154 static GadgetBubbleHelp BubbleHelp[] = 00155 { 00156 00157 { _R(IDC_PREVIEW_PLAY), _R(IDS_PREVIEWBH_PLAY) }, 00158 { _R(IDC_PREVIEW_STOP), _R(IDS_PREVIEWBH_STOP) }, 00159 { _R(IDC_PREVIEW_NEXTFRAME), _R(IDS_PREVIEWBH_NEXTFRAME) }, 00160 { _R(IDC_PREVIEW_PREVFRAME), _R(IDS_PREVIEWBH_PREVFRAME) }, 00161 { _R(IDC_PREVIEW_SLIDER), _R(IDS_PREVIEWBH_SLIDER) }, 00162 { 0, 0 } 00163 00164 }; 00165 00166 BOOL PreviewDialog::viaBitmapGallery = FALSE; 00167 00168 00169 00170 00171 /******************************************************************************************** 00172 00173 > AnimatedBitmapItem::AnimatedBitmapItem(KernelBitmap *pEntry, Layer * pLayer = NULL) 00174 00175 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00176 Created: 11/4/97 00177 Inputs: pEntry - The bitmap to add to the list of frames 00178 pLayer - The layer that the bitmap is associated with (defaults to NULL) 00179 Purpose: To add a bitmap to the list of frames in the animation sequence. If it has 00180 an associated layer then add this at the same time. 00181 00182 ********************************************************************************************/ 00183 00184 AnimatedBitmapItem::AnimatedBitmapItem(KernelBitmap * pEntry, Layer * pLayer) 00185 { 00186 m_pBitmap = pEntry; 00187 m_pLayer = pLayer; 00188 } 00189 00190 /******************************************************************************************** 00191 00192 > AnimatedBitmapItem::AnimatedBitmapItem() 00193 00194 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00195 Created: 11/4/97 00196 Purpose: Default contructor. 00197 00198 ********************************************************************************************/ 00199 00200 AnimatedBitmapItem::AnimatedBitmapItem() 00201 { 00202 ERROR3("AnimatedBitmapItem::AnimatedBitmapItem - call the other constructor"); 00203 m_pBitmap = NULL; 00204 m_pLayer = NULL; 00205 } 00206 00207 /******************************************************************************************** 00208 00209 > AnimatedBitmapItem::~AnimatedBitmapItem() 00210 00211 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00212 Created: 11/4/97 00213 Purpose: Default destructor 00214 00215 ********************************************************************************************/ 00216 00217 AnimatedBitmapItem::~AnimatedBitmapItem() 00218 { 00219 // Do not attempt to delete the pointers that we have as these are references 00220 // rather than anything that we have allocated 00221 } 00222 00223 00224 00225 /******************************************************************************************* 00226 ********************************************************************************************/ 00227 // Initialise our statics 00228 00229 PreviewDialog * PreviewDialog::m_pPreviewDialog = NULL; 00230 UINT32 PreviewDialog::m_Delay = 0; 00231 00232 00233 /******************************************************************************************* 00234 00235 > PreviewDialog::PreviewDialog() : DialogOp(RenderDlg::IDD, RenderDlg::Mode) 00236 00237 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00238 Created: 11/4/97 00239 Purpose: Constructs a Preview Dialog 00240 00241 *******************************************************************************************/ 00242 00243 PreviewDialog::PreviewDialog() : DialogOp(PreviewDialog::IDD, PreviewDialog::Mode), m_Timer(this) 00244 { 00245 m_BitmapListSize = 0; 00246 m_CurrentItem = 0; 00247 m_pPreviewDialog = this; 00248 m_pRender = NULL; 00249 m_PlayAnimation = TRUE; 00250 m_DisplayNextFrame = FALSE; 00251 m_DisplayPreviousFrame = FALSE; 00252 m_SliderPosition = m_BitmapListSize; 00253 m_DocumentAboutToDie = FALSE; 00254 m_SetPreviewDlgToIdleState = FALSE; 00255 m_GeneratedFrameLayers = FALSE; 00256 m_DisposalMethod = GDM_BACKTOBACK; 00257 m_CurrentDisposalMethod = GDM_BACKTOBACK; 00258 00259 m_AnimationRect.MakeEmpty(); 00260 00261 // Reset the loop counts 00262 m_CurrentLoopCount = 0; // The loop that we are currently on (default to start) 00263 m_RequiredLoopCount = 0; // The loop count that we must reach (default for ever) 00264 00265 //viaBitmapGallery = FALSE; // THIS MUST ALREADY HAVE BEEN SET TO THE CORRECT 00266 // VALUE !!!!! 00267 00268 // Get the input focus for bubble help. 00269 GetApplication()->RegisterIdleProcessor(IDLEPRIORITY_HIGH, this); 00270 } 00271 00272 /******************************************************************************************* 00273 00274 > PreviewDialog::~PreviewDialog() 00275 00276 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00277 Created: 11/4/97 00278 Purpose: Destructor 00279 00280 *******************************************************************************************/ 00281 00282 PreviewDialog::~PreviewDialog() 00283 { 00284 // clean out the render region, if allocated 00285 if (m_pRender) 00286 { 00287 // Delete the render region and its (dialog) view 00288 // Do it by hand as StopRender should have been called already 00289 delete m_pRender->GetRenderView(); 00290 delete m_pRender; 00291 // DestroyGRenderRegion(m_pRender); 00292 m_pRender = NULL; 00293 } 00294 00295 // Clean out the list of bitmaps that we were animating 00296 m_BitmapList.DeleteAll(); 00297 00298 // kill the static link to this dialog box 00299 m_pPreviewDialog = NULL; 00300 00301 // The dialog has been destroyed, remove the input focus. 00302 GetApplication()->RemoveIdleProcessor(IDLEPRIORITY_HIGH, this); 00303 } 00304 00305 00306 00307 /******************************************************************************************* 00308 00309 > MsgResult PreviewDialog::Message(Msg* Message) 00310 00311 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00312 Created: 11/4/97 00313 Purpose: Handles all the Preview dialog's messages 00314 00315 *******************************************************************************************/ 00316 00317 MsgResult PreviewDialog::Message(Msg* Message) 00318 { 00319 MsgResult Result; 00320 00321 BOOL EndDialog = FALSE; // TRUE if we should quit the dialog 00322 00323 // See if it is for us 00324 if (IS_OUR_DIALOG_MSG(Message)) 00325 { 00326 // it is 00327 DialogMsg* Msg = (DialogMsg*)Message; 00328 00329 // decide what to do 00330 switch (Msg->DlgMsg) 00331 { 00332 // Create message 00333 case DIM_CREATE : 00334 // As it is a modal dialog box we are sent a message to say the dialog box 00335 // is being created, so we have a chance to set the initial control values. 00336 // if (Mode == MODAL) 00337 { 00338 InitDialog(); 00339 SetUpCallBack(); 00340 00341 INT32 i = 0; 00342 while (BubbleHelp[i].Gadget) 00343 { 00344 SetGadgetHelp(BubbleHelp[i].Gadget, BubbleHelp[i].BubbleID, BubbleHelp[i].BubbleID); 00345 i++; 00346 } 00347 break; 00348 } 00349 // break; 00350 00351 // Close and destroy the dialog 00352 case DIM_COMMIT : 00353 case DIM_CANCEL : 00354 { 00355 EndDialog = TRUE; // Flag to close and end 00356 break; 00357 } 00358 //case DIM_SLIDER_POS_SET: 00359 case DIM_SLIDER_POS_CHANGING: 00360 { 00361 // Messages to all the controls, handled individually 00362 if (Msg->GadgetID == _R(IDC_PREVIEW_SLIDER)) 00363 { 00364 // While the animation is playing, if this button is selected, 00365 // the play button is clicked out, the stop button is clicked in, 00366 // and the next/previous frame in the animation is displayed. 00367 PreviewDlgStop(); 00368 // Kill any bubble help just in case the user has bubble help up 00369 // over the slider 00370 PORTNOTE("other", "Remove Bubble help reference"); 00371 #ifndef EXCLUDE_FROM_XARALX 00372 ControlHelper::BubbleHelpDisable(); 00373 #endif 00374 SetSliderPosition(); 00375 00376 // Force the gadget to be repainted, 00377 // causes a DIM_REDRAW\_R(IDC_REDRAW_ME) message to be sent. 00378 InvalidateGadget(_R(IDC_REDRAW_ME)); 00379 } 00380 break; //DIM_SLIDER_POS_CHANGING: 00381 } 00382 00383 case DIM_LFT_BN_CLICKED : 00384 { 00385 // See which button was pressed 00386 if (FALSE) {} 00387 else if (Msg->GadgetID == _R(IDC_PREVIEW_PLAY)) 00388 { 00389 // Play the animation. 00390 PreviewDlgPlay(); 00391 00392 // Force the gadget to be repainted, 00393 // causes a DIM_REDRAW\_R(IDC_REDRAW_ME) message to be sent. 00394 InvalidateGadget(_R(IDC_REDRAW_ME)); 00395 } 00396 else if (Msg->GadgetID == _R(IDC_PREVIEW_STOP)) 00397 { 00398 // Stop the animation. 00399 PreviewDlgStop(); 00400 00401 // Force the gadget to be repainted, 00402 // causes a DIM_REDRAW\_R(IDC_REDRAW_ME) message to be sent. 00403 InvalidateGadget(_R(IDC_REDRAW_ME)); 00404 } 00405 else if (Msg->GadgetID == _R(IDC_PREVIEW_NEXTFRAME)) 00406 { 00407 // While the animation is playing, if this button is selected, 00408 // the play button is clicked out, the stop button is clicked in, 00409 // and the next frame in the animation is displayed. 00410 PreviewNextFrame(); 00411 00412 // Force the gadget to be repainted, 00413 // causes a DIM_REDRAW\_R(IDC_REDRAW_ME) message to be sent. 00414 InvalidateGadget(_R(IDC_REDRAW_ME)); 00415 00416 // Only show one frame at a time, therefore set this flag back to false. 00417 m_DisplayNextFrame = FALSE; 00418 } 00419 else if (Msg->GadgetID == _R(IDC_PREVIEW_PREVFRAME)) 00420 { 00421 // While the animation is playing, if this button is selected, 00422 // the play button is clicked out, the stop button is clicked in, 00423 // and the previous frame in the animation is displayed. 00424 PreviewPreviousFrame(); 00425 00426 // Force the gadget to be repainted, 00427 // causes a DIM_REDRAW\_R(IDC_REDRAW_ME) message to be sent. 00428 InvalidateGadget(_R(IDC_REDRAW_ME)); 00429 00430 // Only show one frame at a time, therefore, set this flag to false. 00431 m_DisplayPreviousFrame = FALSE; 00432 } 00433 else if (Msg->GadgetID == _R(IDC_PREVIEW_REFRESH)) 00434 { 00435 // Has the refresh button been clicked, while the dlg is in an idle state. 00436 if (m_SetPreviewDlgToIdleState) 00437 SetDlgStateAfterDocChange(); 00438 else 00439 SetDlgStateAfterRefresh(); 00440 } 00441 /* 00442 else if (Msg->GadgetID == _R(IDC_PREVIEW_STARTFRAME)) 00443 { 00444 m_DisplayListOfBitmaps = TRUE; 00445 00446 // Find the first frame in our list. 00447 m_pPreviewDialog->SelectFirstBitmap(); 00448 00449 // Force the gadget to be repainted, 00450 // causes a DIM_REDRAW\_R(IDC_REDRAW_ME) message to be sent. 00451 m_pPreviewDialog->InvalidateGadget(_R(IDC_REDRAW_ME)); 00452 m_DisplayListOfBitmaps = FALSE; 00453 00454 break; 00455 }*/ 00456 00457 /* 00458 else if (Msg->GadgetID == _R(IDC_PREVIEW_ENDFRAME)) 00459 { 00460 m_DisplayListOfBitmaps = TRUE; 00461 // Find the first frame in our list. 00462 SelectLastBitmap(); 00463 00464 // Force the gadget to be repainted, 00465 // causes a DIM_REDRAW\_R(IDC_REDRAW_ME) message to be sent. 00466 m_pPreviewDialog->InvalidateGadget(_R(IDC_REDRAW_ME)); 00467 m_DisplayListOfBitmaps = FALSE; 00468 } 00469 { 00470 BOOL Valid = FALSE; 00471 BOOL State = GetLongGadgetValue(Msg->GadgetID, 0, 1, NULL, &Valid); 00472 //if (State) 00473 // SetLongGadgetValue(Msg->GadgetID, !State); 00474 break; 00475 } */ 00476 } 00477 00478 case DIM_REDRAW : 00479 { 00480 // This is where all the redrawing is done 00481 // Which control in the window is sending the redraw message (if there are many 00482 // grdraw controls you can tell which is which from the Gadget ID 00483 if (Msg->GadgetID == _R(IDC_REDRAW_ME)) 00484 { 00485 if(m_SetPreviewDlgToIdleState) 00486 // Set the Preview dialog to an idle state. 00487 SetPreviewDialogToIdleState((ReDrawInfoType*) Msg->DlgMsgParam); 00488 else 00489 // Render this control. 00490 RenderControl((ReDrawInfoType*) Msg->DlgMsgParam); 00491 } 00492 else 00493 { 00494 // give out an error in debug builds, ignore in retail builds 00495 ERROR3("Got a redraw message for a control I don't know about"); 00496 } 00497 break; 00498 } 00499 default: 00500 break; 00501 } 00502 } 00503 else if (MESSAGE_IS_A(Message, DocChangingMsg)) 00504 { 00505 DocChangingMsg *Msg = (DocChangingMsg *) Message; 00506 switch (Msg->State) 00507 { 00508 case DocChangingMsg::ABOUTTODIE: 00509 /*{ 00510 if (Msg->pOldDoc == NULL) 00511 { 00512 //Stop playing the animation. 00513 m_DocumentAboutToDie = TRUE; 00514 00515 // Since the document is about to die, no frame layers will exist. 00516 m_GeneratedFrameLayers = FALSE; 00517 00518 // Reset the disposal method 00519 m_DisposalMethod = GDM_BACKTOBACK; 00520 m_CurrentDisposalMethod = GDM_BACKTOBACK; 00521 00522 // End the dialog 00523 // EndDialog = TRUE; // Flag to close and end 00524 } 00525 break; 00526 }*/ 00527 case DocChangingMsg::SELCHANGED: 00528 case DocChangingMsg::BORN: 00529 /*{ 00530 // called when new is used,thereafter called when no docs. are around. 00531 if (Msg->pNewDoc == NULL) 00532 { 00533 SetDialogToIdleState(); 00534 00535 // End the dialog 00536 //EndDialog = TRUE; // Flag to close and end 00537 } 00538 // There is an active doucment around. 00539 else 00540 { 00541 SetDialogToIdleState(); 00542 } 00543 break; 00544 }*/ 00545 EndDialog = TRUE; 00546 break; 00547 00548 default: 00549 break; 00550 } 00551 } 00552 00553 // End dialog here 00554 if (EndDialog) 00555 { 00556 Close(); // Hide the dialog box 00557 End(); // Finish the operation 00558 return OK; 00559 } 00560 00561 // Allow the base class access to the message, it will do the 00562 // DLG_EAT_IF_HUNGRY(Msg) for us 00563 // Must do this before the Close and End 00564 Result = DialogOp::Message(Message); 00565 00566 00567 // The message was for our dialog box so return that we have handled it, if necessary 00568 //return (DLG_EAT_IF_HUNGRY(Msg)); 00569 return Result; 00570 } 00571 00572 /****************************************************************************************** 00573 00574 > BOOL PreviewDialog::SetDialogToIdleState() 00575 00576 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00577 Created: 22/7/97 00578 Returns: TRUE if successful, else FALSE 00579 Purpose: Ensures that the the dialog is set into an idle state showing a cross in 00580 the preview section. 00581 00582 ******************************************************************************************/ 00583 00584 BOOL PreviewDialog::SetDialogToIdleState() 00585 { 00586 // Stop playing the animation. 00587 m_DocumentAboutToDie = TRUE; 00588 m_PlayAnimation = FALSE; 00589 00590 // Set the Preview dialog to an idle state. 00591 m_SetPreviewDlgToIdleState = TRUE; 00592 00593 // Since the document has changed no frame layers will exist. 00594 // They will require generating. 00595 m_GeneratedFrameLayers = FALSE; 00596 00597 // Reset the disposal methods 00598 m_DisposalMethod = GDM_BACKTOBACK; 00599 m_CurrentDisposalMethod = GDM_BACKTOBACK; 00600 00601 // SetDlgState(TRUE); 00602 00603 // Clean the list of bitmaps that we were animating. 00604 m_BitmapList.DeleteAll(); 00605 m_BitmapListSize = 0; 00606 m_CurrentItem = 0; 00607 m_SliderPosition = m_BitmapListSize; 00608 m_AnimationRect.MakeEmpty(); 00609 00610 // Reset the loop counts 00611 m_CurrentLoopCount = 0; // The loop that we are currently on (default to start) 00612 m_RequiredLoopCount = 0; // The loop count that we must reach (default for ever) 00613 00614 // Force the gadget to be repainted, 00615 InvalidateGadget(_R(IDC_REDRAW_ME)); 00616 00617 return TRUE; 00618 } 00619 00620 /****************************************************************************************** 00621 00622 > BOOL PreviewDialog::InitDialog() 00623 00624 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00625 Created: 11/4/97 00626 Returns: TRUE if successful, else FALSE 00627 Purpose: Sets initial dialog values 00628 00629 ******************************************************************************************/ 00630 00631 BOOL PreviewDialog::InitDialog() 00632 { 00633 SetGadgetBitmaps(_R(IDC_PREVIEW_SLIDER), _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER)); 00634 INT32 StepValue = 100; 00635 if (m_BitmapListSize > 0) 00636 StepValue = 100/m_BitmapListSize; 00637 00638 // Set the range of the slider control plus the step value. 00639 SetGadgetRange(_R(IDC_PREVIEW_SLIDER), 1, m_BitmapListSize, StepValue); 00640 SetLongGadgetValue(_R(IDC_PREVIEW_SLIDER), m_BitmapListSize - m_CurrentItem); 00641 00642 // Find the correct bitmap to display. 00643 UINT32 BitmapNum = (m_BitmapListSize - 1); 00644 SelectCurrentBitmap(BitmapNum); 00645 00646 // Set up the bitmaps for the play controls 00647 // Uses the title defined in the rc file so do not specify any bitmaps 00648 SetGadgetBitmaps(_R(IDC_PREVIEW_PLAY), 0, 0); 00649 SetGadgetBitmaps(_R(IDC_PREVIEW_STOP), 0, 0); 00650 SetGadgetBitmaps(_R(IDC_PREVIEW_NEXTFRAME), 0, 0); 00651 SetGadgetBitmaps(_R(IDC_PREVIEW_PREVFRAME), 0, 0); 00652 SetGadgetBitmaps(_R(IDC_PREVIEW_STARTFRAME), 0, 0); 00653 SetGadgetBitmaps(_R(IDC_PREVIEW_ENDFRAME), 0, 0); 00654 00655 // Reset the loop count that we are currently on 00656 m_CurrentLoopCount = 0; 00657 00658 // Are we in single bitmap mode? 00659 if (m_BitmapListSize == 1) 00660 { 00661 // Single bitmap mode 00662 00663 // Enable the play button = grab all frames and play 00664 if (viaBitmapGallery) 00665 { 00666 EnableGadget(_R(IDC_PREVIEW_PLAY), FALSE);//TRUE); 00667 00668 // Set the title of the dialog to "Preview single bitmap" 00669 String_256 title(_R(IDS_PREVIEWTITLE_SINGLEBITMAP)); 00670 SetTitlebarName(&title); 00671 00672 // change the name field from saying "Frame:" to "Image:" 00673 String_32 Name(_R(IDS_PREVIEW_FRAMENAMETYPESTR)); 00674 SetStringGadgetValue(_R(IDC_PREVIEW_FRAMENAMETYPE), Name); 00675 } 00676 else 00677 { 00678 EnableGadget(_R(IDC_PREVIEW_PLAY), TRUE); 00679 00680 // Set the title of the dialog to "Preview single frame" 00681 String_256 title(_R(IDS_PREVIEWTITLE_SINGLE)); 00682 SetTitlebarName(&title); 00683 } 00684 00685 // disable all the other controls 00686 EnableGadget(_R(IDC_PREVIEW_STOP), FALSE); 00687 EnableGadget(_R(IDC_PREVIEW_NEXTFRAME), FALSE); 00688 EnableGadget(_R(IDC_PREVIEW_PREVFRAME), FALSE); 00689 00690 // Disable the slider 00691 EnableGadget(_R(IDC_PREVIEW_SLIDER), FALSE); 00692 00693 // Disable the refresh button 00694 EnableGadget (_R(IDC_PREVIEW_REFRESH), FALSE); 00695 00696 m_PlayAnimation = FALSE; 00697 } 00698 else 00699 { 00700 // No, in multiple bitmap mode 00701 00702 if (viaBitmapGallery) 00703 { 00704 // Set the title of the dialog to "Preview multiple images" 00705 String_256 title(_R(IDS_PREVIEWTITLE_MULTIPLEBITMAP)); 00706 SetTitlebarName(&title); 00707 00708 // change the name field from saying "Frame:" to "Image:" 00709 String_32 Name(_R(IDS_PREVIEW_FRAMENAMETYPESTR)); 00710 SetStringGadgetValue(_R(IDC_PREVIEW_FRAMENAMETYPE), Name); 00711 } 00712 else 00713 { 00714 // Set the title of the dialog to "Preview all frames" 00715 String_256 title(_R(IDS_PREVIEWTITLE_MULTIPLE)); 00716 SetTitlebarName(&title); 00717 } 00718 00719 // Disable the Play buttton. Enable the Stop buttton. 00720 EnableGadget(_R(IDC_PREVIEW_PLAY), FALSE); 00721 EnableGadget(_R(IDC_PREVIEW_STOP), TRUE); 00722 00723 // Enable the slider 00724 EnableGadget(_R(IDC_PREVIEW_SLIDER), TRUE); 00725 00726 // although I would like to do this here, viaBitmapGallery has not been set yet 00727 // so instead we do this within ToggleViaBitmapGallery () 00728 00729 if (viaBitmapGallery) 00730 { 00731 EnableGadget (_R(IDC_PREVIEW_REFRESH), FALSE); 00732 SetPlayAnimation (TRUE); 00733 } 00734 } 00735 00736 /* SetGadgetBitmaps(_R(IDC_PREVIEW_PLAY), _R(IDB_PREVIEW_PLAY), _R(IDB_PREVIEW_PLAY)); 00737 SetGadgetBitmaps(_R(IDC_PREVIEW_STOP), _R(IDB_PREVIEW_STOP), _R(IDB_PREVIEW_STOP)); 00738 SetGadgetBitmaps(_R(IDC_PREVIEW_NEXTFRAME), _R(IDB_PREVIEW_NEXT), _R(IDB_PREVIEW_NEXT)); 00739 SetGadgetBitmaps(_R(IDC_PREVIEW_PREVFRAME), _R(IDB_PREVIEW_PREVIOUS), _R(IDB_PREVIEW_PREVIOUS)); 00740 SetGadgetBitmaps(_R(IDC_PREVIEW_STARTFRAME), _R(IDB_PREVIEW_START), _R(IDB_PREVIEW_START)); 00741 SetGadgetBitmaps(_R(IDC_PREVIEW_ENDFRAME), _R(IDB_PREVIEW_END), _R(IDB_PREVIEW_END)); */ 00742 00743 // Set up the frame/layer name control 00744 String_32 BlankName(TEXT("")); 00745 SetStringGadgetValue(_R(IDC_PREVIEW_FRAMENAME), BlankName); 00746 00747 return TRUE; 00748 } 00749 00750 void PreviewDialog::ToggleViaBitmapGallery (BOOL val) 00751 { 00752 viaBitmapGallery = val;//TRUE; 00753 00754 /* if (viaBitmapGallery) 00755 { 00756 // EnableGadget (_R(IDC_PREVIEW_REFRESH), FALSE); 00757 // m_Delay = 100; // lets make the frames tick slower .... 00758 } 00759 else 00760 { 00761 EnableGadget (_R(IDC_PREVIEW_REFRESH), TRUE); 00762 }*/ 00763 } 00764 00765 00766 /****************************************************************************************** 00767 00768 > BOOL PreviewDialog::ReInitDialog() 00769 00770 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> from Ranbir code which was in OpGrabFrame::SetFullBitmapList 00771 Created: 17/6/97 00772 Returns: TRUE if successful, else FALSE 00773 Purpose: Will reset the initial dialog values. Should be used on an already open 00774 dialog box. 00775 00776 ******************************************************************************************/ 00777 00778 BOOL PreviewDialog::ReInitDialog() 00779 { 00780 if (GetDlgState()) 00781 { 00782 SetDocumentAboutToDie(FALSE); 00783 SetDlgState(FALSE); 00784 // Set the correct state of the controls. 00785 } 00786 00787 // Reset the disposal method 00788 m_DisposalMethod = GDM_BACKTOBACK; 00789 m_CurrentDisposalMethod = GDM_BACKTOBACK; 00790 00791 // Reset the loop count that we are currently on 00792 m_CurrentLoopCount = 0; 00793 00794 // Is there more than one bitmap in the animation? 00795 INT32 BitmapListSize = GetBitmapListSize(); 00796 if (BitmapListSize == 1) 00797 { 00798 // Set the title of the dialog to "Preview single frame" 00799 String_256 title(_R(IDS_PREVIEWTITLE_SINGLE)); 00800 SetTitlebarName(&title); 00801 00802 // Enable the play button = grab all frames and play 00803 EnableGadget(_R(IDC_PREVIEW_PLAY), FALSE);//TRUE); 00804 00805 // Disable all the other controls 00806 EnableGadget(_R(IDC_PREVIEW_STOP), FALSE); 00807 EnableGadget(_R(IDC_PREVIEW_NEXTFRAME), FALSE); 00808 EnableGadget(_R(IDC_PREVIEW_PREVFRAME), FALSE); 00809 00810 // Disable the slider 00811 EnableGadget(_R(IDC_PREVIEW_SLIDER), FALSE); 00812 00813 // Disable the refresh button 00814 EnableGadget (_R(IDC_PREVIEW_REFRESH), FALSE); 00815 00816 // A single frame layer has been generated. 00817 SetGeneratedFrameLayers(FALSE); 00818 } 00819 else 00820 { 00821 // Set the title of the dialog to "Preview all frames" 00822 String_256 title(_R(IDS_PREVIEWTITLE_MULTIPLE)); 00823 SetTitlebarName(&title); 00824 00825 // Enable the slider 00826 EnableGadget(_R(IDC_PREVIEW_SLIDER), TRUE); 00827 00828 if (viaBitmapGallery) 00829 { 00830 EnableGadget (_R(IDC_PREVIEW_REFRESH), FALSE); 00831 SetPlayAnimation (TRUE); 00832 } 00833 00834 // Is the animation playing. 00835 if (GetPlayAnimation()) 00836 { 00837 // Set the correct state of the controls. 00838 EnableGadget(_R(IDC_PREVIEW_PLAY), FALSE); 00839 EnableGadget(_R(IDC_PREVIEW_STOP), TRUE); 00840 EnableGadget(_R(IDC_PREVIEW_NEXTFRAME), TRUE); 00841 EnableGadget(_R(IDC_PREVIEW_PREVFRAME), TRUE); 00842 00843 // A document change will stop the timer, therefore re-start it. 00844 RestartTimer(); 00845 } 00846 else 00847 { 00848 // Set the correct state of the controls. 00849 EnableGadget(_R(IDC_PREVIEW_PLAY), TRUE); 00850 EnableGadget(_R(IDC_PREVIEW_STOP), FALSE); 00851 EnableGadget(_R(IDC_PREVIEW_NEXTFRAME), TRUE); 00852 EnableGadget(_R(IDC_PREVIEW_PREVFRAME), TRUE); 00853 } 00854 00855 // Set the correct state of the dlg. 00856 // Ensure that the timer does not get stopped after we restarted it as it thinks 00857 // that either the animation properties have changed or the document is about to die 00858 SetDlgState(FALSE); 00859 SetDocumentAboutToDie(FALSE); 00860 SetGeneratedFrameLayers(TRUE); 00861 SetAnimationPropertiesChanged(FALSE); 00862 } 00863 00864 // If there is only a single layer, set the slider to the end. 00865 m_SliderPosition = m_BitmapListSize; 00866 SetLongGadgetValue(_R(IDC_PREVIEW_SLIDER), m_BitmapListSize); 00867 00868 // Since the dialog is modeless, the user can add extra layers, 00869 // therefore reset the step value of the slider. 00870 INT32 Step = 100/ m_BitmapListSize; 00871 SetGadgetRange(_R(IDC_PREVIEW_SLIDER), 1, m_BitmapListSize, Step); 00872 SetGadgetBitmaps(_R(IDC_PREVIEW_SLIDER), _R(IDB_SLIDERBASE), _R(IDB_SLIDERSLIDER)); 00873 00874 // Find the correct bitmap to display. 00875 //if (m_SliderPosition >= m_BitmapListSize) 00876 // m_SliderPosition = 0; 00877 UINT32 BitmapNum = m_BitmapListSize - m_SliderPosition; 00878 SelectCurrentBitmap(BitmapNum); 00879 00880 // Force the gadget to be repainted, 00881 // causes a DIM_REDRAW\_R(IDC_REDRAW_ME) message to be sent. 00882 InvalidateGadget(_R(IDC_REDRAW_ME)); 00883 00884 // Set up the frame/layer name control 00885 String_32 BlankName(TEXT("")); 00886 SetStringGadgetValue(_R(IDC_PREVIEW_FRAMENAME), BlankName); 00887 00888 return TRUE; 00889 } 00890 00891 /******************************************************************************************** 00892 00893 > BOOL PreviewDialog::SelectCurrentFrame(const UINT32 Position) 00894 00895 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00896 Created: 28/7/97 00897 Inputs: The frame to be selected (0 .. max frames - 1) 00898 Returns: True if worked ok, False otherwise 00899 Purpose: Tries to set the current frame to be displayed and ensure that associated 00900 items are set e.g. the slider. 00901 00902 ********************************************************************************************/ 00903 00904 BOOL PreviewDialog::SelectCurrentFrame(const UINT32 Position) 00905 { 00906 INT32 NewPosition = (INT32)Position; 00907 // check if the requested position is beyond the end of the list 00908 if (NewPosition >= m_BitmapListSize) 00909 NewPosition = 0; 00910 00911 // Set the current selection to be correct 00912 SelectCurrentBitmap(NewPosition); 00913 00914 // Set the slider position REM slider works backwards. 00915 m_SliderPosition = m_BitmapListSize - NewPosition; 00916 SetLongGadgetValue(_R(IDC_PREVIEW_SLIDER), m_SliderPosition); 00917 00918 // Force the main display gadget to be repainted, 00919 // causes a DIM_REDRAW\_R(IDC_REDRAW_ME) message to be sent. 00920 InvalidateGadget(_R(IDC_REDRAW_ME)); 00921 00922 return TRUE; 00923 } 00924 00925 /******************************************************************************************** 00926 00927 > BOOL PreviewDialog::StopPreviewing() 00928 00929 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00930 Created: 20/6/97 00931 Returns: True if worked ok, False otherwise 00932 Purpose: Puts the dialog into a stopped state ready to grab the frames or frame. 00933 00934 ********************************************************************************************/ 00935 00936 BOOL PreviewDialog::StopPreviewing() 00937 { 00938 // Stop the animation. 00939 PreviewDlgStop(); 00940 00941 // Force the gadget to be repainted, 00942 // causes a DIM_REDRAW\_R(IDC_REDRAW_ME) message to be sent. 00943 InvalidateGadget(_R(IDC_REDRAW_ME)); 00944 00945 // Reset the loop count that we are currently on 00946 m_CurrentLoopCount = 0; 00947 00948 return TRUE; 00949 } 00950 00951 /******************************************************************************************** 00952 00953 > void PreviewDialog::RenderControl(ReDrawInfoType* pExtraInfo) 00954 00955 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 00956 Created: 11/4/97 00957 Inputs: pExtraInfo - The structure that has the extra data we need to start rendering 00958 Purpose: Renders the current bitmap into the control. This actually consists of:- 00959 Render slabbed in border 00960 Render items before present bitmap in list to set up background 00961 Render current bitmap 00962 00963 ********************************************************************************************/ 00964 00965 void PreviewDialog::RenderControl(ReDrawInfoType* pExtraInfo) 00966 { 00967 if (pExtraInfo == NULL) 00968 return; 00969 00970 // Go get a render region 00971 DocRect VirtualSize(0, 0, pExtraInfo->dx, pExtraInfo->dy); 00972 DocRect WholeRedrawSize = VirtualSize; 00973 00974 // If we haven't already created our render region then go and create it 00975 BOOL StartedOk = TRUE; 00976 if (m_pRender == NULL) 00977 { 00978 // This will call start render for us 00979 m_pRender = CreateGRenderRegion(&VirtualSize, pExtraInfo); 00980 } 00981 else 00982 { 00983 // and delete the render region and its (dialog) view 00984 View * pDialogView = m_pRender->GetRenderView(); 00985 00986 if (pDialogView) 00987 { 00988 // Try and create the bitmap etc 00989 StartedOk = m_pRender->AttachDevice(pDialogView, pExtraInfo->pDC, NULL); 00990 00991 // Try and start the render region 00992 StartedOk = StartedOk && m_pRender->StartRender(); 00993 } 00994 else 00995 StartedOk = FALSE; 00996 } 00997 00998 // if we have a render region then go and use it 00999 if (m_pRender != NULL && StartedOk) 01000 { 01001 // Code stolen from ColourEditDlg::RenderControl 01002 DialogColourInfo RedrawColours; // Get a supplier for default dlg colours 01003 INT32 PixelSize = 72000 / pExtraInfo->Dpi; // Size of output pixel in millipoints 01004 01005 GridLockRect(&VirtualSize, PixelSize); 01006 01007 // Render the attributes and then a rectangle 01008 m_pRender->SaveContext(); 01009 01010 // Get the current bitmap and try and display it 01011 KernelBitmap * pBitmapToUse = GetCurrentBitmap(); 01012 if (pBitmapToUse) 01013 { 01014 // Using this method we don't get flicker on the backdrop as we draw the background rectangle 01015 // followed by the white new background 01016 // Draw single pixel black line left and top and single pixel background colour 1 pixel in 01017 m_pRender->SetLineWidth(0); 01018 m_pRender->SetFillColour(RedrawColours.DialogBack()); 01019 m_pRender->SetLineColour(COLOUR_BLACK); //RedrawColours.ButtonShadow()); 01020 m_pRender->DrawLine(DocCoord(VirtualSize.lo.x, VirtualSize.hi.y - PixelSize), 01021 DocCoord(VirtualSize.hi.x, VirtualSize.hi.y - PixelSize)); 01022 m_pRender->DrawLine(DocCoord(VirtualSize.lo.x, VirtualSize.hi.y), 01023 DocCoord(VirtualSize.lo.x, VirtualSize.lo.y)); 01024 m_pRender->SetLineColour(RedrawColours.DialogBack()); 01025 m_pRender->DrawLine(DocCoord(VirtualSize.lo.x + PixelSize, VirtualSize.hi.y - 2 * PixelSize), 01026 DocCoord(VirtualSize.hi.x - PixelSize, VirtualSize.hi.y - 2 * PixelSize)); 01027 m_pRender->DrawLine(DocCoord(VirtualSize.lo.x + PixelSize, VirtualSize.lo.y), 01028 DocCoord(VirtualSize.lo.x + PixelSize, VirtualSize.hi.y - 2 * PixelSize)); 01029 01030 // Draw single pixel hightligh line right and bottom and single pixel background colour 1 pixel in 01031 m_pRender->SetLineColour(RedrawColours.ButtonHighlight()); 01032 m_pRender->DrawLine(DocCoord(VirtualSize.hi.x - PixelSize, VirtualSize.hi.y - PixelSize), 01033 DocCoord(VirtualSize.hi.x - PixelSize, VirtualSize.lo.y)); 01034 m_pRender->DrawLine(DocCoord(VirtualSize.hi.x - PixelSize, VirtualSize.lo.y), 01035 DocCoord(VirtualSize.lo.x + PixelSize, VirtualSize.lo.y)); 01036 01037 m_pRender->SetLineColour(RedrawColours.DialogBack()); 01038 m_pRender->DrawLine(DocCoord(VirtualSize.hi.x - 2 * PixelSize, VirtualSize.hi.y - 2 * PixelSize), 01039 DocCoord(VirtualSize.hi.x - 2 * PixelSize, VirtualSize.lo.y + 1 * PixelSize)); 01040 m_pRender->DrawLine(DocCoord(VirtualSize.hi.x - 2 * PixelSize, VirtualSize.lo.y + 1 * PixelSize), 01041 DocCoord(VirtualSize.lo.x + 2 * PixelSize, VirtualSize.lo.y + 1 * PixelSize)); 01042 01043 // And deflate the rect by 2 pixels 01044 VirtualSize.Inflate(-PixelSize * 2); 01045 01046 // Ensure that we cannot redraw into the border that we have just redrawn 01047 // m_pRender->SetClipRect(VirtualSize); 01048 01049 // Code stolen from BfxDlg::RenderBitmap 01050 m_pRender->SetLineColour(COLOUR_TRANS); 01051 01052 // If we are playing then assume we need the quickest redraw and we will 01053 // be overlaying the correct frames. 01054 /* if (m_PlayAnimation) 01055 { 01056 // Check the GIFDisposalMethod for the previous bitmap. If necessary redraw the background. 01057 if (m_DisposalMethod == GDM_BACKTOBACK) 01058 { 01059 // Draw a rectangle to fill in the background - Fill with Dialogue Background colour 01060 //m_pRender->SetFillColour(RedrawColours.DialogBack()); // COLOUR_WHITE); // 01061 m_pRender->SetFillColour(COLOUR_WHITE); 01062 m_pRender->DrawRect(&VirtualSize); 01063 } 01064 // This is REDRAW code and so noting the redraw method is very bad. 01065 // Should be done in the code which moves between frames. 01067 //m_DisposalMethod = pBitmapToUse->GetAnimationRestoreType(); 01068 01069 // redraw the specified bitmap into the render region 01070 RedrawBitmap(pBitmapToUse, &VirtualSize); 01071 } 01072 else */ 01073 { 01074 // Try just redrawing everything we need to 01075 01076 // Not playing so we must redraw everything that is required to make up 01077 // this frame. If the previous frame is restore background then we just 01078 // need to redraw this frame. If the previous frame is anything else then 01079 // we need to move back through the frames until we find the start or a 01080 // frame with restore background and then draw from this point. 01081 // If we encounter a bitmap which is restore previous and it is not this 01082 // one then we need do nothing. 01083 01084 // Draw a rectangle to fill in the background 01085 m_pRender->SetFillColour(COLOUR_WHITE); 01086 m_pRender->DrawRect(&VirtualSize); 01087 01088 // INT32 ThisIndex = m_CurrentItem; 01089 INT32 StartIndex = m_CurrentItem; 01090 BOOL StartFrameFound = FALSE; 01091 // First, search out the first frame to redraw 01092 while (!StartFrameFound && StartIndex > 0) 01093 { 01094 // Move to the previous item in the list 01095 StartIndex--; 01096 KernelBitmap * pBitmap = GetBitmapItem(StartIndex); 01097 // Check the GIFDisposalMethod for the previous bitmap. 01098 if (pBitmap == NULL) 01099 { 01100 // No previous frame so stop the search now 01101 StartFrameFound = TRUE; 01102 StartIndex++; 01103 } 01104 else if (pBitmap->GetAnimationRestoreType() == GDM_BACKTOBACK) 01105 { 01106 // Its a restore background so we have found our first frame 01107 // to redraw, its StartIndex + 1 01108 StartFrameFound = TRUE; 01109 StartIndex++; 01110 } 01111 } 01112 01113 // I'm not sure why they were originally doing this, BUT I've taken it out 01114 // because it was causing problems with my new stuff .... 01115 01116 // Now redraw all the bitmaps from the start frame onwards 01117 // up to the frame before the current one 01118 /* for (INT32 i = StartIndex; i < ThisIndex; i++) 01119 { 01120 KernelBitmap * pBitmap = GetBitmapItem(i); 01121 if (pBitmap && pBitmap->GetAnimationRestoreType() != GDM_PREVIOUS) 01122 { 01123 RedrawBitmap(pBitmap, &VirtualSize); 01124 } 01125 }*/ 01126 01127 // Lastly, redraw the present bitmap into the render region 01128 RedrawBitmap(pBitmapToUse, &VirtualSize); 01129 } 01130 } 01131 else 01132 { 01133 // draw a cross to show we do not have a bitmap 01134 RedrawCross(&VirtualSize, &RedrawColours, PixelSize); 01135 } 01136 01137 // Now that we have drawn everything, reset the cliprect back to the whole 01138 // size, otherwise it seems to stop redrawing the border. 01139 m_pRender->SetClipRect(WholeRedrawSize); 01140 01141 m_pRender->RestoreContext(); 01142 01143 // Get rid of the render region, now done in the destructor 01144 //DestroyGRenderRegion(m_pRender); 01145 01146 // Blit to the screen 01147 m_pRender->StopRender(); 01148 } 01149 } 01150 01151 /******************************************************************************************* 01152 01153 > BOOL PreviewDialog::RedrawBitmap(KernelBitmap * pBitmapToUse, DocRect * pVirtualSize) 01154 01155 Author: Neville_Humphrys (Xara Group Ltd) <camelotdev@xara.com> 01156 Created: 17/6/97 01157 Inputs: pBitmap the bitmap to redraw 01158 pVirtualSize the size of the area to redraw into 01159 Purpose: Redraws th