// OptionsShowDlg.cpp : implementation file
//

#include "stdafx.h"
#include "psm.h"
#include "OptionsShowDlg.h"
#include "PSMDoc.h"
#include "MainFrm.h"
#include "resource.h"

#include "PSMDoc.h"
#include "aplTopLevelItem.h"
//#include "aplTreeItem.h"
#include "TreeProductItem.h"
#include "aplTreeCharacteristicItem.h"
#include "aplTreeApprovalItem.h"
#include "aplDocTreeItem.h"
#include "NavigatorView.h"
#include "aplTreeTaskItem.h"
#include "aplQueryItem.h"

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

/////////////////////////////////////////////////////////////////////////////
// COptionsShowDlg dialog
CStringArray *str_array_font_names=0;

int CALLBACK EnumFontFamExProc(ENUMLOGFONTEX *lpelfe,   NEWTEXTMETRICEX *lpntme,DWORD FontType,LPARAM lParam)
{	if(0!=str_array_font_names)str_array_font_names->Add(lpelfe->elfLogFont.lfFaceName);	return true; }

bool GetAllFontsFaces(CStringArray &fontnames)
{
	fontnames.RemoveAll();
	LOGFONT lf;
	memset(&lf, 0, sizeof(LOGFONT));
	lf.lfCharSet=RUSSIAN_CHARSET;
	CWnd *wnd =AfxGetMainWnd();
	if(0==wnd) return false;
	CDC *dc=wnd->GetDC();
	str_array_font_names=&fontnames;
	EnumFontFamiliesEx(dc->m_hDC,&lf,(FONTENUMPROC)EnumFontFamExProc,(LPARAM) 0,(DWORD) 0);
	str_array_font_names=0;
	wnd->ReleaseDC(dc);
	return true;
}


COptionsShowDlg::COptionsShowDlg(CWnd* pParent /*=NULL*/)
	: CaplTranslateDialog(COptionsShowDlg::IDD, pParent)
	, m_i_mark_work_with_color_warning_time(0)
{
	//{{AFX_DATA_INIT(COptionsShowDlg)
	m_SaveExpendetTreeList = FALSE;
	m_def_context_menu = FALSE;
	m_dbl_click_prd_struct_expand_tree = FALSE;
	m_dbl_click_whereused_expand_tree = FALSE;
	m_show_inst_info = FALSE;
	m_bSortPrjByNumzak=FALSE;
	m_show_subst_in_nauo = FALSE;
	m_show_zagotov_in_nauo = FALSE;
	m_b_show_categ=FALSE;
	m_auto_show_sign_in_doc_ver=TRUE;
	m_show_revocated_approval=FALSE;
	//}}AFX_DATA_INIT
	m_def_context_menu=CaplTreeItem::m_def_context_menu;
	m_autoclose_treeitem = CNavigatorView::AutoCloseItem;

	m_dbl_click_prd_struct_expand_tree=CPSMDoc::m_dbl_click_prd_struct_expand_tree;
	m_dbl_click_whereused_expand_tree=CPSMDoc::m_dbl_click_whereused_expand_tree;

	m_doc=0;
	m_show_org_struct = TRUE;
	m_show_classificators = FALSE;
	m_show_subst_in_nauo=CPSMDoc::m_show_subst_in_nauo;
	m_show_zagotov_in_nauo=CPSMDoc::m_show_zagotov_in_nauo;
	m_auto_show_sign_in_doc_ver=CPSMDoc::m_auto_show_sign_in_doc_ver;
	m_show_revocated_approval=CPSMDoc::m_show_revocated_approval;
	m_show_saved_query_in_tree=CPSMDoc::m_show_saved_query_in_tree;
	if(CPSMDoc::m_show_old_query_dlg == 1){m_show_old_query_dlg=TRUE;}else{m_show_old_query_dlg=FALSE;}


	CFont *tmpFont=CFont::FromHandle((HFONT)GetStockObject(ANSI_VAR_FONT));
	if(0!=tmpFont)
	{
		LOGFONT lf;
		memset(&lf, 0, sizeof(LOGFONT));
		tmpFont->GetLogFont(&lf);
		m_system_font_face=lf.lfFaceName;
		m_system_font_size=lf.lfHeight;
	}
	m_font_face=_T("");
	m_font_size=0;

	m_system_def_fon_color=GetSysColor(COLOR_WINDOW);
	m_def_fon_color=RGB(0,0,0);

	m_bNeewResetFont=false;

	m_b_mark_work_with_color=CaplWorkFlowManager::m_b_mark_work_with_color;
	m_b_mark_ended_work_with_color=CaplWorkFlowManager::m_b_mark_ended_work_with_color;
	m_b_not_show_task_of_future_process=CaplWorkFlowManager::m_b_not_show_task_of_future_process;

	m_i_mark_work_with_color_warning_time=CaplWorkFlowManager::m_i_mark_work_with_color_warning_time;

	m_num_doc_4_group=CaplTreeItem::m_num_doc_4_group;

}


