PluginSupport.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Mon, 26 Apr 2010 19:26:38 +0100
branchjv
changeset 17761 b0e5971141bc
parent 17751 b2273fa8d59f
child 17767 a4a32df3aa5e
permissions -rw-r--r--
Added Lookup and BuiltinLookup classes

"
 COPYRIGHT (c) 2005 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:libbasic' }"

Object subclass:#PluginSupport
	instanceVariableNames:''
	classVariableNames:''
	poolDictionaries:''
	category:'System-Support'
!

!PluginSupport class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2005 by Claus Gittinger
	      All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    Provides support functions to run stx in a browser window as a plugin.
    (actually, it could be started from any other application just the same...)

    [author:]
	Claus Gittinger

    [see also:]
	Smalltalk
"
! !

!PluginSupport class methodsFor:'startup'!

showPluginWarning:message inWindowWithID:windowID
    |messageView|

    messageView := Label new.
    messageView label:message.
    self        
        start:messageView
        inWindowWithID:windowID 
        parameters:#()
!

start:anApplicationOrView inWindowWithID:windowID parameters:parameters
    "open up an application or view in the external browserWindow"

    |v browserWindow|

    browserWindow := ExternalTopView newWithID:windowID.
    browserWindow viewBackground:(Color red).
    browserWindow clear.
    browserWindow width:self getBrowserWindowWidth.
    browserWindow height:self getBrowserWindowHeight.

    (anApplicationOrView isKindOf:ApplicationModel) ifTrue:[
        v := anApplicationOrView window.
    ] ifFalse:[
        v := anApplicationOrView.
    ].
    browserWindow becomeParentOf:v.
    self setPluginWindowHandle:(v id).
!

startClass:anApplicationClass inWindowWithID:windowID parameters:parameters
    "open up a new instance of an application- or view-class in the external browserWindow"

    |applicationOrView|

    (anApplicationClass isSubclassOf:ApplicationModel) ifTrue:[
        applicationOrView := anApplicationClass new.
        applicationOrView allButOpen.
    ] ifFalse:[
        applicationOrView := anApplicationClass new.
    ].

    self
        start:applicationOrView 
        inWindowWithID:windowID 
        parameters:parameters
!

startInBrowserWithWindowID:windowID parameters:parameters
    "take application-info from the browser-parameters,
     and open up a new instance of it in the external browserWindow"

    |appClassName appClass src|

    appClassName := parameters at:'application' ifAbsent:nil.
    appClassName notNil ifTrue:[
        appClass := Smalltalk classNamed:appClassName.
        appClass notNil ifTrue:[
            self
                startClass:appClass
                inWindowWithID:windowID
                parameters:parameters.
            ^ self.
        ].
        self 
            showPluginWarning:'Missing Application Class: ', appClassName
            inWindowWithID:windowID.
        ^ self.
    ].

    src := parameters at:'src' ifAbsent:nil.
    src notNil ifTrue:[
        self halt:'src argument expected'.
        ^ self.
    ].

    self
        start:NewLauncher
        inWindowWithID:windowID
        parameters:parameters.

    "
     |v|

     v := StandardSystemView new.
     v openAndWait.
     self startInBrowserWithWindowID:v id parameters:#().
    "

    "
     |v app|

     v := StandardSystemView new.
     v create.
     app := WorkspaceApplication new.
     app window:v.
     app allButOpen.
     app openWindow.
    "
! !

!PluginSupport class methodsFor:'support'!

getBrowserWindowHeight
%{
    extern int __pluginGetBrowserWindowHeight();

    RETURN (__mkSmallInteger(__pluginGetBrowserWindowHeight()));
%}.
!

getBrowserWindowWidth
%{
    extern int __pluginGetBrowserWindowWidth();

    RETURN (__mkSmallInteger(__pluginGetBrowserWindowWidth()));
%}.
!

setPluginWindowHandle:windowId
%{
    extern void __pluginSetWindow();
#   define HWND         void *

    if (__isExternalAddress(windowId)) {
        HWND hWnd = (HWND)__externalAddressVal(windowId);
        __pluginSetWindow(hWnd);
    }
%}.
! !

!PluginSupport class methodsFor:'documentation'!

version
    ^ '$Id: PluginSupport.st 10517 2010-04-26 18:26:38Z vranyj1 $'
!

version_CVS
    ^ '§Header: /cvs/stx/stx/libbasic/PluginSupport.st,v 1.13 2010/02/01 18:20:21 stefan Exp §'
!

version_SVN
    ^ '$Id: PluginSupport.st 10517 2010-04-26 18:26:38Z vranyj1 $'
! !