

#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "winreg.h"
#include "winerror.h"
#define NO_SHLWAPI_STREAM
#include "shlwapi.h"
#include "winuser.h"
#include "richedit.h"
#include "winnls.h"


#include "wine/debug.h"

WINE_DEFAULT_DEBUG_CHANNEL(richedit);


static LPSTR szRichClass20W;


static LRESULT WINAPI RICHED20_WindowProc(HWND hwnd, UINT uMsg, WPARAM wParam,
                                   LPARAM lParam)
{
    switch( uMsg )
    {
        case EM_CANPASTE:
        case EM_DISPLAYBAND:
        case EM_EXGETSEL:
        case EM_EXLIMITTEXT:
        case EM_EXLINEFROMCHAR:
        case EM_EXSETSEL:
        case EM_FINDTEXT:
        case EM_FORMATRANGE:
        case EM_GETCHARFORMAT:
        case EM_GETEVENTMASK:
        case EM_GETOLEINTERFACE:
        case EM_GETPARAFORMAT:
        case EM_GETSELTEXT:
        case EM_HIDESELECTION:
        case EM_PASTESPECIAL:
        case EM_REQUESTRESIZE:
        case EM_SELECTIONTYPE:
        case EM_SETBKGNDCOLOR:
        case EM_SETCHARFORMAT:
        case EM_SETEVENTMASK:
        case EM_SETOLECALLBACK:
        case EM_SETPARAFORMAT:
        case EM_SETTARGETDEVICE:
        case EM_STREAMIN:
        case EM_STREAMOUT:
        case EM_GETTEXTRANGE:
        case EM_FINDWORDBREAK:
        case EM_SETOPTIONS:
        case EM_GETOPTIONS:
        case EM_FINDTEXTEX:
        case EM_GETWORDBREAKPROCEX:
        case EM_SETWORDBREAKPROCEX:

        case EM_SETUNDOLIMIT:
        case EM_REDO:
        case EM_CANREDO:
        case EM_GETUNDONAME:
        case EM_GETREDONAME:
        case EM_STOPGROUPTYPING:

        case EM_SETTEXTMODE:
        case EM_GETTEXTMODE:
        case EM_AUTOURLDETECT:
        case EM_GETAUTOURLDETECT:
        case EM_SETPALETTE:
        case EM_GETTEXTEX:
        case EM_GETTEXTLENGTHEX:
        case EM_SHOWSCROLLBAR:
        case EM_SETTEXTEX:

        case EM_SETPUNCTUATION:
        case EM_GETPUNCTUATION:
        case EM_SETWORDWRAPMODE:
        case EM_GETWORDWRAPMODE:
        case EM_SETIMECOLOR:
        case EM_GETIMECOLOR:
        case EM_SETIMEOPTIONS:
        case EM_GETIMEOPTIONS:
        case EM_CONVPOSITION:

        case EM_SETLANGOPTIONS:
        case EM_GETLANGOPTIONS:
        case EM_GETIMECOMPMODE:

        case EM_FINDTEXTW:
        case EM_FINDTEXTEXW:

        case EM_RECONVERSION:
        case EM_SETIMEMODEBIAS:
        case EM_GETIMEMODEBIAS:

        case EM_SETBIDIOPTIONS:
        case EM_GETBIDIOPTIONS:

        case EM_SETTYPOGRAPHYOPTIONS:
        case EM_GETTYPOGRAPHYOPTIONS:

        case EM_SETEDITSTYLE:
        case EM_GETEDITSTYLE:

        case EM_OUTLINE:

        case EM_GETSCROLLPOS:
        case EM_SETSCROLLPOS:

        case EM_SETFONTSIZE:
        case EM_GETZOOM:
        case EM_SETZOOM:
            FIXME("Unhandled message 0x%04x (WM_USER + %u)\n", uMsg, uMsg - WM_USER); 
            return DefWindowProcA( hwnd,uMsg,wParam,lParam);


        default:
            FIXME("Unhandled message 0x%04x\n", uMsg); 
            return DefWindowProcA( hwnd,uMsg,wParam,lParam);
        break;
    }


    return 0;
}

static BOOL RICHED20_Register(void)
{
    WNDCLASSA wndClass;
    int len;

    ZeroMemory(&wndClass, sizeof(WNDCLASSA));

    wndClass.style = CS_HREDRAW | CS_VREDRAW | CS_GLOBALCLASS;
    wndClass.lpfnWndProc = (WNDPROC)RICHED20_WindowProc;
    wndClass.cbClsExtra = 0;
    wndClass.cbWndExtra = 0; /*(sizeof(RICHED32_INFO *);*/
    wndClass.hCursor = LoadCursorA(0, IDC_ARROWA);
    wndClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
    wndClass.lpszClassName = RICHEDIT_CLASS20A;

    /* Ascii version */
    RegisterClassA( &wndClass );

    len = lstrlenW( RICHEDIT_CLASS20W ) + 1;
    szRichClass20W = HeapAlloc( GetProcessHeap(), 0, len );
    if( szRichClass20W == NULL )
    {
        UnregisterClassA(RICHEDIT_CLASS20A, (HINSTANCE)NULL);
        return FALSE;
    }

    WideCharToMultiByte(CP_ACP, -1, RICHEDIT_CLASS20W, -1, szRichClass20W, len, NULL, NULL);
    
    wndClass.lpszClassName = szRichClass20W;

    /* Unicode version */
    RegisterClassA( &wndClass ); 

    return TRUE;   
}

static void RICHED32_Unregister(void)
{
    UnregisterClassA(RICHEDIT_CLASS20A, (HINSTANCE)NULL);
    UnregisterClassA(szRichClass20W, (HINSTANCE)NULL);
}



/***********************************************************************
 * RICHED20_LibMain [Internal] Initializes the internal 'RICHED32.DLL'.
 *
 * PARAMS
 *     hinstDLL    [I] handle to the DLL's instance
 *     fdwReason   [I]
 *     lpvReserved [I] reserved, must be NULL
 *
 * RETURNS
 *     Success: TRUE
 *     Failure: FALSE
 */

BOOL WINAPI
RICHED20_LibMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
{
    TRACE("\n");
    switch (fdwReason)
    {
    case DLL_PROCESS_ATTACH:
        RICHED20_Register();
        break;

    case DLL_PROCESS_DETACH:
        RICHED32_Unregister();
        break;
    }
    return TRUE;
}