void COptionsShowDlg::DoDataExchange(CDataExchange* pDX)
{
	CaplTranslateDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(COptionsShowDlg)
	DDX_Control(pDX, IDCANCEL, m_cancel_btn);
	DDX_Control(pDX, IDOK, m_ok_btn);
	DDX_Control(pDX, IDC_AUTOCLOSE_TREE_ITEM, m_autoclose_treeitem_ctrl);
	DDX_Control(pDX, IDC_DEFAULT_CONTEXT_MENU, m_def_context_menu_ctrl);
	DDX_Control(pDX, IDC_PRD_NO_SHOW_PLUS_TO_PART, m_PrdNoShowPlusToPart_Ctrl);
	DDX_Check(pDX, IDC_PRD_NO_SHOW_PLUS_TO_PART, m_PrdNoShowPlusToPart);
	DDX_Check(pDX, IDC_DEFAULT_CONTEXT_MENU, m_def_context_menu);
	DDX_Check(pDX, IDC_AUTOCLOSE_TREE_ITEM, m_autoclose_treeitem);
	DDX_Check(pDX, IDC_DBLCLIC_PRDSTUCT_LIST_EXPAND_TREE, m_dbl_click_prd_struct_expand_tree);
	DDX_Check(pDX, IDC_DBLCLIC_WHEREUSED_LIST_EXPAND_TREE, m_dbl_click_whereused_expand_tree);
	DDX_Check(pDX, IDC_SHOW_INST_ID, m_show_inst_info);
	DDX_Check(pDX, IDC_SHOW_CLASSIFICATORS, m_show_classificators);
	DDX_Check(pDX, IDC_SHOW_ORGANIZATION_STRUCT, m_show_org_struct);
	DDX_Check(pDX, IDC_SHOW_SUBST_IN_NAUO, m_show_subst_in_nauo);
	DDX_Check(pDX, IDC_SHOW_ZAGOTOV_IN_NAUO, m_show_zagotov_in_nauo);
	DDX_Check(pDX, IDC_AUTO_SHOW_SIGN_IN_DOCVER, m_auto_show_sign_in_doc_ver);
	DDX_Check(pDX, IDC_SHOW_REVOCATED_SIGN, m_show_revocated_approval);
	DDX_Check(pDX, IDC_SHOW_SAVED_QUERY_IN_TREE, m_show_saved_query_in_tree);
	DDX_Check(pDX, IDC_SHOW_OLD_QUERY_DLG, m_show_old_query_dlg);
	DDX_Check(pDX, IDC_SHOW_CATEGORY, m_b_show_categ);
	DDX_Check(pDX, IDC_SORT_PRJ_BY_NUMZAK, m_bSortPrjByNumzak);
	DDX_Check(pDX, IDC_MARK_WORK_WITH_COLOR, m_b_mark_work_with_color);
	DDX_Check(pDX, IDC_MARK_ENDED_WORK_WITH_COLOR, m_b_mark_ended_work_with_color);
	DDX_Check(pDX, IDC_NOT_SHOW_FUTURE_TASK, m_b_not_show_task_of_future_process);
	DDX_Text(pDX, IDC_MARK_WORK_WARNING_TIME, m_i_mark_work_with_color_warning_time);
	DDX_Text(pDX, IDC_NUM_DOC4GROUP, m_num_doc_4_group);
	//}}AFX_DATA_MAP
	DDX_Control(pDX, IDC_DBLCLIK_VIEW_DOC, m_dblclick_view_doc);
	DDX_Control(pDX, IDC_FONTS_COMBO, m_fonts_combo);
	DDX_Control(pDX, IDC_ST_FONT_EXAMPLE, m_st_font_example);
	DDX_Control(pDX, IDC_FONT_SIZE_COMBO, m_font_size_combo);

	DDX_Control(pDX, IDC_PRD_NO_SHOW_REPLACED_PARTS, m_PrdNoShowReplacedPartCtrl);
	DDX_Control(pDX, IDC_SHOW_CATEGORY, m_b_show_categ_ctrl);
}


