<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: MtaFop.hxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: rt $ $Date: 2005-09-08 23:50:09 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _MTAFOP_HXX_
#define _MTAFOP_HXX_

#ifndef _SAL_TYPES_H_
#include <sal/types.h>
#endif

#ifndef _RTL_USTRING_
#include <rtl/ustring>
#endif

#ifndef _OSL_MUTEX_HXX_
#include <osl/mutex.hxx>
#endif

#include <utility>
#include <objidl.h>
#include <shlobj.h>

#ifndef _WINIMPLHELPER_HXX_
#include "..\misc\WinImplHelper.hxx"
#endif

//----------------------------------------------------------------
// a simple helper class used to provide a buffer for different
// Win32 file and directory functions
//----------------------------------------------------------------

class CAutoPathBuff
{
public:
    CAutoPathBuff( size_t size = 0 )
    {
        if (0 == size)
            size = 32000; // max path length under Win2000

        pBuff = new sal_Unicode[size];

        OSL_POSTCOND(pBuff,"Could not allocate path buffer");
    }

    ~CAutoPathBuff( )
    {
        delete [] pBuff;
    }

    operator sal_Unicode*( )
    {
        OSL_PRECOND( pBuff, \
            "No path buffer allocated" );
        return pBuff;
    }

    sal_Unicode* get( )
    {
        OSL_PRECOND( pBuff, \
            "No path buffer allocated" );
        return pBuff;
    }

private:
    sal_Unicode* pBuff;
};

//--------------------------------------------------------
// the Mta-Ole clipboard class is for internal use only!
// only one instance of this class should be created, the
// user has to ensure this!
// the class is not thread-safe because it will be used
// only from within the clipboard service and the methods
// of the clipboard service are already synchronized
//--------------------------------------------------------

class CMtaFolderPicker
{
public:
    CMtaFolderPicker( sal_uInt32 Flags );
    virtual ~CMtaFolderPicker( );

    // shell functions
    sal_Bool SAL_CALL browseForFolder( );

    virtual void  SAL_CALL setDisplayDirectory( const rtl::OUString& aDirectory );
    virtual rtl::OUString  SAL_CALL getDisplayDirectory( );
    virtual rtl::OUString SAL_CALL getDirectory( );

    virtual void SAL_CALL setDescription( const rtl::OUString& aDescription );

    virtual void SAL_CALL setTitle( const rtl::OUString& aTitle );
    rtl::OUString  SAL_CALL getTitle( );

    //-----------------------------------------------------
    // XCancellable
    //-----------------------------------------------------

    virtual void SAL_CALL cancel( );

protected:
    void SAL_CALL enableOk( sal_Bool bEnable );
    void SAL_CALL setSelection( const rtl::OUString& aDirectory );
    void SAL_CALL setStatusText( const rtl::OUString& aStatusText );

    virtual void SAL_CALL onInitialized( );
    virtual void SAL_CALL onSelChanged( const rtl::OUString& aNewPath );
    virtual sal_uInt32 SAL_CALL onValidateFailed( sal_Unicode* lpInvalidPath );

private:
    // helper functions
    LPITEMIDLIST  SAL_CALL getItemIdListFromPath( const rtl::OUString& aDirectory );
    rtl::OUString SAL_CALL getPathFromItemIdList( LPCITEMIDLIST lpItemIdList );
    void SAL_CALL releaseItemIdList( LPITEMIDLIST lpItemIdList );

    unsigned int run( );

    // create a hidden windows which serves as an request
    // target; so we guarantee synchronization
    sal_Bool SAL_CALL createStaRequestWindow( );

    //---------------------------------------------------------------
    // message handler functions; remeber these functions are called
    // from a different thread context!
    //---------------------------------------------------------------

    sal_Bool SAL_CALL onBrowseForFolder( );

    static LRESULT CALLBACK StaWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
    static unsigned int WINAPI StaThreadProc( LPVOID pParam );

    static int CALLBACK FolderPickerCallback( HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData );

protected:
    HWND m_hwnd;

private:
    ATOM SAL_CALL RegisterStaRequestWindowClass( );
    void SAL_CALL UnregisterStaRequestWindowClass( );

private:
    HANDLE                      m_hStaThread;
    unsigned                    m_uStaThreadId;
    HANDLE                      m_hEvtThrdReady;
    HWND                        m_hwndStaRequestWnd;
    rtl::OUString               m_dialogTitle;
    rtl::OUString               m_Description;
    rtl::OUString               m_displayDir;
    rtl::OUString               m_SelectedDir;
    BROWSEINFOW                 m_bi;
    CAutoPathBuff               m_pathBuff;
    HINSTANCE                   m_hInstance;

    // the request window class has to be registered only
    // once per process, so multiple instance of this class
    // share the registered window class
    static ATOM       s_ClassAtom;
    static osl::Mutex s_Mutex;
    static sal_Int32  s_StaRequestWndRegisterCount;

// prevent copy and assignment
private:
    CMtaFolderPicker( const CMtaFolderPicker& );
    CMtaFolderPicker& operator=( const CMtaFolderPicker& );
};

#endif
<commit_msg>INTEGRATION: CWS warnings01 (1.6.18); FILE MERGED 2006/05/15 12:09:03 sb 1.6.18.1: #i53898# Made code warning-free and/or compile at all after resync to SRC680m162.<commit_after>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: MtaFop.hxx,v $
 *
 *  $Revision: 1.7 $
 *
 *  last change: $Author: hr $ $Date: 2006-06-20 00:14:33 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

#ifndef _MTAFOP_HXX_
#define _MTAFOP_HXX_

#ifndef _SAL_TYPES_H_
#include <sal/types.h>
#endif

#ifndef _RTL_USTRING_HXX_
#include <rtl/ustring.hxx>
#endif

#ifndef _OSL_MUTEX_HXX_
#include <osl/mutex.hxx>
#endif

#include <utility>
#include <objidl.h>
#include <shlobj.h>

#ifndef _WINIMPLHELPER_HXX_
#include "..\misc\WinImplHelper.hxx"
#endif

//----------------------------------------------------------------
// a simple helper class used to provide a buffer for different
// Win32 file and directory functions
//----------------------------------------------------------------

class CAutoPathBuff
{
public:
    CAutoPathBuff( size_t size = 0 )
    {
        if (0 == size)
            size = 32000; // max path length under Win2000

        pBuff = new sal_Unicode[size];

        OSL_POSTCOND(pBuff,"Could not allocate path buffer");
    }

    ~CAutoPathBuff( )
    {
        delete [] pBuff;
    }

    operator sal_Unicode*( )
    {
        OSL_PRECOND( pBuff, \
            "No path buffer allocated" );
        return pBuff;
    }

    sal_Unicode* get( )
    {
        OSL_PRECOND( pBuff, \
            "No path buffer allocated" );
        return pBuff;
    }

private:
    sal_Unicode* pBuff;
};

//--------------------------------------------------------
// the Mta-Ole clipboard class is for internal use only!
// only one instance of this class should be created, the
// user has to ensure this!
// the class is not thread-safe because it will be used
// only from within the clipboard service and the methods
// of the clipboard service are already synchronized
//--------------------------------------------------------

class CMtaFolderPicker
{
public:
    CMtaFolderPicker( sal_uInt32 Flags );
    virtual ~CMtaFolderPicker( );

    // shell functions
    sal_Bool SAL_CALL browseForFolder( );

    virtual void  SAL_CALL setDisplayDirectory( const rtl::OUString& aDirectory );
    virtual rtl::OUString  SAL_CALL getDisplayDirectory( );
    virtual rtl::OUString SAL_CALL getDirectory( );

    virtual void SAL_CALL setDescription( const rtl::OUString& aDescription );

    virtual void SAL_CALL setTitle( const rtl::OUString& aTitle );
    rtl::OUString  SAL_CALL getTitle( );

    //-----------------------------------------------------
    // XCancellable
    //-----------------------------------------------------

    virtual void SAL_CALL cancel( );

protected:
    void SAL_CALL enableOk( sal_Bool bEnable );
    void SAL_CALL setSelection( const rtl::OUString& aDirectory );
    void SAL_CALL setStatusText( const rtl::OUString& aStatusText );

    virtual void SAL_CALL onInitialized( );
    virtual void SAL_CALL onSelChanged( const rtl::OUString& aNewPath );
    virtual sal_uInt32 SAL_CALL onValidateFailed( sal_Unicode* lpInvalidPath );

private:
    // helper functions
    LPITEMIDLIST  SAL_CALL getItemIdListFromPath( const rtl::OUString& aDirectory );
    rtl::OUString SAL_CALL getPathFromItemIdList( LPCITEMIDLIST lpItemIdList );
    void SAL_CALL releaseItemIdList( LPITEMIDLIST lpItemIdList );

    unsigned int run( );

    // create a hidden windows which serves as an request
    // target; so we guarantee synchronization
    sal_Bool SAL_CALL createStaRequestWindow( );

    //---------------------------------------------------------------
    // message handler functions; remeber these functions are called
    // from a different thread context!
    //---------------------------------------------------------------

    sal_Bool SAL_CALL onBrowseForFolder( );

    static LRESULT CALLBACK StaWndProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
    static unsigned int WINAPI StaThreadProc( LPVOID pParam );

    static int CALLBACK FolderPickerCallback( HWND hwnd, UINT uMsg, LPARAM lParam, LPARAM lpData );

protected:
    HWND m_hwnd;

private:
    ATOM SAL_CALL RegisterStaRequestWindowClass( );
    void SAL_CALL UnregisterStaRequestWindowClass( );

private:
    HANDLE                      m_hStaThread;
    unsigned                    m_uStaThreadId;
    HANDLE                      m_hEvtThrdReady;
    HWND                        m_hwndStaRequestWnd;
    rtl::OUString               m_dialogTitle;
    rtl::OUString               m_Description;
    rtl::OUString               m_displayDir;
    rtl::OUString               m_SelectedDir;
    BROWSEINFOW                 m_bi;
    CAutoPathBuff               m_pathBuff;
    HINSTANCE                   m_hInstance;

    // the request window class has to be registered only
    // once per process, so multiple instance of this class
    // share the registered window class
    static ATOM       s_ClassAtom;
    static osl::Mutex s_Mutex;
    static sal_Int32  s_StaRequestWndRegisterCount;

// prevent copy and assignment
private:
    CMtaFolderPicker( const CMtaFolderPicker& );
    CMtaFolderPicker& operator=( const CMtaFolderPicker& );
};

#endif
<|endoftext|>


<commit_before>#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
#include "cinder/Rand.h"
#include "cinder/Utilities.h"
#include "cinder/Log.h"

#include <list>

using namespace ci;
using namespace ci::app;
using namespace std;

class WindowData {
  public:
	~WindowData() { CI_LOG_V( "Destroying Window Data" ); };
	vector<vec2> 	mPoints;
};

class WindowTestApp : public App {
 public:
	// this is passed into the app intantiation macro at the bottom of the file
	static void prepareSettings( Settings *settings );

	void setup() override;
	void keyDown( KeyEvent event ) override;
	void mouseDown( MouseEvent event ) override;
	void mouseDrag( MouseEvent event ) override;
	void fileDrop( FileDropEvent event ) override;
	void resize() override;
	void update() override;

