0

我正在尝试使用IupTabsIupScintilla创建一个带有 IUP 的简单文本编辑器。但是,在 Linux 上运行时,我遇到了一种我似乎无法解决的奇怪的制表符关闭行为。

当存在多个选项卡时,第一个选项卡被删除(使用SHOWCLOSE按钮或通过我的回调close_cb,剩下的单个选项卡留空。我尝试了IupUpdateIupRedrawIupRefreshIupRefreshChildren的所有组合,似乎没有什么可以强制选项卡正确绘制。

我什至深入研究 IUP 源并在iupgtk_tabs.cgtkTabsCloseButtonClicked (第 307 行)中找到该函数,以验证是否使用以下代码删除了选项卡,以便我的回调至少执行相同的操作。close_cb

if (ret == IUP_CONTINUE) /* destroy tab and children */
{
  IupDestroy(child);
  IupRefreshChildren(ih);
}

我已将问题提炼为下面的示例代码。我在 Lubuntu 12.04 x86-64 上运行它。IUP 版本是iup-3.16_Linux32_64_lib,从 Sourceforge 下载。该问题仅发生在 GTK 而不是 Windows 上。我不确定这是一个错误还是我只是做错了什么。如果它是一个错误,我不确定它是否与 GTK 或 IUP 有关。

#include <iup.h>
#include <iup_scintilla.h>
#include <stdlib.h>

int new_cb( Ihandle* self )
{
    // create a new Scintilla control
    Ihandle* sci = IupScintilla();
    IupSetAttributes( sci, "TABSIZE=4, EXPAND=YES, VISIBLE=YES, "
        "TABTITLE=Untitled, TABIMAGE=IUP_FileSave" );

    // add the Scintilla to the tabs
    Ihandle* tabs = IupGetHandle( "tabs" );
    IupAppend( tabs, sci );
    IupMap( sci );
    IupSetAttributeHandle( tabs, "VALUE", sci );
    IupSetFocus( sci );
    IupRefresh( tabs );

    return IUP_IGNORE;
}

int close_cb( Ihandle* self )
{
    Ihandle* tabs = IupGetHandle( "tabs" );

    int old_count = IupGetChildCount( tabs );
    if ( old_count == 0 ) return IUP_IGNORE;

    // remove the current tab
    Ihandle* old_tab = IupGetAttributeHandle( tabs, "VALUE" );

    // see iupgtk_tabs.c:307
    IupDestroy( old_tab );
    IupRefreshChildren( tabs );

    int new_count = IupGetChildCount( tabs );
    if ( new_count == 0 ) return IUP_IGNORE;

    // set focus to the new tab
    Ihandle* new_tab = IupGetAttributeHandle( tabs, "VALUE" );
    IupSetFocus( new_tab );

    return IUP_IGNORE;
}

int tabchange_cb( Ihandle* self, Ihandle* old_tab, Ihandle* new_tab )
{
    // set focus to the new tab
    IupSetFocus( new_tab );
    return IUP_CONTINUE;
}

int tabclose_cb( Ihandle* self, int pos )
{
    // allow the old tab to be removed
    return IUP_CONTINUE;
}

int main( int argc, char** argv )
{
    IupOpen( &argc, &argv );
    IupScintillaOpen();
    IupImageLibOpen();

    Ihandle* tabs = IupTabs( NULL );
    IupSetAttribute( tabs, "SHOWCLOSE", "YES" );
    IupSetCallback( tabs, "TABCHANGE_CB", (Icallback)tabchange_cb );
    IupSetCallback( tabs, "TABCLOSE_CB", (Icallback)tabclose_cb );
    IupSetHandle( "tabs", tabs );

    Ihandle* dialog = IupDialog( tabs );
    IupSetAttribute( dialog, "SIZE", "HALFxHALF" );
    IupSetAttribute( dialog, "TITLE", "Tabs Demo" );
    IupSetHandle( "dialog", dialog );

    // Ctrl+N opens a new tab    
    IupSetCallback( dialog, "K_cN", (Icallback)new_cb );

    // Ctrl+W closes the current tab
    IupSetCallback( dialog, "K_cW", (Icallback)close_cb );

    IupShowXY( dialog, IUP_CENTER, IUP_CENTER );

    // add a new tab by default
    new_cb( NULL );

    IupMainLoop();

    IupClose();

    return EXIT_SUCCESS;
}

截图:tabsdemo.png

4

1 回答 1

1

那是 IUP 中的一个错误。它现在已在 SVN 中修复。从今天起。

于 2015-10-30T15:58:10.207 回答