BEGIN_MESSAGE_MAP(COptionsShowDlg, CaplTranslateDialog)
	//{{AFX_MSG_MAP(COptionsShowDlg)
	ON_BN_CLICKED(IDC_PRD_ID, OnPrdId)
	ON_BN_CLICKED(IDC_PRD_NAME, OnPrdName)
	ON_BN_CLICKED(IDC_CHARACT_VALUE, OnCharactValue)
	ON_BN_CLICKED(IDC_DOC_ID, OnDocId)
	ON_BN_CLICKED(IDC_DOC_NAME, OnDocName)
	ON_BN_CLICKED(IDC_APPR_PERSON, OnApprPerson)
	ON_BN_CLICKED(IDC_APPR_PERSON_ROLE, OnApprPersonRole)
	ON_BN_CLICKED(IDC_APPR_STATUS, OnApprStatus)
	ON_BN_CLICKED(IDC_CHARACT_UNIT, OnCharactUnit)
	ON_BN_CLICKED(IDC_ORG_ID, OnOrgId)
	ON_BN_CLICKED(IDC_ORG_NAME, OnOrgName)
	ON_BN_CLICKED(IDC_UNIT_ID, OnUnitId)
	ON_BN_CLICKED(IDC_UNIT_NAME, OnUnitName)
	ON_BN_CLICKED(IDC_LB_DBLCLICK_OPEN, OnLbDblclickOpen)
	ON_BN_CLICKED(IDC_LB_DBLCLICK_PROPERTY, OnLbDblclickProperty)
	ON_BN_CLICKED(IDC_CATEG_ID, OnCategId)
	ON_BN_CLICKED(IDC_CATEG_NAME, OnCategName)
	ON_BN_CLICKED(IDC_ACT_ID, OnActId)
	ON_BN_CLICKED(IDC_ACT_NAME, OnActName)
	//}}AFX_MSG_MAP
	ON_CBN_SELCHANGE(IDC_FONTS_COMBO, &COptionsShowDlg::OnCbnSelchangeFontsCombo)
	ON_CBN_SELCHANGE(IDC_FONT_SIZE_COMBO, &COptionsShowDlg::OnCbnSelchangeFontSizeCombo)
	ON_CBN_EDITCHANGE(IDC_FONT_SIZE_COMBO, &COptionsShowDlg::OnCbnEditchangeFontSizeCombo)
	ON_BN_CLICKED(IDC_SEL_DEF_FON_COLOR, &COptionsShowDlg::OnBnClickedSelDefFonColor)
	ON_BN_CLICKED(IDC_CLEAR_DEF_SYS_COLOR, &COptionsShowDlg::OnBnClickedClearDefSysColor)
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// COptionsShowDlg message handlers

void COptionsShowDlg::OnPrdId() 
{
	// TODO: Add your control notification handler code here
/*	BOOL a1=m_prd_id_ctrl.GetCheck();
	BOOL a2=m_prd_name_ctrl.GetCheck();
	if((a1==FALSE)&&(a2==FALSE))
		m_prd_name_ctrl.SetCheck(1);*/
}

void COptionsShowDlg::OnPrdName() 
{
	// TODO: Add your control notification handler code here
/*	BOOL a1=m_prd_id_ctrl.GetCheck();
	BOOL a2=m_prd_name_ctrl.GetCheck();
	if((a1==FALSE)&&(a2==FALSE))
		m_prd_id_ctrl.SetCheck(1);*/
}