	// Cinder calls this function 30 times per second by default
	void windowDraw();
	void anotherTest( MouseEvent event );
	void mouseDown1( MouseEvent &event );
	bool mouseDown2( MouseEvent event );
	void mouseDown3( MouseEvent &event );
	void windowMove();
	void windowClose();
	void windowMouseDown( MouseEvent &mouseEvt );
	void displayChange();

	bool shouldQuit();

	// This will maintain a list of points which we will draw line segments between
	WindowRef		mSecondWindow;
};

void WindowTestApp::mouseDrag( MouseEvent event )
{
	vec2 v = event.getPos();
	WindowRef w = event.getWindow();
	vector<vec2> &points = w->getUserData<WindowData>()->mPoints;
	points.push_back( v );
}

void WindowTestApp::prepareSettings( Settings *settings )
{
	settings->setPowerManagementEnabled( false );
	settings->setQuitOnLastWindowCloseEnabled( false );
//	settings->setFullScreen( true );
	settings->setWindowSize( 800, 500 );
	settings->setTitle( "title set from App::Settings" );
//	settings->prepareWindow( Window::Format().resizable( false ).renderer( RendererGl::create() ).fullScreen( true ) );
//	settings->prepareWindow( Window::Format().fullScreen().fullScreenButton() );
}

void WindowTestApp::setup()
{
	for( auto displayIt = Display::getDisplays().begin(); displayIt != Display::getDisplays().end(); ++displayIt )
		CI_LOG_V( "Resolution: " << (*displayIt)->getBounds() );

	getWindow()->setUserData( new WindowData );

	getWindow()->getSignalMouseDown().connect( signals::slot( this, &WindowTestApp::anotherTest ) );
	getWindow()->getSignalMouseDown().connect( std::bind( &WindowTestApp::mouseDown1, this, std::placeholders::_1 ) );
//	getWindow()->getSignalMouseDown().connect( std::bind( &WindowTestApp::mouseDown2, this, std::placeholders::_1 ) ); // This shouldn't build because it has the wrong signature (<bool( MouseEvent )>) - to note, the reference is not the problem, just the return value is different.
	getWindow()->getSignalMouseDown().connect( std::bind( &WindowTestApp::mouseDown3, this, std::placeholders::_1 ) );
	getSignalShouldQuit().connect( std::bind( &WindowTestApp::shouldQuit, this ) );

	getWindow()->getSignalMove().connect( std::bind( &WindowTestApp::windowMove, this ) );
	getWindow()->getSignalDraw().connect( std::bind( &WindowTestApp::windowDraw, this ) );
	getWindow()->getSignalDisplayChange().connect( std::bind( &WindowTestApp::displayChange, this ) );
	getWindow()->getSignalClose().connect( std::bind( &WindowTestApp::windowClose, this ) );

	getSignalDidBecomeActive().connect( [] { CI_LOG_V( "App became active." ); } );
	getSignalWillResignActive().connect( [] { CI_LOG_V( "App will resign active." ); } );
}

bool WindowTestApp::shouldQuit()
{
	return true;
}

void WindowTestApp::update()
{
}

void WindowTestApp::anotherTest( MouseEvent event )
{
	CI_LOG_V( "Totes." );
}

void WindowTestApp::mouseDown( MouseEvent event )
{
	CI_LOG_V( "Main mouseDown" );
}

void WindowTestApp::mouseDown1( MouseEvent &event )
{
	enablePowerManagement( ! isPowerManagementEnabled() );
	CI_LOG_V( "Power mgmt: " << isPowerManagementEnabled() );
	CI_LOG_V( "window pos: " << getWindow()->getPos() );
	CI_LOG_V( "Title was: " << getWindow()->getTitle() << "." );
	getWindow()->setTitle( "Crunk " + toString( getWindow()->getPos().x ) );
	CI_LOG_V( "Window size from app: " << getWindowWidth() << " x " << getWindowHeight() << " from window: " << event.getWindow()->getSize() );
	CI_LOG_V( "Window pos from app: " << getWindowPos() << " from window: " << getWindow()->getPos() );
//	event.setHandled();
}

void WindowTestApp::windowMove()
{
	CI_LOG_V( "window pos: " << getWindow()->getPos() );
}

void WindowTestApp::displayChange()
{
	CI_LOG_V( "window display changed: " << getWindow()->getDisplay()->getBounds() );
}

bool WindowTestApp::mouseDown2( MouseEvent event )
{
	CI_ASSERT_MSG( 0, "getSignalMouseDown() called with wrong signature (should be <void( MouseEvent &event)>" );
	return false;
}

void WindowTestApp::mouseDown3( MouseEvent &event )
{
	CI_LOG_V( "It worked 3!" << getMousePos() );
	event.setHandled();
}

void WindowTestApp::windowClose()
{
	WindowRef win = getWindow();
	CI_LOG_V( "Closing " << getWindow() );
}

void WindowTestApp::windowMouseDown( MouseEvent &mouseEvt )
{
	CI_LOG_V( "Mouse down in window" );
}

void WindowTestApp::keyDown( KeyEvent event )
{
	if( event.getCode() == KeyEvent::KEY_RSHIFT ) {
		CI_LOG_V( "Right shift down" );
	}
	else if( event.getCode() == KeyEvent::KEY_LCTRL ) {
		CI_LOG_V( "Left control down" );
	}
	if( event.getChar() == 'f' ) {
		CI_LOG_V( "Toggling from fullscreen: " << getWindow()->isFullScreen() );
		getWindow()->setFullScreen( ! getWindow()->isFullScreen(), FullScreenOptions().display( Display::getDisplays()[1] ) );
	}
	else if( event.getChar() == 'o' ) {
		CI_LOG_V( "(kiosk) Toggling from fullscreen: " << getWindow()->isFullScreen() );
		FullScreenOptions fullScreenOptions = FullScreenOptions().kioskMode();
		if( event.isControlDown() )
			fullScreenOptions.secondaryDisplayBlanking( false );
		else
			fullScreenOptions.secondaryDisplayBlanking( true );
		//if( event.isControlDown() )
		//	fullScreenOptions.exclusive();
		getWindow()->setFullScreen( ! getWindow()->isFullScreen(), fullScreenOptions );
	}
	else if( event.getCode() == KeyEvent::KEY_LEFT )
		getWindow()->setPos( getWindow()->getPos().x - 1, getWindow()->getPos().y );
	else if( event.getCode() == KeyEvent::KEY_RIGHT )
		getWindow()->setPos( getWindow()->getPos().x + 1, getWindow()->getPos().y );
	else if( event.getCode() == KeyEvent::KEY_UP )
		getWindow()->setSize( getWindow()->getSize().x + 1, getWindow()->getSize().y );
	else if( event.getCode() == KeyEvent::KEY_DOWN )
		getWindow()->setSize( getWindow()->getSize().x + 1, getWindow()->getSize().y + 1 );
	else if( event.getChar() == 'w' ) {
		Window::Format format( RendererGl::create() );
		//format.setFullScreen( true );
		mSecondWindow = createWindow( format );
		mSecondWindow->getSignalClose().connect( std::bind( &WindowTestApp::windowClose, this ) );
		mSecondWindow->getSignalMouseDown().connect( std::bind( &WindowTestApp::windowMouseDown, this, std::placeholders::_1 ) );
		mSecondWindow->getSignalDraw().connect( std::bind( &WindowTestApp::windowDraw, this ) );
		mSecondWindow->setUserData( new WindowData );
	}
	else if( event.getChar() == 'c' ) {
		getWindow()->close();
//		getWindow( getNumWindows() - 1 )->close();
	}
	else if( event.getChar() == 'h' ) {
		if( getWindowIndex(0)->isHidden() )
			getWindowIndex(0)->show();
		else
			getWindowIndex(0)->hide();
	}
	else if( event.getChar() == 'b' ) {
		getWindow()->setBorderless( ! getWindow()->isBorderless() );
	}
	else if( event.getChar() == 't' ) {
		getWindow()->setAlwaysOnTop( ! getWindow()->isAlwaysOnTop() );
	}
	else if( event.getChar() == 's' ) {
		getWindow()->setBorderless();
		getWindow()->spanAllDisplays();
		CI_LOG_V( "Spanning Area: " << Display::getSpanningArea() );
		CI_LOG_V( "Bounds: " << getWindow()->getBounds() );
		//getWindow()->setPos( ivec2( -1680 + 1, 0 + 1 ) );
//		getWindow()->setSize( 1440, 900 );
//		getWindow()->setPos( 0, 0 );
	}
}

void WindowTestApp::fileDrop( FileDropEvent event )
{
	CI_LOG_V( "File drop: " << event );
}

void WindowTestApp::resize()
{
	CI_LOG_V( "Resized: " << getWindowSize() );
}

void WindowTestApp::windowDraw()
{
	gl::enableAlphaBlending();
//	glEnable(GL_MULTISAMPLE_ARB);
	if( getWindow() == getForegroundWindow() )
		gl::clear( Color( 0.1f, 0.1f, 0.5f ) );
	else
		gl::clear( Color( 0.3f, 0.1f, 0.1f ) );

	// We'll set the color to an orange color
	gl::color( 1.0f, 0.5f, 0.25f );

	glEnable( GL_LINE_SMOOTH );
	glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );

	gl::begin( GL_LINE_STRIP );
	const vector<vec2> &points = getWindow()->getUserData<WindowData>()->mPoints;
	for( auto pointIter = points.begin(); pointIter != points.end(); ++pointIter ) {
		gl::vertex( *pointIter /*+ vec2( 0, getElapsedSeconds() )*/ );
	}
	gl::end();

	//if( window == mSecondWindow )
		gl::drawLine( vec2( 50, 50 ), vec2( 250, 250 ) );
	gl::pushMatrices();
		gl::color( 1.0f, 0.2f, 0.15f );
		gl::translate( getWindowCenter() );
		gl::rotate( getElapsedSeconds() );
		gl::drawSolidRect( Rectf( -100, -100, 100, 100 ) );
	gl::popMatrices();
}

// This line tells Flint to actually create the application
CINDER_APP( WindowTestApp, RendererGl, WindowTestApp::prepareSettings )
<commit_msg>minor test update<commit_after>#include "cinder/app/App.h"
#include "cinder/app/RendererGl.h"
#include "cinder/gl/gl.h"
#include "cinder/Rand.h"
#include "cinder/Utilities.h"
#include "cinder/Log.h"

#include <list>

using namespace ci;
using namespace ci::app;
using namespace std;

class WindowData {
  public:
	~WindowData() { CI_LOG_V( "Destroying Window Data" ); };
	vector<vec2> 	mPoints;
};

class WindowTestApp : public App {
 public:
	// this is passed into the app intantiation macro at the bottom of the file
	static void prepareSettings( Settings *settings );

	void setup() override;
	void keyDown( KeyEvent event ) override;
	void mouseDown( MouseEvent event ) override;
	void mouseDrag( MouseEvent event ) override;
	void fileDrop( FileDropEvent event ) override;
	void resize() override;
	void update() override;

