Creating plug-ins with HIView

View: New views
3 Messages — Rating Filter:   Alert me  

Creating plug-ins with HIView

by Miloslav Bystricky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

We tried to create a new v11 plugin using HIView in the plug-in area.  
Did anybody successfully did that?  Are there any problems and catches  
we should be aware of?

We tried to install WebKit into HIView but immediately run into  
uncought exception - WebKit did not like it is not running in main  
thread. As I understand, 4D should be doing some thread manipulation  
in the background so system events are delivered to HIView in the  
context of its 4D process thread - does this work reliably? Can we  
register and get any Carbon events?

We did not get to windows yet, but I assume we will have the same  
questions there - if we install a child window above external area,  
will it get system events with proper 4D context?

TIA

Peter Bozek
http://www.inforce.sk
**********************************************************************
4D Plugins hosted by 4D, Inc.                      http://www.4D.com/

    Register for 4D Summit 2009 Today
    Early Bird Pricing Ends August 28th - http://www.4D.com/summit

To Unsubscribe:                      mailto:4D-Plugins-off@...
***********************************************************************


Re: Creating plug-ins with HIView

by Rob Laveaux :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 20 jul 2009, at 23:01, Miloslav Bystricky wrote:

> We tried to create a new v11 plugin using HIView in the plug-in  
> area. Did anybody successfully did that?

Yes, I did.

> Are there any problems and catches we should be aware of?

Yes :-)

> We tried to install WebKit into HIView but immediately run into  
> uncought exception - WebKit did not like it is not running in main  
> thread.

As you know 4D's threading model has changed from using setjmp to  
using native OS threads. Some WebKit functions must be called from the  
main thread. You can achieve that with PA_RunInMainProcess. In one of  
my projects I use a helper object which I use to store all arguments I  
need to pass for the function call on the main thread. This makes  
coding simpler. For example:

void CMyPluginArea::adjustBounds( CGRect rect )
{
        if( ! CGRectEqualToRect( rect, this->bounds ) )
        {
                if( IsMainThread() )
                {
                        this->bounds = rect;
                        HIViewSetFrame( this->webview, &this->bounds );
                }
                else
                {
                        CMyPluginMessage message( this, CMyPluginMessage::kAdjustBounds );
                        message.setBounds( rect );
                        message.send();
                }
        }
}

bool CMyPluginArea::IsMainThread()
{
        return ( PA_GetCurrentProcessNumber() == 0 );
}

#pragma mark CMyPluginMessage

CMyPluginMessage:: CMyPluginMessage( CMyPluginArea* area, short action )
{
        this->area = area;
        this->action = action;
}

void CMyPluginMessage::send()
{
        PA_RunInMainProcess( CMyPluginMessage::Execute, (void*) this );
}

void CMyPluginMessage::setBounds( CGRect rect )
{
        this->bounds = rect;
}

void CMyPluginMessage::Execute( void* param )
{
        CMyPluginMessage* message = (CMyPluginMessage*) param;
       
        switch( message->action )
        {
                case kAdjustBounds :
                        message->area->adjustBounds( message->bounds );
                        break;

                // Other actions omitted for brevity
        }
}

HTH,

- Rob Laveaux

--------------------------------------------------------
Pluggers Software
Bleriotlaan 62
2497 BM  Den Haag
The Netherlands

Email: rob.laveaux@...
Website: http://www.pluggers.nl

--------------------------------------------------------


**********************************************************************
4D Plugins hosted by 4D, Inc.                      http://www.4D.com/

    Register for 4D Summit 2009 Today
    Early Bird Pricing Ends August 28th - http://www.4D.com/summit

To Unsubscribe:                      mailto:4D-Plugins-off@...
***********************************************************************


Re: Creating plug-ins with HIView

by Miloslav Bystricky :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


On 21 Jul 2009, at 09:43, Rob Laveaux wrote:

> As you know 4D's threading model has changed from using setjmp to  
> using native OS threads. Some WebKit functions must be called from  
> the main thread. You can achieve that with PA_RunInMainProcess. In  
> one of my projects I use a helper object which I use to store all  
> arguments I need to pass for the function call on the main thread.  
> This makes coding simpler. For example:


Thanks, this helped us a lot. You know if the same holds in Windows -  
does window procedure get events in the 4D process context?

Peter Bozek
http://www.inforce.sk

**********************************************************************
4D Plugins hosted by 4D, Inc.                      http://www.4D.com/

    Register for 4D Summit 2009 Today
    Early Bird Pricing Ends August 28th - http://www.4D.com/summit

To Unsubscribe:                      mailto:4D-Plugins-off@...
***********************************************************************