/*
 * ************************************************************************************************************
 * 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_THEME_H__
#define __MZSTDGUI_THEME_H__

#include "mzstdguiCommon.h"
#include "mzObject.h"
#include "mzString.h"
#include "mzBitmap.h"
#include "mzAnimatedBitmap.h"
#include "mzIcon.h"
#include "mzFont.h"

class CResource;
class DECLSPEC_MZSTDGUI CTheme : public CObject {
public:
    WINAPI CTheme(HINSTANCE hInst, CResource* res, CString name);
    virtual WINAPI ~CTheme();

    // Bitmapy okna
    CBitmap* wnd_caption_left;
    CBitmap* wnd_caption_middle;
    CBitmap* wnd_caption_right;
    CBitmap* wnd_caption_inactive_left;
    CBitmap* wnd_caption_inactive_middle;
    CBitmap* wnd_caption_inactive_right;
    CBitmap* wnd_frame_left;
    CBitmap* wnd_frame_right;
    CBitmap* wnd_frame_bottom;
    CBitmap* wnd_frame_bottom_left;
    CBitmap* wnd_frame_bottom_right;
    CBitmap* wnd_frame_inactive_left;
    CBitmap* wnd_frame_inactive_right;
    CBitmap* wnd_frame_inactive_bottom;
    CBitmap* wnd_frame_inactive_bottom_left;
    CBitmap* wnd_frame_inactive_bottom_right;
    CAnimatedBitmap* wnd_leftmenu_button;
    CAnimatedBitmap* wnd_minimize_button;
    CAnimatedBitmap* wnd_maximize_button;
    CAnimatedBitmap* wnd_restore_button;
    CAnimatedBitmap* wnd_close_button;

    // Bitmapy panelu
    CBitmap* panel_caption_left;
    CBitmap* panel_caption_middle;
    CBitmap* panel_caption_right;
    CBitmap* panel_nocaption_left;
    CBitmap* panel_nocaption_middle;
    CBitmap* panel_nocaption_right;
    CBitmap* panel_frame_left;
    CBitmap* panel_frame_right;
    CBitmap* panel_frame_bottom;
    CBitmap* panel_frame_bottom_left;
    CBitmap* panel_frame_bottom_right;
    CBitmap* panel_inner_bg;
    CBitmap* panel_inner_bg_fullscreen;

	// Bitmapy menu
	CBitmap* menu_bg_left;
	CBitmap* menu_bg_middle;
	CBitmap* menu_bg_right;
	CBitmap* menu_selected_mainmenu_item_bg_left;
	CBitmap* menu_selected_mainmenu_item_bg_middle;
	CBitmap* menu_selected_mainmenu_item_bg_right;
	CBitmap* menu_opened_mainmenu_item_bg_left;
	CBitmap* menu_opened_mainmenu_item_bg_middle;
	CBitmap* menu_opened_mainmenu_item_bg_right;
	CBitmap* menu_shadow_bottom_left;
	CBitmap* menu_shadow_bottom_middle;
	CBitmap* menu_shadow_bottom_right;
	CBitmap* menu_shadow_right_middle;
	CBitmap* menu_shadow_right_top;

    // Bitmapy popupmenu
    CBitmap* popupmenu_bg;
    CBitmap* popupmenu_frame_bottom;
    CBitmap* popupmenu_frame_bottom_left;
    CBitmap* popupmenu_frame_bottom_right;
    CBitmap* popupmenu_frame_left;
    CBitmap* popupmenu_frame_left_top;
    CBitmap* popupmenu_frame_right;
    CBitmap* popupmenu_frame_top;
    CBitmap* popupmenu_frame_top_hilited;
    CBitmap* popupmenu_frame_top_hilited_end;
    CBitmap* popupmenu_frame_top_right;
    CBitmap* popupmenu_icon_area_left;
    CBitmap* popupmenu_submenu_arrow;
    CBitmap* popupmenu_frame_shadow_bottom;
    CBitmap* popupmenu_frame_shadow_bottom_left;
    CBitmap* popupmenu_frame_shadow_bottom_right;
    CBitmap* popupmenu_frame_shadow_right;
    CBitmap* popupmenu_frame_shadow_top_right;
    CBitmap* popupmenu_divider;
	CBitmap* popupmenu_selected_item_bg_left;
	CBitmap* popupmenu_selected_item_bg_middle;
	CBitmap* popupmenu_selected_item_bg_right;
	CBitmap* popupmenu_opened_item_bg_left;
	CBitmap* popupmenu_opened_item_bg_middle;
	CBitmap* popupmenu_opened_item_bg_right;

    // Bitmapy toolbara przeznaczonego na ikony o rozmiarze 16x16
    CBitmap* toolbar16_left;
    CBitmap* toolbar16_middle;
    CBitmap* toolbar16_right;
    CBitmap* toolbar16_button_hilited;
    CBitmap* toolbar16_button_pressed;
    CBitmap* toolbar16_separator;

    // Bitmapy scrollbara
    CBitmap* scrollbar_horizontal_arrow_left;
    CBitmap* scrollbar_horizontal_arrow_left_clicked;
    CBitmap* scrollbar_horizontal_arrow_right;
    CBitmap* scrollbar_horizontal_arrow_right_clicked;
    CBitmap* scrollbar_horizontal_thumb_left;
    CBitmap* scrollbar_horizontal_thumb_middle;
    CBitmap* scrollbar_horizontal_thumb_right;
    CBitmap* scrollbar_horizontal_thumb_bg;
    CBitmap* scrollbar_horizontal_bg;
    CBitmap* scrollbar_horizontal_bg_clicked;
    CBitmap* scrollbar_vertical_arrow_up;
    CBitmap* scrollbar_vertical_arrow_up_clicked;
    CBitmap* scrollbar_vertical_arrow_down;
    CBitmap* scrollbar_vertical_arrow_down_clicked;
    CBitmap* scrollbar_vertical_thumb_top;
    CBitmap* scrollbar_vertical_thumb_middle;
    CBitmap* scrollbar_vertical_thumb_bottom;
    CBitmap* scrollbar_vertical_thumb_bg;
    CBitmap* scrollbar_vertical_bg;
    CBitmap* scrollbar_vertical_bg_clicked;

    // Bitmapy textfield
    CBitmap* textfield_frame_left;
    CBitmap* textfield_frame_right;
    CBitmap* textfield_frame_middle;
    CBitmap* textfield_frame_left_hover;
    CBitmap* textfield_frame_right_hover;
    CBitmap* textfield_frame_middle_hover;
    CBitmap* textfield_frame_left_active;
    CBitmap* textfield_frame_right_active;
    CBitmap* textfield_frame_middle_active;
    CBitmap* textfield_selection;

    // Bitmapy button
    CBitmap* button_left;
    CBitmap* button_right;
    CBitmap* button_middle;
    CBitmap* button_left_disabled;
    CBitmap* button_right_disabled;
    CBitmap* button_middle_disabled;
    CBitmap* button_left_hover;
    CBitmap* button_right_hover;
    CBitmap* button_middle_hover;
    CBitmap* button_left_pushed;
    CBitmap* button_right_pushed;
    CBitmap* button_middle_pushed;

    // checkbox bitmaps
    CBitmap* checkbox;
    CBitmap* checkbox_disabled;
    CBitmap* checkbox_hover;
    CBitmap* checkbox_checked;
    CBitmap* checkbox_checked_disabled;
    CBitmap* checkbox_checked_hover;

    // listbox bitmaps
    CBitmap* listbox_bg_fullscreen;
    CBitmap* listbox_bg;
    CBitmap* listbox_frame_top_left;
    CBitmap* listbox_frame_top;
    CBitmap* listbox_frame_top_right;
    CBitmap* listbox_frame_bottom_left;
    CBitmap* listbox_frame_bottom;
    CBitmap* listbox_frame_bottom_right;
    CBitmap* listbox_frame_left;
    CBitmap* listbox_frame_right;

    // Bitmapy grid
    CBitmap* grid_cell_inner_bg_normal;
    CBitmap* grid_cell_inner_bg_selected;
    CBitmap* grid_cell_inner_bg_selected_active;
    CBitmap* grid_left_header_inner_bg_normal_cell;
    CBitmap* grid_left_header_inner_bg_selected_cell;
    CBitmap* grid_left_top_header_inner_bg;
    CBitmap* grid_left_top_header_mark;
    CBitmap* grid_top_header_inner_bg_normal_cell;
    CBitmap* grid_top_header_inner_bg_selected_cell;

    // Dostępne fonty
    CFont* globalStandardFont;
    CFont* windowCaptionFont;
    CFont* captionFont;
    CFont* menuFont;
    CFont* commonLabelFont;
    CFont* commonTextControlFont;
    CFont* commonButtonControlFont;
    CFont* commonGridControlFont;
    CFont* commonCheckboxControlFont;
    CFont* commonListboxControlFont;


    // kolory fontu this->commonTextControlFont wyświetlonego w trybie normalnym i zaznaczonym
    COLORREF commonTextControlNormalFontColor;
    COLORREF commonTextControlSelectedFontColor;

    COLORREF commonGridControlTopHeaderNormalFontColor;
    COLORREF commonGridControlTopHeaderSelectedFontColor;
    COLORREF commonGridControlLeftHeaderNormalFontColor;
    COLORREF commonGridControlLeftHeaderSelectedFontColor;
    COLORREF commonGridControlTopHeaderCellBorderColor_Normal;
    COLORREF commonGridControlTopHeaderCellBorderColor_Selected;
    COLORREF commonGridControlLeftTopHeaderCellBorderColor;
    COLORREF commonGridControlLeftHeaderCellBorderColor_Normal;
    COLORREF commonGridControlLeftHeaderCellBorderColor_Selected;
    COLORREF commonGridControlCellBorderColor_Normal;
    COLORREF commonGridControlCellBorderColor_Selected;
    COLORREF commonGridControlCellBorderColor_Active;
    COLORREF commonGridControlSelectionBorderColor;
    COLORREF commonGridControlFocusedGridBorderColor;

    VOID WINAPI load(CString name);
    VOID WINAPI loadDefaultFonts();
    VOID WINAPI unload();

    VOID WINAPI loadWindowSkinResources(CString themeName);
    VOID WINAPI unloadWindowSkinResources();
    VOID WINAPI loadPanelSkinResources(CString themeName);
    VOID WINAPI unloadPanelSkinResources();
    VOID WINAPI loadMenuSkinResources(CString themeName);
    VOID WINAPI unloadMenuSkinResources();
    VOID WINAPI loadPopupmenuSkinResources(CString themeName);
    VOID WINAPI unloadPopupmenuSkinResources();
    VOID WINAPI loadToolbar16SkinResources(CString themeName);
    VOID WINAPI unloadToolbar16SkinResources();
    VOID WINAPI loadLabelSkinResources(CString themeName);
    VOID WINAPI unloadLabelSkinResources();
    VOID WINAPI loadScrollbarSkinResources(CString themeName);
    VOID WINAPI unloadScrollbarSkinResources();
    VOID WINAPI loadTextfieldSkinResources(CString themeName);
    VOID WINAPI unloadTextfieldSkinResources();
    VOID WINAPI loadButtonSkinResources(CString themeName);
    VOID WINAPI unloadButtonSkinResources();
    VOID WINAPI loadCheckboxSkinResources(CString themeName);
    VOID WINAPI unloadCheckboxSkinResources();
    VOID WINAPI loadListboxSkinResources(CString themeName);
    VOID WINAPI unloadListboxSkinResources();
    VOID WINAPI loadGridSkinResources(CString themeName);
    VOID WINAPI unloadGridSkinResources();

    BOOL WINAPI isLoaded();
    BOOL WINAPI isWindowSkinLoaded();
    BOOL WINAPI isPanelSkinLoaded();
    BOOL WINAPI isMenuSkinLoaded();
    BOOL WINAPI isPopupmenuSkinLoaded();
    BOOL WINAPI isToolbar16SkinLoaded();
    BOOL WINAPI isLabelSkinLoaded();
    BOOL WINAPI isScrollbarSkinLoaded();
    BOOL WINAPI isScrollbarHorizontalSkinLoaded();
    BOOL WINAPI isScrollbarVerticalSkinLoaded();
    BOOL WINAPI isTextfieldSkinLoaded();
    BOOL WINAPI isButtonSkinLoaded();
    BOOL WINAPI isCheckboxSkinLoaded();
    BOOL WINAPI isListboxSkinLoaded();
    BOOL WINAPI isGridSkinLoaded();
    
    inline CString WINAPI getThemesDir() { return this->_themesDir; }
    inline CString WINAPI getThemeDir() { return this->_themesDir + L"\\" + this->_name; }

    BOOL WINAPI themeExists(CString dir);

protected:
    CString _name;
    CResource* _resources;
    CString _themesDir;
    HINSTANCE _hInst;
private:
    CString _iniSectionColors;

    CBitmap* WINAPI _prepareScreenBg(CBitmap *source);
    VOID WINAPI _initAttributes(HINSTANCE hInst);
    COLORREF WINAPI _getIniColorValue(CString settings_fname, WCHAR *ini_varname);
};

typedef CTheme* PTheme;

#endif
