root/SettingGeneralAppearanceDlg.cpp

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. CSettingGeneralAppearanceDlg
  2. DoDataExchange
  3. BEGIN_MESSAGE_MAP
  4. SetButtonColor
  5. OnFolderviewBgColor
  6. OnFolderviewFontColor
  7. OnSummaryviewBgColor
  8. OnSummaryviewFontColor
  9. OnTextviewBgColor
  10. OnTextviewFontColor
  11. OnTextviewHeaderColor
  12. OnTextviewFontType
  13. OnEditviewBgColor
  14. OnEditviewFontColor
  15. OnEditviewFontType

/*
 * Copyright (C) 2002-2003 chik, s.hiranaka
 * For license terms, see the file COPYING in this directory.
 */

// SettingGeneralAppearanceDlgDlg.cpp : インプリメンテーション ファイル
//

#include "stdafx.h"
#include "pochy.h"
#include "SettingGeneralAppearanceDlg.h"
#include "MainFrm.h"
#include "lib.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CSettingGeneralAppearanceDlg ダイアログ


CSettingGeneralAppearanceDlg::CSettingGeneralAppearanceDlg(CWnd* pParent /*=NULL*/)
        : CDialog(CSettingGeneralAppearanceDlg::IDD, pParent)
{
        //{{AFX_DATA_INIT(CSettingGeneralAppearanceDlg)
                // メモ - ClassWizard はこの位置にマッピング用のマクロを追加または削除します。
        //}}AFX_DATA_INIT
}


void CSettingGeneralAppearanceDlg::DoDataExchange(CDataExchange* pDX)
{
        CDialog::DoDataExchange(pDX);
        //{{AFX_DATA_MAP(CSettingGeneralAppearanceDlg)
//      DDX_Control(pDX, IDC_SETTING_GENERAL_FOLDERVIEW_BG_COLOR, m_folderview_color);
        //}}AFX_DATA_MAP
}


BEGIN_MESSAGE_MAP(CSettingGeneralAppearanceDlg, CDialog)
        //{{AFX_MSG_MAP(CSettingGeneralAppearanceDlg)
        ON_BN_CLICKED(IDC_SETTING_GENERAL_FOLDERVIEW_BG_COLOR, OnFolderviewBgColor)
        ON_BN_CLICKED(IDC_SETTING_GENERAL_FOLDERVIEW_FONT_COLOR, OnFolderviewFontColor)
        ON_BN_CLICKED(IDC_SETTING_GENERAL_SUMMARYVIEW_BG_COLOR, OnSummaryviewBgColor)
        ON_BN_CLICKED(IDC_SETTING_GENERAL_SUMMARYVIEW_FONT_COLOR, OnSummaryviewFontColor)
        ON_BN_CLICKED(IDC_SETTING_GENERAL_TEXTVIEW_BG_COLOR, OnTextviewBgColor)
        ON_BN_CLICKED(IDC_SETTING_GENERAL_TEXTVIEW_FONT_COLOR, OnTextviewFontColor)
        ON_BN_CLICKED(IDC_SETTING_GENERAL_TEXTVIEW_HEADER_COLOR, OnTextviewHeaderColor)
        ON_BN_CLICKED(IDC_SETTING_GENERAL_TEXTVIEW_FONT_TYPE, OnTextviewFontType)
        ON_BN_CLICKED(IDC_SETTING_GENERAL_EDITVIEW_BG_COLOR, OnEditviewBgColor)
        ON_BN_CLICKED(IDC_SETTING_GENERAL_EDITVIEW_FONT_COLOR, OnEditviewFontColor)
        ON_BN_CLICKED(IDC_SETTING_GENERAL_EDITVIEW_FONT_TYPE, OnEditviewFontType)
        //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CSettingGeneralAppearanceDlg メッセージ ハンドラ

