GME  13
ConnityDlg.cpp
Go to the documentation of this file.
00001 // ConnityDlg.cpp : implementation file
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "resource.h"
00006 #include "ConnityDlg.h"
00007 
00008 
00009 // CConnityDlg dialog
00010 
00011 //static
00012 int          CConnityDlg::m_lastCX     = 0;
00013 int          CConnityDlg::m_lastCY     = 0;
00014 int          CConnityDlg::m_smallestCX = 170;
00015 int          CConnityDlg::m_smallestCY = 150;
00016 int          CConnityDlg::m_leftPad    = 15;
00017 int          CConnityDlg::m_rightPad   = 14;
00018 
00019 
00020 
00021 IMPLEMENT_DYNAMIC(CConnityDlg, CDialog)
00022 CConnityDlg::CConnityDlg( bool p_reverse, CWnd* pParent /*=NULL*/)
00023         : CDialog(CConnityDlg::IDD, pParent)
00024         , m_listC( 0)
00025         , m_selectedC( 0)
00026         , m_reverse( p_reverse)
00027 {
00028 }
00029 
00030 CConnityDlg::~CConnityDlg()
00031 {
00032 }
00033 
00034 void CConnityDlg::setList( CGuiConnectionList& p_list)
00035 {
00036         m_listC = &p_list;
00037 }
00038 
00039 CGuiConnection*    CConnityDlg::getSelectedC()
00040 {
00041         return m_selectedC;
00042 }
00043 
00044 void CConnityDlg::DoDataExchange(CDataExchange* pDX)
00045 {
00046         CDialog::DoDataExchange(pDX);
00047         DDX_Control(pDX, IDC_LIST1, m_options);
00048         DDX_Control(pDX, IDOK, m_ok);
00049         DDX_Control(pDX, IDCANCEL, m_ca);
00050 }
00051 
00052 
00053 BEGIN_MESSAGE_MAP(CConnityDlg, CDialog)
00054         ON_LBN_DBLCLK(IDC_LIST1, OnLbnDblclkList1)
00055         ON_WM_SIZING()
00056         ON_WM_SIZE()
00057         ON_WM_CREATE()
00058         ON_WM_PAINT()
00059 END_MESSAGE_MAP()
00060 
00061 
00062 // CConnityDlg message handlers
00063 
00064 BOOL CConnityDlg::OnInitDialog()
00065 {
00066         CDialog::OnInitDialog();
00067 
00068         if( CConnityDlg::m_lastCX && CConnityDlg::m_lastCY)
00069         {
00070                 CRect rect;
00071                 GetWindowRect( &rect);
00072                 SetWindowPos( 0, rect.left, rect.top, m_lastCX, m_lastCY, SWP_NOZORDER | SWP_NOACTIVATE);
00073         }
00074 
00075         if( m_listC && m_listC->GetCount() > 0)
00076         {
00077                 POSITION pos = m_listC->GetHeadPosition();
00078                 while( pos)
00079                 {
00080                         CGuiConnection* one = m_listC->GetNext( pos);
00081                         if( !one) continue;
00082 
00083                         CGuiObject* end = m_reverse? one->src    : one->dst;
00084                         CGuiPort*  port = m_reverse? one->srcPort: one->dstPort;
00085 
00086                         CString item;
00087                         item += ( !one->name.IsEmpty()? one->name: one->kindName);
00088                         if( end && port && port->IsRealPort())
00089                         {
00090                                 item += " -> [ " + end->name + " : " + port->name + " ]";
00091                         }
00092                         else if( end)
00093                                 item += " -> " + end->name;
00094 
00095                         m_options.AddString( item);
00096                 }
00097         }
00098 
00099         return TRUE;
00100 }
00101 
00102 void CConnityDlg::OnOK()
00103 {
00104         int which = m_options.GetCurSel();
00105 
00106         // finding the selected object in the list based on the index
00107         // relies on the unsorted  behaviour of the listbox
00108         if( m_listC && m_listC->GetCount() > 0)
00109         {
00110                 int pos_i = -1;
00111                 POSITION pos = m_listC->GetHeadPosition();
00112                 while( pos)
00113                 {
00114                         CGuiConnection* one = m_listC->GetNext( pos);
00115                         if( ++pos_i == which)
00116                                 m_selectedC = one;
00117                 }
00118         }
00119 
00120         // save the actual Height and Width
00121         CRect rect;
00122         GetWindowRect( &rect);
00123 
00124         CConnityDlg::m_lastCX = rect.Width();
00125         CConnityDlg::m_lastCY = rect.Height();
00126 
00127         CDialog::OnOK();
00128 }
00129 
00130 void CConnityDlg::OnLbnDblclkList1()
00131 {
00132         OnOK();
00133 }
00134 
00135 
00136 void CConnityDlg::OnSizing(UINT fwSide, LPRECT pRect)
00137 {
00138         if( pRect->bottom - pRect->top > m_smallestCY
00139          && pRect->right - pRect->left > m_smallestCX)
00140                 CDialog::OnSizing(fwSide, pRect);
00141         else
00142         {
00143                 if( pRect->bottom - pRect->top < m_smallestCY) pRect->bottom = pRect->top + m_smallestCY;
00144                 if( pRect->right - pRect->left < m_smallestCX) pRect->right = pRect->left + m_smallestCX;
00145         }
00146 }
00147 
00148 void CConnityDlg::OnSize(UINT nType, int cx, int cy)
00149 {
00150         CDialog::OnSize(nType, cx, cy);
00151 
00152         CRect ls_rect, ok_rect, ca_rect;
00153         if (m_options.GetSafeHwnd() && m_ok.GetSafeHwnd() && m_ca.GetSafeHwnd()) {
00154                 m_options.GetWindowRect( &ls_rect);
00155                 m_ok.GetWindowRect( &ok_rect);
00156                 m_ca.GetWindowRect( &ca_rect);
00157 
00158                 ScreenToClient( &ls_rect);
00159                 ScreenToClient( &ok_rect);
00160                 ScreenToClient( &ca_rect);
00161 
00162                 int width = cx - m_leftPad - m_rightPad;
00163 
00164                 m_options.SetWindowPos( NULL, m_leftPad, ls_rect.top, width > 20? width: 20, cy - ls_rect.top - 2*ok_rect.Height(), SWP_NOZORDER);
00165 
00166                 int btn_y = cy - 3* ok_rect.Height()/2;
00167                 m_ok.SetWindowPos( 0, ok_rect.left, btn_y, ok_rect.Width(), ok_rect.Height(), SWP_NOZORDER);
00168                 m_ca.SetWindowPos( 0, ca_rect.left, btn_y, ca_rect.Width(), ok_rect.Height(), SWP_NOZORDER);
00169 
00170                 Invalidate();
00171         }
00172 }
00173 
00174 int CConnityDlg::OnCreate(LPCREATESTRUCT lpCreateStruct)
00175 {
00176         if (CDialog::OnCreate(lpCreateStruct) == -1)
00177                 return -1;
00178 
00179         return 0;
00180 }
00181 
00182 void CConnityDlg::OnPaint()
00183 {
00184         CPaintDC dc(this); // device context for painting
00185         CRect rc;
00186         GetClientRect(&rc);
00187 
00188         rc.left = rc.right - ::GetSystemMetrics(SM_CXHSCROLL);
00189         rc.top = rc.bottom - ::GetSystemMetrics(SM_CYVSCROLL);
00190 
00191         dc.DrawFrameControl(rc, DFC_SCROLL, DFCS_SCROLLSIZEGRIP);
00192 }