Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Typedefs | Functions | Variables
poppad.c File Reference
#include "nspr.h"
#include "plevent.h"
#include <windows.h>
#include <commdlg.h>
#include <stdlib.h>
#include "poppad.h"
#include <time.h>

Go to the source code of this file.

Classes

struct  PadEvent

Defines

#define EDITID   1
#define UNTITLED   "(untitled)"

Typedefs

typedef struct PadEvent PadEvent

Functions

long FAR PASCAL _export WndProc (HWND, UINT, UINT, LONG)
BOOL FAR PASCAL _export AboutDlgProc (HWND, UINT, UINT, LONG)
static void PR_CALLBACK TimerThread (void *arg)
static void PR_CALLBACK HandlePadEvent (PadEvent *padEvent)
static void PR_CALLBACK DestroyPadEvent (PadEvent *padevent)
void PopFileInitialize (HWND)
BOOL PopFileOpenDlg (HWND, LPSTR, LPSTR)
BOOL PopFileSaveDlg (HWND, LPSTR, LPSTR)
BOOL PopFileRead (HWND, LPSTR)
BOOL PopFileWrite (HWND, LPSTR)
HWND PopFindFindDlg (HWND)
HWND PopFindReplaceDlg (HWND)
BOOL PopFindFindText (HWND, int *, LPFINDREPLACE)
BOOL PopFindReplaceText (HWND, int *, LPFINDREPLACE)
BOOL PopFindNextText (HWND, int *)
BOOL PopFindValidFind (void)
void PopFontInitialize (HWND)
BOOL PopFontChooseFont (HWND)
void PopFontSetFont (HWND)
void PopFontDeinitialize (void)
BOOL PopPrntPrintFile (HANDLE, HWND, HWND, LPSTR)
int PASCAL WinMain (HANDLE hInstance, HANDLE hPrevInstance, LPSTR lpszCmdLine, int nCmdShow)
void DoCaption (HWND hwnd, char *szTitleName)
void OkMessage (HWND hwnd, char *szMessage, char *szTitleName)
short AskAboutSave (HWND hwnd, char *szTitleName)

Variables

static PRThreadtThread
static PLEventQueuepadQueue
static int quitSwitch = 0
static long ThreadSleepTime = 1000
static long timerCount = 0
static char * startMessage = "You should be able to type in the window.\n\n\n"
static char szAppName [] = "PopPad"
static HWND hDlgModeless
static HWND hwndEdit

Class Documentation

struct PadEvent

Definition at line 85 of file winevent.c.

Collaboration diagram for PadEvent:
Class Members
PLEvent plEvent
int unused

Define Documentation

#define EDITID   1

Definition at line 51 of file poppad.c.

#define UNTITLED   "(untitled)"

Definition at line 52 of file poppad.c.


Typedef Documentation

typedef struct PadEvent PadEvent

Function Documentation

BOOL FAR PASCAL _export AboutDlgProc ( HWND  hDlg,
UINT  message,
UINT  wParam,
LONG  lParam 
)

Definition at line 564 of file poppad.c.

     {
     switch (message)
          {
          case WM_INITDIALOG:
               return TRUE ;

          case WM_COMMAND:
               switch (wParam)
                    {
                    case IDOK:
                         EndDialog (hDlg, 0) ;
                         return TRUE ;
                    }
               break ;
          }
     return FALSE ;
     }

Here is the caller graph for this function:

short AskAboutSave ( HWND  hwnd,
char *  szTitleName 
)

Definition at line 206 of file poppad.c.

     {
     char  szBuffer [64 + _MAX_FNAME + _MAX_EXT] ;
     short nReturn ;

     wsprintf (szBuffer, "Save current changes in %s?",
               (LPSTR) (szTitleName [0] ? szTitleName : UNTITLED)) ;

     nReturn = MessageBox (hwnd, szBuffer, szAppName,
                           MB_YESNOCANCEL | MB_ICONQUESTION) ;

     if (nReturn == IDYES)
          if (!SendMessage (hwnd, WM_COMMAND, IDM_SAVE, 0L))
               nReturn = IDCANCEL ;

     return nReturn ;
     }

