1
#| nokogiri-layout.jl -- arranging groups of slots
3
$Id: layout.jl,v 1.8 2000/11/27 18:13:50 jsh Exp $
5
Copyright (C) 2000 John Harper <john@dcs.warwick.ac.uk>
7
This file is part of sawfish.
9
sawfish is free software; you can redistribute it and/or modify it
10
under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2, or (at your option)
14
sawfish is distributed in the hope that it will be useful, but
15
WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
19
You should have received a copy of the GNU General Public License
20
along with sawfish; see the file COPYING. If not, write to
21
the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24
(define-structure sawfish.ui.layout
26
(export define-layout-type
37
(access rep.structures))
39
(define (define-layout-type name fun) (put name 'nokogiri-layout fun))
41
(define (layout-type name)
42
(or (get name 'nokogiri-layout)
43
;; try to dynamically load it
44
(let ((module-name (intern (concat "sawfish.ui.layouts."
45
(symbol-name name)))))
48
(rep.structures#intern-structure module-name)
49
(get name 'nokogiri-layout))
50
(error (layout-type 'vbox))))))
52
(define (layout-slots name slots)
53
((layout-type (or (car name) name)) name slots))
55
;;; basic layout styles
57
(define (layout-single style slots)
59
(let ((placeholder (gtk-vbox-new nil 0)))
60
(gtk-widget-show placeholder)
63
(let ((w (document-slot (car slots))))
64
(set-slot-layout (car slots) w)
66
(t (error "Too many slots for `single' layout"))))
68
(define-layout-type 'single layout-single)
70
(define (layout-box style slots)
71
(let ((box ((if (eq style 'hbox)
73
gtk-vbox-new) nil box-spacing)))
75
(let ((w (document-slot s)))
77
(if (memq 'expand-vertically (slot-flags s))
78
(gtk-box-pack-start box w t t)
79
(gtk-box-pack-start box w)))) slots)
83
(define-layout-type 'vbox layout-box)
84
(define-layout-type 'hbox layout-box)
86
(define (layout-frame style slots)
87
(let ((frame (gtk-frame-new (cadr style)))
88
(vbox (layout-slots 'vbox slots)))
89
(gtk-container-border-width frame box-border)
90
(gtk-container-add frame vbox)
91
(gtk-widget-show frame)
94
(define-layout-type 'frame layout-frame)
96
;;; including doc strings alongside slot widgets
98
(define (document-slot slot)
99
(let ((doc (slot-doc slot)))
100
(if (or (null doc) (string= doc ""))
101
(slot-gtk-widget slot)
102
(let ((split (tooltip-split doc)))
103
(define (add-tooltip widget)
105
;; tooltips need a window to receive events..
106
(let ((ebox (gtk-event-box-new)))
107
(gtk-container-add ebox widget)
108
(tooltip-set ebox (cdr split))
112
(setq doc (remove-newlines (car split)))
113
(if (memq 'framed (slot-flags slot))
114
(let ((hbox (gtk-hbox-new nil 0))
115
(vbox (gtk-vbox-new nil 0)))
116
(gtk-box-pack-start hbox (gtk-label-new doc))
117
(gtk-box-pack-start vbox hbox)
118
(gtk-box-pack-start vbox (slot-gtk-widget slot) t t)
119
(setq vbox (add-tooltip vbox))
120
(gtk-widget-show-all vbox)
122
(let ((hbox (gtk-hbox-new nil box-spacing))
123
(break (if (string-match "\\\\w" doc)
127
(gtk-box-pack-start hbox (make-label (substring doc 0 break))))
128
(if (memq 'expand-horizontally (slot-flags slot))
129
(gtk-box-pack-start hbox (slot-gtk-widget slot) t t)
130
(gtk-box-pack-start hbox (slot-gtk-widget slot) nil nil))
131
(when (< break (length doc))
133
hbox (make-label (substring doc (+ break 2)))))
134
(setq hbox (add-tooltip hbox))
135
(gtk-widget-show-all hbox)
138
(define (remove-newlines string)
141
(if (string-match "\n" string point)
143
(list* #\space (substring string point (match-start)) out))
144
(apply concat (nreverse (cons (substring string point) out))))))
146
(define (make-label text)
147
(let ((label (gtk-label-new text)))
148
(gtk-label-set-justify label 'left)
149
;; XXX GtkLabel line wrapping sucks, but it stops the
150
;; XXX text disappearing..
151
(gtk-label-set-line-wrap label t)