1. xemacs
  2. xlib

Commits

lg  committed ca759e5

* lisp/xlib-hello.el (XX-Hello): 'Press me' button added, and
'Dismiss' button added to destroy xhello window.

* lisp/xlib-const.el (xlib-version): [new] version variable added.

  • Participants
  • Parent commits df0a185
  • Branches default

Comments (0)

Files changed (3)

File ChangeLog

View file
+2004-03-17  Zajcev Evgeny  <zevlg@yandex.ru>
+
+	* lisp/xlib-hello.el (XX-Hello): 'Press me' button added, and
+	'Dismiss' button added to destroy xhello window.
+
+	* lisp/xlib-const.el (xlib-version): [new] version variable added.
+
 2004-03-15  Norbert Koch  <viteno@xemacs.org>
 
 	* Makefile (VERSION): XEmacs package 1.05 released.

File lisp/xlib-const.el

View file
 
 
 ;;;###autoload
+(defconst xlib-version "xlib(xemacs-package): $Revision$")
+
+;;;###autoload
 (defconst X-CopyFromParent 0 "CopyFromParent opcode.")
 ;;;###autoload
 (defconst X-InputOutput 1 "InputOutput opcode.")

File lisp/xlib-hello.el

View file
 
 ;; Author: Eric M. Ludlam <zappo@gnu.ai.mit.edu>
 ;; Modified: Zajcev Evgeny <zevlg@yandex.ru>
-;; Keywords: xlib, xwem
+;; Keywords: xlib
 ;; X-CVS: $Id$
 
 ;; This file is part of XWEM.
 
 ;;; Commentary:
 
-;; 
+;; This program very close to first hello program that Eric Ludlam
+;; wrote at least arcs, text and lines drawing did not changed, only
+;; buttons added.
 
-(require 'xlib-xlib)
-
-;; NOTE: xlib-xpm does not work under GNU Emacs
-;;(require 'xlib-xpm)
+;; Many hard codes, do not use as real example, this hello world
+;; application needed only to show that xlib works, not as
+;; recommendation how to write applications that uses xlib.
 
 ;;; Code:
+
+
+(defconst XH-event-mask
+  (Xmask-or XM-Exposure XM-StructureNotify XM-KeyPress XM-KeyRelease
+            XM-ButtonPress XM-ButtonRelease))
+
 (defvar XH-gc-1 nil)
 (defvar XH-gc-2 nil)
 (defvar XH-win nil)
 
 (defvar XH-buttons nil "List of buttons.")
+(defvar XH-close-buttons nil "List of buttons to dismiss.")
 
 (defun XX-Hello (dname)
   (interactive "sDisplay: ")
 			      (make-X-Attr :override-redirect t
 					   :background-pixel (XWhitePixel xdpy)
 					   :border-pixel (XBlackPixel xdpy)
-					   :event-mask (Xmask-or XM-Exposure
-								 XM-StructureNotify
-								 XM-KeyPress XM-KeyRelease XM-ButtonPress XM-ButtonRelease))))
+					   :event-mask XH-event-mask)))
 	    (cmap (XDefaultColormap xdpy))
 	    (co (make-X-Color :dpy xdpy)))
 	(if (not (X-Win-p w))
 	  (XMapWindow xdpy w)
 	  (setq XH-win w))))))
 