void COptionsShowDlg::OnOK() 
{
	// TODO: Add extra validation here
/*	BOOL a1=m_prd_id_ctrl.GetCheck();
	BOOL a2=m_prd_name_ctrl.GetCheck();
	if(a1==0)CaplProductTreeItem::m_ShowId=false;
	else CaplProductTreeItem::m_ShowId=true;
	if(a2==0)CaplProductTreeItem::m_ShowName=false;
	else CaplProductTreeItem::m_ShowName=true;*/

	BOOL s1=m_def_context_menu_ctrl.GetCheck();
	if(s1==0)CaplTreeItem::m_def_context_menu=false;
	else CaplTreeItem::m_def_context_menu=true;


	BOOL s3=m_autoclose_treeitem_ctrl.GetCheck();
	if(s3==0)CNavigatorView::AutoCloseItem=false;
	else CNavigatorView::AutoCloseItem=true;

	BOOL s4=m_dblclick_view_doc.GetCheck();
	if(s4==0)CNavigatorView::DblclickViewDoc=false;
	else CNavigatorView::DblclickViewDoc=true;
	if(m_doc!=0)m_doc->m_api.m_show.m_doc__view_on_dblclick = CNavigatorView::DblclickViewDoc;


/*	BOOL p1=m_prd_position_ctrl.GetCheck();
	if(p1==0)CaplProductTreeItem::m_ShowPosition=false;
	else CaplProductTreeItem::m_ShowPosition=true;

	BOOL p2=m_PrdNoShowPlusToPart_Ctrl.GetCheck();
	if(p2==0)CaplProductTreeItem::m_PrdNoShowPlusToPart=false;
	else CaplProductTreeItem::m_PrdNoShowPlusToPart=true;

/*	BOOL c1=m_prd_count_ctrl.GetCheck();
	if(c1==0)CaplProductTreeItem::m_ShowCount=false;
	else CaplProductTreeItem::m_ShowCount=true;

	BOOL d1=m_doc_id_ctrl.GetCheck();
	if(d1==0)CaplDocTreeItem::m_bShowID=false;
	else CaplDocTreeItem::m_bShowID=true;

	BOOL d2=m_doc_name_ctrl.GetCheck();
	if(d2==0)CaplDocTreeItem::m_bShowName=false;
	else CaplDocTreeItem::m_bShowName=true;

	BOOL d3=m_doc_ver_ctrl.GetCheck();
	if(d3==0)CaplDocTreeItem::m_bShowActiveVersion=false;
	else CaplDocTreeItem::m_bShowActiveVersion=true;

	BOOL d4=m_doc_type_ctrl.GetCheck();
	if(d4==0)CaplDocTreeItem::m_bShowType=false;
	else CaplDocTreeItem::m_bShowType=true;

	BOOL cat1=m_categ_id_ctrl.GetCheck();
	if(cat1==0)CaplCategoryTreeItem::m_bShowID=false;
	else CaplCategoryTreeItem::m_bShowID=true;

	BOOL cat2=m_categ_name_ctrl.GetCheck();
	if(cat2==0)CaplCategoryTreeItem::m_bShowName=false;
	else CaplCategoryTreeItem::m_bShowName=true;

	BOOL ch1=m_charact_unit_ctrl.GetCheck();
	if(ch1==0)CaplCharacteristicTreeItem::m_ShowUnit=false;
	else CaplCharacteristicTreeItem::m_ShowUnit=true;

	BOOL ch2=m_charact_value_ctrl.GetCheck();
	if(ch2==0)CaplCharacteristicTreeItem::m_ShowValue=false;
	else CaplCharacteristicTreeItem::m_ShowValue=true;

	BOOL appr1=m_appr_status_ctrl.GetCheck();
	if(appr1==0)CaplApprovalTreeItem::m_ShowStatus=false;
	else CaplApprovalTreeItem::m_ShowStatus=true;

	BOOL appr2=m_appr_pers_role_ctrl.GetCheck();
	if(appr2==0)CaplApprovalTreeItem::m_ShowPesonRole=false;
	else CaplApprovalTreeItem::m_ShowPesonRole=true;

	BOOL appr3=m_appr_pers_ctrl.GetCheck();
	if(appr3==0)CaplApprovalTreeItem::m_ShowPerson=false;
	else CaplApprovalTreeItem::m_ShowPerson=true;

	BOOL o1=m_org_id_ctrl.GetCheck();
	BOOL o2=m_org_name_ctrl.GetCheck();
	if(o1==0)CaplApprovalTreeItem::m_ShowOrgId=false;
	else CaplApprovalTreeItem::m_ShowOrgId=true;
	if(o2==0)CaplApprovalTreeItem::m_ShowOrgName=false;
	else CaplApprovalTreeItem::m_ShowOrgName=true;

	int i=GetCheckedRadioButton(IDC_UNIT_ID,IDC_UNIT_NAME);
	if(i==IDC_UNIT_ID)CaplCharacteristicTreeItem::m_ShowID_or_Name=0;
	else CaplCharacteristicTreeItem::m_ShowID_or_Name=1;*/

	int i=GetCheckedRadioButton(IDC_LB_DBLCLICK_OPEN,IDC_LB_DBLCLICK_PROPERTY);
	if(i==IDC_LB_DBLCLICK_OPEN)CaplTreeItem::m_LbDblClick_Open=true;
	else CaplTreeItem::m_LbDblClick_Open=false;
	
/*	BOOL tSusp= m_task_suspend_ctrl.GetCheck();
	if(tSusp) CaplTaskTreeItem::m_ShowSuspended= true;
	else CaplTaskTreeItem::m_ShowSuspended= false;
	BOOL tComp= m_task_complete_ctrl.GetCheck();
	if(tComp) CaplTaskTreeItem::m_ShowCompleted= true;
	else CaplTaskTreeItem::m_ShowCompleted= false;
	BOOL tCncl= m_task_cancel_ctrl.GetCheck();
	if(tCncl) CaplTaskTreeItem::m_ShowCanceled= true;
	else CaplTaskTreeItem::m_ShowCanceled= false;*/

/*	if(m_act_id_ctrl.GetCheck()) CaplBPManager::m_bShowId=true; else CaplBPManager::m_bShowId=false;
	if(m_act_name_ctrl.GetCheck()) CaplBPManager::m_bShowName=true; else CaplBPManager::m_bShowName=false;
	if(m_act_type_ctrl.GetCheck()) CaplBPManager::m_bShowType=true; else CaplBPManager::m_bShowType=false;*/

	UpdateData(TRUE);

	CPSMDoc::m_dbl_click_prd_struct_expand_tree=m_dbl_click_prd_struct_expand_tree;
	CPSMDoc::m_dbl_click_whereused_expand_tree=m_dbl_click_whereused_expand_tree;
	CPSMDoc::m_show_inst_info=m_show_inst_info;
	CPSMDoc::m_bSortPrjByNumzak=m_bSortPrjByNumzak;
	CPSMDoc::m_show_subst_in_nauo=m_show_subst_in_nauo;
	CPSMDoc::m_show_zagotov_in_nauo=m_show_zagotov_in_nauo;
	CPSMDoc::m_auto_show_sign_in_doc_ver=m_auto_show_sign_in_doc_ver;
	CPSMDoc::m_show_revocated_approval=m_show_revocated_approval;
	CPSMDoc::m_show_saved_query_in_tree=m_show_saved_query_in_tree;
	// хитрая схема нужна, чтобы опция в БД перебила значение по умолчанию из конструктора приложения
	if(m_show_old_query_dlg == TRUE){CPSMDoc::m_show_old_query_dlg=1;}else{CPSMDoc::m_show_old_query_dlg=0xFFFF;}

	if(	m_b_mark_work_with_color!=CaplWorkFlowManager::m_b_mark_work_with_color ||
		m_b_mark_ended_work_with_color!=CaplWorkFlowManager::m_b_mark_ended_work_with_color||
		m_b_not_show_task_of_future_process!=CaplWorkFlowManager::m_b_not_show_task_of_future_process||
		m_i_mark_work_with_color_warning_time!=CaplWorkFlowManager::m_i_mark_work_with_color_warning_time)
	{
		CaplWorkFlowManager::m_b_mark_work_with_color=m_b_mark_work_with_color;
		CaplWorkFlowManager::m_b_mark_ended_work_with_color=m_b_mark_ended_work_with_color;
		CaplWorkFlowManager::m_b_not_show_task_of_future_process=m_b_not_show_task_of_future_process;
		CaplWorkFlowManager::m_i_mark_work_with_color_warning_time=m_i_mark_work_with_color_warning_time;
		CaplWorkFlowManager::SaveOptions();
	}

	m_doc->m_api.m_show.m_PrdNoShowReplacedPart=m_PrdNoShowReplacedPartCtrl.GetCheck();
	
//	CPSMDoc *doc=(CPSMDoc*)((CMainFrame*)AfxGetMainWnd())->m_last_open_doc;
//	if(doc==0) return;
//	CNavigatorView *view=doc->m_navigator;
//
//	if(view->m_queries_item!=0){
//		view->m_queries_item->Expand(1);
//		view->m_queries_item->Expand(2);
//	}

	CaplTreeItem::m_num_doc_4_group=m_num_doc_4_group;

	CaplDefWindowParam::Load(); // На всякий случай

	if(	m_font_face!=CaplDefWindowParam::m_font_face || 
		m_font_size!=CaplDefWindowParam::m_font_size ||
		m_def_fon_color!=CaplDefWindowParam::m_win_bk_color)
	{
		CaplDefWindowParam::m_font_face=m_font_face;
		CaplDefWindowParam::m_font_size=m_font_size;
		CaplDefWindowParam::m_win_bk_color=m_def_fon_color;
		CaplDefWindowParam::Save(); 
		
		AfxMessageBox(APL_T("Полное изменения шрифтов и цвета произойдет только после перезапуска приложения!"));
		m_bNeewResetFont=true;
	}
	CaplTranslateDialog::OnOK();
}

