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: 

Amodal dialog box: positioning in lower right corner of screen

Former Member
0 Kudos

I have what seems a quite common requirement, that is to automatically position an amodal dialog box (CL_ABAP_DIALOGBOX_CONTAINER) to the lower right corner of the screen.

The logical approach to do this would be to read the screen resolution, deduct the size of the box, and pass the result to the TOP and LEFT parameters of the constructor of the container.

Unfortunately, I haven't found any documentation of what the values for TOP and LEFT (and for WIDTH and HEIGHT, for that matter) really represent. They're not screen pixels, that's for sure.

To read the screen resolution, I execute the following code:

DATA:

lo_consumer TYPE REF TO cl_gui_props_consumer,

ls_metric_factors TYPE cntl_metric_factors.

lo_consumer = cl_gui_props_consumer=>create_consumer( ).

ls_metric_factors = lo_consumer->get_metric_factors( ).

In ls_metric_factors-screen-x and ls_metric_factors-screen-y I get back the screen resolution (x = 1280 and y = 994 on a 1280 x 1024 screen, weirdly, but close enough). Got this from another SDN post, BTW - thanks.

When I manually position my dialog box to the farthest right lower corner, so that the mouse cursor can just about reach it, the GET_LEFT and GET_TOP methods for the dialog box return LEFT = 1453 and TOP = 387. So, obviously, these values have nothing to do with screen pixels.

What I did, then, was to calculate a factor between the screen pixels and the TOP and LEFT values - a factor which is different for the X and the Y dimensions. I got:

- (1453 / 1280) = 1.135 for the x dimension

- (387 / 994) = 0.389 for the y dimension.

With these factors, I calculate the initial position of the box as follows:

l_box_pos_x = ( ls_metric_factors-screen-x * lc_factor_x ) - lc_box_width.

l_box_pos_y = ( ls_metric_factors-screen-y * lc_factor_y ) - lc_box_height.

This seems to work fine, at least on my system and my front-end PC, with all supported resolutions from 800 x 600 up to 1280 x 1024.

It just leaves the question open: Does anybody know what the unit of measure for the sizing and positioning parameters of controls is? Why a box with a width and a height of 100 [whatevers] each is not square, but rectangular?

And finally: does somebody have a more intelligent way to do this?

Thanks, regards & stuff

Rainer

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Hi Rainer,

While creating the dialogbox container object, just set metric property to '1' (for Pixels) and then while setting TOP and LEFT you can provide pixels.

For example,

CREATE OBJECT REF_DIALOGBOX_CONTAINER

EXPORTING

WIDTH = 100

HEIGHT = 100

TOP = 638

LEFT = 924

CAPTION = 'hello world'

<b> metric = 1.</b>

Then your calculation simply becomes,

l_box_pos_x = ls_metric_factors-screen-x - lc_box_width.

l_box_pos_y = ls_metric_factors-screen-y - lc_box_height.

<b>NOTE: Now you will see that your dialog box is a SQUARE!!</b>

Hope this helps..

Sri

2 REPLIES 2

Former Member
0 Kudos

Hi Rainer,

While creating the dialogbox container object, just set metric property to '1' (for Pixels) and then while setting TOP and LEFT you can provide pixels.

For example,

CREATE OBJECT REF_DIALOGBOX_CONTAINER

EXPORTING

WIDTH = 100

HEIGHT = 100

TOP = 638

LEFT = 924

CAPTION = 'hello world'

<b> metric = 1.</b>

Then your calculation simply becomes,

l_box_pos_x = ls_metric_factors-screen-x - lc_box_width.

l_box_pos_y = ls_metric_factors-screen-y - lc_box_height.

<b>NOTE: Now you will see that your dialog box is a SQUARE!!</b>

Hope this helps..

Sri

0 Kudos

Hi Sri,

You're absolutely, utterly, totally right. I just wish this were documented somewhere (maybe I just didn't find the right spot...).

Thanks ever so much

Rainer