00001 #include "stdafx.h"
00002 #include "Console.h"
00003
00004 #include "Gme.h"
00005
00006 namespace GMEConsole
00007 {
00008 CComPtr<IGMEOLEApp> Console::gmeoleapp = 0;
00009
00010 void Console::SetupConsole(CComPtr<IMgaProject> project)
00011 {
00012 CComPtr<IMgaClient> client;
00013 CComQIPtr<IDispatch> pDispatch;
00014 HRESULT s1 = project->GetClientByName(CComBSTR(L"GME.Application"), &client);
00015
00016 if ((SUCCEEDED(s1)) && (client != 0))
00017 {
00018 HRESULT s2 = client->get_OLEServer(&pDispatch);
00019 if ((SUCCEEDED(s2)) && (pDispatch != 0) && gmeoleapp == 0)
00020 {
00021 COMTHROW(pDispatch->QueryInterface(&gmeoleapp));
00022 }
00023 }
00024 }
00025 void Console::ReleaseConsole() {
00026 if (gmeoleapp)
00027 gmeoleapp.Release();
00028 }
00029
00030 void Console::WriteLine(const CString& message, msgtype_enum type)
00031 {
00032 if (gmeoleapp == 0) {
00033 switch (type) {
00034 case MSG_NORMAL:
00035 case MSG_INFO:
00036 case MSG_WARNING:
00037 _tprintf(_T("%s\n"), message);
00038 break;
00039 case MSG_ERROR:
00040 _ftprintf(stderr, _T("%s\n"), message);
00041 break;
00042 }
00043 }
00044 else {
00045 COMTHROW(gmeoleapp->ConsoleMessage( CComBSTR(message.GetLength(),message),type));
00046 }
00047 }
00048
00049 void Console::Clear()
00050 {
00051 if (gmeoleapp != 0) {
00052 CComBSTR empty(L"");
00053 COMTHROW(gmeoleapp->put_ConsoleContents(empty));
00054 }
00055 }
00056
00057 void Console::SetContents(const CString& contents)
00058 {
00059 if (gmeoleapp != 0) {
00060 COMTHROW(gmeoleapp->put_ConsoleContents( CComBSTR(contents.GetLength(),contents)));
00061 }
00062 }
00063
00064 void Console::NavigateTo(const CString& url)
00065 {
00066 if (gmeoleapp != 0) {
00067 COMTHROW(gmeoleapp->ConsoleNavigateTo(CComBSTR(url.GetLength(), url)));
00068 }
00069 }
00070
00071 void Console::Error::WriteLine(const CString& message)
00072 {
00073 Console::WriteLine(message,MSG_ERROR);
00074 }
00075
00076 void Console::Out::WriteLine(const CString& message)
00077 {
00078 Console::WriteLine(message, MSG_NORMAL);
00079 }
00080 void Console::Warning::WriteLine(const CString& message)
00081 {
00082 Console::WriteLine(message, MSG_WARNING);
00083 }
00084 void Console::Info::writeLine(const CString& message)
00085 {
00086 Console::WriteLine(message,MSG_INFO);
00087 }
00088 void Console::Info::WriteLine(const CString& message)
00089 {
00090 Console::WriteLine(message,MSG_INFO);
00091 }
00092 }
00093
00094