Here is the caller graph for this function:

static void PR_CALLBACK DestroyPadEvent ( PadEvent padevent) [static]

Definition at line 668 of file poppad.c.

{
   PR_Free( padevent );
   return;
}    

Here is the caller graph for this function:

void DoCaption ( HWND  hwnd,
char *  szTitleName 
)

Definition at line 186 of file poppad.c.

     {
     char szCaption [64 + _MAX_FNAME + _MAX_EXT] ;

     wsprintf (szCaption, "%s - %s", (LPSTR) szAppName,
               (LPSTR) (szTitleName [0] ? szTitleName : UNTITLED)) ;

     SetWindowText (hwnd, szCaption) ;
     }

Here is the caller graph for this function:

static void PR_CALLBACK HandlePadEvent ( PadEvent padEvent) [static]

Definition at line 616 of file poppad.c.

{
    if ( timerCount++ == 0 )
    {
        char *cp;
        
        for ( cp = startMessage; *cp != 0 ; cp++ )
        {
            SendMessage( hwndEdit, WM_CHAR, *cp, MAKELONG( *cp, 1 ));
        }
    }
    /* 
    ** Send a WM_CHAR event the edit Window
    */
    if ((timerCount % 10) == 0)
    {
        SendMessage( hwndEdit, WM_CHAR, '+', MAKELONG( '+', 1 ));
    }
    else if ((timerCount % 5) == 0)
    {
        SendMessage( hwndEdit, WM_CHAR, '_', MAKELONG( '_', 1 ));
    }
    else
    {
        SendMessage( hwndEdit, WM_CHAR, '.', MAKELONG( '.', 1 ));
    }
    
    if ( (timerCount % 50) == 0)
    {
        SendMessage( hwndEdit, WM_CHAR, '\n', MAKELONG( '\n', 1 ));
    }

    /*
    ** PL_RevokeEvents() is broken. Test to fix it.
    */
    {
        static long revokeCounter = 0;

        if (revokeCounter++ > 10 )
        {
            PR_Sleep( ThreadSleepTime * 10 );
            SendMessage( hwndEdit, WM_CHAR, '*', MAKELONG( '\n', 1 ));
            PL_RevokeEvents( padQueue, NULL );
            revokeCounter = 0;
        }
    }
    return;
}

Here is the call graph for this function:

Here is the caller graph for this function:

void OkMessage ( HWND  hwnd,
char *  szMessage,
char *  szTitleName 
)

Definition at line 196 of file poppad.c.

     {
     char szBuffer [64 + _MAX_FNAME + _MAX_EXT] ;

     wsprintf (szBuffer, szMessage,
               (LPSTR) (szTitleName [0] ? szTitleName : UNTITLED)) ;

     MessageBox (hwnd, szBuffer, szAppName, MB_OK | MB_ICONEXCLAMATION) ;
     }

Here is the caller graph for this function:

Definition at line 49 of file popfile.c.

     {
     static char *szFilter[] = { "Text Files (*.TXT)",  "*.txt",
                                 "ASCII Files (*.ASC)", "*.asc",
                                 "All Files (*.*)",     "*.*",
                                 "" } ;

     ofn.lStructSize       = sizeof (OPENFILENAME) ;
     ofn.hwndOwner         = hwnd ;
     ofn.hInstance         = NULL ;
     ofn.lpstrFilter       = szFilter [0] ;
     ofn.lpstrCustomFilter = NULL ;
     ofn.nMaxCustFilter    = 0 ;
     ofn.nFilterIndex      = 0 ;
     ofn.lpstrFile         = NULL ;          // Set in Open and Close functions
     ofn.nMaxFile          = _MAX_PATH ;
     ofn.lpstrFileTitle    = NULL ;          // Set in Open and Close functions
     ofn.nMaxFileTitle     = _MAX_FNAME + _MAX_EXT ;
     ofn.lpstrInitialDir   = NULL ;
     ofn.lpstrTitle        = NULL ;
     ofn.Flags             = 0 ;             // Set in Open and Close functions
     ofn.nFileOffset       = 0 ;
     ofn.nFileExtension    = 0 ;
     ofn.lpstrDefExt       = "txt" ;
     ofn.lCustData         = 0L ;
     ofn.lpfnHook          = NULL ;
     ofn.lpTemplateName    = NULL ;
     }

