<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<META NAME="Generator" CONTENT="MS Exchange Server version 6.5.7638.1">
<TITLE>Menus Experiment</TITLE>
</HEAD>
<BODY>
<!-- Converted from text/plain format -->

<P><FONT SIZE=2>Hi all,<BR>
<BR>
This time I have a little menus experiment. Again all you should have to do is change the path to RDNZL itself.<BR>
<BR>
Have fun!<BR>
<BR>
Regards,<BR>
<BR>
Matthew<BR>
<BR>
;; ========================================================================<BR>
;; Menus Experiment.<BR>
;;<BR>
;; Matthew O'Connor<BR>
;;<BR>
;; In this experiment I create some menus. I link the menus back to<BR>
;; callbacks when they are pressed and even control the state of the 'Save'<BR>
;; menu item by pressing the 'Save' or 'Save As' menu items.<BR>
;;<BR>
;; As usual there is no warranty. Use at your own peril. I am relatively<BR>
;; new to Lisp so you are warned.<BR>
<BR>
;; NOTE: You need to modify this to point to the location of RDNZL on your system.<BR>
(load "../RDNZL/rdnzl-0.12.0/load.lisp")<BR>
<BR>
(rdnzl:enable-rdnzl-syntax)<BR>
<BR>
(rdnzl:import-types "System.Windows.Forms"<BR>
                    "Application" "Form" "MenuStrip" "ToolStripMenuItem"<BR>
                    "ToolStripSeparator" "MessageBox" "MessageBoxButtons"<BR>
                    "MessageBoxIcon")<BR>
(rdnzl:use-namespace "System.Windows.Forms")<BR>
<BR>
;; Display a message in a message box.<BR>
(defun message(text &optional (caption "Message"))<BR>
  [MessageBox.Show text caption<BR>
    ;; we want the message box to have just the "OK" button<BR>
    [$MessageBoxButtons.OK]<BR>
    ;; We want an exclamation mark as the icon.<BR>
    [$MessageBoxIcon.Information]]<BR>
    nil)<BR>
<BR>
;; Create a menu item and add it to the supplied menu strip.<BR>
(defun create-menu (menu-strip-item x)<BR>
  (let ((menu (rdnzl:new "ToolStripMenuItem" (second x))))<BR>
    ;; Bind the menu to the sybmol.<BR>
    (setf (symbol-value (first x)) menu)<BR>
    ;; Add the callback if one is supplied.<BR>
    (if (cddr x)<BR>
        [+Click menu (rdnzl:new "System.EventHandler" (car (cddr x)))])<BR>
    (if (cdddr x)<BR>
        (setf [%Image menu] (rdnzl:property "Resources" (car (cdddr x)))))<BR>
    ;; Add the menu item to the parent.<BR>
    [Add [%DropDownItems menu-strip-item] menu]))<BR>
<BR>
;; Create a menu splitter and add it to the supplied menu strip.<BR>
(defun create-splitter (menu-strip-item)<BR>
  [Add [%DropDownItems menu-strip-item] (rdnzl:new "ToolStripSeparator")])<BR>
<BR>
;; Add either a menu item or a splitter to the supplied menu strip.<BR>
(defun add-menus (menu-strip-item menus)<BR>
  (mapcar #'(lambda (x) (if (= (length x) 1)<BR>
                            (create-splitter menu-strip-item)<BR>
                          (create-menu menu-strip-item x)))<BR>
          menus))<BR>
<BR>
;; Build the menus.<BR>
(defun build-menus (menu-strip menus)<BR>
  (mapcar #'(lambda (x) (let ((menu (rdnzl:new "ToolStripMenuItem" (second x))))<BR>
                          ;; Bind the menu to the symbol<BR>
                          (setf (symbol-value (first x)) menu)<BR>
                          ;; Take care of the children.<BR>
                          (add-menus menu (third x))<BR>
                          ;; Add the menu to the MenuStrip.<BR>
                          [Add [%Items menu-strip] menu])) menus))<BR>
<BR>
<BR>
<BR>
;; Callbacks.<BR>
(defun file-new-clicked (object event)<BR>
  (message "file-new-clicked!!"))<BR>
<BR>
(defun file-open-clicked (object event)<BR>
  (message "file-open-clicked!!"))<BR>
<BR>
;; Disable the Save menu item.<BR>
(defun file-save-clicked (object event)<BR>
  (message "Disabling Save!")<BR>
  (setf [%Enabled menu-file-save] nil))<BR>
<BR>
;; Enable the Save menu item.<BR>
(defun file-save-as-clicked (object event)<BR>
  (message "Enabling Save!")<BR>
  (setf [%Enabled menu-file-save] t))<BR>
<BR>
;; Exit the application<BR>
(defun file-exit-clicked (object event)<BR>
  [Application.Exit])<BR>
<BR>
(defun edit-undo-clicked (object event)<BR>
  (message "edit-undo-clicked!!"))<BR>
(defun edit-redo-clicked (object event)<BR>
  (message "edit-redo-clicked!!"))<BR>
<BR>
;; Create my experimental menu system.<BR>
(defun create-menus (menu-strip)<BR>
  (setf menus '((menu-file "File"<BR>
                 ((menu-file-new "New" file-new-clicked)<BR>
                  (menu-file-open "Open" file-open-clicked)<BR>
                  (menu-file-save "Save" file-save-clicked)<BR>
                  (menu-file-save-as "Save As" file-save-as-clicked)<BR>
                  (menu-file-splitter)<BR>
                  (menu-file-exit "Exit" file-exit-clicked)))<BR>
                (menu-edit "Edit"<BR>
                 ((menu-edit-undo "Undo" edit-undo-clicked)<BR>
                  (menu-edit-redo "Redo" edit-redo-clicked)))<BR>
                (menu-help "Help")))<BR>
  (build-menus menu-strip menus))<BR>
<BR>
(defun run-menus-experiment ()<BR>
  (let ((menu-strip (rdnzl:new "MenuStrip"))<BR>
        (form (rdnzl:new "Form")))       <BR>
    (setf [%Text form] "Menus Experiment")<BR>
<BR>
    [Add [%Controls form] menu-strip]<BR>
    (create-menus menu-strip)<BR>
    [Application.Run form]))<BR>
<BR>
(run-menus-experiment)<BR>
<BR>
(rdnzl:disable-rdnzl-syntax)<BR>
<BR>
</FONT>
</P>

</BODY>
</HTML>