Skip to content

Copy/Paste not working in inputBox input line #178

@unxed

Description

@unxed

You have to create statusbar "listening" for Ctrl/Shift+Ins/Del to generate cmCopy, cmPaste, cmCut commands.

Expected behavior: clipboard manipulations work in inputBox out of the box without processing key combinations manually.

Example below, see !!! comment

#define Uses_TApplication
#define Uses_TEvent
#define Uses_TRect
#define Uses_TDialog
#define Uses_TStaticText
#define Uses_TButton
#define Uses_TMenuBar
#define Uses_TSubMenu
#define Uses_TMenuItem
#define Uses_TStatusLine
#define Uses_TStatusItem
#define Uses_TStatusDef
#define Uses_TDeskTop
#define Uses_TKeys
#define Uses_MsgBox

#include <tvision/tv.h>
#include <string>

const int cmCallInputBox = 100;
const int cmMyAppQuit    = cmQuit;

class TInputBoxApp : public TApplication {
public:
    TInputBoxApp();

    static TMenuBar *initMenuBar(TRect r);
    static TStatusLine *initStatusLine(TRect r);


    virtual void handleEvent(TEvent& event);

private:
    void callInputBoxDemo();

};

TInputBoxApp::TInputBoxApp() :
    TProgInit(&TInputBoxApp::initStatusLine,
              &TInputBoxApp::initMenuBar,
              &TApplication::initDeskTop
             )
{
}

TMenuBar* TInputBoxApp::initMenuBar(TRect r) {
    r.b.y = r.a.y + 1;

    TSubMenu& fileMenu =
        *new TSubMenu("~F~ile", kbAltF, hcNoContext);

    fileMenu +
        *new TMenuItem("Call ~I~nputBox", cmCallInputBox, kbF2, hcNoContext, "F2") +
        newLine() +
        *new TMenuItem("E~x~it", cmMyAppQuit, kbAltX, hcNoContext, "Alt-X");

    return new TMenuBar(r, fileMenu );
}

TStatusLine* TInputBoxApp::initStatusLine(TRect r) {
    r.a.y = r.b.y - 1;
    return new TStatusLine(r,
        *new TStatusDef(0, 0xFFFF) +
            *new TStatusItem("~F2~ InputBox", kbF2, cmCallInputBox) +
            *new TStatusItem("~Alt-X~ Exit", kbAltX, cmMyAppQuit)
            /*
            // !!! UNCOMMENT TO ENABLE COPY-PASTE BY KEYBOARD
            +
            *new TStatusItem(nullptr, kbCtrlIns,  cmCopy) +
            *new TStatusItem(nullptr, kbShiftIns, cmPaste) +
            *new TStatusItem(nullptr, kbShiftDel, cmCut)
            */
        );
}

void TInputBoxApp::handleEvent(TEvent& event) {
    TApplication::handleEvent(event);
    if (event.what == evCommand) {
        switch (event.message.command) {
            case cmCallInputBox:
                callInputBoxDemo();
                clearEvent(event);
                break;
        }
    }
}

void TInputBoxApp::callInputBoxDemo() {
    char buffer[251];
    strcpy(buffer, "Default text");

    ushort result = inputBox("Enter Text", "Your input:", buffer, 250);

    if (result == cmOK) {
        std::string displayText = "Last input: ";
        displayText += buffer;
        messageBox(displayText.c_str(), mfInformation | mfOKButton);
    } else {
        messageBox("Input Canceled.", mfInformation | mfOKButton);
    }
}

int main() {
    TInputBoxApp myApp;
    myApp.run();
    return 0;
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions