Alain Bonnefoy <email@example.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
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.