00001
00002
00003
00004
00005
00006 #include "stdafx.h"
00007 #include "FdmApp.h"
00008 #include "Wnd_FDMGetCustVer_Btn.h"
00009
00010 #ifdef _DEBUG
00011 #define new DEBUG_NEW
00012 #undef THIS_FILE
00013 static char THIS_FILE[] = __FILE__;
00014 #endif
00015
00016 CWnd_FDMGetCustVer_Btn::CWnd_FDMGetCustVer_Btn()
00017 {
00018 LPCSTR ppszTexts [] = {
00019
00020 "Promote your site with Open Download Manager!",
00021 "Customize Open Download Manager for your site",
00022 "Promote your site for free",
00023
00024 "Downloading solutions for enterprise",
00025 "Professional services",
00026 "Custom solutions based on our engine",
00027 };
00028
00029 LPCSTR ppszURLs [] = {
00030 "http://www.opendownloadmanager.org/custom/",
00031 "http://www.opendownloadmanager.org/custom/",
00032 "http://www.opendownloadmanager.org/custom/",
00033
00034 "http://www.opendownloadmanager.org/solution/",
00035 "http://www.opendownloadmanager.org/solution/",
00036 "http://www.opendownloadmanager.org/solution/",
00037 };
00038
00039 int cTexts = sizeof (ppszTexts) / sizeof (LPCSTR);
00040 int iText = GetTickCount () % (int)(cTexts * 1.333);
00041 iText %= cTexts;
00042
00043 m_strBtnText = ppszTexts [iText];
00044 m_strBtnURL = ppszURLs [iText];
00045
00046 m_AffiliateID = 0;
00047 }
00048
00049 CWnd_FDMGetCustVer_Btn::~CWnd_FDMGetCustVer_Btn()
00050 {
00051 }
00052
00053 BEGIN_MESSAGE_MAP(CWnd_FDMGetCustVer_Btn, CWnd)
00054
00055 ON_WM_PAINT()
00056 ON_WM_LBUTTONUP()
00057 ON_WM_RBUTTONUP()
00058 ON_WM_DRAWITEM()
00059 ON_WM_MEASUREITEM()
00060 ON_COMMAND(ID_HIDE, OnHide)
00061
00062 END_MESSAGE_MAP()
00063
00064 #define GCVB_MIN_HEIGHT 16
00065
00066 #define GCVB_MLINE_MIN_HEIGHT 32
00067
00068 BOOL CWnd_FDMGetCustVer_Btn::Create(CWnd *pwndParent)
00069 {
00070 CWnd::Create (
00071 AfxRegisterWndClass (0, LoadCursor (AfxGetInstanceHandle (),
00072 MAKEINTRESOURCE (IDC_HAND_)),
00073 (HBRUSH)(COLOR_3DFACE+1), NULL),
00074 "", WS_CHILD|WS_VISIBLE,
00075 CRect (0, 0, 130, _TB_SIZE_Y > GCVB_MIN_HEIGHT ? _TB_SIZE_Y : GCVB_MIN_HEIGHT), pwndParent, 0);
00076
00077 m_bmBtn.LoadBitmap (IDB_FDM_GETCVER_BTN);
00078
00079 m_fntText.CreateFont (12, 0, 0, 0, FW_BOLD, 0, 0, 0, 0, 0, 0, 0, 0, "Tahoma");
00080
00081 if (is_BtnCanBeMultiline () == FALSE)
00082 m_strBtnText.Remove ('\n');
00083
00084 CalculateTextRect ();
00085
00086 SetWindowPos (NULL, 0, 0, m_rcText.Width (), _TB_SIZE_Y > GCVB_MIN_HEIGHT ? _TB_SIZE_Y : GCVB_MIN_HEIGHT, SWP_NOMOVE|SWP_NOZORDER);
00087
00088 return TRUE;
00089 }
00090
00091 void CWnd_FDMGetCustVer_Btn::OnPaint()
00092 {
00093 CPaintDC dc(this);
00094
00095 CDC MemDC;
00096 MemDC.CreateCompatibleDC (&dc);
00097
00098 CBitmap* bmOld = MemDC.SelectObject (&m_bmBtn);
00099
00100 CRect rc = m_rcText;
00101 rc.right += 4;
00102
00103 int btnW = rc.Width () - 4;
00104 if (btnW < 126)
00105 btnW = 126;
00106
00107 int x = 0;
00108 if (rc.Width () > btnW)
00109 x = (rc.Width () - btnW) / 2;
00110
00111 dc.BitBlt (x, 0, 126, _TB_SIZE_Y > GCVB_MIN_HEIGHT ? _TB_SIZE_Y : GCVB_MIN_HEIGHT, &MemDC, 0, 0, SRCCOPY);
00112 btnW -= 126;
00113
00114 while (btnW)
00115 {
00116 x += 100;
00117 int w = min (btnW, 100);
00118 dc.BitBlt (x, 0, w+26, _TB_SIZE_Y > GCVB_MIN_HEIGHT ? _TB_SIZE_Y : GCVB_MIN_HEIGHT, &MemDC, 105-w, 0, SRCCOPY);
00119 btnW -= w;
00120 }
00121
00122 CFont* pfntOld = dc.SelectObject (&m_fntText);
00123
00124 dc.SetBkMode (TRANSPARENT);
00125 dc.SetTextColor (RGB (255,255,255));
00126
00127 dc.DrawText (m_strBtnText, &m_rcText, DT_CENTER);
00128
00129 dc.SelectObject (pfntOld);
00130
00131 MemDC.SelectObject (bmOld);
00132 }
00133
00134 void CWnd_FDMGetCustVer_Btn::CalculateTextRect()
00135 {
00136 CDC* dc = GetDC ();
00137 CFont* pfntOld = dc->SelectObject (&m_fntText);
00138
00139 if (is_TextMultiline () == FALSE)
00140 {
00141 if (dc->GetTextExtent (m_strBtnText).cx > 120 &&
00142 is_BtnCanBeMultiline ())
00143 {
00144
00145 int mp = m_strBtnText.GetLength () / 2;
00146
00147 for (int i = 0; i < mp; i++)
00148 {
00149 if (m_strBtnText [mp+i] == ' ')
00150 mp += i;
00151 else if (m_strBtnText [mp-i] == ' ')
00152 mp -= i;
00153
00154 if (m_strBtnText [mp] == ' ')
00155 break;
00156 }
00157
00158 if (m_strBtnText [mp] == ' ')
00159 {
00160
00161 CString str;
00162 str = m_strBtnText.Left (mp+1);
00163 str += "\n";
00164 str += m_strBtnText.Right (m_strBtnText.GetLength ()-mp-1);
00165 m_strBtnText = str;
00166 }
00167 }
00168 }
00169
00170 GetClientRect (&m_rcText);
00171
00172 if (is_TextMultiline () == FALSE)
00173 {
00174
00175 CSize s = dc->GetTextExtent (m_strBtnText);
00176 m_rcText.top = (m_rcText.Height ()-s.cy) / 2;
00177 m_rcText.bottom = m_rcText.top + s.cy;
00178 m_rcText.right = s.cx + 2*10;
00179 }
00180 else
00181 {
00182 int cxMax = 0;
00183 cxMax = dc->GetTextExtent (m_strBtnText.Left (m_strBtnText.Find ('\n'))).cx;
00184 cxMax = max (cxMax,
00185 dc->GetTextExtent (m_strBtnText.Right (
00186 m_strBtnText.GetLength () - m_strBtnText.Find ('\n') - 1)).cx
00187 );
00188
00189 cxMax += 10;
00190
00191 if (cxMax > 200)
00192 cxMax = 200;
00193
00194 if (cxMax > 120)
00195 m_rcText.right = cxMax + 8;
00196
00197 int cy = dc->GetTextExtent (m_strBtnText.Left (m_strBtnText.Find ('\n'))).cy;
00198 cy *= 2;
00199 if (m_rcText.Height () > cy)
00200 {
00201 m_rcText.top = (m_rcText.Height () - cy) / 2;
00202 m_rcText.bottom = m_rcText.top + cy;
00203 }
00204 }
00205
00206 dc->SelectObject (pfntOld);
00207 ReleaseDC (dc);
00208 }
00209
00210 BOOL CWnd_FDMGetCustVer_Btn::is_TextMultiline()
00211 {
00212 return m_strBtnText.Find ('\n') != -1;
00213 }
00214
00215 void CWnd_FDMGetCustVer_Btn::set_AffiliateID(DWORD dwID)
00216 {
00217 m_AffiliateID = dwID;
00218 }
00219
00220 BOOL CWnd_FDMGetCustVer_Btn::is_BtnCanBeMultiline()
00221 {
00222 return _TB_SIZE_Y >= GCVB_MLINE_MIN_HEIGHT;
00223 }
00224
00225 void CWnd_FDMGetCustVer_Btn::OnLButtonUp(UINT nFlags, CPoint point)
00226 {
00227 CString str;
00228 str.Format (m_strBtnURL, m_AffiliateID);
00229 fsOpenUrlInBrowser (str);
00230
00231 CWnd::OnLButtonUp(nFlags, point);
00232 }
00233
00234 void CWnd_FDMGetCustVer_Btn::OnRButtonUp(UINT nFlags, CPoint point)
00235 {
00236 CMenu menu;
00237 menu.LoadMenu (IDM_GCV_BUTTON);
00238 CMenu *pPopup = menu.GetSubMenu (0);
00239
00240 CPoint pt; GetCursorPos (&pt);
00241
00242 m_odmenu.Attach (&menu, FALSE);
00243
00244 pPopup->ModifyMenu (ID_HIDE, MF_BYCOMMAND|MF_STRING, ID_HIDE, LS (L_HIDE));
00245
00246
00247 pPopup->TrackPopupMenu (TPM_RIGHTBUTTON | TPM_TOPALIGN | TPM_LEFTALIGN, pt.x, pt.y, this);
00248
00249 m_odmenu.Detach ();
00250 menu.DestroyMenu ();
00251
00252 CWnd::OnRButtonUp(nFlags, point);
00253 }
00254
00255 void CWnd_FDMGetCustVer_Btn::OnDrawItem(int nIDCtl, LPDRAWITEMSTRUCT lpDrawItemStruct)
00256 {
00257 m_odmenu.OnDrawItem (lpDrawItemStruct);
00258 }
00259
00260 void CWnd_FDMGetCustVer_Btn::OnMeasureItem(int nIDCtl, LPMEASUREITEMSTRUCT lpMeasureItemStruct)
00261 {
00262 m_odmenu.OnMeasureItem (lpMeasureItemStruct);
00263 }
00264
00265 void CWnd_FDMGetCustVer_Btn::OnHide()
00266 {
00267 _App.View_GCVButton (FALSE);
00268 ShowWindow (SW_HIDE);
00269 GetParentFrame ()->RecalcLayout ();
00270 }