0

我正在使用 OpenEdge ABL / Progress 4GL。我有一个填充了行的浏览器小部件。当我左键单击一行时,该行突出显示,该行现在成为焦点。我希望当我右键单击不同的行以执行“左键单击”(将焦点移动到右键单击的行)然后右键单击。

4

4 回答 4

1

检查鼠标事件的 ABL 参考(10.2B ABL 参考指南的第 1834 页)。

通常的方法是使用“ON event-name OF widget-name”捕获有问题的事件,然后将不同的事件应用于小部件(将“鼠标选择单击”应用到 b-name)然后告诉 AVM 忽略带有“RETURN NO-APPLY”的原始事件。

它看起来像这样:

ON MOUSE-MENU-CLICK   OF b-name
   DO:
   APPLY "mouse-select-click" TO SELF.
   RETURN NO-APPLY.
   END.

警告:我不确定右键单击会触发什么事件,因此您需要调整此代码以适应。

于 2012-01-20T15:31:08.550 回答
0

基本上,您必须像这样定义触发器:

ON RIGHT-MOUSE-CLICK OF myBrowseRow DO:  

APPLY "ENTRY" TO myBrowse IN FRAME myFrame.  

/* Code to focus a particular row in the browse. */  
APPLY "ENTRY" TO SELF IN BROWSE myBrowse.
END.

问题可能是您必须将该触发器添加到浏览中的每一行,因为如果您仅为浏览本身设置触发器,AFAIK 无法确定右键单击了哪一行...

于 2012-01-20T15:35:16.107 回答
0

我已经在这里回答了这个问题:如何在 OpenEdge ABL / Progress 4GL 中找到在浏览器中右键单击的行的行 ID。

我不确定这个重复问题的政策是什么,但我在这里重复我的回答,我希望没问题。

我也有类似的情况;我想在浏览中响应鼠标的右键单击。右键单击不会选择您正在单击的行,因此我必须以编程方式确定它是哪一行。下面的编码确定您单击并选择了哪一行。恐怕真的有这么复杂。

这发生在浏览的 MOUSE-MENU-DOWN 事件中:

DEFINE VARIABLE iRowHeight   AS INTEGER     NO-UNDO.
DEFINE VARIABLE iLastY       AS INTEGER     NO-UNDO.
DEFINE VARIABLE iRow         AS INTEGER     NO-UNDO.
DEFINE VARIABLE hCell        AS HANDLE      NO-UNDO.
DEFINE VARIABLE iTopRowY     AS INTEGER     NO-UNDO.

/* See if there are ANY rows in view... */
IF SELF:NUM-ITERATIONS = 0 THEN 
DO:
   /* No rows, the user clicked on an empty browse widget */
   RETURN NO-APPLY. 
END.

/* We don't know which row was clicked on, we have to calculate it from the mouse coordinates and the row heights. No really. */
SELF:SELECT-ROW(1).               /* Select the first row so we can get the first cell. */
hCell      = SELF:FIRST-COLUMN.   /* Get the first cell so we can get the Y coord of the first row, and the height of cells. */
iTopRowY   = hCell:Y - 1.         /* The Y coord of the top of the top row relative to the browse widget. Had to subtract 1 pixel to get it accurate. */
iRowHeight = hCell:HEIGHT-PIXELS. /* SELF:ROW-HEIGHT-PIXELS is not the same as hCell:HEIGHT-PIXELS for some reason */
iLastY     = LAST-EVENT:Y.        /* The Y position of the mouse event (relative to the browse widget) */

/* calculate which row was clicked. Truncate so that it doesn't round clicks past the middle of the row up to the next row. */
iRow       = 1 + TRUNCATE((iLastY - iTopRowY) / iRowHeight, 0). 

IF iRow > 0 AND iRow <= SELF:NUM-ITERATIONS THEN 
DO:
  /* The user clicked on a populated row */
  Your coding here, for example:
  SELF:SELECT-ROW(iRow).
END.
ELSE DO:
  /* The click was on an empty row. */
  SELF:DESELECT-ROWS().
  RETURN NO-APPLY.
END.

我希望这有帮助。

于 2012-02-14T13:00:25.713 回答
0

为了扩展主要答案,这里有一些附加说明和示例代码。
1.您需要注意标题和标题的高度。
2. 如果你有标准的浏览功能,你可以动态附加一个菜单。
3. 多选浏览器的行为略有不同。

