////////////////////////////////////////////////////////////////////////////////
//
// Copyright (c) 2004 Sergey Solozhentsev
// Author: Sergey Solozhentsev e-mail: salos@mail.ru
// Product: WTL Helper
// File: WtlHelperDlg.cpp
// Created: 12.01.2005 13:54
//
// Using this software in commercial applications requires an author
// permission. The permission will be granted to everyone excluding the cases
// when someone simply tries to resell the code.
// This file may be redistributed by any means PROVIDING it is not sold for
// profit without the authors written consent, and providing that this notice
// and the authors name is included.
// This file is provided "as is" with no expressed or implied warranty. The
// author accepts no liability if it causes any damage to you or your computer
// whatsoever.
//
////////////////////////////////////////////////////////////////////////////////
// This file was generated by WTL Dialog wizard
// WtlHelperDlg.cpp : Implementation of CWtlHelperDlg
#include "stdafx.h"
#include "WtlHelperDlg.h"
LPCTSTR g_MainDlgName = _T("MainDlg");
extern LPCTSTR RegPath;
// CWtlHelperDlg
CWtlHelperDlg::CWtlHelperDlg() : m_iActivePage(-1), m_bSavePreviousPane(false)
{
}
CWtlHelperDlg::~CWtlHelperDlg()
{
}
void CWtlHelperDlg::SetCommonPointers()
{
m_FunctionPage.m_pClassVector = m_VariablePage.m_pClassVector = m_pClassVector;
m_FunctionPage.m_pModifications = m_VariablePage.m_pModifications = m_pModifications;
m_FunctionPage.m_piCurrentClass = m_VariablePage.m_piCurrentClass = m_piCurrentClass;
m_FunctionPage.m_pResManager = m_VariablePage.m_pResManager = m_pResManager;
}
void CWtlHelperDlg::LoadSettings()
{
CRegArchive RegArchive;
if (RegArchive.Open(HKEY_CURRENT_USER, RegPath))
{
CSettings<CWtlHelperDlg>::LoadSettings(RegArchive, g_MainDlgName);
RegArchive.Close();
}
if (m_DlgSettings.m_WindowRect.right == 0)
{
m_DlgSettings.m_WindowRect.SetRect(0, 0, 600, 450);
}
MoveWindow(m_DlgSettings.m_WindowRect);
}
void CWtlHelperDlg::SaveSettings()
{
GetWindowRect(m_DlgSettings.m_WindowRect);
m_DlgSettings.m_ActiveTab = m_tabbedChildWindow.GetTabCtrl().GetCurSel();
CRegArchive RegArchive;
if (RegArchive.Open(HKEY_CURRENT_USER, RegPath, true))
{
m_DlgSettings.SaveSettings(RegArchive, g_MainDlgName);
RegArchive.Close();
}
}
LRESULT CWtlHelperDlg::OnInitDialog(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
START_PROFILE(MainDlg_Init);
LoadSettings();
CenterWindow();
DWORD dwStyle = ATL_SIMPLE_TOOLBAR_STYLE | TBSTYLE_FLAT;
m_ToolBar.Create(m_hWnd, NULL, NULL, dwStyle, 0, ATL_IDW_TOOLBAR);
m_ToolBar.SetButtonStructSize();
m_ToolBar.SetBitmapSize(CSize(18, 18));
m_ToolBar.SendMessage(WM_SIZE);
CRect rc, tabrc, dlgrc;
m_ToolBar.GetWindowRect(&rc);
ScreenToClient(&rc);
tabrc.top = rc.bottom;
tabrc.left = 0;
tabrc.right = rc.right;
GetClientRect(dlgrc);
CRect r1(0, 0, 4, 3);
MapDialogRect(r1);
CSize Spaces = r1.Size();
int OffSetX = Spaces.cx * 2;
GetDlgItem(IDC_BUTTON_APPLY).GetWindowRect(&rc);
ScreenToClient(rc);
rc.OffsetRect(dlgrc.right - rc.right - OffSetX, dlgrc.bottom - rc.bottom - Spaces.cy);
GetDlgItem(IDC_BUTTON_APPLY).MoveWindow(rc);
GetDlgItem(IDC_BUTTON_APPLY).EnableWindow(FALSE);
OffSetX += rc.Width() + Spaces.cx;
GetDlgItem(IDCANCEL).GetWindowRect(&rc);
ScreenToClient(rc);
rc.OffsetRect(dlgrc.right - rc.right - OffSetX, dlgrc.bottom - rc.bottom - Spaces.cy);
GetDlgItem(IDCANCEL).MoveWindow(rc);
OffSetX += rc.Width() + Spaces.cx;
GetDlgItem(IDOK).GetWindowRect(&rc);
ScreenToClient(rc);
rc.OffsetRect(dlgrc.right - rc.right - OffSetX, dlgrc.bottom - rc.bottom - Spaces.cy);
GetDlgItem(IDOK).MoveWindow(rc);
OffSetX += rc.Width() + Spaces.cx;
tabrc.bottom = rc.top - Spaces.cy;
SetCommonPointers();
m_tabbedChildWindow.SetTabStyles(CTCS_TOOLTIPS | CTCS_DRAGREARRANGE);
m_tabbedChildWindow.Create(m_hWnd, NULL, NULL, WS_CHILD | WS_VISIBLE | WS_CLIPSIBLINGS | WS_CLIPCHILDREN,
WS_EX_STATICEDGE, IDC_PAGESTAB);
m_tabbedChildWindow.SetForwardNotifications();
START_PROFILE(CreateChild)
m_FunctionPage.Create(m_tabbedChildWindow);
m_VariablePage.Create(m_tabbedChildWindow);
END_PROFILE(CreateChild, _T("CWtlHelperDlg::OnInitDialog - Create Children"));
m_tabbedChildWindow.AddTab(m_FunctionPage, _T("Messages"));
m_tabbedChildWindow.AddTab(m_VariablePage, _T("Variables"));
m_tabbedChildWindow.MoveWindow(tabrc);
int ActiveTab = 0;
if (m_iActivePage == -1)
{
ActiveTab = (m_bSavePreviousPane) ? m_DlgSettings.m_ActiveTab : 0;
}
else
{
ActiveTab = m_iActivePage;
}
m_tabbedChildWindow.GetTabCtrl().SetCurSel(ActiveTab);
DlgResize_Init(true, false);
END_PROFILE(MainDlg_Init, _T("CWtlHelperDlg::OnInitDialog"));
return 0; // Let the system set the focus
}
LRESULT CWtlHelperDlg::OnSize(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
CDialogResize<CWtlHelperDlg>::OnSize(uMsg, wParam, lParam, bHandled);
if (m_ToolBar.m_hWnd)
{
m_ToolBar.SendMessage(WM_SIZE);
}
bHandled = TRUE;
return 0;
}
LRESULT CWtlHelperDlg::OnDestroy(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
SaveSettings();
return 0;
}
LRESULT CWtlHelperDlg::OnGetMinMaxInfo(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
MINMAXINFO* pMinMax = (MINMAXINFO*)lParam;
pMinMax->ptMinTrackSize.x = 600;
pMinMax->ptMinTrackSize.y = 450;
bHandled = TRUE;
return 0;
}
LRESULT CWtlHelperDlg::OnClickedOK(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
m_FunctionPage.UpdateForwardReflect();
EndDialog(wID);
return 0;
}
LRESULT CWtlHelperDlg::OnClickedCancel(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
EndDialog(wID);
return 0;
}
LRESULT CWtlHelperDlg::OnApply(WORD wNotifyCode, WORD wID, HWND hWndCtl, BOOL& bHandled)
{
m_FunctionPage.UpdateForwardReflect();
UpdateClasses(m_pModifications, m_pClassVector);
GetDlgItem(IDC_BUTTON_APPLY).EnableWindow(FALSE);
return 0;
}
LRESULT CWtlHelperDlg::OnTabSelectChange(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
int CurSel = m_tabbedChildWindow.GetTabCtrl().GetCurSel();
if (CurSel >= 0)
{
::SendMessage(m_tabbedChildWindow.GetActiveView(), WTLH_SETACTIVE, (WPARAM)m_ToolBar.m_hWnd, 0);
}
return 0;
}
LRESULT CWtlHelperDlg::OnTtnGetDispInfo(int idCtrl, LPNMHDR pnmh, BOOL& bHandled)
{
LPNMTTDISPINFO lpnmtdi = (LPNMTTDISPINFO)pnmh;
if((idCtrl != 0) && !(lpnmtdi->uFlags & TTF_IDISHWND))
{
CString Tip;
if (Tip.LoadString(idCtrl))
{
if (Tip.GetLength() > 80)
{
Tip = Tip.Left(79);
}
lstrcpy(lpnmtdi->szText, Tip);
}
}
return 0;
}
LRESULT CWtlHelperDlg::OnSetModified(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
GetDlgItem(IDC_BUTTON_APPLY).EnableWindow((BOOL)wParam);
return 0;
}