12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123 |
- /*
- Cool Scrollbar Library Version 1.2
- Module: coolscroll.c
- Copyright (c) J Brown 2001
-
- This code is freeware, however, you may not publish
- this code elsewhere or charge any money for it. This code
- is supplied as-is. I make no guarantees about the suitability
- of this code - use at your own risk.
-
- It would be nice if you credited me, in the event
- that you use this code in a product.
-
- VERSION HISTORY:
- V1.2: TreeView problem fixed by Diego Tartara
- Small problem in thumbsize calculation also fixed (thanks Diego!)
- V1.1: Added support for Right-left windows
- Changed calling convention of APIs to WINAPI (__stdcall)
- Completely standalone (no need for c-runtime)
- Now supports ALL windows with appropriate USER32.DLL patching
- (you provide!!)
- V1.0: Apr 2001: Initial Version
- IMPORTANT:
- This whole library is based around code for a horizontal scrollbar.
- All "vertical" scrollbar drawing / mouse interaction uses the
- horizontal scrollbar functions, but uses a trick to convert the vertical
- scrollbar coordinates into horizontal equivelants. When I started this project,
- I quickly realised that the code for horz/vert bars was IDENTICAL, apart
- from the fact that horizontal code uses left/right coords, and vertical code
- uses top/bottom coords. On entry to a "vertical" drawing function, for example,
- the coordinates are "rotated" before the horizontal function is called, and
- then rotated back once the function has completed. When something needs to
- be drawn, the coords are converted back again before drawing.
-
- This trick greatly reduces the amount of code required, and makes
- maintanence much simpler. This way, only one function is needed to draw
- a scrollbar, but this can be used for both horizontal and vertical bars
- with careful thought.
- */
- #include "stdafx.h"
- #define WIN32_LEAN_AND_MEAN
- #include <windows.h>
- #include <commctrl.h>
- #include <tchar.h>
- #include "coolscroll.h"
- #include "userdefs.h"
- #include "coolsb_internal.h"
- extern HBRUSH g_frameedgebrush; //´°¿Ú±ß¿òÑÕÉ«»Ë¢
- //define some values if the new version of common controls CoolSB_SetStyle
- //is not available. GetParent
- #ifndef NM_CUSTOMDRAW
- #define NM_CUSTOMDRAW (NM_FIRST-12)
- #define CDRF_DODEFAULT 0x0000
- #define CDRF_SKIPDEFAULT 0x0004
- #define CDDS_PREPAINT 0x0001
- #define CDDS_POSTPAINT 0x0002
- #endif
- //
- // Special thumb-tracking variables
- //
- //
- static UINT uCurrentScrollbar = COOLSB_NONE; //SB_HORZ / SB_VERT
- static UINT uCurrentScrollPortion = HTSCROLL_NONE;
- static UINT uCurrentButton = 0;
- static RECT rcThumbBounds; //area that the scroll thumb can travel in
- static int nThumbSize; //(pixels)
- static int nThumbPos; //(pixels)
- static int nThumbMouseOffset; //(pixels)
- static int nLastPos = -1; //(scrollbar units)
- static int nThumbPos0; //(pixels) initial thumb position
- //
- // Temporary state used to auto-generate timer messages
- //
- static UINT uMouseOverId = 0;
- static UINT uMouseOverScrollbar = COOLSB_NONE;
- static UINT uHitTestPortion = HTSCROLL_NONE;
- static UINT uLastHitTestPortion = HTSCROLL_NONE;
- static RECT MouseOverRect;
- static UINT uScrollTimerMsg = 0;
- static UINT uScrollTimerPortion = HTSCROLL_NONE;
- static UINT uScrollTimerId = 0;
- static HWND hwndCurCoolSB = 0;
- int nVScrollMax, nVScrollPos, nVScrollPage;
- int nHScrollMax, nHScrollPos, nHScrollPage;
- int nVMaxLines = 20;
- int nHMaxLines = 80;
- int xChar = 10;
- int yChar = 10;
- void SetupScrollbars(HWND hwnd)
- {
- SCROLLINFO si;
- RECT rect;
- GetClientRect(hwnd, &rect);
- // VERT
- nVScrollPage = min(nVMaxLines + 1, (rect.bottom - rect.top) / yChar);
- nVScrollMax = max(0, nVMaxLines);
- nVScrollPos = min(nVScrollPos, nVScrollMax - nVScrollPage + 1);
-
- si.cbSize = sizeof(si);
- si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
- si.nMin = 0;
- si.nMax = nVScrollMax;
- si.nPos = nVScrollPos;
- si.nPage = min(nVScrollPage, nVScrollMax + 1);
-
- CoolSB_SetScrollInfo (hwnd, SB_VERT, &si, TRUE);
- // HORZ
- nHScrollPage = min(nHMaxLines + 1, (rect.right - rect.left) / xChar);
- nHScrollMax = max(0, nHMaxLines);
- nHScrollPos = min(nHScrollPos, nHScrollMax - nHScrollPage + 1);
-
- si.cbSize = sizeof(si);
- si.fMask = SIF_PAGE | SIF_POS | SIF_RANGE | SIF_DISABLENOSCROLL;
- si.nMin = 0;
- si.nMax = nHScrollMax;
- si.nPos = nHScrollPos;
- si.nPage = min(nHScrollPage, nHScrollMax + 1);
-
- CoolSB_SetScrollInfo (hwnd, SB_HORZ, &si, TRUE);
- }
- //
- // Provide this so there are NO dependencies on CRT
- //
- static void CoolSB_ZeroMemory(void *ptr, DWORD bytes)
- {
- BYTE *bptr = (BYTE *)ptr;
- while(bytes--) *bptr++ = 0;
- }
- BOOL WINAPI CoolSB_IsThumbTracking(HWND hwnd)
- {
- SCROLLWND *sw;
- if((sw = GetScrollWndFromHwnd(hwnd)) == NULL)
- return FALSE;
- else
- return sw->fThumbTracking;
- }
- //
- // swap the rectangle's x coords with its y coords
- //
- static void __stdcall RotateRect(RECT *rect)
- {
- int temp;
- temp = rect->left;
- rect->left = rect->top;
- rect->top = temp;
- temp = rect->right;
- rect->right = rect->bottom;
- rect->bottom = temp;
- }
- //
- // swap the coords if the scrollbar is a SB_VERT
- //
- static void __stdcall RotateRect0(SCROLLBAR *sb, RECT *rect)
- {
- if(sb->nBarType == SB_VERT)
- RotateRect(rect);
- }
- //
- // Calculate if the SCROLLINFO members produce
- // an enabled or disabled scrollbar
- //
- static BOOL IsScrollInfoActive(SCROLLINFO *si)
- {
- if((si->nPage > (UINT)si->nMax
- || si->nMax <= si->nMin || si->nMax == 0))
- return FALSE;
- else
- return TRUE;
- }
- //
- // Return if the specified scrollbar is enabled or not
- //
- static BOOL IsScrollbarActive(SCROLLBAR *sb)
- {
- SCROLLINFO *si = &sb->scrollInfo;
- if(((sb->fScrollFlags & ESB_DISABLE_BOTH) == ESB_DISABLE_BOTH) ||
- !(sb->fScrollFlags & CSBS_THUMBALWAYS) && !IsScrollInfoActive(si))
- return FALSE;
- else
- return TRUE;
- }
- //
- // Draw a standard scrollbar arrow
- //
- static int DrawScrollArrow(SCROLLBAR *sbar, HDC hdc, RECT *rect, UINT arrow, BOOL fMouseDown, BOOL fMouseOver)
- {
- UINT ret;
- UINT flags = arrow;
- //HACKY bit so this routine can be called by vertical and horizontal code
- if(sbar->nBarType == SB_VERT)
- {
- if(flags & DFCS_SCROLLLEFT) flags = flags & ~DFCS_SCROLLLEFT | DFCS_SCROLLUP;
- if(flags & DFCS_SCROLLRIGHT) flags = flags & ~DFCS_SCROLLRIGHT | DFCS_SCROLLDOWN;
- }
- if(fMouseDown) flags |= (DFCS_FLAT | DFCS_PUSHED);
- #ifdef FLAT_SCROLLBARS
- if(sbar->fFlatScrollbar != CSBS_NORMAL)
- {
- HDC hdcmem1, hdcmem2;
- HBITMAP hbm1, oldbm1;
- HBITMAP hbm2, oldbm2;
- RECT rc;
- int width, height;
- rc = *rect;
- width = rc.right-rc.left;
- height = rc.bottom-rc.top;
- SetRect(&rc, 0, 0, width, height);
- //MONOCHROME bitmap to convert the arrow to black/white mask
- hdcmem1 = CreateCompatibleDC(hdc);
- hbm1 = CreateBitmap(width, height, 1, 1, NULL);
- UnrealizeObject(hbm1);
- oldbm1 = (HBITMAP)SelectObject(hdcmem1, hbm1);
-
- //NORMAL bitmap to draw the arrow into
- hdcmem2 = CreateCompatibleDC(hdc);
- hbm2 = CreateCompatibleBitmap(hdc, width, height);
- UnrealizeObject(hbm2);
- oldbm2 = (HBITMAP)SelectObject(hdcmem2, hbm2);
-
- flags = flags & ~DFCS_PUSHED | DFCS_FLAT; //just in case
- DrawFrameControl(hdcmem2, &rc, DFC_SCROLL, flags);
- #ifndef HOT_TRACKING
- if(fMouseDown)
- {
- //uncomment these to make the cool scrollbars
- //look like the common controls flat scrollbars
- //fMouseDown = FALSE;
- //fMouseOver = TRUE;
- }
- #endif
- //draw a flat monochrome version of a scrollbar arrow (dark)
- if(fMouseDown)
- {
- SetBkColor(hdcmem2, GetSysColor(COLOR_BTNTEXT));
- BitBlt(hdcmem1, 0, 0, width, height, hdcmem2, 0, 0, SRCCOPY);
- SetBkColor(hdc, 0x00ffffff);
- SetTextColor(hdc, GetSysColor(COLOR_3DDKSHADOW));
- BitBlt(hdc, rect->left, rect->top, width, height, hdcmem1, 0, 0, SRCCOPY);
- }
- //draw a flat monochrome version of a scrollbar arrow (grey)
- else if(fMouseOver)
- {
- SetBkColor(hdcmem2, GetSysColor(COLOR_BTNTEXT));
- FillRect(hdcmem1, &rc, (HBRUSH)GetStockObject(WHITE_BRUSH));
- BitBlt(hdcmem1, 0, 0, width, height, hdcmem2, 0, 0, SRCINVERT);
- SetBkColor(hdc, GetSysColor(COLOR_3DSHADOW));
- SetTextColor(hdc, 0x00ffffff);
- BitBlt(hdc, rect->left, rect->top, width, height, hdcmem1, 0, 0, SRCCOPY);
- }
- //draw the arrow normally
- else
- {
- BitBlt(hdc, rect->left, rect->top, width, height, hdcmem2, 0, 0, SRCCOPY);
- }
- SelectObject(hdcmem1, oldbm1);
- SelectObject(hdcmem2, oldbm2);
- DeleteObject(hbm1);
- DeleteObject(hbm2);
- DeleteDC(hdcmem1);
- DeleteDC(hdcmem2);
- ret = 0;
- }
- else
- #endif
- ret = DrawFrameControl(hdc, rect, DFC_SCROLL, flags);
- return ret;
- }
- //
- // Return the size in pixels for the specified scrollbar metric,
- // for the specified scrollbar SM_CXVERTSB
- //
- static int GetScrollMetric(SCROLLBAR *sbar, int metric)
- {
- if(sbar->nBarType == SB_HORZ)
- {
- if(metric == SM_CXHORZSB)
- {
- if(sbar->nArrowLength < 0)
- return -sbar->nArrowLength * GetSystemMetrics(SM_CXHSCROLL);
- else
- return sbar->nArrowLength;
- }
- else
- {
- if(sbar->nArrowWidth < 0)
- return -sbar->nArrowWidth * GetSystemMetrics(SM_CYHSCROLL);
- else
- return sbar->nArrowWidth;
- }
- }
- else if(sbar->nBarType == SB_VERT)
- {
- if(metric == SM_CYVERTSB)
- {
- if(sbar->nArrowLength < 0)
- return -sbar->nArrowLength * GetSystemMetrics(SM_CYVSCROLL);
- else
- return sbar->nArrowLength;
- }
- else
- {
- if(sbar->nArrowWidth < 0)
- return -sbar->nArrowWidth * GetSystemMetrics(SM_CXVSCROLL);
- else
- return sbar->nArrowWidth;
- }
- }
- return 0;
- }
- //
- //
- //
- static COLORREF GetSBForeColor(void)
- {
- COLORREF c1 = GetSysColor(COLOR_3DHILIGHT);
- COLORREF c2 = GetSysColor(COLOR_WINDOW);
- if(c1 != 0xffffff && c1 == c2)
- {
- return GetSysColor(COLOR_BTNFACE);
- }
- else
- {
- return GetSysColor(COLOR_3DHILIGHT);
- }
- }
- static COLORREF GetSBBackColor(void)
- {
- return GetSysColor(COLOR_SCROLLBAR);
- }
- //
- // Paint a checkered rectangle, with each alternate
- // pixel being assigned a different colour
- //
- static void DrawCheckedRect(HDC hdc, RECT *rect, COLORREF fg, COLORREF bg)
- {
- static WORD wCheckPat[8] =
- {
- 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555, 0xaaaa, 0x5555
- };
- HBITMAP hbmp;
- HBRUSH hbr, hbrold;
- COLORREF fgold, bgold;
- hbmp = CreateBitmap(8, 8, 1, 1, wCheckPat);
- hbr = CreatePatternBrush(hbmp);
- UnrealizeObject(hbr);
- SetBrushOrgEx(hdc, rect->left, rect->top, 0);
- hbrold = (HBRUSH)SelectObject(hdc, hbr);
- fgold = SetTextColor(hdc, fg);
- bgold = SetBkColor(hdc, bg);
-
- PatBlt(hdc, rect->left, rect->top,
- rect->right - rect->left,
- rect->bottom - rect->top,
- PATCOPY);
-
- SetBkColor(hdc, bgold);
- SetTextColor(hdc, fgold);
-
- SelectObject(hdc, hbrold);
- DeleteObject(hbr);
- DeleteObject(hbmp);
- }
- //
- // Fill the specifed rectangle using a solid colour
- //
- static void PaintRect(HDC hdc, RECT *rect, COLORREF color)
- {
- COLORREF oldcol = SetBkColor(hdc, color);
- ExtTextOut(hdc, 0, 0, ETO_OPAQUE, rect, _T(""), 0, 0);
- SetBkColor(hdc, oldcol);
- }
- //
- // Draw a simple blank scrollbar push-button. Can be used
- // to draw a push button, or the scrollbar thumb
- // drawflag - could set to BF_FLAT to make flat scrollbars
- //
- void DrawBlankButton(HDC hdc, const RECT *rect, UINT drawflag)
- {
- RECT rc = *rect;
-
- #ifndef FLAT_SCROLLBARS
- drawflag &= ~BF_FLAT;
- #endif
-
- DrawEdge(hdc, &rc, EDGE_RAISED, BF_RECT | drawflag | BF_ADJUST);
- FillRect(hdc, &rc, GetSysColorBrush(COLOR_BTNFACE));
- }
- //
- // Send a WM_VSCROLL or WM_HSCROLL message
- //
- static void SendScrollMessage(HWND hwnd, UINT scrMsg, UINT scrId, UINT pos)
- {
- SendMessage(hwnd, scrMsg, MAKEWPARAM(scrId, pos), 0);
- }
- //
- // Calculate the screen coordinates of the area taken by
- // the horizontal scrollbar. Take into account the size
- // of the window borders
- //
- static BOOL GetHScrollRect(SCROLLWND *sw, HWND hwnd, RECT *rect)
- {
- GetWindowRect(hwnd, rect);
-
- if(sw->fLeftScrollbar)
- {
- rect->left += sw->cxLeftEdge + (sw->sbarVert.fScrollVisible ?
- GetScrollMetric(&sw->sbarVert, SM_CXVERTSB) : 0);
- rect->right -= sw->cxRightEdge;
- }
- else
- {
- rect->left += sw->cxLeftEdge; //left window edge
-
- rect->right -= sw->cxRightEdge + //right window edge
- (sw->sbarVert.fScrollVisible ?
- GetScrollMetric(&sw->sbarVert, SM_CXVERTSB) : 0);
- }
-
- rect->bottom -= sw->cyBottomEdge; //bottom window edge
-
- rect->top = rect->bottom -
- (sw->sbarHorz.fScrollVisible ?
- GetScrollMetric(&sw->sbarHorz, SM_CYHORZSB) : 0);
-
- return TRUE;
- }
- //
- // Calculate the screen coordinates of the area taken by the
- // vertical scrollbar
- //
- static BOOL GetVScrollRect(SCROLLWND *sw, HWND hwnd, RECT *rect)
- {
- GetWindowRect(hwnd, rect);
- rect->top += sw->cyTopEdge; //top window edge
-
- rect->bottom -= sw->cyBottomEdge +
- (sw->sbarHorz.fScrollVisible ? //bottom window edge
- GetScrollMetric(&sw->sbarHorz, SM_CYHORZSB) : 0);
- if(sw->fLeftScrollbar)
- {
- rect->left += sw->cxLeftEdge;
- rect->right = rect->left + (sw->sbarVert.fScrollVisible ?
- GetScrollMetric(&sw->sbarVert, SM_CXVERTSB) : 0);
- }
- else
- {
- rect->right -= sw->cxRightEdge;
- // rect->left = rect->right - 18;
- rect->left = rect->right - (sw->sbarVert.fScrollVisible ?GetScrollMetric(&sw->sbarVert, SM_CXVERTSB) : 0);
- }
- return TRUE;
- }
- // Depending on what type of scrollbar nBar refers to, call the
- // appropriate Get?ScrollRect function
- //
- BOOL GetScrollRect(SCROLLWND *sw, UINT nBar, HWND hwnd, RECT *rect)
- {
- if(nBar == SB_HORZ)
- return GetHScrollRect(sw, hwnd, rect);
- else if(nBar == SB_VERT)
- return GetVScrollRect(sw, hwnd, rect);
- else
- return FALSE;
- }
- //
- // Work out the scrollbar width/height for either type of scrollbar (SB_HORZ/SB_VERT)
- // rect - coords of the scrollbar.
- // store results into *thumbsize and *thumbpos
- //
- static int CalcThumbSize(SCROLLBAR *sbar, const RECT *rect, int *pthumbsize, int *pthumbpos)
- {
- SCROLLINFO *si;
- int scrollsize; //total size of the scrollbar including arrow buttons
- int workingsize; //working area (where the thumb can slide)
- int siMaxMin;
- int butsize;
- int startcoord;
- int thumbpos = 0, thumbsize = 0;
- int adjust=0;
- static int count=0;
- //work out the width (for a horizontal) or the height (for a vertical)
- //of a standard scrollbar button
- butsize = GetScrollMetric(sbar, SM_SCROLL_LENGTH);
- if(1) //sbar->nBarType == SB_HORZ)
- {
- scrollsize = rect->right - rect->left;
- startcoord = rect->left;
- }
- /*else if(sbar->nBarType == SB_VERT)
- {
- scrollsize = rect->bottom - rect->top;
- startcoord = rect->top;
- }
- else
- {
- return 0;
- }*/
- si = &sbar->scrollInfo;
- siMaxMin = si->nMax - si->nMin + 1;
- workingsize = scrollsize - butsize * 2;
- //
- // Work out the scrollbar thumb SIZE
- //
- if(si->nPage == 0)
- {
- thumbsize = butsize;
- }
- else if(siMaxMin > 0)
- {
- thumbsize = MulDiv(si->nPage, workingsize, siMaxMin);
- if(thumbsize < sbar->nMinThumbSize)
- thumbsize = sbar->nMinThumbSize;
- }
- //
- // Work out the scrollbar thumb position
- //
- if(siMaxMin > 0)
- {
- int pagesize = max(1, si->nPage);
- thumbpos = MulDiv(si->nPos - si->nMin, workingsize-thumbsize, siMaxMin - pagesize);
-
- if(thumbpos < 0)
- thumbpos = 0;
- if(thumbpos >= workingsize-thumbsize)
- thumbpos = workingsize-thumbsize;
- }
- thumbpos += startcoord + butsize;
- *pthumbpos = thumbpos;
- *pthumbsize = thumbsize;
- return 1;
- }
- //
- // return a hit-test value for whatever part of the scrollbar x,y is located in
- // rect, x, y: SCREEN coordinates
- // the rectangle must not include space for any inserted buttons
- // (i.e, JUST the scrollbar area)
- //
- static UINT GetHorzScrollPortion(SCROLLBAR *sbar, HWND hwnd, const RECT *rect, int x, int y)
- {
- int thumbwidth, thumbpos;
- int butwidth = GetScrollMetric(sbar, SM_SCROLL_LENGTH);
- int scrollwidth = rect->right-rect->left;
- int workingwidth = scrollwidth - butwidth*2;
- if(y < rect->top || y >= rect->bottom)
- return HTSCROLL_NONE;
- CalcThumbSize(sbar, rect, &thumbwidth, &thumbpos);
- //if we have had to scale the buttons to fit in the rect,
- //then adjust the button width accordingly
- if(scrollwidth <= butwidth * 2)
- {
- butwidth = scrollwidth / 2;
- }
- //check for left button click
- if(x >= rect->left && x < rect->left + butwidth)
- {
- return HTSCROLL_LEFT;
- }
- //check for right button click
- else if(x >= rect->right-butwidth && x < rect->right)
- {
- return HTSCROLL_RIGHT;
- }
-
- //if the thumb is too big to fit (i.e. it isn't visible)
- //then return a NULL scrollbar area
- if(thumbwidth >= workingwidth)
- return HTSCROLL_NONE;
-
- //check for point in the thumbbar
- if(x >= thumbpos && x < thumbpos+thumbwidth)
- {
- return HTSCROLL_THUMB;
- }
- //check for left margin
- else if(x >= rect->left+butwidth && x < thumbpos)
- {
- return HTSCROLL_PAGELEFT;
- }
- else if(x >= thumbpos+thumbwidth && x < rect->right-butwidth)
- {
- return HTSCROLL_PAGERIGHT;
- }
-
- return HTSCROLL_NONE;
- }
- //
- // For vertical scrollbars, rotate all coordinates by -90 degrees
- // so that we can use the horizontal version of this function
- //
- static UINT GetVertScrollPortion(SCROLLBAR *sb, HWND hwnd, RECT *rect, int x, int y)
- {
- UINT r;
-
- RotateRect(rect);
- r = GetHorzScrollPortion(sb, hwnd, rect, y, x);
- RotateRect(rect);
- return r;
- }
- //
- // CUSTOM DRAW support
- //
- static LRESULT PostCustomPrePostPaint0(HWND hwnd, HDC hdc, SCROLLBAR *sb, UINT dwStage)
- {
- NMCSBCUSTOMDRAW nmcd;
- CoolSB_ZeroMemory(&nmcd, sizeof nmcd);
- nmcd.hdr.hwndFrom = hwnd;
- nmcd.hdr.idFrom = GetWindowLong(hwnd, GWL_ID);
- nmcd.hdr.code = NM_COOLSB_CUSTOMDRAW;
- nmcd.nBar = sb->nBarType;
- nmcd.dwDrawStage = dwStage;
- nmcd.hdc = hdc;
- hwnd = GetParent(hwnd);
- return SendMessage(hwnd, WM_NOTIFY, 0, (LPARAM)&nmcd);
- }
- static LRESULT PostCustomDrawNotify0(HWND hwnd, HDC hdc, UINT nBar, RECT *prect, UINT nItem, BOOL fMouseDown, BOOL fMouseOver, BOOL fInactive)
- {
- NMCSBCUSTOMDRAW nmcd;
- //fill in the standard header
- nmcd.hdr.hwndFrom = hwnd;
- nmcd.hdr.idFrom = GetWindowLong(hwnd, GWL_ID);
- nmcd.hdr.code = NM_COOLSB_CUSTOMDRAW;
- nmcd.dwDrawStage = CDDS_ITEMPREPAINT;
- nmcd.nBar = nBar;
- nmcd.rect = *prect;
- nmcd.uItem = nItem;
- nmcd.hdc = hdc;
- if(fMouseDown)
- nmcd.uState = CDIS_SELECTED;
- else if(fMouseOver)
- nmcd.uState = CDIS_HOT;
- else if(fInactive)
- nmcd.uState = CDIS_DISABLED;
- else
- nmcd.uState = CDIS_DEFAULT;
- hwnd = GetParent(hwnd);
- return SendMessage(hwnd, WM_NOTIFY, nmcd.hdr.idFrom, (LPARAM)&nmcd);
- }
- // Depending on if we are supporting custom draw, either define
- // a macro to the function name, or to nothing at all. If custom draw
- // is turned off, then we can save ALOT of code space by binning all
- // calls to the custom draw support.
- //
- #define PostCustomDrawNotify PostCustomDrawNotify0
- #define PostCustomPrePostPaint PostCustomPrePostPaint0
- static LRESULT PostMouseNotify0(HWND hwnd, UINT msg, UINT nBar, RECT *prect, UINT nCmdId, POINT pt)
- {
- #ifdef NOTIFY_MOUSE
- NMCOOLBUTMSG nmcb;
- //fill in the standard header
- nmcb.hdr.hwndFrom = hwnd;
- nmcb.hdr.idFrom = GetWindowLong(hwnd, GWL_ID);
- nmcb.hdr.code = NM_CLICK;
- nmcb.nBar = nBar;
- nmcb.uCmdId = nCmdId;
- nmcb.uState = 0;
- nmcb.rect = *prect;
- nmcb.pt = pt;
- hwnd = GetParent(hwnd);
- return SendMessage(hwnd, WM_NOTIFY, nmcb.hdr.idFrom, (LPARAM)&nmcb);
- #else
- return 0;
- #endif
- }
- #ifdef NOTIFY_MOUSE
- #define PostMouseNotify PostMouseNotify0
- #else
- #define PostMouseNotify 1 ? (void)0 : PostMouseNotify0
- #endif
- //
- // Draw a complete HORIZONTAL scrollbar in the given rectangle
- // Don't draw any inserted buttons in this procedure
- //
- // uDrawFlags - hittest code, to say if to draw the
- // specified portion in an active state or not.
- //
- //
- static LRESULT NCDrawHScrollbar(SCROLLBAR *sb, HWND hwnd, HDC hdc, const RECT *rect, UINT uDrawFlags)
- {
- SCROLLINFO *si;
- RECT ctrl, thumb;
- RECT sbm;
- int butwidth = GetScrollMetric(sb, SM_SCROLL_LENGTH);
- int scrollwidth = rect->right-rect->left;
- int workingwidth = scrollwidth - butwidth*2;
- int thumbwidth = 0, thumbpos = 0;
- int siMaxMin;
- BOOL fCustomDraw = 0;
- BOOL fMouseDownL = 0, fMouseOverL = 0, fBarHot = 0;
- BOOL fMouseDownR = 0, fMouseOverR = 0;
- COLORREF crCheck1 = GetSBForeColor();
- COLORREF crCheck2 = GetSBBackColor();
- COLORREF crInverse1 = InvertCOLORREF(crCheck1);
- COLORREF crInverse2 = InvertCOLORREF(crCheck2);
- UINT uDFCFlat = sb->fFlatScrollbar ? DFCS_FLAT : 0;
- UINT uDEFlat = sb->fFlatScrollbar ? BF_FLAT : 0;
- //drawing flags to modify the appearance of the scrollbar buttons
- UINT uLeftButFlags = DFCS_SCROLLLEFT;
- UINT uRightButFlags = DFCS_SCROLLRIGHT;
- if(scrollwidth <= 0)
- return 0;
- si = &sb->scrollInfo;
- siMaxMin = si->nMax - si->nMin;
- if(hwnd != hwndCurCoolSB)
- uDrawFlags = HTSCROLL_NONE;
- //
- // work out the thumb size and position
- //
- CalcThumbSize(sb, rect, &thumbwidth, &thumbpos);
-
- if(sb->fScrollFlags & ESB_DISABLE_LEFT) uLeftButFlags |= DFCS_INACTIVE;
- if(sb->fScrollFlags & ESB_DISABLE_RIGHT) uRightButFlags |= DFCS_INACTIVE;
- //if we need to grey the arrows because there is no data to scroll
- if(!IsScrollInfoActive(si) && !(sb->fScrollFlags & CSBS_THUMBALWAYS))
- {
- uLeftButFlags |= DFCS_INACTIVE;
- uRightButFlags |= DFCS_INACTIVE;
- }
- if(hwnd == hwndCurCoolSB)
- {
- #ifdef FLAT_SCROLLBARS
- BOOL ldis = !(uLeftButFlags & DFCS_INACTIVE);
- BOOL rdis = !(uRightButFlags & DFCS_INACTIVE);
- fBarHot = (sb->nBarType == (int)uMouseOverScrollbar && sb->fFlatScrollbar == CSBS_HOTTRACKED);
-
- fMouseOverL = uHitTestPortion == HTSCROLL_LEFT && fBarHot && ldis;
- fMouseOverR = uHitTestPortion == HTSCROLL_RIGHT && fBarHot && rdis;
- #endif
- fMouseDownL = (uDrawFlags == HTSCROLL_LEFT);
- fMouseDownR = (uDrawFlags == HTSCROLL_RIGHT);
- }
- #ifdef CUSTOM_DRAW
- fCustomDraw = ((PostCustomPrePostPaint(hwnd, hdc, sb, CDDS_PREPAINT)) == CDRF_SKIPDEFAULT);
- #endif
- //
- // Draw the scrollbar now
- //
- if(scrollwidth > butwidth*2)
- {
- //LEFT ARROW
- SetRect(&ctrl, rect->left, rect->top, rect->left + butwidth, rect->bottom);
- RotateRect0(sb, &ctrl);
- if(fCustomDraw)
- PostCustomDrawNotify(hwnd, hdc, sb->nBarType, &ctrl, SB_LINELEFT, fMouseDownL, fMouseOverL, uLeftButFlags & DFCS_INACTIVE);
- else
- DrawScrollArrow(sb, hdc, &ctrl, uLeftButFlags, fMouseDownL, fMouseOverL);
- RotateRect0(sb, &ctrl);
- //MIDDLE PORTION
- //if we can fit the thumbbar in, then draw it
- if(thumbwidth > 0 && thumbwidth <= workingwidth
- && IsScrollInfoActive(si) && ((sb->fScrollFlags & ESB_DISABLE_BOTH) != ESB_DISABLE_BOTH))
- {
- //Draw the scrollbar margin above the thumb
- SetRect(&sbm, rect->left + butwidth, rect->top, thumbpos, rect->bottom);
-
- RotateRect0(sb, &sbm);
-
- if(fCustomDraw)
- {
- PostCustomDrawNotify(hwnd, hdc, sb->nBarType, &sbm, SB_PAGELEFT, uDrawFlags == HTSCROLL_PAGELEFT, FALSE, FALSE);
- }
- else
- {
- if(uDrawFlags == HTSCROLL_PAGELEFT)
- DrawCheckedRect(hdc, &sbm, crInverse1, crInverse2);
- else
- DrawCheckedRect(hdc, &sbm, crCheck1, crCheck2);
- }
- RotateRect0(sb, &sbm);
-
- //Draw the margin below the thumb
- sbm.left = thumbpos+thumbwidth;
- sbm.right = rect->right - butwidth;
-
- RotateRect0(sb, &sbm);
- if(fCustomDraw)
- {
- PostCustomDrawNotify(hwnd, hdc, sb->nBarType, &sbm, SB_PAGERIGHT, uDrawFlags == HTSCROLL_PAGERIGHT, 0, 0);
- }
- else
- {
- if(uDrawFlags == HTSCROLL_PAGERIGHT)
- DrawCheckedRect(hdc, &sbm, crInverse1, crInverse2);
- else
- DrawCheckedRect(hdc, &sbm, crCheck1, crCheck2);
-
- }
- RotateRect0(sb, &sbm);
-
- //Draw the THUMB finally
- SetRect(&thumb, thumbpos, rect->top, thumbpos+thumbwidth, rect->bottom);
- RotateRect0(sb, &thumb);
- if(fCustomDraw)
- {
- PostCustomDrawNotify(hwnd, hdc, sb->nBarType, &thumb, SB_THUMBTRACK, uDrawFlags==HTSCROLL_THUMB, uHitTestPortion == HTSCROLL_THUMB && fBarHot, FALSE);
- }
- else
- {
- #ifdef FLAT_SCROLLBARS
- if(hwnd == hwndCurCoolSB && sb->fFlatScrollbar && (uDrawFlags == HTSCROLL_THUMB ||
- (uHitTestPortion == HTSCROLL_THUMB && fBarHot)))
- {
- PaintRect(hdc, &thumb, GetSysColor(COLOR_3DSHADOW));
- }
- else
- #endif
- {
- DrawBlankButton(hdc, &thumb, uDEFlat);
- }
- }
- RotateRect0(sb, &thumb);
- }
- //otherwise, just leave that whole area blank
- else
- {
- OffsetRect(&ctrl, butwidth, 0);
- ctrl.right = rect->right - butwidth;
- //if we always show the thumb covering the whole scrollbar,
- //then draw it that way
- if(!IsScrollInfoActive(si) && (sb->fScrollFlags & CSBS_THUMBALWAYS)
- && ctrl.right - ctrl.left > sb->nMinThumbSize)
- {
- //leave a 1-pixel gap between the thumb + right button
- ctrl.right --;
- RotateRect0(sb, &ctrl);
- if(fCustomDraw)
- PostCustomDrawNotify(hwnd, hdc, sb->nBarType, &ctrl, SB_THUMBTRACK, fMouseDownL, FALSE, FALSE);
- else
- {
- #ifdef FLAT_SCROLLBARS
- if(sb->fFlatScrollbar == CSBS_HOTTRACKED && uDrawFlags == HTSCROLL_THUMB)
- PaintRect(hdc, &ctrl, GetSysColor(COLOR_3DSHADOW));
- else
- #endif
- DrawBlankButton(hdc, &ctrl, uDEFlat);
- }
- RotateRect0(sb, &ctrl);
- //draw the single-line gap
- ctrl.left = ctrl.right;
- ctrl.right += 1;
-
- RotateRect0(sb, &ctrl);
-
- if(fCustomDraw)
- PostCustomDrawNotify(hwnd, hdc, sb->nBarType, &ctrl, SB_PAGERIGHT, 0, 0, 0);
- else
- PaintRect(hdc, &ctrl, GetSysColor(COLOR_SCROLLBAR));
- RotateRect0(sb, &ctrl);
- }
- //otherwise, paint a blank if the thumb doesn't fit in
- else
- {
- RotateRect0(sb, &ctrl);
-
- if(fCustomDraw)
- PostCustomDrawNotify(hwnd, hdc, sb->nBarType, &ctrl, SB_PAGERIGHT, 0, 0, 0);
- else
- DrawCheckedRect(hdc, &ctrl, crCheck1, crCheck2);
-
- RotateRect0(sb, &ctrl);
- }
- }
- //RIGHT ARROW
- SetRect(&ctrl, rect->right - butwidth, rect->top, rect->right, rect->bottom);
- RotateRect0(sb, &ctrl);
- if(fCustomDraw)
- PostCustomDrawNotify(hwnd, hdc, sb->nBarType, &ctrl, SB_LINERIGHT, fMouseDownR, fMouseOverR, uRightButFlags & DFCS_INACTIVE);
- else
- DrawScrollArrow(sb, hdc, &ctrl, uRightButFlags, fMouseDownR, fMouseOverR);
- RotateRect0(sb, &ctrl);
- }
- //not enough room for the scrollbar, so just draw the buttons (scaled in size to fit)
- else
- {
- butwidth = scrollwidth / 2;
- //LEFT ARROW
- SetRect(&ctrl, rect->left, rect->top, rect->left + butwidth, rect->bottom);
- RotateRect0(sb, &ctrl);
- if(fCustomDraw)
- PostCustomDrawNotify(hwnd, hdc, sb->nBarType, &ctrl, SB_LINELEFT, fMouseDownL, fMouseOverL, uLeftButFlags & DFCS_INACTIVE);
- else
- DrawScrollArrow(sb, hdc, &ctrl, uLeftButFlags, fMouseDownL, fMouseOverL);
- RotateRect0(sb, &ctrl);
- //RIGHT ARROW
- OffsetRect(&ctrl, scrollwidth - butwidth, 0);
-
- RotateRect0(sb, &ctrl);
- if(fCustomDraw)
- PostCustomDrawNotify(hwnd, hdc, sb->nBarType, &ctrl, SB_LINERIGHT, fMouseDownR, fMouseOverR, uRightButFlags & DFCS_INACTIVE);
- else
- DrawScrollArrow(sb, hdc, &ctrl, uRightButFlags, fMouseDownR, fMouseOverR);
- RotateRect0(sb, &ctrl);
- //if there is a gap between the buttons, fill it with a solid color
- //if(butwidth & 0x0001)
- if(ctrl.left != rect->left + butwidth)
- {
- ctrl.left --;
- ctrl.right -= butwidth;
- RotateRect0(sb, &ctrl);
-
- if(fCustomDraw)
- PostCustomDrawNotify(hwnd, hdc, sb->nBarType, &ctrl, SB_PAGERIGHT, 0, 0, 0);
- else
- DrawCheckedRect(hdc, &ctrl, crCheck1, crCheck2);
- RotateRect0(sb, &ctrl);
- }
-
- }
- #ifdef CUSTOM_DRAW
- PostCustomPrePostPaint(hwnd, hdc, sb, CDDS_POSTPAINT);
- #endif
- return fCustomDraw;
- }
- //
- // Draw a vertical scrollbar using the horizontal draw routine, but
- // with the coordinates adjusted accordingly
- //
- static LRESULT NCDrawVScrollbar(SCROLLBAR *sb, HWND hwnd, HDC hdc, const RECT *rect, UINT uDrawFlags)
- {
- LRESULT ret;
- RECT rc;
- rc = *rect;
- RotateRect(&rc);
- ret = NCDrawHScrollbar(sb, hwnd, hdc, &rc, uDrawFlags);
- RotateRect(&rc);
-
- return ret;
- }
- //
- // Generic wrapper function for the scrollbar drawing
- //
- static LRESULT NCDrawScrollbar(SCROLLBAR *sb, HWND hwnd, HDC hdc, const RECT *rect, UINT uDrawFlags)
- {
- if(sb->nBarType == SB_HORZ)
- return NCDrawHScrollbar(sb, hwnd, hdc, rect, uDrawFlags);
- else
- return NCDrawVScrollbar(sb, hwnd, hdc, rect, uDrawFlags);
- }
- //
- // Define these two for proper processing of NCPAINT
- // NOT needed if we don't bother to mask the scrollbars we draw
- // to prevent the old window procedure from accidently drawing over them
- //
- HDC CoolSB_GetDC(HWND hwnd, WPARAM wParam)
- {
- // I just can't figure out GetDCEx, so I'll just use this:
- return GetWindowDC(hwnd);
- /*
- RECT rc;
- DWORD flags = 0x10000;
- HRGN hrgn = (HRGN)wParam;
- if(hrgn == (HRGN)1)
- {
- GetWindowRect(hwnd, &rc);
- OffsetRect(&rc, -rc.left, -rc.top);
- hrgn = CreateRectRgnIndirect(&rc);
- }
- if(GetWindowLong(hwnd, GWL_STYLE) & WS_CLIPCHILDREN)
- flags |= DCX_CLIPCHILDREN;
- if(GetWindowLong(hwnd, GWL_STYLE) & WS_CLIPSIBLINGS)
- flags |= DCX_CLIPSIBLINGS;
- return GetDCEx(hwnd, hrgn, flags | DCX_CACHE|DCX_NORESETATTRS|DCX_WINDOW | DCX_INTERSECTUPDATE);
- */
- //return GetDCEx(hwnd, NULL, flags | DCX_WINDOW| DCX_NORESETATTRS);
- }
- static void NCPaint(SCROLLWND *sw, HWND hwnd, WPARAM wParam, LPARAM lParam)
- {
- SCROLLBAR *sb;
- HDC hdc;
- HRGN hrgn;
- RECT winrect, rect;
- BOOL fUpdateAll = ((LONG)wParam == 1);
- BOOL fCustomDraw = FALSE;
- GetWindowRect(hwnd, &winrect);
- int aaa=GetSystemMetrics(SM_CXVSCROLL);
- //if entire region needs painting, then make a region to cover the entire window
- if(fUpdateAll)
- hrgn = (HRGN)wParam;
- else
- hrgn = (HRGN)wParam;
-
- //hdc = GetWindowDC(hwnd);
- hdc = CoolSB_GetDC(hwnd, wParam);
- ///////////////////////////////////////////////////
- CRect rcItem;
- GetWindowRect(hwnd, &rcItem);
- rcItem.right -=rcItem.left ;
- rcItem.bottom -=rcItem.top ;
- rcItem.left =rcItem.top =0;
- ::FrameRect(hdc, rcItem, g_frameedgebrush);
- InflateRect(&rcItem, -1, -1);
- FrameRect(hdc, &rcItem, (HBRUSH) ::GetStockObject (WHITE_BRUSH));
- ////////////////////////////////////////////////////////////////////////////
- //
- // Only draw the horizontal scrollbar if the window is tall enough
- //
- sb = &sw->sbarHorz;
- if(sb->fScrollVisible)
- {
- int hbarwidth = 0, leftright = 0;
- //get the screen coordinates of the whole horizontal scrollbar area
- GetHScrollRect(sw, hwnd, &rect);
- //make the coordinates relative to the window for drawing
- OffsetRect(&rect, -winrect.left, -winrect.top);
- if(uCurrentScrollbar == SB_HORZ)
- fCustomDraw |= NCDrawHScrollbar(sb, hwnd, hdc, &rect, uScrollTimerPortion);
- else
- fCustomDraw |= NCDrawHScrollbar(sb, hwnd, hdc, &rect, HTSCROLL_NONE);
- }
- //
- // Only draw the vertical scrollbar if the window is wide enough to accomodate it
- //
- sb = &sw->sbarVert;
- if(sb->fScrollVisible)
- {
- int vbarheight = 0, updown = 0;
- //get the screen cooridinates of the whole horizontal scrollbar area
- GetVScrollRect(sw, hwnd, &rect);
- //make the coordinates relative to the window for drawing
- OffsetRect(&rect, -winrect.left, -winrect.top);
- if(uCurrentScrollbar == SB_VERT)
- fCustomDraw |= NCDrawVScrollbar(sb, hwnd, hdc, &rect, uScrollTimerPortion);
- else
- fCustomDraw |= NCDrawVScrollbar(sb, hwnd, hdc, &rect, HTSCROLL_NONE);
- }
- // DRAW THE DEAD AREA
- // only do this if the horizontal and vertical bars are visible
- if(sw->sbarHorz.fScrollVisible && sw->sbarVert.fScrollVisible)
- {
- GetWindowRect(hwnd, &rect);
- OffsetRect(&rect, -winrect.left, -winrect.top);
- rect.bottom -= sw->cyBottomEdge;
- rect.top = rect.bottom - GetScrollMetric(&sw->sbarHorz, SM_CYHORZSB);
- if(sw->fLeftScrollbar)
- {
- rect.left += sw->cxLeftEdge;
- rect.right = rect.left + GetScrollMetric(&sw->sbarVert, SM_CXVERTSB);
- }
- else
- {
- rect.right -= sw->cxRightEdge;
- rect.left = rect.right - GetScrollMetric(&sw->sbarVert, SM_CXVERTSB);
- }
-
- PostCustomDrawNotify(hwnd, hdc, SB_BOTH, &rect, 32, 0, 0, 0);
-
- }
- ReleaseDC(hwnd, hdc);
- }
- //
- // Need to detect if we have clicked in the scrollbar region or not
- //
- static LRESULT NCHitTest(SCROLLWND *sw, HWND hwnd, WPARAM wParam, LPARAM lParam)
- {
- RECT hrect;
- RECT vrect;
- POINT pt;
- pt.x = LOWORD(lParam);
- pt.y = HIWORD(lParam);
-
- //work out exactly where the Horizontal and Vertical scrollbars are
- GetHScrollRect(sw, hwnd, &hrect);
- GetVScrollRect(sw, hwnd, &vrect);
-
- //Clicked in the horizontal scrollbar area
- if(sw->sbarHorz.fScrollVisible && PtInRect(&hrect, pt))
- {
- return HTHSCROLL;
- }
- //Clicked in the vertical scrollbar area
- else if(sw->sbarVert.fScrollVisible && PtInRect(&vrect, pt))
- {
- return HTVSCROLL;
- }
- //clicked somewhere else
- else
- {
- return CallWindowProc(sw->oldproc, hwnd, WM_NCHITTEST, wParam, lParam);
- }
- }
- //
- // Return a HT* value indicating what part of the scrollbar was clicked
- // Rectangle is not adjusted
- //
- static UINT GetHorzPortion(SCROLLBAR *sb, HWND hwnd, RECT *rect, int x, int y)
- {
- RECT rc = *rect;
- if(y < rc.top || y >= rc.bottom) return HTSCROLL_NONE;
- //Now we have the rectangle for the scrollbar itself, so work out
- //what part we clicked on.
- return GetHorzScrollPortion(sb, hwnd, &rc, x, y);
- }
- //
- // Just call the horizontal version, with adjusted coordinates
- //
- static UINT GetVertPortion(SCROLLBAR *sb, HWND hwnd, RECT *rect, int x, int y)
- {
- UINT ret;
- RotateRect(rect);
- ret = GetHorzPortion(sb, hwnd, rect, y, x);
- RotateRect(rect);
- return ret;
- }
- //
- // Wrapper function for GetHorzPortion and GetVertPortion
- //
- static UINT GetPortion(SCROLLBAR *sb, HWND hwnd, RECT *rect, int x, int y)
- {
- if(sb->nBarType == SB_HORZ)
- return GetHorzPortion(sb, hwnd, rect, x, y);
- else if(sb->nBarType == SB_VERT)
- return GetVertPortion(sb, hwnd, rect, x, y);
- else
- return HTSCROLL_NONE;
- }
- //
- // Input: rectangle of the total scrollbar area
- // Output: adjusted to take the inserted buttons into account
- //
- static void GetRealHorzScrollRect(SCROLLBAR *sb, RECT *rect)
- {
- if(sb->fButVisibleBefore) rect->left += sb->nButSizeBefore;
- if(sb->fButVisibleAfter) rect->right -= sb->nButSizeAfter;
- }
- //
- // Input: rectangle of the total scrollbar area
- // Output: adjusted to take the inserted buttons into account
- //
- static void GetRealVertScrollRect(SCROLLBAR *sb, RECT *rect)
- {
- if(sb->fButVisibleBefore) rect->top += sb->nButSizeBefore;
- if(sb->fButVisibleAfter) rect->bottom -= sb->nButSizeAfter;
- }
- //
- // Decide which type of scrollbar we have before calling
- // the real function to do the job
- //
- static void GetRealScrollRect(SCROLLBAR *sb, RECT *rect)
- {
- if(sb->nBarType == SB_HORZ)
- {
- GetRealHorzScrollRect(sb, rect);
- }
- else if(sb->nBarType == SB_VERT)
- {
- GetRealVertScrollRect(sb, rect);
- }
- }
- //
- // Left button click in the non-client area
- //
- static LRESULT NCLButtonDown(SCROLLWND *sw, HWND hwnd, WPARAM wParam, LPARAM lParam)
- {
- RECT rect, winrect;
- HDC hdc;
- SCROLLBAR *sb;
- SCROLLBUT *sbut = 0;
- POINT pt;
- pt.x = LOWORD(lParam);
- pt.y = HIWORD(lParam);
- hwndCurCoolSB = hwnd;
- /////////////////////////////////////////////////////////////////////////////////
- //
- // HORIZONTAL SCROLLBAR PROCESSING
- //
- if(wParam == HTHSCROLL)
- {
- uScrollTimerMsg = WM_HSCROLL;
- uCurrentScrollbar = SB_HORZ;
- sb = &sw->sbarHorz;
- //get the total area of the normal Horz scrollbar area
- GetHScrollRect(sw, hwnd, &rect);
- uCurrentScrollPortion = GetHorzPortion(sb, hwnd, &rect, LOWORD(lParam), HIWORD(lParam));
- }
- //
- // VERTICAL SCROLLBAR PROCESSING
- //
- else if(wParam == HTVSCROLL)
- {
- uScrollTimerMsg = WM_VSCROLL;
- uCurrentScrollbar = SB_VERT;
- sb = &sw->sbarVert;
- //get the total area of the normal Horz scrollbar area
- GetVScrollRect(sw, hwnd, &rect);
- uCurrentScrollPortion = GetVertPortion(sb, hwnd, &rect, LOWORD(lParam), HIWORD(lParam));
- }
- //
- // NORMAL PROCESSING
- //
- else
- {
- uCurrentScrollPortion = HTSCROLL_NONE;
- return CallWindowProc(sw->oldproc, hwnd, WM_NCLBUTTONDOWN, wParam, lParam);
- }
- //
- // we can now share the same code for vertical
- // and horizontal scrollbars
- //
- switch(uCurrentScrollPortion)
- {
- case HTSCROLL_THUMB:
- //if the scrollbar is disabled, then do no further processing
- if(!IsScrollbarActive(sb))
- return 0;
-
- GetRealScrollRect(sb, &rect);
- RotateRect0(sb, &rect);
- CalcThumbSize(sb, &rect, &nThumbSize, &nThumbPos);
- RotateRect0(sb, &rect);
-
- //remember the bounding rectangle of the scrollbar work area
- rcThumbBounds = rect;
-
- sw->fThumbTracking = TRUE;
- sb->scrollInfo.nTrackPos = sb->scrollInfo.nPos;
-
- if(wParam == HTVSCROLL)
- nThumbMouseOffset = pt.y - nThumbPos;
- else
- nThumbMouseOffset = pt.x - nThumbPos;
- nLastPos = -sb->scrollInfo.nPos;
- nThumbPos0 = nThumbPos;
-
- //if(sb->fFlatScrollbar)
- //{
- GetWindowRect(hwnd, &winrect);
- OffsetRect(&rect, -winrect.left, -winrect.top);
- hdc = GetWindowDC(hwnd);
- NCDrawScrollbar(sb, hwnd, hdc, &rect, HTSCROLL_THUMB);
- ReleaseDC(hwnd, hdc);
- //}
- break;
- //Any part of the scrollbar
- case HTSCROLL_LEFT:
- if(sb->fScrollFlags & ESB_DISABLE_LEFT) return 0;
- else goto target1;
-
- case HTSCROLL_RIGHT:
- if(sb->fScrollFlags & ESB_DISABLE_RIGHT) return 0;
- else goto target1;
- goto target1;
- case HTSCROLL_PAGELEFT: case HTSCROLL_PAGERIGHT:
- target1:
- //if the scrollbar is disabled, then do no further processing
- if(!IsScrollbarActive(sb))
- break;
- //ajust the horizontal rectangle to NOT include
- //any inserted buttons
- GetRealScrollRect(sb, &rect);
- SendScrollMessage(hwnd, uScrollTimerMsg, uCurrentScrollPortion, 0);
- // Check what area the mouse is now over :
- // If the scroll thumb has moved under the mouse in response to
- // a call to SetScrollPos etc, then we don't hilight the scrollbar margin
- if(uCurrentScrollbar == SB_HORZ)
- uScrollTimerPortion = GetHorzScrollPortion(sb, hwnd, &rect, pt.x, pt.y);
- else
- uScrollTimerPortion = GetVertScrollPortion(sb, hwnd, &rect, pt.x, pt.y);
- GetWindowRect(hwnd, &winrect);
- OffsetRect(&rect, -winrect.left, -winrect.top);
- hdc = GetWindowDC(hwnd);
-
- #ifndef HOT_TRACKING
- //if we aren't hot-tracking, then don't highlight
- //the scrollbar thumb unless we click on it
- if(uScrollTimerPortion == HTSCROLL_THUMB)
- uScrollTimerPortion = HTSCROLL_NONE;
- #endif
- NCDrawScrollbar(sb, hwnd, hdc, &rect, uScrollTimerPortion);
- ReleaseDC(hwnd, hdc);
- //Post the scroll message!!!!
- uScrollTimerPortion = uCurrentScrollPortion;
- //set a timer going on the first click.
- //if this one expires, then we can start off a more regular timer
- //to generate the auto-scroll behaviour
- uScrollTimerId = SetTimer(hwnd, COOLSB_TIMERID1, COOLSB_TIMERINTERVAL1, 0);
- break;
- default:
- return CallWindowProc(sw->oldproc, hwnd, WM_NCLBUTTONDOWN, wParam, lParam);
- //return 0;
- }
-
- SetCapture(hwnd);
- return 0;
- }
- //
- // Left button released
- //
- static LRESULT LButtonUp(SCROLLWND *sw, HWND hwnd, WPARAM wParam, LPARAM lParam)
- {
- RECT rect;
- //UINT thisportion;
- HDC hdc;
- POINT pt;
- RECT winrect;
- UINT buttonIdx = 0;
-
- //current scrollportion is the button that we clicked down on
- if(uCurrentScrollPortion != HTSCROLL_NONE)
- {
- SCROLLBAR *sb = &sw->sbarHorz;
- lParam = GetMessagePos();
- ReleaseCapture();
- GetWindowRect(hwnd, &winrect);
- pt.x = LOWORD(lParam);
- pt.y = HIWORD(lParam);
- //emulate the mouse input on a scrollbar here...
- if(uCurrentScrollbar == SB_HORZ)
- {
- //get the total area of the normal Horz scrollbar area
- sb = &sw->sbarHorz;
- GetHScrollRect(sw, hwnd, &rect);
- }
- else if(uCurrentScrollbar == SB_VERT)
- {
- //get the total area of the normal Horz scrollbar area
- sb = &sw->sbarVert;
- GetVScrollRect(sw, hwnd, &rect);
- }
- //we need to do different things depending on if the
- //user is activating the scrollbar itself, or one of
- //the inserted buttons
- switch(uCurrentScrollPortion)
- {
- //The scrollbar is active
- case HTSCROLL_LEFT: case HTSCROLL_RIGHT:
- case HTSCROLL_PAGELEFT: case HTSCROLL_PAGERIGHT:
- case HTSCROLL_NONE:
-
- KillTimer(hwnd, uScrollTimerId);
- case HTSCROLL_THUMB:
-
- //In case we were thumb tracking, make sure we stop NOW
- if(sw->fThumbTracking == TRUE)
- {
- SendScrollMessage(hwnd, uScrollTimerMsg, SB_THUMBPOSITION, nLastPos);
- sw->fThumbTracking = FALSE;
- }
- //send the SB_ENDSCROLL message now that scrolling has finished
- SendScrollMessage(hwnd, uScrollTimerMsg, SB_ENDSCROLL, 0);
- //adjust the total scroll area to become where the scrollbar
- //really is (take into account the inserted buttons)
- GetRealScrollRect(sb, &rect);
- OffsetRect(&rect, -winrect.left, -winrect.top);
- hdc = GetWindowDC(hwnd);
-
- //draw whichever scrollbar sb is
- NCDrawScrollbar(sb, hwnd, hdc, &rect, HTSCROLL_NORMAL);
- ReleaseDC(hwnd, hdc);
- break;
- }
- //reset our state to default
- uCurrentScrollPortion = HTSCROLL_NONE;
- uScrollTimerPortion = HTSCROLL_NONE;
- uScrollTimerId = 0;
- uScrollTimerMsg = 0;
- uCurrentScrollbar = COOLSB_NONE;
- return 0;
- }
- else
- {
- /*
- // Can't remember why I did this!
- if(GetCapture() == hwnd)
- {
- ReleaseCapture();
- }*/
- }
- return CallWindowProc(sw->oldproc, hwnd, WM_LBUTTONUP, wParam, lParam);
- }
- //
- // This function is called whenever the mouse is moved and
- // we are dragging the scrollbar thumb about.
- //
- static LRESULT ThumbTrackHorz(SCROLLBAR *sbar, HWND hwnd, int x, int y)
- {
- POINT pt;
- RECT rc, winrect, rc2;
- COLORREF crCheck1 = GetSBForeColor();
- COLORREF crCheck2 = GetSBBackColor();
- HDC hdc;
- int thumbpos = nThumbPos;
- int pos;
- int siMaxMin = 0;
- UINT flatflag = sbar->fFlatScrollbar ? BF_FLAT : 0;
- BOOL fCustomDraw = FALSE;
- SCROLLINFO *si;
- si = &sbar->scrollInfo;
- pt.x = x;
- pt.y = y;
- //draw the thumb at whatever position
- rc = rcThumbBounds;
- SetRect(&rc2, rc.left - THUMBTRACK_SNAPDIST*2, rc.top - THUMBTRACK_SNAPDIST,
- rc.right + THUMBTRACK_SNAPDIST*2, rc.bottom + THUMBTRACK_SNAPDIST);
- rc.left += GetScrollMetric(sbar, SM_CXHORZSB);
- rc.right -= GetScrollMetric(sbar, SM_CXHORZSB);
- //if the mouse is not in a suitable distance of the scrollbar,
- //then "snap" the thumb back to its initial position
- #ifdef SNAP_THUMB_BACK
- if(!PtInRect(&rc2, pt))
- {
- thumbpos = nThumbPos0;
- }
- //otherwise, move the thumb to where the mouse is
- else
- #endif //SNAP_THUMB_BACK
- {
- //keep the thumb within the scrollbar limits
- thumbpos = pt.x - nThumbMouseOffset;
- if(thumbpos < rc.left) thumbpos = rc.left;
- if(thumbpos > rc.right - nThumbSize) thumbpos = rc.right - nThumbSize;
- }
- GetWindowRect(hwnd, &winrect);
- if(sbar->nBarType == SB_VERT)
- RotateRect(&winrect);
-
- hdc = GetWindowDC(hwnd);
-
- #ifdef CUSTOM_DRAW
- fCustomDraw = PostCustomPrePostPaint(hwnd, hdc, sbar, CDDS_PREPAINT) == CDRF_SKIPDEFAULT;
- #endif
- OffsetRect(&rc, -winrect.left, -winrect.top);
- thumbpos -= winrect.left;
- //draw the margin before the thumb
- SetRect(&rc2, rc.left, rc.top, thumbpos, rc.bottom);
- RotateRect0(sbar, &rc2);
- if(fCustomDraw)
- PostCustomDrawNotify(hwnd, hdc, sbar->nBarType, &rc2, SB_PAGELEFT, 0, 0, 0);
- else
- DrawCheckedRect(hdc, &rc2, crCheck1, crCheck2);
-
- RotateRect0(sbar, &rc2);
- //draw the margin after the thumb
- SetRect(&rc2, thumbpos+nThumbSize, rc.top, rc.right, rc.bottom);
-
- RotateRect0(sbar, &rc2);
-
- if(fCustomDraw)
- PostCustomDrawNotify(hwnd, hdc, sbar->nBarType, &rc2, SB_PAGERIGHT, 0, 0, 0);
- else
- DrawCheckedRect(hdc, &rc2, crCheck1, crCheck2);
-
- RotateRect0(sbar, &rc2);
-
- //finally draw the thumb itelf. This is how it looks on win2000, anyway
- SetRect(&rc2, thumbpos, rc.top, thumbpos+nThumbSize, rc.bottom);
-
- RotateRect0(sbar, &rc2);
- if(fCustomDraw)
- PostCustomDrawNotify(hwnd, hdc, sbar->nBarType, &rc2, SB_THUMBTRACK, TRUE, TRUE, FALSE);
- else
- {
- #ifdef FLAT_SCROLLBARS
- if(sbar->fFlatScrollbar)
- PaintRect(hdc, &rc2, GetSysColor(COLOR_3DSHADOW));
- else
- #endif
- {
- DrawBlankButton(hdc, &rc2, flatflag);
- }
- }
- RotateRect0(sbar, &rc2);
- ReleaseDC(hwnd, hdc);
- //post a SB_TRACKPOS message!!!
- siMaxMin = si->nMax - si->nMin;
- if(siMaxMin > 0)
- pos = MulDiv(thumbpos-rc.left, siMaxMin-si->nPage + 1, rc.right-rc.left-nThumbSize);
- else
- pos = thumbpos - rc.left;
- if(pos != nLastPos)
- {
- si->nTrackPos = pos;
- SendScrollMessage(hwnd, uScrollTimerMsg, SB_THUMBTRACK, pos);
- }
- nLastPos = pos;
- #ifdef CUSTOM_DRAW
- PostCustomPrePostPaint(hwnd, hdc, sbar, CDDS_POSTPAINT);
- #endif
-
- return 0;
- }
- //
- // remember to rotate the thumb bounds rectangle!!
- //
- static LRESULT ThumbTrackVert(SCROLLBAR *sb, HWND hwnd, int x, int y)
- {
- //sw->swapcoords = TRUE;
- RotateRect(&rcThumbBounds);
- ThumbTrackHorz(sb, hwnd, y, x);
- RotateRect(&rcThumbBounds);
- //sw->swapcoords = FALSE;
- return 0;
- }
- //
- // Called when we have set the capture from the NCLButtonDown(...)
- //
- static LRESULT MouseMove(SCROLLWND *sw, HWND hwnd, WPARAM wParam, LPARAM lParam)
- {
- RECT rect;
- UINT thisportion;
- HDC hdc;
- static UINT lastportion = 0;
- static UINT lastbutton = 0;
- POINT pt;
- RECT winrect;
- UINT buttonIdx = 0;
- if(sw->fThumbTracking == TRUE)
- {
- int x, y;
- lParam = GetMessagePos();
- x = LOWORD(lParam);
- y = HIWORD(lParam);
- if(uCurrentScrollbar == SB_HORZ)
- return ThumbTrackHorz(&sw->sbarHorz, hwnd, x,y);
- else if(uCurrentScrollbar == SB_VERT)
- return ThumbTrackVert(&sw->sbarVert, hwnd, x,y);
- }
- if(uCurrentScrollPortion == HTSCROLL_NONE)
- {
- return CallWindowProc(sw->oldproc, hwnd, WM_MOUSEMOVE, wParam, lParam);
- }
- else
- {
- LPARAM nlParam;
- SCROLLBAR *sb = &sw->sbarHorz;
- SCROLLBUT *sbut = 0;
- nlParam = GetMessagePos();
- GetWindowRect(hwnd, &winrect);
- pt.x = LOWORD(nlParam);
- pt.y = HIWORD(nlParam);
- //emulate the mouse input on a scrollbar here...
- if(uCurrentScrollbar == SB_HORZ)
- {
- sb = &sw->sbarHorz;
- }
- else if(uCurrentScrollbar == SB_VERT)
- {
- sb = &sw->sbarVert;
- }
- //get the total area of the normal scrollbar area
- GetScrollRect(sw, sb->nBarType, hwnd, &rect);
-
- //see if we clicked in the inserted buttons / normal scrollbar
- //thisportion = GetPortion(sb, hwnd, &rect, LOWORD(lParam), HIWORD(lParam));
- thisportion = GetPortion(sb, hwnd, &rect, pt.x, pt.y);
-
- //we need to do different things depending on if the
- //user is activating the scrollbar itself, or one of
- //the inserted buttons
- switch(uCurrentScrollPortion)
- {
- //The scrollbar is active
- case HTSCROLL_LEFT: case HTSCROLL_RIGHT:case HTSCROLL_THUMB:
- case HTSCROLL_PAGELEFT: case HTSCROLL_PAGERIGHT:
- case HTSCROLL_NONE:
-
- //adjust the total scroll area to become where the scrollbar
- //really is (take into account the inserted buttons)
- GetRealScrollRect(sb, &rect);
- OffsetRect(&rect, -winrect.left, -winrect.top);
- hdc = GetWindowDC(hwnd);
-
- if(thisportion != uCurrentScrollPortion)
- {
- uScrollTimerPortion = HTSCROLL_NONE;
- if(lastportion != thisportion)
- NCDrawScrollbar(sb, hwnd, hdc, &rect, HTSCROLL_NORMAL);
- }
- //otherwise, draw the button in its depressed / clicked state
- else
- {
- uScrollTimerPortion = uCurrentScrollPortion;
- if(lastportion != thisportion)
- NCDrawScrollbar(sb, hwnd, hdc, &rect, thisportion);
- }
- ReleaseDC(hwnd, hdc);
- break;
- }
- lastportion = thisportion;
- lastbutton = buttonIdx;
- //must return zero here, because we might get cursor anomilies
- //CallWindowProc(sw->oldproc, hwnd, WM_MOUSEMOVE, wParam, lParam);
- return 0;
-
- }
- }
- //
- // We must allocate from in the non-client area for our scrollbars
- // Call the default window procedure first, to get the borders (if any)
- // allocated some space, then allocate the space for the scrollbars
- // if they fit
- //
- static LRESULT NCCalcSize(SCROLLWND *sw, HWND hwnd, WPARAM wParam, LPARAM lParam)
- {
- NCCALCSIZE_PARAMS *nccsp;
- RECT *rect;
- RECT oldrect;
- BOOL fCalcValidRects = (wParam == TRUE);
- SCROLLBAR *sb;
- UINT ret;
- DWORD dwStyle;
- //Regardless of the value of fCalcValidRects, the first rectangle
- //in the array specified by the rgrc structure member of the
- //NCCALCSIZE_PARAMS structure contains the coordinates of the window,
- //so we can use the exact same code to modify this rectangle, when
- //wParam is TRUE and when it is FALSE.
- nccsp = (NCCALCSIZE_PARAMS *)lParam;
- rect = &nccsp->rgrc[0];
- oldrect = *rect;
- dwStyle = GetWindowLong(hwnd, GWL_STYLE);
- // TURN OFF SCROLL-STYLES.
- if ( dwStyle & (WS_VSCROLL|WS_HSCROLL) )
- {
- sw->bPreventStyleChange = TRUE;
- SetWindowLong(hwnd, GWL_STYLE, dwStyle & ~(WS_VSCROLL|WS_HSCROLL));
- }
-
- //call the default procedure to get the borders allocated
- ret = CallWindowProc(sw->oldproc, hwnd, WM_NCCALCSIZE, wParam, lParam);
- // RESTORE PREVIOUS STYLES (if present at all)
- if ( dwStyle & (WS_VSCROLL|WS_HSCROLL) )
- {
- SetWindowLong(hwnd, GWL_STYLE, dwStyle);
- sw->bPreventStyleChange = FALSE;
- }
- // calculate what the size of each window border is,
- sw->cxLeftEdge = rect->left - oldrect.left;
- sw->cxRightEdge = oldrect.right - rect->right;
- sw->cyTopEdge = rect->top - oldrect.top;
- sw->cyBottomEdge = oldrect.bottom - rect->bottom;
- sb = &sw->sbarHorz;
- //if there is room, allocate some space for the horizontal scrollbar
- //NOTE: Change the ">" to a ">=" to make the horz bar totally fill the
- //window before disappearing
- if((sb->fScrollFlags & CSBS_VISIBLE) &&
- #ifdef COOLSB_FILLWINDOW
- rect->bottom - rect->top >= GetScrollMetric(sb, SM_CYHORZSB))
- #else
- rect->bottom - rect->top > GetScrollMetric(sb, SM_CYHORZSB))
- #endif
- {
- rect->bottom -= GetScrollMetric(sb, SM_CYHORZSB);
- sb->fScrollVisible = TRUE;
- }
- else
- sb->fScrollVisible = FALSE;
- sb = &sw->sbarVert;
- //if there is room, allocate some space for the vertical scrollbar
- if((sb->fScrollFlags & CSBS_VISIBLE) &&
- rect->right - rect->left >= GetScrollMetric(sb, SM_CXVERTSB))
- {
- if(sw->fLeftScrollbar)
- rect->left += GetScrollMetric(sb, SM_CXVERTSB);
- else
- rect->right -= GetScrollMetric(sb, SM_CXVERTSB);
- sb->fScrollVisible = TRUE;
- }
- else
- sb->fScrollVisible = FALSE;
- //don't return a value unless we actually modify the other rectangles
- //in the NCCALCSIZE_PARAMS structure. In this case, we return 0
- //no matter what the value of fCalcValidRects is
- return ret;//FALSE;
- }
- //
- // Timer routine to generate scrollbar messages
- //
- static LRESULT CoolSB_Timer(SCROLLWND *swnd, HWND hwnd, WPARAM wTimerId, LPARAM lParam)
- {
- //let all timer messages go past if we don't have a timer installed ourselves
- if(uScrollTimerId == 0 && uMouseOverId == 0)
- {
- return CallWindowProc(swnd->oldproc, hwnd, WM_TIMER, wTimerId, lParam);
- }
- #ifdef HOT_TRACKING
- //mouse-over timer
- if(wTimerId == COOLSB_TIMERID3)
- {
- POINT pt;
- RECT rect, winrect;
- HDC hdc;
- SCROLLBAR *sbar;
- if(swnd->fThumbTracking)
- return 0;
- //if the mouse moves outside the current scrollbar,
- //then kill the timer..
- GetCursorPos(&pt);
- if(!PtInRect(&MouseOverRect, pt))
- {
- KillTimer(hwnd, uMouseOverId);
- uMouseOverId = 0;
- uMouseOverScrollbar = COOLSB_NONE;
- uLastHitTestPortion = HTSCROLL_NONE;
- uHitTestPortion = HTSCROLL_NONE;
- NCPaint(swnd, hwnd, 1, 0);
- }
- else
- {
- if(uMouseOverScrollbar == SB_HORZ)
- {
- sbar = &swnd->sbarHorz;
- uHitTestPortion = GetHorzPortion(sbar, hwnd, &MouseOverRect, pt.x, pt.y);
- }
- else
- {
- sbar = &swnd->sbarVert;
- uHitTestPortion = GetVertPortion(sbar, hwnd, &MouseOverRect, pt.x, pt.y);
- }
- if(uLastHitTestPortion != uHitTestPortion)
- {
- rect = MouseOverRect;
- GetRealScrollRect(sbar, &rect);
- GetWindowRect(hwnd, &winrect);
- OffsetRect(&rect, -winrect.left, -winrect.top);
- hdc = GetWindowDC(hwnd);
- NCDrawScrollbar(sbar, hwnd, hdc, &rect, HTSCROLL_NONE);
- ReleaseDC(hwnd, hdc);
- }
-
- uLastHitTestPortion = uHitTestPortion;
- }
- return 0;
- }
- #endif // HOT_TRACKING
- //if the first timer goes off, then we can start a more
- //regular timer interval to auto-generate scroll messages
- //this gives a slight pause between first pressing the scroll arrow, and the
- //actual scroll starting
- if(wTimerId == COOLSB_TIMERID1)
- {
- KillTimer(hwnd, uScrollTimerId);
- uScrollTimerId = SetTimer(hwnd, COOLSB_TIMERID2, COOLSB_TIMERINTERVAL2, 0);
- return 0;
- }
- //send the scrollbar message repeatedly
- else if(wTimerId == COOLSB_TIMERID2)
- {
- //need to process a spoof WM_MOUSEMOVE, so that
- //we know where the mouse is each time the scroll timer goes off.
- //This is so we can stop sending scroll messages if the thumb moves
- //under the mouse.
- POINT pt;
- GetCursorPos(&pt);
- ScreenToClient(hwnd, &pt);
-
- MouseMove(swnd, hwnd, MK_LBUTTON, MAKELPARAM(pt.x, pt.y));
- if(uScrollTimerPortion != HTSCROLL_NONE)
- SendScrollMessage(hwnd, uScrollTimerMsg, uScrollTimerPortion, 0);
-
- return 0;
- }
- else
- {
- return CallWindowProc(swnd->oldproc, hwnd, WM_TIMER, wTimerId, lParam);
- }
- }
- //
- // We must intercept any calls to SetWindowLong, to check if
- // left-scrollbars are taking effect or not
- //
- static LRESULT CoolSB_StyleChange(SCROLLWND *swnd, HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
- {
- STYLESTRUCT *ss = (STYLESTRUCT *)lParam;
- if(wParam == GWL_EXSTYLE)
- {
- if(ss->styleNew & WS_EX_LEFTSCROLLBAR)
- swnd->fLeftScrollbar = TRUE;
- else
- swnd->fLeftScrollbar = FALSE;
- }
- return CallWindowProc(swnd->oldproc, hwnd, msg, wParam, lParam);
- }
- //
- // CoolScrollbar subclass procedure.
- // Handle all messages needed to mimick normal windows scrollbars
- //
- LRESULT CALLBACK CoolSBWndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
- {
- WNDPROC oldproc;
- SCROLLWND *swnd = GetScrollWndFromHwnd(hwnd);
- static int count;
- switch(message)
- {
- case WM_NCDESTROY:
- //this should NEVER be called, because the user
- //should have called Uninitialize() themselves.
- //However, if the user tries to call Uninitialize()..
- //after this window is destroyed, this window's entry in the lookup
- //table will not be there, and the call will fail
- oldproc = swnd->oldproc;
- UninitializeCoolSB(hwnd);
-
- //we must call the original window procedure, otherwise it
- //will never get the WM_NCDESTROY message, and it wouldn't
- //be able to clean up etc.
- return CallWindowProc(oldproc, hwnd, message, wParam, lParam);
- case WM_NCCALCSIZE:
- return NCCalcSize(swnd, hwnd, wParam, lParam);
- case WM_NCPAINT:
- NCPaint(swnd, hwnd, wParam, lParam);
- return 1;
- case WM_NCHITTEST:
- return NCHitTest(swnd, hwnd, wParam, lParam);
- case WM_NCLBUTTONDBLCLK:
- //TRACE("WM_NCLBUTTONDBLCLK %d\n", count++);
- if(wParam == HTHSCROLL || wParam == HTVSCROLL)
- return NCLButtonDown(swnd, hwnd, wParam, lParam);
- else
- break;
- case WM_NCLBUTTONDOWN:
- return NCLButtonDown(swnd, hwnd, wParam, lParam);
- case WM_LBUTTONUP:
- return LButtonUp(swnd, hwnd, wParam, lParam);
- //Mouse moves are received when we set the mouse capture,
- //even when the mouse moves over the non-client area
- case WM_MOUSEMOVE:
- //TRACE("WM_MOUSEMOVE %d\n", count++);
- return MouseMove(swnd, hwnd, wParam, lParam);
-
- case WM_TIMER:
- return CoolSB_Timer(swnd, hwnd, wParam, lParam);
- //case WM_STYLECHANGING:
- // return CoolSB_StyleChange(swnd, hwnd, WM_STYLECHANGING, wParam, lParam);
- case WM_STYLECHANGED:
- if(swnd->bPreventStyleChange)
- {
- // the NCPAINT handler has told us to eat this message!
- return 0;
- }
- else
- {
- if (message == WM_STYLECHANGED)
- return CoolSB_StyleChange(swnd, hwnd, WM_STYLECHANGED, wParam, lParam);
- else
- break;
- }
- default:
- break;
- }
-
- return CallWindowProc(swnd->oldproc, hwnd, message, wParam, lParam);
- }
|