void COptionsShowDlg::OnCharactUnit() 
{
	// TODO: Add your control notification handler code here
/*	BOOL a2=m_charact_unit_ctrl.GetCheck();
	if(a2==TRUE)m_charact_value_ctrl.SetCheck(1);*/
}

void COptionsShowDlg::OnCharactValue() 
{
	// TODO: Add your control notification handler code here
/*	BOOL a1=m_charact_value_ctrl.GetCheck();
	if(a1==FALSE) m_charact_unit_ctrl.SetCheck(0);*/
}

void COptionsShowDlg::OnDocId() 
{
	// TODO: Add your control notification handler code here
/*	BOOL a1=m_doc_id_ctrl.GetCheck();
	BOOL a2=m_doc_name_ctrl.GetCheck();
	if((a1==FALSE)&&(a2==FALSE))
		m_doc_name_ctrl.SetCheck(1);*/
}

void COptionsShowDlg::OnDocName() 
{
	// TODO: Add your control notification handler code here
/*	BOOL a1=m_doc_id_ctrl.GetCheck();
	BOOL a2=m_doc_name_ctrl.GetCheck();
	if((a1==FALSE)&&(a2==FALSE))
		m_doc_id_ctrl.SetCheck(1);*/
}

void COptionsShowDlg::OnApprPerson() 
{
	// TODO: Add your control notification handler code here
/*	BOOL a1=m_appr_pers_ctrl.GetCheck();
	BOOL a2=m_appr_pers_role_ctrl.GetCheck();
	BOOL a3=m_appr_status_ctrl.GetCheck();
	if((a1==FALSE)&&(a2==FALSE)&&(a3==FALSE))
		m_appr_status_ctrl.SetCheck(1);*/
}

