From -2422041024558655816
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f78e5,800e73b29c3c5cd1
X-Google-Attributes: gidf78e5,public
X-Google-ArrivalTime: 1994-12-09 09:49:09 PST
Newsgroups: comp.std.c++
Path: bga.com!news.sprintlink.net!pipex!uunet!psinntp!internet!meteor!sunny!saroj
From: saroj@sunny.sbi.com (Saroj Mahapatra)
Subject: Re: accessing private members in motif callback
Message-ID: <D0Jry1.8AM@meteor.sbi.com>
Sender: news@meteor.sbi.com
Reply-To: saroj@sunny.sbi.com
Organization: Salomon Brothers Inc
References: <D0HwBH.7Io@cee.hw.ac.uk>
Date: Fri, 9 Dec 1994 14:22:49 GMT
Lines: 71

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




