void TScrollBar::SetValue(int32 value) { if (value < fMinimum) value = fMinimum; else if (value > fMaximum) value = fMaximum; if (value != fValue) { TRect oldThumb; GetThumb(oldThumb); fValue = value; HandleCommand(this, this, kValueChangedCommandID); TRect newThumb; GetThumb(newThumb); if (newThumb != oldThumb) { TDrawContext context(this); TRect rect; if (newThumb.left < oldThumb.left) rect.Set(newThumb.right, newThumb.top, oldThumb.right, newThumb.bottom); else if (newThumb.left > oldThumb.left) rect.Set(oldThumb.left, newThumb.top, newThumb.left, newThumb.bottom); if (newThumb.top < oldThumb.top) rect.Set(newThumb.left, newThumb.bottom, newThumb.right, oldThumb.bottom); else if (newThumb.top > oldThumb.top) rect.Set(newThumb.left, oldThumb.top, newThumb.right, newThumb.top); if (context.GetDepth() < 8) { context.SetStipple(TGraphicsUtils::GetGrayStipple()); context.SetForeColor(kBlackColor); context.SetBackColor(kWhiteColor); } else context.SetForeColor(kMediumGrayColor); context.PaintRect(rect); DrawThumb(context); } } }
void TScrollBar::DoMouseMoved(const TPoint& point, TModifierState state) { bool inTrackingRect = fTrackingRect.Contains(point); if (fTrackingPart == kArrow1 || fTrackingPart == kArrow2 || fTrackingPart == kPageUp || fTrackingPart == kPageDown) { if (inTrackingRect != fInTrackingRect) { if (fTrackingPart == kArrow1 || fTrackingPart == kArrow2) { TDrawContext context(this); if (fTrackingPart == kArrow1) DrawArrow1(context, inTrackingRect); else DrawArrow2(context, inTrackingRect); } fInTrackingRect = inTrackingRect; EnableIdling(inTrackingRect); } } else if (fTrackingPart == kThumb && fMinimum < fMaximum) { TCoord delta = (IsVertical() ? point.v - fLastPoint.v : point.h - fLastPoint.h); if (delta != 0) { TRect thumb, thumbArea; GetThumb(thumb); GetThumbArea(thumbArea); if ((IsVertical() && thumb.GetHeight() < thumbArea.GetHeight()) || (!IsVertical() && thumb.GetWidth() < thumbArea.GetWidth())) { int32 newValue; if (IsVertical()) newValue = (int32)(((float)(thumb.top - thumbArea.top + delta + 1) * 2.0 * (fMaximum - fMinimum)) / ((thumbArea.GetHeight() - thumb.GetHeight()) * 2)); else newValue = (int32)(((float)(thumb.left - thumbArea.left + delta + 1) * 2.0 * (fMaximum - fMinimum)) / ((thumbArea.GetWidth() - thumb.GetWidth()) * 2)); SetValue(newValue); } } } fLastPoint = point; }
ScrollBarPart TScrollBar::IdentifyPoint(const TPoint& point, TRect& outTrackingRect) const { GetArrow1(outTrackingRect); if (outTrackingRect.Contains(point)) return kArrow1; GetArrow2(outTrackingRect); if (outTrackingRect.Contains(point)) return kArrow2; TRect thumb; GetThumb(thumb); if (thumb.Contains(point)) { outTrackingRect = thumb; return kThumb; } TRect thumbArea; GetThumbArea(thumbArea); if (! thumbArea.Contains(point)) return kNone; if (IsVertical()) { outTrackingRect.Set(thumbArea.left, thumbArea.top, thumbArea.right, thumb.top); if (outTrackingRect.Contains(point)) return kPageUp; else { outTrackingRect.top = thumb.bottom; outTrackingRect.bottom = thumbArea.bottom; return kPageDown; } } else { outTrackingRect.Set(thumbArea.left, thumbArea.top, thumb.left, thumbArea.bottom); if (outTrackingRect.Contains(point)) return kPageUp; else { outTrackingRect.left = thumb.right; outTrackingRect.right = thumbArea.right; return kPageDown; } } }
void TScrollBar::DrawThumb(TDrawContext& context) { TRect thumbArea; GetThumbArea(thumbArea); TRect thumb; GetThumb(thumb); if (context.GetDepth() < 8) { context.SetStipple(TGraphicsUtils::GetGrayStipple()); context.SetForeColor(kBlackColor); context.SetBackColor(kWhiteColor); } else context.SetForeColor(kMediumGrayColor); if (thumb.IsEmpty()) { context.PaintRect(thumbArea); } else { if (IsVertical()) { TRect r(thumbArea.left, thumbArea.top, thumbArea.right, thumb.top); context.PaintRect(r); r.Set(thumb.left, thumb.bottom, thumbArea.right, thumbArea.bottom); context.PaintRect(r); } else { TRect r(thumbArea.left, thumbArea.top, thumb.left, thumbArea.bottom); context.PaintRect(r); r.Set(thumb.right, thumbArea.top, thumbArea.right, thumbArea.bottom); context.PaintRect(r); } TGraphicsUtils::Draw3DBorderAndInset(context, thumb); context.SetForeColor(kLightGrayColor); context.PaintRect(thumb); } }
uint32_t os2_get_file( CAMHandle hCam, CAMObjectInfoPtr pObjInfo, uint32_t handle, char* filename, int replace, int thumb) { APIRET rc = 0; uint32_t rtn = 0; HFILE hFile = 0; char * pBuf = 0; char * pMem = 0; char * pMsg = 0; ULONG ulSize; ULONG ul; FILESTATUS3 fs3; struct tm * ptm; do { if (!filename) { filename = pObjInfo->Filename; printf (" Saving %3d (%s)... ", handle, filename); } else printf (" Saving %3d (%s) as \"%s\"... ", handle, pObjInfo->Filename, filename); ulSize = (thumb ? pObjInfo->ThumbCompressedSize : pObjInfo->ObjectCompressedSize); if (ulSize == 0) { pMsg = "skipped - file size is zero\n"; break; } rc = DosOpen( filename, &hFile, &ul, ulSize, FILE_NORMAL, OPEN_ACTION_CREATE_IF_NEW | (replace ? OPEN_ACTION_REPLACE_IF_EXISTS : OPEN_ACTION_FAIL_IF_EXISTS), (OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYREADWRITE | OPEN_ACCESS_READWRITE), 0); if (rc) { if (rc == ERROR_OPEN_FAILED) pMsg = "skipped - file exists\n"; break; } rc = DosAllocMem( (PVOID)&pMem, ulSize + 0x1000 - CAMCNR_DATASIZE, PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE); if (rc) break; // this trick eliminates 400 memcpy()s in UsbBulkRead() for a 2mb file; // after GetData() reads the first 500 bytes, the buffer it passes // to UsbBulkRead() will be page-aligned & can be used as-is pBuf = pMem + 0x1000 - CAMCNR_DATASIZE; if (thumb) rtn = GetThumb( hCam, handle, &pBuf); else rtn = GetObject( hCam, handle, &pBuf); if (rtn) { rc = (APIRET)rtn; break; } rc = DosWrite( hFile, pBuf, ulSize, &ul); if (rc) break; if (pObjInfo->CaptureDate == 0) { pMsg = "done\n"; break; } pMsg = "done - unable to set timestamp\n"; rc = DosQueryFileInfo( hFile, FIL_STANDARD, &fs3, sizeof(FILESTATUS3)); if (rc) break; ptm = localtime( &pObjInfo->CaptureDate); if (!ptm) break; fs3.fdateCreation.year = ptm->tm_year - 80; fs3.fdateCreation.month = ptm->tm_mon + 1; fs3.fdateCreation.day = ptm->tm_mday; fs3.ftimeCreation.hours = ptm->tm_hour; fs3.ftimeCreation.minutes = ptm->tm_min; fs3.ftimeCreation.twosecs = ptm->tm_sec / 2; fs3.fdateLastWrite = fs3.fdateCreation; fs3.ftimeLastWrite = fs3.ftimeCreation; rc = DosSetFileInfo( hFile, FIL_STANDARD, &fs3, sizeof(FILESTATUS3)); if (rc) break; pMsg = "done\n"; } while (0); if (pMem) DosFreeMem( pMem); if (hFile) DosClose( hFile); if (pMsg) printf( pMsg); else printf( "error - rc= %d\n", (int)rc); return rtn; }
void PtpThumbnailThread( void * camthumbptr) { uint32_t rc = 0; uint32_t errCtr = 0; char * pBuf = 0; CAMThumbPtr pct = (CAMThumbPtr)camthumbptr; CAMRecPtr * ppcr = pct->pcr; CAMRecPtr pcr; do{ rc = DosRequestMutexSem( pct->thisCam->hmtxCam, CAM_MUTEXWAIT); if (rc) break; while (*ppcr) { pcr = *ppcr; // get the thumb from the camera rc = GetThumb( pct->thisCam->hCam, pcr->hndl, &pBuf); if (rc) { printf( "PtpThumbnailThread - GetThumb #1 - handle= %d rc= 0x%x\n", (int)pcr->hndl, (int)rc); if (rc == CAMERR_NULLCAMERAPTR) break; rc = ClearStall( pct->thisCam->hCam); if (rc == CAMERR_NULLCAMERAPTR) break; rc = GetThumb( pct->thisCam->hCam, pcr->hndl, &pBuf); if (rc) { printf( "PtpThumbnailThread - GetThumb #2 - handle= %d rc= 0x%x\n", (int)pcr->hndl, (int)rc); if (rc == CAMERR_NULLCAMERAPTR) break; ClearStall( pct->thisCam->hCam); if (++errCtr > 2) break; } } if (!rc) { errCtr = 0; // if rotate-on-load is set, get the // Exif orientation info from the main image if (pct->fRotate && pcr->fmtnbr == PTP_OFC_EXIF_JPEG && pcr->size >= 500) PtpGetOrientation( pct->thisCam, pcr); // create the bitmap pcr->bmp = CreateThumbnailBmp( pcr, pBuf); } // free the memory allocated by GetThumb() if (pBuf) { free( pBuf); pBuf = 0; } // let the main thread know we finished processing this record if (pcr->bmp && !WinPostMsg( pct->hReply, CAMMSG_FETCHTHUMBS, (MP)pcr, 0)) printf( "PtpThumbnailThread - WinPostMsg failed\n"); ppcr++; } DosReleaseMutexSem( pct->thisCam->hmtxCam); } while (0); WinPostMsg( pct->hReply, CAMMSG_FETCHTHUMBS, (MP)-1, (MP)rc); free( pct); return; }