OSDN Git Service

Plugins: Fix a crash on Window XP
[winmerge-jp/winmerge-jp.git] / Src / PropTextColors.cpp
index 2e5c9c5..31add85 100644 (file)
@@ -3,22 +3,17 @@
  *
  * @brief Implementation of PropTextColors propertysheet
  */
-// ID line follows -- this is updated by SVN
-// $Id$
 
 #include "stdafx.h"
 #include "PropTextColors.h"
-#include "Merge.h"
 #include "SyntaxColors.h"
-#include "CustomColors.h"
+#include "OptionsCustomColors.h"
 #include "OptionsDef.h"
 #include "OptionsMgr.h"
 #include "OptionsPanel.h"
 
 #ifdef _DEBUG
 #define new DEBUG_NEW
-#undef THIS_FILE
-static char THIS_FILE[] = __FILE__;
 #endif
 
 /** @brief Section name for settings in registry. */
@@ -29,28 +24,29 @@ static const TCHAR Section[] = _T("Custom Colors");
  */
 PropTextColors::PropTextColors(COptionsMgr *optionsMgr, SyntaxColors *pColors)
  : OptionsPanel(optionsMgr, PropTextColors::IDD)
-, m_bCustomColors(FALSE)
+, m_bCustomColors(false)
 , m_pTempColors(pColors)
+, m_cCustColors()
 {
-       memset(m_cCustColors, 0, sizeof(m_cCustColors));
 }
 
 void PropTextColors::DoDataExchange(CDataExchange* pDX)
 {
        CDialog::DoDataExchange(pDX);
        //{{AFX_DATA_MAP(PropTextColors)
-       DDX_Control(pDX, IDC_DEFAULT_STANDARD_COLORS, m_btnDefaultStandardColors);
        DDX_Check(pDX, IDC_DEFAULT_STANDARD_COLORS, m_bCustomColors);
        DDX_Control(pDX, IDC_WHITESPACE_BKGD_COLOR, m_btnWhitespaceBackground);
        DDX_Control(pDX, IDC_REGULAR_BKGD_COLOR, m_btnRegularBackground);
        DDX_Control(pDX, IDC_REGULAR_TEXT_COLOR, m_btnRegularText);
        DDX_Control(pDX, IDC_SELECTION_BKGD_COLOR, m_btnSelectionBackground);
        DDX_Control(pDX, IDC_SELECTION_TEXT_COLOR, m_btnSelectionText);
+       DDX_Control(pDX, IDC_MARGIN_BKGD_COLOR, m_btnMarginBackground);
        //}}AFX_DATA_MAP
+       EnableColorButtons(m_bCustomColors);
 }
 
 
-BEGIN_MESSAGE_MAP(PropTextColors, CDialog)
+BEGIN_MESSAGE_MAP(PropTextColors, OptionsPanel)
        //{{AFX_MSG_MAP(PropTextColors)
        ON_BN_CLICKED(IDC_DEFAULT_STANDARD_COLORS, OnDefaultsStandardColors)
        ON_BN_CLICKED(IDC_WHITESPACE_BKGD_COLOR, OnWhitespaceBackgroundColor)
@@ -58,32 +54,17 @@ BEGIN_MESSAGE_MAP(PropTextColors, CDialog)
        ON_BN_CLICKED(IDC_REGULAR_TEXT_COLOR, OnRegularTextColor)
        ON_BN_CLICKED(IDC_SELECTION_BKGD_COLOR, OnSelectionBackgroundColor)
        ON_BN_CLICKED(IDC_SELECTION_TEXT_COLOR, OnSelectionTextColor)
+       ON_BN_CLICKED(IDC_MARGIN_BKGD_COLOR, OnMarginBackgroundColor)
        //}}AFX_MSG_MAP
 END_MESSAGE_MAP()
 
 /** 
- * @brief Enable/Disable controls when dialog is shown.
- */
-BOOL PropTextColors::OnInitDialog()
-{
-       theApp.TranslateDialog(m_hWnd);
-       CPropertyPage::OnInitDialog();
-
-       if (m_bCustomColors)
-               EnableColorButtons(TRUE);
-       else
-               EnableColorButtons(FALSE);
-    
-       return TRUE;  // return TRUE  unless you set the focus to a control
-}
-
-/** 
  * @brief Reads options values from storage to UI.
  * (Property sheet calls this before displaying all property pages)
  */
 void PropTextColors::ReadOptions()
 {
-       m_bCustomColors = GetOptionsMgr()->GetBool(OPT_CLR_DEFAULT_TEXT_COLORING) ? FALSE : TRUE;
+       m_bCustomColors = GetOptionsMgr()->GetBool(OPT_CLR_DEFAULT_TEXT_COLORING) ? false : true;
        SerializeColorsToFromScreen(LOAD_COLORS);
 }
 
