IUP奇怪的标签关闭行为

时间:2015-10-22 05:01:38

标签: iup

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

如果存在多个标签,并且 first 已删除(使用SHOWCLOSE按钮或通过我的回调close_cb,则单个剩余标签将留空。我已经尝试了 IupUpdate IupRedraw IupRefresh IupRefreshChildren 的所有组合,似乎没有任何东西强制使用标签正确绘制。

我甚至潜入IUP源并将gtkTabsCloseButtonClicked函数放在 iupgtk_tabs.c (第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上。我不确定这是一个错误还是我做错了什么。如果是bug,我不确定它是否与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

1 个答案:

答案 0 :(得分:0)

这是IUP中的一个错误。它现在在SVN中修复。从今天开始。