Re: crash attempting to create tab menu

From: Dom Lachowicz <domlachowicz_at_yahoo.com>
Date: Wed Sep 29 2004 - 06:14:12 CEST

Hi Kevin,

Firstly, thanks for taking a stab at this. It's much
appreciated and pretty much correct.

That said, there are several of things wrong in this
patch, but fortunately they are all easily
correctable.

1) Please use getStringUTF8() for doing translations.
Do not use an encoding returned by
getDefaultEncoding(). GTK and Pango will hate you for
it.

2) You don't seem to set the widget's "user_data" but
you expect a AP_UnixTopRuler to live there. So in this
callback function:

AP_UnixTopRuler * pUnixTopRuler =
static_cast<AP_UnixTopRuler *>(g_object_get_data
(G_OBJECT (w), "user_data"));

pUnixTopRuler will always be NULL.

I'd suggest reworking your callback function a bit so
that the AP_UnixTopRuler was passed in as user_data,
and the tab type was determined somehow else. But
that's just personal preference.

I'd also suggest spending about 10 minutes getting
familiar with GDB or one of its wrappers (DDD, GUD in
Emacs, ...) if you're not already. It would've caught
your problem instantly.

Thanks a lot for your patch.
Dom

--- Kevin Duffus <KevinDuffus@mail.rit.edu> wrote:

---------------------------------
  Hey. I've gotten the tab menu in place according to