	// Cinder calls this function 30 times per second by default
	void windowDraw();
	void anotherTest( MouseEvent event );
	void mouseDown1( MouseEvent &event );
	bool mouseDown2( MouseEvent event );
	void mouseDown3( MouseEvent &event );
	void windowMove();
	void windowClose();
	void windowMouseDown( MouseEvent &mouseEvt );
	void displayChange();

	bool shouldQuit();

	// This will maintain a list of points which we will draw line segments between
	WindowRef		mSecondWindow;
};

void WindowTestApp::mouseDrag( MouseEvent event )
{
	vec2 v = event.getPos();
	WindowRef w = event.getWindow();
	vector<vec2> &points = w->getUserData<WindowData>()->mPoints;
	points.push_back( v );
}

void WindowTestApp::prepareSettings( Settings *settings )
{
	settings->setPowerManagementEnabled( false );
	settings->setQuitOnLastWindowCloseEnabled( false );
//	settings->setFullScreen( true );
	settings->setWindowSize( 800, 500 );
	settings->setTitle( "title set from App::Settings" );
//	settings->prepareWindow( Window::Format().resizable( false ).renderer( RendererGl::create() ).fullScreen( true ) );
//	settings->prepareWindow( Window::Format().fullScreen().fullScreenButton() );
}

void WindowTestApp::setup()
{
	for( auto displayIt = Display::getDisplays().begin(); displayIt != Display::getDisplays().end(); ++displayIt )
		CI_LOG_V( "Resolution: " << (*displayIt)->getBounds() );

	getWindow()->setUserData( new WindowData );

	getWindow()->getSignalMouseDown().connect( signals::slot( this, &WindowTestApp::anotherTest ) );
	getWindow()->getSignalMouseDown().connect( std::bind( &WindowTestApp::mouseDown1, this, std::placeholders::_1 ) );
//	getWindow()->getSignalMouseDown().connect( std::bind( &WindowTestApp::mouseDown2, this, std::placeholders::_1 ) ); // This shouldn't build because it has the wrong signature (<bool( MouseEvent )>) - to note, the reference is not the problem, just the return value is different.
	getWindow()->getSignalMouseDown().connect( std::bind( &WindowTestApp::mouseDown3, this, std::placeholders::_1 ) );
	getSignalShouldQuit().connect( std::bind( &WindowTestApp::shouldQuit, this ) );

	getWindow()->getSignalMove().connect( std::bind( &WindowTestApp::windowMove, this ) );
	getWindow()->getSignalDraw().connect( std::bind( &WindowTestApp::windowDraw, this ) );
	getWindow()->getSignalDisplayChange().connect( std::bind( &WindowTestApp::displayChange, this ) );
	getWindow()->getSignalClose().connect( std::bind( &WindowTestApp::windowClose, this ) );

	getSignalDidBecomeActive().connect( [] { CI_LOG_V( "App became active." ); } );
	getSignalWillResignActive().connect( [] { CI_LOG_V( "App will resign active." ); } );
}

bool WindowTestApp::shouldQuit()
{
	return true;
}

void WindowTestApp::update()
{
}

void WindowTestApp::anotherTest( MouseEvent event )
{
	CI_LOG_V( "Totes." );
}

void WindowTestApp::mouseDown( MouseEvent event )
{
	CI_LOG_V( "Main mouseDown" );
}

void WindowTestApp::mouseDown1( MouseEvent &event )
{
	enablePowerManagement( ! isPowerManagementEnabled() );
	CI_LOG_V( "Power mgmt: " << isPowerManagementEnabled() );
	CI_LOG_V( "window pos: " << getWindow()->getPos() );
	CI_LOG_V( "Title was: " << getWindow()->getTitle() << "." );
	getWindow()->setTitle( "Crunk " + toString( getWindow()->getPos().x ) );
	CI_LOG_V( "Window size from app: " << getWindowWidth() << " x " << getWindowHeight() << " from window: " << event.getWindow()->getSize() );
	CI_LOG_V( "Window pos from app: " << getWindowPos() << " from window: " << getWindow()->getPos() );
//	event.setHandled();
}

void WindowTestApp::windowMove()
{
	CI_LOG_V( "window pos: " << getWindow()->getPos() );
}

void WindowTestApp::displayChange()
{
	CI_LOG_V( "window display changed: " << getWindow()->getDisplay()->getBounds() );
}

bool WindowTestApp::mouseDown2( MouseEvent event )
{
	CI_ASSERT_MSG( 0, "getSignalMouseDown() called with wrong signature (should be <void( MouseEvent &event)>" );
	return false;
}

void WindowTestApp::mouseDown3( MouseEvent &event )
{
	CI_LOG_V( "It worked 3!" << getMousePos() );
	event.setHandled();
}

void WindowTestApp::windowClose()
{
	WindowRef win = getWindow();
	CI_LOG_V( "Closing " << getWindow() );
}

void WindowTestApp::windowMouseDown( MouseEvent &mouseEvt )
{
	CI_LOG_V( "Mouse down in window" );
}

void WindowTestApp::keyDown( KeyEvent event )
{
	if( event.getCode() == KeyEvent::KEY_RSHIFT ) {
		CI_LOG_V( "Right shift down" );
	}
	else if( event.getCode() == KeyEvent::KEY_LCTRL ) {
		CI_LOG_V( "Left control down" );
	}
	if( event.getChar() == 'f' ) {
		CI_LOG_V( "Toggling from fullscreen: " << getWindow()->isFullScreen() );
		getWindow()->setFullScreen( ! getWindow()->isFullScreen(), FullScreenOptions().display( Display::getDisplays()[1] ) );
	}
	else if( event.getChar() == 'o' ) {
		CI_LOG_V( "(kiosk) Toggling from fullscreen: " << getWindow()->isFullScreen() );
		FullScreenOptions fullScreenOptions = FullScreenOptions().kioskMode();
		if( event.isControlDown() )
			fullScreenOptions.secondaryDisplayBlanking( false );
		else
			fullScreenOptions.secondaryDisplayBlanking( true );
		//if( event.isControlDown() )
		//	fullScreenOptions.exclusive();
		getWindow()->setFullScreen( ! getWindow()->isFullScreen(), fullScreenOptions );
	}
	else if( event.getCode() == KeyEvent::KEY_LEFT )
		getWindow()->setPos( getWindow()->getPos().x - 1, getWindow()->getPos().y );
	else if( event.getCode() == KeyEvent::KEY_RIGHT )
		getWindow()->setPos( getWindow()->getPos().x + 1, getWindow()->getPos().y );
	else if( event.getCode() == KeyEvent::KEY_UP )
		getWindow()->setSize( getWindow()->getSize().x + 1, getWindow()->getSize().y );
	else if( event.getCode() == KeyEvent::KEY_DOWN )
		getWindow()->setSize( getWindow()->getSize().x + 1, getWindow()->getSize().y + 1 );
	else if( event.getChar() == 'w' ) {
		Window::Format format( RendererGl::create() );
		//format.setFullScreen( true );
		mSecondWindow = createWindow( format );
		mSecondWindow->getSignalClose().connect( std::bind( &WindowTestApp::windowClose, this ) );
		mSecondWindow->getSignalMouseDown().connect( std::bind( &WindowTestApp::windowMouseDown, this, std::placeholders::_1 ) );
		mSecondWindow->getSignalDraw().connect( std::bind( &WindowTestApp::windowDraw, this ) );
		mSecondWindow->setUserData( new WindowData );
	}
	else if( event.getChar() == 'c' ) {
		getWindow()->close();
//		getWindow( getNumWindows() - 1 )->close();
	}
	else if( event.getChar() == 'h' ) {
		if( getWindowIndex(0)->isHidden() )
			getWindowIndex(0)->show();
		else
			getWindowIndex(0)->hide();
	}
	else if( event.getChar() == 'b' ) {
		getWindow()->setBorderless( ! getWindow()->isBorderless() );
	}
	else if( event.getChar() == 't' ) {
		getWindow()->setAlwaysOnTop( ! getWindow()->isAlwaysOnTop() );
	}
	else if( event.getChar() == 's' ) {
		getWindow()->setBorderless();
		getWindow()->spanAllDisplays();
		CI_LOG_V( "Spanning Area: " << Display::getSpanningArea() );
		CI_LOG_V( "Bounds: " << getWindow()->getBounds() );
		//getWindow()->setPos( ivec2( -1680 + 1, 0 + 1 ) );
//		getWindow()->setSize( 1440, 900 );
//		getWindow()->setPos( 0, 0 );
	}
}

void WindowTestApp::fileDrop( FileDropEvent event )
{
	CI_LOG_V( "File drop: " << event );
}

void WindowTestApp::resize()
{
	CI_LOG_V( "window pos: " << getWindowPos() << ", size: " << getWindowSize() );
}

void WindowTestApp::windowDraw()
{
	gl::enableAlphaBlending();
//	glEnable(GL_MULTISAMPLE_ARB);
	if( getWindow() == getForegroundWindow() )
		gl::clear( Color( 0.1f, 0.1f, 0.5f ) );
	else
		gl::clear( Color( 0.3f, 0.1f, 0.1f ) );

	// We'll set the color to an orange color
	gl::color( 1.0f, 0.5f, 0.25f );

	glEnable( GL_LINE_SMOOTH );
	glHint( GL_LINE_SMOOTH_HINT, GL_NICEST );

	gl::begin( GL_LINE_STRIP );
	const vector<vec2> &points = getWindow()->getUserData<WindowData>()->mPoints;
	for( auto pointIter = points.begin(); pointIter != points.end(); ++pointIter ) {
		gl::vertex( *pointIter /*+ vec2( 0, getElapsedSeconds() )*/ );
	}
	gl::end();

	//if( window == mSecondWindow )
		gl::drawLine( vec2( 50, 50 ), vec2( 250, 250 ) );
	gl::pushMatrices();
		gl::color( 1.0f, 0.2f, 0.15f );
		gl::translate( getWindowCenter() );
		gl::rotate( getElapsedSeconds() );
		gl::drawSolidRect( Rectf( -100, -100, 100, 100 ) );
	gl::popMatrices();
}

CINDER_APP( WindowTestApp, RendererGl, WindowTestApp::prepareSettings )
<|endoftext|>


<commit_before><commit_msg>Real STD implementation of conv_4d_full_flipped<commit_after><|endoftext|>


<commit_before><commit_msg>added missing iomanip header<commit_after><|endoftext|>


