1 ;;; liece-xemacs.el --- XEmacs specific routines.
2 ;; Copyright (C) 1998-2000 Daiki Ueno
4 ;; Author: Daiki Ueno <ueno@unixuser.org>
9 ;; This file is part of Liece.
11 ;; This program is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; This program is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
24 ;; Boston, MA 02111-1307, USA.
33 (require 'liece-inlines)
34 (require 'liece-crypt)
35 (require 'liece-commands))
37 (autoload 'liece-command-dcc-send "liece-dcc")
38 (defvar liece-nick-popup-menu)
40 (defgroup liece-toolbar nil
41 "Toolbar of your XEmacs"
45 (defgroup liece-toolbar-icons nil
46 "Toolbar Icons of your XEmacs"
48 :prefix "liece-toolbar-"
51 (defmacro liece-xemacs-icon-path (file)
52 "Search icon FILE and return absolete path of the file."
53 `(or (and liece-icon-directory
54 (expand-file-name ,file liece-icon-directory))
55 (let ((path (liece-find-path ,file "icons")))
57 (setq liece-icon-directory
58 (file-name-directory path)))
61 (define-widget 'liece-toolbar-icon 'list
62 "Edit toolbar spec entries"
63 :match (lambda (widget value)
64 (valid-plist-p value))
65 :convert-widget 'liece-toolbar-icon-convert)
68 (defconst liece-toolbar-icon-states
69 '(:up :down :disabled :cap-up :cap-down :cap-disabled)
70 "toolbar event states")
72 (defun liece-toolbar-icon-convert-1 (state)
73 (list 'group :inline t :format "%t: %v"
74 :tag (capitalize (substring (symbol-name state) 1))
75 (list 'const :format "" :value state
76 (list 'radio '(const :tag "none" nil) 'file)))))
78 (defun liece-toolbar-icon-convert (widget)
79 "Widget converter of the WIDGET `liece-toolbar-icon'."
80 (apply #'widget-put widget :args
82 (mapcar #'liece-toolbar-icon-convert-1
83 liece-toolbar-icon-states)))
86 (defcustom liece-use-toolbar (if (featurep 'toolbar)
89 "*If nil, do not use a toolbar.
90 If it is non-nil, it must be a toolbar. The five valid values are
91 `default-toolbar', `top-toolbar', `bottom-toolbar',
92 `right-toolbar', and `left-toolbar'."
93 :type '(choice (const default-toolbar)
94 (const top-toolbar) (const bottom-toolbar)
95 (const left-toolbar) (const right-toolbar)
96 (const :tag "no toolbar" nil))
97 :group 'liece-toolbar)
99 (defcustom liece-toolbar-back-icon '(:up "back.xpm")
101 :type 'liece-toolbar-icon
102 :group 'liece-toolbar-icons)
104 (defcustom liece-toolbar-forward-icon '(:up "forward.xpm")
106 :type 'liece-toolbar-icon
107 :group 'liece-toolbar-icons)
109 (defcustom liece-toolbar-reload-icon '(:up "reload.xpm")
111 :type 'liece-toolbar-icon
112 :group 'liece-toolbar-icons)
114 (defcustom liece-toolbar-home-icon '(:up "home.xpm")
116 :type 'liece-toolbar-icon
117 :group 'liece-toolbar-icons)
119 (defcustom liece-toolbar-search-icon '(:up "search.xpm")
121 :type 'liece-toolbar-icon
122 :group 'liece-toolbar-icons)
124 (defcustom liece-toolbar-location-icon '(:up "location.xpm")
126 :type 'liece-toolbar-icon
127 :group 'liece-toolbar-icons)
129 (defcustom liece-toolbar-crypt-active-icon '(:up "encrypt.xpm")
130 "Crypt button (active)."
131 :type 'liece-toolbar-icon
132 :group 'liece-toolbar-icons)
134 (defcustom liece-toolbar-crypt-inactive-icon '(:up "crypt.xpm")
135 "Crypt button (inactive)."
136 :type 'liece-toolbar-icon
137 :group 'liece-toolbar-icons)
139 (defcustom liece-toolbar-crypt-icon
140 liece-toolbar-crypt-inactive-icon
142 :type 'liece-toolbar-icon
143 :group 'liece-toolbar-icons)
145 (defcustom liece-toolbar-stop-icon '(:up "stop.xpm")
147 :type 'liece-toolbar-icon
148 :group 'liece-toolbar-icons)
150 ;;; @ internal variables
152 (defvar liece-glyph-cache nil)
153 (defvar liece-toolbar-position (if (featurep 'toolbar)
154 default-toolbar-position
157 (defvar liece-toolbar-back-glyph nil)
158 (defvar liece-toolbar-forward-glyph nil)
159 (defvar liece-toolbar-reload-glyph nil)
160 (defvar liece-toolbar-home-glyph nil)
161 (defvar liece-toolbar-search-glyph nil)
162 (defvar liece-toolbar-location-glyph nil)
163 (defvar liece-toolbar-crypt-glyph nil)
164 (defvar liece-toolbar-crypt-active-glyph nil)
165 (defvar liece-toolbar-crypt-inactive-glyph nil)
166 (defvar liece-toolbar-stop-glyph nil)
168 (defvar liece-toolbar-spec-list
169 '([liece-toolbar-back-glyph
170 liece-command-previous-channel t "Previous Channel"]
171 [liece-toolbar-forward-glyph
172 liece-command-next-channel t "Next Channel"]
173 [liece-toolbar-reload-glyph
174 liece-command-list t "List Channel"]
175 [liece-toolbar-home-glyph
176 liece-switch-to-channel-no-1 t "Go Home Channel"]
177 [liece-toolbar-search-glyph
178 liece-command-finger t "Finger"]
179 [liece-toolbar-location-glyph
180 liece-command-join t "Join Channel"]
181 [liece-toolbar-crypt-glyph
182 liece-toolbar-toggle-crypt t "Toggle Crypt Mode"]
183 [liece-toolbar-stop-glyph
184 liece-command-quit t "Quit IRC"]))
188 (defun liece-toolbar-icon-plist-get (spec prop)
189 "Return absolete path of icon file which SPEC has PROP."
190 (let ((icon (plist-get spec prop)))
191 (if icon (liece-locate-icon-file icon))))
193 (defun liece-toolbar-map-button-list (plist)
194 "Make toolbar icon list based on status PLIST."
195 (apply #'toolbar-make-button-list
198 (liece-toolbar-icon-plist-get plist prop))
199 liece-toolbar-icon-states)))
201 (defun liece-xemacs-setup-toolbar (bar &optional force)
202 "Prepare icons of toolbar BAR.
203 If optional argument FORCE is non-nil, always update toolbar."
205 (set-default-toolbar-position liece-toolbar-position)
207 (setq icon (aref spec 0)
210 (substring (prin1-to-string icon) -5 0)
213 (not (symbol-value icon)))
214 (set icon (liece-toolbar-map-button-list plist))))
215 (run-hooks 'liece-xemacs-setup-toolbar-hook)))
217 (add-hook 'liece-xemacs-setup-toolbar-hook 'liece-toolbar-setup-crypt-glyph)
219 (defun liece-toolbar-setup-crypt-glyph ()
220 "Set crypt icons in two states."
221 (setq liece-toolbar-crypt-active-glyph
222 (liece-toolbar-map-button-list liece-toolbar-crypt-active-icon)
223 liece-toolbar-crypt-inactive-glyph
224 (liece-toolbar-map-button-list liece-toolbar-crypt-inactive-icon)))
226 (defun liece-toolbar-toggle-crypt ()
227 "Toolbar button handler for crypt mode."
229 (liece-command-toggle-crypt)
230 (setq liece-toolbar-crypt-glyph
231 (if liece-crypt-mode-active
232 liece-toolbar-crypt-active-glyph
233 liece-toolbar-crypt-inactive-glyph))
234 (when liece-use-toolbar
235 (set-specifier (symbol-value liece-use-toolbar) liece-toolbar-spec-list
238 ;;; @ modeline decoration
240 (defun liece-xemacs-hide-modeline ()
241 "Remove modeline from current window."
242 (set-specifier has-modeline-p nil (current-buffer)))
244 (when (featurep 'scrollbar)
245 (defun liece-xemacs-hide-scrollbars ()
247 ((boundp 'horizontal-scrollbar-visible-p)
248 (set-specifier horizontal-scrollbar-visible-p nil (current-buffer)))
249 ((boundp 'scrollbar-height)
250 (set-specifier scrollbar-height 0 (current-buffer)))))
251 (add-hook 'liece-nick-mode-hook 'liece-xemacs-hide-scrollbars)
252 (add-hook 'liece-channel-list-mode-hook 'liece-xemacs-hide-scrollbars))
254 (add-hook 'liece-nick-mode-hook 'liece-xemacs-hide-modeline)
255 (add-hook 'liece-channel-list-mode-hook 'liece-xemacs-hide-modeline)
257 (defvar liece-xemacs-modeline-left-extent
258 (let ((ext (copy-extent modeline-buffer-id-left-extent)))
261 (defvar liece-xemacs-modeline-right-extent
262 (let ((ext (copy-extent modeline-buffer-id-right-extent)))
265 (add-hook 'liece-command-mode-hook 'liece-setup-toolbar)
267 (defun liece-setup-toolbar ()
268 "Prepare toolbar if wanted."
269 (when liece-use-toolbar
270 (liece-xemacs-setup-toolbar liece-toolbar-spec-list)
271 (set-specifier (symbol-value liece-use-toolbar) liece-toolbar-spec-list
274 (defun liece-xemacs-modeline-glyph ()
275 "Return a glyph of modeline pointer."
280 (if (setq file (liece-locate-icon-file
281 "liece-pointer.xpm"))
282 (list (vector 'xpm :file file)))
283 (if (setq file (liece-locate-icon-file
284 "liece-pointer.xbm"))
285 (list (vector 'xbm :file file)))
286 '([string :data "Liece:"]))))))
287 (set-glyph-face glyph 'modeline-buffer-id)
290 (defun liece-xemacs-mode-line-buffer-identification (line)
291 "Decorate 1st element of `mode-line-buffer-identification' LINE.
292 Modify whole identification by side effect."
293 (let ((id (car line)) chop)
294 (if (and (stringp id) (string-match "^Liece:" id))
296 (setq chop (match-end 0))
299 (let ((glyph (liece-xemacs-modeline-glyph)))
301 (cons liece-xemacs-modeline-left-extent glyph)
302 (cons liece-xemacs-modeline-left-extent
303 (substring id 0 chop))))
304 (cons liece-xemacs-modeline-right-extent
305 (substring id chop)))
309 (defun liece-xemacs-suppress-modeline-format ()
310 "Remove unnecessary information from `modeline-format'."
311 (setq modeline-format
312 (remrassq 'modeline-modified
313 (delq 'modeline-multibyte-status
314 (copy-sequence mode-line-format)))))
318 (defun liece-xemacs-nick-popup-menu (widget &optional event)
319 "Trigger function for popup menu."
320 (let ((pos (widget-event-point event)))
323 (if (eq major-mode 'liece-nick-mode)
324 (liece-nick-update-region))
325 (let ((menu (cdr liece-nick-popup-menu)))
326 (setq menu (nconc (list "IRCHAT" ; title: not displayed
328 "--:shadowDoubleEtchedOut")
329 (mapcar (lambda (spec)
334 (let (popup-menu-titles)
335 (popup-menu menu))))))
337 (fset 'liece-nick-popup-menu 'liece-xemacs-nick-popup-menu)
339 ;;; @ nick buffer decoration
341 (defun liece-xemacs-create-nick-glyph (file &optional string)
342 "Return a glyph of nick indicator from FILE or STRING."
344 (cdr-safe (assoc file liece-glyph-cache))
348 (if (setq file (liece-locate-icon-file file))
349 (list (vector 'xpm :file file)))
351 (list (vector 'string :data string)))))))
352 (push (cons file glyph) liece-glyph-cache)
353 (set-glyph-face glyph 'default)
356 (defun liece-xemacs-glyph-nick-region (start end)
357 "Decorate nick buffer between START and END."
359 (setq start (progn (goto-char start)(beginning-of-line)(point))
360 end (progn (goto-char end)(beginning-of-line 2)(point)))
362 (narrow-to-region start end)
363 (let ((buffer-read-only nil)
364 (inhibit-read-only t)
365 (case-fold-search nil)
366 mark file glyph ext ant)
371 e 'liece-xemacs-glyph-nick-extent)
373 e 'liece-xemacs-glyph-nick-annotation))
375 (current-buffer) start end)
376 (dolist (entry liece-nick-image-alist)
377 (setq mark (car entry)
379 glyph (liece-xemacs-create-nick-glyph
380 file (char-to-string mark)))
384 (when (eq (char-after) mark)
385 (mapcar 'delete-annotation
386 (annotations-at (1+ (point))))
387 (setq ext (make-extent (point) (1+ (point)))
388 ant (make-annotation glyph (1+ (point)) 'text))
389 (set-extent-property ext 'end-open t)
390 (set-extent-property ext 'start-open t)
391 (set-extent-property ext 'invisible t)
392 (set-extent-property ext 'intangible t)
394 ant 'liece-xemacs-glyph-nick-extent ext)
396 ext 'liece-xemacs-glyph-nick-annotation ant))
397 (beginning-of-line 2))))))))
399 (defun liece-xemacs-set-drop-functions (start end)
400 "Initialize drag and drop in DCC between START and END.
401 This function needs window system independent drag and drop
402 support (21.0 b39 or later)"
404 (liece-xemacs-set-drop-functions-buffer
405 (current-buffer) start end)
408 (defun liece-xemacs-set-drop-functions-buffer (&optional buffer start end)
409 "Initialize BUFFER drag and drop DCC settings between START and END.
410 This function needs window system independent drag and drop
411 support (21.0 b39 or later)"
413 (when (and (featurep 'x) (featurep 'dragdrop))
417 (setq start (or start (point-min))
418 end (or end (point-max)))
420 (setq start (line-beginning-position))
422 (setq end (line-beginning-position))
425 (beginning-of-line 2)
428 (narrow-to-region start end)
429 (let (buffer-read-only case-fold-search)
433 (when (extent-property e 'liece-xemacs-drop-extent)
437 (let (st nd nick func)
441 nd (line-end-position)
442 nick (buffer-substring st nd))
443 (mapcar 'delete-annotation (annotations-at nd))
444 (setq func (intern (concat "liece-xemacs-drop-function-" nick)))
446 (list 'lambda (list 'object)
447 (list 'liece-xemacs-drop-function 'object nick)))
448 (let ((ext (make-extent st nd)))
449 (set-extent-property ext 'liece-xemacs-drop-extent t)
450 (set-extent-property ext 'dragdrop-drop-functions (list func)))
451 (beginning-of-line 2))))))))
453 (defun liece-xemacs-drop-function (object nick)
454 "Drag and drop handler.
455 Always two arguments are passed, OBJECT and NICK."
456 (if (and (eq (car object) 'dragdrop_URL)
457 (stringp (cdr object))
458 (string-match "^[^:]*:\\(.*\\)" (cdr object)))
459 (let ((filename (match-string 1 (cdr object))))
460 (liece-command-dcc-send filename nick))))
462 (defadvice easy-menu-add-item
463 (around liece-fix-menu-path-switch-buffer activate)
464 "Advice for XEmacs 20.4 or earlier."
466 (set-buffer liece-command-buffer)
468 (cons (car (ad-get-arg 0)) (ad-get-arg 1))
469 (ad-get-arg 2) (ad-get-arg 3))))
472 (setq liece-x-face-insert-function
473 (function liece-x-face-insert-with-xemacs))
475 (defun liece-x-face-insert-with-xemacs (buffer str nick)
477 (let ((glyph (cdr-safe (assoc nick liece-glyph-cache))))
479 (setq glyph (make-glyph
481 ((and (featurep 'xface)
482 (memq (console-type) '(x mswindows)))
484 (t `[string :data ,str]))))
486 (push (cons nick glyph) liece-glyph-cache)
487 (set-glyph-face glyph 'default)))
489 (goto-char (point-max))
491 (set-extent-end-glyph (make-extent (point) (point)) glyph))))))
498 `(,(if (and (boundp 'filename)
500 (file-exists-p filename))
501 (file-name-directory filename)
505 (when (featurep 'xpm)
507 (defmacro liece-xemacs-logo ()
508 (let ((logo "liece.xpm")
509 (dir (if (and (boundp 'filename)
511 (file-exists-p filename))
512 (file-name-directory filename)
514 (setq logo (expand-file-name logo dir))
515 (if (file-exists-p logo)
516 (let ((buffer (generate-new-buffer " *liece-logo*"))
517 (coding-system-for-read (quote binary))
518 buffer-file-format format-alist
519 insert-file-contents-post-hook
520 insert-file-contents-pre-hook)
524 (insert-file-contents logo)
526 (kill-buffer buffer)))
529 "Warning: file \"%s\" not found." logo)
533 (defconst liece-xemacs-logo
534 (when (featurep 'xpm)
535 (liece-xemacs-logo)))
537 (defun liece-xemacs-splash-at-point (&optional height)
538 "Display splash logo in HEIGHT."
539 (or (bolp) (insert "\n"))
541 (glyph (make-glyph `[xpm :data ,liece-xemacs-logo]))
542 (lh (/ (window-pixel-height) (window-height)))
543 (lw (/ (window-pixel-width) (window-width)))
544 (liece-insert-environment-version nil)
547 (insert-char ?\n (max 0 (/ (- (or height (window-height))
548 (/ (glyph-height glyph) lh))
550 (insert-char ?\ (max 0 (/ (- (window-width)
551 (/ (glyph-width glyph) lw))
553 (when (and (featurep 'xpm) (memq (console-type) '(x mswindows)))
554 (set-extent-end-glyph
555 (make-extent (point) (point))
558 (insert-char ?\ (max 0 (/ (- (window-width) (length (liece-version))) 2)))
560 (insert (liece-version))
561 (and (find-face 'bold-italic)
562 (put-text-property bov (point) 'face 'bold-italic))
564 (set-window-start (get-buffer-window (current-buffer)) (point))
567 (defun liece-xemacs-splash (&optional arg)
568 "Display splash logo interactively.
569 If ARG is given, don't hide splash buffer."
571 (and liece-xemacs-logo
572 (let ((frame (selected-frame))
574 (liece-insert-environment-version nil))
578 (setq config (current-window-configuration))
580 (setq buffer (generate-new-buffer
581 (concat (if arg "*" " *")
582 (liece-version) "*"))))
583 (delete-other-windows)
584 (liece-xemacs-splash-at-point)
585 (set-buffer-modified-p nil)
586 (or arg (sleep-for 2)))
589 (set-window-configuration config)
590 (redisplay-frame frame)))))))
592 (or (eq 'stream (device-type))
593 (liece-xemacs-splash))
596 ;;; @ emulation functions
598 (defun liece-xemacs-map-extents (function)
599 "Map FUNCTION over the extents which overlap the current buffer."
600 (map-extents (lambda (extent ignore)
601 (if (overlayp extent) (funcall function extent)))))
603 (defun liece-xemacs-kill-all-overlays ()
604 "Delete all extents in the current buffer."
605 (liece-xemacs-map-extents #'delete-extent))
607 (defun liece-xemacs-overlays-at (pos)
608 "Return a list of the overlays that contain position POS."
609 (let ((ext (extent-at pos)))
610 (and ext (overlayp ext) (list ext))))
612 (fset 'liece-mode-line-buffer-identification
613 'liece-xemacs-mode-line-buffer-identification)
615 (fset 'liece-suppress-mode-line-format
616 'liece-xemacs-suppress-modeline-format)
618 (fset 'liece-kill-all-overlays 'liece-xemacs-kill-all-overlays)
619 (fset 'liece-map-overlays 'liece-xemacs-map-extents)
620 (fset 'liece-locate-data-directory 'locate-data-directory)
622 (add-hook 'liece-nick-insert-hook 'liece-xemacs-glyph-nick-region)
623 (add-hook 'liece-nick-insert-hook 'liece-xemacs-set-drop-functions)
625 (add-hook 'liece-nick-replace-hook 'liece-xemacs-glyph-nick-region)
626 (add-hook 'liece-nick-replace-hook 'liece-xemacs-set-drop-functions)
628 (provide 'liece-xemacs)
630 ;;; liece-xemacs.el ends here