home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / pr / tests / w16gui / poppad.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-04-08  |  22.2 KB  |  654 lines

  1. /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
  2. /*
  3.  * The contents of this file are subject to the Netscape Public License
  4.  * Version 1.0 (the "NPL"); you may not use this file except in
  5.  * compliance with the NPL.  You may obtain a copy of the NPL at
  6.  * http://www.mozilla.org/NPL/
  7.  * 
  8.  * Software distributed under the NPL is distributed on an "AS IS" basis,
  9.  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  10.  * for the specific language governing rights and limitations under the
  11.  * NPL.
  12.  * 
  13.  * The Initial Developer of this code under the NPL is Netscape
  14.  * Communications Corporation.  Portions created by Netscape are
  15.  * Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  16.  * Reserved.
  17.  */
  18.  
  19. /*---------------------------------------
  20.    POPPAD.C -- Popup Editor
  21.    (c) Charles Petzold, 1992
  22.   ---------------------------------------*/
  23.  
  24. #include "nspr.h"
  25. #include "plevent.h"
  26. #include <windows.h>
  27. #include <commdlg.h>
  28. #include <stdlib.h>
  29. #include "poppad.h"
  30. #include <time.h>
  31.  
  32. #define EDITID   1
  33. #define UNTITLED "(untitled)"
  34.  
  35. long FAR PASCAL _export WndProc      (HWND, UINT, UINT, LONG) ;
  36. BOOL FAR PASCAL _export AboutDlgProc (HWND, UINT, UINT, LONG) ;
  37.  
  38. /* Declarations for NSPR customization
  39. ** 
  40. */
  41. typedef struct PadEvent
  42. {
  43.     PLEvent plEvent;
  44.     int     unused;    
  45. } PadEvent;
  46.  
  47. static void PR_CALLBACK TimerThread( void *arg);
  48. static void PR_CALLBACK HandlePadEvent( PadEvent *padEvent );
  49. static void PR_CALLBACK DestroyPadEvent( PadEvent *padevent );
  50. static PRThread *tThread;
  51. static PLEventQueue *padQueue; 
  52. static int  quitSwitch = 0;
  53. static long ThreadSleepTime = 1000;
  54. static long timerCount = 0;
  55. static char *startMessage = "Poppad: NSPR GUI and event test program.\n"
  56.                             "You should see lines of 50 characters\n"
  57.                             "with a new character appearing at 1 second intervals.\n"
  58.                             "Every 10 seconds gets a '+'; every 5 seconds gets a '_';\n"
  59.                             "every 1 second gets a '.'.\n\n"
  60.                             "You should be able to type in the window.\n\n\n";
  61.  
  62.  
  63.           // Functions in POPFILE.C
  64.  
  65. void PopFileInitialize (HWND) ;
  66. BOOL PopFileOpenDlg    (HWND, LPSTR, LPSTR) ;
  67. BOOL PopFileSaveDlg    (HWND, LPSTR, LPSTR) ;
  68. BOOL PopFileRead       (HWND, LPSTR) ;
  69. BOOL PopFileWrite      (HWND, LPSTR) ;
  70.  
  71.           // Functions in POPFIND.C
  72.  
  73. HWND PopFindFindDlg     (HWND) ;
  74. HWND PopFindReplaceDlg  (HWND) ;
  75. BOOL PopFindFindText    (HWND, int *, LPFINDREPLACE) ;
  76. BOOL PopFindReplaceText (HWND, int *, LPFINDREPLACE) ;
  77. BOOL PopFindNextText    (HWND, int *) ;
  78. BOOL PopFindValidFind   (void) ;
  79.  
  80.           // Functions in POPFONT.C
  81.  
  82. void PopFontInitialize   (HWND) ;
  83. BOOL PopFontChooseFont   (HWND) ;
  84. void PopFontSetFont      (HWND) ;
  85. void PopFontDeinitialize (void) ;
  86.  
  87.           // Functions in POPPRNT.C
  88.  
  89. BOOL PopPrntPrintFile (HANDLE, HWND, HWND, LPSTR) ;
  90.  
  91.           // Global variables
  92.  
  93. static char szAppName [] = "PopPad" ;
  94. static HWND hDlgModeless ;
  95. static HWND hwndEdit ;
  96.  
  97. int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance,
  98.                     LPSTR lpszCmdLine, int nCmdShow)
  99.     {
  100.     MSG      msg;
  101.     HWND     hwnd ;
  102.     HANDLE   hAccel ;
  103.     WNDCLASS wndclass ;
  104.  
  105.     PR_STDIO_INIT();
  106.     PR_Init(0, 0, 0);
  107.           
  108.     if (!hPrevInstance) 
  109.           {
  110.           wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  111.           wndclass.lpfnWndProc   = WndProc ;
  112.           wndclass.cbClsExtra    = 0 ;
  113.           wndclass.cbWndExtra    = 0 ;
  114.           wndclass.hInstance     = hInstance ;
  115.           wndclass.hIcon         = LoadIcon (hInstance, szAppName) ;
  116.           wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  117.           wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
  118.           wndclass.lpszMenuName  = szAppName ;
  119.           wndclass.lpszClassName = szAppName ;
  120.  
  121.           RegisterClass (&wndclass) ;
  122.           }
  123.  
  124.      hwnd = CreateWindow (szAppName, NULL,
  125.                           WS_OVERLAPPEDWINDOW,
  126.                           CW_USEDEFAULT, CW_USEDEFAULT,
  127.                           CW_USEDEFAULT, CW_USEDEFAULT,
  128.                           NULL, NULL, hInstance, lpszCmdLine) ;
  129.  
  130.      ShowWindow (hwnd, nCmdShow) ;
  131.      UpdateWindow (hwnd); 
  132.  
  133.      hAccel = LoadAccelerators (hInstance, szAppName) ;
  134.      
  135.      for(;;)
  136.      {
  137.         if ( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE  ))
  138.         {
  139.             if (GetMessage(&msg, NULL, 0, 0))
  140.             {
  141.                 if (hDlgModeless == NULL || !IsDialogMessage (hDlgModeless, &msg))
  142.                 {
  143.                     if (!TranslateAccelerator (hwnd, hAccel, &msg))
  144.                     {
  145.                         TranslateMessage (&msg) ;
  146.                         DispatchMessage (&msg) ;
  147.                     } /* end if !TranslateAccelerator */
  148.                 } 
  149.             }
  150.             else
  151.             {
  152.                 break;    
  153.             } /* end if GetMessage() */
  154.         } 
  155.         else /* !PeekMessage */
  156.         {
  157.             PR_Sleep(50);
  158.         }/* end if PeekMessage() */
  159.      } /* end for() */
  160.  
  161.      PR_JoinThread( tThread );
  162.      PL_DestroyEventQueue( padQueue );
  163.      PR_Cleanup();
  164.      return msg.wParam ;
  165.      }
  166.  
  167. void DoCaption (HWND hwnd, char *szTitleName)
  168.      {
  169.      char szCaption [64 + _MAX_FNAME + _MAX_EXT] ;
  170.  
  171.      wsprintf (szCaption, "%s - %s", (LPSTR) szAppName,
  172.                (LPSTR) (szTitleName [0] ? szTitleName : UNTITLED)) ;
  173.  
  174.      SetWindowText (hwnd, szCaption) ;
  175.      }
  176.  
  177. void OkMessage (HWND hwnd, char *szMessage, char *szTitleName)
  178.      {
  179.      char szBuffer [64 + _MAX_FNAME + _MAX_EXT] ;
  180.  
  181.      wsprintf (szBuffer, szMessage,
  182.                (LPSTR) (szTitleName [0] ? szTitleName : UNTITLED)) ;
  183.  
  184.      MessageBox (hwnd, szBuffer, szAppName, MB_OK | MB_ICONEXCLAMATION) ;
  185.      }
  186.  
  187. short AskAboutSave (HWND hwnd, char *szTitleName)
  188.      {
  189.      char  szBuffer [64 + _MAX_FNAME + _MAX_EXT] ;
  190.      short nReturn ;
  191.  
  192.      wsprintf (szBuffer, "Save current changes in %s?",
  193.                (LPSTR) (szTitleName [0] ? szTitleName : UNTITLED)) ;
  194.  
  195.      nReturn = MessageBox (hwnd, szBuffer, szAppName,
  196.                            MB_YESNOCANCEL | MB_ICONQUESTION) ;
  197.  
  198.      if (nReturn == IDYES)
  199.           if (!SendMessage (hwnd, WM_COMMAND, IDM_SAVE, 0L))
  200.                nReturn = IDCANCEL ;
  201.  
  202.      return nReturn ;
  203.      }
  204.  
  205. long FAR PASCAL _export WndProc (HWND hwnd, UINT message, UINT wParam,
  206.                                                           LONG lParam)
  207.      {
  208.      static BOOL    bNeedSave = FALSE ;
  209.      static char    szFileName  [_MAX_PATH] ;
  210.      static char    szTitleName [_MAX_FNAME + _MAX_EXT] ;
  211.      static FARPROC lpfnAboutDlgProc ;
  212.      static HANDLE  hInst ;
  213.      static int     iOffset ;
  214.      static UINT    messageFindReplace ;
  215.      LONG           lSelect ;
  216.      LPFINDREPLACE  lpfr ;
  217.      WORD           wEnable ;
  218.  
  219.      switch (message)
  220.           {
  221.           case WM_CREATE:
  222.                          // Get About dialog instance address
  223.  
  224.                hInst = ((LPCREATESTRUCT) lParam)->hInstance ;
  225.                lpfnAboutDlgProc = MakeProcInstance ((FARPROC) AboutDlgProc,
  226.                                                     hInst) ;
  227.  
  228.                          // Create the edit control child window
  229.  
  230.                hwndEdit = CreateWindow ("edit", NULL,
  231.                          WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
  232.                               WS_BORDER | ES_LEFT | ES_MULTILINE |
  233.                               ES_NOHIDESEL | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
  234.                          0, 0, 0, 0,
  235.                          hwnd, EDITID, hInst, NULL) ;
  236.  
  237.                SendMessage (hwndEdit, EM_LIMITTEXT, 32000, 0L) ;
  238.  
  239.                          // Initialize common dialog box stuff
  240.  
  241.                PopFileInitialize (hwnd) ;
  242.                PopFontInitialize (hwndEdit) ;
  243.  
  244.                messageFindReplace = RegisterWindowMessage (FINDMSGSTRING) ;
  245.  
  246.                          // Process command line
  247.  
  248.                lstrcpy (szFileName, (LPSTR)
  249.                         (((LPCREATESTRUCT) lParam)->lpCreateParams)) ;
  250.  
  251.                if (lstrlen (szFileName) > 0)
  252.                     {
  253.                     GetFileTitle (szFileName, szTitleName,
  254.                                   sizeof (szTitleName)) ;
  255.  
  256.                     if (!PopFileRead (hwndEdit, szFileName))
  257.                          OkMessage (hwnd, "File %s cannot be read!",
  258.                                           szTitleName) ;
  259.                     }
  260.  
  261.                DoCaption (hwnd, szTitleName) ;
  262.  
  263.                /* Initialize Event Processing for NSPR
  264.                ** Retrieve the event queue just created
  265.                ** Create the TimerThread
  266.                */               
  267.                PL_InitializeEventsLib("someName");
  268.                padQueue = PL_GetMainEventQueue();
  269.                tThread = PR_CreateThread(PR_USER_THREAD,
  270.                         TimerThread,
  271.                         NULL,
  272.                         PR_PRIORITY_NORMAL,
  273.                         PR_LOCAL_THREAD,
  274.                         PR_JOINABLE_THREAD,
  275.                         0 );
  276.                return 0 ;
  277.  
  278.           case WM_SETFOCUS:
  279.                SetFocus (hwndEdit) ;
  280.                return 0 ;
  281.  
  282.           case WM_SIZE: 
  283.                MoveWindow (hwndEdit, 0, 0, LOWORD (lParam),
  284.                                            HIWORD (lParam), TRUE) ;
  285.                return 0 ;
  286.  
  287.           case WM_INITMENUPOPUP:
  288.                switch (lParam)
  289.                     {
  290.                     case 1:        // Edit menu
  291.  
  292.                               // Enable Undo if edit control can do it
  293.  
  294.                          EnableMenuItem (wParam, IDM_UNDO,
  295.                               SendMessage (hwndEdit, EM_CANUNDO, 0, 0L) ?
  296.                                    MF_ENABLED : MF_GRAYED) ;
  297.  
  298.                               // Enable Paste if text is in the clipboard
  299.  
  300.                          EnableMenuItem (wParam, IDM_PASTE,
  301.                               IsClipboardFormatAvailable (CF_TEXT) ?
  302.                                    MF_ENABLED : MF_GRAYED) ;
  303.  
  304.                               // Enable Cut, Copy, and Del if text is selected
  305.  
  306.                          lSelect = SendMessage (hwndEdit, EM_GETSEL, 0, 0L) ;
  307.                          wEnable = HIWORD (lSelect) != LOWORD (lSelect) ?
  308.                                         MF_ENABLED : MF_GRAYED ;
  309.  
  310.                          EnableMenuItem (wParam, IDM_CUT,  wEnable) ;
  311.                          EnableMenuItem (wParam, IDM_COPY, wEnable) ;
  312.                          EnableMenuItem (wParam, IDM_DEL,  wEnable) ;
  313.                          break ;
  314.  
  315.                     case 2:        // Search menu
  316.  
  317.                               // Enable Find, Next, and Replace if modeless
  318.                               //   dialogs are not already active
  319.  
  320.                          wEnable = hDlgModeless == NULL ?
  321.                                         MF_ENABLED : MF_GRAYED ;
  322.  
  323.                          EnableMenuItem (wParam, IDM_FIND,    wEnable) ;
  324.                          EnableMenuItem (wParam, IDM_NEXT,    wEnable) ;
  325.                          EnableMenuItem (wParam, IDM_REPLACE, wEnable) ;
  326.                          break ;
  327.                     }
  328.                return 0 ;
  329.  
  330.           case WM_COMMAND :
  331.                               // Messages from edit control
  332.  
  333.                if (LOWORD (lParam) && wParam == EDITID)
  334.                     {
  335.                     switch (HIWORD (lParam))
  336.                          {
  337.                          case EN_UPDATE:
  338.                               bNeedSave = TRUE ;
  339.                               return 0 ;
  340.  
  341.                          case EN_ERRSPACE:
  342.                          case EN_MAXTEXT:
  343.                               MessageBox (hwnd, "Edit control out of space.",
  344.                                         szAppName, MB_OK | MB_ICONSTOP) ;
  345.                               return 0 ;
  346.                          }
  347.                     break ;
  348.                     }
  349.  
  350.                switch (wParam)
  351.                     {
  352.                               // Messages from File menu
  353.  
  354.                     case IDM_NEW:
  355.                          if (bNeedSave && IDCANCEL ==
  356.                                    AskAboutSave (hwnd, szTitleName))
  357.                               return 0 ;
  358.  
  359.                          SetWindowText (hwndEdit, "\0") ;
  360.                          szFileName [0]  = '\0' ;
  361.                          szTitleName [0] = '\0' ;
  362.                          DoCaption (hwnd, szTitleName) ;
  363.                          bNeedSave = FALSE ;
  364.                          return 0 ;
  365.  
  366.                     case IDM_OPEN:
  367.                          if (bNeedSave && IDCANCEL ==
  368.                                    AskAboutSave (hwnd, szTitleName))
  369.                               return 0 ;
  370.  
  371.                          if (PopFileOpenDlg (hwnd, szFileName, szTitleName))
  372.                               {
  373.                               if (!PopFileRead (hwndEdit, szFileName))
  374.                                    {
  375.                                    OkMessage (hwnd, "Could not read file %s!",
  376.                                                     szTitleName) ;
  377.                                    szFileName  [0] = '\0' ;
  378.                                    szTitleName [0] = '\0' ;
  379.                                    }
  380.                               }
  381.  
  382.                          DoCaption (hwnd, szTitleName) ;
  383.                          bNeedSave = FALSE ;
  384.                          return 0 ;
  385.  
  386.                     case IDM_SAVE:
  387.                          if (szFileName [0])
  388.                               {
  389.                               if (PopFileWrite (hwndEdit, szFileName))
  390.                                    {
  391.                                    bNeedSave = FALSE ;
  392.                                    return 1 ;
  393.                                    }
  394.                               else
  395.                                    OkMessage (hwnd, "Could not write file %s",
  396.                                                     szTitleName) ;
  397.                               return 0 ;
  398.                               }
  399.                                                   // fall through
  400.                     case IDM_SAVEAS:
  401.                          if (PopFileSaveDlg (hwnd, szFileName, szTitleName))
  402.                               {
  403.                               DoCaption (hwnd, szTitleName) ;
  404.  
  405.                               if (PopFileWrite (hwndEdit, szFileName))
  406.                                    {
  407.                                    bNeedSave = FALSE ;
  408.                                    return 1 ;
  409.                                    }
  410.                               else
  411.                                    OkMessage (hwnd, "Could not write file %s",
  412.                                                     szTitleName) ;
  413.                               }
  414.                          return 0 ;
  415.  
  416.                     case IDM_PRINT:
  417.                          if (!PopPrntPrintFile (hInst, hwnd, hwndEdit,
  418.                                                 szTitleName))
  419.                               OkMessage (hwnd, "Could not print file %s",
  420.                                          szTitleName) ;
  421.                          return 0 ;
  422.  
  423.                     case IDM_EXIT:
  424.                          SendMessage (hwnd, WM_CLOSE, 0, 0L) ;
  425.                          return 0 ;
  426.  
  427.                               // Messages from Edit menu
  428.  
  429.                     case IDM_UNDO:
  430.                          SendMessage (hwndEdit, WM_UNDO, 0, 0L) ;
  431.                          return 0 ;
  432.  
  433.                     case IDM_CUT:
  434.                          SendMessage (hwndEdit, WM_CUT, 0, 0L) ;
  435.                          return 0 ;
  436.  
  437.                     case IDM_COPY:
  438.                          SendMessage (hwndEdit, WM_COPY, 0, 0L) ;
  439.                          return 0 ;
  440.  
  441.                     case IDM_PASTE:
  442.                          SendMessage (hwndEdit, WM_PASTE, 0, 0L) ;
  443.                          return 0 ;
  444.  
  445.                     case IDM_DEL:
  446.                          SendMessage (hwndEdit, WM_CLEAR, 0, 0L) ;
  447.                          return 0 ;
  448.  
  449.                     case IDM_SELALL:
  450.                          SendMessage (hwndEdit, EM_SETSEL, 0,
  451.                                         MAKELONG (0, 32767)) ;
  452.                          return 0 ;
  453.  
  454.                               // Messages from Search menu
  455.  
  456.                     case IDM_FIND:
  457.                          iOffset = HIWORD (
  458.                               SendMessage (hwndEdit, EM_GETSEL, 0, 0L)) ;
  459.                          hDlgModeless = PopFindFindDlg (hwnd) ;
  460.                          return 0 ;
  461.  
  462.                     case IDM_NEXT:
  463.                          iOffset = HIWORD (
  464.                               SendMessage (hwndEdit, EM_GETSEL, 0, 0L)) ;
  465.  
  466.                          if (PopFindValidFind ())
  467.                               PopFindNextText (hwndEdit, &iOffset) ;
  468.                          else
  469.                               hDlgModeless = PopFindFindDlg (hwnd) ;
  470.  
  471.                          return 0 ;
  472.  
  473.                     case IDM_REPLACE:
  474.                          iOffset = HIWORD (
  475.                               SendMessage (hwndEdit, EM_GETSEL, 0, 0L)) ;
  476.  
  477.                          hDlgModeless = PopFindReplaceDlg (hwnd) ;
  478.                          return 0 ;
  479.  
  480.                     case IDM_FONT:
  481.                          if (PopFontChooseFont (hwnd))
  482.                               PopFontSetFont (hwndEdit) ;
  483.  
  484.                          return 0 ;
  485.  
  486.                               // Messages from Help menu
  487.  
  488.                     case IDM_HELP:
  489.                          OkMessage (hwnd, "Help not yet implemented!", NULL) ;
  490.                          return 0 ;
  491.  
  492.                     case IDM_ABOUT:
  493.                          DialogBox (hInst, "AboutBox", hwnd, lpfnAboutDlgProc);
  494.                          return 0 ;
  495.                     }
  496.                break ;
  497.  
  498.           case WM_CLOSE:
  499.                if (!bNeedSave || IDCANCEL != AskAboutSave (hwnd, szTitleName))
  500.                     DestroyWindow (hwnd) ;
  501.  
  502.                return 0 ;
  503.  
  504.           case WM_QUERYENDSESSION:
  505.                if (!bNeedSave || IDCANCEL != AskAboutSave (hwnd, szTitleName))
  506.                     return 1L ;
  507.  
  508.                return 0 ;
  509.  
  510.           case WM_DESTROY:
  511.                PopFontDeinitialize () ;
  512.                PostQuitMessage (0) ;
  513.                quitSwitch = 1;
  514.                return 0 ;
  515.  
  516.           default:
  517.                          // Process "Find-Replace" messages
  518.  
  519.                if (message == messageFindReplace)
  520.                     {
  521.                     lpfr = (LPFINDREPLACE) lParam ;
  522.  
  523.                     if (lpfr->Flags & FR_DIALOGTERM)
  524.                          hDlgModeless = NULL ;
  525.  
  526.                     if (lpfr->Flags & FR_FINDNEXT)
  527.                          if (!PopFindFindText (hwndEdit, &iOffset, lpfr))
  528.                               OkMessage (hwnd, "Text not found!", NULL) ;
  529.  
  530.                     if (lpfr->Flags & FR_REPLACE ||
  531.                         lpfr->Flags & FR_REPLACEALL)
  532.                          if (!PopFindReplaceText (hwndEdit, &iOffset, lpfr))
  533.                               OkMessage (hwnd, "Text not found!", NULL) ;
  534.  
  535.                     if (lpfr->Flags & FR_REPLACEALL)
  536.                          while (PopFindReplaceText (hwndEdit, &iOffset, lpfr));
  537.  
  538.                     return 0 ;
  539.                     }
  540.                break ;
  541.           }
  542.      return DefWindowProc (hwnd, message, wParam, lParam) ;
  543.      }
  544.  
  545. BOOL FAR PASCAL _export AboutDlgProc (HWND hDlg, UINT message, UINT wParam,
  546.                                                                LONG lParam)
  547.      {
  548.      switch (message)
  549.           {
  550.           case WM_INITDIALOG:
  551.                return TRUE ;
  552.  
  553.           case WM_COMMAND:
  554.                switch (wParam)
  555.                     {
  556.                     case IDOK:
  557.                          EndDialog (hDlg, 0) ;
  558.                          return TRUE ;
  559.                     }
  560.                break ;
  561.           }
  562.      return FALSE ;
  563.      }
  564. /*
  565. ** TimerThread() -- The Main function of the timer pop thread
  566. **
  567. */
  568. static void PR_CALLBACK TimerThread( void *arg)
  569. {
  570.     do {
  571.         PadEvent   *ev;
  572.         
  573.         /*
  574.         ** Should we quit now?
  575.         */
  576.         if ( quitSwitch )
  577.             break;
  578.         /*
  579.         ** Create and Post the event the event
  580.         */
  581.         PL_ENTER_EVENT_QUEUE_MONITOR( padQueue );
  582.         ev = (PadEvent *) PR_NEW( PadEvent );
  583.         PL_InitEvent( &ev->plEvent, NULL, 
  584.                 (PLHandleEventProc)HandlePadEvent, 
  585.                 (PLDestroyEventProc)DestroyPadEvent );
  586.         PL_PostEvent( padQueue, &ev->plEvent );
  587.         PL_EXIT_EVENT_QUEUE_MONITOR( padQueue );
  588.             
  589.         PR_Sleep( ThreadSleepTime );
  590.     } while(1);
  591.     return;
  592. }    
  593.  
  594. /*
  595. ** HandlePadEvent() -- gets called because of PostEvent
  596. */
  597. static void PR_CALLBACK HandlePadEvent( PadEvent *padEvent )
  598. {
  599.     if ( timerCount++ == 0 )
  600.     {
  601.         char *cp;
  602.         
  603.         for ( cp = startMessage; *cp != 0 ; cp++ )
  604.         {
  605.             SendMessage( hwndEdit, WM_CHAR, *cp, MAKELONG( *cp, 1 ));
  606.         }
  607.     }
  608.     /* 
  609.     ** Send a WM_CHAR event the edit Window
  610.     */
  611.     if ((timerCount % 10) == 0)
  612.     {
  613.         SendMessage( hwndEdit, WM_CHAR, '+', MAKELONG( '+', 1 ));
  614.     }
  615.     else if ((timerCount % 5) == 0)
  616.     {
  617.         SendMessage( hwndEdit, WM_CHAR, '_', MAKELONG( '_', 1 ));
  618.     }
  619.     else
  620.     {
  621.         SendMessage( hwndEdit, WM_CHAR, '.', MAKELONG( '.', 1 ));
  622.     }
  623.     
  624.     if ( (timerCount % 50) == 0)
  625.     {
  626.         SendMessage( hwndEdit, WM_CHAR, '\n', MAKELONG( '\n', 1 ));
  627.     }
  628.  
  629.     /*
  630.     ** PL_RevokeEvents() is broken. Test to fix it.
  631.     */
  632.     {
  633.         static long revokeCounter = 0;
  634.  
  635.         if (revokeCounter++ > 10 )
  636.         {
  637.             PR_Sleep( ThreadSleepTime * 10 );
  638.             SendMessage( hwndEdit, WM_CHAR, '*', MAKELONG( '\n', 1 ));
  639.             PL_RevokeEvents( padQueue, NULL );
  640.             revokeCounter = 0;
  641.         }
  642.     }
  643.     return;
  644. }
  645.  
  646. /*
  647. ** DestroyPadEvent() -- Called after HandlePadEvent()
  648. */
  649. static void PR_CALLBACK DestroyPadEvent( PadEvent *padevent )
  650. {
  651.    PR_Free( padevent );
  652.    return;
  653. }    
  654.