asking for Pt_SELECTION_MODE in Pt_ARG_RAWLIST_SELECT_F

Hi,
Is it valid to get this flags in this callback?

I tried this, but I get a strange value:

void cb_RawList_users_select(PtWidget_t *widget, PtGenListItem_t * item,
int pos, int column, int nitems, int subtype, PhEvent_t *event){
int n = 0;
unsigned short *sel_flags_p;
user_list_t *user_p = (user_list_t *)item;

PtGetResource(widget, Pt_ARG_SELECTION_MODE, &sel_flags_p, 0);

if (*sel_flags_p & Pt_SELECTION_MODE_RANGE) {


}
}

Alain Bonnefoy <alain.bonnefoy@icbt.com> wrote:

Is it valid to get this flags in this callback?

Yes, but the value of this resource is not exactly flags. It preserves
the last value you set it to, but how that value is interpreted is a bit
complicated. You have read the docs, haven’t you?

If you care about the details, the value is divided into bit fields like
this:

C0ff ffff ffMM SSSS

C is the “compose flag”. If it’s unset, the ff’s and the MM are
zero, and the SSSS is non-zero and it matches one of the Photon
1.0-style “predefined” modes (Pt_xxx_MODE).

If C is set, SSSS is zero, the MM matches one of the “new” style
modes and the ffff’s are flags. Both the mode and the flags use the
Pt_SELECTION_MODE_xxxx naming convention, but there’s a catch: the
macros always have the C flag ORed in them. Therefore, your

if (*sel_flags_p & Pt_SELECTION_MODE_RANGE) …

returns true whenever the C flag is set and false when it’s not.


Instead of trying to parse this value yourself and to turn the SSSS
mode into the ffMM mode, you can take the pre-parsed value from the
widget. The MM is stored in list->sel_xmode and the ff’s are in
list->sel_flags. But you need to use some macros to mask out the C bit
and shift the bits down. In short, here’s the correct way of doing it:

if ( list->sel_xmode == Pt_SELECTION_MODE(Pt_SELECTION_MODE_xxxx) )
// xxxx stands for MULTIPLE, RANGE, SINGLE, or NONE

if ( list->sel_flags & Pt_SELECTION_FLAGS(Pt_SELECTION_MODE_yyyy) )
// yyyy is NOSCROLL, NOMOVE, NOREST, AUTO, NOCLEAR, TOGGLE, or NOFOCUS

\

Wojtek Lerch QNX Software Systems Ltd.

Hi Wojtek,

I’ve RE-read the PtGenList doc and I didn’t find these subtleties so
obvious!!
In particular, There is no mention about Pt_SELECTION_MODE and
Pt_SELECTION_FLAGS. I made a search about these macros and we can
effectively find these in ‘Creating a List Widget’ chapter which belongs
to ‘Building a Custom Widget’.

I think it should be necessary to find more explanation about this point
in the GenList documentation.
Maybe talking about these ‘details’ would draw our attention to not
consider these modes as simple flags.

Thanks a lot,
Alain

Wojtek Lerch a écrit:

Alain Bonnefoy <> alain.bonnefoy@icbt.com> > wrote:


Is it valid to get this flags in this callback?



Yes, but the value of this resource is not exactly flags. It preserves
the last value you set it to, but how that value is interpreted is a bit
complicated. You have read the docs, haven’t you?

If you care about the details, the value is divided into bit fields like
this:

C0ff ffff ffMM SSSS

C is the “compose flag”. If it’s unset, the ff’s and the MM are
zero, and the SSSS is non-zero and it matches one of the Photon
1.0-style “predefined” modes (Pt_xxx_MODE).

If C is set, SSSS is zero, the MM matches one of the “new” style
modes and the ffff’s are flags. Both the mode and the flags use the
Pt_SELECTION_MODE_xxxx naming convention, but there’s a catch: the
macros always have the C flag ORed in them. Therefore, your

if (*sel_flags_p & Pt_SELECTION_MODE_RANGE) …

returns true whenever the C flag is set and false when it’s not.


Instead of trying to parse this value yourself and to turn the SSSS
mode into the ffMM mode, you can take the pre-parsed value from the
widget. The MM is stored in list->sel_xmode and the ff’s are in
list->sel_flags. But you need to use some macros to mask out the C bit
and shift the bits down. In short, here’s the correct way of doing it:

if ( list->sel_xmode == Pt_SELECTION_MODE(Pt_SELECTION_MODE_xxxx) )
// xxxx stands for MULTIPLE, RANGE, SINGLE, or NONE

if ( list->sel_flags & Pt_SELECTION_FLAGS(Pt_SELECTION_MODE_yyyy) )
// yyyy is NOSCROLL, NOMOVE, NOREST, AUTO, NOCLEAR, TOGGLE, or NOFOCUS
\

Alain Bonnefoy wrote:

I’ve RE-read the PtGenList doc and I didn’t find these subtleties so
obvious!!

If they were, I would have just pointed at the docs instead of
explaining them here! :wink:

Most of the time, all you need is to know is how to set the mode to make
the widget behave the way you want. This is the first time I know of
that someone tries to read the value back and analyze it and guess how
the widget was meant to behave. The docs don’t concentrate on this kind
of subtleties of the selection mode because, well, I guess we didn’t
think anybody would need this.

In particular, There is no mention about Pt_SELECTION_MODE and
Pt_SELECTION_FLAGS. I made a search about these macros and we can
effectively find these in ‘Creating a List Widget’ chapter which belongs
to ‘Building a Custom Widget’.

Yes. All the PtRaw… widgets are basically a way to let you use the
functionality described in the Widget Building doc without actually
writing a new widget class. Perhaps their docs pages should make that
clearer.

I think it should be necessary to find more explanation about this point
in the GenList documentation.
Maybe talking about these ‘details’ would draw our attention to not
consider these modes as simple flags.

Well, Pt_ARG_SELECTION mode is documented as a scalar resource, not as
flags. And the docs do mention that you can’t set it to zero or mix the
two different kinds of modes. What else do you think we should mention?..

Wojtek Lerch a écrit:

Alain Bonnefoy wrote:

I’ve RE-read the PtGenList doc and I didn’t find these subtleties so
obvious!!


If they were, I would have just pointed at the docs instead of
explaining them here! > :wink:

Most of the time, all you need is to know is how to set the mode to
make the widget behave the way you want. This is the first time I
know of that someone tries to read the value back and analyze it and
guess how the widget was meant to behave. The docs don’t concentrate
on this kind of subtleties of the selection mode because, well, I
guess we didn’t think anybody would need this.

hum, maybe!

In particular, There is no mention about Pt_SELECTION_MODE and
Pt_SELECTION_FLAGS. I made a search about these macros and we can
effectively find these in ‘Creating a List Widget’ chapter which
belongs to ‘Building a Custom Widget’.


Yes. All the PtRaw… widgets are basically a way to let you use the
functionality described in the Widget Building doc without actually
writing a new widget class. Perhaps their docs pages should make that
clearer.

I think it should be necessary to find more explanation about this
point in the GenList documentation.
Maybe talking about these ‘details’ would draw our attention to not
consider these modes as simple flags.


Well, Pt_ARG_SELECTION mode is documented as a scalar resource, not as
flags.

Maybe I should to take care of that!

And the docs do mention that you can’t set it to zero or mix the two
different kinds of modes. What else do you think we should mention?..

Thanks a lot,

Alain.