ON 'right-mouse-down':U ANYWHERE DO:
    RUN set_focus (SELF).
    IF SELF:TYPE = 'BROWSE' THEN DO:
        RETURN NO-APPLY.
    END.
    ELSE DO:
        APPLY 'menu-drop' TO SELF.
    END.
END.

PROCEDURE set_focus.
DEF INPUT PARAM i_object            AS HANDLE   NO-UNDO.
DEF VAR l_was_row_one_selected      AS LOG      NO-UNDO.
DEF VAR l_header_y                  AS DEC      NO-UNDO.
DEF VAR w_browse_title_bar_height   AS DEC      NO-UNDO INITIAL 19. /* determine this for your UI */
DEF VAR o_labels                    AS CHAR     NO-UNDO.
DEF VAR o_procedures                AS CHAR     NO-UNDO.
DEF VAR h_menu                      AS HANDLE   NO-UNDO.
DEF VAR h_menu_item                 AS HANDLE   NO-UNDO.
DEF VAR l_count                     AS INT      NO-UNDO.
/* given an object ... */
    IF i_object:TYPE = 'browse' THEN DO:
        IF i_object:NUM-SELECTED-ROWS = 0
            THEN ASSIGN l_was_row_one_selected = FALSE.
            ELSE ASSIGN l_was_row_one_selected = i_object:IS-ROW-SELECTED(1) NO-ERROR.
        i_object:SELECT-ROW(1) NO-ERROR.
        IF ERROR-STATUS:ERROR THEN RETURN.
        l_header_y = MAX(1,i_object:FIRST-COLUMN:Y). /* in case there are no column headers */
        IF i_object:TITLE <> ? THEN l_header_y = l_header_y - w_browse_title_bar_height.
        IF l_was_row_one_selected = FALSE THEN i_object:DESELECT-SELECTED-ROW(1) NO-ERROR.
        /* this section selects the correct row, based on where it was clicked, minus the height of the headers divided by row height */
        i_object:SELECT-ROW(
            INT(
                1 + 
                TRUNC(
                      (LAST-EVENT:Y - l_header_y) / i_object:FIRST-COLUMN:HEIGHT-PIXELS
                     ,0)
                )
            )
            NO-ERROR.
        APPLY 'ENTRY':u TO i_object. /* to get focus properly */
        APPLY 'VALUE-CHANGED':u TO i_object.
        /* use some rule to find associated dynamic menu items, e.g. maintenance options, finding related data*/
        RUN find_menu_stuff (i_object:NAME, OUTPUT o_labels, OUTPUT o_procedures).
        IF o_labels = '' THEN RETURN.

        /* this finds a popup menu, if any */
        h_menu = i_object:POPUP-MENU NO-ERROR.

        IF VALID-HANDLE(h_menu) THEN RETURN. /* already created previously */
        /* create a popup menu */
        CREATE MENU h_menu.
        ASSIGN
            h_menu:POPUP-ONLY   = TRUE
            i_object:POPUP-MENU = h_menu
            .
        /* add the standard maintenance options (they still may not be supported though) */
        DO l_count = 1 TO NUM-ENTRIES (o_labels):
            IF ENTRY(l_count,o_labels) = 'Rule' THEN DO:
                CREATE MENU-ITEM h_menu_item
                    ASSIGN
                        SUBTYPE     = 'RULE'
                        PARENT      = h_menu
                        .

            END.
            ELSE DO:
                CREATE MENU-ITEM h_menu_item
                    ASSIGN
                        PARENT      = h_menu
                        LABEL       = ENTRY(l_count,o_labels)
                        SENSITIVE   = TRUE
                    TRIGGERS:
                        ON CHOOSE PERSISTENT RUN pp_apply_maint_action IN THIS-PROCEDURE (SELF, ENTRY(l_count,o_procedures)).
                    END TRIGGERS.
            END.
        END.
    END.
    IF VALID-HANDLE(h_menu)
        THEN APPLY 'menu-drop' TO h_menu.
    /* MENU-DROP - Supported only when the POPUP-ONLY attribute is set to TRUE and the
                   menu is set as a popup for some other widget */
END PROCEDURE.

PROCEDURE find_menu_stuff.
    /* do lookups or other general or specific things here */
END.
于 2012-06-12T08:57:37.920 回答