BOOL CSettingGeneralAppearanceDlg::OnInitDialog() 
{
        CDialog::OnInitDialog();
        
        // TODO: この位置に初期化の補足処理を追加してください
        // ボタンのサイズを取得
/*      CButton* button = (CButton *)GetDlgItem(IDC_SETTING_GENERAL_FOLDERVIEW_BG_COLOR);
        RECT rect;
        button->GetClientRect(&rect);
        int width = rect.right;
        int height = rect.bottom;

        // ボタンに色を表示するための bitmap を用意
        CClientDC dc(this);
        m_bitmap.CreateCompatibleBitmap(&dc, width, height);*/

        // 黒で初期化
        CPochyApp *app = (CPochyApp *)AfxGetApp();
        SetButtonColor(
                app->GetProfileInt("FolderViewColor", "BkColorR", DEF_BKG_COLOR_R),
                app->GetProfileInt("FolderViewColor", "BkColorG", DEF_BKG_COLOR_G),
                app->GetProfileInt("FolderViewColor", "BkColorB", DEF_BKG_COLOR_B),
                IDC_SETTING_GENERAL_FOLDERVIEW_BG_COLOR);
        m_fv_bg_cr = RGB(
                app->GetProfileInt("FolderViewColor", "BkColorR", DEF_BKG_COLOR_R),
                app->GetProfileInt("FolderViewColor", "BkColorG", DEF_BKG_COLOR_G),
                app->GetProfileInt("FolderViewColor", "BkColorB", DEF_BKG_COLOR_B));
        SetButtonColor(
                app->GetProfileInt("FolderViewColor", "TxtColorR", DEF_TXT_COLOR_R),
                app->GetProfileInt("FolderViewColor", "TxtColorG", DEF_TXT_COLOR_G),
                app->GetProfileInt("FolderViewColor", "TxtColorB", DEF_TXT_COLOR_B),
                IDC_SETTING_GENERAL_FOLDERVIEW_FONT_COLOR);
        m_fv_font_cr = RGB(
                app->GetProfileInt("FolderViewColor", "TxtColorR", DEF_TXT_COLOR_R),
                app->GetProfileInt("FolderViewColor", "TxtColorG", DEF_TXT_COLOR_G),
                app->GetProfileInt("FolderViewColor", "TxtColorB", DEF_TXT_COLOR_B));

        SetButtonColor(
                app->GetProfileInt("SummaryViewColor", "BkColorR", DEF_BKG_COLOR_R),
                app->GetProfileInt("SummaryViewColor", "BkColorG", DEF_BKG_COLOR_G),
                app->GetProfileInt("SummaryViewColor", "BkColorB", DEF_BKG_COLOR_B),
                IDC_SETTING_GENERAL_SUMMARYVIEW_BG_COLOR);
        m_sv_bg_cr = RGB(
                app->GetProfileInt("SummaryViewColor", "BkColorR", DEF_BKG_COLOR_R),
                app->GetProfileInt("SummaryViewColor", "BkColorG", DEF_BKG_COLOR_G),
                app->GetProfileInt("SummaryViewColor", "BkColorB", DEF_BKG_COLOR_B));
        SetButtonColor(
                app->GetProfileInt("SummaryViewColor", "TxtColorR", DEF_TXT_COLOR_R),
                app->GetProfileInt("SummaryViewColor", "TxtColorG", DEF_TXT_COLOR_G),
                app->GetProfileInt("SummaryViewColor", "TxtColorB", DEF_TXT_COLOR_B),
                IDC_SETTING_GENERAL_SUMMARYVIEW_FONT_COLOR);
        m_sv_font_cr = RGB(
                app->GetProfileInt("SummaryViewColor", "TxtColorR", DEF_TXT_COLOR_R),
                app->GetProfileInt("SummaryViewColor", "TxtColorG", DEF_TXT_COLOR_G),
                app->GetProfileInt("SummaryViewColor", "TxtColorB", DEF_TXT_COLOR_B));

        SetButtonColor(
                app->GetProfileInt("TextViewColor", "BkColorR", DEF_BKG_COLOR_R),
                app->GetProfileInt("TextViewColor", "BkColorG", DEF_BKG_COLOR_G),
                app->GetProfileInt("TextViewColor", "BkColorB", DEF_BKG_COLOR_B),
                IDC_SETTING_GENERAL_TEXTVIEW_BG_COLOR);
        m_tv_bg_cr = RGB(
                app->GetProfileInt("TextViewColor", "BkColorR", DEF_BKG_COLOR_R),
                app->GetProfileInt("TextViewColor", "BkColorG", DEF_BKG_COLOR_G),
                app->GetProfileInt("TextViewColor", "BkColorB", DEF_BKG_COLOR_B));
        SetButtonColor(
                app->GetProfileInt("TextViewColor", "TxtColorR", DEF_TXT_COLOR_R),
                app->GetProfileInt("TextViewColor", "TxtColorG", DEF_TXT_COLOR_G),
                app->GetProfileInt("TextViewColor", "TxtColorB", DEF_TXT_COLOR_B),
                IDC_SETTING_GENERAL_TEXTVIEW_FONT_COLOR);
        m_tv_font_cr = RGB(
                app->GetProfileInt("TextViewColor", "TxtColorR", DEF_TXT_COLOR_R),
                app->GetProfileInt("TextViewColor", "TxtColorG", DEF_TXT_COLOR_G),
                app->GetProfileInt("TextViewColor", "TxtColorB", DEF_TXT_COLOR_B));
        SetButtonColor(
                app->GetProfileInt("TextViewHdColor", "TxtColorR", DEF_HEADER_INFO_COLOR_R),
                app->GetProfileInt("TextViewHdColor", "TxtColorG", DEF_HEADER_INFO_COLOR_G),
                app->GetProfileInt("TextViewHdColor", "TxtColorB", DEF_HEADER_INFO_COLOR_B),
                IDC_SETTING_GENERAL_TEXTVIEW_HEADER_COLOR);
        m_tv_head_cr = RGB(
                app->GetProfileInt("TextViewHdColor", "TxtColorR", DEF_HEADER_INFO_COLOR_R),
                app->GetProfileInt("TextViewHdColor", "TxtColorG", DEF_HEADER_INFO_COLOR_G),
                app->GetProfileInt("TextViewHdColor", "TxtColorB", DEF_HEADER_INFO_COLOR_B));

        SetButtonColor(
                app->GetProfileInt("EditViewColor", "TxtColorR", DEF_TXT_COLOR_R),
                app->GetProfileInt("EditViewColor", "TxtColorG", DEF_TXT_COLOR_G),
                app->GetProfileInt("EditViewColor", "TxtColorB", DEF_TXT_COLOR_B),
                IDC_SETTING_GENERAL_EDITVIEW_FONT_COLOR);
        m_ev_font_cr = RGB(
                app->GetProfileInt("EditViewColor", "TxtColorR", DEF_TXT_COLOR_R),
                app->GetProfileInt("EditViewColor", "TxtColorG", DEF_TXT_COLOR_G),
                app->GetProfileInt("EditViewColor", "TxtColorB", DEF_TXT_COLOR_B));
        SetButtonColor(
                app->GetProfileInt("EditViewColor", "BkColorR", DEF_BKG_COLOR_R),
                app->GetProfileInt("EditViewColor", "BkColorG", DEF_BKG_COLOR_G),
                app->GetProfileInt("EditViewColor", "BkColorB", DEF_BKG_COLOR_B),
                IDC_SETTING_GENERAL_EDITVIEW_BG_COLOR);
        m_ev_bg_cr = RGB(
                app->GetProfileInt("EditViewColor", "BkColorR", DEF_BKG_COLOR_R),
                app->GetProfileInt("EditViewColor", "BkColorG", DEF_BKG_COLOR_G),
                app->GetProfileInt("EditViewColor", "BkColorB", DEF_BKG_COLOR_B));

        // fontの設定
        LPBYTE pData;
        UINT nSize;
        if(app->GetProfileBinary("EditViewFont", "LogFont", &pData, &nSize)){
                ASSERT(nSize == sizeof(LOGFONT));
                ::CopyMemory(&m_ev_lf, pData, sizeof(LOGFONT));
                delete [] pData; 
        }else{
                m_ev_lf.lfHeight = -16;
                m_ev_lf.lfWidth = 0;
                m_ev_lf.lfEscapement = 0;
                m_ev_lf.lfOrientation = 0;
                m_ev_lf.lfWeight = 400;
                m_ev_lf.lfItalic = 0;
                m_ev_lf.lfUnderline = 0;
                m_ev_lf.lfStrikeOut = 0;
                m_ev_lf.lfCharSet = 128;
                m_ev_lf.lfOutPrecision = 3;
                m_ev_lf.lfClipPrecision = 2;
                m_ev_lf.lfQuality = 1;
                m_ev_lf.lfPitchAndFamily = 49;
                strcpy(m_ev_lf.lfFaceName, "MS ゴシック");
        }

        if(app->GetProfileBinary("TextViewFont", "LogFont", &pData, &nSize)){
                ASSERT(nSize == sizeof(LOGFONT));
                ::CopyMemory(&m_tv_lf, pData, sizeof(LOGFONT));
                delete [] pData; 
        }else{
                m_tv_lf.lfHeight = -16;
                m_tv_lf.lfWidth = 0;
                m_tv_lf.lfEscapement = 0;
                m_tv_lf.lfOrientation = 0;
                m_tv_lf.lfWeight = 400;
                m_tv_lf.lfItalic = 0;
                m_tv_lf.lfUnderline = 0;
                m_tv_lf.lfStrikeOut = 0;
                m_tv_lf.lfCharSet = 128;
                m_tv_lf.lfOutPrecision = 3;
                m_tv_lf.lfClipPrecision = 2;
                m_tv_lf.lfQuality = 1;
                m_tv_lf.lfPitchAndFamily = 49;
                strcpy(m_tv_lf.lfFaceName, "MS ゴシック");
        }


        return TRUE;  // コントロールにフォーカスを設定しないとき、戻り値は TRUE となります
                      // 例外: OCX プロパティ ページの戻り値は FALSE となります
}

