我正在尝试使用IupTabs和IupScintilla创建一个带有IUP的简单文本编辑器。然而,在Linux上运行时,我遇到了一种奇怪的关闭选项卡的行为,我似乎无法解决。
当存在多个选项卡时,第一个选项卡将被删除(使用SHOWCLOSE按钮或通过我的回调close_cb ),剩下的单个选项卡将为空。我已经尝试了IupUpdate、IupRedraw、IupRefresh和IupRedraw的所有组合,但似乎没有什么能强制正确绘制选项卡。
我甚至深入到IUP源代码中,并在iupgtk_tabs.c (第307行)中定位了gtkTabsCloseButtonClicked函数,以验证下面的代码是否删除了选项卡,以便我的回调close_cb至少执行相同的操作。
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有关。
#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
发布于 2015-10-30 15:58:10
那是宫内节育器里的一只虫子。现在已在SVN中修复。从今天开始。
https://stackoverflow.com/questions/33273710
复制相似问题