Here is the caller graph for this function:

BOOL PopFileOpenDlg ( HWND  ,
LPSTR  ,
LPSTR   
)

Definition at line 78 of file popfile.c.

     {
     ofn.hwndOwner         = hwnd ;
     ofn.lpstrFile         = lpstrFileName ;
     ofn.lpstrFileTitle    = lpstrTitleName ;
     ofn.Flags             = OFN_CREATEPROMPT ;

     return GetOpenFileName (&ofn) ;
     }

Here is the caller graph for this function:

BOOL PopFileRead ( HWND  ,
LPSTR   
)

Definition at line 108 of file popfile.c.

     {
     long   lLength ;
     HANDLE hBuffer ;
     int    hFile ;
     LPSTR  lpstrBuffer ;

     if (-1 == (hFile = _lopen (lpstrFileName, OF_READ | OF_SHARE_DENY_WRITE)))
          return FALSE ;

     if ((lLength = PopFileLength (hFile)) >= 32000)
          {
          _lclose (hFile) ;
          return FALSE ;
          }

     if (NULL == (hBuffer = GlobalAlloc (GHND, lLength + 1)))
          {
          _lclose (hFile) ;
          return FALSE ;
          }

     lpstrBuffer = GlobalLock (hBuffer) ;
     _lread (hFile, lpstrBuffer, (WORD) lLength) ;
     _lclose (hFile) ;
     lpstrBuffer [(WORD) lLength] = '\0' ;

     SetWindowText (hwndEdit, lpstrBuffer) ;
     GlobalUnlock (hBuffer) ;
     GlobalFree (hBuffer) ;

     return TRUE ;
     }

Here is the call graph for this function:

Here is the caller graph for this function:

BOOL PopFileSaveDlg ( HWND  ,
LPSTR  ,
LPSTR   
)

Definition at line 88 of file popfile.c.

     {
     ofn.hwndOwner         = hwnd ;
     ofn.lpstrFile         = lpstrFileName ;
     ofn.lpstrFileTitle    = lpstrTitleName ;
     ofn.Flags             = OFN_OVERWRITEPROMPT ;

     return GetSaveFileName (&ofn) ;
     }

Here is the caller graph for this function:

BOOL PopFileWrite ( HWND  ,
LPSTR   
)

Definition at line 142 of file popfile.c.

     {
     HANDLE hBuffer ;
     int    hFile ;
     LPSTR  lpstrBuffer ;
     WORD   wLength ;

     if (-1 == (hFile = _lopen (lpstrFileName, OF_WRITE | OF_SHARE_EXCLUSIVE)))
          if (-1 == (hFile = _lcreat (lpstrFileName, 0)))
               return FALSE ;

     wLength = GetWindowTextLength (hwndEdit) ;
     hBuffer = (HANDLE) SendMessage (hwndEdit, EM_GETHANDLE, 0, 0L) ;
     lpstrBuffer = (LPSTR) LocalLock (hBuffer) ;

     if (wLength != _lwrite (hFile, lpstrBuffer, wLength))
          {
          _lclose (hFile) ;
          return FALSE ;
          }

     _lclose (hFile) ;
     LocalUnlock (hBuffer) ;

     return TRUE ;
     }

Here is the caller graph for this function:

Definition at line 51 of file popfind.c.

     {
     static FINDREPLACE fr ;       // must be static for modeless dialog!!!

     fr.lStructSize      = sizeof (FINDREPLACE) ;
     fr.hwndOwner        = hwnd ;
     fr.hInstance        = NULL ;
     fr.Flags            = FR_HIDEUPDOWN | FR_HIDEMATCHCASE | FR_HIDEWHOLEWORD ;
     fr.lpstrFindWhat    = szFindText ;
     fr.lpstrReplaceWith = NULL ;
     fr.wFindWhatLen     = sizeof (szFindText) ;
     fr.wReplaceWithLen  = 0 ;
     fr.lCustData        = 0 ;
     fr.lpfnHook         = NULL ;
     fr.lpTemplateName   = NULL ;

     return FindText (&fr) ;
     }