<commit_before>/*************************************************************************
 *
 *  OpenOffice.org - a multi-platform office productivity suite
 *
 *  $RCSfile: keymapping.cxx,v $
 *
 *  $Revision: 1.6 $
 *
 *  last change: $Author: obo $ $Date: 2007-07-18 13:25:39 $
 *
 *  The Contents of this file are made available subject to
 *  the terms of GNU Lesser General Public License Version 2.1.
 *
 *
 *    GNU Lesser General Public License Version 2.1
 *    =============================================
 *    Copyright 2005 by Sun Microsystems, Inc.
 *    901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License version 2.1, as published by the Free Software Foundation.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 *
 *    You should have received a copy of the GNU Lesser General Public
 *    License along with this library; if not, write to the Free Software
 *    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *    MA  02111-1307  USA
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_framework.hxx"

#ifndef __FRAMEWORK_ACCELERATORS_KEYMAPPING_HXX_
#include <accelerators/keymapping.hxx>
#endif

//_______________________________________________
// own includes

#include <macros/generic.hxx>

//_______________________________________________
// interface includes

#ifndef _COM_SUN_STAR_AWT_KEY_HPP_
#include <com/sun/star/awt/Key.hpp>
#endif

//_______________________________________________
// other includes

//_______________________________________________
// namespace

namespace framework
{

//_______________________________________________
// helper

KeyMapping::KeyIdentifierInfo KeyMapping::KeyIdentifierMap[] =
{
    {css::awt::Key::NUM0          , "KEY_0"          },
    {css::awt::Key::NUM1          , "KEY_1"          },
    {css::awt::Key::NUM2          , "KEY_2"          },
    {css::awt::Key::NUM3          , "KEY_3"          },
    {css::awt::Key::NUM4          , "KEY_4"          },
    {css::awt::Key::NUM5          , "KEY_5"          },
    {css::awt::Key::NUM6          , "KEY_6"          },
    {css::awt::Key::NUM7          , "KEY_7"          },
    {css::awt::Key::NUM8          , "KEY_8"          },
    {css::awt::Key::NUM9          , "KEY_9"          },
    {css::awt::Key::A             , "KEY_A"          },
    {css::awt::Key::B             , "KEY_B"          },
    {css::awt::Key::C             , "KEY_C"          },
    {css::awt::Key::D             , "KEY_D"          },
    {css::awt::Key::E             , "KEY_E"          },
    {css::awt::Key::F             , "KEY_F"          },
    {css::awt::Key::G             , "KEY_G"          },
    {css::awt::Key::H             , "KEY_H"          },
    {css::awt::Key::I             , "KEY_I"          },
    {css::awt::Key::J             , "KEY_J"          },
    {css::awt::Key::K             , "KEY_K"          },
    {css::awt::Key::L             , "KEY_L"          },
    {css::awt::Key::M             , "KEY_M"          },
    {css::awt::Key::N             , "KEY_N"          },
    {css::awt::Key::O             , "KEY_O"          },
    {css::awt::Key::P             , "KEY_P"          },
    {css::awt::Key::Q             , "KEY_Q"          },
    {css::awt::Key::R             , "KEY_R"          },
    {css::awt::Key::S             , "KEY_S"          },
    {css::awt::Key::T             , "KEY_T"          },
    {css::awt::Key::U             , "KEY_U"          },
    {css::awt::Key::V             , "KEY_V"          },
    {css::awt::Key::W             , "KEY_W"          },
    {css::awt::Key::X             , "KEY_X"          },
    {css::awt::Key::Y             , "KEY_Y"          },
    {css::awt::Key::Z             , "KEY_Z"          },
    {css::awt::Key::F1            , "KEY_F1"         },
    {css::awt::Key::F2            , "KEY_F2"         },
    {css::awt::Key::F3            , "KEY_F3"         },
    {css::awt::Key::F4            , "KEY_F4"         },
    {css::awt::Key::F5            , "KEY_F5"         },
    {css::awt::Key::F6            , "KEY_F6"         },
    {css::awt::Key::F7            , "KEY_F7"         },
    {css::awt::Key::F8            , "KEY_F8"         },
    {css::awt::Key::F9            , "KEY_F9"         },
    {css::awt::Key::F10           , "KEY_F10"        },
    {css::awt::Key::F11           , "KEY_F11"        },
    {css::awt::Key::F12           , "KEY_F12"        },
    {css::awt::Key::F13           , "KEY_F13"        },
    {css::awt::Key::F14           , "KEY_F14"        },
    {css::awt::Key::F15           , "KEY_F15"        },
    {css::awt::Key::F16           , "KEY_F16"        },
    {css::awt::Key::F17           , "KEY_F17"        },
    {css::awt::Key::F18           , "KEY_F18"        },
    {css::awt::Key::F19           , "KEY_F19"        },
    {css::awt::Key::F20           , "KEY_F20"        },
    {css::awt::Key::F21           , "KEY_F21"        },
    {css::awt::Key::F22           , "KEY_F22"        },
    {css::awt::Key::F23           , "KEY_F23"        },
    {css::awt::Key::F24           , "KEY_F24"        },
    {css::awt::Key::F25           , "KEY_F25"        },
    {css::awt::Key::F26           , "KEY_F26"        },
    {css::awt::Key::DOWN          , "KEY_DOWN"       },
    {css::awt::Key::UP            , "KEY_UP"         },
    {css::awt::Key::LEFT          , "KEY_LEFT"       },
    {css::awt::Key::RIGHT         , "KEY_RIGHT"      },
    {css::awt::Key::HOME          , "KEY_HOME"       },
    {css::awt::Key::END           , "KEY_END"        },
    {css::awt::Key::PAGEUP        , "KEY_PAGEUP"     },
    {css::awt::Key::PAGEDOWN      , "KEY_PAGEDOWN"   },
    {css::awt::Key::RETURN        , "KEY_RETURN"     },
    {css::awt::Key::ESCAPE        , "KEY_ESCAPE"     },
    {css::awt::Key::TAB           , "KEY_TAB"        },
    {css::awt::Key::BACKSPACE     , "KEY_BACKSPACE"  },
    {css::awt::Key::SPACE         , "KEY_SPACE"      },
    {css::awt::Key::INSERT        , "KEY_INSERT"     },
    {css::awt::Key::DELETE        , "KEY_DELETE"     },
    {css::awt::Key::ADD           , "KEY_ADD"        },
    {css::awt::Key::SUBTRACT      , "KEY_SUBTRACT"   },
    {css::awt::Key::MULTIPLY      , "KEY_MULTIPLY"   },
    {css::awt::Key::DIVIDE        , "KEY_DIVIDE"     },
    {css::awt::Key::POINT         , "KEY_POINT"      },
    {css::awt::Key::COMMA         , "KEY_COMMA"      },
    {css::awt::Key::LESS          , "KEY_LESS"       },
    {css::awt::Key::GREATER       , "KEY_GREATER"    },
    {css::awt::Key::EQUAL         , "KEY_EQUAL"      },
    {css::awt::Key::OPEN          , "KEY_OPEN"       },
    {css::awt::Key::CUT           , "KEY_CUT"        },
    {css::awt::Key::COPY          , "KEY_COPY"       },
    {css::awt::Key::PASTE         , "KEY_PASTE"      },
    {css::awt::Key::UNDO          , "KEY_UNDO"       },
    {css::awt::Key::REPEAT        , "KEY_REPEAT"     },
    {css::awt::Key::FIND          , "KEY_FIND"       },
    {css::awt::Key::PROPERTIES    , "KEY_PROPERTIES" },
    {css::awt::Key::FRONT         , "KEY_FRONT"      },
    {css::awt::Key::CONTEXTMENU   , "KEY_CONTEXTMENU"},
    {css::awt::Key::HELP          , "KEY_HELP"       },
    {css::awt::Key::MENU          , "KEY_MENU"       },
    {css::awt::Key::HANGUL_HANJA  , "KEY_HANGUL_HANJA"},
    {css::awt::Key::DECIMAL       , "KEY_DECIMAL"    },
    {css::awt::Key::TILDE         , "KEY_TILDE"      },
    {css::awt::Key::QUOTELEFT     , "KEY_QUOTELEFT"  },
    {0                            , ""               } // mark the end of this array!
};

//-----------------------------------------------
KeyMapping::KeyMapping()
{
    sal_Int32 i = 0;
    while(KeyIdentifierMap[i].Code != 0)
    {
        ::rtl::OUString sIdentifier = ::rtl::OUString::createFromAscii(KeyIdentifierMap[i].Identifier);
        sal_Int16       nCode       = KeyIdentifierMap[i].Code;

        m_lIdentifierHash[sIdentifier] = nCode      ;
        m_lCodeHash      [nCode]       = sIdentifier;

        ++i;
    }
}

//-----------------------------------------------
KeyMapping::~KeyMapping()
{
}

//-----------------------------------------------
sal_uInt16 KeyMapping::mapIdentifierToCode(const ::rtl::OUString& sIdentifier)
    throw(css::lang::IllegalArgumentException)
{
    Identifier2CodeHash::const_iterator pIt = m_lIdentifierHash.find(sIdentifier);
    if (pIt != m_lIdentifierHash.end())
        return pIt->second;

    // Its not well known identifier - but may be a pure key code formated as string ...
    // Check and convert it!
    sal_uInt16 nCode = 0;
    if (!KeyMapping::impl_st_interpretIdentifierAsPureKeyCode(sIdentifier, nCode))
        throw css::lang::IllegalArgumentException(
                DECLARE_ASCII("Cant map given identifier to a valid key code value."),
                css::uno::Reference< css::uno::XInterface >(),
                0);

    return (sal_uInt16)nCode;
}

//-----------------------------------------------
::rtl::OUString KeyMapping::mapCodeToIdentifier(sal_uInt16 nCode)
{
    Code2IdentifierHash::const_iterator pIt = m_lCodeHash.find(nCode);
    if (pIt != m_lCodeHash.end())
        return pIt->second;

    // If we have no well known identifier - use the pure code value!
    return ::rtl::OUString::valueOf((sal_Int32)nCode);
}

//-----------------------------------------------
sal_Bool KeyMapping::impl_st_interpretIdentifierAsPureKeyCode(const ::rtl::OUString& sIdentifier,
                                                                    sal_uInt16&      rCode      )
{
    sal_Int32 nCode = sIdentifier.toInt32();
    if (nCode > 0)
    {
        rCode = (sal_uInt16)nCode;
        return sal_True;
    }

    // 0 is normaly an error of the called method toInt32() ...
    // But we must be aware, that the identifier is "0"!
    rCode = 0;
    return sIdentifier.equalsAscii("0");
}

} // namespace framework
<commit_msg>INTEGRATION: CWS changefileheader (1.6.128); FILE MERGED 2008/04/01 10:58:01 thb 1.6.128.2: #i85898# Stripping all external header guards 2008/03/28 15:35:09 rt 1.6.128.1: #i87441# Change license header to LPGL v3.<commit_after>/*************************************************************************
 *
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 *
 * Copyright 2008 by Sun Microsystems, Inc.
 *
 * OpenOffice.org - a multi-platform office productivity suite
 *
 * $RCSfile: keymapping.cxx,v $
 * $Revision: 1.7 $
 *
 * This file is part of OpenOffice.org.
 *
 * OpenOffice.org is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License version 3
 * only, as published by the Free Software Foundation.
 *
 * OpenOffice.org is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License version 3 for more details
 * (a copy is included in the LICENSE file that accompanied this code).
 *
 * You should have received a copy of the GNU Lesser General Public License
 * version 3 along with OpenOffice.org.  If not, see
 * <http://www.openoffice.org/license.html>
 * for a copy of the LGPLv3 License.
 *
 ************************************************************************/

// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_framework.hxx"
#include <accelerators/keymapping.hxx>

//_______________________________________________
// own includes

#include <macros/generic.hxx>

//_______________________________________________
// interface includes
#include <com/sun/star/awt/Key.hpp>

//_______________________________________________
// other includes

//_______________________________________________
// namespace