void COptionsShowDlg::OnApprPersonRole() 
{
	// TODO: Add your control notification handler code here
/*	BOOL a1=m_appr_pers_ctrl.GetCheck();
	BOOL a2=m_appr_pers_role_ctrl.GetCheck();
	BOOL a3=m_appr_status_ctrl.GetCheck();
	if((a1==FALSE)&&(a2==FALSE)&&(a3==FALSE))
		m_appr_pers_ctrl.SetCheck(1);*/
}

void COptionsShowDlg::OnApprStatus() 
{
	// TODO: Add your control notification handler code here
/*	BOOL a1=m_appr_pers_ctrl.GetCheck();
	BOOL a2=m_appr_pers_role_ctrl.GetCheck();
	BOOL a3=m_appr_status_ctrl.GetCheck();
	if((a1==FALSE)&&(a2==FALSE)&&(a3==FALSE))
		m_appr_pers_role_ctrl.SetCheck(1);*/
}

void COptionsShowDlg::OnOrgId() 
{
/*	BOOL a1=m_org_id_ctrl.GetCheck();
	BOOL a2=m_org_name_ctrl.GetCheck();
	if((a1==FALSE)&&(a2==FALSE))
		m_org_name_ctrl.SetCheck(1);*/
}

void COptionsShowDlg::OnOrgName() 
{
/*	BOOL a1=m_org_id_ctrl.GetCheck();
	BOOL a2=m_org_name_ctrl.GetCheck();
	if((a1==FALSE)&&(a2==FALSE))
		m_org_id_ctrl.SetCheck(1);*/
}