uwogspecifications
(http://www.rit.edu/~kod1929/AbiWord/tabMenu.png).There
is just one problem with the callback foractivated
menu items. Abiword crashes and spitsout "Aborted" on
the terminal whenever i try to modifym_iDefaultTabType
:( in ap_UnixTopRuler.*

i have the menu code set up and then a number
corresponding to theclicked menu item is sent to
"setTabStop (int)" in ap_TopRuler.* i'm attempting to
set m_iDefaultTabType like so:m_iDefaultTabType =
static_cast<eTabType>(TabType), where TabType is the
int passed to the function.

AbiWord crashes even if i just call a functionwithin
ap_TopRuler itself, such as _displayStatusMessage ()

Does anyone have any idea why this occurs?
> ---
>
/root/Media/abiword-2.1.6/abi/src/wp/ap/xp/ap_TopRuler.cpp
> 2004-08-18 19:17:53.000000000 -0400
> +++ ./ap_TopRuler.cpp 2004-09-28 21:49:01.770533088
> -0400
> @@ -2035,6 +2035,18 @@
> return 0;
> }
>
> +void AP_TopRuler::setTabStop(int m_iTabType)
> +{
> + //m_iDefaultTabType =
> static_cast<eTabType>(m_iTabType);
> +}
> +
> +// produce old behaviour if showTabMenu is not
> implemented on platform
> +void AP_TopRuler::showTabMenu(void)
> +{
> + currentTabType = --currentTabType <= FL_TAB_NONE ?
> __FL_TAB_MAX-1 : currentTabType;
> + m_iDefaultTabType =
> static_cast<eTabType>(currentTabType);
> +}
> +
> void AP_TopRuler::mousePress(EV_EditModifierState
> /* ems */,
> EV_EditMouseButton emb , UT_uint32 x,
> UT_uint32 y)
> {
> @@ -2093,16 +2105,16 @@
> if ( pView->getViewMode () == VIEW_WEB )
> return ;
>
> - int currentTabType = m_iDefaultTabType;
> + currentTabType = m_iDefaultTabType;
> if(emb == EV_EMB_BUTTON1)
> {
> currentTabType = ++currentTabType >=
> __FL_TAB_MAX ? FL_TAB_NONE+1 : currentTabType;
> + m_iDefaultTabType =
> static_cast<eTabType>(currentTabType);
> }
> - else
> + else if (emb == EV_EMB_BUTTON3)
> {
> - currentTabType = --currentTabType <= FL_TAB_NONE
> ? __FL_TAB_MAX-1 : currentTabType;
> + showTabMenu ();
> }
> - m_iDefaultTabType =
> static_cast<eTabType>(currentTabType);
> _drawTabToggle(NULL, true);
> XAP_String_Id baseTabName =
> AP_STRING_ID_TabToggleLeftTab-1;
> _displayStatusMessage(baseTabName +
> m_iDefaultTabType);
> ---
>
/root/Media/abiword-2.1.6/abi/src/wp/ap/xp/ap_TopRuler.h
> 2004-03-22 19:13:28.000000000 -0500
> +++ ./ap_TopRuler.h 2004-09-28 21:51:04.421887248
> -0400
> @@ -204,6 +204,8 @@
>
> UT_sint32 setTableLineDrag(PT_DocPosition
> pos, UT_sint32 x, UT_sint32 & iFixed);
> void mouseMotion(EV_EditModifierState ems,
> UT_sint32 x, UT_sint32 y);
> + void setTabStop (int);
> + virtual void showTabMenu (void);
> void mousePress(EV_EditModifierState ems,
> EV_EditMouseButton emb, UT_uint32 x, UT_uint32 y);
> void mouseRelease(EV_EditModifierState ems,
> EV_EditMouseButton emb, UT_sint32 x, UT_sint32 y);
>
> @@ -355,6 +357,7 @@
> bool m_bBeforeFirstMotion;
> UT_sint32 m_oldX; /* Only for dragging; used to
> see if object has moved */
>
> + int currentTabType;
> eTabType m_iDefaultTabType;
> UT_sint32 m_draggingCell; // index of
> cell being dragged
> bool m_bGuide; /* true ==> guide line XORed
> onscreen */
> ---
>
/root/Media/abiword-2.1.6/abi/src/wp/ap/unix/ap_UnixTopRuler.h
> 2002-07-27 20:49:40.000000000 -0400
> +++ ../unix/ap_UnixTopRuler.h 2004-09-28
> 21:58:48.751298448 -0400
> @@ -37,11 +37,12 @@
>
> class AP_UnixTopRuler : public AP_TopRuler
> {
> -public:
> +public :
> AP_UnixTopRuler(XAP_Frame * pFrame);
> virtual ~AP_UnixTopRuler(void);
>
> GtkWidget * createWidget(void);
> + virtual void showTabMenu (void);
> virtual void setView(AV_View * pView);
>
> // cheats for the callbacks
> @@ -58,6 +59,7 @@
> class _fe
> {
> public:
> + static void TabStop(GtkWidget * w, gpointer
> TabType);
> static gint button_press_event(GtkWidget * w,
> GdkEventButton * e);
> static gint button_release_event(GtkWidget * w,
> GdkEventButton * e);
> static gint configure_event(GtkWidget* w,
> GdkEventConfigure *e);
> ---
>
/root/Media/abiword-2.1.6/abi/src/wp/ap/unix/ap_UnixTopRuler.cpp
> 2004-03-01 06:45:35.000000000 -0500
> +++ ../unix/ap_UnixTopRuler.cpp 2004-09-28
> 21:54:15.729804024 -0400
> @@ -24,6 +24,7 @@
> #include "ut_debugmsg.h"
> #include "xap_UnixDialogHelper.h"
>
> +#include "ap_Strings.h"
> #include "xap_Frame.h"
> #include "xap_UnixFrameImpl.h"
>
> @@ -153,7 +154,50 @@
> return m_rootWindow;
> }
>
> -
>
+/*****************************************************************/
> +
> +void AP_UnixTopRuler::_fe::TabStop(GtkWidget * w,
> gpointer TabType)
> +{
> + AP_UnixTopRuler * pUnixTopRuler =
> static_cast<AP_UnixTopRuler *>(g_object_get_data
> (G_OBJECT (w), "user_data"));
> + pUnixTopRuler->setTabStop (GPOINTER_TO_INT
> (TabType));
> +}
> +
> +void AP_UnixTopRuler::showTabMenu (void)
> +{
> + GtkWidget *menu = gtk_menu_new ();
> + GtkWidget *menu_item;
> + int TabType = 0;
> +
> + UT_String pzMessageFormat;
> +
>
m_pFrame->getApp()->getStringSet()->getValue(AP_STRING_ID_TabToggleLeftTab,
>
XAP_App::getApp()->getDefaultEncoding(),pzMessageFormat);
> + menu_item = gtk_menu_item_new_with_label
> (pzMessageFormat.c_str ());
> + g_signal_connect (G_OBJECT (menu_item),
> "activate", G_CALLBACK (_fe::TabStop),
> GINT_TO_POINTER (TabType++));
> + gtk_menu_append (GTK_MENU (menu), menu_item);
> +
> +
>
m_pFrame->getApp()->getStringSet()->getValue(AP_STRING_ID_TabToggleCenterTab,
>
XAP_App::getApp()->getDefaultEncoding(),pzMessageFormat);
> + menu_item = gtk_menu_item_new_with_label
> (pzMessageFormat.c_str ());
> + g_signal_connect (G_OBJECT (menu_item),
> "activate", G_CALLBACK (_fe::TabStop),
> GINT_TO_POINTER (TabType++));
> + gtk_menu_append (GTK_MENU (menu), menu_item);
> +
> +
>
m_pFrame->getApp()->getStringSet()->getValue(AP_STRING_ID_TabToggleRightTab,
>
XAP_App::getApp()->getDefaultEncoding(),pzMessageFormat);
> + menu_item = gtk_menu_item_new_with_label
> (pzMessageFormat.c_str ());
> + g_signal_connect (G_OBJECT (menu_item),
> "activate", G_CALLBACK (_fe::TabStop),
> GINT_TO_POINTER (TabType++));
> + gtk_menu_append (GTK_MENU (menu), menu_item);
> +
> +
>
m_pFrame->getApp()->getStringSet()->getValue(AP_STRING_ID_TabToggleDecimalTab,
>
XAP_App::getApp()->getDefaultEncoding(),pzMessageFormat);
> + menu_item = gtk_menu_item_new_with_label
> (pzMessageFormat.c_str ());
> + g_signal_connect (G_OBJECT (menu_item),
> "activate", G_CALLBACK (_fe::TabStop),
> GINT_TO_POINTER (TabType++));
> + gtk_menu_append (GTK_MENU (menu), menu_item);
> +
> +
>
m_pFrame->getApp()->getStringSet()->getValue(AP_STRING_ID_TabToggleBarTab,
>
XAP_App::getApp()->getDefaultEncoding(),pzMessageFormat);
> + menu_item = gtk_menu_item_new_with_label
> (pzMessageFormat.c_str ());
> + g_signal_connect (G_OBJECT (menu_item),
> "activate", G_CALLBACK (_fe::TabStop),
> GINT_TO_POINTER
=== message truncated ===

                
_______________________________
Do you Yahoo!?
Declare Yourself - Register online to vote today!
http://vote.yahoo.com
Received on Wed Sep 29 06:14:40 2004

This archive was generated by hypermail 2.1.8 : Wed Sep 29 2004 - 06:14:40 CEST