Split Bar Object

back to main page

The Split bar is very important part of the GUI. This object simpifies usage such visual control. The sample project shows how different dialogs (coded using VPI GUI strategy) can be easily organized together using vertical and horizontal sliders (or split bars). You can use VIP Code explorer to write event handlers and other code and let split bar control layout of your itnerface.

To include Split Bar Object - open your project.inc file with VP Studio Setup utility and checkout necessary options:

The sample project can be used alsow for learning of Visual Prolog OOP - good visual example of how it works.  (click here to download VIP 5.2 project cource)

 

The idea of the this sample is quite primitive:

Window has two objects (represented as panel_class ) with split bar between them. On e_create() event you create a separator object (see code here), and pass e_MouseXXX events to this separator object (see Mouse control code here)

Test window has two controls:Left and Right panels with separator between them.

 

To include Separator Object into your project - simply include *.PRO file into the project with *.DOM and *.PRE files included into PROJECT.INC file. Click here for Separator Class Definition code.

The following Code should be added on e_create(_): of the window

....
    LEFT_WINDOW = win_GetCtlHandle(_Win, idc_edit),
    RIGHT_WINDOW = win_GetCtlHandle(_Win, panel_control),
    SeparatorObj = separator_object::new(_Win, LEFT_WINDOW, RIGHT_WINDOW,vertical),
    % store separator in a window data
    Data = cast(long, SeparatorObj),
    win_SetData(_Win, Data),
.....

Code to control mouse and redraw object on e_update() event:

..

%BEGIN Test Window, e_MouseUp
win_test_window_eh(_Win,e_MouseUp(_PNT,_ShiftCtlAlt,_Button),0):-!,
    Data = win_GetData(_Win),
    Separator = cast(separator_object, Data),
    Separator:check_separator(e_MouseUp(_PNT,_ShiftCtlAlt,_Button)),!.
%END Test Window, e_MouseUp

%BEGIN Test Window, e_MouseMove
win_test_window_eh(_Win,e_MouseMove(_PNT,_ShiftCtlAlt,_Button),0):-!,
    Data = win_GetData(_Win),
    Separator = cast(separator_object, Data),
    Separator:check_separator(e_MouseMove(_PNT,_ShiftCtlAlt,_Button)),!.
%END Test Window, e_MouseMove

%BEGIN Test Window, e_MouseDown
win_test_window_eh(_Win,e_MouseDown(_PNT,_ShiftCtlAlt,_Button),0):-!,
    Data = win_GetData(_Win),
    Separator = cast(separator_object, Data),
    Separator:check_separator(e_MouseDown(_PNT,_ShiftCtlAlt,_Button)),!.
%END Test Window, e_MouseDown

%BEGIN Test Window, e_Update
win_test_window_eh(_Win,e_Update(_UpdateRct),0):-
    win_Clear(_Win,_UpdateRct,color_ltgray),
    Data = win_GetData(_Win),
    Separator = cast(separator_object, Data),
    Separator:draw_separator_line(color_blue),!.
%END Test Window, e_Update

..
Now size of these Windows controls will be controlled by vertical slider.

 

Separator Class Definition:

GLOBAL DOMAINS
SEPARATOR_STATUS =
        pressed;
        released;
        nothing
SEPARATOR_TYPE     =
        horizontal;
        vertical

Object Class Definition:

class    separator_object
predicates
procedure    new(WINDOW PARENT, WINDOW LEFT, WINDOW RIGHT,SEPARATOR_TYPE)
procedure    delete()
procedure    adjust_separator
procedure    process_action(SEPARATOR_STATUS)
procedure    set_separator(PNT) - (i)
procedure    check_separator(EVENT) - (i)    % mouse event processing
procedure    draw_separator_line(COLOR)
facts
determ    object_rectangle(RCT)
determ    object_windows(WINDOW PARENT, WINDOW LEFT, WINDOW RIGHT)
determ    object_status(SEPARATOR_STATUS)
determ    object_type(SEPARATOR_TYPE)
endclass separator_object

