From fbbab97b3949432f241635988d190d665b09af57 Mon Sep 17 00:00:00 2001 From: David Botton Date: Thu, 11 Feb 2021 19:01:21 -0500 Subject: [PATCH] fixed current window issues --- clog-element.lisp | 2 +- clog-gui.lisp | 66 +++++++++++++++++++++++++++++++++---------- clog.lisp | 5 +++- demos/03-demo.lisp | 70 +++++++++++++++++++++++++++------------------- 4 files changed, 98 insertions(+), 45 deletions(-) diff --git a/clog-element.lisp b/clog-element.lisp index dd57d17..aa9562e 100644 --- a/clog-element.lisp +++ b/clog-element.lisp @@ -1267,7 +1267,7 @@ Note: z-index only works on Elements with Position Type of absolute, relative and fixed.")) (defmethod z-index ((obj clog-element)) - (style obj "z-index")) + (parse-integer (style obj "z-index") :junk-allowed t)) (defgeneric set-z-index (clog-element value) (:documentation "Set z-index VALUE for CLOG-ELEMENT")) diff --git a/clog-gui.lisp b/clog-gui.lisp index 4019258..ebd4ab3 100644 --- a/clog-gui.lisp +++ b/clog-gui.lisp @@ -45,7 +45,11 @@ :documentation "Location of the left side or width relative to pointer during drag") (drag-y :accessor drag-y - :documentation "Location of the top or height relative to pointer during drag"))) + :documentation "Location of the top or height relative to pointer during drag") + (on-window-change + :accessor on-window-change + :initform nil + :documentation "Fired when foreground window changed."))) ;;;;;;;;;;;;;;;;;;;;; ;; create-clog-gui ;; @@ -179,7 +183,49 @@ icon ⤢ and full screen mode.")) on-click)) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; Implementation - Windows +;; Implementation - Window System +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;;;;;;;;;;;;;;;;;;;; +;; current-window ;; +;;;;;;;;;;;;;;;;;;;; + +(defgeneric current-window (clog-obj) + (:documentation "Get the current selected clog-gui-window")) + +(defmethod current-window ((obj clog-obj)) + (let ((app (connection-data-item obj "clog-gui"))) + (current-win app))) + +;;;;;;;;;;;;;;;;;;;;;;;;;; +;; set-on-window-change ;; +;;;;;;;;;;;;;;;;;;;;;;;;;; + +(defgeneric set-on-window-change (clog-obj handler) + (:documentation "Set the on-window-change HANDLER. +The on-window-change clog-obj received is the new window")) + +(defmethod set-on-window-change ((obj clog-obj) handler) + (let ((app (connection-data-item obj "clog-gui"))) + (setf (on-window-change app) handler))) + +(defmethod fire-on-window-change (obj app) + "Fire handler if set. Change the value of current-win to clog-obj (Private)" + (unless obj + (let (new-order + (order -9999)) + (maphash (lambda (key value) + (setf new-order (z-index value)) + (when (>= new-order order) + (setf order new-order) + (setf obj value))) + (windows app)))) + (setf (current-win app) obj) + (when (on-window-change app) + (funcall (on-window-change app) obj))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; Implementation - Individual Windows ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defclass clog-gui-window (clog-element) @@ -261,7 +307,7 @@ icon ⤢ and full screen mode.")) (t (format t "Warning - invalid data-drag-type attribute"))) (setf (z-index (drag-obj app)) (incf (last-z app))) - (setf (current-win app) (drag-obj app)) + (fire-on-window-change (drag-obj app) app) (setf (drag-y app) (- pointer-y obj-top)) (setf (drag-x app) (- pointer-x obj-left))) (cond (perform-drag @@ -366,22 +412,12 @@ icon ⤢ and full screen mode.")) (when (fire-on-window-can-close win) (remhash (format nil "~A" html-id) (windows app)) (remove-from-dom win) + (fire-on-window-change nil app) (fire-on-window-close win)))) (setf (gethash (format nil "~A" html-id) (windows app)) win) - (setf (current-win app) win) + (fire-on-window-change win app) win)) -;;;;;;;;;;;;;;;;;;;; -;; current-window ;; -;;;;;;;;;;;;;;;;;;;; - -(defgeneric current-window (clog-obj) - (:documentation "Get the current selected clog-gui-window")) - -(defmethod current-window ((obj clog-obj)) - (let ((app (connection-data-item obj "clog-gui"))) - (current-win app))) - ;;;;;;;;;;;;;;;;;; ;; window-title ;; ;;;;;;;;;;;;;;;;;; diff --git a/clog.lisp b/clog.lisp index 6855f00..83950b9 100644 --- a/clog.lisp +++ b/clog.lisp @@ -665,8 +665,11 @@ embedded in a native template application.)" (create-gui-menu-full-screen generic-function) (create-gui-menu-icon generic-function) - "CLOG-GUI - Windows" + "CLOG-GUI - Window System" (current-window generic-function) + (set-on-window-change generic-function) + + "CLOG-GUI - Individual Windows" (clog-gui-window class) (create-gui-window generic-function) (window-title generic-function) diff --git a/demos/03-demo.lisp b/demos/03-demo.lisp index 66eeac5..b0652dc 100644 --- a/demos/03-demo.lisp +++ b/demos/03-demo.lisp @@ -89,46 +89,60 @@ (defun do-ide-file-save (obj) (if (equalp (window-title (current-window obj)) "New Window") (do-ide-file-save-as obj) - (write-file (js-query obj (format nil "editor_~A.getValue()" - (html-id (current-window obj)))) - (window-title (current-window obj))))) + (let* ((cw (current-window obj)) + (fname (window-title cw))) + (write-file (js-query obj (format nil "editor_~A.getValue()" + (html-id cw))) + fname) + (setf (window-title cw) "SAVED") + (sleep 2) + (setf (window-title cw) fname)))) (defun do-ide-file-save-as (obj) (let ((cw (current-window obj))) - (get-file-name obj "Save As.." - (lambda (fname) - (setf (window-title cw) fname) - (write-file (js-query obj (format nil "editor_~A.getValue()" - (html-id cw))) - fname))))) + (when cw + (get-file-name obj "Save As.." + (lambda (fname) + (setf (window-title cw) fname) + (write-file (js-query obj (format nil "editor_~A.getValue()" + (html-id cw))) + fname)))))) (defun do-ide-edit-copy (obj) - (let* ((app (connection-data-item obj "app-data"))) - (setf (copy-buf app) (js-query obj (format nil "editor_~A.getCopyText();" - (html-id (current-window obj))))))) + (let ((cw (current-window obj))) + (when cw + (let* ((app (connection-data-item obj "app-data"))) + (setf (copy-buf app) (js-query obj (format nil "editor_~A.getCopyText();" + (html-id cw)))))))) (defun do-ide-edit-cut (obj) - (do-ide-edit-copy obj) - (js-execute obj (format nil "editor_~A.execCommand('cut')" - (html-id (current-window obj))))) + (let ((cw (current-window obj))) + (when cw + (do-ide-edit-copy obj) + (js-execute obj (format nil "editor_~A.execCommand('cut')" + (html-id cw)))))) (defun do-ide-edit-paste (obj) - (let* ((app (connection-data-item obj "app-data"))) - (js-execute obj (format nil "editor_~A.execCommand('paste', '~A')" - (html-id (current-window obj)) - (escape-string (copy-buf app)))))) + (let ((cw (current-window obj))) + (when cw + (let ((app (connection-data-item obj "app-data"))) + (js-execute obj (format nil "editor_~A.execCommand('paste', '~A')" + (html-id cw) + (escape-string (copy-buf app)))))))) (defun do-ide-lisp-eval-file (obj) - (let* ((form-string (js-query obj (format nil "editor_~A.getValue()" - (html-id (current-window obj))))) - (result (capture-eval form-string))) - - (do-ide-file-new obj) - (js-execute obj (format nil "editor_~A.setValue('~A');editor_~A.moveCursorTo(0,0);" - (html-id (current-window obj)) - (escape-string result) - (html-id (current-window obj)))))) + (let ((cw (current-window obj))) + (when cw + (let* ((form-string (js-query obj (format nil "editor_~A.getValue()" + (html-id (current-window obj))))) + (result (capture-eval form-string))) + + (do-ide-file-new obj) + (js-execute obj (format nil "editor_~A.setValue('~A');editor_~A.moveCursorTo(0,0);" + (html-id cw) + (escape-string result) + (html-id cw))))))) (defun do-ide-help-about (obj) (let* ((app (connection-data-item obj "app-data"))