Back to index

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

Go to the source code of this file.

Classes

struct  PadEvent

Defines

#define ID_EDIT   1

Typedefs

typedef struct PadEvent PadEvent

Functions

static void PR_CALLBACK TimerThread (void *arg)
static void PR_CALLBACK HandlePadEvent (PadEvent *padEvent)
static void PR_CALLBACK DestroyPadEvent (PadEvent *padevent)
LRESULT CALLBACK WinProc (HWND, UINT, WPARAM, LPARAM)
int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, PSTR szCmdLine, int iCmdShow)

Variables

static PRThreadtThread
static PLEventQueuepadQueue
static long ThreadSleepTime = 1000
static long timerCount = 0
static HWND hDlgModeless
static HWND hwndEdit
static PRBool testFinished = PR_FALSE
static HWND hwnd
TCHAR appName [] = TEXT ("WinEvent")
static char * startMessage = "You should be able to type in the window.\n\n"
static char * stopMessage = " at one second intervals, the test worked.\n\n"

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 ID_EDIT   1

Definition at line 79 of file winevent.c.


Typedef Documentation

typedef struct PadEvent PadEvent

Function Documentation

static void PR_CALLBACK DestroyPadEvent ( PadEvent padevent) [static]

Definition at line 344 of file winevent.c.

{
   PR_Free( padevent );
   return;
}    

Here is the caller graph for this function:

static void PR_CALLBACK HandlePadEvent ( PadEvent padEvent) [static]

Definition at line 302 of file winevent.c.

{
    char *cp;
    static const long lineLimit = 10;   /* limit on number of '.' per line */
    static const long timerLimit = 25;  /* limit on timer pop iterations */

    if ( timerCount++ == 0 )
    {
        
        for ( cp = startMessage; *cp != 0 ; cp++ )
        {
            SendMessage( hwndEdit, WM_CHAR, *cp, 1 );
        }
    }
    /* 
    ** Send a WM_CHAR event the edit Window
    */
    SendMessage( hwndEdit, WM_CHAR, '.', 1 );
    
    /*
    ** Limit the number of characters sent via timer pop to lineLimit
    */
    if ( (timerCount % lineLimit) == 0)
    {
        SendMessage( hwndEdit, WM_CHAR, '\n', 1 );
    }

    if ( timerCount >= timerLimit )
    {
        for ( cp = stopMessage; *cp != 0 ; cp++ )
        {
            SendMessage( hwndEdit, WM_CHAR, *cp, 1 );
        }
        testFinished = PR_TRUE;
    }

    return;
}

Here is the caller graph for this function:

static void PR_CALLBACK TimerThread ( void arg) [static]

Definition at line 260 of file winevent.c.

{
    PRIntn  rc;

    do {
        PadEvent   *ev;
        
        /*
        ** 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( PR_MillisecondsToInterval(ThreadSleepTime) );
    } while( testFinished == PR_FALSE );

    PR_Sleep( PR_SecondsToInterval(4) );

    /*
    ** All done now. This thread can kill the main thread by sending 
    ** WM_DESTROY message to the main window.
    */
    SendMessage( hwnd, WM_DESTROY, 0, 0 );
    return;
}    

Here is the call graph for this function:

int WINAPI WinMain ( HINSTANCE  hInstance,
HINSTANCE  hPrevInstance,
PSTR  szCmdLine,
int  iCmdShow 
)

Definition at line 108 of file winevent.c.

{
    MSG      msg ;
    WNDCLASS wndclass ;
    HANDLE   hAccel ;
    
    PR_Init(0, 0, 0);

    wndclass.style = CS_HREDRAW | CS_VREDRAW;
    wndclass.lpfnWndProc = WinProc;
    wndclass.cbClsExtra = 0;
    wndclass.cbWndExtra = 0;
    wndclass.hInstance = hInstance;
    wndclass.hIcon = LoadIcon( NULL, IDI_APPLICATION );
    wndclass.hCursor = LoadCursor( NULL, IDC_ARROW );
    wndclass.hbrBackground = (HBRUSH)GetStockObject( WHITE_BRUSH );
    wndclass.lpszMenuName = NULL;
    wndclass.lpszClassName = appName;
     
    if ( !RegisterClass( &wndclass ))
    {
        MessageBox( NULL, 
            TEXT( "This program needs Win32" ),
            appName, 
            MB_ICONERROR );
        return 0; 
    }
     
    hwnd = CreateWindow( appName, 
        appName,
        WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, 
        CW_USEDEFAULT,
        CW_USEDEFAULT, 
        CW_USEDEFAULT,
        NULL, 
        NULL, 
        hInstance, 
        NULL);
     
     ShowWindow( hwnd, iCmdShow );
     UpdateWindow( hwnd ); 
     
     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:

LRESULT CALLBACK WinProc ( HWND  hwnd,
UINT  message,
WPARAM  wParam,
LPARAM  lParam 
)

Definition at line 188 of file winevent.c.

{
     switch (message)
     {
     case WM_CREATE :
          hwndEdit = CreateWindow(
                        TEXT( "edit" ), 
                        NULL,
                        WS_CHILD | WS_VISIBLE | WS_HSCROLL | WS_VSCROLL | 
                            WS_BORDER | ES_LEFT | ES_MULTILINE |
                            ES_AUTOHSCROLL | ES_AUTOVSCROLL,
                         0, 0, 0, 0, 
                         hwnd, 
                         (HMENU)ID_EDIT,
                         ((LPCREATESTRUCT)lParam)->hInstance, 
                         NULL);
     
          /* Initialize Event Processing for NSPR
          ** Retrieve the event queue just created
          ** Create the TimerThread
          */

/*
          PL_InitializeEventsLib( "someName" );
          padQueue = PL_GetMainEventQueue();
*/
          padQueue = PL_CreateEventQueue("MainQueue", PR_GetCurrentThread());
                PR_ASSERT( padQueue != NULL );
          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_COMMAND :
          if ( LOWORD(wParam) == ID_EDIT )
               if ( HIWORD(wParam ) == EN_ERRSPACE || 
                         HIWORD( wParam ) == EN_MAXTEXT )

                    MessageBox( hwnd, TEXT( "Edit control out of space." ),
                        appName, MB_OK | MB_ICONSTOP );
          return 0;
               
     case WM_DESTROY :
          PostQuitMessage(0);
          return 0;
     }
     return DefWindowProc( hwnd, message, wParam, lParam );
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

TCHAR appName[] = TEXT ("WinEvent")

Definition at line 106 of file winevent.c.

HWND hDlgModeless [static]

Definition at line 99 of file winevent.c.

HWND hwnd [static]

Definition at line 102 of file winevent.c.

HWND hwndEdit [static]

Definition at line 100 of file winevent.c.

Definition at line 96 of file winevent.c.

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

Definition at line 291 of file winevent.c.

char* stopMessage = " at one second intervals, the test worked.\n\n" [static]

Definition at line 296 of file winevent.c.

Definition at line 101 of file winevent.c.

long ThreadSleepTime = 1000 [static]

Definition at line 97 of file winevent.c.

long timerCount = 0 [static]

Definition at line 98 of file winevent.c.

PRThread* tThread [static]

Definition at line 95 of file winevent.c.