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

Cannot get() MUIA_TextEditor_RedoAvailable from call hook #25

Closed afalkenhahn closed 5 years ago

afalkenhahn commented 5 years ago

Trying to get() MUIA_TextEditor_RedoAvailable doesn't work from a call hook. Here's how to reproduce it:

  1. Enter a char
  2. Click the button to undo the operation
  3. Note the debug output: AppMsgFunc2 correctly receives 1 in the x argument because redo is now available. However, when querying MUIA_TextEditor_RedoAvailable using get() at the same time, y still receives 0 but it should be 1 now.

Here is the demo code:

#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 IntuitionBase *IntuitionBase = NULL;

#define REG(x) register __ ## x
#define ASM    __asm
#define SAVEDS __saveds

SAVEDS ASM LONG AppMsgFunc(REG(a2) APTR obj, REG(a1) int *x)
{
    int y = -1;

    get(obj, MUIA_TextEditor_UndoAvailable, &y);

    printf("Undo available: %d %d\n", *x, y);

    return(0);
}

SAVEDS ASM LONG AppMsgFunc2(REG(a2) APTR obj, REG(a1) int *x)
{
    int y = -1;

    get(obj, MUIA_TextEditor_RedoAvailable, &y);

    printf("Redo available: %d %d\n", *x, y);

    return(0);
}

int main(int argc, char *argv[])
{
    Object *win, *app, *bt, *editor;
    ULONG sigs = 0;
    ULONG id;
    int flag = 0;
    Object *subwin, *parent, *reg;
    static const struct Hook AppMsgHook = { { NULL,NULL },(VOID *)AppMsgFunc,NULL,NULL };   
    static const struct Hook AppMsgHook2 = { { NULL,NULL },(VOID *)AppMsgFunc2,NULL,NULL }; 

    IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0);
    MUIMasterBase = OpenLibrary("muimaster.library", 0);

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

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

            WindowContents, VGroup,

                Child, VGroup,

                    Child, editor = TextEditorObject,
                        MUIA_CycleChain, 1,
                    End,                
                    Child, bt = SimpleButton("Click"),
                End,
            End,
        End,
    End;

    DoMethod(bt,MUIM_Notify,MUIA_Pressed,FALSE,app,2,MUIM_Application_ReturnID,1000);
    DoMethod(editor, MUIM_Notify, MUIA_TextEditor_UndoAvailable, MUIV_EveryTime, editor, 3, MUIM_CallHook,&AppMsgHook,MUIV_TriggerValue);
    DoMethod(editor, MUIM_Notify, MUIA_TextEditor_RedoAvailable, MUIV_EveryTime, editor, 3, MUIM_CallHook,&AppMsgHook2,MUIV_TriggerValue);  
    DoMethod(win, MUIM_Notify, MUIA_Window_CloseRequest, TRUE, app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);

    set(win, MUIA_Window_Open, TRUE);

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

        switch(id) {
        case 1000:
            DoMethod(editor, MUIM_TextEditor_ARexxCmd, "UNDO");             
            break;
        }

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

    MUI_DisposeObject(app);

    if(MUIMasterBase) CloseLibrary(MUIMasterBase);
    if(IntuitionBase) CloseLibrary((struct Library *) IntuitionBase);

    return 0;
}
afalkenhahn commented 5 years ago

Btw, as you can see, MUIA_TextEditor_UndoAvailable behaves correctly. It's only MUIA_TextEditor_RedoAvailable that doesn't work correctly.

tboeckel commented 5 years ago

This version should fix the issue. MCC_TextEditor-15.53.zip