1/* Part of XPCE --- The SWI-Prolog GUI toolkit 2 3 Author: Jan Wielemaker and Anjo Anjewierden 4 E-mail: J.Wielemaker@vu.nl 5 WWW: http://www.swi-prolog.org/packages/xpce/ 6 Copyright (c) 1985-2022, University of Amsterdam 7 VU University Amsterdam 8 CWI, Amsterdam 9 SWI-Prolog Solutions b.v. 10 All rights reserved. 11 12 Redistribution and use in source and binary forms, with or without 13 modification, are permitted provided that the following conditions 14 are met: 15 16 1. Redistributions of source code must retain the above copyright 17 notice, this list of conditions and the following disclaimer. 18 19 2. Redistributions in binary form must reproduce the above copyright 20 notice, this list of conditions and the following disclaimer in 21 the documentation and/or other materials provided with the 22 distribution. 23 24 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 25 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 26 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 27 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 28 COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 29 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, 30 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 31 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 32 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 33 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 34 ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 35 POSSIBILITY OF SUCH DAMAGE. 36*/ 37 38/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 39Module PCE. This module defines the core of XPCE. It is designed in 40such a way that it may be compiled using the SWI-Prolog qcompile/1 41compiler, which makes XPCE an autoloadable module of SWI-Prolog. 42 43Various things are Prolog-implementation specific in this module and 44therefore each Prolog system will require a different version of this 45module. 46 47This module only defines some paths, some things to make the .qlf 48compiler work on it and finally it just loads the XPCE modules and 49reexports the content of these files. 50- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ 51 52:- module(pce, 53 [ new/2, free/1, % pce_principal predicates 54 55 send/2, send/3, send/4, send/5, send/6, send/7, 56 send/8, 57 58 get/3, get/4, get/5, get/6, get/7, get/8, 59 60 send_class/3, 61 get_class/4, 62 object/1, object/2, 63 64 pce_global/2, % pce_global 65 pce_autoload/2, % pce_autoload 66 pce_autoload_all/0, 67 68 pce_term_expansion/2, 69 pce_compiling/1, % -Class 70 pce_compiling/2, % -Class, -Path 71 pce_begin_recording/1, 72 pce_end_recording/0, 73 74 pce_register_class/1, 75 pce_extended_class/1, 76 pce_begin_class_definition/4, 77 pce_prolog_class/1, 78 pce_prolog_class/2, 79 80 pce_catch_error/2, % pce_error 81 pce_open/3, 82 in_pce_thread/1, % :Goal 83 in_pce_thread_sync/1, % :Goal 84 set_pce_thread/0, 85 pce_thread/1, % -Thread 86 pce_dispatch/0, 87 88 op(200, fy, @), 89 op(250, yfx, ?), 90 op(800, xfx, :=) 91 ]). 92 93:- multifile 94 on_load/0. 95 96:- set_prolog_flag(generate_debug_info, false). 97 98:- meta_predicate 99 in_pce_thread_sync( ). 100 101 /******************************** 102 * LOAD COMMON PLATFORM * 103 ********************************/ 104 105:- multifile user:file_search_path/2. 106 107:- load_files([ '../boot/pce_expand', 108 '../boot/pce_pl', 109 '../boot/pce_principal', 110 '../boot/pce_error', 111 '../boot/pce_global', 112 '../boot/pce_expansion', 113 '../boot/pce_realise', 114 '../boot/pce_goal_expansion', 115 '../boot/pce_autoload', 116 '../boot/pce_editor', 117 '../boot/pce_keybinding', 118 '../boot/pce_portray', 119 english/pce_messages 120 ], 121 [ qcompile(part), % compile boot files as part of pce.qlf 122 silent(true) 123 ]). 124:- if(current_prolog_flag(threads, true)). 125:- use_module(pce_dispatch). 126:- endif.
135:- current_prolog_flag(threads, HasThreads), 136 create_prolog_flag(xpce_threaded, HasThreads, [keep(true)]). 137 138:- dynamic 139 pce_thread/1.
Possible bindings of Goal are returned, but be aware that the term has been copied. If in_pce_thread_sync/1 is called in the thread running pce, it behaves as once/1.
151in_pce_thread_sync(Goal) :- 152 thread_self(Me), 153 pce_thread(Me), 154 !, 155 , 156 !. 157in_pce_thread_sync(Goal) :- 158 term_variables(Goal, Vars), 159 pce_principal:in_pce_thread_sync2(Goal-Vars, Vars). 160 161:- if(current_prolog_flag(threads, true)). 162start_dispatch :- 163 ( current_predicate(pce_dispatch:start_dispatch/0) 164 -> pce_dispatch:start_dispatch 165 ; true 166 ). 167 168:- initialization 169 start_dispatch. 170:- endif. 171 172set_version :- 173 current_prolog_flag(version_data, swi(Major, Minor, Patch, _)), 174 format(string(PlId), 175 'SWI-Prolog version ~w.~w.~w', [Major, Minor, Patch]), 176 send(@prolog, system, PlId). 177 178:- initialization set_version. 179 180get_pce_version :- 181 ( current_prolog_flag(xpce_version, _) 182 -> true 183 ; get(@pce, version, name, Version), 184 create_prolog_flag(xpce_version, Version, []) 185 ). 186 187:- initialization get_pce_version. 188 189run_on_load :- 190 forall(on_load, true). 191 192:- initialization run_on_load. 193 194 195 /******************************* 196 * CONSOLE * 197 *******************************/ 198 199%:- send(@pce, console_label, 'XPCE/SWI-Prolog'). 200 201 202 /******************************** 203 * PROLOG LIBRARIES * 204 ********************************/ 205 206:- multifile 207 user:file_search_path/2. 208 209user:file_search_path(demo, pce('prolog/demo')). 210user:file_search_path(contrib, pce('prolog/contrib')). 211user:file_search_path(image, pce(bitmaps)). 212 213 214 /******************************* 215 * HOOKS * 216 *******************************/ 217 218:- use_module(library(swi_hooks)). 219 220 /******************************* 221 * EDIT HOOKS * 222 *******************************/ 223 224% make sure SWI-Prolog edit/0 loads the XPCE edit hooks. 225 226:- multifile 227 prolog_edit:load/0, 228 prolog:locate_clauses/2. 229 230prolog_edit:load :- 231 ensure_loaded(library(swi_edit)). 232 233 /******************************* 234 * LIST HOOKS * 235 *******************************/
see library(listing).
244prolog:locate_clauses(Term, Refs) :- 245 ( Term = ->(_,_) 246 ; Term = <-(_,_) 247 ), 248 !, 249 findall(R, method_clause(Term, R), Refs). 250 251match_id(->(Class, Method), Id) :- 252 atomic(Class), atomic(Method), 253 !, 254 atomic_list_concat([Class, (->), Method], Id). 255match_id(->(_Class, _Method), _Id). 256match_id(<-(Class, Method), Id) :- 257 atomic(Class), atomic(Method), 258 !, 259 atomic_list_concat([Class, (<-), Method], Id). 260match_id(<-(_Class, _Method), _Id). 261 262method_clause(->(Class, Send), Ref) :- 263 match_id((Class->Send), Id), 264 clause(pce_principal:send_implementation(Id, _M, _O), _B, Ref), 265 atom(Id), 266 atomic_list_concat([Class,Send], '->', Id). 267method_clause(<-(Class, Get), Ref) :- 268 match_id(<-(Class, Get), Id), 269 clause(pce_principal:get_implementation(Id, _M, _O, _R), _B, Ref), 270 atom(Id), 271 atomic_list_concat([Class,Get], '->', Id). 272 273 274 /******************************* 275 * MESSAGES * 276 *******************************/ 277 278:- multifile 279 prolog:message/3. 280 281prologmessage(Spec) --> 282 pce_message(Spec). 283prologmessage(context_error(Goal, Context, What)) --> 284 [ '~w: ~w '-[Goal, What] ], 285 pce_message_context(Context). 286prologmessage(type_error(Goal, ArgN, Type, _Value)) --> 287 [ '~w: argument ~w must be a ~w'-[Goal, ArgN, Type], nl ]