namespace framework
{

//_______________________________________________
// helper

KeyMapping::KeyIdentifierInfo KeyMapping::KeyIdentifierMap[] =
{
    {css::awt::Key::NUM0          , "KEY_0"          },
    {css::awt::Key::NUM1          , "KEY_1"          },
    {css::awt::Key::NUM2          , "KEY_2"          },
    {css::awt::Key::NUM3          , "KEY_3"          },
    {css::awt::Key::NUM4          , "KEY_4"          },
    {css::awt::Key::NUM5          , "KEY_5"          },
    {css::awt::Key::NUM6          , "KEY_6"          },
    {css::awt::Key::NUM7          , "KEY_7"          },
    {css::awt::Key::NUM8          , "KEY_8"          },
    {css::awt::Key::NUM9          , "KEY_9"          },
    {css::awt::Key::A             , "KEY_A"          },
    {css::awt::Key::B             , "KEY_B"          },
    {css::awt::Key::C             , "KEY_C"          },
    {css::awt::Key::D             , "KEY_D"          },
    {css::awt::Key::E             , "KEY_E"          },
    {css::awt::Key::F             , "KEY_F"          },
    {css::awt::Key::G             , "KEY_G"          },
    {css::awt::Key::H             , "KEY_H"          },
    {css::awt::Key::I             , "KEY_I"          },
    {css::awt::Key::J             , "KEY_J"          },
    {css::awt::Key::K             , "KEY_K"          },
    {css::awt::Key::L             , "KEY_L"          },
    {css::awt::Key::M             , "KEY_M"          },
    {css::awt::Key::N             , "KEY_N"          },
    {css::awt::Key::O             , "KEY_O"          },
    {css::awt::Key::P             , "KEY_P"          },
    {css::awt::Key::Q             , "KEY_Q"          },
    {css::awt::Key::R             , "KEY_R"          },
    {css::awt::Key::S             , "KEY_S"          },
    {css::awt::Key::T             , "KEY_T"          },
    {css::awt::Key::U             , "KEY_U"          },
    {css::awt::Key::V             , "KEY_V"          },
    {css::awt::Key::W             , "KEY_W"          },
    {css::awt::Key::X             , "KEY_X"          },
    {css::awt::Key::Y             , "KEY_Y"          },
    {css::awt::Key::Z             , "KEY_Z"          },
    {css::awt::Key::F1            , "KEY_F1"         },
    {css::awt::Key::F2            , "KEY_F2"         },
    {css::awt::Key::F3            , "KEY_F3"         },
    {css::awt::Key::F4            , "KEY_F4"         },
    {css::awt::Key::F5            , "KEY_F5"         },
    {css::awt::Key::F6            , "KEY_F6"         },
    {css::awt::Key::F7            , "KEY_F7"         },
    {css::awt::Key::F8            , "KEY_F8"         },
    {css::awt::Key::F9            , "KEY_F9"         },
    {css::awt::Key::F10           , "KEY_F10"        },
    {css::awt::Key::F11           , "KEY_F11"        },
    {css::awt::Key::F12           , "KEY_F12"        },
    {css::awt::Key::F13           , "KEY_F13"        },
    {css::awt::Key::F14           , "KEY_F14"        },
    {css::awt::Key::F15           , "KEY_F15"        },
    {css::awt::Key::F16           , "KEY_F16"        },
    {css::awt::Key::F17           , "KEY_F17"        },
    {css::awt::Key::F18           , "KEY_F18"        },
    {css::awt::Key::F19           , "KEY_F19"        },
    {css::awt::Key::F20           , "KEY_F20"        },
    {css::awt::Key::F21           , "KEY_F21"        },
    {css::awt::Key::F22           , "KEY_F22"        },
    {css::awt::Key::F23           , "KEY_F23"        },
    {css::awt::Key::F24           , "KEY_F24"        },
    {css::awt::Key::F25           , "KEY_F25"        },
    {css::awt::Key::F26           , "KEY_F26"        },
    {css::awt::Key::DOWN          , "KEY_DOWN"       },
    {css::awt::Key::UP            , "KEY_UP"         },
    {css::awt::Key::LEFT          , "KEY_LEFT"       },
    {css::awt::Key::RIGHT         , "KEY_RIGHT"      },
    {css::awt::Key::HOME          , "KEY_HOME"       },
    {css::awt::Key::END           , "KEY_END"        },
    {css::awt::Key::PAGEUP        , "KEY_PAGEUP"     },
    {css::awt::Key::PAGEDOWN      , "KEY_PAGEDOWN"   },
    {css::awt::Key::RETURN        , "KEY_RETURN"     },
    {css::awt::Key::ESCAPE        , "KEY_ESCAPE"     },
    {css::awt::Key::TAB           , "KEY_TAB"        },
    {css::awt::Key::BACKSPACE     , "KEY_BACKSPACE"  },
    {css::awt::Key::SPACE         , "KEY_SPACE"      },
    {css::awt::Key::INSERT        , "KEY_INSERT"     },
    {css::awt::Key::DELETE        , "KEY_DELETE"     },
    {css::awt::Key::ADD           , "KEY_ADD"        },
    {css::awt::Key::SUBTRACT      , "KEY_SUBTRACT"   },
    {css::awt::Key::MULTIPLY      , "KEY_MULTIPLY"   },
    {css::awt::Key::DIVIDE        , "KEY_DIVIDE"     },
    {css::awt::Key::POINT         , "KEY_POINT"      },
    {css::awt::Key::COMMA         , "KEY_COMMA"      },
    {css::awt::Key::LESS          , "KEY_LESS"       },
    {css::awt::Key::GREATER       , "KEY_GREATER"    },
    {css::awt::Key::EQUAL         , "KEY_EQUAL"      },
    {css::awt::Key::OPEN          , "KEY_OPEN"       },
    {css::awt::Key::CUT           , "KEY_CUT"        },
    {css::awt::Key::COPY          , "KEY_COPY"       },
    {css::awt::Key::PASTE         , "KEY_PASTE"      },
    {css::awt::Key::UNDO          , "KEY_UNDO"       },
    {css::awt::Key::REPEAT        , "KEY_REPEAT"     },
    {css::awt::Key::FIND          , "KEY_FIND"       },
    {css::awt::Key::PROPERTIES    , "KEY_PROPERTIES" },
    {css::awt::Key::FRONT         , "KEY_FRONT"      },
    {css::awt::Key::CONTEXTMENU   , "KEY_CONTEXTMENU"},
    {css::awt::Key::HELP          , "KEY_HELP"       },
    {css::awt::Key::MENU          , "KEY_MENU"       },
    {css::awt::Key::HANGUL_HANJA  , "KEY_HANGUL_HANJA"},
    {css::awt::Key::DECIMAL       , "KEY_DECIMAL"    },
    {css::awt::Key::TILDE         , "KEY_TILDE"      },
    {css::awt::Key::QUOTELEFT     , "KEY_QUOTELEFT"  },
    {0                            , ""               } // mark the end of this array!
};

//-----------------------------------------------
KeyMapping::KeyMapping()
{
    sal_Int32 i = 0;
    while(KeyIdentifierMap[i].Code != 0)
    {
        ::rtl::OUString sIdentifier = ::rtl::OUString::createFromAscii(KeyIdentifierMap[i].Identifier);
        sal_Int16       nCode       = KeyIdentifierMap[i].Code;

        m_lIdentifierHash[sIdentifier] = nCode      ;
        m_lCodeHash      [nCode]       = sIdentifier;

        ++i;
    }
}

//-----------------------------------------------
KeyMapping::~KeyMapping()
{
}

//-----------------------------------------------
sal_uInt16 KeyMapping::mapIdentifierToCode(const ::rtl::OUString& sIdentifier)
    throw(css::lang::IllegalArgumentException)
{
    Identifier2CodeHash::const_iterator pIt = m_lIdentifierHash.find(sIdentifier);
    if (pIt != m_lIdentifierHash.end())
        return pIt->second;

    // Its not well known identifier - but may be a pure key code formated as string ...
    // Check and convert it!
    sal_uInt16 nCode = 0;
    if (!KeyMapping::impl_st_interpretIdentifierAsPureKeyCode(sIdentifier, nCode))
        throw css::lang::IllegalArgumentException(
                DECLARE_ASCII("Cant map given identifier to a valid key code value."),
                css::uno::Reference< css::uno::XInterface >(),
                0);

    return (sal_uInt16)nCode;
}

//-----------------------------------------------
::rtl::OUString KeyMapping::mapCodeToIdentifier(sal_uInt16 nCode)
{
    Code2IdentifierHash::const_iterator pIt = m_lCodeHash.find(nCode);
    if (pIt != m_lCodeHash.end())
        return pIt->second;

    // If we have no well known identifier - use the pure code value!
    return ::rtl::OUString::valueOf((sal_Int32)nCode);
}

//-----------------------------------------------
sal_Bool KeyMapping::impl_st_interpretIdentifierAsPureKeyCode(const ::rtl::OUString& sIdentifier,
                                                                    sal_uInt16&      rCode      )
{
    sal_Int32 nCode = sIdentifier.toInt32();
    if (nCode > 0)
    {
        rCode = (sal_uInt16)nCode;
        return sal_True;
    }

    // 0 is normaly an error of the called method toInt32() ...
    // But we must be aware, that the identifier is "0"!
    rCode = 0;
    return sIdentifier.equalsAscii("0");
}

} // namespace framework
<|endoftext|>


