Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

single and double click events on a single picture control

mahendraperisetty
Discoverer
0 Kudos

hi everbody,

how can we register both single click and double click events for a single image control?

18 REPLIES 18

raymond_giuseppi
Active Contributor
0 Kudos

You can use same method to handle both events PICTURE_CLICK and PICTURE_DBLCLICK, they bear the same signature.

Regards,

Raymond

0 Kudos

Thank u for the reply,

i think we cannot use same handler method for two different events. if we use like that it is giving an error message that "method 'method name' already exists".

0 Kudos

I was suggesting to create a single method, and two empty methods declared with the FOR EVENT option that call it. But what are you exactly asking for?

Regards,

Raymond

mahendraperisetty
Discoverer
0 Kudos

My actual requirement is that i am having single image on my container when user single clicks

on the image it should do some action and when he double clicks on it then some other action .

in this scenario it is always doing the activity present in the single click event method only,and it is not going for the double click method.

0 Kudos

First try to click faster (or change mouse parameters) so first event (single click) is not triggered before double-click is recorded.

But this may not be possible (as a double-click on a hotspot) so better use some contextual menu to execute a second (or more) method.

Regards,

Raymond

Sandra_Rossi
Active Contributor
0 Kudos

For info, I reproduced the issue on SAPGUI 7.40 SP 5, if we handle click and dblclick, then a doubleclick only triggers click. I couldn't find any SAP note about this issue

DATA picture_control_1 TYPE REF TO cl_gui_picture.
DATA event_tab TYPE cntl_simple_events.
DATA event_tab_line TYPE cntl_simple_event.

PARAMETERS dummy.

CLASS lcl_app DEFINITION.
  PUBLIC SECTION.
    CLASS-METHODS on_picture_click
                  FOR EVENT picture_click OF cl_gui_picture
      IMPORTING mouse_pos_x mouse_pos_y sender.
    CLASS-METHODS on_picture_dblclick
                  FOR EVENT picture_dblclick OF cl_gui_picture
      IMPORTING mouse_pos_x mouse_pos_y sender.
ENDCLASS.

CLASS lcl_app IMPLEMENTATION.
  METHOD on_picture_click .
  ENDMETHOD.
  METHOD on_picture_dblclick.
  ENDMETHOD.
ENDCLASS.

AT SELECTION-SCREEN OUTPUT.
  IF picture_control_1 IS NOT BOUND.
    CREATE OBJECT picture_control_1
      EXPORTING
        parent = cl_gui_container=>screen0.
    CALL METHOD picture_control_1->load_picture_from_sap_icons
      EXPORTING
        icon  = '@08@'
      EXCEPTIONS
        error = 1.

    event_tab_line-eventid = cl_gui_picture=>eventid_picture_click.
    APPEND event_tab_line TO event_tab.

    event_tab_line-eventid = cl_gui_picture=>eventid_picture_dblclick.
    APPEND event_tab_line TO event_tab.

    CALL METHOD picture_control_1->set_registered_events
      EXPORTING
        events = event_tab.

    SET HANDLER lcl_app=>on_picture_click
                FOR picture_control_1.
    SET HANDLER lcl_app=>on_picture_dblclick
                FOR picture_control_1.
  ENDIF.

0 Kudos

Hi.

I tested your example and had another result. If I set a BREAK-POINT within the handler-Methods, I get the same result as Sandra. But I added some lines to the example, so that I don't need a Break-point to see the result. In this case I see, that the DBLCLICK raises both Events, first the CLICK and then the DBLCLICK.

My Changes in the Report:

..

CLASS-DATA gt_text TYPE STANDARD TABLE OF char30.

..

   METHOD on_picture_click .
     APPEND 'CLICK' TO gt_text.
   ENDMETHOD.                    "on_picture_click

   METHOD on_picture_dblclick.
     APPEND 'DBLCLICK' TO gt_text.
   ENDMETHOD.                    "on_picture_dblclick


....