PANEL_OBJECT class handling

The panel object is simple custom control with 2 EDIT controls separated by Horizontal line. On e_create(_) event there is a call to create horizontal separator objects (Separator Class Definition) between them. There is also redirection of Mouse events to separator object. As a result, horizontal line controls size of these two objects.

Task window has the following code on e_create():

    class_Create("panel_class",panel_handler),

Where panel_handler:

panel_handler(_Win,e_create(_),0):-
    RCT = win_GetClientRect( _Win ),
   % calculate control rectangles
    RCT = rct(_,_,R,B),Mid1 = B div 2,Bottom = B - 2,Right = R - 2,Top = Mid1 + 5,
    TopWin = win_CreateControl(wc_Edit,rct(1,2,Right,Mid1),"Top Object\nEdit Control",_Win,[wsf_AlignLeft,wsf_Group,wsf_TabStop,wsf_AutoHScroll,wsf_MultiLine],object_id1),
    BottomWin = win_CreateControl(wc_Edit,rct(1,Top,Right,Bottom),"Bottom Object\nEdit Control",_Win,[wsf_AlignLeft,wsf_Group,wsf_TabStop,wsf_AutoHScroll,wsf_MultiLine],object_id2),
    SeparatorObj = separator_object::new(_Win, TopWin, BottomWin,horizontal),
    % store separator in a window data
    Data = cast(long, SeparatorObj),
    win_SetData(_Win, Data),!.
panel_handler
(_Win,e_destroy(),0):-Data = win_GetData(_Win),
    SeparatorObj = cast(separator_object, Data),
    SeparatorObj:delete(),!.
panel_handler
(_Win,e_update(RCT),0):-
    % redraw object and separator
    win_Clear(_Win,RCT,0xFFFF80),
    Data = win_GetData(_Win),
    SeparatorObj = cast(separator_object, Data),
    SeparatorObj:draw_separator_line(color_red),!.
% control mouse behaviour

panel_handler
(_Win,e_MouseUp(_PNT,_ShiftCtlAlt,_Button),0):-
    Data = win_GetData(_Win),
    SeparatorObj = cast(separator_object, Data),
    SeparatorObj:check_separator(e_MouseUp(_PNT,_ShiftCtlAlt,_Button)),!.
panel_handler
(_Win,e_MouseDown(_PNT,_ShiftCtlAlt,_Button),0):-
    Data = win_GetData(_Win),
    SeparatorObj = cast(separator_object, Data),
    SeparatorObj:check_separator(e_MouseDown(_PNT,_ShiftCtlAlt,_Button)),!.
panel_handler(_Win,e_MouseMove(_PNT,_ShiftCtlAlt,_Button),0):-
    Data = win_GetData(_Win),
    SeparatorObj = cast(separator_object, Data),
    SeparatorObj:check_separator(e_MouseMove(_PNT,_ShiftCtlAlt,_Button)),!.
panel_handler
(_Win,e_size(_Width,_Height),0):-
    CtrlWin1 = win_GetCtlHandle(_Win, object_id1),
    CtrlWin2 = win_GetCtlHandle(_Win, object_id2),
    RCT1 = win_GetOuterRect(CtrlWin1),RCT1 = rct(L,T,_,B),
    NewR = _Width - 2,
    win_Move(CtrlWin1,rct(L,T,NewR,B)),
    RCT2 = win_GetOuterRect(CtrlWin2),RCT2 = rct(L2,T2,_,B2),
    win_Move(CtrlWin2,rct(L2,T2,NewR,B2)),
    Data = win_GetData(_Win),
    SeparatorObj = cast(separator_object, Data),
    SeparatorObj:adjust_separator,
    SeparatorObj:draw_separator_line(color_red),!.
 

 


Copyright 1998-2000 EDMGROUP (Australia)

Last Updated: April 17, 2002