void CSettingGeneralAppearanceDlg::SetButtonColor(int red, int green, int blue, int id)
{
        CButton* button = (CButton *)GetDlgItem(id);
        RECT rect;
        button->GetClientRect(&rect);
        int width = rect.right;
        int height = rect.bottom;

        // ボタンに色を表示するための bitmap を用意
        CClientDC dc(this);
        m_bitmap.Detach();
        m_bitmap.CreateCompatibleBitmap(&dc, width, height);

        // ビットマップを描画する DCメモリの作成
        CDC dc_mem;
        dc_mem.CreateCompatibleDC(&dc);

        // 描画
        CBrush brush(RGB(red, green, blue));
        CBitmap* pbitmap = dc_mem.SelectObject(&m_bitmap);
        dc_mem.FillRect(&rect, &brush);
        dc_mem.SelectObject(pbitmap);
        button->RedrawWindow();

        // ボタンに張り付け
        button->SetBitmap(m_bitmap);
}

void CSettingGeneralAppearanceDlg::OnFolderviewBgColor() 
{
        CColorDialog dlg_color(m_fv_bg_cr/*RGB(0,0,0)*/, /*CC_PREVENTFULLOPEN*/NULL, NULL);
        if(dlg_color.DoModal() == IDOK){
                SetButtonColor(
                        GetRValue(dlg_color.GetColor()),
                        GetGValue(dlg_color.GetColor()),
                        GetBValue(dlg_color.GetColor()),
                        IDC_SETTING_GENERAL_FOLDERVIEW_BG_COLOR);
                m_fv_bg_cr = dlg_color.GetColor();
        }
}

