GME  13
PartBrowserPaneFrame.cpp
Go to the documentation of this file.
00001 // PartBrowserPaneFrame.cpp : implementation file
00002 //
00003 
00004 #include "stdafx.h"
00005 #include "PartBrowserPane.h"
00006 #include "PartBrowserPaneFrame.h"
00007 #include "PartBrowserDlg.h"
00008 
00009 #ifdef _DEBUG
00010 #define new DEBUG_NEW
00011 #undef THIS_FILE
00012 static char THIS_FILE[] = __FILE__;
00013 #endif
00014 
00016 // CPartBrowserPaneFrame dialog
00017 
00018 
00019 CPartBrowserPaneFrame::CPartBrowserPaneFrame(CWnd* pParent/* = NULL*/)
00020         : CDialog(CPartBrowserPaneFrame::IDD, pParent),
00021         vScrollWidth (::GetSystemMetrics (SM_CXVSCROLL)),       // WinXP default style: 17
00022         lineSize (20),
00023         pageSize (60),
00024     pageHeight(100), // maybe fix UNINITIALIZED READ: reading register edx PartBrowser.OCX!CPartBrowserPaneFrame::Resize [c:\users\kevin\documents\gme\gme\partbrowser\partbrowserpaneframe.cpp:57]
00025     logicalHeight(100)
00026 {
00027         //{{AFX_DATA_INIT(CPartBrowserPaneFrame)
00028                 // NOTE: the ClassWizard will add member initialization here
00029         //}}AFX_DATA_INIT
00030 }
00031 
00032 
00033 void CPartBrowserPaneFrame::DoDataExchange(CDataExchange* pDX)
00034 {
00035         CDialog::DoDataExchange(pDX);
00036         //{{AFX_DATA_MAP(CPartBrowserPaneFrame)
00037                 // NOTE: the ClassWizard will add DDX and DDV calls here
00038         //}}AFX_DATA_MAP
00039 }
00040 
00041 
00042 BEGIN_MESSAGE_MAP(CPartBrowserPaneFrame, CDialog)
00043         //{{AFX_MSG_MAP(CPartBrowserPaneFrame)
00044         ON_WM_VSCROLL()
00045         ON_WM_MOUSEWHEEL()
00046         //}}AFX_MSG_MAP
00047 END_MESSAGE_MAP()
00048 
00049 
00050 void CPartBrowserPaneFrame::Resize(RECT r)
00051 {
00052         MoveWindow(&r);
00053         GetClientRect(&r);
00054 
00055         // ok, if there is the scroll bar there then we want to
00056         // increase the size, the number 16 is empirical 
00057 
00058         if (logicalHeight > pageHeight)
00059                 r.right += vScrollWidth;
00060         
00061         pane.MoveWindow(&r);
00062         BringWindowToTop();
00063         pane.BringWindowToTop();
00064         pane.Resize(r);
00065 }
00066 
00067 void CPartBrowserPaneFrame::SetScrollBar()
00068 {
00069         if (scrollPos > (logicalHeight - pageHeight + 1))
00070                 scrollPos = (logicalHeight - pageHeight + 1);
00071         if (scrollPos < 0)
00072                 scrollPos = 0;
00073 
00074         if (logicalHeight > pageHeight) {
00075                 SCROLLINFO si;
00076                 si.cbSize = sizeof(SCROLLINFO);
00077                 si.fMask = SIF_ALL;
00078                 si.nPage = pageHeight;
00079                 si.nMin = 0;
00080                 si.nMax = logicalHeight;
00081                 si.nPos = scrollPos;
00082                 SetScrollInfo(SB_VERT, &si);
00083         }
00084 
00085         ShowScrollBar(SB_VERT, logicalHeight > pageHeight);
00086 }
00087 
00089 // Get/Set methods
00090 
00091 CPartBrowserPane& CPartBrowserPaneFrame::GetPane (void)
00092 {
00093         return pane;
00094 }
00095 
00096 
00097 void CPartBrowserPaneFrame::SetLogicalHeight (int logHeight)
00098 {
00099         logicalHeight = logHeight;
00100 }
00101 
00102 
00103 void CPartBrowserPaneFrame::SetPageHeight (int pgHeight)
00104 {
00105         pageHeight = pgHeight;
00106 }
00107 
00108 
00109 int CPartBrowserPaneFrame::GetScrollPosition (void)
00110 {
00111         return scrollPos;
00112 }
00113 
00114 
00115 void CPartBrowserPaneFrame::SetScrollPosition (int scrollPosition)
00116 {
00117         scrollPos = scrollPosition;
00118 }
00119 
00120 
00122 // CPartBrowserPaneFrame message handlers
00123 
00124 BOOL CPartBrowserPaneFrame::OnInitDialog()
00125 {
00126         CDialog::OnInitDialog();
00127         
00128         RECT r;
00129         GetClientRect(&r);
00130         BOOL success = pane.Create(NULL, _T("PartsPane"), WS_CHILD | WS_VISIBLE | WS_BORDER, r, this, IDD_PARTBROWSER_PANE);
00131         pane.ModifyStyleEx(0, WS_EX_CLIENTEDGE);
00132 
00133         return TRUE;    // return TRUE unless you set the focus to a control
00134                                         // EXCEPTION: OCX Property Pages should return FALSE
00135 }
00136 
00137 void CPartBrowserPaneFrame::OnVScroll(UINT nSBCode, UINT nPos, CScrollBar* /*pScrollBar*/)
00138 {
00139         int oldPos = scrollPos;
00140 
00141         switch(nSBCode)
00142         {
00143         case SB_TOP:
00144                 scrollPos = 0;
00145                 break;
00146         case SB_BOTTOM:
00147                 scrollPos = logicalHeight - pageHeight;
00148                 break;
00149         case SB_ENDSCROLL:
00150                 break;
00151         case SB_LINEDOWN:
00152                 scrollPos += lineSize;
00153                 break;
00154         case SB_LINEUP:
00155                 scrollPos -= lineSize; 
00156                 break;
00157         case SB_PAGEDOWN:
00158                 scrollPos += pageSize;
00159                 break;
00160         case SB_PAGEUP:
00161                 scrollPos -= pageSize;
00162                 break;
00163         case SB_THUMBPOSITION:
00164         case SB_THUMBTRACK:
00165                 scrollPos = nPos;
00166                 break;
00167         }
00168 
00169         if (scrollPos > (logicalHeight - pageHeight + 1))
00170                 scrollPos = (logicalHeight - pageHeight + 1);
00171         if (scrollPos < 0)
00172                 scrollPos = 0;
00173 
00174         pane.ScrollWindow(0, oldPos - scrollPos, NULL, NULL);
00175         SetScrollPos(SB_VERT, scrollPos);
00176 
00177 //      CDialog::OnVScroll(nSBCode, nPos, pScrollBar);
00178 }
00179 
00180 BOOL CPartBrowserPaneFrame::OnMouseWheel(UINT fFlags, short zDelta, CPoint point)
00181 {
00182         UNUSED_ALWAYS(point);
00183 
00184         // we don't handle anything but scrolling just now
00185         if (fFlags & (MK_SHIFT | MK_CONTROL))
00186                 return FALSE;
00187 
00188         // if we have a vertical scroll bar, the wheel scrolls that
00189         // if we have _only_ a horizontal scroll bar, the wheel scrolls that
00190         // otherwise, don't do any work at all
00191 
00192         DWORD dwStyle = GetStyle();
00193         CScrollBar* pBar = GetScrollBarCtrl(SB_VERT);
00194         BOOL bHasVertBar = ((pBar != NULL) && pBar->IsWindowEnabled()) ||
00195                                                 (dwStyle & WS_VSCROLL);
00196 
00197         if (bHasVertBar) {
00198                 OnVScroll(zDelta < 0 ? SB_LINEDOWN : SB_LINEUP, 0, NULL);
00199 
00200                 UpdateWindow();
00201                 return TRUE;
00202         }
00203 
00204         return FALSE;
00205 }