Here is the caller graph for this function:

BOOL PopFindFindText ( HWND  ,
int ,
LPFINDREPLACE   
)

Definition at line 89 of file popfind.c.

     {
     int         iPos ;
     LOCALHANDLE hLocal ;
     LPSTR       lpstrDoc, lpstrPos ;

               // Get a pointer to the edit document

     hLocal   = (HWND) SendMessage (hwndEdit, EM_GETHANDLE, 0, 0L) ;
     lpstrDoc = (LPSTR) LocalLock (hLocal) ;

               // Search the document for the find string

     lpstrPos = _fstrstr (lpstrDoc + *piSearchOffset, lpfr->lpstrFindWhat) ;
     LocalUnlock (hLocal) ;

               // Return an error code if the string cannot be found

     if (lpstrPos == NULL)
          return FALSE ;

               // Find the position in the document and the new start offset

     iPos = lpstrPos - lpstrDoc ;
     *piSearchOffset = iPos + _fstrlen (lpfr->lpstrFindWhat) ;

               // Select the found text

     SendMessage (hwndEdit, EM_SETSEL, 0,
                  MAKELONG (iPos, *piSearchOffset)) ;

     return TRUE ;
     }

Here is the caller graph for this function:

BOOL PopFindNextText ( HWND  ,
int  
)

Definition at line 123 of file popfind.c.

     {
     FINDREPLACE fr ;

     fr.lpstrFindWhat = szFindText ;

     return PopFindFindText (hwndEdit, piSearchOffset, &fr) ;
     }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 70 of file popfind.c.

     {
     static FINDREPLACE fr ;       // must be static for modeless dialog!!!

     fr.lStructSize      = sizeof (FINDREPLACE) ;
     fr.hwndOwner        = hwnd ;
     fr.hInstance        = NULL ;
     fr.Flags            = FR_HIDEUPDOWN | FR_HIDEMATCHCASE | FR_HIDEWHOLEWORD ;
     fr.lpstrFindWhat    = szFindText ;
     fr.lpstrReplaceWith = szReplText ;
     fr.wFindWhatLen     = sizeof (szFindText) ;
     fr.wReplaceWithLen  = sizeof (szReplText) ;
     fr.lCustData        = 0 ;
     fr.lpfnHook         = NULL ;
     fr.lpTemplateName   = NULL ;

     return ReplaceText (&fr) ;
     }

Here is the caller graph for this function:

BOOL PopFindReplaceText ( HWND  ,
int ,
LPFINDREPLACE   
)

Definition at line 132 of file popfind.c.

     {
               // Find the text

     if (!PopFindFindText (hwndEdit, piSearchOffset, lpfr))
          return FALSE ;

               // Replace it

     SendMessage (hwndEdit, EM_REPLACESEL, 0, (long) lpfr->lpstrReplaceWith) ;

     return TRUE ;
     }

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 146 of file popfind.c.

     {
     return *szFindText != '\0' ;
     }

Here is the caller graph for this function:

Definition at line 49 of file popfont.c.

     {
     CHOOSEFONT cf ;

     cf.lStructSize      = sizeof (CHOOSEFONT) ;
     cf.hwndOwner        = hwnd ;
     cf.hDC              = NULL ;
     cf.lpLogFont        = &logfont ;
     cf.iPointSize       = 0 ;
     cf.Flags            = CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS
                                                  | CF_EFFECTS ;
     cf.rgbColors        = 0L ;
     cf.lCustData        = 0L ;
     cf.lpfnHook         = NULL ;
     cf.lpTemplateName   = NULL ;
     cf.hInstance        = NULL ;
     cf.lpszStyle        = NULL ;
     cf.nFontType        = 0 ;               // Returned from ChooseFont
     cf.nSizeMin         = 0 ;
     cf.nSizeMax         = 0 ;

     return ChooseFont (&cf) ;
     }

Here is the caller graph for this function:

