home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 22 gnu / 22-gnu.zip / gwm18a.zip / data / wbrooms.gwm < prev    next >
Lisp/Scheme  |  1995-07-03  |  20KB  |  767 lines

  1. ;; William Burdick's attempt at icon groups/rooms
  2. ;; The idea is like dvrooms, except that a room is a bar of buttons
  3. ;;=============================================================================
  4. ;; Date: Thu, 01 Jul 1993 00:08:26 EST
  5. ;; From: William R Burdick <burdick@ecn.purdue.edu>
  6. ;; 
  7. ;; I'm not sure whether the way I did things was totally correct
  8. ;; (particularly the justifying of menu items and the user event
  9. ;; handling), so please look over the code, if you have time.  I also
  10. ;; messed around with the standard menus and their behavior near the end
  11. ;; of the file.  Some things I did may not be done right.
  12. ;; 
  13. ;; I had a little time to clean up this thing, but not too much, so some
  14. ;; of my original hacks may still be around.  Let me know if you have any
  15. ;; questions or if you have better ways to do some things.  In
  16. ;; particular, I learned about user-events halfway through this project.
  17. ;; I might have been able to do some of the earlier things better with
  18. ;; user-events.  I like user-events, by the way -- they're like message
  19. ;; passing in OO languages.
  20. ;; 
  21. ;;     -- Bill Burdick
  22. ;;     burdick@octopus.ecn.purdue.edu
  23. ;; 
  24. ;; A few explanations...
  25. ;; 
  26. ;; (load 'wbrooms)
  27. ;;     put this in your .profile.gwm after the standard behaviors are
  28. ;;     reparsed (just like with dvrooms)
  29. ;; 
  30. ;; (wb-add-to-named-room "roomName.barName")
  31. ;;     adds a window to a room.  This implicitly creates the
  32. ;;     room and bar if they are not already there.
  33. ;; 
  34. ;; (wb-find-room "roomName" "barName")
  35. ;;     gets a room by name
  36. ;; 
  37. ;; (wb-add-to-room room)
  38. ;;     adds a window to a room when you already have the room
  39. ;; 
  40. ;; (wb-make-named-room "roomName.barName")
  41. ;;     makes a room (and a bar if that bar doesn't exist, yet).
  42. ;; 
  43. ;; (wb-reattach)
  44. ;;     reattaches all windows to their rooms
  45. ;; 
  46. ;; wbroom.background.name (it's a string)
  47. ;;     the name of a 4-shade color (like Thistle or RosyBrown)
  48. ;;     for the background color of room bars
  49. ;; 
  50. ;; New rooms are added to the right side of their bar.
  51. ;;=============================================================================
  52. ;;
  53. ;; objects
  54. ;; type: room-bar
  55. ;;    a menu with a bar in it containing rooms
  56. ;; property: name
  57. ;;    the name of the room-bar
  58. ;; property: rooms
  59. ;;    a list of the rooms in the room-bar
  60. ;; property: plugs
  61. ;;    a list of the room plugs in the room-bar
  62. ;;
  63. ;; type: room
  64. ;;    a plug
  65. ;; property: name
  66. ;;    the name of the room-bar
  67. ;; property: members
  68. ;;    the windows in the room
  69. ;; property: closed
  70. ;;    the pixmap for the picture displayed when the room is closed
  71. ;; property: open
  72. ;;    the pixmap for the picture displayed when the room is open
  73. ;; property: openp
  74. ;;    whether the room is open
  75.  
  76.  
  77. ;; variables
  78. (defaults-to
  79.   wbroom.horizontal-margin 5
  80.   wbroom.vertical-margin 5
  81.   wbroom.font (font-make "8x13")
  82.   wbroom.background.name "RosyBrown"    ; this color should be a 4-shade color
  83. ; wbroom.background.name "DodgerBlue"
  84.   wbroom.foreground black
  85.   wbroom.borderwidth borderwidth
  86.   wbroom.current ()
  87.   wbroom.loaded ()
  88.   wbroom.room-bars ()
  89.   wbroom.x 0
  90.   wbroom.y 0
  91.   wbroom.item-height ()
  92.   wbroom.item-width ()
  93.   wbroom.menu-item.background.name "NavajoWhite"
  94.   wbroom.menu-label.background.name "goldenrod"
  95. )
  96.  
  97.  
  98. ;(with (m (menu-wob tools-pop) menu-width (width m)) (? "send\n") (send-user-event 'expand m))
  99. ;wb-simple-label-make
  100. ;    make a simple label with name centered in pixmap
  101. (defun wb-simple-label-make (name wd ht fnt)
  102.   (with (l (if (and wd ht)
  103.            (with (l (label-make name fnt)
  104.             w (width l)
  105.             h (height l)
  106.             pix (pixmap-make wd ht))
  107.              (draw-rectangle pix 0 0 wd ht 0 2)
  108.              (draw-text pix
  109.                 wbroom.horizontal-margin ;(/ (- wd w) 2))
  110.                 12
  111.                 fnt
  112.                 name)
  113.              pix)
  114.          (label-make name fnt)))
  115.     l))
  116.  
  117.  
  118. (defun wb-draw-borders (p1 p2 c1 c2 x y w h)
  119.   (with (w-1 (- w 1)
  120.      h-1 (- h 1)
  121.      x+1 (+ x 1)
  122.      y+1 (+ y 1))
  123.     (setq foreground c1)
  124.     (draw-line p1 x y w y)
  125.     (draw-line p1 x+1 y+1 w-1 1)
  126.     (draw-line p1 x y x h)
  127.     (draw-line p1 x+1 y+1 x+1 h-1)
  128.     (draw-line p2 w h w y)
  129.     (draw-line p2 w-1 h-1 w-1 y+1)
  130.     (draw-line p2 w h x h)
  131.     (draw-line p2 w-1 h-1 x+1 h-1)
  132.     (setq foreground c2)
  133.     (draw-line p1 w h w y)
  134.     (draw-line p1 w-1 h-1 w-1 y+1)
  135.     (draw-line p1 w h x h)
  136.     (draw-line p1 w-1 h-1 x+1 h-1)
  137.     (draw-line p2 x y w y)
  138.     (draw-line p2 x+1 x+1 w-1 x+1)
  139.     (draw-line p2 x y x h)
  140.     (draw-line p2 x+1 y+1 x+1 h-1)))
  141.   
  142.  
  143.  
  144. ;wb-labels-make
  145. ;    makes two 2.5d pixmaps for name (on off)
  146. (defun wb-labels-make (name wd ht fnt)
  147.   (with (label-horizontal-margin wbroom.horizontal-margin
  148.      label-vertical-margin wbroom.vertical-margin
  149.      borderwidth 0
  150.      foreground black
  151.      background (color-make (+ wbroom.background.name "2"))
  152.      offpix (wb-simple-label-make name wd ht fnt)
  153.      background (color-make (+ wbroom.background.name "3"))
  154.      onpix (wb-simple-label-make name wd ht fnt))
  155.      (wb-draw-borders offpix onpix (color-make (+ wbroom.background.name "1")) (color-make (+ wbroom.background.name "4")) 0 0 (- (width onpix) 1) (- (height onpix) 1))
  156.     (list offpix onpix)))
  157.  
  158. ; wb-plug-make
  159. ;    makes a 2.5d plug
  160. ;    properties of plug on return:
  161. ;        on: on pixmap
  162. ;        off: off pixmap
  163. ;        name: name given to wb-plug-make
  164. (defun wb-plug-make args
  165.   (with (name (# 0 args)
  166.      wd (# 1 args)
  167.      ht (# 2 args)
  168.      font wbroom.font
  169.      pix (wb-labels-make name wd ht font)
  170.      offpix (# 0 pix)
  171.      onpix (# 1 pix)
  172.      property (+ (list 'off offpix
  173.                'on onpix
  174.                'name name) property))
  175.     (plug-make offpix)))
  176.  
  177.  
  178. ; wb-make-room
  179. ;    makes a room
  180. (defun wb-make-room (name)
  181.   (with (property (+ (list 'members ()
  182.                'openp t
  183.                'registered ())
  184.              property)
  185.      borderwidth 0
  186.      fsm (fsm-make
  187.           (state-make (on map-notify (wb-register-room) open))
  188.           (: open (state-make
  189.              (on (user-event 'raise) (wb-raise-room))
  190.              (on (user-event 'lower) (wb-lower-room))
  191.              (on (user-event 'disable) (wb-disable) disabled-open)
  192.              (on (buttonpress 1 any) (wb-raise-room))
  193.              (on (buttonpress 2 any) (wb-close-room) closed)
  194.              (on (buttonpress 3 any) (wb-lower-room))))
  195.           (: closed (state-make
  196.               (on (user-event 'disable) (wb-disable) disabled-closed)
  197.              (on (buttonpress 2 any) (wb-open-room) open)))
  198.           (: disabled-open (state-make
  199.              (on (user-event 'enable) (wb-enable) open)))
  200.           (: disabled-closed (state-make
  201.              (on (user-event 'enable) (wb-enable) closed)))))
  202.     (wb-plug-make name)))
  203.  
  204.  
  205. ; wb-make-room-control
  206. ;    makes a room control
  207. (defun wb-make-room-control ()
  208.   (with (borderwidth 0
  209.      fsm (fsm-make
  210.           (: s2 (state-make
  211.              (on (buttonpress 1 any) (wb-raise-rooms))
  212.              (on (buttonpress 2 any) (wb-close-rooms) s1)
  213.              (on (buttonpress 3 any) (wb-lower-rooms))))
  214.           (: s1 (state-make (on (buttonpress 2 any) (wb-open-rooms) s2))))
  215.      label-horizontal-margin wbroom.horizontal-margin
  216.      label-vertical-margin wbroom.vertical-margin
  217.      background (color-make (+ wbroom.background.name "2"))
  218.      font wbroom.font
  219.      offpix (label-make " ")
  220.      background (color-make (+ wbroom.background.name "3"))
  221.      onpix (label-make " ")
  222.      property (+ (list 'off offpix
  223.                'on onpix
  224.                'openp t)
  225.              property))
  226.     (wb-draw-borders offpix onpix (color-make (+ wbroom.background.name "1")) (color-make (+ wbroom.background.name "4")) 0 0 (- (width onpix) 1) (- (height onpix) 1))
  227.     (wb-draw-borders offpix onpix (color-make (+ wbroom.background.name "1")) (color-make (+ wbroom.background.name "4")) 4 4 (- (width onpix) 5) (- (height onpix) 5))
  228.     (plug-make offpix)))
  229.  
  230.  
  231. ; wb-is-room-bar
  232. ;    returns whether wob is a room-bar
  233. (defun wb-is-room-bar (obj)
  234.   (member obj wbroom.room-bars))
  235.  
  236.  
  237. ; wb-register-room
  238. ;    register room in menu
  239. (defun wb-register-room ()
  240.   (if (not (# 'registered wob))
  241.       (progn
  242.     (## 'registered wob t)
  243.     (wb-set-bar-rooms window (+ (wb-bar-rooms window) (list wob))))))
  244.  
  245.  
  246. ; wb-room-members
  247. ;    returns all the members of a room
  248. (defun wb-room-members (room)
  249.   (# 'members room))
  250.  
  251.  
  252. ; wb-set-room-members
  253. ;    returns all the members of a room
  254. (defun wb-set-room-members (room mems)
  255.   (## 'members room mems))
  256.  
  257.  
  258. ; wb-bar-members
  259. ;    returns all the members of a bar
  260. (defun wb-bar-members (bar)
  261.   (: mems ())
  262.   (for room (# 'rooms bar)
  263.        (: mems (+ mems (# 'members room))))
  264.   mems)
  265.  
  266.  
  267. ; wb-bar-rooms
  268. ;    returns the rooms in a room-bar
  269. (defun wb-bar-rooms (bar)
  270.   (# 'rooms bar))
  271.  
  272.  
  273. ; wb-set-bar-rooms
  274. ;    sets the rooms in a bar
  275. (defun wb-set-bar-rooms (bar rooms)
  276.   (## 'rooms bar rooms))
  277.  
  278.  
  279. ;wb-enable
  280. (defun wb-enable ()
  281.   (if (# 'openp wob)
  282.       (wb-open-room)))
  283.  
  284.  
  285. ;wb-disable
  286. (defun wb-disable ()
  287.   (with (oldwob wob)
  288.     (if (# 'openp oldwob)
  289.         (progn
  290.           (wb-close-room)
  291.           (## 'openp oldwob t)))))
  292.  
  293.  
  294. ; wb-open-room
  295. ;    map all the windows in the room
  296. (defun wb-open-room ()
  297.   (with (oldwob wob
  298.      wob wob)
  299.     (wob-tile (# 'off oldwob))
  300.     (## 'openp oldwob t)
  301.     (wb-map-wins (wb-room-members oldwob))
  302.     (: wbroom.current wob)))
  303.  
  304.  
  305. ; wb-map-room-members
  306. ;    map each member of the room
  307. (defun wb-map-wins (wins)
  308.   (for window wins
  309.        (if (# 'wbroom-state window)
  310.        (wb-map-window window)
  311.      (map-window window-icon)))
  312.   (wb-raise-wins wins))
  313.  
  314.  
  315.  
  316. ; wb-close-room
  317. ;    unmap all the windows in the room
  318. (defun wb-close-room ()
  319.   (wob-tile (# 'on wob))
  320.   (## 'openp wob ())
  321.   (: wbroom.current wob)
  322.   (wb-unmap-wins (wb-room-members wob)))
  323.  
  324.  
  325.  
  326. ; wb-unmap-room-members
  327. ;    map each member of the room
  328. (defun wb-unmap-wins (wins)
  329.   (for window wins
  330.        (## 'wbroom-state window window-is-mapped)
  331.        (if window-is-mapped (wb-unmap-window window))
  332.        (if (window-icon?)
  333.        (with (window window-icon)
  334.          (if  window-is-mapped (unmap-window window))))))
  335.  
  336.  
  337. ; wb-add-to-room
  338. ;    add this window to a room
  339. (defun wb-add-to-room (room)
  340.   (if (not (member window (wb-room-members room)))
  341.       (with (win window
  342.          wob room)
  343.         (wb-set-room-members room (+ (wb-room-members room) (list win)))
  344.         (## 'wbroom-state window window-is-mapped)
  345.         (with (bar window
  346.            window win)
  347.           (set-x-property "GWM_WBROOM"
  348.                   (+ (# 'name room)
  349.                      "."
  350.                      (# 'name bar)))))))
  351.  
  352.  
  353. ; wb-remove-from-room
  354. ;    remove this window from the room
  355. (defun wb-remove-from-room (room)
  356.   (with (pos (member window (wb-room-members room)))
  357.     (if pos (delete-nth pos (wb-room-members room)))))
  358.  
  359.  
  360. ; wb-add-room-to-bar
  361. ;    adds a room to a room-bar
  362. (defun wb-add-room-to-bar (room bar)
  363.   (## 'plugs bar (+ (# 'plugs bar) (list room)))
  364.   (wb-set-bar-rooms bar ())
  365.   (with (plug-separator 1
  366.      borderwidth 0
  367.      newb (menu-make (eval (+ '(bar-make) (list (wb-make-room-control)) (# 'plugs bar))))
  368.      x (with (wob bar) window-x)
  369.      y (with (wob bar) window-y)
  370.      property (with (wob bar) wob-property)
  371.      newbar (place-menu "wbroombar" newb x y))
  372.     (## (member bar wbroom.room-bars) wbroom.room-bars newbar)
  373.     (with (wob bar)
  374.           (delete-window))))
  375.           
  376.      
  377. ; wb-add-room-to-named-bar
  378. ;    makes a room-bar containing only this room or adds the room
  379. ;    to the existing room-bar
  380. (defun wb-add-room-to-named-bar (room name)
  381.   (: b (wb-find-room-bar name))
  382.   (if b (wb-add-room-to-bar room b)
  383.     (with (borderwidth 0
  384.        b (menu-make (bar-make (wb-make-room-control) room))
  385.        property (+ (list 'name name
  386.                  'plugs (list room)
  387.                  'rooms ())
  388.                property)
  389.        bar (place-menu "wbroombar" b wbroom.x wbroom.y))
  390.       (: wbroom.room-bars (+ wbroom.room-bars (list bar))))))
  391.  
  392.  
  393. (defun wb-add-named-room-to-named-bar (rname bname)
  394.   (wb-add-room-to-named-bar (wb-make-room rname) bname))
  395.  
  396.  
  397. ; wb-find-room-bar
  398. ;    gets the room bar named name
  399. (defun wb-find-room-bar (name)
  400.   (with (ret ())
  401.     (for b wbroom.room-bars
  402.          (if (= (# 'name b) name) (: ret b)))
  403.     ret))
  404.  
  405.  
  406. ; wb-find-room
  407. ;    finds a room in a bar
  408. (defun wb-find-room (rname bname)
  409.   (with (bar (wb-find-room-bar bname)
  410.      ret ())
  411.     (for r (wb-bar-rooms bar)
  412.          (if (= (# 'name r) rname) (: ret r)))
  413.     ret))
  414.     
  415.  
  416. ; wb-flush-rooms
  417. ;    removes a window from all the rooms
  418. ;    add wb-flush-rooms to the global closing code
  419. ;    wbrooms should be loaded before the set-{window,icon} calls
  420. ;    in .profile.gwm
  421. (if (not wbroom.loaded)
  422.     (progn
  423.       (: wbroom.loaded t)
  424.       (: closing (+ closing '((wb-flush-rooms))))))
  425. (defun wb-flush-rooms ()
  426.   (for bar wbroom.room-bars
  427.        (for room (wb-bar-rooms bar)
  428.         (if (member window (wb-room-members room))
  429.         (wb-remove-from-room room))))
  430.   (with (pos (member window wbroom.room-bars))
  431.     (if pos
  432.         (progn
  433.           (wb-map-wins (wb-bar-members window))
  434.           (delete-nth pos wbroom.room-bars))))
  435.   (: wbroom.current ()))
  436.  
  437.  
  438. ; wb-unmap-window
  439. ;    unmap a window and all of its members
  440. (defun wb-unmap-window (win)
  441.   (if (wb-is-room-bar win)
  442.       (wb-unmap-wins (wb-bar-members win)))
  443.   (unmap-window win))
  444.  
  445.  
  446. ; wb-map-window
  447. ;    map a window and all of its members
  448. (defun wb-map-window (win)
  449.   (if (wb-is-room-bar win)
  450.       (for room (wb-bar-rooms win)
  451.        (if (# 'openp room)
  452.            (wb-map-wins (wb-bar-members win)))))
  453.   (map-window win))
  454.  
  455.  
  456. (if (not (boundp 'wb-previous-iconify-window))
  457.     (setq wb-previous-iconify-window iconify-window))
  458. (defun iconify-window ()
  459.   (if (wb-is-room-bar window-window)
  460.     ; (de)iconifing a room bar
  461.       (with (window window-window)
  462.         (: wbroom.current ())
  463.         (if window-is-mapped
  464.         ; iconifing (closing) a dvroom manager
  465.           (wb-unmap-wins (wb-bar-members window))
  466.         ; deiconifing (opening) a dvroom manager
  467.         (for room (wb-bar-rooms window-window)
  468.              (if (# 'openp room)
  469.              (wb-map-wins (wb-room-members room)))))))
  470.         ; (de)iconifing other windows
  471.   (wb-previous-iconify-window))
  472.  
  473.  
  474. ;wb-add-to-named-room
  475. ;    adds window to room named room.bar
  476. (defun wb-add-to-named-room (name)
  477.   (with (names (wb-get-room-and-bar name)
  478.      rname (# 0 names)
  479.      bname (# 1 names)
  480.      room (wb-find-room rname bname))
  481.     (if room (wb-add-to-room room))))
  482.  
  483.  
  484. (defun wb-make-named-room (name)
  485.   (with (names (wb-get-room-and-bar name)
  486.      rname (# 0 names)
  487.      bname (# 1 names))
  488.     (wb-add-named-room-to-named-bar rname bname)))
  489.  
  490. ; wb-get-room-and-bar
  491. ;    returns list of room and bar names from string
  492. (defun wb-get-room-and-bar (name)
  493.   (list (match "\\([^.]*\\)" name 1)
  494.     (match "\\.\\(.*\\)" name 1)))
  495.  
  496. (defun reverse (l)
  497.   (: res (list-make (length l)))
  498.   (: ind (length l))
  499.   (for item l
  500.     (: ind (- ind 1))
  501.     (## ind res item))
  502.   res)
  503.  
  504. (defun wb-reorder-wins (windows)
  505.   (: wins ())
  506.   (for w (list-of-windows 'stacking-order)
  507.        (if (member w windows)
  508.        (: wins (+ wins (list w)))))
  509.   wins)
  510.  
  511.  
  512. ;control functions
  513. (defun wb-raise-rooms ()
  514.   (send-user-event 'raise window))
  515.  
  516.  
  517. (defun wb-lower-rooms ()
  518.   (send-user-event 'lower window))
  519.  
  520.  
  521. (defun wb-open-rooms ()
  522.   (wob-tile (# 'off wob))
  523.   (## 'openp wob t)
  524.   (send-user-event 'enable window))
  525.  
  526.  
  527. (defun wb-close-rooms ()
  528.   (wob-tile (# 'on wob))
  529.   (## 'openp wob ())
  530.   (send-user-event 'disable window))
  531.  
  532.  
  533. ;room functions
  534. (defun wb-raise-room ()
  535.   (wb-raise-wins (wb-room-members wob)))
  536.  
  537. (defun wb-lower-room ()
  538.   (wb-lower-wins (wb-room-members wob)))
  539.  
  540. (defun wb-raise-wins (wins)
  541.   (with (w (wb-reorder-wins wins))
  542.     (for window w
  543.          (if (and (member window wbroom.room-bars)
  544.               window-is-mapped)
  545.          (for room (wb-bar-rooms window)
  546.               (if (# 'openp window)
  547.               (wb-raise-wins (wb-room-members room))))
  548.            (with (window (if (window-is-mapped) window window-icon))
  549.              (raise-window))))))
  550.  
  551.  
  552. (defun wb-lower-wins (wins)
  553.   (with (w (wb-reorder-wins wins))
  554.     (for window (reverse w)
  555.          (if (and (member window wbroom.room-bars)
  556.               window-is-mapped)
  557.          (for room (wb-bar-rooms window)
  558.               (if (# 'openp window)
  559.               (with (window room)
  560.                 (wb-lower-wins (wb-room-members room)))))
  561.            (with (window (if (window-is-mapped) window window-icon))
  562.              (lower-window))))))
  563.  
  564.  
  565. (defun wb-reattach ()
  566.   (for bar wbroom.room-bars
  567.        (for room (wb-bar-rooms bar)
  568.         (wb-set-room-members room ())))
  569.   (for window (list-of-windows)
  570.        (with (window window-window
  571.           name (get-x-property "GWM_WBROOM"))
  572.          (if (< 0 (length name))
  573.          (progn
  574.            (wb-add-to-named-room name)
  575.            (if (and window-is-mapped
  576.                 (not (# 'wbroom-state window)))
  577.                (unmap-window))
  578.            (if (and (not window-is-mapped)
  579.                 (# 'wbroom-state window))
  580.                (map-window)))))))
  581.  
  582.  
  583. (de menu-plug-make (label)
  584.   (if (# (type label) string-types)
  585.       (with (wbroom.horizontal-margin label-horizontal-margin
  586.          wbroom.vertical-margin label-vertical-margin)
  587.         (wb-plug-make label)); wbroom.item-width wbroom.item-height))
  588.     
  589.     (= 'pixmap (type label))
  590.     (plug-make label)
  591.     
  592.     (= 'list (type label))
  593.     (plug-make (eval label))
  594.     
  595.     (trigger-error "Bad menu item declaration")
  596.     ))
  597.  
  598.  
  599. (defun wb-popups-trigger (arg)
  600.   (wb-wob-off)
  601.   (std-popups.trigger arg))
  602.  
  603.  
  604. (defun std-popups.trigger (multi)
  605.   (with (calling-wob wob-parent
  606.      wob wob)
  607.     (setq std-popups.action
  608.       (# 'action wob-property))
  609.     (wob wob-parent)
  610.     (if multi (wob wob-parent))
  611.     (send-user-event 'depop wob t)
  612.     (eval std-popups.action)))
  613.  
  614.  
  615.  
  616. (setq std-popups.fsm
  617.       (fsm-make 
  618.        (: closed
  619.       (state-make 
  620.        (on (user-event 'expand)
  621.            (wb-expand-item))
  622.        (on enter-window (wb-wob-on) opened)
  623.        (on (buttonrelease any any) (std-popups.trigger ()))))
  624.        (: opened
  625.       (state-make
  626.        (on (user-event 'expand)
  627.            (wb-expand-item))
  628.        (on (buttonrelease any any)
  629.            (wb-popups-trigger ())
  630.            closed)
  631.        (on enter-window (wb-wob-on))
  632.        (on leave-window (wb-wob-off))))))
  633.  
  634.  
  635. ;; fsm for multi-items (plugs in bar)
  636. (setq std-popups.multi-fsm
  637.       (fsm-make 
  638.        (: closed 
  639.       (state-make 
  640.        (on enter-window (wb-wob-on) opened)
  641.        (on (buttonrelease any any) (std-popups.trigger t))))
  642.        (: opened
  643.       (state-make
  644.        (on (buttonrelease any any)
  645.            (wb-popups-trigger t)
  646.            closed)
  647.        (on enter-window (wb-wob-on))
  648.        (on leave-window (wb-wob-off))))))
  649.  
  650.  
  651. (df item-make (label action)
  652.     (with (borderwidth 0
  653.        borderpixel pop-label.background
  654.        background pop-item.background
  655.        wbroom.background.name wbroom.menu-item.background.name
  656.        foreground pop-item.foreground
  657.        item (with (fsm std-popups.fsm
  658.                property (+ (list 'action action) property)
  659.                borderwidth 0
  660.                font pop-item.font
  661.                bar-min-width pop-item.height)
  662.               (menu-plug-make label))
  663.        property (+ (list 'item item) property))
  664.       (bar-make
  665.        ()
  666.        item
  667.        ())))
  668.  
  669.     
  670. (de wb-wob-on ()
  671.     (with (wob wob)
  672.       (if (# 'on wob)
  673.           (wob-tile (# 'on wob))
  674.         (progn
  675.           (wob-invert)))))
  676.  
  677.  
  678. (de wb-wob-off ()
  679.     (with (wob wob)
  680.       (if (# 'off wob)
  681.           (wob-tile (# 'off wob))
  682.         (wob-invert))))
  683.  
  684.  
  685. (if (not (boundp 'old-menu-make-from-list))
  686.     (: old-menu-make-from-list menu-make-from-list))
  687. (de menu-make-from-list (l)
  688.     (with (m (old-menu-make-from-list l)
  689.        menu-width (width (menu-wob m)))
  690.       (send-user-event 'expand (menu-wob m))
  691.       m))
  692.  
  693. (de wb-register-item ()
  694.     (if (not (# 'registered wob))
  695.     (progn
  696.       (## 'registered wob t)
  697.       (## 'wobs window (+ (# 'wobs window) (list wob))))))
  698.  
  699.  
  700. (de wb-expand-wob ()
  701.     (if (# 'name wob)
  702.     (with (pix (wb-labels-make
  703.             (# 'name wob)
  704.             (- menu-width 2)
  705.             pop-item.height
  706.             wbroom.font))
  707.           (## 'off wob (# 0 pix))
  708.           (## 'on wob (# 1 pix))
  709.           (wb-wob-off))))
  710.  
  711.  
  712. (df wb-expand-item ()
  713.     (with (wbroom.background.name wbroom.menu-item.background.name)
  714.       (wb-expand-wob)))
  715.  
  716.  
  717. (df wb-expand-label ()
  718.     (with (wbroom.background.name wbroom.menu-label.background.name)
  719.       (wb-expand-wob)))
  720.  
  721.  
  722. (df pop-label-make (label)
  723.   (with (fsm (fsm-make (state-make
  724.             (on (user-event 'expand)
  725.                 (wb-expand-label))))
  726.      borderwidth 0
  727.      borderpixel pop-label.background
  728.      background pop-label.background
  729.      wbroom.background.name wbroom.menu-label.background.name
  730.      foreground pop-label.foreground) 
  731.     (bar-make
  732.      (with (borderwidth 0 font pop-label.font) 
  733.            (menu-plug-make label)))))
  734.  
  735.  
  736. (df multi-item-make list-of-buttons
  737.   (with (
  738.       wbroom.background.name wbroom.menu-item.background.name
  739.       fsm ()
  740.       borderwidth 0 borderpixel pop-label.background
  741.       background pop-item.background
  742.       foreground pop-item.foreground
  743.     )               
  744.     (eval (+ '(bar-make)
  745.     (with (
  746.         borderwidth 1
  747.         fsm std-popups.multi-fsm
  748.         font pop-item.font
  749.         bar-min-width pop-item.height
  750.       )
  751.       (mapfor button list-of-buttons
  752.         (if (and (= 'list (type button))
  753.         (= (length button) 2))
  754.           (with (
  755.           label (# 0 button)
  756.           action (# 1 button)
  757.           property (+ (list 'action action) property)
  758.         )
  759.         (if label
  760.           (menu-plug-make label)))
  761.           (if button
  762.         (with (fsm () borderwidth 0)
  763.           (menu-plug-make button)))
  764. )))))))
  765.  
  766. ;End of wbrooms.gwm
  767.