amiga-mui / texteditor

A well-known and used MUI custom class (TextEditor.mcc) which provides application programmers a textedit gadget. It supports features like word wrapping, soft styles (bold, italic, underline), a spell checking interface as well as an AREXX interface for scripting.
GNU Lesser General Public License v2.1
19 stars 4 forks source link

MUIV_TextEditor_WrapMode_SoftWrap seems to be the default #27

Closed afalkenhahn closed 4 years ago

afalkenhahn commented 4 years ago

The autodocs say that MUIV_TextEditor_WrapMode_HardWrap is the default but that contradicts my tests. When I don't specify MUIA_TextEditor_WrapMode I always seem to get soft wrapping. Is this a documentation error or a bug?

tboeckel commented 4 years ago

HardWrap is definitely the default value. See here: https://github.com/amiga-mui/texteditor/blob/a8c6b2af2c4f4fe0c3e0214426bb60367fb24597/mcc/Dispatcher.c#L179

I'll have to check whether specifying or omitting MUIA_TextEditor_WrapMode during OM_NEW makes any difference or not.

tboeckel commented 4 years ago

Well, according to a quick test data->WrapMode stays MUIV_TextEditor_WrapMode_HardWrap all the time when it is not explicitly defined at OM_NEW time, at least the value is correct. And hence I assume the behaviour also corresponds to that value. Have you tried OM_GET'ing it already when you think it has the wrong value?

tboeckel commented 4 years ago

Any comment on this issue?

afalkenhahn commented 4 years ago

Seems I forgot about this. Try the attached example. Enter enough words to make TextEditor wrap the line. Then hit the button. You'll see that no newline characters have been inserted. In other words: Softwrapping has been used.

#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>

#include <exec/exec.h>
#include <exec/types.h>

#include <intuition/intuition.h>

#include <libraries/mui.h>

#include <mui/TextEditor_mcc.h>

#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/muimaster.h>
#include <proto/utility.h>

struct Library *MUIMasterBase = NULL;
struct MUIMasterIFace *IMUIMaster = NULL;

struct Library *IntuitionBase = NULL;
struct IntuitionIFace *IIntuition = NULL;

int main(int argc, char *argv[])
{
    Object *win, *app, *bt, *str;
    ULONG sigs = 0;
    ULONG id;
    int flag = 0;
    Object *subwin, *parent, *reg;

    IntuitionBase = (struct Library *) OpenLibrary("intuition.library", 0);
    IIntuition = (struct IntuitionIFace *) GetInterface(IntuitionBase, "main", 1, NULL);

    MUIMasterBase = OpenLibrary("muimaster.library", 0);
    IMUIMaster = (struct MUIMasterIFace *) GetInterface(MUIMasterBase, "main", 1, NULL);

    app = ApplicationObject,
        MUIA_Application_Title, "Foo",
        MUIA_Application_Base, "xxxxx",

        SubWindow, win = WindowObject,
            MUIA_Window_Title, "Bar",

            WindowContents, VGroup,

                Child, VGroup,

                    Child, str = TextEditorObject,
                        MUIA_TextEditor_Contents, "x",
                    End,

                    Child, VGroup,
                        Child, bt = SimpleButton("Click me"),
                    End,
                End,
            End,
        End,
    End;

    DoMethod(win, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);
    DoMethod(bt, MUIM_Notify, MUIA_Pressed, FALSE, app, 2, MUIM_Application_ReturnID, 1001);

    set(win, MUIA_Window_Open, TRUE);

    while((id = DoMethod(app,MUIM_Application_NewInput,&sigs)) != MUIV_Application_ReturnID_Quit) {

        if(id == 1001) {

            STRPTR s = DoMethod(str, MUIM_TextEditor_ExportText);

            printf("HMM: %s\n", s);
            FreeVec(s);
        }

        if(sigs) {
            sigs = Wait(sigs | SIGBREAKF_CTRL_C);
            if (sigs & SIGBREAKF_CTRL_C) break;
        }
    }

    MUI_DisposeObject(app);

    if(IIntuition) DropInterface((struct Interface *) IIntuition);
    if(IMUIMaster) DropInterface((struct Interface *) IMUIMaster);

    if(MUIMasterBase) CloseLibrary(MUIMasterBase);
    if(IntuitionBase) CloseLibrary(IntuitionBase);

    return 0;
} 
tboeckel commented 4 years ago

Ah, yes, now I get it!

It seems you did not read the documentation carefully enough. It is clearly stated that MUIV_TextEditor_WrapMode_HardWrap requires MUIA_TextEditor_WrapBorder to be set to a non-zero value to work. However, the default value of MUIA_TextEditor_WrapBorder is zero and hence effectively disables hard wrapping. As soon as MUIA_TextEditor_WrapBorder ist set to i.e. 20 you will get the desired result.