void CSettingGeneralAppearanceDlg::OnFolderviewFontColor() 
{
        CColorDialog dlg_color(m_fv_font_cr/*RGB(0,0,0)*/, /*CC_PREVENTFULLOPEN*/NULL, NULL);
        if(dlg_color.DoModal() == IDOK){
                SetButtonColor(
                        GetRValue(dlg_color.GetColor()),
                        GetGValue(dlg_color.GetColor()),
                        GetBValue(dlg_color.GetColor()),
                        IDC_SETTING_GENERAL_FOLDERVIEW_FONT_COLOR);
                m_fv_font_cr = dlg_color.GetColor();
        }
}

void CSettingGeneralAppearanceDlg::OnSummaryviewBgColor() 
{
        CColorDialog dlg_color(m_sv_bg_cr/*RGB(0,0,0)*/, /*CC_PREVENTFULLOPEN*/NULL, NULL);
        if(dlg_color.DoModal() == IDOK){
                SetButtonColor(
                        GetRValue(dlg_color.GetColor()),
                        GetGValue(dlg_color.GetColor()),
                        GetBValue(dlg_color.GetColor()),
                        IDC_SETTING_GENERAL_SUMMARYVIEW_BG_COLOR);
                m_sv_bg_cr = dlg_color.GetColor();
        }
}

void CSettingGeneralAppearanceDlg::OnSummaryviewFontColor() 
{
        CColorDialog dlg_color(m_sv_font_cr/*RGB(0,0,0)*/, /*CC_PREVENTFULLOPEN*/NULL, NULL);
        if(dlg_color.DoModal() == IDOK){
                SetButtonColor(
                        GetRValue(dlg_color.GetColor()),
                        GetGValue(dlg_color.GetColor()),
                        GetBValue(dlg_color.GetColor()),
                        IDC_SETTING_GENERAL_SUMMARYVIEW_FONT_COLOR);
                m_sv_font_cr = dlg_color.GetColor();
        }
}

