1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include "precompiled_slideshow.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include "debug.hxx" 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include "animationnodes/basecontainernode.hxx" 35*cdf0e10cSrcweir #include "animationnodes/paralleltimecontainer.hxx" 36*cdf0e10cSrcweir #include "animationnodes/sequentialtimecontainer.hxx" 37*cdf0e10cSrcweir #include "animationnodes/animationtransitionfilternode.hxx" 38*cdf0e10cSrcweir #include "animationnodes/animationaudionode.hxx" 39*cdf0e10cSrcweir #include "animationnodes/animationcolornode.hxx" 40*cdf0e10cSrcweir #include "animationnodes/animationcommandnode.hxx" 41*cdf0e10cSrcweir #include "animationnodes/animationpathmotionnode.hxx" 42*cdf0e10cSrcweir #include "animationnodes/animationsetnode.hxx" 43*cdf0e10cSrcweir #include "animationnodes/animationtransformnode.hxx" 44*cdf0e10cSrcweir #include "animationnodes/propertyanimationnode.hxx" 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir #include <com/sun/star/animations/XAnimationNode.hpp> 47*cdf0e10cSrcweir #include <com/sun/star/animations/Event.hpp> 48*cdf0e10cSrcweir 49*cdf0e10cSrcweir #include <cstdio> 50*cdf0e10cSrcweir #include <cstdarg> 51*cdf0e10cSrcweir 52*cdf0e10cSrcweir using ::rtl::OUString; 53*cdf0e10cSrcweir using namespace ::com::sun::star; 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir namespace slideshow { namespace internal { 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir namespace { 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir class NodeContainer : public BaseContainerNode 61*cdf0e10cSrcweir { 62*cdf0e10cSrcweir public: 63*cdf0e10cSrcweir void ShowChildrenState (void) const; 64*cdf0e10cSrcweir }; 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir OUString DebugGetDescription (const AnimationNodeSharedPtr& rpNode) 70*cdf0e10cSrcweir { 71*cdf0e10cSrcweir if (::boost::dynamic_pointer_cast<BaseContainerNode>(rpNode)) 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir // Node is a container. 74*cdf0e10cSrcweir if (::boost::dynamic_pointer_cast<ParallelTimeContainer>(rpNode)) 75*cdf0e10cSrcweir return OUString::createFromAscii("ParallelTimeContainer"); 76*cdf0e10cSrcweir else if (::boost::dynamic_pointer_cast<SequentialTimeContainer>(rpNode)) 77*cdf0e10cSrcweir return OUString::createFromAscii("SequentialTimeContainer"); 78*cdf0e10cSrcweir else 79*cdf0e10cSrcweir return OUString::createFromAscii("<unknown container>"); 80*cdf0e10cSrcweir } 81*cdf0e10cSrcweir else if (::boost::dynamic_pointer_cast<AnimationTransitionFilterNode>(rpNode)) 82*cdf0e10cSrcweir return OUString::createFromAscii("AnimationTransitionFilterNode"); 83*cdf0e10cSrcweir else if (::boost::dynamic_pointer_cast<AnimationAudioNode>(rpNode)) 84*cdf0e10cSrcweir return OUString::createFromAscii("AnimationAudioNode"); 85*cdf0e10cSrcweir else if (::boost::dynamic_pointer_cast<AnimationColorNode>(rpNode)) 86*cdf0e10cSrcweir return OUString::createFromAscii("AnimationColorNode"); 87*cdf0e10cSrcweir else if (::boost::dynamic_pointer_cast<AnimationCommandNode>(rpNode)) 88*cdf0e10cSrcweir return OUString::createFromAscii("AnimationCommandNode"); 89*cdf0e10cSrcweir else if (::boost::dynamic_pointer_cast<AnimationPathMotionNode>(rpNode)) 90*cdf0e10cSrcweir return OUString::createFromAscii("AnimationPathMotionNode"); 91*cdf0e10cSrcweir else if (::boost::dynamic_pointer_cast<AnimationSetNode>(rpNode)) 92*cdf0e10cSrcweir return OUString::createFromAscii("AnimationSetNode"); 93*cdf0e10cSrcweir else if (::boost::dynamic_pointer_cast<AnimationTransformNode>(rpNode)) 94*cdf0e10cSrcweir return OUString::createFromAscii("AnimationTransformNode"); 95*cdf0e10cSrcweir else if (::boost::dynamic_pointer_cast<PropertyAnimationNode>(rpNode)) 96*cdf0e10cSrcweir return OUString::createFromAscii("PropertyAnimationNode"); 97*cdf0e10cSrcweir else 98*cdf0e10cSrcweir return OUString::createFromAscii("<unknown node type>"); 99*cdf0e10cSrcweir } 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir void DebugShowState (const AnimationNodeSharedPtr& rpNode) 105*cdf0e10cSrcweir { 106*cdf0e10cSrcweir if ( ! rpNode) 107*cdf0e10cSrcweir return; 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir OUString sState; 110*cdf0e10cSrcweir OUString sStateColor; 111*cdf0e10cSrcweir switch (rpNode->getState()) 112*cdf0e10cSrcweir { 113*cdf0e10cSrcweir default: 114*cdf0e10cSrcweir case AnimationNode::INVALID: 115*cdf0e10cSrcweir sState = OUString::createFromAscii("Invalid"); 116*cdf0e10cSrcweir sStateColor = OUString::createFromAscii("firebrick1"); 117*cdf0e10cSrcweir break; 118*cdf0e10cSrcweir case AnimationNode::UNRESOLVED: 119*cdf0e10cSrcweir sState = OUString::createFromAscii("Unresolved"); 120*cdf0e10cSrcweir sStateColor = OUString::createFromAscii("dodgerblue4"); 121*cdf0e10cSrcweir break; 122*cdf0e10cSrcweir case AnimationNode::RESOLVED: 123*cdf0e10cSrcweir sState = OUString::createFromAscii("Resolved"); 124*cdf0e10cSrcweir sStateColor = OUString::createFromAscii("dodgerblue"); 125*cdf0e10cSrcweir break; 126*cdf0e10cSrcweir case AnimationNode::ACTIVE: 127*cdf0e10cSrcweir sState = OUString::createFromAscii("Active"); 128*cdf0e10cSrcweir sStateColor = OUString::createFromAscii("seagreen1"); 129*cdf0e10cSrcweir break; 130*cdf0e10cSrcweir case AnimationNode::FROZEN: 131*cdf0e10cSrcweir sState = OUString::createFromAscii("Frozen"); 132*cdf0e10cSrcweir sStateColor = OUString::createFromAscii("lightskyblue1"); 133*cdf0e10cSrcweir break; 134*cdf0e10cSrcweir case AnimationNode::ENDED: 135*cdf0e10cSrcweir sState = OUString::createFromAscii("Ended"); 136*cdf0e10cSrcweir sStateColor = OUString::createFromAscii("slategray3"); 137*cdf0e10cSrcweir break; 138*cdf0e10cSrcweir } 139*cdf0e10cSrcweir 140*cdf0e10cSrcweir const uno::Any aBegin (rpNode->getXAnimationNode()->getBegin()); 141*cdf0e10cSrcweir OUString sTrigger; 142*cdf0e10cSrcweir if (aBegin.hasValue()) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir animations::Event aEvent; 145*cdf0e10cSrcweir double nTimeOffset; 146*cdf0e10cSrcweir const static char* sEventTriggers[] = { 147*cdf0e10cSrcweir "NONE", "ON_BEGIN", "ON_END", "BEGIN_EVENT", "END_EVENT", "ON_CLICK", 148*cdf0e10cSrcweir "ON_DBL_CLICK", "ON_MOUSE_ENTER", "ON_MOUSE_LEAVE", "ON_NEXT", "ON_PREV", 149*cdf0e10cSrcweir "ON_STOP_AUDIO", "REPEAT"}; 150*cdf0e10cSrcweir if (aBegin >>= aEvent) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir sTrigger = OUString::createFromAscii(sEventTriggers[aEvent.Trigger]); 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir else if (aBegin >>= nTimeOffset) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir sTrigger = OUString::valueOf(nTimeOffset); 157*cdf0e10cSrcweir } 158*cdf0e10cSrcweir else 159*cdf0e10cSrcweir { 160*cdf0e10cSrcweir sTrigger = OUString::createFromAscii("other"); 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir else 164*cdf0e10cSrcweir sTrigger = ::rtl::OUString::createFromAscii("void"); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir TRACE("Node state: n%x [label=\"%x / %x / %s\\n%s\\n%s\",style=filled,fillcolor=\"%s\"]\r", 167*cdf0e10cSrcweir rpNode.get(), 168*cdf0e10cSrcweir rpNode.get(), 169*cdf0e10cSrcweir rpNode->getXAnimationNode().get(), 170*cdf0e10cSrcweir ::rtl::OUStringToOString(sState, RTL_TEXTENCODING_ASCII_US).getStr(), 171*cdf0e10cSrcweir ::rtl::OUStringToOString(DebugGetDescription(rpNode), RTL_TEXTENCODING_ASCII_US).getStr(), 172*cdf0e10cSrcweir ::rtl::OUStringToOString(sTrigger, RTL_TEXTENCODING_ASCII_US).getStr(), 173*cdf0e10cSrcweir ::rtl::OUStringToOString(sStateColor, RTL_TEXTENCODING_ASCII_US).getStr()); 174*cdf0e10cSrcweir 175*cdf0e10cSrcweir BaseContainerNodeSharedPtr pContainer ( 176*cdf0e10cSrcweir ::boost::dynamic_pointer_cast<BaseContainerNode>(rpNode)); 177*cdf0e10cSrcweir if (pContainer) 178*cdf0e10cSrcweir ::boost::static_pointer_cast<NodeContainer>(rpNode)->ShowChildrenState(); 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir void NodeContainer::ShowChildrenState (void) const 185*cdf0e10cSrcweir { 186*cdf0e10cSrcweir for (std::size_t nIndex=0; nIndex<maChildren.size(); ++nIndex) 187*cdf0e10cSrcweir { 188*cdf0e10cSrcweir TRACE("Node connection: n%x -> n%x", this, maChildren[nIndex].get()); 189*cdf0e10cSrcweir DebugShowState(maChildren[nIndex]); 190*cdf0e10cSrcweir } 191*cdf0e10cSrcweir } 192*cdf0e10cSrcweir 193*cdf0e10cSrcweir 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir 196*cdf0e10cSrcweir AnimationNodeSharedPtr DebugGetTreeRoot (const BaseNodeSharedPtr& rpNode) 197*cdf0e10cSrcweir { 198*cdf0e10cSrcweir BaseNodeSharedPtr pNode (rpNode); 199*cdf0e10cSrcweir if (pNode) 200*cdf0e10cSrcweir { 201*cdf0e10cSrcweir BaseNodeSharedPtr pParent (pNode->getParentNode()); 202*cdf0e10cSrcweir while (pParent) 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir pNode = pParent; 205*cdf0e10cSrcweir pParent = pNode->getParentNode(); 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir return pNode; 209*cdf0e10cSrcweir } 210*cdf0e10cSrcweir 211*cdf0e10cSrcweir } // end of anonymous namespace 212*cdf0e10cSrcweir 213*cdf0e10cSrcweir 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir void Debug_ShowNodeTree (const AnimationNodeSharedPtr& rpNode) 217*cdf0e10cSrcweir { 218*cdf0e10cSrcweir DebugTraceScope aTraceScope ("NodeTree"); 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir DebugShowState(DebugGetTreeRoot(::boost::dynamic_pointer_cast<BaseNode>(rpNode))); 221*cdf0e10cSrcweir } 222*cdf0e10cSrcweir 223*cdf0e10cSrcweir 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir //----- Tracing --------------------------------------------------------------- 227*cdf0e10cSrcweir 228*cdf0e10cSrcweir extern "C" { 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir namespace { 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir class TraceData 233*cdf0e10cSrcweir { 234*cdf0e10cSrcweir public: 235*cdf0e10cSrcweir TraceData (void) 236*cdf0e10cSrcweir : mnIndentation(0), 237*cdf0e10cSrcweir mpFile(fopen(TRACE_LOG_FILE_NAME, "w")), 238*cdf0e10cSrcweir maTime() 239*cdf0e10cSrcweir { 240*cdf0e10cSrcweir } 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir int mnIndentation; 243*cdf0e10cSrcweir FILE* mpFile; 244*cdf0e10cSrcweir ::canvas::tools::ElapsedTime maTime; 245*cdf0e10cSrcweir }; 246*cdf0e10cSrcweir static TraceData gTraceData; 247*cdf0e10cSrcweir 248*cdf0e10cSrcweir inline void SAL_CALL DebugTrace ( 249*cdf0e10cSrcweir const int nIndentationOffset, 250*cdf0e10cSrcweir const sal_Char* sFormat, 251*cdf0e10cSrcweir va_list args) 252*cdf0e10cSrcweir { 253*cdf0e10cSrcweir if (gTraceData.mpFile != NULL) 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir // Write line head with current time and indentation. 256*cdf0e10cSrcweir // Adapt indentation. 257*cdf0e10cSrcweir if (nIndentationOffset < 0) 258*cdf0e10cSrcweir gTraceData.mnIndentation += nIndentationOffset; 259*cdf0e10cSrcweir fprintf(gTraceData.mpFile, "%10.8f ", gTraceData.maTime.getElapsedTime()); 260*cdf0e10cSrcweir for (int nIndentation=0; nIndentation<gTraceData.mnIndentation; ++nIndentation) 261*cdf0e10cSrcweir fprintf(gTraceData.mpFile, " "); 262*cdf0e10cSrcweir if (nIndentationOffset > 0) 263*cdf0e10cSrcweir gTraceData.mnIndentation += nIndentationOffset; 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir // Write message. 266*cdf0e10cSrcweir vfprintf(gTraceData.mpFile, sFormat, args); 267*cdf0e10cSrcweir fprintf(gTraceData.mpFile, "\n"); 268*cdf0e10cSrcweir fflush(gTraceData.mpFile); 269*cdf0e10cSrcweir } 270*cdf0e10cSrcweir } 271*cdf0e10cSrcweir 272*cdf0e10cSrcweir } // end of anonymous namespace 273*cdf0e10cSrcweir 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir } // end of extern "C" 276*cdf0e10cSrcweir 277*cdf0e10cSrcweir void SAL_CALL DebugTraceBegin (const sal_Char* sFormat, ...) 278*cdf0e10cSrcweir { 279*cdf0e10cSrcweir va_list args; 280*cdf0e10cSrcweir va_start(args, sFormat); 281*cdf0e10cSrcweir DebugTrace(+1,sFormat, args); 282*cdf0e10cSrcweir va_end(args); 283*cdf0e10cSrcweir } 284*cdf0e10cSrcweir 285*cdf0e10cSrcweir void SAL_CALL DebugTraceEnd (const sal_Char* sFormat, ...) 286*cdf0e10cSrcweir { 287*cdf0e10cSrcweir va_list args; 288*cdf0e10cSrcweir va_start(args, sFormat); 289*cdf0e10cSrcweir DebugTrace(-1,sFormat, args); 290*cdf0e10cSrcweir va_end(args); 291*cdf0e10cSrcweir } 292*cdf0e10cSrcweir 293*cdf0e10cSrcweir void SAL_CALL DebugTraceMessage (const sal_Char* sFormat, ...) 294*cdf0e10cSrcweir { 295*cdf0e10cSrcweir va_list args; 296*cdf0e10cSrcweir va_start(args, sFormat); 297*cdf0e10cSrcweir DebugTrace(0,sFormat, args); 298*cdf0e10cSrcweir va_end(args); 299*cdf0e10cSrcweir } 300*cdf0e10cSrcweir 301*cdf0e10cSrcweir 302*cdf0e10cSrcweir 303*cdf0e10cSrcweir DebugTraceScope::DebugTraceScope (const sal_Char* sFormat, ...) 304*cdf0e10cSrcweir : msMessage(new sal_Char[mnBufferSize]) 305*cdf0e10cSrcweir { 306*cdf0e10cSrcweir va_list args; 307*cdf0e10cSrcweir va_start(args, sFormat); 308*cdf0e10cSrcweir 309*cdf0e10cSrcweir msMessage[mnBufferSize-1] = 0; 310*cdf0e10cSrcweir vsnprintf(msMessage, mnBufferSize-1, sFormat, args); 311*cdf0e10cSrcweir TRACE_BEGIN("[ %s", msMessage); 312*cdf0e10cSrcweir va_end(args); 313*cdf0e10cSrcweir } 314*cdf0e10cSrcweir 315*cdf0e10cSrcweir DebugTraceScope::~DebugTraceScope (void) 316*cdf0e10cSrcweir { 317*cdf0e10cSrcweir TRACE_END("] %s", msMessage); 318*cdf0e10cSrcweir delete [] msMessage; 319*cdf0e10cSrcweir } 320*cdf0e10cSrcweir 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir } } 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir #endif // OSL_DEBUG_LEVEL > 1 325