Definition at line 91 of file popfont.c.

     {
     DeleteObject (hFont) ;
     }

Here is the caller graph for this function:

Definition at line 73 of file popfont.c.

     {
     GetObject (GetStockObject (SYSTEM_FONT), sizeof (LOGFONT),
                                              (LPSTR) &logfont) ;
     hFont = CreateFontIndirect (&logfont) ;
     SendMessage (hwndEdit, WM_SETFONT, hFont, 0L) ;
     }

Here is the caller graph for this function:

Definition at line 81 of file popfont.c.

     {
     HFONT hFontNew ;

     hFontNew = CreateFontIndirect (&logfont) ;
     SendMessage (hwndEdit, WM_SETFONT, hFontNew, 0L) ;
     DeleteObject (hFont) ;
     hFont = hFontNew ;
     }

Here is the caller graph for this function:

BOOL PopPrntPrintFile ( HANDLE  ,
HWND  ,
HWND  ,
LPSTR   
)

Definition at line 45 of file popprnt0.c.

     {
     return FALSE ;
     }

Here is the caller graph for this function:

static void PR_CALLBACK TimerThread ( void arg) [static]

Definition at line 587 of file poppad.c.

{
    do {
        PadEvent   *ev;
        
        /*
        ** Should we quit now?
        */
        if ( quitSwitch )
            break;
        /*
        ** Create and Post the event the event
        */
        PL_ENTER_EVENT_QUEUE_MONITOR( padQueue );
        ev = (PadEvent *) PR_NEW( PadEvent );
        PL_InitEvent( &ev->plEvent, NULL, 
                (PLHandleEventProc)HandlePadEvent, 
                (PLDestroyEventProc)DestroyPadEvent );
        PL_PostEvent( padQueue, &ev->plEvent );
        PL_EXIT_EVENT_QUEUE_MONITOR( padQueue );
            
        PR_Sleep( ThreadSleepTime );
    } while(1);
    return;
}    

Here is the call graph for this function:

int PASCAL WinMain ( HANDLE  hInstance,
HANDLE  hPrevInstance,
LPSTR  lpszCmdLine,
int  nCmdShow 
)

Definition at line 116 of file poppad.c.

    {
    MSG      msg;
    HWND     hwnd ;
    HANDLE   hAccel ;
    WNDCLASS wndclass ;

    PR_STDIO_INIT();
    PR_Init(0, 0, 0);
          
    if (!hPrevInstance) 
          {
          wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
          wndclass.lpfnWndProc   = WndProc ;
          wndclass.cbClsExtra    = 0 ;
          wndclass.cbWndExtra    = 0 ;
          wndclass.hInstance     = hInstance ;
          wndclass.hIcon         = LoadIcon (hInstance, szAppName) ;
          wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
          wndclass.hbrBackground = GetStockObject (WHITE_BRUSH) ;
          wndclass.lpszMenuName  = szAppName ;
          wndclass.lpszClassName = szAppName ;

          RegisterClass (&wndclass) ;
          }

     hwnd = CreateWindow (szAppName, NULL,
                          WS_OVERLAPPEDWINDOW,
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          CW_USEDEFAULT, CW_USEDEFAULT,
                          NULL, NULL, hInstance, lpszCmdLine) ;

     ShowWindow (hwnd, nCmdShow) ;
     UpdateWindow (hwnd); 

     hAccel = LoadAccelerators (hInstance, szAppName) ;
     
     for(;;)
     {
        if ( PeekMessage( &msg, NULL, 0, 0, PM_NOREMOVE  ))
        {
            if (GetMessage(&msg, NULL, 0, 0))
            {
                if (hDlgModeless == NULL || !IsDialogMessage (hDlgModeless, &msg))
                {
                    if (!TranslateAccelerator (hwnd, hAccel, &msg))
                    {
                        TranslateMessage (&msg) ;
                        DispatchMessage (&msg) ;
                    } /* end if !TranslateAccelerator */
                } 
            }
            else
            {
                break;    
            } /* end if GetMessage() */
        } 
        else /* !PeekMessage */
        {
            PR_Sleep(50);
        }/* end if PeekMessage() */
     } /* end for() */

     PR_JoinThread( tThread );
     PL_DestroyEventQueue( padQueue );
     PR_Cleanup();
     return msg.wParam ;
     }

