'RICHUTIL.INC
=============


% CFE_BOLD        1
% CFE_ITALIC      2
% CFE_UNDERLINE	  4
% CFE_STRIKEOUT	  8
% CFE_PROTECTED	  16
% CFE_AUTOCOLOR	  0x40000000
% CFE_SUBSCRIPT	  0x00010000
% CFE_SUPERSCRIPT 0x00020000

% SCF_DEFAULT     0
% SCF_SELECTION   1
% SCF_WORD        2
% SCF_ALL         4
% SCF_USEUIRULES  8

% SF_TEXT           1
% SF_RTF            2
% SF_RTFNOOBJS      3
% SF_TEXTIZED       4
% SF_UNICODE        16
% SF_USECODEPAGE    32
% SF_NCRFORNONASCII 64
% SF_RTFVAL         0x0700
% SFF_PWD           0x0800
% SFF_KEEPDOCINFO   0x1000
% SFF_PERSISTVIEWSCALE 0x2000
% SFF_PLAINRTF      0x4000
% SFF_SELECTION     0x8000


% WM_USER           0x0400
% LF_FACESIZE       32

% EM_GETCHARFORMAT  0x043A
% EM_SETCHARFORMAT  0x0444
% EM_EXGETSEL       0x0434
% EM_EXSETSEL       0x0437
% EM_GETSELTEXT     0x043E
% EM_HIDESELECTION  0x043F

% EM_STREAMIN       0x0449
% EM_STREAMOUT      0x044A
% EM_GETTEXTRANGE   0x044B

% EM_SETBKGNDCOLOR  0x0443

% EM_GETTEXTEX      0x045E
% EM_SETTEXTEX      0x0461

==========================================

typedef dword COLORREF ' R G B bytes
typedef dword LCID
typedef sys   LPSTR, LPWSTR

'92 bytes
typedef struct _charformatw {
	UINT cbSize;
	DWORD dwMask;
	DWORD dwEffects;
	LONG yHeight;
	LONG yOffset;
	COLORREF crTextColor;
	BYTE bCharSet;
	BYTE bPitchAndFamily;
	WCHAR szFaceName[LF_FACESIZE];
} CHARFORMATW;

typedef struct _charformat2w {
	UINT cbSize;
	DWORD dwMask;
	DWORD dwEffects;
	LONG yHeight;
	LONG yOffset;
	COLORREF crTextColor;
	BYTE bCharSet;
	BYTE bPitchAndFamily;
	WCHAR szFaceName[LF_FACESIZE];
	WORD wWeight;
	SHORT sSpacing;
	COLORREF crBackColor;
	LCID lcidv;
	DWORD dwReserved;
	SHORT sStyle;
	WORD wKerning;
	BYTE bUnderlineType;
	BYTE bAnimation;
	BYTE bRevAuthor;
} CHARFORMAT2W;

typedef struct _charrange {
  LONG cpMin;
  LONG cpMax;
} CHARRANGE;

typedef struct _textrangew {
  CHARRANGE chrg;
  LPWSTR    lpstrText;
} TEXTRANGEW;

typedef struct _editstream {
  sys                dwCookie;
  DWORD              dwError;
  sys                pfnCallback;
} EDITSTREAM;

==========================================
'ANSI


typedef struct _charformat {
  UINT     cbSize;
  DWORD    dwMask;
  DWORD    dwEffects;
  LONG     yHeight;
  LONG     yOffset;
  COLORREF crTextColor;
  BYTE     bCharSet;
  BYTE     bPitchAndFamily;
  char     szFaceName[LF_FACESIZE];
} CHARFORMATA;

typedef struct _charformat2a {
  UINT     cbSize;
  DWORD    dwMask;
  DWORD    dwEffects;
  LONG     yHeight;
  LONG     yOffset;
  COLORREF crTextColor;
  BYTE     bCharSet;
  BYTE     bPitchAndFamily;
  char     szFaceName[LF_FACESIZE];
  WORD     wWeight;
  SHORT    sSpacing;
  COLORREF crBackColor;
  LCID     lcid;
  union {
    DWORD dwReserved;
    DWORD dwCookie;
  };
  DWORD    dwReserved;
  SHORT    sStyle;
  WORD     wKerning;
  BYTE     bUnderlineType;
  BYTE     bAnimation;
  BYTE     bRevAuthor;
  BYTE     bUnderlineColor;
} CHARFORMAT2A;


typedef struct _textrange {
  CHARRANGE chrg;
  LPSTR     lpstrText;
} TEXTRANGEA;

==========================================


  sys rt = loadlibrary("MSFTEDIT.DLL")
  'print rt

  'sys rt = loadlibraryW(l"MSFTEDIT.DLL")

  #ifndef w
    sys w[16] 'child windows
  #endif

  sys hFont
  wstring ws
  int da[100] 'diagnostic
  wstring ds 'diagnostic
  'ws = (wstring) getfile "Multilingual.txt"

  string ubuf
  sys ubufp, ubufe, ubufl

  % ID_FIRSTCHILD  100


   function Editstreamocallback(sys *dwCookie, pbBuff, cb, *pcb) as dword callback
  ================================================================================
  '  DWORD_PTR dwCookie,
  '  LPBYTE pbBuff,
  '  LONG cb,
  '  LONG *pcb
  '
  'ACCUMULATE OUTPUT
  if ubufl+cb>ubufe 'stretch buffer
    sys obufp
    obufp=ubufp
    ubufe=ubufe*2+cb+0x1000
    ubufp=getmemory ubufe
    if obufp
      copy ubufp,obufp,ubufl
      freememory obufp
    endif
  endif
  copy ubufp+ubufl,pbBuff,cb
  ubufl+=cb
  pcb=cb
  '
  return 0 'no errors
  end function


  function Editstreamicallback(sys *dwCookie, pbBuff, cb, *pcb) as dword callback
  ===============================================================================
  '  DWORD_PTR dwCookie,
  '  LPBYTE pbBuff,
  '  LONG cb,
  '  LONG *pcb
  '
  'PASS INPUT
  if ubufl<ubufe
    if cb>ubufe-ubufl
      cb=ubufe-ubufl
    endif
    copy pbBuff,ubufp+ubufl,cb
    ubufl+=cb
    pcb=cb
  else
    pcb=0
  endif
  return 0 'no errors
  end function

  EDITSTREAM StreamIn, StreamOut
  '
  if ubufp
    freememory ubufp
    ubufp=0
    ubufe=0
  endif
  '
  ubufl=0
  '
  'bstring fdi=getfile("test.rtf")
  'ubufp=strptr(fdi)
  'ubufe=len(fdi)
  'StreamIn={0,0,@Editstreamicallback}
  'SendMessageW(h,EM_STREAMIN,SF_RTF,StreamIn)



  int fvc 'first visible char (from firs visible line)
  int fvp '
  int pvc '
