[Openmcl-devel] Displaying subviews under MS-Windows

Paul Krueger plkrueger at comcast.net
Tue Jul 26 13:40:53 PDT 2011


I'm a mac guy, not windows, but just so you know, your code works just fine on a mac (i.e. the button shows immediately on being added to the window). The only thing I can think to try might be to call (#/setNeedsDisplay: (#/contentView my-window1) #$YES) to force a window re-draw after the button is added. That shouldn't be necessary, but who knows ...

Paul

On Jul 26, 2011, at 3: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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.clozure.com/pipermail/openmcl-devel/attachments/20110726/439ce838/attachment.htm>


More information about the Openmcl-devel mailing list