home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / samples / ioc / mmstereo / mltvid.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-22  |  9.1 KB  |  203 lines

  1. /******************************************************************************
  2. * .FILE:         mltvid.cpp                                                   *
  3. *                                                                             *
  4. * .DESCRIPTION:  Multimedia Stereo Sample:             Class Implementation   *
  5. *                                                                             *
  6. * .CLASSES:      VIDEO                                                        *
  7. *                VideoHandler                                                 *
  8. *                VideoObserver                                                *
  9. *                                                                             *
  10. * .COPYRIGHT:                                                                 *
  11. *    Licensed Material - Program-Property of IBM                              *
  12. *    (C) Copyright IBM Corp. 1992, 1996 - All Rights Reserved                 *
  13. *                                                                             *
  14. * .DISCLAIMER:                                                                *
  15. *   The following [enclosed] code is sample code created by IBM               *
  16. *   Corporation.  This sample code is not part of any standard IBM product    *
  17. *   and is provided to you solely for the purpose of assisting you in the     *
  18. *   development of your applications.  The code is provided 'AS IS',          *
  19. *   without warranty of any kind.  IBM shall not be liable for any damages    *
  20. *   arising out of your use of the sample code, even if they have been        *
  21. *   advised of the possibility of such damages.                               *
  22. *                                                                             *
  23. * .NOTE: WE RECOMMEND USING A FIXED SPACE FONT TO LOOK AT THE SOURCE          *
  24. *                                                                             *
  25. ******************************************************************************/
  26. #include <ibase.hpp>
  27. #include <ireslib.hpp>
  28. #include "mmstereo.hpp"
  29. #include "mltvid.hpp"
  30.  
  31. /*------------------------------------------------------------------------------
  32. | VIDEO::VIDEO                                                                   |
  33. |                                                                              |
  34. |                                                                              |
  35. ------------------------------------------------------------------------------*/
  36. VIDEO::VIDEO( IMMDigitalVideo*  aVideoPlayer,
  37.               unsigned long     windowid,
  38.               IWindow*          parent,
  39.               IWindow*          owner)
  40.      : IMMPlayerPanel(windowid,parent,owner,IMMDevice::digitalVideo),
  41.        readout       (VIDEOREADOUTID, this,this),
  42.        name          (VIDEONAMEID, this, this),
  43.        pVideoPlayer  (aVideoPlayer),
  44.        observer      (0),
  45.        handler       (0)
  46. {
  47.    setPlayableDevice(pVideoPlayer);
  48.  
  49.    loadit= new IAnimatedButton(VIDEOLOADID,this,this,IRectangle(),
  50.                     IWindow::visible | IAnimatedButton::animateWhenLatched);
  51.    //Add the additional buttons to the player panel.
  52.    addToCell(&readout ,     9, 1, 1, 2);
  53.    addToCell(loadit   ,    11, 1, 1, 2);
  54.    addToCell(&name    ,     2, 3, 8, 1);
  55.    playButton()->disable();
  56.    rewindButton()->disable();
  57.    fastForwardButton()->disable();
  58.    stepForwardButton()->disable();
  59.    stepBackwardButton()->disable();
  60.  
  61.    //Put the bitmaps on the button.
  62.    loadit->setBitmaps(IAnimatedButton::eject);
  63.  
  64.    //Put text on the button.
  65.    loadit->setText(STR_LOAD_VID);
  66.  
  67.    //Set up the title
  68.    name.setText(TITLE_VID_PLAYER);
  69.    name.setForegroundColor(IColor(IColor::red));
  70.  
  71.    //Set up the display
  72.    readout.setForegroundColor(IColor(0,160,0));
  73.    readout.setBackgroundColor(IColor(IColor::black));
  74.    readout.setText(STR_DEF_TIME);
  75.    readout.setLimit(22);
  76.  
  77.    if (pVideoPlayer)
  78.    {
  79.       handler  = new VideoHandler();
  80.       handler->handleEventsFor(this);
  81.       observer = new VideoObserver(*this);
  82.       observer->handleNotificationsFor(*pVideoPlayer);
  83.    }
  84. }
  85.  
  86.  
  87. /*------------------------------------------------------------------------------
  88. | VIDEO::~VIDEO                                                                      |
  89. |                                                                              |
  90. |                                                                              |
  91. ------------------------------------------------------------------------------*/
  92. VIDEO::~VIDEO()
  93. {
  94.   if (observer)
  95.      observer->stopHandlingNotificationsFor(*pVideoPlayer);
  96.   if (handler)
  97.      handler->stopHandlingEventsFor(this);
  98. }
  99.  
  100.  
  101. /*------------------------------------------------------------------------------
  102. | VIDEO::videoPlayer                                                             |
  103. |                                                                              |
  104. |                                                                              |
  105. ------------------------------------------------------------------------------*/
  106. IMMDigitalVideo* VIDEO::videoPlayer () const
  107. {
  108.   return pVideoPlayer;
  109. }
  110.  
  111.  
  112. /*------------------------------------------------------------------------------
  113. | VideoHandler::VideoHandler                                                     |
  114. |                                                                              |
  115. |                                                                              |
  116. ------------------------------------------------------------------------------*/
  117. VideoHandler::VideoHandler()
  118.           : VideoHandler::Inherited()
  119. {}
  120.  
  121. /*------------------------------------------------------------------------------
  122. | VideoHandler::command                                                         |
  123. |                                                                              |
  124. ------------------------------------------------------------------------------*/
  125. IBase::Boolean VideoHandler::command(ICommandEvent& event)
  126. {
  127.   Boolean handled = false;
  128.   VIDEO* panel = 0;
  129.   IResourceLibrary reslib;
  130.  
  131.   switch (event.commandId())
  132.   {
  133.     case VIDEOLOADID:
  134.          {
  135.          panel = (VIDEO*) (event.window());
  136.          IFileDialog::Settings fdSettings;
  137.          fdSettings.setTitle(STR_LOAD_VID_FILE);
  138.          fdSettings.setFileName(reslib.loadString(STR_AVI_EXT));
  139.          IFileDialog fd(panel->desktopWindow(),panel,fdSettings);
  140.          if (fd.pressedOK())
  141.          {
  142.             panel->videoPlayer()->loadOnThread(fd.fileName());
  143.             stop(*panel);
  144.             panel->videoPlayer()->startPositionTracking(IMMTime(3000));
  145.             panel->playButton()->enable();
  146.             panel->rewindButton()->enable();
  147.             panel->fastForwardButton()->enable();
  148.             panel->stepForwardButton()->enable();
  149.             panel->stepBackwardButton()->enable();
  150.          }
  151.          }
  152.          handled=true;
  153.          break;
  154.     default:
  155.          handled = Inherited::command(event);
  156.          break;
  157.   } /* endswitch */
  158.   return handled;
  159. }
  160.  
  161.  
  162. /*------------------------------------------------------------------------------
  163. | VideoObserver::VideoObserver                                                   |
  164. |                                                                              |
  165. |                                                                              |
  166. ------------------------------------------------------------------------------*/
  167. VideoObserver::VideoObserver(VIDEO& videoPanel)
  168.           : VideoObserver::Inherited(),
  169.           panel(videoPanel)
  170. {}
  171.  
  172. /*------------------------------------------------------------------------------
  173. | VideoObserver::dispatchNotificationEvent                                      |
  174. |                                                                              |
  175. |                                                                              |
  176. ------------------------------------------------------------------------------*/
  177. VideoObserver& VideoObserver::dispatchNotificationEvent(const INotificationEvent& event)
  178. {
  179.    IResourceLibrary reslib;
  180.    if (event.notificationId() == IMMDevice::positionChangeId)
  181.    {
  182.       IMMPositionChangeEvent* positionEvent = (IMMPositionChangeEvent*)(event.eventData().asUnsignedLong());
  183.  
  184.       IMMTime time(positionEvent->position());
  185.       panel.readout.setText(
  186.                       IString(time.hours()).rightJustify(2,'0') +
  187.                       reslib.loadString(STR_COLON) +
  188.                       IString(time.minutes()).rightJustify(2,'0') +
  189.                       reslib.loadString(STR_COLON) +
  190.                       IString(time.seconds()).rightJustify(2,'0'));
  191.       if (!panel.playButton()->isLatched())
  192.          if (panel.videoPlayer()->mode()==IMMDevice::playing)
  193.             panel.playButton()->latch();
  194.    } /* endif */
  195.    if (event.notificationId() == IMMDevice::commandNotifyId)
  196.    {
  197.       IMMNotifyEvent* notifyEvent = (IMMNotifyEvent*)(event.eventData().asUnsignedLong());
  198.       if (notifyEvent->command() == IMMNotifyEvent::play)
  199.          panel.playButton()->unlatch();
  200.    } /* endif */
  201.    return *this;
  202. }
  203.