<commit_before>/*************************************************************************
 *
 *  $RCSfile: ocomponentaccess.cxx,v $
 *
 *  $Revision: 1.1 $
 *
 *  last change: $Author: as $ $Date: 2000-09-26 13:01:15 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

//_________________________________________________________________________________________________________________
//  my own includes
//_________________________________________________________________________________________________________________

#ifndef __FRAMEWORK_HELPER_OCOMPONENTACCESS_HXX_
#include <helper/ocomponentaccess.hxx>
#endif

#ifndef __FRAMEWORK_HELPER_OCOMPONENTENUMERATION_HXX_
#include <helper/ocomponentenumeration.hxx>
#endif

//_________________________________________________________________________________________________________________
//  interface includes
//_________________________________________________________________________________________________________________

#ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
#include <com/sun/star/frame/FrameSearchFlag.hpp>
#endif

//_________________________________________________________________________________________________________________
//  includes of other projects
//_________________________________________________________________________________________________________________

//_________________________________________________________________________________________________________________
//  namespace
//_________________________________________________________________________________________________________________

namespace framework{

using namespace ::com::sun::star::container     ;
using namespace ::com::sun::star::frame         ;
using namespace ::com::sun::star::lang          ;
using namespace ::com::sun::star::uno           ;
using namespace ::cppu                          ;
using namespace ::osl                           ;
using namespace ::rtl                           ;

//_________________________________________________________________________________________________________________
//  non exported const
//_________________________________________________________________________________________________________________

//_________________________________________________________________________________________________________________
//  non exported definitions
//_________________________________________________________________________________________________________________

//_________________________________________________________________________________________________________________
//  declarations
//_________________________________________________________________________________________________________________

//*****************************************************************************************************************
//  constructor
//*****************************************************************************************************************
OComponentAccess::OComponentAccess( const   Reference< XDesktop >&      xOwner  ,
                                            Mutex&                      aMutex  )
        //  Init baseclasses first
        :   OWeakObject     (           )
        // Init member
        ,   m_aMutex        ( aMutex    )
        ,   m_xOwner        ( xOwner    )
{
    // Safe impossible cases
    LOG_ASSERT( impldbg_checkParameter_OComponentAccessCtor( xOwner, aMutex ), "OComponentAccess::OComponentAccess()\nInvalid parameter detected!\n" )
}

//*****************************************************************************************************************
//  destructor
//*****************************************************************************************************************
OComponentAccess::~OComponentAccess()
{
}

//*****************************************************************************************************************
//  XInterface, XTypeProvider
//*****************************************************************************************************************
DEFINE_XINTERFACE_3(    OComponentAccess                        ,
                        OWeakObject                             ,
                        DIRECT_INTERFACE(XTypeProvider      )   ,
                        DIRECT_INTERFACE(XEnumerationAccess )   ,
                        DIRECT_INTERFACE(XElementAccess     )   )

DEFINE_XTYPEPROVIDER_3( OComponentAccess                        ,
                        XTypeProvider                           ,
                        XEnumerationAccess                      ,
                        XElementAccess                          )

//*****************************************************************************************************************
//  XEnumerationAccess
//*****************************************************************************************************************
Reference< XEnumeration > SAL_CALL OComponentAccess::createEnumeration() throw( RuntimeException )
{
    // Ready for multithreading
    LOCK_MUTEX( aGuard, m_aMutex, "OComponentAccess::createEnumeration()" )

    // Set default return value, if method failed.
    // If no desktop exist and there is no task container - return an empty enumeration!
    Reference< XEnumeration > xReturn = Reference< XEnumeration >();

    // Try to "lock" the desktop for access to task container.
    Reference< XInterface > xLock = m_xOwner.get();
    if ( xLock.is() == sal_True )
    {
        // Desktop exist => pointer to task container must be valid.
        // Initialize a new enumeration ... if some tasks and his components exist!
        // (OTasksEnumeration will make an assert, if we initialize the new instance without valid values!)

        Sequence< Reference< XComponent > > seqComponents;
        impl_collectAllChildComponents( Reference< XFramesSupplier >( xLock, UNO_QUERY ), seqComponents );
        OComponentEnumeration* pEnumeration = new OComponentEnumeration( seqComponents );
        xReturn = Reference< XEnumeration >( (OWeakObject*)pEnumeration, UNO_QUERY );
    }

    // Return result of this operation.
    return xReturn;
}

//*****************************************************************************************************************
//  XElementAccess
//*****************************************************************************************************************
Type SAL_CALL OComponentAccess::getElementType() throw( RuntimeException )
{
    // Elements in list an enumeration are components!
    // Return the uno-type of XComponent.
    return ::getCppuType((const Reference< XComponent >*)NULL);
}

//*****************************************************************************************************************
//  XElementAccess
//*****************************************************************************************************************
sal_Bool SAL_CALL OComponentAccess::hasElements() throw( RuntimeException )
{
    // Ready for multithreading
    LOCK_MUTEX( aGuard, m_aMutex, "OComponentAccess::hasElements()" )

    // Set default return value, if method failed.
    sal_Bool bReturn = sal_False;

    // Try to "lock" the desktop for access to taskscontainer.
    Reference< XInterface > xLock = m_xOwner.get();
    if ( xLock.is() == sal_True )
    {
        // Ask container of owner for existing elements.
        Reference< XElementAccess > xDesktopContainer( xLock, UNO_QUERY );
        bReturn = xDesktopContainer->hasElements();
    }

    // Return result of this operation.
    return bReturn;
}

//*****************************************************************************************************************
//  private method
//*****************************************************************************************************************
void OComponentAccess::impl_collectAllChildComponents(  const   Reference< XFramesSupplier >&           xNode           ,
                                                                 Sequence< Reference< XComponent > >&   seqComponents   )
{
    // If valid node was given ...
    if( xNode.is() == sal_True )
    {
        // ... continue collection at these.

        // Get the container of current node, collect the components of existing child frames
        // and go down to next level in tree (recursive!).

        sal_Int32 nComponentCount = seqComponents.getLength();

        const Reference< XFrames >              xContainer  = xNode->getFrames();
        const Sequence< Reference< XFrame > >   seqFrames   = xContainer->queryFrames( FrameSearchFlag::CHILDREN );

        const sal_Int32 nFrameCount = seqFrames.getLength();
        for( sal_Int32 nFrame=0; nFrame<nFrameCount; ++nFrame )
        {
            Reference< XComponent > xComponent = impl_getFrameComponent( seqFrames[nFrame] );
            if( xComponent.is() == sal_True )
            {
                nComponentCount++;
                seqComponents.realloc( nComponentCount );
                seqComponents[nComponentCount-1] = xComponent;
            }

            impl_collectAllChildComponents( Reference< XFramesSupplier>( seqFrames[nFrame], UNO_QUERY ), seqComponents );
        }
    }
    // ... otherwise break a recursive path and go back at current stack!
}

//*****************************************************************************************************************
//  private method
//*****************************************************************************************************************
Reference< XComponent > OComponentAccess::impl_getFrameComponent( const Reference< XFrame >& xFrame ) const
{
    // Set default return value, if method failed.
    Reference< XComponent > xComponent = Reference< XComponent >();
    // Does no controller exists?
    Reference< XController > xController = xFrame->getController();
    if ( xController.is() == sal_False )
    {
        // Controller not exist - use the VCL-component.
        xComponent = Reference< XComponent >( xFrame->getComponentWindow(), UNO_QUERY );
    }
    else
    {
        // Does no model exists?
        Reference< XModel > xModel( xController->getModel(), UNO_QUERY );
        if ( xModel.is() == sal_True )
        {
            // Model exist - use the model as component.
            xComponent = Reference< XComponent >( xModel, UNO_QUERY );
        }
        else
        {
            // Model not exist - use the controller as component.
            xComponent = Reference< XComponent >( xController, UNO_QUERY );
        }
    }

    return xComponent;
}

//_________________________________________________________________________________________________________________
//  debug methods
//_________________________________________________________________________________________________________________

/*-----------------------------------------------------------------------------------------------------------------
    The follow methods checks the parameter for other functions. If a parameter or his value is non valid,
    we return "sal_False". (else sal_True) This mechanism is used to throw an ASSERT!

    ATTENTION

        If you miss a test for one of this parameters, contact the autor or add it himself !(?)
        But ... look for right testing! See using of this methods!
-----------------------------------------------------------------------------------------------------------------*/

#ifdef ENABLE_ASSERTIONS

//*****************************************************************************************************************
sal_Bool OComponentAccess::impldbg_checkParameter_OComponentAccessCtor( const   Reference< XDesktop >&      xOwner  ,
                                                                                Mutex&                      aMutex  ) const
{
    // Set default return value.
    sal_Bool bOK = sal_True;
    // Check parameter.
    if  (
            ( &xOwner       ==  NULL        )   ||
            ( &aMutex       ==  NULL        )   ||
            ( xOwner.is()   ==  sal_False   )
        )
    {
        bOK = sal_False ;
    }
    // Return result of check.
    return bOK ;
}

#endif  //  #ifdef ENABLE_ASSERTIONS

}       //  namespace framework
<commit_msg>#79212# use right interface to get component access at desktop<commit_after>/*************************************************************************
 *
 *  $RCSfile: ocomponentaccess.cxx,v $
 *
 *  $Revision: 1.2 $
 *
 *  last change: $Author: as $ $Date: 2000-10-06 11:34:43 $
 *
 *  The Contents of this file are made available subject to the terms of
 *  either of the following licenses
 *
 *         - GNU Lesser General Public License Version 2.1
 *         - Sun Industry Standards Source License Version 1.1
 *
 *  Sun Microsystems Inc., October, 2000
 *
 *  GNU Lesser General Public License Version 2.1
 *  =============================================
 *  Copyright 2000 by Sun Microsystems, Inc.
 *  901 San Antonio Road, Palo Alto, CA 94303, USA
 *
 *  This library is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU Lesser General Public
 *  License version 2.1, as published by the Free Software Foundation.
 *
 *  This library is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *  Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public
 *  License along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *  MA  02111-1307  USA
 *
 *
 *  Sun Industry Standards Source License Version 1.1
 *  =================================================
 *  The contents of this file are subject to the Sun Industry Standards
 *  Source License Version 1.1 (the "License"); You may not use this file
 *  except in compliance with the License. You may obtain a copy of the
 *  License at http://www.openoffice.org/license.html.
 *
 *  Software provided under this License is provided on an "AS IS" basis,
 *  WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
 *  WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
 *  MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
 *  See the License for the specific provisions governing your rights and
 *  obligations concerning the Software.
 *
 *  The Initial Developer of the Original Code is: Sun Microsystems, Inc.
 *
 *  Copyright: 2000 by Sun Microsystems, Inc.
 *
 *  All Rights Reserved.
 *
 *  Contributor(s): _______________________________________
 *
 *
 ************************************************************************/

//_________________________________________________________________________________________________________________
//  my own includes
//_________________________________________________________________________________________________________________

#ifndef __FRAMEWORK_HELPER_OCOMPONENTACCESS_HXX_
#include <helper/ocomponentaccess.hxx>
#endif

#ifndef __FRAMEWORK_HELPER_OCOMPONENTENUMERATION_HXX_
#include <helper/ocomponentenumeration.hxx>
#endif

//_________________________________________________________________________________________________________________
//  interface includes
//_________________________________________________________________________________________________________________

#ifndef _COM_SUN_STAR_FRAME_FRAMESEARCHFLAG_HPP_
#include <com/sun/star/frame/FrameSearchFlag.hpp>
#endif

//_________________________________________________________________________________________________________________
//  includes of other projects
//_________________________________________________________________________________________________________________

//_________________________________________________________________________________________________________________
//  namespace
//_________________________________________________________________________________________________________________