'
    function GoProc(sys hwnd, uMsg, wParam, lParam,uIdSubclass,dwRefData) as int callback
  =====================================================================================
  indexbase 0
  int a,b

  select uMsg

  case WM_CHAR
    if wparam<>VK_RETURN
      DefSubClassProc(hwnd, uMsg, wParam, lParam)
    else
     char ch[40]
     SendMessage w[5],WM_GETTEXT, 32, ch
     a=val(ch)
     b=SendMessage w[3], EM_LINEINDEX, a, 0    'LOCATE START OF LINE
     SendMessage w[3],EM_SETSEL,b,b
     SetFocus w[3]
    endif
    return 1

  case else

    return DefSubClassProc(hwnd, uMsg, wParam, lParam)

  end select
  end function


function EdProc(sys hwnd, uMsg, wParam, lParam,uIdSubclass,dwRefData) as int callback
  =====================================================================================
  indexbase 0
  int a,b,x,y
  RECT r

  select uMsg

  case WM_KEYDOWN

    DefSubClassProc(hwnd, uMsg, wParam, lParam)
    SendMessage w[3], EM_GETSEL, @a, @b
    a=SendMessage w[3], EM_LINEFROMCHAR, a, 0
    SendMessage w[5],WM_SETTEXT, 0, str(a+1) 
    return 1

  case WM_LBUTTONDOWN
  
    DefSubClassProc(hwnd, uMsg, wParam, lParam)
    SendMessage w[3], EM_GETSEL, @a, @b
    a=SendMessage w[3], EM_LINEFROMCHAR, a, 0
    SendMessage w[5],WM_SETTEXT, 0, str(a+1) 
    return 1
/*
  case WM_KEYDOWN
    '
    select wParam
    case VK_HOME : a=1
    'case VK_END  : a=1
    end select
    if a
      GetClientRect(hwnd,r)
      InvalidateRect(hwnd,r,0)
    endif

  case WM_HSCROLL
    ' 
    DefSubClassProc(hwnd, uMsg, wParam, lParam)
    'r.right = 40 'margin lie number area
    GetClientRect(hwnd,r)
    InvalidateRect(hwnd,r,0)
    return 1

  case WM_PAINT
    '
    point pt
    'stati c wchar sz[32]
    static char sz[32]
    DWORD lc
    RECT crect
    sys rgn
    int dret
    sys hDC
    int line
    int charidx

    function = DefSubClassProc(hwnd, uMsg, wParam, lParam)
    '
    if pvc
      return 1
    endif
    '
    'lc = SendMessageW(hWnd,EM_GETLINECOUNT,0,0)
    lc = SendMessage(hWnd,EM_GETLINECOUNT,0,0)
    if lc
      hDC = GetDC(hWnd)
      SaveDC(hDC)
      GetClientRect(hWnd,&crect)
      rgn = CreateRectRgn(crect.left,crect.top,40,crect.bottom)
      SelectClipRgn(hDC,rgn)
      'SendMessageW(hWnd,WM_SETFONT,hfont,0)
      'SendMessage(hWnd,WM_SETFONT,hfont,0)
      % PATCOPY 0x00F00021
      BitBlt(hDC,0,0,40,crect.bottom, hDC,0,0,PATCOPY)
      '
      'line = SendMessageW(hWnd,EM_GETFIRSTVISIBLELINE,0,0)
      line = SendMessage(hWnd,EM_GETFIRSTVISIBLELINE,0,0)
      while line <= lc
        'charidx = SendMessageW(hWnd,EM_LINEINDEX,line,0)
        charidx = SendMessage(hWnd,EM_LINEINDEX,line,0)
        exit if charidx == -1
        'SendMessageW(hWnd,EM_POSFROMCHAR,@pt,charidx)
        SendMessage(hWnd,EM_POSFROMCHAR,@pt,charidx)
        'standard edit control
        'a=SendMessage(hWnd,EM_POSFROMCHAR,charidx,0)
        'pt.x=a and 0xffff
        'pt.y=a>>16
        exit if pt.y >= crect.bottom
        'set line number
        'wsprintf(&sz,"%lu",10*(line+1))
        SetTextColor(hDC,0xffbbbb)
        sz = STR(line+1)+"  "
        TextOut hDC,4,pt.y,strptr(sz),len(sz)
        line++
      wend
      RestoreDC(hDC,-1)           
      DeleteObject(rgn)
      ReleaseDC(hWnd,hDC)
    endif
    return 1
*/
  end select
  return DefSubClassProc(hwnd, uMsg, wParam, lParam)
  end function
 
 