Changing background colors and mutability of XPCE dialogs

I’ve been trying to scratch a recent itch involving prolog and gui applications, so I’ve been trying my hand at writing some basic applications with XPCE. While manpce and the user guide have been useful for building the most basic of applications, I am struggling to manipulate simple elements.

I’m building a toy flight booker app ala 7GUIs. I’m currently struggling on changing the background color of an XPCE text_item. If possible, I’d also like to make a text element immutable (or view only) like one might make an immutable textbox in HTML.

My code so far is simple:

% main.pl
% usage: swipl-win.exe main.pl
:- use_module(library(pce)).
:- initialization main.

main :-
    new(D, dialog('Flight Booker')),
    menu(Menu),
    date_box(StartBox, '2022-01-01'),
    date_box(ReturnBox, '2022-02-01'),
    send(D, append, Menu),
    send(D, append, StartBox),
    send(D, append, ReturnBox),
    send(Menu, message, message(@prolog, menu_selected, Menu)),
    get(D, confirm, _).

menu_selected(Menu) :-
    get(Menu, selection, Item),
    % print Item
    write(Item), nl.

menu(Menu):-
    new(Menu, menu(flighttype, cycle)),
    send(Menu, show_label, @off),
    send_list(Menu, append, ['one-way flight', 'return flight']).

date_box(Box, InitDate) :-
    new(Box, text_item(date, InitDate)),
    send(Box, type, string),
    send(Box, length, 12),
    send(Box, show_label, @off).

image

I can change the color of the text in the text_item box by sending a message the color properties in date_box, but I can’t change the color of the background (which I would like to turn red). In general, it has been difficult to determine which properties I can notify by reading the manual. The closest I’ve gotten is to look through Appendix H and glimpsing some hints from the code samples there. I have used the manpce dialog editor to build elements and view the generated source in (the built-in) emacs, but unfortunately it doesn’t look like there is anything related to the background.

I’m hoping there’s a way to modify visual properties from one of the dialog’s super classes:

image

It would be great too if there were ways to prevent input from temporarily being accepted to one of the dialogs. I’m just not sure how I could achieve this goal.

To make it non-editable you can use send(TextItem, editable, @off).. A quick look through the source indicates that the background is than painted using an internal elevation instance that has no externally visible reference. See init_entry_resources() in x_menu.c You’d have to go through the same setup as used for the elevation of buttons that do provide user access. Means changing the C code …

Xpce is old :frowning:

Nice to see the editable is easy to handle. I started digging into the code and found that h/graphics.h is super useful for figuring out what messages are available to send to different resources. I noticed that background is actually available to dialog items like buttons or text items:

I tried setting background on buttons and text items with no avail – it seems to retain the same gray background regardless of the value:

:- use_module(library(pce)).
:- initialization main.
main :-
    new(D, dialog(test)),
    new(B, button(test)),
    send(B, background, colour(green)),
    send(D, append, B),
    get(D, confirm, _).

I noticed that dialog groups have a public elevation, so I tried sending a new elevation with a background color over:

main :-
    new(D, dialog(test)),
    new(G, dialog_group(test)),
    send(G, elevation, elevation(background:=colour(green))),
    send(D, append, G),
    get(D, confirm, _).

But this also looks like a dead-end. I’m guessing that the background isn’t hooked into the colour initialization in xmenu/msmenu implementations. It’s not clear to me how the the colors are actually being initialized here:

Am I reading this correctly? Is that the native scrollbar color? It sure does seem a tad strange.

Would it be feasible it is to grab values from the available properties/attributes/messages and get them into the dialog drawing routines, with a little bit of massaging here?

Aha, I see where I’d have to make change, probably somewhere around here.

Well, that and all of the elements where it makes sense to have the background color change. Looks like this has context to class variables and does the actual drawing of elements, calling into the platform specific code where necessary.

I might try my hand at compiling XPCE eventually, but I think I’ll go ahead and set the text color instead of the background color for my exercise and call it a day :slight_smile:

1 Like