namespace framework{

using namespace ::com::sun::star::container     ;
using namespace ::com::sun::star::frame         ;
using namespace ::com::sun::star::lang          ;
using namespace ::com::sun::star::uno           ;
using namespace ::cppu                          ;
using namespace ::osl                           ;
using namespace ::rtl                           ;

//_________________________________________________________________________________________________________________
//  non exported const
//_________________________________________________________________________________________________________________

//_________________________________________________________________________________________________________________
//  non exported definitions
//_________________________________________________________________________________________________________________

//_________________________________________________________________________________________________________________
//  declarations
//_________________________________________________________________________________________________________________

//*****************************************************************************************************************
//  constructor
//*****************************************************************************************************************
OComponentAccess::OComponentAccess( const   Reference< XDesktop >&      xOwner  ,
                                            Mutex&                      aMutex  )
        //  Init baseclasses first
        :   OWeakObject     (           )
        // Init member
        ,   m_aMutex        ( aMutex    )
        ,   m_xOwner        ( xOwner    )
{
    // Safe impossible cases
    LOG_ASSERT( impldbg_checkParameter_OComponentAccessCtor( xOwner, aMutex ), "OComponentAccess::OComponentAccess()\nInvalid parameter detected!\n" )
}

//*****************************************************************************************************************
//  destructor
//*****************************************************************************************************************
OComponentAccess::~OComponentAccess()
{
}

//*****************************************************************************************************************
//  XInterface, XTypeProvider
//*****************************************************************************************************************
DEFINE_XINTERFACE_3(    OComponentAccess                        ,
                        OWeakObject                             ,
                        DIRECT_INTERFACE(XTypeProvider      )   ,
                        DIRECT_INTERFACE(XEnumerationAccess )   ,
                        DIRECT_INTERFACE(XElementAccess     )   )

DEFINE_XTYPEPROVIDER_3( OComponentAccess                        ,
                        XTypeProvider                           ,
                        XEnumerationAccess                      ,
                        XElementAccess                          )

//*****************************************************************************************************************
//  XEnumerationAccess
//*****************************************************************************************************************
Reference< XEnumeration > SAL_CALL OComponentAccess::createEnumeration() throw( RuntimeException )
{
    // Ready for multithreading
    LOCK_MUTEX( aGuard, m_aMutex, "OComponentAccess::createEnumeration()" )

    // Set default return value, if method failed.
    // If no desktop exist and there is no task container - return an empty enumeration!
    Reference< XEnumeration > xReturn = Reference< XEnumeration >();

    // Try to "lock" the desktop for access to task container.
    Reference< XInterface > xLock = m_xOwner.get();
    if ( xLock.is() == sal_True )
    {
        // Desktop exist => pointer to task container must be valid.
        // Initialize a new enumeration ... if some tasks and his components exist!
        // (OTasksEnumeration will make an assert, if we initialize the new instance without valid values!)

        Sequence< Reference< XComponent > > seqComponents;
        impl_collectAllChildComponents( Reference< XFramesSupplier >( xLock, UNO_QUERY ), seqComponents );
        OComponentEnumeration* pEnumeration = new OComponentEnumeration( seqComponents );
        xReturn = Reference< XEnumeration >( (OWeakObject*)pEnumeration, UNO_QUERY );
    }

    // Return result of this operation.
    return xReturn;
}

//*****************************************************************************************************************
//  XElementAccess
//*****************************************************************************************************************
Type SAL_CALL OComponentAccess::getElementType() throw( RuntimeException )
{
    // Elements in list an enumeration are components!
    // Return the uno-type of XComponent.
    return ::getCppuType((const Reference< XComponent >*)NULL);
}

//*****************************************************************************************************************
//  XElementAccess
//*****************************************************************************************************************
sal_Bool SAL_CALL OComponentAccess::hasElements() throw( RuntimeException )
{
    // Ready for multithreading
    LOCK_MUTEX( aGuard, m_aMutex, "OComponentAccess::hasElements()" )

    // Set default return value, if method failed.
    sal_Bool bReturn = sal_False;

    // Try to "lock" the desktop for access to task container.
    Reference< XFramesSupplier > xLock( m_xOwner.get(), UNO_QUERY );
    if ( xLock.is() == sal_True )
    {
        // Ask container of owner for existing elements.
        bReturn = xLock->getFrames()->hasElements();
    }

    // Return result of this operation.
    return bReturn;
}

//*****************************************************************************************************************
//  private method
//*****************************************************************************************************************
void OComponentAccess::impl_collectAllChildComponents(  const   Reference< XFramesSupplier >&           xNode           ,
                                                                 Sequence< Reference< XComponent > >&   seqComponents   )
{
    // If valid node was given ...
    if( xNode.is() == sal_True )
    {
        // ... continue collection at these.

        // Get the container of current node, collect the components of existing child frames
        // and go down to next level in tree (recursive!).

        sal_Int32 nComponentCount = seqComponents.getLength();

        const Reference< XFrames >              xContainer  = xNode->getFrames();
        const Sequence< Reference< XFrame > >   seqFrames   = xContainer->queryFrames( FrameSearchFlag::CHILDREN );

        const sal_Int32 nFrameCount = seqFrames.getLength();
        for( sal_Int32 nFrame=0; nFrame<nFrameCount; ++nFrame )
        {
            Reference< XComponent > xComponent = impl_getFrameComponent( seqFrames[nFrame] );
            if( xComponent.is() == sal_True )
            {
                nComponentCount++;
                seqComponents.realloc( nComponentCount );
                seqComponents[nComponentCount-1] = xComponent;
            }

            impl_collectAllChildComponents( Reference< XFramesSupplier>( seqFrames[nFrame], UNO_QUERY ), seqComponents );
        }
    }
    // ... otherwise break a recursive path and go back at current stack!
}

//*****************************************************************************************************************
//  private method
//*****************************************************************************************************************
Reference< XComponent > OComponentAccess::impl_getFrameComponent( const Reference< XFrame >& xFrame ) const
{
    // Set default return value, if method failed.
    Reference< XComponent > xComponent = Reference< XComponent >();
    // Does no controller exists?
    Reference< XController > xController = xFrame->getController();
    if ( xController.is() == sal_False )
    {
        // Controller not exist - use the VCL-component.
        xComponent = Reference< XComponent >( xFrame->getComponentWindow(), UNO_QUERY );
    }
    else
    {
        // Does no model exists?
        Reference< XModel > xModel( xController->getModel(), UNO_QUERY );
        if ( xModel.is() == sal_True )
        {
            // Model exist - use the model as component.
            xComponent = Reference< XComponent >( xModel, UNO_QUERY );
        }
        else
        {
            // Model not exist - use the controller as component.
            xComponent = Reference< XComponent >( xController, UNO_QUERY );
        }
    }

    return xComponent;
}

//_________________________________________________________________________________________________________________
//  debug methods
//_________________________________________________________________________________________________________________

/*-----------------------------------------------------------------------------------------------------------------
    The follow methods checks the parameter for other functions. If a parameter or his value is non valid,
    we return "sal_False". (else sal_True) This mechanism is used to throw an ASSERT!

    ATTENTION

        If you miss a test for one of this parameters, contact the autor or add it himself !(?)
        But ... look for right testing! See using of this methods!
-----------------------------------------------------------------------------------------------------------------*/

#ifdef ENABLE_ASSERTIONS

//*****************************************************************************************************************
sal_Bool OComponentAccess::impldbg_checkParameter_OComponentAccessCtor( const   Reference< XDesktop >&      xOwner  ,
                                                                                Mutex&                      aMutex  ) const
{
    // Set default return value.
    sal_Bool bOK = sal_True;
    // Check parameter.
    if  (
            ( &xOwner       ==  NULL        )   ||
            ( &aMutex       ==  NULL        )   ||
            ( xOwner.is()   ==  sal_False   )
        )
    {
        bOK = sal_False ;
    }
    // Return result of check.
    return bOK ;
}

#endif  //  #ifdef ENABLE_ASSERTIONS

}       //  namespace framework
<|endoftext|>


<commit_before>/* Siconos-Kernel version 3.0.0, Copyright INRIA 2005-2008.
 * Siconos is a program dedicated to modeling, simulation and control
 * of non smooth dynamical systems.
 * Siconos is a free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * Siconos is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Siconos; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Contact: Vincent ACARY vincent.acary@inrialpes.fr
 */

/*! \file PluginTypes.hpp
  \brief list of typedef for pointers to functions used in plugin mechanism.
*/

#ifndef PLUGINTYPES_HPP
#define PLUGINTYPES_HPP

/** Pointer to function used for plug-in for matrix-type operators that depends only on time */
typedef void (*MatrixFunctionOfTime)(double, unsigned int, unsigned int, double*, unsigned int, double*);

/** Pointer to function used for plug-in for vector-type operators that depends only on time */
typedef void (*VectorFunctionOfTime)(double, unsigned int, double*, unsigned int, double*);

#include "SimpleMatrix.h"
#include "PluggedObject.hpp"

/** Matrix plugged to a MatrixFunctionOfTime */
typedef PluggedObject<MatrixFunctionOfTime, SimpleMatrix> Plugged_Matrix_FTime;

/** Vector plugged to a VectorFunctionOfTime */
typedef PluggedObject<VectorFunctionOfTime, SimpleVector> Plugged_Vector_FTime;

/** Smart pointer to a Plugged_Matrix_FTime */
TYPEDEF_SPTR(Plugged_Matrix_FTime);

/** Smart pointer to a Plugged_Vector_FTime */
TYPEDEF_SPTR(Plugged_Vector_FTime);

/** */
typedef void (*FPtr1)(double, unsigned int, const double*, double*, unsigned int, double*);

/** */
typedef void (*FPtr2)(unsigned int, const double*, unsigned int, const double*, double*, unsigned int, double*);

/** */
typedef void (*FPtr3)(unsigned int, const double*, unsigned int, double*, unsigned int, double*);
typedef void (*FPtr4bis)(unsigned int, const double*, unsigned int, double*, unsigned int, double*, unsigned int, double*);

/** */
typedef void (*FPtr4)(unsigned int, const double*, double, unsigned int, double*, unsigned int, double*);

/** */
typedef void (*FPtr5)(unsigned int, const double*, const double*, double*, unsigned int, double*);

/** */
typedef void (*FPtr6)(double, unsigned int, const double*, const double*, double*, unsigned int, double*);

/** */
typedef void (*FPtr7)(unsigned int, const double*, double*, unsigned int, double*);

#endif
<commit_msg>update is: -> Kernel without template. -> Rename Jacobian operators. -> PluggedObject unused.<commit_after>/* Siconos-Kernel version 3.0.0, Copyright INRIA 2005-2008.
 * Siconos is a program dedicated to modeling, simulation and control
 * of non smooth dynamical systems.
 * Siconos is a free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * Siconos is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Siconos; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 *
 * Contact: Vincent ACARY vincent.acary@inrialpes.fr
 */

/*! \file PluginTypes.hpp
  \brief list of typedef for pointers to functions used in plugin mechanism.
*/

#ifndef PLUGINTYPES_HPP
#define PLUGINTYPES_HPP

/** Pointer to function used for plug-in for matrix-type operators that depends only on time */
typedef void (*MatrixFunctionOfTime)(double, unsigned int, unsigned int, double*, unsigned int, double*);

/** Pointer to function used for plug-in for vector-type operators that depends only on time */
typedef void (*VectorFunctionOfTime)(double, unsigned int, double*, unsigned int, double*);

#include "SimpleMatrix.h"

/** */
typedef void (*FPtr1)(double, unsigned int, const double*, double*, unsigned int, double*);

/** */
typedef void (*FPtr2)(unsigned int, const double*, unsigned int, const double*, double*, unsigned int, double*);

/** */
typedef void (*FPtr3)(unsigned int, const double*, unsigned int, double*, unsigned int, double*);
typedef void (*FPtr4bis)(unsigned int, const double*, unsigned int, double*, unsigned int, double*, unsigned int, double*);

/** */
typedef void (*FPtr4)(unsigned int, const double*, double, unsigned int, double*, unsigned int, double*);

/** */
typedef void (*FPtr5)(unsigned int, const double*, const double*, double*, unsigned int, double*);

/** */
typedef void (*FPtr6)(double, unsigned int, const double*, const double*, double*, unsigned int, double*);

/** */
typedef void (*FPtr7)(unsigned int, const double*, double*, unsigned int, double*);

#endif
<|endoftext|>


<commit_before>// RUN: cat %s | %cling 2>&1 | FileCheck %s