START-OF-SELECTION.

   DATA gv_text TYPE char30.

   LOOP AT lcl_app=>gt_text INTO gv_text.
     WRITE:/ gv_text.
   ENDLOOP.
   cl_gui_container=>screen0->free( ).

Now you have to start the Report, do the DBLCLICK and then Execute the Report with F8.

You will receive 2 Lines:

          CLICK

          DBLCLICK


0 Kudos

Nice 🙂 I have the same behavior on my SAP GUI. Now, the big question: is it possible to differentiate between click and double-click in the program? I did a few tests, and it sounds impossible. The click event is always triggered first, but how to know if it's a click or a double-click?

0 Kudos

Hi

Impossible?

It seems not to make sense, before doing the double click it does a single click

Max

0 Kudos

When a double-click is done on the picture (CL_GUI_PICTURE), the "click" event is triggered first (that's an issue, but it's how it works), then the "double click" event is triggered. In the single click event handler, how to know if it's a click or a double-click?

0 Kudos

Hi

it's very hard of course,

I mean a double click is two single click, so the event of the single click will be triggered as soon as the first click of the double click will be done, that explains why the 'click' event is triggered first.

So the action for the "click" event should be in stand by : it'll be done only if the double-click event is not triggered

You can try to do these modifications in your samples:


CLASS LCL_APP IMPLEMENTATION.

   METHOD ON_PICTURE_CLICK .

     FREE GT_TEXT.

     APPEND 'CLICK' TO GT_TEXT.

   ENDMETHOD.                    "on_picture_click

   METHOD ON_PICTURE_DBLCLICK.

     APPEND 'DCLICK' TO GT_TEXT.

   ENDMETHOD.                    "on_picture_dblclick

ENDCLASS.                    "lcl_app IMPLEMENTATION


START-OF-SELECTION.

   DATA GV_TEXT TYPE CHAR30.

   IF  LINES( LCL_APP=>GT_TEXT ) = 1.

     MESSAGE I208(00) WITH 'Do action for Single Click'.

   ELSEIF LINES( LCL_APP=>GT_TEXT ) = 2.

     MESSAGE I208(00) WITH 'Do action for Double Click'.

   ENDIF.

So probably what to do has to be triggered out of the events, perhaps in PAI

Max

0 Kudos

of course here it's easy because PAI (so START-OF-SELECTION) is triggered by F8, I don't know if it's possible to do the same in the dynpro

0 Kudos

Hmm, for the sample I have provided, why not, but in real life programs, we need to handle events via the event handler methods. I have absolutely no idea how to solve the issue, and my conclusion is that we should not mix single and double clicks (workaround: use single or double click + contextual menu, as Raymond suggested)

0 Kudos

Yes

I agree with you, I believe it doesn't make sense to use them together, probably it wouldn't be a clear situation for a user too, so I don't know if it make sense to spend a cent to solve the problem

To fix the problem seems a self-seeking game, a game of skills

0 Kudos

Hi

There is a possibility, using the Class CL_GUI_TIMER. Using this class you can set a Delay. In both event-handler methods you stop the timer, if he is started and start it again. The name of the event you can write to a variable. First the Click will be handled and write 'CLICK' to the Variable. If you did a dblclick, the variable will be overwritten by 'DBLCLICK' during the Delay-Time of the timer.

At the Event TIMER_FINISHED you can start another method and in the variable you can see, if the event was click or dblclick. Unfortunatly the minimum delay is 1 second, so after your click/dblclick the action will start with a delay of 1 second.

0 Kudos

OMG

loyd_enochs3
Participant
0 Kudos

Not a question of how but why.  This is a classic "back to the drawing board" moment.

First, as has been mentioned extensively, there really isn't a technical way to distinguish them when clicking on the same object.

Second, who asked for this dubious functionality?  If two different actions are needed for a single object, two pushbuttons or two menu items would appear to be more meaningful ways to inform the user of the available processing options.

Third, who approved this request?  There should be some sanity checking involved with approving change orders.

mahendraperisetty
Discoverer
0 Kudos

thank u all for your valuable time