Here is the call graph for this function:

long FAR PASCAL _export WndProc ( HWND  hwnd,
UINT  message,
UINT  wParam,
LONG  lParam 
)

Definition at line 224 of file poppad.c.

     {
     static BOOL    bNeedSave = FALSE ;
     static char    szFileName  [_MAX_PATH] ;
     static char    szTitleName [_MAX_FNAME + _MAX_EXT] ;
     static FARPROC lpfnAboutDlgProc ;
     static HANDLE  hInst ;
     static int     iOffset ;
     static UINT    messageFindReplace ;
     LONG           lSelect ;
     LPFINDREPLACE  lpfr ;
     WORD           wEnable ;

     switch (message)
          {
          case WM_CREATE:
                         // Get About dialog instance address

               hInst = ((LPCREATESTRUCT) lParam)->hInstance ;
               lpfnAboutDlgProc = MakeProcInstance ((FARPROC) AboutDlgProc,
                                                    hInst) ;

                         // Create the edit control child window

               hwndEdit = CreateWindow ("edit", NULL,
                         WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL |
                              WS_BORDER | ES_LEFT | ES_MULTILINE |
                              ES_NOHIDESEL | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
                         0, 0, 0, 0,
                         hwnd, EDITID, hInst, NULL) ;

               SendMessage (hwndEdit, EM_LIMITTEXT, 32000, 0L) ;

                         // Initialize common dialog box stuff

               PopFileInitialize (hwnd) ;
               PopFontInitialize (hwndEdit) ;

               messageFindReplace = RegisterWindowMessage (FINDMSGSTRING) ;

                         // Process command line

               lstrcpy (szFileName, (LPSTR)
                        (((LPCREATESTRUCT) lParam)->lpCreateParams)) ;

               if (lstrlen (szFileName) > 0)
                    {
                    GetFileTitle (szFileName, szTitleName,
                                  sizeof (szTitleName)) ;

                    if (!PopFileRead (hwndEdit, szFileName))
                         OkMessage (hwnd, "File %s cannot be read!",
                                          szTitleName) ;
                    }

               DoCaption (hwnd, szTitleName) ;

               /* Initialize Event Processing for NSPR
               ** Retrieve the event queue just created
               ** Create the TimerThread
               */               
               PL_InitializeEventsLib("someName");
               padQueue = PL_GetMainEventQueue();
               tThread = PR_CreateThread(PR_USER_THREAD,
                        TimerThread,
                        NULL,
                        PR_PRIORITY_NORMAL,
                        PR_LOCAL_THREAD,
                        PR_JOINABLE_THREAD,
                        0 );
               return 0 ;

          case WM_SETFOCUS:
               SetFocus (hwndEdit) ;
               return 0 ;

          case WM_SIZE: 
               MoveWindow (hwndEdit, 0, 0, LOWORD (lParam),
                                           HIWORD (lParam), TRUE) ;
               return 0 ;

          case WM_INITMENUPOPUP:
               switch (lParam)
                    {
                    case 1:        // Edit menu

                              // Enable Undo if edit control can do it

                         EnableMenuItem (wParam, IDM_UNDO,
                              SendMessage (hwndEdit, EM_CANUNDO, 0, 0L) ?
                                   MF_ENABLED : MF_GRAYED) ;

                              // Enable Paste if text is in the clipboard

                         EnableMenuItem (wParam, IDM_PASTE,
                              IsClipboardFormatAvailable (CF_TEXT) ?
                                   MF_ENABLED : MF_GRAYED) ;

                              // Enable Cut, Copy, and Del if text is selected

                         lSelect = SendMessage (hwndEdit, EM_GETSEL, 0, 0L) ;
                         wEnable = HIWORD (lSelect) != LOWORD (lSelect) ?
                                        MF_ENABLED : MF_GRAYED ;

                         EnableMenuItem (wParam, IDM_CUT,  wEnable) ;
                         EnableMenuItem (wParam, IDM_COPY, wEnable) ;
                         EnableMenuItem (wParam, IDM_DEL,  wEnable) ;
                         break ;

                    case 2:        // Search menu

                              // Enable Find, Next, and Replace if modeless
                              //   dialogs are not already active

                         wEnable = hDlgModeless == NULL ?
                                        MF_ENABLED : MF_GRAYED ;

                         EnableMenuItem (wParam, IDM_FIND,    wEnable) ;
                         EnableMenuItem (wParam, IDM_NEXT,    wEnable) ;
                         EnableMenuItem (wParam, IDM_REPLACE, wEnable) ;
                         break ;
                    }
               return 0 ;

          case WM_COMMAND :
                              // Messages from edit control

               if (LOWORD (lParam) && wParam == EDITID)
                    {
                    switch (HIWORD (lParam))
                         {
                         case EN_UPDATE:
                              bNeedSave = TRUE ;
                              return 0 ;

                         case EN_ERRSPACE:
                         case EN_MAXTEXT:
                              MessageBox (hwnd, "Edit control out of space.",
                                        szAppName, MB_OK | MB_ICONSTOP) ;
                              return 0 ;
                         }
                    break ;
                    }

               switch (wParam)
                    {
                              // Messages from File menu

                    case IDM_NEW:
                         if (bNeedSave && IDCANCEL ==
                                   AskAboutSave (hwnd, szTitleName))
                              return 0 ;

                         SetWindowText (hwndEdit, "\0") ;
                         szFileName [0]  = '\0' ;
                         szTitleName [0] = '\0' ;
                         DoCaption (hwnd, szTitleName) ;
                         bNeedSave = FALSE ;
                         return 0 ;

                    case IDM_OPEN:
                         if (bNeedSave && IDCANCEL ==
                                   AskAboutSave (hwnd, szTitleName))
                              return 0 ;

                         if (PopFileOpenDlg (hwnd, szFileName, szTitleName))
                              {
                              if (!PopFileRead (hwndEdit, szFileName))
                                   {
                                   OkMessage (hwnd, "Could not read file %s!",
                                                    szTitleName) ;
                                   szFileName  [0] = '\0' ;
                                   szTitleName [0] = '\0' ;
                                   }
                              }

                         DoCaption (hwnd, szTitleName) ;
                         bNeedSave = FALSE ;
                         return 0 ;

                    case IDM_SAVE:
                         if (szFileName [0])
                              {
                              if (PopFileWrite (hwndEdit, szFileName))
                                   {
                                   bNeedSave = FALSE ;
                                   return 1 ;
                                   }
                              else
                                   OkMessage (hwnd, "Could not write file %s",
                                                    szTitleName) ;
                              return 0 ;
                              }
                                                  // fall through
                    case IDM_SAVEAS:
                         if (PopFileSaveDlg (hwnd, szFileName, szTitleName))
                              {
                              DoCaption (hwnd, szTitleName) ;

                              if (PopFileWrite (hwndEdit, szFileName))
                                   {
                                   bNeedSave = FALSE ;
                                   return 1 ;
                                   }
                              else
                                   OkMessage (hwnd, "Could not write file %s",
                                                    szTitleName) ;
                              }
                         return 0 ;

                    case IDM_PRINT:
                         if (!PopPrntPrintFile (hInst, hwnd, hwndEdit,
                                                szTitleName))
                              OkMessage (hwnd, "Could not print file %s",
                                         szTitleName) ;
                         return 0 ;

                    case IDM_EXIT:
                         SendMessage (hwnd, WM_CLOSE, 0, 0L) ;
                         return 0 ;

                              // Messages from Edit menu

                    case IDM_UNDO:
                         SendMessage (hwndEdit, WM_UNDO, 0, 0L) ;
                         return 0 ;

                    case IDM_CUT:
                         SendMessage (hwndEdit, WM_CUT, 0, 0L) ;
                         return 0 ;

                    case IDM_COPY:
                         SendMessage (hwndEdit, WM_COPY, 0, 0L) ;
                         return 0 ;

                    case IDM_PASTE:
                         SendMessage (hwndEdit, WM_PASTE, 0, 0L) ;
                         return 0 ;

                    case IDM_DEL:
                         SendMessage (hwndEdit, WM_CLEAR, 0, 0L) ;
                         return 0 ;

                    case IDM_SELALL:
                         SendMessage (hwndEdit, EM_SETSEL, 0,
                                        MAKELONG (0, 32767)) ;
                         return 0 ;

                              // Messages from Search menu

                    case IDM_FIND:
                         iOffset = HIWORD (
                              SendMessage (hwndEdit, EM_GETSEL, 0, 0L)) ;
                         hDlgModeless = PopFindFindDlg (hwnd) ;
                         return 0 ;

                    case IDM_NEXT:
                         iOffset = HIWORD (
                              SendMessage (hwndEdit, EM_GETSEL, 0, 0L)) ;

                         if (PopFindValidFind ())
                              PopFindNextText (hwndEdit, &iOffset) ;
                         else
                              hDlgModeless = PopFindFindDlg (hwnd) ;

                         return 0 ;

                    case IDM_REPLACE:
                         iOffset = HIWORD (
                              SendMessage (hwndEdit, EM_GETSEL, 0, 0L)) ;

                         hDlgModeless = PopFindReplaceDlg (hwnd) ;
                         return 0 ;

                    case IDM_FONT:
                         if (PopFontChooseFont (hwnd))
                              PopFontSetFont (hwndEdit) ;

                         return 0 ;

                              // Messages from Help menu

                    case IDM_HELP:
                         OkMessage (hwnd, "Help not yet implemented!", NULL) ;
                         return 0 ;

                    case IDM_ABOUT:
                         DialogBox (hInst, "AboutBox", hwnd, lpfnAboutDlgProc);
                         return 0 ;
                    }
               break ;

          case WM_CLOSE:
               if (!bNeedSave || IDCANCEL != AskAboutSave (hwnd, szTitleName))
                    DestroyWindow (hwnd) ;

               return 0 ;

          case WM_QUERYENDSESSION:
               if (!bNeedSave || IDCANCEL != AskAboutSave (hwnd, szTitleName))
                    return 1L ;

               return 0 ;

          case WM_DESTROY:
               PopFontDeinitialize () ;
               PostQuitMessage (0) ;
               quitSwitch = 1;
               return 0 ;

          default:
                         // Process "Find-Replace" messages

               if (message == messageFindReplace)
                    {
                    lpfr = (LPFINDREPLACE) lParam ;

                    if (lpfr->Flags & FR_DIALOGTERM)
                         hDlgModeless = NULL ;

                    if (lpfr->Flags & FR_FINDNEXT)
                         if (!PopFindFindText (hwndEdit, &iOffset, lpfr))
                              OkMessage (hwnd, "Text not found!", NULL) ;

                    if (lpfr->Flags & FR_REPLACE ||
                        lpfr->Flags & FR_REPLACEALL)
                         if (!PopFindReplaceText (hwndEdit, &iOffset, lpfr))
                              OkMessage (hwnd, "Text not found!", NULL) ;

                    if (lpfr->Flags & FR_REPLACEALL)
                         while (PopFindReplaceText (hwndEdit, &iOffset, lpfr));

                    return 0 ;
                    }
               break ;
          }
     return DefWindowProc (hwnd, message, wParam, lParam) ;
     }

Here is the call graph for this function:


Variable Documentation

HWND hDlgModeless [static]

Definition at line 113 of file poppad.c.

HWND hwndEdit [static]

Definition at line 114 of file poppad.c.

Definition at line 70 of file poppad.c.

int quitSwitch = 0 [static]

Definition at line 71 of file poppad.c.

char* startMessage = "You should be able to type in the window.\n\n\n" [static]

Definition at line 74 of file poppad.c.

char szAppName[] = "PopPad" [static]

Definition at line 112 of file poppad.c.

long ThreadSleepTime = 1000 [static]

Definition at line 72 of file poppad.c.

long timerCount = 0 [static]

Definition at line 73 of file poppad.c.

PRThread* tThread [static]

Definition at line 69 of file poppad.c.