; Common editor messages
; They should be very simply and easy to be implemented. The most checks and error
; detection should be made by common functions in the file manager. This will make
; writing of the additional editors more easy.
;
;
;Description of CEI (common editor interface).
;
; Preface:
;   CEI is intended to provide easy interface for different files
; editor integrated to Fresh IDE. In the future, it is possible to
; make this interface open for editors added as DLL plugins.
;
; All interaction between "CEI compatible editor" (CCE) and Fresh file
; manager is only trough windows user defined messages (_CEM) and data
; structures. On the other hand, Fresh should interacts with CCE only
; through file manager API (FMA). The main goal of this approach is to
; make requirements for _CEM message handlers more simple and easy to
; implement. As a rule, _CEM message handlers should not provide error
; checking and only basic parameters checking.
;
; 1. Data structures:
;
; For every file that should be edited in some CCE, there should be
; defined data structure of type TFileType that describes the file
; format, editor and points to procedures that to make specific for
; this file type processing. This structure is defined following way:


struc TFileType createproc, ptrfilter, imageindex, lparam {
  .CreateProc dd  createproc   ; procedure that creates editor window for given file type.

  .ptrFilter  dd  ptrfilter    ; pointer (or handle) to the string that
                               ; contains the filter for Open/Save
                               ; dialogs for given file type.

  .iFileIcon  dd imageindex    ; Index of the icon for the file itself (in the project manager).

  .lParam    dd lparam       ; SyntaxProc for text source files. For another file types,
                             ; this may serve another functions.
}

virtual at 0
  TFileType TFileType 0,0,0,0
  sizeof.TFileType = $
end virtual

; The structure for the file that is created by File manager.
; This is description of the file and it's state in Fresh.
; It is not necessary the file to be loaded in the editor window.
; For example this structure is created for every file in the
; current open project, but only when the file is open for editing,
; editor will be created.
struct TOpenFile
  .ptrType      dd      ?       ; pointer to TFileType structure.
  .hFileName    dd      ?       ; handle of a string with full filename.
  .hashFileName dd      ?       ; precompiled hash value of the filename.

  .hEditor      dd      ?       ; Handle of the editor window. Every editor window
                                ; edits only one file.

  .projectID    dd      ?       ; Identifier that is back link to the project.
                                ; probably it should be handle of the treeview
                                ; item. The exact meaning of this value depends
                                ; only from project manager.

  .fNeverSaved  dd      ?       ; if TRUE, the file is created but never saved,
                                ; i.e. there is no file with this name on the disk.
                                ; File manager provides SaveAs dialogs for such
                                ; files on Save action. Also, such files MUST be
                                ; always loaded in the editor.

  .wParam       dd      ?       ; Last two dwords can have different meaning
  .lParam       dd      ?       ; depending of the particular type of the file.
ends

struct TInMemoryFile
  .fAscii    dd ?
  .fileSize  dd ?
  .ptrBuffer dd ?
ends


; 2. _CEM messages:
;
winmessage _CEM_GETTEXT      ; (0, ptrMemoryFile) - returns filled up structure [ptrMemoryFile]
                             ;                    the buffer is filled with content of the file
                             ;                    eax = FALSE if there is no error.
                             ;                    Returns TRUE if the error occurs.

winmessage CEM_LOADFILE      ; (hFilename, 0) - NULL if OK,
                             ; ErrorCode if error.
                             ; Loads (or reloads) the file in the editor.

winmessage _CEM_SETMODIFIED  ; (fModified, 0) - sets the "modified" status of the editor.

winmessage _CEM_CHANGENOTIFY  ; (0, 0) - notifies the editor
                              ; that content of the structure was changed
                              ; - name, the status of the file, etc.
                              ; Editor should provide updating of the file view.
                              ; Of course it can discard this message if it
                              ; not need such notifications. Also, the editor
                              ; can send _CEN_FILECHANGED to it's parent window

winmessage _CEM_FOCUSFILE    ; (0, 0) - Activates the editor window
                             ; and focuses the file.

winmessage _CEM_CANACTION    ; (0, action) - returns TRUE if the
                             ; content of the editor allows given action in
                             ; this moment.
                             ;  [action] can be one of:
                             ;    WM_UNDO
                             ;    WM_COPY
                             ;    WM_CUT
                             ;    WM_PASTE
                             ;    WM_CLEAR

winmessage _CEM_EDITACTION   ; (0, action) - Execute common edit
                             ; action in given file.
                             ;  [action] can be one of:
                             ;    WM_UNDO
                             ;    WM_COPY
                             ;    WM_CUT
                             ;    WM_PASTE
                             ;    WM_CLEAR

winmessage _CEM_GETMODIFIED  ; (0, 0) - returns TRUE if the given
                             ; file is modified and FALSE if the file is not
                             ; modified after the last save - it is probably
                             ; safe to always return TRUE.

winmessage _CEM_GETFILE      ; (0, 0) - returns pointer to TOpenFile structure
                             ; of the given file.

winmessage _CEM_GETASMEDIT   ; (0, 0) - returns handle of possibly internal for editor
                             ; ASMEDIT window, if any. NULL otherwize.

macro StrList [string] {
common
  local ..cnt
  ..cnt = 0
forward
  ..cnt = ..cnt + 1
common
         dd  ..cnt
forward
  local ..str
         dd  ..str
forward
  ..str  db  string,0
}


fcEditor = 1
fcProject = 2
fcAll     = 3
fcDontFree = 4

; Results from CloseFile function

cfrClosed = 0
cfrDestroyed = 1
cfrFault = 2
cfrCanceled = 3
