unit wRichTextFrame0;

{ Feel free to use this unit as you want.
  First developped by Bernard Gisin

  It uses the  Riched32.dll  file, which should be in your
  windows\system directory.

  to facilitate to have a RichEdit control in a window,
  to edit text.

  Descendent, which treats many Windows messages

  Menu numbers in  [65200..65399]  are reserved to treat
  menu commands concerning this control.
  ----------------------------------------------------------------}

// To tell FreePascal that the application is a Graphical User Interface
// i.e. is running in windows, not in text mode.
{$APPTYPE GUI}

INTERFACE
//"""""""

Uses wRichText0, wStatusLine0, wControl0, wWindowBase0, wGlobals2, Windows;

type
  PRichTextFrame0 = ^TRichTextFrame0;
  TRichTextFrame0 = object(TRichText)
  //"""""""""""""""""""""""""""""""""
//  hWin     : HWND;  // Handle on the edit box, got from TWindowBase
//  hParent : HWND;  // Handle on the parent, got from TWindowBase
//  poParent: PWindowBase0;  // Pointer on the parent, got from TWindowBase

  fReadOnly : boolean;
  // Can we write text, or only read it ?

  constructor Init(poParentW:PWindowBase0);
  destructor  Done; virtual;

  function WMCommand(wNrMenu:UINT):boolean; virtual;
  // Handles the WM_COMMAND messages comming from the menu,
  // which are standart for the library.

  procedure CtrlCreate; virtual;
  // If a status line exist, send a pointer on it,
  // if not, set poStatL to NIL
{
  function CtrlWindowProc(hWindow:HWND; wMsg:UINT; wPar:WPARAM; lPar:LPARAM):LRESULT; virtual;
  // Handles the window messages
  // It is usually overriden
  // A SendMessage(hWin, ...) must never be called from here, since
  // it would be a calling loop
}
  end; // TRichText0 = object(TControl)
  TRichTextFrame =  TRichTextFrame0;
  PRichTextFrame = ^TRichTextFrame;

IMPLEMENTATION
//""""""""""""

Uses wErrors0, wDebug0;

var nNotUsed : integer; // only to avoid an error message while compliling in DevPascal 1.9

constructor TRichTextFrame0.Init(poParentW:PWindowBase0);
//=======================================================
begin
inherited Init(poParentW);

wWindowType:=GGLCTE_CTRL_RICHEDIT;  // _FRAME ??????

// Can we write text, or only read it ?  We can wirte by default.
fReadOnly :=FALSE;
end;  // TRichTextFrame0.Init

destructor  TRichTextFrame0.Done;
//===============================
begin
inherited Done;
end;  // TRichTextFrame0.Done

function TRichTextFrame0.WMCommand(wNrMenu:UINT):boolean;
//=======================================================
// Handles the WM_COMMAND messages comming from the menu,
// which are standart for the library.
var
  hMenuWin    : HWND;
  wCheck      // to set a check mark in a menu.
              : word32;
begin
WMCommand:=TRUE; // by default, we treated the message

case wNrMenu of
   65201 : NewText;
   65202 : LoadRICH;
   65203 : SaveRICH;
   65204 : SaveRICHas;

   65211 : UndoText;
   65212 : CutText;
   65213 : CopyText;
   65214 : PasteText;
   65215 : SelectAllText;

   65231 : SelectFont;

   65232 : begin // toggle the read only flag.
      if (poParent = NIL) then exit;
      fReadOnly:=not fReadOnly;

      // tell the control to set or reset its readonly mode.
      SendMessage(hWin, EM_SETREADONLY, WPARAM(fReadOnly), 0);

      // Get the handle on the menu of the window owning this control
      hMenuWin:=GetMenu(poParent^.hWin);

      // change the menu check mark
      if fReadOnly then wCheck:=MF_CHECKED
      else              wCheck:=MF_UNCHECKED;
      CheckMenuItem(hMenuWin, wNrMenu, MF_BYCOMMAND or wCheck);
      end;

   else WMCommand:=FALSE; // We didn't treat the message.
   end; // case
end;  // TRichTextFrame0.WMCommand

procedure TRichTextFrame0.CtrlCreate;
//=======================================
begin
inherited CtrlCreate;

// Sets the focus on him, since it's the main control.
SetFocus(hWin);
end;  // TRichTextFrame0.CtrlCreate

{
function TRichTextFrame0.CtrlWindowProc(hWindow:HWND; wMsg:UINT; wPar:WPARAM; lPar:LPARAM):LRESULT;
//=================================================================================================
// handles the messages of the window control.
// A SendMessage(hWin, ...) must never be called from here, since
// it would be a calling loop
begin
CtrlWindowProc:=inherited CtrlWindowProc(hWindow, wMsg, wPar, lPar);
end; // TRichTextFrame0.CtrlWindowProc
}
End.  // unit wRichTextFrame0;

