Fresh IDE . Artifact [6733aac584]
Not logged in

This repository is a mirror!

The original is located on: https://fresh.flatassembler.net/fossil/repo/fresh
If you want to follow the project, please update your remote-url

Artifact 6733aac584e21b737d47ba23126e88e61e5bdd8d:


subject: How to create editors for Fresh common editor interface.
author:  John Found


I. Preface:
    Fresh common editor interface is system of data structures messages
and functions, that provides one common interface for different files
editors.

1. The editor can be implemented as independent window class or as a
windows of some common class (for example TForm) possibly with children
windows. For example, editor for text type files ( sourceeditor.asm ) is
implemented as one AsmEdit window, while for editor (formeditor.asm) is
complex system with parent of class TForm and childs TPropEdit and AsmEdit.

Common is that every editor window have to be registered as alignable window
with RegisterWindow function and must process all messages from
common editor messages group. (see below for description).




II. How to create such editors and how to integrate them in Fresh IDE:


1. At first, you have to create 3 data objects - descriptions of the
desired file type. All of these 3 data objects is element of array of
the same data descriptions for another file types.

        All 3 arrays are defined at the begining of the file "filemanager.asm' of
Fresh sources.

  1.1 The first of them is TFileType structure. It is defined following way:

struc TFileType createproc, ptrfilter, imageindex, lparam {
  .CreateProc dd  createproc
  .ptrFilter  dd  ptrfilter
  .iFileIcon  dd  imageindex
  .lParam     dd  lparam
}

Arguments of the structure are:

  createproc - pointer to the function for creating one editor instance.
               (for details, see paragraph 2.)
  ptrfilter  - pointer to string that contains filter for Open/Save dialogs.
  imageindex - index of the icon for this file type in the standard files
               image list.
  lparam     - editor defined value. You can use it for internal editors
               purposes or not use it at all. For example in text based
               file formats, this is pointer to the editor highligher.


  For example, I will show how to create descripion for .bmp image files:

  ; Windows bitmap (.bmp) image file.
  ftBmpImage  TFileType CreateGraphicEditor, \
                        BmpFilter,           \
                        4,                   \
                        NULL

  TFileType structure have to be included in the array of TFileType
definitions: FileTypes


  1.2. Second data object is the screen name of the file type. It is
quoted string, inserted at the proper place (depending of the placement
of TFileType) in the string sequence: FileTypeNames
For our .bmp editor (if we insert TFileType as a last element of FileTypes)
the string list will become:

  FileTypeNames:
        StrList                               \
          'Project',                          \
          'Source file',                      \
          'Main file',                        \
          'Form',                             \
          'Text document',                    \
          'Bitmap image'


  1.3. The third element is dword number with 4 ascii codes for default
file extension, inserted in dword array: FileTypeExt. The first char must
be '.', so you can use only 3 chars extensions. You can use quoted string
for this definition - '.bmp' for example.

  FileTypeExt  dd '.fpr', '.asm', '.asm', '.frm', '.txt', '.bmp'



  2. Creation procedure: You need to write a procedure that to create
one instance of editor window.

  2.1. Parameter passing.

This procedure have one argument - pointer to TOpenFile structure from
the file manager:

proc CreateGraphicEditor, ptrOpenFile
begin
...
endp

  2.2. What this procedure have to do:

  2.2.1 - Create editor window.

  2.2.2 - Properly placeing this editor window in the screen - for example
        registering for tabbed editing (see "editorshost.asm" file).

  2.2.3 - Ensure registering this window for auto align operations (and
        possibly for user defined message handler) - with RegisterWindow.

  2.2.4 - storing the handle of the editor window to the TOpenFile.hEditor
        field.

  2.2.5 - Save the pointer to TOpenFile in the internal editors data (this
        data fields have to be separate for every editor instance)

  2.2.6 - Loading the file specified in TOpenFile structure passed to the
        function - loading of the file is highly recomended to be made with
        sending message CEM_LOADFILE to the created window.


  2.3. Return values:

        If the editor window is created successfully,
  the procedure must return NULL

        If there is some error in creation or loading
  file it should return error code obtained via GetLastError.

        If the window is created, but there is some error in
  loading file, the function have to destroy window prior to exiting.


Example:

proc CreateGraphicEditor, ptrOpenFile
begin
        push    ebx esi

        mov     esi, [ptrOpenFile]

        xor     eax, eax
        invoke  CreateWindowEx, WS_EX_CLIENTEDGE, cBmpEditClassName, NULL, \
                WS_CHILD or WS_HSCROLL or WS_VSCROLL,                      \
                eax, eax, eax, eax,                                        \
                [hEditorsHost], eax, [hInstance], eax

        test    eax, eax
        jz      .errorcreate

        mov     ebx, eax
        mov     [esi+TOpenFile.hEditor], ebx

        invoke  SetWindowLong, ebx, 4, esi   ; save TOpenFile pointer.

        stdcall RegisterWindow, ebx, waNone, BmpEditProc ; register for autoalign and
                                                         ; custom message processing.

        invoke  SendMessage, ebx, CEM_LOADFILE, 0, 0     ; load the file.
        test    eax, eax
        jnz     .errorload

        ; register the editor for tabbed editing (editorshost.asm)
        invoke  SendMessage, [hEditorsHost], EHM_DOCKWINDOW, ebx, dfClient
; OK
        xor     eax, eax
        pop     esi ebx
        return

.errorcreate:
        invoke  GetLastError
        pop     esi ebx
        return

.errorload:
        push    eax
        invoke  DestroyWindow, ebx
        pop     eax
        pop     esi ebx
        return
endp