;; a sample special-purpose customisation for framemaker windows

;;=============================================================================
;; framemaker windows
;;=============================================================================
;; frame windows: Maker.name
;; where name is *kit (makerkit, dockit) for main windows
;; other for popups

;; frame icons:
(setq frame-icon-color.1 (color-make "RoyalBlue1"))
(setq frame-icon-font.1 pop-item.font)
(setq frame-icon-color.2 (color-make "RoyalBlue2"))
(setq frame-icon-font.2 small-font)
(setq frame-inactive-color frame-icon-color.1)
(setq frame-active-color (color-make "RoyalBlue4"))

;; frame windows:
;; main windows:
(set-window Maker.dockit (simple-win
    'background frame-inactive-color
    'active.background frame-active-color
    'label.background frame-inactive-color
))
;; popups:
(set-window Maker (simple-win
    'map-on-raise t
    'font small-font
    'background frame-inactive-color
    'active.background frame-active-color
    'label.background frame-inactive-color
))

(require 'simple-icon)

;; an icon decoration for framemaker
(set-icon-window Maker
  (if (= "makerkit" window-client-name) ; top window(menu): use frame pixmap
    (simple-icon 'background frame-icon-color.2)

    (match ".*kit" window-client-name)
    (progn				; main edit windows: icon name
      (simple-icon 'background frame-icon-color.1
	'simple-icon.plug-name (+ "[ " window-icon-name " ]")
	'simple-icon.no-center-plug t
	'font frame-icon-font.1
      )
    )

					; all popups, use a smaller name
    (with (name (match "FrameMaker - \\(.*\\)$" window-name 1))
      (if (= name "")
	(setq name window-name)
      )
      (simple-icon 'background frame-icon-color.2
	'font frame-icon-font.2
	'simple-icon.plug-name name)
)))

;; center main frame windows in screen if they map offscreen, 
;; make frame popups appear under cursor

(set-placement Maker
  (lambda (f) (if f 
      (if 
	(match ".*kit" window-client-name)
	(if (or (< window-x 0) (< window-y 0))
	  (move-window 0 0)
	)
	
	t
	(with (mouse-pos (current-mouse-position)
	    x (# 0 mouse-pos)
	    y (# 1 mouse-pos)
	    xe 0
	    ye 0
	  )
	  (setq x (- x (/ window-width 2)))
	  (setq y (- y (/ window-height 2)))
	  (setq xe (+ x (window-width)))
	  (setq ye (+ y (window-height)))
	  (if (< x 0) (setq x 0))
	  (if (< y 0) (setq y 0))
	  (if (> xe screen-width) (setq x (- screen-width
		(window-width)
	  )))
	  (if (> ye screen-height) (setq y (- screen-height
		(window-height)
	  )))
	  (move-window x y)
)))))