BOOL COptionsShowDlg::OnInitDialog() 
{
	CaplTranslateDialog::OnInitDialog();
	m_show_inst_info=CPSMDoc::m_show_inst_info;
	m_bSortPrjByNumzak=CPSMDoc::m_bSortPrjByNumzak;
	
	m_cancel_btn.SetIcon(GetAplStdIco16(APLSTDICO_CANCEL));
	m_cancel_btn.SetFlat(FALSE);
	m_ok_btn.SetIcon(GetAplStdIco16(APLSTDICO_OK));
	m_ok_btn.SetFlat(FALSE);

	UpdateData(FALSE);
	
	if(CaplCharacteristicTreeItem::m_ShowID_or_Name==0)	CheckRadioButton(IDC_UNIT_ID,IDC_UNIT_NAME,IDC_UNIT_ID);
	else CheckRadioButton(IDC_UNIT_ID,IDC_UNIT_NAME,IDC_UNIT_NAME);
	
	if(CaplTreeItem::m_LbDblClick_Open==true)	CheckRadioButton(IDC_LB_DBLCLICK_OPEN,IDC_LB_DBLCLICK_PROPERTY,IDC_LB_DBLCLICK_OPEN);
	else CheckRadioButton(IDC_LB_DBLCLICK_OPEN,IDC_LB_DBLCLICK_PROPERTY,IDC_LB_DBLCLICK_PROPERTY);
	

	if(CNavigatorView::DblclickViewDoc)m_dblclick_view_doc.SetCheck(1);
	else m_dblclick_view_doc.SetCheck(0);

	m_PrdNoShowReplacedPartCtrl.SetCheck(m_doc->m_api.m_show.m_PrdNoShowReplacedPart);

#ifdef _UNICODE
	m_b_show_categ_ctrl.EnableWindow(FALSE);
	m_b_show_categ_ctrl.ShowWindow(SW_HIDE);
#endif


/*	if(CaplBPManager::m_bShowId) m_act_id_ctrl.SetCheck(TRUE);
	if(CaplBPManager::m_bShowName) m_act_name_ctrl.SetCheck(TRUE);
	if(CaplBPManager::m_bShowType) m_act_type_ctrl.SetCheck(TRUE);*/

	CaplDefWindowParam::Load(); // На всякий случай
	m_font_face=CaplDefWindowParam::m_font_face;
	m_font_size=CaplDefWindowParam::m_font_size;

	CStringArray strarray;
	GetAllFontsFaces(strarray);
	int i,j;
	m_fonts_combo.AddString(_T(""));
	for(i=0;i<strarray.GetSize(); i++)
	{
		j=m_fonts_combo.AddString(strarray[i]);
		if(m_font_face==strarray[i]) m_fonts_combo.SetCurSel(j);
	}

	m_font_size_combo.AddString(_T(""));
	m_font_size_combo.SelectString(-1,_T(""));
	m_font_size_combo.AddString(_T("7"));
	m_font_size_combo.AddString(_T("8"));
	m_font_size_combo.AddString(_T("9"));
	m_font_size_combo.AddString(_T("10"));
	m_font_size_combo.AddString(_T("11"));
	m_font_size_combo.AddString(_T("12"));
	m_font_size_combo.AddString(_T("13"));
	m_font_size_combo.AddString(_T("14"));
	m_font_size_combo.AddString(_T("15"));

	if(m_font_size!=0)
	{
		CString buf;
		buf.Format(_T("%i"),-m_font_size);
		m_font_size_combo.SetWindowText(buf);
	}

	ResetExampleFont();

	m_def_fon_color=CaplDefWindowParam::m_win_bk_color;
	if(m_def_fon_color!=RGB(0,0,0)) m_st_font_example.SetBackgroundColor(m_def_fon_color);
	else m_st_font_example.SetBackgroundColor(m_system_def_fon_color);

	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}

void COptionsShowDlg::OnUnitId() 
{
	CheckRadioButton(IDC_UNIT_ID,IDC_UNIT_NAME,IDC_UNIT_ID);	
}

