Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
9 user(s) are online (7 user(s) are browsing Forums)

Members: 0
Guests: 9

more...

Support us!

Headlines

 
  Register To Post  

texteditor.gadget and copy/paste
Home away from home
Home away from home


See User information
@all

I'm developing small tools using texteditor.gadget that require copying text to the clipboard and pasting from it.
Instead of clipboard.device, I'm using textclip.library, which works well for both copying to and retrieving from the clipboard.
However, I'm facing issues with texteditor.gadget. Here are the details:

1. Unmarking Text and Setting Cursor After Copy

After copying text to the clipboard, I want the selection to unmark and the cursor to move to the start of the previously marked text. My current approach, executed after ITextClip->WriteClipVector, is:

// Set cursor to selection start
IIntuition->SetGadgetAttrs((struct Gadget *)textEditorwindowNULL,
    
GA_TEXTEDITOR_CursorXstartx,
    
GA_TEXTEDITOR_CursorYstarty,
    
TAG_DONE);

// Activate the text editor
if (IIntuition->ActivateGadget((struct Gadget *)textEditorwindowNULL)) {
    
IDOS->Printf("Text editor activated successfully\n");
} else {
    
IDOS->Printf("Failed to activate text editor\n");
}

// Verify cursor position
ULONG newCursorX 0newCursorY 0;
IIntuition->GetAttr(GA_TEXTEDITOR_CursorXtextEditor, &newCursorX);
IIntuition->GetAttr(GA_TEXTEDITOR_CursorYtextEditor, &newCursorY);
IDOS->Printf("Cursor set to position (%lu, %lu), selection should be cleared\n"newCursorXnewCursorY);

// Refresh to clear selection visually
IIntuition->RefreshGadgets((struct Gadget *)textEditorwindowNULL);
} else {
    
IDOS->Printf("Failed to write to clipboard\n");
}



This works, but is there a simpler way to instruct texteditor.gadget to unmark and reposition the cursor?

2. Pasting from Clipboard

I'm stuck when pasting text from the clipboard into the texteditor window. I successfully read the clipboard buffer, but pasting fails. My code is:

IDOS->Printf("Pasting text: '%s', length: %lu\n"clipTexttextLen);

// Ensure window and gadget are active
IIntuition->ActivateWindow(window);
if (!
IIntuition->ActivateGadget((struct Gadget *)textEditorwindowNULL)) {
    
IDOS->Printf("Failed to activate text editor before paste\n");
    
ITextClip->DisposeClipVector(clipText);
    return;
}

// Attempt to insert text at cursor
struct GP_TEXTEDITOR_InsertText insertMsg = {
    .
MethodID GM_TEXTEDITOR_InsertText,
    .
GInfo NULL// GadgetInfo can be NULL
    
.text clipText,
    .
pos GV_TEXTEDITOR_InsertText_Cursor
};

if (
IIntuition->IDoMethodA(textEditor, (Msg)&insertMsg)) {
    
IDOS->Printf("Successfully pasted %lu bytes into text editor\n"textLen);

    
// Activate and refresh
    
if (IIntuition->ActivateGadget((struct Gadget *)textEditorwindowNULL)) {
        
IDOS->Printf("Text editor activated successfully after paste\n");
    } else {
        
IDOS->Printf("Failed to activate text editor after paste\n");
    }
    
IIntuition->RefreshGadgets((struct Gadget *)textEditorwindowNULL);
    
IIntuition->RefreshWindowFrame(window);
} else {
    
IDOS->Printf("Failed to paste text into text editor: possible error in context or method\n");
}

ITextClip->DisposeClipVector(clipText);


I consistently get "Failed to paste text..." with IDoMethodA. Switching to DoGadgetMethodA yields the same error, though the text appears visually. Any suggestions?

3. Reading Selected Text for Clipboard

Reading selected text to copy to the clipboard works, but the process feels cumbersome. My current logic is:

Get selection coordinates via GM_TEXTEDITOR_BlockInfo (startx, starty, stopx, stopy).
Export full text with GM_TEXTEDITOR_ExportText.
Split text into lines by counting \n and replacing with \0.
Calculate indices, adjust order if needed.
Compute length, allocate a buffer, copy the selected portion, and add \n between lines.
Copy to clipboard.
Is there a more efficient method?

Any help would be greatly appreciated. Thanks!

Join us to improve dopus5!
AmigaOS4 on youtube
Go to top

  Register To Post

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project