-;; Events handler
-(defun XH-key-press (xdpy win xev)
-  "keypress event."
-  (message "key press."))
-
-(defun XH-key-release (xdpy win xev)
-  "keyrelease event."
-  (message "key release."))
-  
 (defun XH-button-press (xdpy win xev)
   "Button press event."
   (let ((x (X-Event-xbutton-event-x xev))
 	(y (X-Event-xbutton-event-y xev)))
-    (if (and (>= x 20)
-	     (<= x (+ 20 (length (caar XH-buttons))))
-	     (>= y 20)
-	     (<= y (+ 20 (length (car XH-buttons)))))
-	(progn
-	  (XH-show-button xdpy win 20 20 1)
-	  (message "Hellow world!")
-	  ))))
+    (cond ((and (>= x 20)
+                (<= x (+ 20 (X-Image-width (nth 1 XH-buttons))))
+                (>= y 20)
+                (<= y (+ 20 (X-Image-height (nth 1 XH-buttons)))))
+           (XH-show-button xdpy win 20 20 1)
+           (message "Hellow world!"))
+
+          ((and (>= x 20)
+                (<= x (+ 20 (X-Image-width (nth 1 XH-close-buttons))))
+                (>= y 60)
+                (<= y (+ 60 (X-Image-height (nth 1 XH-close-buttons)))))
+
+           (XH-show-close-button xdpy win 20 60 1)
+           (message "XH: Exiting  ..")
+           (XSelectInput xdpy win 0)
+           (XDestroyWindow xdpy win))
+          )
+    ))
 
 (defun XH-button-release (xdpy win xev)
   "Button release event."
   (XDrawArc xdpy w XH-gc-1 50 50 20 20 0 360)
   (XFillArc xdpy w XH-gc-2 55 55 10 10 0 360)
   
-  ;; NOTE: xlib-xpm does not work unde GNU Emacs
-;;  (XH-show-button xdpy w 20 20 0)
+  ;; Show 'Press me' button
+  (XH-show-button xdpy w 20 20 0)
+
+  ;; Show 'Dismiss' button
+  (XH-show-close-button xdpy w 20 60 0)
   )
 
 (defun XH-events-handler (xdpy w xev)
   "X hello events dispatcher."
   (X-Event-CASE xev
     (:X-Expose
+     (message "XH got Exposure event ..")
      (XH-expose xdpy w xev))
 
     (:X-KeyPress
-     (XH-key-press xdpy w xev))
+     (message "XH got KeyPress event .."))
 
     (:X-KeyRelease
-     (XH-key-release xdpy w xev))
+     (message "XH got KeyRelease event .."))
 
     (:X-ButtonPress
+     (message "XH got ButtonPress event ..")
      (XH-button-press xdpy w xev))
 
     (:X-ButtonRelease
+     (message "XH got ButtonRelease event ..")
      (XH-button-release xdpy w xev))
 
+    (:X-DestroyNotify
+     (XCloseDisplay xdpy)
+     (setq XH-win nil
+           XH-buttons nil
+           XH-close-buttons nil))
+
     (t (message "XH Got event: %d" (X-Event-type xev)))))
-   
-(defun XH-events-handler-old (xdpy w xev)
-  (cond ((= (X-Event-type xev) X-Expose)
-	 (XH-expose xdpy w xev))
-
-	((= (X-Event-type xev) X-KeyPress)
-	 (XH-key-press xdpy w xev))
-
-	((= (X-Event-type xev) X-KeyRelease)
-	 (XH-key-release xdpy w xev))
-
-	(t (message "XH Got event: %d" (X-Event-type xev)))))
-
 
 (defun XH-show-button (dpy win x y &optional state)
   "Show 'Press Me' button."
   (unless state
     (setq state 0))
 
-  (X:xpm-put-image dpy 16 win x y (nth state XH-buttons)))
+  (XImagePut dpy (XDefaultGC dpy) win x y (nth state XH-buttons)))
 
+(defun XH-show-close-button (dpy win x y &optional state)
+  "Show 'Dismiss' button."
+  (unless XH-close-buttons
+    (require 'xpm-button)
+    (let ((buts (xpm-button-create "Dismiss" 4 "Red4" "gray80")))
+      (setq XH-close-buttons
+            (mapcar (lambda (but)
+                      (X:xpm-img-from-data dpy (aref but 2)))
+                    buts))))
+
+  (unless state
+    (setq state 0))
+  
+  (XImagePut dpy (XDefaultGC dpy) win x y (nth state XH-close-buttons)))
+
+
 (provide 'xlib-hello)
 
 ;;; xlib-hello.el ends here