home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 8 / IOPROG_8.ISO / soft / sdkplnet / mac / macnpsdk.sit / PluginSDK / Examples / PPViewText / Source / CViewText.cpp < prev    next >
Encoding:
Text File  |  1996-07-09  |  4.0 KB  |  141 lines

  1. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  2. //
  3. // NetscapePlugin.cpp
  4. //
  5. //
  6. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  7. #include "CViewText.h"
  8.  
  9. #include "CPlainTextStream.h"
  10.  
  11. #include <string.h>
  12. #include "Files.h"
  13. #include "Events.h"
  14.  
  15. #include <LScroller.h>
  16. #include <LActiveScroller.h>
  17. #include <URegistrar.h>
  18. #include "CFastTextEdit.h"
  19.  
  20. extern QDGlobals*    gQDPtr;
  21.  
  22. const PaneIDT kTopViewPaneID = 'NPlg';
  23. const PaneIDT kScrollerPaneID = 'NPsc';
  24. const PaneIDT kTextEditPaneID = 'NPtx';
  25.  
  26. //======================================================================
  27. //        CViewText::Initialize()
  28. //======================================================================
  29.  
  30. NPError
  31. CViewText::Initialize( void )
  32. {
  33.     NPError err = CMacPluginView::Initialize();
  34.     if( err == NPERR_NO_ERROR )
  35.     {
  36.         URegistrar::RegisterClass(LScroller::class_ID,        (ClassCreatorFunc) LScroller::CreateScrollerStream);
  37.         URegistrar::RegisterClass(CFastTextEdit::class_ID,    (ClassCreatorFunc) CFastTextEdit::CreateFastTextEditStream);
  38.         URegistrar::RegisterClass(LActiveScroller::class_ID,(ClassCreatorFunc) LActiveScroller::CreateActiveScrollerStream);
  39.     }
  40.  
  41.     return err; 
  42. }
  43.  
  44. //======================================================================
  45. //        CViewText::Shutdown()
  46. //======================================================================
  47.  
  48. NPError
  49. CViewText::Shutdown( void )
  50. {
  51.     return NPERR_NO_ERROR; 
  52. }
  53.  
  54. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  55. //
  56. //    Object Allocation Methods
  57. //
  58. //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
  59.  
  60. //======================================================================
  61. //        CViewText::CViewText()
  62. //======================================================================
  63.  
  64. CViewText::CViewText( NPP instance, uint16 mode, CPluginArguments* adoptedArgs )
  65. :    CNetscapePlugin( instance, mode, adoptedArgs )
  66. {
  67.     instance->pdata = (void*) this;
  68. }
  69.  
  70. //======================================================================
  71. //        CViewText::~CViewText()
  72. //======================================================================
  73.  
  74. CViewText::~CViewText()
  75. {
  76. }
  77.  
  78.  
  79. //------------------------------------------------------------------------------------
  80. // CViewText::Handle_Event
  81. //
  82. // Default functionality for this virtual function is to ignore all but update events,
  83. // and draw when those are received.
  84. //------------------------------------------------------------------------------------
  85. NPBool
  86. CViewText::Handle_Event( void* inEvent )
  87. {
  88.     EventRecord* event = (EventRecord*) inEvent;
  89.  
  90.     CMacPluginView* macView = GetMacPluginView();
  91.     
  92.     NPBool eventHandled = false;
  93.     switch( event->what )
  94.     {
  95.         case keyDown:
  96.         case nullEvent:
  97.         case updateEvt:
  98.         case getFocusEvent:
  99.         case loseFocusEvent:
  100.         case mouseDown:
  101.         case mouseUp:
  102.         case activateEvt:
  103.             eventHandled = macView->Handle_Event( *event );
  104.             break;
  105.         default:
  106.             eventHandled = false;
  107.     }
  108.     return eventHandled;
  109. }
  110.  
  111. //------------------------------------------------------------------------------------
  112. // CViewText::CreateStream:
  113. //------------------------------------------------------------------------------------
  114. CNetscapeStream*
  115. CViewText::CreateStream( NPMIMEType type, NPStream *stream, NPBool seekable, uint16 stype )
  116. {
  117.     return new CPlainTextStream( type, stream, seekable, stype, GetTextEditView() );
  118. }
  119.  
  120. //------------------------------------------------------------------------------------
  121. // CViewText::GetTextEditView:
  122. //------------------------------------------------------------------------------------
  123. LTextEdit*
  124. CViewText::GetTextEditView()
  125. {
  126.     CMacPluginView* macView = GetMacPluginView();
  127.     return (LTextEdit*)macView->FindPaneByID( kTextEditPaneID );
  128. }
  129.  
  130. //------------------------------------------------------------------------------------
  131. // CViewText::CreatePluginView
  132. //------------------------------------------------------------------------------------
  133. CPluginView*
  134. CViewText::CreatePluginView( )
  135. {
  136.     return new CMacPluginView( this );
  137. }
  138.  
  139.  
  140.  
  141.