Consultor Eletrônico



Kbase P39288: How to make RIGHT MOUSE button select a row in a browse ?
Autor   Progress Software Corporation - Progress
Acesso   Público
Publicação   17/10/2007
Status: Unverified

GOAL:

How to make RIGHT MOUSE button select a row in a browse ?

FIX:

How to make RIGHT MOUSE button select a row in a browse ?

INTRODUCTION:
=============
This Technical Support library entry describes how to make RIGHT MOUSE button select a row in a browse. It can be used in V7 and V8.

WHY YOU NEED TO KNOW THIS:
===========================
Some customers might ask how to do it. They usually want to use right mouse button to view some additional information and the problem is that applying user events (such as MOUSE-SELECT-CLICK) fires user-defined triggers, but not the built-in behavior of the object itself.

PROCEDURAL APPROACH:
====================
Put the following piece of code either as a MOUSE-MENU-CLICK or as a LEFT-MOUSE-CLICK trigger:

DEFINE VARIABLE h-cell AS WIDGET-HANDLE NO-UNDO.
DEFINE VARIABLE i-cellHeight AS INTEGER NO-UNDO.
DEFINE VARIABLE i-lastY AS INTEGER NO-UNDO.
DEFINE VARIABLE i-row AS INTEGER NO-UNDO.
DEFINE VARIABLE l-ok AS LOGICAL NO-UNDO.

h-cell = SELF:FIRST-COLUMN.

IF VALID-HANDLE(h-cell) THEN i-cellHeight = h-cell:HEIGHT-PIXELS.
ELSE i-cellHeight = 20.

i-lastY = LAST-EVENT:Y.

IF i-lastY >= i-cellHeight AND
i-lastY <= i-cellHeight * (SELF:NUM-ITERATIONS + 1) THEN
DO:
i-lastY = i-lastY - i-cellHeight / 2.
i-row = i-lastY / i-cellHeight.
l-ok = SELF:SELECT-ROW(i-row).
END.

Explanation of the code:
------------------------
The first IF is because not all browses are updatable so to make the code as universal as possible this checks whether the handle of the first enabled column is valid. If so then it takes height from it. If not it is necessary to check whether the value 20 is OK (to see how refer to the paragraph "PROCEDURES OR UTILITIES". This IF and the previous line h-cell = SELF:FIRST-COLUMN can be used in V8 ONLY !!! The second IF checks whether or not it makes sense to select the row. If this would not be there it would give errors when either column header or the "tail" of the browse would be clicked on.

ONLINE PROCEDURES OR UTILITIES:
===============================
How to find out a height of a row (this applies to V8 ONLY):
- create a browse with an enabled field
- edit a trigger ON VALUE-CHANGED OF browse:

DEFINE VARIABLE h-cell AS WIDGET-HANDLE NO-UNDO.
h-cell = SELF:FIRST-COLUMN.
MESSAGE h-cell:HEIGHT-PIXELS VIEW-AS ALERT-BOX INFORMATION.

- run the code and click on a row in the browse, the value returned by the message is height of the row
- now you can hard code the value for non-updatable browsers