[Openmcl-devel] Displaying subviews under MS-Windows

Alexander Repenning ralex at cs.colorado.edu
Wed Jul 27 15:10:06 UTC 2011


If you like to do GUI level programming for Windows I suggest

1) do NOT use the current version of CCL as it includes quite ancient versions of Cocotron's DLLs (e.g., AppKit.DLL). I think it would be great for Clozure, especially for the nearby release, to include more recent versions of Cocotron. The old versions are quite buggy. We are supporting the Cocotron project and while there is still a lot of room for improvement we have supported some crucial bug fixes. You can download a version of CCL including the much newer Cocotron DLLs here: http://code.google.com/p/xmlisp/  Hopefully we can find a strategy to get a combination of the latest version of CCL AND Cocotron. I think that would be a good CCL 1.7 release goal

2) In XMLisp Windows (i.e., CCL + Cocotron + 2D/3D gui kit + XML) you can create your first example with very little code (3 lines). Most importantly it works in Windows and on the Mac. Notice, no trickery required with threads etc. You can eval in hemlock buffer, listener, ...




(in-package :xlui)

;;; Option A for the XML phobic 
(add-subviews 
 (make-instance 'application-window)
 (make-instance 'button :text "Hello!" :x 10 :y 10 :width 72 :height 32))





;; Option B :  if you can handle XML and (more generally) also need layout management
<application-window>
  <canvas>
    <button text="Hello!" x="10" y="10" width="72" height="32"/>
  </canvas>
</application-window>





Alex


On Jul 26, 2011, at 2:02 PM, Greg Bennett wrote:

> Good morning from Greg Bennett
> I am trying to understand the relationship between the handling of subviews and
> the display of their host windows/views under MS-Windows. 
> 
> What follows is a blow-by-blow account of my attempts to follow two of the supplied examples, 
> which I realise are directed to those using Mac OS rather than Windows. 
> 
> If I this is not the right place for such posts, or if I have been too verbose, please let me know.
> Perhaps there is documentation about what I observe. If so, I should be delighted to receive a
> pointer to it.
> 
> I have used ;-> to show lines returned by CCL
> 
> Thanks for any and all advice and comment
> Cheers /Greg Bennett
> 
> ;; In Clozure CL Version 1.7-dev-r14869  (WindowsX8632)!
> ;; Running under Windows7 Pro 64bit
> ;; Using 32bit executables and listener 
> 
> ;; Initially, code from ccl/examples/cocoa/ui-elements//HOWTO.html
> (in-package :ccl)
> ;->#<Package "CCL">
> 
> ;; First sequence
> ;; (a) allocate my-window1
> ;; (b) equip it with attributes
> ;; (c) show it
> ;; (d) allocate my-button
> ;; (e) equip it too
> ;; (f) add my-button as a subview to my-window1
> ;; (g) add a label to my-button
> 
> (setf my-window1 (#/alloc (@class ns-window)))
> ;->#<NS-WINDOW [uninitialized] (#x3591640)>
> (ns:with-ns-rect (r 100 100 400 300)
>   (#/initWithContentRect:styleMask:backing:defer: 
>    my-window1 
>    r 
>    (logior  #$NSTitledWindowMask 
>             #$NSClosableWindowMask  
>             #$NSMiniaturizableWindowMask 
>             #$NSResizableWindowMask)
>    #$NSBackingStoreBuffered
>    #$NO))
> ;->;Compiler warnings :
> ;->;   In an anonymous lambda form at position 93: Undeclared free variable MY-WINDOW1
> ;->#<NS-WINDOW <NSWindow 0x03591640> (#x3591640)>  
> (#/makeKeyAndOrderFront: my-window1 nil)
> ;->NIL
> 
> ;;; .. and there is the window
> 
> (setf my-button (#/alloc ns:ns-button))
> ;->#<NS-BUTTON [uninitialized] (#x36981D0)>
> (ns:with-ns-rect (frame 10 10 72 32)
>   (#/initWithFrame: my-button frame)
>   (#/setButtonType: my-button #$NSMomentaryPushInButton)
>   (#/setImagePosition: my-button #$NSNoImage)
>   (#/setBezelStyle: my-button #$NSRoundedBezelStyle))
> ;->;Compiler warnings :
> ;->;   In an anonymous lambda form at position 183: Undeclared free variable MY-BUTTON (4 references)
> ;->NIL  
> (#/addSubview: (#/contentView my-window1) my-button)
> ;->NIL
> 
> ;;; and my-window1 is unchanged in appearance
> 
> ;;; Check on the subviews of my-window1
> 
> (#/subviews (#/contentView my-window1))
> ;->#<NS-MUTABLE-ARRAY (
> ;-> "<NSButton[0x36981d0] frame: {{10, 10}, {72, 32}}>"
> ;-> ) (#x35F19E8)>
> 
> ;;; so the data structure behind my-window1 seems to know about the button
> 
> (let ((label (%make-nsstring "Hello!")))
>   (#/setTitle: my-button label)
>   (#/release label))
> ;->;Compiler warnings :
> ;->;   In an anonymous lambda form at position 57: Undeclared free variable MY-BUTTON
> ;->NIL  
> 
> ;;; nothing shows in my-window1
> 
> ;; Second sequence with my-window2 for my-window1 
> ;; switching adding the subview and showing the window
> ;; (a) allocate my-window2
> ;; (b) equip it with attributes
> ;; (f) add my-button as a subview to my-window2
> ;; (c) show my-window2
> 
> (setf my-window2 (#/alloc (@class ns-window)))
> ;->#<NS-WINDOW [uninitialized] (#x35D8C50)>
> (ns:with-ns-rect (r 100 100 400 300)
>   (#/initWithContentRect:styleMask:backing:defer: 
>    my-window2 
>    r 
>    (logior  #$NSTitledWindowMask 
>             #$NSClosableWindowMask  
>             #$NSMiniaturizableWindowMask 
>             #$NSResizableWindowMask)
>    #$NSBackingStoreBuffered
>    #$NO))
> ;->;Compiler warnings :
> ;->;   In an anonymous lambda form at position 93: Undeclared free variable MY-WINDOW2
> ;->#<NS-WINDOW <NSWindow 0x035d8c50> (#x35D8C50)>   
> (#/addSubview: (#/contentView my-window2) my-button)
> ;->NIL
> (#/makeKeyAndOrderFront: my-window2 nil)   
> ;->NIL
> 
> ;;; There is my-window2 complete with button which shows Hello!
> ;;; Hence the label was indeed added to the button under
> ;;; the First sequence.
> 
> ::: It seems that I can assemble a composite view and then successfully display
> ;;; the whole thing, but not display part of it and then add the rest. But what
> ;;; follows has me wondering about such a simple dichotomy ..
> 
> ;;; Third sequence
> ;;; Now some code from http://trac.clozure.com/ccl/wiki/CocoaBridge
> ;;; but operating in the :ccl package still
> (defclass red-view (ns:ns-view)
>   ()
>   (:metaclass ns:+ns-object))
> ;->#<OBJC:OBJC-CLASS RED-VIEW (#x35EA810)>
> (objc:defmethod (#/drawRect: :void) ((self red-view) (rect :<NSR>ect))
>   (#/set (#/redColor ns:ns-color))
>   (#_NSRectFill (#/bounds self)))
> ;->|-[RedView drawRect:]|
> (defun show-red-window ()
>   (ccl::with-autorelease-pool
>    (let* ((rect (ns:make-ns-rect 0 0 300 300))
>       (w (make-instance 'ns:ns-window
>                 :with-content-rect rect
>                 :style-mask (logior #$NSTitledWindowMask
>                            #$NSClosableWindowMask
>                            #$NSMiniaturizableWindowMask)
>                 :backing #$NSBackingStoreBuffered
>                 :defer t)))
>      (#/setTitle: w #@"Red")
>      (#/setContentView: w (#/autorelease (make-instance 'red-view)))
>      (#/center w)
>      (#/orderFront: w nil)
>      (#/contentView w))))
> ;->SHOW-RED-WINDOW     
> (defmacro with-focused-view (view &body forms)
>   `(when (#/lockFocusIfCanDraw ,view)
>      (unwind-protect
>       (progn , at forms)
>        (#/unlockFocus ,view)
>        (#/flushGraphics (#/currentContext ns:ns-graphics-context))
>        (#/flushWindow (#/window ,view)))))
> ;->WITH-FOCUSED-VIEW
> (setf *v* (show-red-window))
> ;->#<RED-VIEW <RedView[0x45726578] frame: {{3, 3}, {300, 300}}> (#x45726578)>
> 
> ;;; there is the red window
> 
> ;;; Modify the "More drawing" code of this example to
> ;;; (1) draw a line diagonally across the view, and
> ;;; (2) omit the "hello world" text 
> 
> (with-focused-view *v*
>     (let* ((path (#/bezierPath ns:ns-bezier-path)))
>       (#/moveToPoint: path (ns:make-ns-point 10 10))
>       (#/lineToPoint: path (ns:make-ns-point 300 300))
>       (#/stroke path)
>       ))
> ;;; now there is a diagonal line (lower left -> upper right)
> 
> ;;; Add my-button to this
> (#/addSubview: *v* my-button)
> 
> ;;; There is the button too (with "Hello!"), BUT with a piece of the
> ;;; diagonal line missing (from (0,0) to just above the "e"
> ;;; on the button.
> 
> ;;; Thus I have been able to make a piece of a view, show it, and
> ;;; then add to it, unlike what happened in the First sequence. 
> 
> ;;; So is it possible that my-button really was drawn in my first sequence,
> ;;; but in the background colour of its window ?
> 
> ;; add a title to the button
> (#/setTitle: my-button #@"Zootlewirdle")
> ;;;the title has changed, showing just the quartet ("rdle") 
> ;;; so that I can modify part of an already displayed view.
> 
> Again, thanks for any and all assistance.                    
> _______________________________________________
> Openmcl-devel mailing list
> Openmcl-devel at clozure.com
> http://clozure.com/mailman/listinfo/openmcl-devel

Prof. Alexander Repenning

University of Colorado
Computer Science Department
Boulder, CO 80309-430

vCard: http://www.cs.colorado.edu/~ralex/AlexanderRepenning.vcf


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.clozure.com/pipermail/openmcl-devel/attachments/20110727/d3f33cc6/attachment.html>


More information about the Openmcl-devel mailing list