// Test the ability of unloading the last transaction. Here as a matter of fact
// we unload the wrapper as well and TODO: decrement the unique wrapper counter.
extern "C" int printf(const char* fmt, ...);
printf("Force printf codegeneration. Otherwise CG will defer it and .storeState will be unhappy.\n");
//CHECK: Force printf codegeneration. Otherwise CG will defer it and .storeState will be unhappy.
.storeState "preUnload"
int f = 0;
.U
.rawInput 1
int f() {
  printf("Now f is a function\n");
  return 0;
} int a = f();
.U
.rawInput 0
//CHECK: Now f is a function
.compareState "preUnload"
//CHECK-NOT: Differences
double f = 3.14
//CHECK: (double) 3.14
<commit_msg>Fail the test because of the dead constant leftover.<commit_after>// RUN: cat %s | %cling 2>&1 | FileCheck %s
// XFAIL:*
// because we fail to remove a dead constant. We should investigate the globalDCE pass.
// +@.str1 = private unnamed_addr constant [21 x i8] c"Now f is a function\0A\00", align 1
// Test the ability of unloading the last transaction. Here as a matter of fact
// we unload the wrapper as well and TODO: decrement the unique wrapper counter.
extern "C" int printf(const char* fmt, ...);
printf("Force printf codegeneration. Otherwise CG will defer it and .storeState will be unhappy.\n");
//CHECK: Force printf codegeneration. Otherwise CG will defer it and .storeState will be unhappy.
.storeState "preUnload"
int f = 0;
.U
.rawInput 1
int f() {
  printf("Now f is a function\n");
  return 0;
} int a = f();
.U
.rawInput 0
//CHECK: Now f is a function
.compareState "preUnload"
//CHECK-NOT: Differences
double f = 3.14
//CHECK: (double) 3.14
<|endoftext|>


<commit_before>// Test instrumentation of C++ exception handling constructs.

// FIXME: Don't seek bb labels, like "if.else"
// REQUIRES: asserts

// RUN: %clangxx %s -o - -emit-llvm -S -fprofile-instr-generate -fexceptions -target %itanium_abi_triple | FileCheck -check-prefix=PGOGEN %s
// RUN: %clangxx %s -o - -emit-llvm -S -fprofile-instr-generate -fexceptions -target %itanium_abi_triple | FileCheck -check-prefix=PGOGEN-EXC %s

// RUN: llvm-profdata merge %S/Inputs/cxx-throws.proftext -o %t.profdata
// RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-use=%t.profdata -fcxx-exceptions -target %itanium_abi_triple | FileCheck -check-prefix=PGOUSE %s
// RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-use=%t.profdata -fcxx-exceptions -target %itanium_abi_triple | FileCheck -check-prefix=PGOUSE-EXC %s

// PGOGEN: @[[THC:__llvm_profile_counters__Z6throwsv]] = private global [9 x i64] zeroinitializer
// PGOGEN-EXC: @[[THC:__llvm_profile_counters__Z6throwsv]] = private global [9 x i64] zeroinitializer
// PGOGEN: @[[UNC:__llvm_profile_counters__Z11unreachablei]] = private global [3 x i64] zeroinitializer

// PGOGEN-LABEL: @_Z6throwsv()
// PGOUSE-LABEL: @_Z6throwsv()
// PGOGEN: store {{.*}} @[[THC]], i64 0, i64 0
void throws() {
  // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 1
  // PGOUSE: br {{.*}} !prof ![[TH1:[0-9]+]]
  for (int i = 0; i < 100; ++i) {
    try {
      // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 3
      // PGOUSE: br {{.*}} !prof ![[TH2:[0-9]+]]
      if (i % 3) {
        // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 4
        // PGOUSE: br {{.*}} !prof ![[TH3:[0-9]+]]
        if (i < 50)
          throw 1;
      } else {
        // The catch block may be emitted after the throw above, we can skip it
        // by looking for an else block, but this will break if anyone puts an
        // else in the catch
        // PGOUSE: if.else{{.*}}:
        // PGOGEN: if.else{{.*}}:

        // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 5
        // PGOUSE: br {{.*}} !prof ![[TH4:[0-9]+]]
        if (i >= 50)
          throw 0;
      }
    } catch (int e) {
      // PGOUSE-EXC: catch{{.*}}:
      // PGOGEN-EXC: catch{{.*}}:

      // PGOGEN-EXC: store {{.*}} @[[THC]], i64 0, i64 6
      // PGOGEN-EXC: store {{.*}} @[[THC]], i64 0, i64 7
      // PGOUSE-EXC: br {{.*}} !prof ![[TH5:[0-9]+]]
      if (e) {}
    }
    // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 2

    // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 8
    // PGOUSE: br {{.*}} !prof ![[TH6:[0-9]+]]
    if (i < 100) {}
  }

  // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
  // PGOUSE: ret void
}

// PGOGEN-LABEL: @_Z11unreachablei(i32 %i)
// PGOUSE-LABEL: @_Z11unreachablei(i32 %i)
// PGOGEN: store {{.*}} @[[UNC]], i64 0, i64 0
void unreachable(int i) {
  // PGOGEN: store {{.*}} @[[UNC]], i64 0, i64 1
  // PGOUSE: br {{.*}} !prof ![[UN1:[0-9]+]]
  if (i)
    throw i;

  // PGOGEN: store {{.*}} @[[UNC]], i64 0, i64 2
  // Since we never reach here, the weights should all be zero (and skipped)
  // PGOUSE-NOT: br {{.*}} !prof !{{.*}}
  if (i) {}
}

// PGOUSE-DAG: ![[TH1]] = !{!"branch_weights", i32 101, i32 2}
// PGOUSE-DAG: ![[TH2]] = !{!"branch_weights", i32 67, i32 35}
// PGOUSE-DAG: ![[TH3]] = !{!"branch_weights", i32 34, i32 34}
// PGOUSE-DAG: ![[TH4]] = !{!"branch_weights", i32 18, i32 18}
// PGOUSE-EXC: ![[TH5]] = !{!"branch_weights", i32 34, i32 18}
// PGOUSE-DAG: ![[TH6]] = !{!"branch_weights", i32 101, i32 1}
// PGOUSE-DAG: ![[UN1]] = !{!"branch_weights", i32 2, i32 1}

int main(int argc, const char *argv[]) {
  throws();
  try {
    unreachable(1);
  } catch (int) {}
  return 0;
}
<commit_msg>InstrProf: Match a bit less strictly - some targets may add signext<commit_after>// Test instrumentation of C++ exception handling constructs.

// FIXME: Don't seek bb labels, like "if.else"
// REQUIRES: asserts

// RUN: %clangxx %s -o - -emit-llvm -S -fprofile-instr-generate -fexceptions -target %itanium_abi_triple | FileCheck -check-prefix=PGOGEN %s
// RUN: %clangxx %s -o - -emit-llvm -S -fprofile-instr-generate -fexceptions -target %itanium_abi_triple | FileCheck -check-prefix=PGOGEN-EXC %s

// RUN: llvm-profdata merge %S/Inputs/cxx-throws.proftext -o %t.profdata
// RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-use=%t.profdata -fcxx-exceptions -target %itanium_abi_triple | FileCheck -check-prefix=PGOUSE %s
// RUN: %clang %s -o - -emit-llvm -S -fprofile-instr-use=%t.profdata -fcxx-exceptions -target %itanium_abi_triple | FileCheck -check-prefix=PGOUSE-EXC %s

// PGOGEN: @[[THC:__llvm_profile_counters__Z6throwsv]] = private global [9 x i64] zeroinitializer
// PGOGEN-EXC: @[[THC:__llvm_profile_counters__Z6throwsv]] = private global [9 x i64] zeroinitializer
// PGOGEN: @[[UNC:__llvm_profile_counters__Z11unreachablei]] = private global [3 x i64] zeroinitializer

// PGOGEN-LABEL: @_Z6throwsv()
// PGOUSE-LABEL: @_Z6throwsv()
// PGOGEN: store {{.*}} @[[THC]], i64 0, i64 0
void throws() {
  // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 1
  // PGOUSE: br {{.*}} !prof ![[TH1:[0-9]+]]
  for (int i = 0; i < 100; ++i) {
    try {
      // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 3
      // PGOUSE: br {{.*}} !prof ![[TH2:[0-9]+]]
      if (i % 3) {
        // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 4
        // PGOUSE: br {{.*}} !prof ![[TH3:[0-9]+]]
        if (i < 50)
          throw 1;
      } else {
        // The catch block may be emitted after the throw above, we can skip it
        // by looking for an else block, but this will break if anyone puts an
        // else in the catch
        // PGOUSE: if.else{{.*}}:
        // PGOGEN: if.else{{.*}}:

        // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 5
        // PGOUSE: br {{.*}} !prof ![[TH4:[0-9]+]]
        if (i >= 50)
          throw 0;
      }
    } catch (int e) {
      // PGOUSE-EXC: catch{{.*}}:
      // PGOGEN-EXC: catch{{.*}}:

      // PGOGEN-EXC: store {{.*}} @[[THC]], i64 0, i64 6
      // PGOGEN-EXC: store {{.*}} @[[THC]], i64 0, i64 7
      // PGOUSE-EXC: br {{.*}} !prof ![[TH5:[0-9]+]]
      if (e) {}
    }
    // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 2

    // PGOGEN: store {{.*}} @[[THC]], i64 0, i64 8
    // PGOUSE: br {{.*}} !prof ![[TH6:[0-9]+]]
    if (i < 100) {}
  }

  // PGOUSE-NOT: br {{.*}} !prof ![0-9]+
  // PGOUSE: ret void
}

// PGOGEN-LABEL: @_Z11unreachablei(i32
// PGOUSE-LABEL: @_Z11unreachablei(i32
// PGOGEN: store {{.*}} @[[UNC]], i64 0, i64 0
void unreachable(int i) {
  // PGOGEN: store {{.*}} @[[UNC]], i64 0, i64 1
  // PGOUSE: br {{.*}} !prof ![[UN1:[0-9]+]]
  if (i)
    throw i;

  // PGOGEN: store {{.*}} @[[UNC]], i64 0, i64 2
  // Since we never reach here, the weights should all be zero (and skipped)
  // PGOUSE-NOT: br {{.*}} !prof !{{.*}}
  if (i) {}
}

// PGOUSE-DAG: ![[TH1]] = !{!"branch_weights", i32 101, i32 2}
// PGOUSE-DAG: ![[TH2]] = !{!"branch_weights", i32 67, i32 35}
// PGOUSE-DAG: ![[TH3]] = !{!"branch_weights", i32 34, i32 34}
// PGOUSE-DAG: ![[TH4]] = !{!"branch_weights", i32 18, i32 18}
// PGOUSE-EXC: ![[TH5]] = !{!"branch_weights", i32 34, i32 18}
// PGOUSE-DAG: ![[TH6]] = !{!"branch_weights", i32 101, i32 1}
// PGOUSE-DAG: ![[UN1]] = !{!"branch_weights", i32 2, i32 1}

int main(int argc, const char *argv[]) {
  throws();
  try {
    unreachable(1);
  } catch (int) {}
  return 0;
}
<|endoftext|>