void COptionsShowDlg::OnUnitName() 
{
	CheckRadioButton(IDC_UNIT_ID,IDC_UNIT_NAME,IDC_UNIT_NAME);
}

void COptionsShowDlg::OnLbDblclickOpen() 
{
	CheckRadioButton(IDC_LB_DBLCLICK_OPEN,IDC_LB_DBLCLICK_PROPERTY,IDC_LB_DBLCLICK_OPEN);	
}

void COptionsShowDlg::OnLbDblclickProperty() 
{
	CheckRadioButton(IDC_LB_DBLCLICK_OPEN,IDC_LB_DBLCLICK_PROPERTY,IDC_LB_DBLCLICK_PROPERTY);
}

void COptionsShowDlg::OnCategId() 
{
/*	BOOL a1=m_categ_id_ctrl.GetCheck();
	BOOL a2=m_categ_name_ctrl.GetCheck();
	if((a1==FALSE)&&(a2==FALSE))
		m_categ_name_ctrl.SetCheck(1);*/
}

void COptionsShowDlg::OnCategName() 
{
/*	BOOL a1=m_categ_id_ctrl.GetCheck();
	BOOL a2=m_categ_name_ctrl.GetCheck();
	if((a1==FALSE)&&(a2==FALSE))
		m_categ_id_ctrl.SetCheck(1);*/
}

void COptionsShowDlg::OnActId() 
{
/*	BOOL a1=m_act_id_ctrl.GetCheck();
	BOOL a2=m_act_name_ctrl.GetCheck();
	if((a1==FALSE)&&(a2==FALSE))
		m_act_name_ctrl.SetCheck(1);*/
}

void COptionsShowDlg::OnActName() 
{
/*	BOOL a1=m_act_id_ctrl.GetCheck();
	BOOL a2=m_act_name_ctrl.GetCheck();
	if((a1==FALSE)&&(a2==FALSE))
		m_act_id_ctrl.SetCheck(1);*/
}




void COptionsShowDlg::OnCbnSelchangeFontsCombo()
{
	m_fonts_combo.GetWindowText(m_font_face);
	ResetExampleFont();
}

void COptionsShowDlg::OnCbnSelchangeFontSizeCombo()
{
	CString buf;
	int cur = m_font_size_combo.GetCurSel();
	if(cur>=0) m_font_size_combo.GetLBText(cur,buf);
	else 
	 m_font_size_combo.GetWindowText(buf);
	int i=_atoi(buf);
	if(i>0)m_font_size=-i;
	else
	{
		m_font_size=0;
		m_font_size_combo.SelectString(-1,_T(""));
	}
	ResetExampleFont();
}

void COptionsShowDlg::ResetExampleFont()
{
	LOGFONT lf;
	memset(&lf, 0, sizeof(LOGFONT));
	lf.lfHeight=-11;
	lf.lfCharSet=RUSSIAN_CHARSET;
	lf.lfWeight=FW_NORMAL;

	TCHAR *p_font_face=0;
	if(m_font_face!=_T(""))p_font_face=(TCHAR*)((LPCTSTR)m_font_face);
	else p_font_face=(TCHAR*)(LPCTSTR)m_system_font_face;

	int i;
	for(i=0; i<LF_FACESIZE;i++)
	{
		TCHAR c=(p_font_face)[i];
		lf.lfFaceName[i]=c;
		if(c==_T('\0')) break;
	}
	lf.lfFaceName[LF_FACESIZE-1]=_T('\0');

	if(m_font_size!=0) lf.lfHeight=m_font_size;
	else lf.lfHeight=m_system_font_size;

	m_st_font_example.SetFont(&lf);
}



void COptionsShowDlg::OnCbnEditchangeFontSizeCombo()
{
	OnCbnSelchangeFontSizeCombo();
}


void COptionsShowDlg::OnBnClickedSelDefFonColor()
{
	CColorDialog dlg;
	if(IDOK!=dlg.DoModal()) return;
	m_def_fon_color=dlg.GetColor();
	m_st_font_example.SetBackgroundColor(m_def_fon_color);
}

void COptionsShowDlg::OnBnClickedClearDefSysColor()
{
	m_def_fon_color=RGB(0,0,0);
	m_st_font_example.SetBackgroundColor(m_system_def_fon_color);
}

