Topic: accessing private members in motif callback
Author: jeff@cee.hw.ac.uk (Jeffrey Morgan)
Date: Thu, 8 Dec 1994 14:02:04 GMT Raw View
Dear All,
Does anyone know how to use a private member function (C++) as a callback
for a Motif (C) Widget?
I have the class ArticleViewer with a scrolled list widget. At the momment
I have the following :-
XtAddCallback(
the_articles_scrolled_list,
XmNdefaultActionCallback,
(XtCallbackProc) articles_scrolled_list_callback,
(XtPointer) this);
with the corresponding function definition :-
static
void
articles_scrolled_list_callback(Widget scrolled_list,
XtPointer client_data,
XmListCallbackStruct *cbs)
The (XtPointer) this in the callback allows me to access the object of which
the scrolled list is part. However, I cannot get access to the private
data/members in that object (if you know how - let me know) so I have to
have access members returning the values of the private data members e.g.
Article get_article();
just so I can access the internals of the object in a callback that is
conceptually part of the object.
What I would prefer to do would be to use a private memeber function as the
callback function e.g.
void
ArticleViewer::articles_scrolled_list_callback(Widget scrolled_list,
XtPointer client_data,
XmListCallbackStruct *cbs)
to give me access to the private members. Any ideas?
Please answer in the group or preferably via email:-
jeff@cee.hw.ac.uk
Thanks.
Author: mojemj@unidhp.uni-c.dk (Mogens Jensen)
Date: 9 Dec 1994 01:48:49 GMT Raw View
Jeffrey Morgan (jeff@cee.hw.ac.uk) wrote:
: Dear All,
: Does anyone know how to use a private member function (C++) as a callback
: for a Motif (C) Widget?
: static
: void
: articles_scrolled_list_callback(Widget scrolled_list,
: XtPointer client_data,
: XmListCallbackStruct *cbs)
: The (XtPointer) this in the callback allows me to access the object of which
: the scrolled list is part. However, I cannot get access to the private
: data/members in that object (if you know how - let me know)
: What I would prefer to do would be to use a private memeber function as the
: callback function e.g.
: void
: ArticleViewer::articles_scrolled_list_callback(Widget scrolled_list,
: XtPointer client_data,
: XmListCallbackStruct *cbs)
: to give me access to the private members. Any ideas?
What about merging the two:
class ArticleViewer : ... {
static void articles_scrolled_list_callback( Widget, XtPointer,
XmListCallbackStruct* );
public:
...
};
void
ArticleViewer::articles_scrolled_list_callback( Widget list, XtPointer data,
XmListCallbackStruct *myThis )
{
ArticleViewer &that = *(ArticleViewer*)myThis;
...
float that.foo = that.fooBar();
...
}
I think that will do it ... ?
: Thanks.
I hope it works...
Greetings from Jens Jakob Jensen, Denmark (using my fathers account)
Author: saroj@sunny.sbi.com (Saroj Mahapatra)
Date: Fri, 9 Dec 1994 14:22:49 GMT Raw View
In article 7Io@cee.hw.ac.uk, jeff@cee.hw.ac.uk (Jeffrey Morgan) writes:
>
> Dear All,
>
> Does anyone know how to use a private member function (C++) as a callback
> for a Motif (C) Widget?
>
> I have the class ArticleViewer with a scrolled list widget. At the momment
> I have the following :-
>
> XtAddCallback(
> the_articles_scrolled_list,
> XmNdefaultActionCallback,
> (XtCallbackProc) articles_scrolled_list_callback,
> (XtPointer) this);
>
> with the corresponding function definition :-
>
> static
> void
> articles_scrolled_list_callback(Widget scrolled_list,
> XtPointer client_data,
> XmListCallbackStruct *cbs)
>
>
> The (XtPointer) this in the callback allows me to access the object of which
> the scrolled list is part. However, I cannot get access to the private
> data/members in that object (if you know how - let me know) so I have to
> have access members returning the values of the private data members e.g.
>
> Article get_article();
>
> just so I can access the internals of the object in a callback that is
> conceptually part of the object.
>
> What I would prefer to do would be to use a private memeber function as the
> callback function e.g.
>
> void
> ArticleViewer::articles_scrolled_list_callback(Widget scrolled_list,
> XtPointer client_data,
> XmListCallbackStruct *cbs)
>
> to give me access to the private members. Any ideas?
>
> Please answer in the group or preferably via email:-
>
> jeff@cee.hw.ac.uk
>
> Thanks.
>
Declare it as a static function in the class:
class ArticleViewer {
static void articles_scrolled_list (Widget, XtPointer, XmListCallbackStruct*);
};
void ArticleViewer::articles_scrolled_list (...)
{
...
}
You have to cast it to XtCallbackProc in XtAddCallback.
- Saroj