void CSettingGeneralAppearanceDlg::OnTextviewBgColor() 
{
        CColorDialog dlg_color(m_tv_bg_cr/*RGB(0,0,0)*/, /*CC_PREVENTFULLOPEN*/NULL, NULL);
        if(dlg_color.DoModal() == IDOK){
                SetButtonColor(
                        GetRValue(dlg_color.GetColor()),
                        GetGValue(dlg_color.GetColor()),
                        GetBValue(dlg_color.GetColor()),
                        IDC_SETTING_GENERAL_TEXTVIEW_BG_COLOR);
                m_tv_bg_cr = dlg_color.GetColor();
        }
}

void CSettingGeneralAppearanceDlg::OnTextviewFontColor() 
{
        CColorDialog dlg_color(m_tv_font_cr/*RGB(0,0,0)*/, /*CC_PREVENTFULLOPEN*/NULL, NULL);
        if(dlg_color.DoModal() == IDOK){
                SetButtonColor(
                        GetRValue(dlg_color.GetColor()),
                        GetGValue(dlg_color.GetColor()),
                        GetBValue(dlg_color.GetColor()),
                        IDC_SETTING_GENERAL_TEXTVIEW_FONT_COLOR);
                m_tv_font_cr = dlg_color.GetColor();
        }
}

void CSettingGeneralAppearanceDlg::OnTextviewHeaderColor() 
{
        CColorDialog dlg_color(m_tv_head_cr/*RGB(0,0,0)*/, /*CC_PREVENTFULLOPEN*/NULL, NULL);
        if(dlg_color.DoModal() == IDOK){
                SetButtonColor(
                        GetRValue(dlg_color.GetColor()),
                        GetGValue(dlg_color.GetColor()),
                        GetBValue(dlg_color.GetColor()),
                        IDC_SETTING_GENERAL_TEXTVIEW_HEADER_COLOR);
                m_tv_head_cr = dlg_color.GetColor();
        }
}

void CSettingGeneralAppearanceDlg::OnTextviewFontType()
{
        LOGFONT lf;

        g_logfont_copy(&lf, &m_tv_lf);
        CFontDialog dlg(&lf, CF_SCREENFONTS|CF_INITTOLOGFONTSTRUCT);
        if(dlg.DoModal() == IDOK){
                g_logfont_copy(&m_tv_lf, &lf);
        }
}

void CSettingGeneralAppearanceDlg::OnEditviewBgColor() 
{
        CColorDialog dlg_color(m_ev_bg_cr/*RGB(0,0,0)*/, /*CC_PREVENTFULLOPEN*/NULL, NULL);
        if(dlg_color.DoModal() == IDOK){
                SetButtonColor(
                        GetRValue(dlg_color.GetColor()),
                        GetGValue(dlg_color.GetColor()),
                        GetBValue(dlg_color.GetColor()),
                        IDC_SETTING_GENERAL_EDITVIEW_BG_COLOR);
                m_ev_bg_cr = dlg_color.GetColor();
        }
}

void CSettingGeneralAppearanceDlg::OnEditviewFontColor() 
{
        CColorDialog dlg_color(m_ev_font_cr/*RGB(0,0,0)*/, /*CC_PREVENTFULLOPEN*/NULL, NULL);
        if(dlg_color.DoModal() == IDOK){
                SetButtonColor(
                        GetRValue(dlg_color.GetColor()),
                        GetGValue(dlg_color.GetColor()),
                        GetBValue(dlg_color.GetColor()),
                        IDC_SETTING_GENERAL_EDITVIEW_FONT_COLOR);
                m_ev_font_cr = dlg_color.GetColor();
        }
}

void CSettingGeneralAppearanceDlg::OnEditviewFontType() 
{
        LOGFONT lf;

        g_logfont_copy(&lf, &m_ev_lf);
        CFontDialog dlg(&lf, CF_SCREENFONTS|CF_INITTOLOGFONTSTRUCT);
        if(dlg.DoModal() == IDOK){
                g_logfont_copy(&m_ev_lf, &lf);
        }
}

/* [<][>][^][v][top][bottom][index][help] */