首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >IUP奇怪标签关闭行为

IUP奇怪标签关闭行为
EN

Stack Overflow用户
提问于 2015-10-22 05:01:37
回答 1查看 97关注 0票数 0

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

当存在多个选项卡时,第一个选项卡将被删除(使用SHOWCLOSE按钮或通过我的回调close_cb ),剩下的单个选项卡将为空。我已经尝试了IupUpdateIupRedrawIupRefresh和IupRedraw的所有组合,但似乎没有什么能强制正确绘制选项卡。

我甚至深入到IUP源代码中,并在iupgtk_tabs.c (第307行)中定位了gtkTabsCloseButtonClicked函数,以验证下面的代码是否删除了选项卡,以便我的回调close_cb至少执行相同的操作。

代码语言:javascript
复制
if (ret == IUP_CONTINUE) /* destroy tab and children */
{
  IupDestroy(child);
  IupRefreshChildren(ih);
}

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

代码语言:javascript
复制
#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

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-10-30 15:58:10

那是宫内节育器里的一只虫子。现在已在SVN中修复。从今天开始。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/33273710

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档