0

I'm having some trouble with my selection listener, currently I have independently trialed selection of text from TOP to BOTTOM, and BOTTOM to TOP (Mouse movement), however these trials won't work together i.e. the one SelectionListener is bidirectional...

private void setupSelectionListener() {

    this.contentValues.addSelectionListener(new SelectionListener() {

        @Override
        public void widgetSelected(SelectionEvent event) {

            StyledText text = (StyledText)event.widget;

            int x = event.x;
            int y = event.y;

            //Mouse Drag Listener here??? - Detects Right

                //FOR TOP TO BOTTOM SELECTION
                text.setSelection(event.x); 

                int beginPosition = event.x; 
                int beginByte = beginPosition / 3;

                int endPosition = event.y; 
                int endByte = endPosition / 3;

                setSelection(beginByte, endByte);

            //Mouse Drag Listener here??? - Detects Left

                //FOR BOTTOM TO TOP SELECTION
                text.setSelection(event.y);

                int beginPosition = event.y;
                int beginByte = beginPosition / 3;

                int endPosition = event.x;
                int endByte = endPosition / 3;

                setSelection(beginByte, endByte);               

        }

        @Override
        public void widgetDefaultSelected(SelectionEvent e) {
            // Does nothing...
        }
    });     

So either I need a Mouse Drag Listener like I have stated in the comments, or a conditional statement comparing the event.x and event.y

I have attempted at adding a drag detection listener inside the selection listener, but this disrupts the format of the event coordinate selection.

Any help would be greatly appreciated.

1 Answers1

0

If the source widget on which event happend is Styled Text object then this selection will happen automatically without any listener correct, means if you drag with mouse holding, the contents will automatically selected.

Syam
  • 1,202
  • 11
  • 23