/*
 * ************************************************************************************************************
 * 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: mzstdgui
 * Version: 1.07
 * First release date:   2010-11-08
 * Current release date: 2011-03-04
 *
 *
 * This file is part of mzstdgui library
 * 
 * mzstdgui 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.
 * 
 * mzstdgui 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/>.
 * ************************************************************************************************************
 */

#ifndef __MZSTDGUI_LAYOUT_FILE_H__
#define __MZSTDGUI_LAYOUT_FILE_H__

#include "mzstdguiCommon.h"
#include "mzObject.h"
#include "mzString.h"
#include "mzStyledWindow.h"
#include "mzGuiContainer.h"
#include "mzResource.h"
#include "mzStringList.h"

class CLayoutFile;
typedef VOID (WINAPI *ADDGUICONTROLFUNC)(CLayoutFile* loader, CStdObject* item, CGuiContainer* parent);


class DECLSPEC_MZSTDGUI CLayoutFile : public CObject {
public:
    WINAPI CLayoutFile();
    virtual WINAPI ~CLayoutFile();
    
    BOOL WINAPI loadLayoutFromFile(CString fname, INT layoutContentType, CStyledWindow* wnd);    
    BOOL WINAPI loadLayout(CString layoutContent, INT layoutContentType, CStyledWindow* wnd);    
    VOID WINAPI addControl(CGuiControl* gc, CGuiContainer* parent);
    VOID WINAPI getCommonProperties(CStdObject* item, BOOL* transparentDrawing);
    VOID WINAPI getDimensionProperties(CStdObject* item, LONG* x, LONG* y, LONG* width, LONG* height);
    VOID WINAPI getRelativePositionProperties(CStdObject* item, CString* relativeControl, CString* relativePosition);    
    VOID WINAPI doRelativePositioning(CGuiControl* gc, WCHAR* positionRelativeTo, WCHAR* position);

protected:
    // auxiliary array of controls to add to window
    CArrayList* _controls;
    CGuiControl* WINAPI _getControl(WCHAR* name);
    VOID WINAPI _commonInit();
    virtual VOID WINAPI _cleanup();

private:
    // Variable valid only during call to drawJsonFile method.
    // It is set to canvas pointer and NULL-ed just before drawJsonFile method return.
    CStyledWindow* _wnd;
    CString _filename;

    CStringList* WINAPI _getAsStringList(CStdObject* item, WCHAR* name);
    VOID WINAPI _processData(CStdObject* data);
    VOID WINAPI _processToplevelItems(CArrayList* items);
    VOID WINAPI _processItems(CArrayList* items, CGuiContainer* parent);
    VOID WINAPI _processWindowItem(CStdObject* item);
    VOID WINAPI _processMenuItem(CStdObject* item, CGuiContainer* parent);
    VOID WINAPI _processLabelItem(CStdObject* item, CGuiContainer* parent);
    VOID WINAPI _processTextfieldItem(CStdObject* item, CGuiContainer* parent);
    VOID WINAPI _processGridItem(CStdObject* item, CGuiContainer* parent);
    VOID WINAPI _processButtonItem(CStdObject* item, CGuiContainer* parent);
    VOID WINAPI _processCheckboxItem(CStdObject* item, CGuiContainer* parent);
    VOID WINAPI _processListboxItem(CStdObject* item, CGuiContainer* parent);
    VOID WINAPI _processGuiControlFromOtherDllItem(CStdObject* item, CGuiContainer* parent);
};
typedef CLayoutFile* PLayoutFile;

#endif
