/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
/* ***** BEGIN LICENSE BLOCK *****
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
*
* The contents of this file are subject to the Mozilla Public License Version
* 1.1 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
* for the specific language governing rights and limitations under the
* License.
*
* The Original Code is the Netscape Portable Runtime (NSPR).
*
* The Initial Developer of the Original Code is
* Netscape Communications Corporation.
* Portions created by the Initial Developer are Copyright (C) 1998-2000
* the Initial Developer. All Rights Reserved.
*
* Contributor(s):
*
* Alternatively, the contents of this file may be used under the terms of
* either the GNU General Public License Version 2 or later (the "GPL"), or
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
* in which case the provisions of the GPL or the LGPL are applicable instead
* of those above. If you wish to allow use of your version of this file only
* under the terms of either the GPL or the LGPL, and not to allow others to
* use your version of this file under the terms of the MPL, indicate your
* decision by deleting the provisions above and replace them with the notice
* and other provisions required by the GPL or the LGPL. If you do not delete
* the provisions above, a recipient may use your version of this file under
* the terms of any one of the MPL, the GPL or the LGPL.
*
* ***** END LICENSE BLOCK ***** */
/*---------------------------------------
POPPAD.C -- Popup Editor
(c) Charles Petzold, 1992
---------------------------------------*/
#include "nspr.h"
#include "plevent.h"
#include <windows.h>
#include <commdlg.h>
#include <stdlib.h>
#include "poppad.h"
#include <time.h>
/* Declarations for NSPR customization
**
*/
typedef struct PadEvent
{
int unused;
} PadEvent;
static int quitSwitch = 0;
static long timerCount = 0;
"You should see lines of 50 characters\n"
"with a new character appearing at 1 second intervals.\n"
"Every 10 seconds gets a '+'; every 5 seconds gets a '_';\n"
"every 1 second gets a '.'.\n\n"
"You should be able to type in the window.\n\n\n";
// Functions in POPFILE.C
void PopFileInitialize (HWND) ;
// Functions in POPFIND.C
BOOL PopFindValidFind (void) ;
// Functions in POPFONT.C
void PopFontInitialize (HWND) ;
void PopFontSetFont (HWND) ;
void PopFontDeinitialize (void) ;
// Functions in POPPRNT.C
// Global variables
{
PR_Init(0, 0, 0);
if (!hPrevInstance)
{
wndclass.cbClsExtra = 0 ;
wndclass.cbWndExtra = 0 ;
RegisterClass (&wndclass) ;
}
UpdateWindow (hwnd);
for(;;)
{
{
{
{
{
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 );
PR_Cleanup();
}
{
}
{
}
{
short nReturn ;
return nReturn ;
}
{
static int iOffset ;
switch (message)
{
case WM_CREATE:
// Get About dialog instance address
hInst) ;
// Create the edit control child window
0, 0, 0, 0,
// Initialize common dialog box stuff
// Process command line
if (lstrlen (szFileName) > 0)
{
sizeof (szTitleName)) ;
szTitleName) ;
}
/* Initialize Event Processing for NSPR
** Retrieve the event queue just created
** Create the TimerThread
*/
PL_InitializeEventsLib("someName");
NULL,
0 );
return 0 ;
case WM_SETFOCUS:
return 0 ;
case WM_SIZE:
return 0 ;
case WM_INITMENUPOPUP:
switch (lParam)
{
case 1: // Edit menu
// Enable Undo if edit control can do it
MF_ENABLED : MF_GRAYED) ;
// Enable Paste if text is in the clipboard
MF_ENABLED : MF_GRAYED) ;
// Enable Cut, Copy, and Del if text is selected
MF_ENABLED : MF_GRAYED ;
break ;
case 2: // Search menu
// Enable Find, Next, and Replace if modeless
// dialogs are not already active
MF_ENABLED : MF_GRAYED ;
break ;
}
return 0 ;
case WM_COMMAND :
// Messages from edit control
{
{
case EN_UPDATE:
return 0 ;
case EN_ERRSPACE:
case EN_MAXTEXT:
return 0 ;
}
break ;
}
switch (wParam)
{
// Messages from File menu
case IDM_NEW:
return 0 ;
szFileName [0] = '\0' ;
szTitleName [0] = '\0' ;
return 0 ;
case IDM_OPEN:
return 0 ;
{
{
szTitleName) ;
szFileName [0] = '\0' ;
szTitleName [0] = '\0' ;
}
}
return 0 ;
case IDM_SAVE:
if (szFileName [0])
{
{
return 1 ;
}
else
szTitleName) ;
return 0 ;
}
// fall through
case IDM_SAVEAS:
{
{
return 1 ;
}
else
szTitleName) ;
}
return 0 ;
case IDM_PRINT:
szTitleName) ;
return 0 ;
case IDM_EXIT:
return 0 ;
// Messages from Edit menu
case IDM_UNDO:
return 0 ;
case IDM_CUT:
return 0 ;
case IDM_COPY:
return 0 ;
case IDM_PASTE:
return 0 ;
case IDM_DEL:
return 0 ;
case IDM_SELALL:
MAKELONG (0, 32767)) ;
return 0 ;
// Messages from Search menu
case IDM_FIND:
return 0 ;
case IDM_NEXT:
if (PopFindValidFind ())
else
return 0 ;
case IDM_REPLACE:
return 0 ;
case IDM_FONT:
if (PopFontChooseFont (hwnd))
return 0 ;
// Messages from Help menu
case IDM_HELP:
return 0 ;
case IDM_ABOUT:
return 0 ;
}
break ;
case WM_CLOSE:
DestroyWindow (hwnd) ;
return 0 ;
case WM_QUERYENDSESSION:
return 1L ;
return 0 ;
case WM_DESTROY:
PopFontDeinitialize () ;
PostQuitMessage (0) ;
quitSwitch = 1;
return 0 ;
default:
// Process "Find-Replace" messages
if (message == messageFindReplace)
{
hDlgModeless = NULL ;
return 0 ;
}
break ;
}
}
{
switch (message)
{
case WM_INITDIALOG:
return TRUE ;
case WM_COMMAND:
switch (wParam)
{
case IDOK:
return TRUE ;
}
break ;
}
return FALSE ;
}
/*
** TimerThread() -- The Main function of the timer pop thread
**
*/
{
do {
/*
** Should we quit now?
*/
if ( quitSwitch )
break;
/*
** Create and Post the event the event
*/
} while(1);
return;
}
/*
** HandlePadEvent() -- gets called because of PostEvent
*/
{
if ( timerCount++ == 0 )
{
char *cp;
{
}
}
/*
** Send a WM_CHAR event the edit Window
*/
if ((timerCount % 10) == 0)
{
}
else if ((timerCount % 5) == 0)
{
}
else
{
}
if ( (timerCount % 50) == 0)
{
}
/*
** PL_RevokeEvents() is broken. Test to fix it.
*/
{
static long revokeCounter = 0;
if (revokeCounter++ > 10 )
{
revokeCounter = 0;
}
}
return;
}
/*
** DestroyPadEvent() -- Called after HandlePadEvent()
*/
{
return;
}