implemented
This commit is contained in:
+40
-8
@@ -3,39 +3,71 @@
|
||||
;(require racket-tray)
|
||||
(require "../main.rkt")
|
||||
|
||||
;; This example demonstrates the two common "close to tray" behaviours:
|
||||
;;
|
||||
;; * minimize: handled by racket-tray through #:hide-on-minimize?
|
||||
;; * close [X]: handled by frame%'s normal on-close callback
|
||||
;;
|
||||
;; The frame remains alive in both cases because the tray icon uses its HWND.
|
||||
(define simple%
|
||||
(class frame%
|
||||
(super-new [label "Racket Tray"]
|
||||
[width 400]
|
||||
[height 250])
|
||||
|
||||
(define lbl (new message% [label "Counting tray clicks"] [parent this]
|
||||
[auto-resize #t] [stretchable-width #t]))
|
||||
(define lbl
|
||||
(new message%
|
||||
[label "Counting tray clicks"]
|
||||
[parent this]
|
||||
[auto-resize #t]
|
||||
[stretchable-width #t]))
|
||||
|
||||
(define count 0)
|
||||
|
||||
(define/public (count-next)
|
||||
(set! count (+ count 1))
|
||||
(send lbl set-label (format "Counting tray clicks: ~a" count)))
|
||||
))
|
||||
(set! count (add1 count))
|
||||
(send lbl set-label
|
||||
(format "Counting tray clicks: ~a" count)))
|
||||
|
||||
;; Clicking the window's close button hides the frame instead of
|
||||
;; destroying it. The tray menu's Exit item terminates the application.
|
||||
(define/override (on-close)
|
||||
(send this show #f))))
|
||||
|
||||
(define frame (new simple%))
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
; goal : Show and restore the example frame from the tray.
|
||||
; pre : frame has been created and has not been destroyed.
|
||||
; post : frame is visible and no longer iconized.
|
||||
; result : Unspecified.
|
||||
; internals:
|
||||
; A frame hidden in response to SIZE_MINIMIZED can still retain its
|
||||
; iconized state, so show #t is followed by iconize #f when needed.
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
(define (show-frame)
|
||||
;; A frame hidden after a minimize can still be iconized. Make sure it is
|
||||
;; restored when it is opened from the tray.
|
||||
(send frame show #t)
|
||||
(when (send frame is-iconized?)
|
||||
(send frame iconize #f)))
|
||||
|
||||
(define tray
|
||||
(mk-tray frame
|
||||
"simple.png"
|
||||
(λ ()
|
||||
(send frame count-next)
|
||||
(send frame show #t))))
|
||||
(show-frame))
|
||||
#:hide-on-minimize? #t))
|
||||
|
||||
(tray-set-menu!
|
||||
tray
|
||||
(list
|
||||
(list "Open" (λ () (send frame show #t)))
|
||||
(list "Open" show-frame)
|
||||
'separator
|
||||
(list "Exit"
|
||||
(λ ()
|
||||
(tray-close tray)
|
||||
(send frame show #f)))))
|
||||
(exit)))))
|
||||
|
||||
(send frame show #t)
|
||||
|
||||
Reference in New Issue
Block a user