@@ -93,7 +74,7 @@ void PropTextColors::ReadOptions()
  */
 void PropTextColors::WriteOptions()
 {
-       GetOptionsMgr()->SaveOption(OPT_CLR_DEFAULT_TEXT_COLORING, m_bCustomColors == FALSE);
+       GetOptionsMgr()->SaveOption(OPT_CLR_DEFAULT_TEXT_COLORING, !m_bCustomColors);
        // User can only change colors via BrowseColorAndSave,
        // which writes to m_pTempColors
        // so user's latest choices are in m_pTempColors
@@ -111,13 +92,13 @@ void PropTextColors::WriteOptions()
 void PropTextColors::BrowseColorAndSave(CColorButton & colorButton, int colorIndex)
 {
        // Ignore user if colors are slaved to system
-       if (m_btnDefaultStandardColors.GetCheck() == BST_UNCHECKED)
+       if (IsDlgButtonChecked(IDC_DEFAULT_STANDARD_COLORS) == BST_UNCHECKED)
                return;
 
        COLORREF currentColor = m_pTempColors->GetColor(colorIndex);
        CColorDialog dialog(currentColor);
-       CustomColors::Load(m_cCustColors);
-       dialog.m_cc.lpCustColors = m_cCustColors;
+       Options::CustomColors::Load(GetOptionsMgr(), m_cCustColors.data());
+       dialog.m_cc.lpCustColors = m_cCustColors.data();
        
        if (dialog.DoModal() == IDOK)
        {
@@ -125,7 +106,7 @@ void PropTextColors::BrowseColorAndSave(CColorButton & colorButton, int colorInd
                colorButton.SetColor(currentColor);
                m_pTempColors->SetColor(colorIndex, currentColor);
        }
-       CustomColors::Save(m_cCustColors);
+       Options::CustomColors::Save(GetOptionsMgr(), m_cCustColors.data());
 }
 
 /** 
@@ -168,6 +149,14 @@ void PropTextColors::OnSelectionTextColor()
        BrowseColorAndSave(m_btnSelectionText, COLORINDEX_SELTEXT);
 }
 
+/** 
+ * @brief User wants to change margin background color
+ */
+void PropTextColors::OnMarginBackgroundColor() 
+{
+       BrowseColorAndSave(m_btnMarginBackground, COLORINDEX_SELMARGIN);
+}
+
 /**
  * @brief Load all colors, Save all colors, or set all colors to default
  * @param [in] op Operation to do, one of
@@ -187,6 +176,8 @@ void PropTextColors::SerializeColorsToFromScreen(OPERATION op)
 
        SerializeColorToFromScreen(op, m_btnSelectionBackground, COLORINDEX_SELBKGND);
        SerializeColorToFromScreen(op, m_btnSelectionText, COLORINDEX_SELTEXT);
+
+       SerializeColorToFromScreen(op, m_btnMarginBackground, COLORINDEX_SELMARGIN);
 }
 
 /**
@@ -198,23 +189,12 @@ void PropTextColors::SerializeColorsToFromScreen(OPERATION op)
  */
 void PropTextColors::SerializeColorToFromScreen(OPERATION op, CColorButton & btn, int colorIndex)
 {
-       
        switch (op)
        {
        case SET_DEFAULTS:
-               {
-               COLORREF color = m_pTempColors->GetColor(colorIndex);
-               btn.SetColor(color);
-               return;
-               }
-
        case LOAD_COLORS:
-               {
-               COLORREF color = m_pTempColors->GetColor(colorIndex);
-               // Set colors for buttons, do NOT invalidate
-               btn.SetColor(color, FALSE);
-               return;
-               }
+               btn.SetColor(m_pTempColors->GetColor(colorIndex));
+               break;
        }
 }
 
@@ -226,33 +206,19 @@ void PropTextColors::OnDefaultsStandardColors()
        // Reset all text colors to default every time user checks defaults button
        SerializeColorsToFromScreen(SET_DEFAULTS);
 
-       CButton * btn = (CButton *)GetDlgItem(IDC_DEFAULT_STANDARD_COLORS);
-       if (btn->GetCheck() == BST_UNCHECKED)
-       {
-               EnableColorButtons(FALSE);
-       }
-       else
-       {
-               EnableColorButtons(TRUE);
-       }
+       UpdateData();
 }
 
 /** 
  * @brief Enable / disable color controls on dialog.
- * @param [in] bEnable If TRUE color controls are enabled.
+ * @param [in] bEnable If `true` color controls are enabled.
  */
-void PropTextColors::EnableColorButtons(BOOL bEnable)
+void PropTextColors::EnableColorButtons(bool bEnable)
 {
-       CStatic * stc = (CStatic *) GetDlgItem(IDC_CUSTOM_COLORS_GROUP);
-       stc->EnableWindow(bEnable);
-       stc = (CStatic *) GetDlgItem(IDC_WHITESPACE_COLOR_LABEL);
-       stc->EnableWindow(bEnable);
-       stc = (CStatic *) GetDlgItem(IDC_TEXT_COLOR_LABEL);
-       stc->EnableWindow(bEnable);
-       stc = (CStatic *) GetDlgItem(IDC_SELECTION_COLOR_LABEL);
-       stc->EnableWindow(bEnable);
-       stc = (CStatic *) GetDlgItem(IDC_BACKGROUND_COLUMN_LABEL);
-       stc->EnableWindow(bEnable);
-       stc = (CStatic *) GetDlgItem(IDC_TEXT_COLUMN_LABEL);
-       stc->EnableWindow(bEnable);
+       EnableDlgItem(IDC_WHITESPACE_COLOR_LABEL, bEnable);
+       EnableDlgItem(IDC_TEXT_COLOR_LABEL, bEnable);
+       EnableDlgItem(IDC_SELECTION_COLOR_LABEL, bEnable);
+       EnableDlgItem(IDC_MARGIN_COLOR_LABEL, bEnable);
+       EnableDlgItem(IDC_BACKGROUND_COLUMN_LABEL, bEnable);
+       EnableDlgItem(IDC_TEXT_COLUMN_LABEL, bEnable);
 }