1

I am trying to build a toolbar in WIN-PROLOG and I am having some problems on giving functionalities to the buttons.

I want to have buttons that have the same functionalities that items in the menu bar have. For example, a button named "New" that has the same functionality that the item "New File" has in the File Menu.

I thought that it was enough to write "system_menu(0,file,new)" because it worked for "New" and "Open" functionalities, but it doesn't work for the other items such as Save or Save As. How can I make it work for the other items in the File Menu and other menus (Edit,Search,Run,Options,Window,Help).

go:-
  dynamic(known_focus/1),
  gfx_brush_create(toolbar,128,128,128,solid),
  toolbar,
  window_handler(0,tlb_handler),
  sndmsg(0,wm_size,0,0,_).

toolbar:-
  _S2 = [ws_child,ws_visible,bs_pushbutton,ws_clipsiblings],
  _S3 = [ws_child,ws_clipsiblings,ws_clipchildren,ws_visible],
  wccreate((0,2),grafix,       '',            0,  0, 32, 32, _S3),
  wccreate((0,2,1000), button, 'New',         2,  2, 64 ,30, _S2),
  wccreate((0,2,1001), button, 'Open',       67,  2, 64 ,30, _S2),
  wccreate((0,2,1002), button, 'Save',      135,  2, 64 ,30, _S2),
  wccreate((0,2,1003), button, 'Save as',   200,  2, 64 ,30, _S2),
  wccreate((0,2,1004), button, 'Save all',  265,  2, 64 ,30, _S2).


tlb_handler(Win,msg_paint,_,_):-
  Win = (0,2).
  warea(Win,_,_,W,H),
  W1 is W + 2,
  H1 is H + 2,
  gfx_paint(Win),
  gfx((brush=toolbar -> rectangle(-1,-1,W1,H1)) ),
  gfx_end(Win).


tlb_handler(Win,msg_button,_,_) :-
  Win = (0,2,I),
  tlb_button(I).

tlb_handler(Win,Msg,Dat,Res) :-
  window_handler(Win,Msg,Dat,Res).

tlb_handler( (0,2,_) , msg_focus,Data,_) :-
  wclass(Data,Class),
  Class= 'Rich',
  rectractall(known_focus(_)),
  assert(known_focus(Data)).


tlb_button(1000) :-
  system_menu(0,file,new).

tlb_button(1001):-
  system_menu(0,file,open).

tlb_button(1002):-
  system_menu(0,file,save).

tlb_button(1003):-
  system_menu(0,file,save_as). ```
Rodrigo
  • 11
  • 1

0 Answers0