/*
 * ************************************************************************************************************
 * Author: Marcin Załęczny
 * Copyright (C)2010 Marcin Załęczny <mzaleczny@hotmail.com>
 * License: The GNU Lesser General Public License, version 3.0 (LGPLv3)
 * Library Name: mzstd
 * Version: 1.07
 * First release date:   2010-11-08
 * Current release date: 2011-03-04
 *
 *
 * This file is part of mzstd library
 * 
 * mzstd library is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 * 
 * mzstd 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 program. If not, see <http://www.gnu.org/licenses/>.
 * ************************************************************************************************************
 */

#include "mzstdGlobals.h"
#include "mzMessageBox.h"

LONG msgboxOpened = 0;

BOOL WINAPI isMessageBoxOpened() {
    return ::msgboxOpened > 0;
}

LONG WINAPI MessageBox(CString caption, CString message) {
    ::msgboxOpened += 1;
	LONG result = MessageBox(GetActiveWindow(), message.getBuffer(), caption.getBuffer(), MB_OK | MB_ICONINFORMATION);
    ::msgboxOpened -= 1;
    return result;
}

LONG WINAPI AlertBox(CString message) {
    ::msgboxOpened += 1;
	LONG result = MessageBox(GetActiveWindow(), message.getBuffer(), L"Uwaga", MB_OK | MB_ICONWARNING);
    ::msgboxOpened -= 1;
    return result;
}

LONG WINAPI WarningBox(CString message) {
    ::msgboxOpened += 1;
	LONG result = MessageBox(GetActiveWindow(), message.getBuffer(), L"Uwaga", MB_OK | MB_ICONWARNING);
    ::msgboxOpened -= 1;
    return result;
}

LONG WINAPI QuestionBox(CString message) {
    ::msgboxOpened += 1;
	LONG result = MessageBox(GetActiveWindow(), message.getBuffer(), L"Pytanie", MB_YESNO | MB_ICONQUESTION);
    ::msgboxOpened -= 1;
    return result;
}

LONG WINAPI QuestionCancelBox(CString message) {
    ::msgboxOpened += 1;
	LONG result = MessageBox(GetActiveWindow(), message.getBuffer(), L"Pytanie", MB_YESNOCANCEL | MB_ICONQUESTION);
    ::msgboxOpened -= 1;
    return result;
}

LONG WINAPI ErrorBox(CString message) {
    ::msgboxOpened += 1;
	LONG result = MessageBox(GetActiveWindow(), message.getBuffer(), L"Błąd", MB_OK | MB_ICONERROR);
    ::msgboxOpened -= 1;
    return result;
}

LONG WINAPI InformationBox(CString message) {
    ::msgboxOpened += 1;
	LONG result = MessageBox(GetActiveWindow(), message.getBuffer(), L"Informacja", MB_OK | MB_ICONINFORMATION);
    ::msgboxOpened -= 1;
    return result;
}

VOID WINAPI ShowLastSystemError(WCHAR* prependString) {
    ShowSystemError(GetLastError(), prependString);
}

VOID WINAPI ShowSystemError(DWORD errorCode, WCHAR* prependString) {
	ErrorBox(GetSystemErrorMessage(errorCode));
}

VOID WINAPI ShowDetailedLastSystemError(WCHAR* prependString) {
    ShowDetailedSystemError(GetLastError(), prependString);
}

VOID WINAPI ShowDetailedSystemError(DWORD errorCode, WCHAR* prependString) {
	ErrorBox(GetDetailedSystemErrorMessage(errorCode, prependString));
}
