#ifndef _COMMON_WINDOWSTATION_HPP_
#define _COMMON_WINDOWSTATION_HPP_
#ifndef _COMMON_WINDOWS_HPP_
#include <common/windows.hpp>
#endif
#ifndef _COMMON_STRING_HPP_
#include <common/string.hpp>
#endif

class WindowStation
{
public:
  enum Access{AccessClipboard=WINSTA_ACCESSCLIPBOARD,AccessGlobalAtoms=WINSTA_ACCESSGLOBALATOMS,AccessCreateDesktop=WINSTA_CREATEDESKTOP,
	            AccessEnumerateDesktops=WINSTA_ENUMDESKTOPS,AccessEnumerate=WINSTA_ENUMERATE,AccessExitWindows=WINSTA_EXITWINDOWS,
							AccessReadAttributes=WINSTA_READATTRIBUTES,AccessReadScreen=WINSTA_READSCREEN,AccessWriteAttributes=WINSTA_WRITEATTRIBUTES};
  WindowStation(void);
	WindowStation(const String &strWindowStation,DWORD desriredAccess=AccessEnumerateDesktops|AccessEnumerate,bool inheritHandle=false);
	virtual ~WindowStation();
	bool open(const String &strWindowStation,DWORD desiredAccess=AccessEnumerateDesktops|AccessEnumerate,bool inheritHandle=false);
	void close(void);
	const String &windowStation(void)const;
	HWINSTA getHandle(void)const;
	bool isOkay(void)const;
private:
  WindowStation(const WindowStation &someWindowStation);
	WindowStation &operator=(const WindowStation &someWindowStation);

  String mStrWindowStation;
  HWINSTA mhWindowStation;
};

inline
WindowStation::WindowStation(void)
: mhWindowStation(0)
{
}

inline
WindowStation::WindowStation(const String &strWindowStation,DWORD desiredAccess,bool inheritHandle)
: mhWindowStation(0)
{
  open(strWindowStation,desiredAccess,inheritHandle);
}

inline
WindowStation::WindowStation(const WindowStation &/*someWindowStation*/)
{ // private implemnentation
}

inline
WindowStation::~WindowStation()
{
  close();
}

inline
WindowStation &WindowStation::operator=(const WindowStation &/*someWindowStation*/)
{ // private implementation
  return *this;
}

inline
bool WindowStation::isOkay(void)const
{
  return getHandle()?true:false;
}

inline
bool WindowStation::open(const String &strWindowStation,DWORD desiredAccess,bool inheritHandles)
{
  close();
	if(strWindowStation.isNull())return false;
	mStrWindowStation=strWindowStation;
	mhWindowStation=::OpenWindowStation((LPSTR)(String&)strWindowStation,inheritHandles,desiredAccess);
	return isOkay();
}

inline
void WindowStation::close(void)
{
  if(!isOkay())return;
	::CloseWindowStation(mhWindowStation);
	mhWindowStation=0;
}

inline
const String &WindowStation::windowStation(void)const
{
  return mStrWindowStation;
}

inline
HWINSTA WindowStation::getHandle(void)const
{
  return mhWindowStation;
}
#endif
