Szabolcs
Szabolcs

Reputation: 25703

Controlling the size of an embedded Vim window (in plugin mode)

I am trying to embed a GVim window inside a Qt application on Windows by getting the winId of a QWidget and passing it to Vim using --windowid.

I have two problems:

  1. The actual Vim window can only have certain sizes (because it has an integer number of columns and rows), so it will be smaller than the QWidget that embeds it. How can I get the allowed (font-dependent) sizes so I can size the QWidget accordingly?

  2. The resize grip of Vim is still active, and resizes Vim inside the QWidget, of course without changing the size of the QWidget. How can I prevent this and disable the Vim resize grip?

EDIT: I am trying to bundle a Vim window together with a PDF viewer to be used as a LaTeX previewer

Upvotes: 0

Views: 357

Answers (1)

Piotr Borys
Piotr Borys

Reputation: 51

To embed your external application first remove the styles from the window, and only after that reparent it:

void CWinSystemTools::reparentWindow(HWND hWindow, QWidget *widget)
    {
    if (hWindow == 0)
        return;
    DWORD style = GetWindowLong(hWindow, GWL_STYLE);
    style = style & ~(WS_POPUP);
    style = style & ~(WS_OVERLAPPEDWINDOW);
    style = style | WS_CHILD;
    SetWindowLong(hWindow, GWL_STYLE, style);

    SetParent(hWindow, widget->winId());
    }

Now, to maintain the resizing correctly, implement the resize event:

void TrVisApp::resizeEvent(QResizeEvent *event)
    {
    resizeClients();
    }

and further:

void TrVisApp::resizeClients()
    {
    if (hWndGvim != 0)
        CWinSystemTools::resizeWindowToWidget(hWndGvim, ui.wdgGvim->geometry());
    }

where:

void CWinSystemTools::resizeWindowToWidget(HWND hWnd, QRect geometry, bool moveToTopLeftCorner = true)
    {
    int x = geometry.left();
    int y = geometry.top();
    if (moveToTopLeftCorner)
        {
        x = 0;
        y = 0;
        }
    int width = geometry.width();
    int height = geometry.height();
    SetWindowPos(hWnd, HWND_TOP, x, y, width, height, SWP_NOACTIVATE);
    }

Works nicely for me :)

Upvotes: 1

Related Questions