1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282
|
/* $Id: persistent_frame.pl,v 1.4 2002/02/01 15:04:49 jan Exp $
Part of XPCE --- The SWI-Prolog GUI toolkit
Author: Jan Wielemaker and Anjo Anjewierden
E-mail: jan@swi.psy.uva.nl
WWW: http://www.swi.psy.uva.nl/projects/xpce/
Copyright (C): 1985-2002, University of Amsterdam
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
As a special exception, if you link this library with other files,
compiled with a Free Software compiler, to produce an executable, this
library does not by itself cause the resulting executable to be covered
by the GNU General Public License. This exception does not however
invalidate any other reasons why the executable file might be covered by
the GNU General Public License.
*/
:- module(persistent_frame, []).
:- use_module(library(pce)).
:- use_module(library(pce_config)).
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
This library defines the class persistent_frame, a subclass of class
frame remembering its geometry and optionally (by default on) the
subwindow layout.
This class cooperates with the library(pce_config), a generic package
for managing application preferences. It collects the locations of user
frames in the file <profile-dir>/Geometry.cnf
Geometry information is stored in the internal configuration DB (see
library(pce_config)) if a frame is closed or on exit from the
application. The internal database is written to tehe above mentioned
file on exit from the application.
Somehow the system must identify the frame to decide which geometry to
use. This is done using the <->geometry_key. If not set, this is the
classname or, if the class is not subclassed it is the <-label of the
frame.
Exploiting this library is very simple, just make your toplevel windows
for which you want the geometry remembered a subclass of class
persistent_frame rather than class frame. Note that this implies you
have to create your frame explitely:
...
new(F, persistent_frame('Pretty Application')),
send(F, geometry_key, pretty_app),
send(F, append, new(D, dialog)),
send(new(V, view), right, D),
...
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
:- pce_begin_class(persistent_frame, frame, "Frame remembering location").
variable(persistent_subwindow_layout, bool := @on, get,
"Remember the layout of the subwindows?").
variable(geometry_key, name*, send,
"Key used to identify this frame").
unlink(F) :->
"Save layout and destroy"::
send(F, save_layout),
send_super(F, unlink).
create(F) :->
"Create and restore layout"::
send_super(F, create),
send(F, load_layout).
:- pce_group(config).
geometry_key(F, Key:name) :<-
"Name to store geometry"::
( get(F, slot, geometry_key, Key),
Key \== @nil
-> true
; get(F, class_name, Key),
Key \== persistent_frame
-> true
; get(F, label, Key)
).
save_layout(F) :->
"Save current layout in config DB"::
get(F, geometry, Geometry),
get(F, geometry_key, Key),
set_config(history/geometry/Key, Geometry),
( get(F, persistent_subwindow_layout, @on),
get(F, tile, RootTile),
get(RootTile, members, Members),
Members \== @nil,
get_tile_layout(RootTile, Layout)
-> set_config(history/subwindow_layout/Key, Layout)
; true
).
load_layout(F) :->
load_geometry_config,
get(F, geometry_key, Key),
( get_config(history/geometry/Key, Geometry)
-> send(F, geometry, Geometry)
; true
),
( get(F, persistent_subwindow_layout, @on),
get_config(history/subwindow_layout/Key, Layout)
-> get(F, tile, RootTile),
apply_tile_layout(RootTile, Layout)
; true
).
% get_tile_layout(+Tile, -Layout)
%
% Create a Prolog term representing the subwindow (tile) layout.
% Note that we only save the width/height of resizeable subwindows,
% leaving the others to the application. This ensures proper behaviour
% if the application is modified.
get_tile_layout(T, layout(Me, SubLayout)) :-
get_this_tile_layout(T, Me),
( get(T, members, Members),
Members \== @nil
-> chain_list(Members, List),
maplist(get_this_tile_layout, List, SubLayout),
has_specifier(layout(Me, SubLayout))
; SubLayout = []
).
get_this_tile_layout(T, Size) :-
get(T, can_resize, @on), !,
get(T, area, A),
( get(T?super, orientation, horizontal)
-> get(A, width, Size)
; get(A, height, Size)
).
get_this_tile_layout(_, *).
% has_specifier(+Layout)
%
% See whether there is a specification somewhere, otherwise there
% is no use storing it.
has_specifier(layout(Size, _)) :-
Size \== *, !.
has_specifier(layout(_, Subs)) :-
member(Sub, Subs),
has_specifier(Sub).
% apply_tile_layout(+Tile, +Layout)
%
% Apply a previously saved layout description, sending ->width
% or ->height messages to resizeable tiles.
apply_tile_layout(T, layout(Me, SubLayout)) :-
apply_this_tile_layout(T, Me),
( get(T, members, Members),
Members \== @nil
-> chain_list(Members, List),
maplist(apply_this_tile_layout, List, SubLayout)
; true
).
apply_this_tile_layout(_, *) :- !.
apply_this_tile_layout(T, Size) :-
( get(T?super, orientation, horizontal)
-> send(T, width, Size)
; send(T, height, Size)
).
:- pce_end_class(persistent_frame).
/*******************************
* EXIT HOOKS *
*******************************/
:- initialization
send(@pce, exit_message,
message(@display?frames,
for_some,
if(message(@arg1, instance_of, persistent_frame),
message(@arg1, save_layout)))).
/*******************************
* CONFIG HOOKS *
*******************************/
config(config/file,
[ default('Geometry')
]).
config(history/geometry/_Key,
[ type(geometry),
editable(false),
comment('(X-)geometry for persistent frames')
]).
config(history/subwindow_layout/_Key,
[ type(subwindow_layout),
editable(false),
comment('Sub-window layout for persistent frames')
]).
:- register_config(config).
load_geometry_config :-
context_module(M),
ensure_loaded_config(M:_).
/*******************************
* TEST *
*******************************/
end_of_file. % make the file end here.
test :-
send(new(mydialog), open).
:- pce_begin_class(myframe1, persistent_frame).
initialise(F) :->
send_super(F, initialise, 'Frame holding a browser'),
send(F, append, new(browser)).
:- pce_end_class(myframe1).
:- pce_begin_class(myframe2, persistent_frame).
initialise(F) :->
send_super(F, initialise, 'Frame holding a view'),
send(F, append, new(V, view)),
send(new(picture), left, V).
:- pce_end_class(myframe2).
:- pce_begin_class(myframe3, persistent_frame).
initialise(F) :->
send_super(F, initialise, 'Frame holding a picture'),
send(F, append, new(picture)).
:- pce_end_class(myframe3).
:- pce_begin_class(mydialog, persistent_frame).
initialise(F) :->
send_super(F, initialise('Test persistent frames')),
send(F, append, new(D, dialog)),
send(D, append, button(frame_1)),
send(D, append, button(frame_2)),
send(D, append, button(frame_3)),
send(D, open).
frame_1(_F) :->
send(new(myframe1), open).
frame_2(_F) :->
send(new(myframe2), open).
frame_3(_F) :->
send(new(myframe3), open).
:- pce_end_class(mydialog).
|