#include <sgdrag.h>
Inheritance diagram for SGScrollDragTarget:
Public Member Functions | |
SGScrollDragTarget (DialogOp *TheDialog, CGadgetID TheGadget=NULL) | |
Constructor. | |
virtual UINT32 | GetCursorID () |
Base Method to set cursor over this target. | |
virtual BOOL | GetStatusLineText (String_256 *TheText) |
Provide status line text for this target. | |
Protected Member Functions | |
virtual BOOL | ProcessEvent (DragEventType Event, DragInformation *pDragInfo, OilCoord *pMousePos, KeyPress *pKeyPress) |
Event Handler for SuperGallery scrollbar drag events. | |
Protected Attributes | |
MonotonicTime | Timer |
Friends | |
class | DragManagerOp |
Notes: Drag targets are destructed automatically when a drag finishes by the drag manager with which they were registered.
To remove a drag target at any time, destruct it - it automatically deregisters and cleans up.
Definition at line 141 of file sgdrag.h.
|
Constructor.
Definition at line 150 of file sgdrag.cpp. 00151 : KernelDragTarget(TheDialog, TheGadget) 00152 { 00153 Timer.Sample(); // Remember the time at which we were created, for autorepeat 00154 00155 IWantAllEvents = TRUE; // Ask for all events to be given to us, even if the pointer 00156 // strays out of our target window area. 00157 }
|
|
Base Method to set cursor over this target.
Reimplemented from DragTarget. Definition at line 384 of file sgdrag.cpp.
|
|
Provide status line text for this target.
Reimplemented from DragTarget. Definition at line 404 of file sgdrag.cpp. 00405 { 00406 return FALSE; 00407 }
|
|
Event Handler for SuperGallery scrollbar drag events. BOOL SGScrollDragTarget::ProcessEvent(DragEventType Event, DragInformation *pDragInfo, OilCoord *pMousePos, KeyPress* pKeyPress)
Reimplemented from KernelDragTarget. Definition at line 181 of file sgdrag.cpp. 00183 { 00184 // Weed out events that we are not interested in 00185 switch(Event) 00186 { 00187 case DRAGEVENT_ABORT: 00188 case DRAGEVENT_COMPLETED: 00189 // Just claim the event as ours. 00190 // We don't get these events unless the pointer is over us, so we don't do 00191 // anything here - see the deinitialise handler 00192 return(TRUE); 00193 00194 case DRAGEVENT_INITIALISE: 00195 case DRAGEVENT_DEINITIALISE: 00196 case DRAGEVENT_MOUSEMOVED: 00197 case DRAGEVENT_MOUSESTOPPED: 00198 case DRAGEVENT_MOUSEIDLE: 00199 // We want these events, so break to drop through and process them 00200 break; 00201 00202 default: 00203 // An unknown/unwanted event type - it could be dangerous to do something on 00204 // an unknown event, so we won't! 00205 return(TRUE); 00206 } 00207 00208 // Cast the draginfo into the correct type 00209 SGScrollDragInfo *DragInfo = (SGScrollDragInfo *) pDragInfo; 00210 00211 // FALSE if we aren't dragging, but just handling auto-repeat 00212 BOOL NotAutoRepeat = (DragInfo->GetDragType() == SGDRAG_SAUSAGE); 00213 00214 SGDisplayRootScroll *Root = DragInfo->GetDragRootNode(); 00215 SGMiscInfo *MiscInfo = DragInfo->GetDragMiscInfo(); 00216 SuperGallery *ParentGallery = Root->GetParentGallery(); 00217 00218 // Convert the OilCoord into a DocCoord, and convert into displaylist coords 00219 DocCoord MousePos(pMousePos->x, pMousePos->y); 00220 ParentGallery->ConvertToVirtualCoords(MiscInfo, &MousePos); 00221 00222 // And calculate the relevant rectangles... 00223 DocRect UpButton; 00224 DocRect DownButton; 00225 DocRect SausageRect; 00226 DocRect PageUp; 00227 DocRect PageDown; 00228 DocRect ScrollRect; 00229 Root->CalculateScrollRects(MiscInfo, TRUE, 00230 &UpButton, &DownButton, &SausageRect, 00231 &PageUp, &PageDown, &ScrollRect); 00232 00233 if (Event == DRAGEVENT_MOUSEMOVED && NotAutoRepeat) 00234 { 00235 // Dragging the scroll sausage 00236 00237 // Get the offset - the scroll sausage should try to move this point of the 00238 // sausage (measured in millipoints from the top of the sausage) to lie under 00239 // the mouse pointer position if possible. 00240 INT32 AnchorOffset = DragInfo->GetDragAnchorOffset(); 00241 00242 INT32 ScrollWindowTo; 00243 00244 if (SausageRect.Height() <= SausageRect.Width()) 00245 { 00246 // The sausage is a minimum-size square, so now does not proportionally represent 00247 // the displayed area of the window. Thus, we need to use the top position of the 00248 // bar in (barheight - sausageheight) as a fractional scroll between 0 and 00249 // (ScrollExtent - WindowHeight) 00250 ScrollWindowTo = (INT32) ( 00251 ( ((double) (ScrollRect.hi.y - (MousePos.y + AnchorOffset))) / 00252 (double) (ScrollRect.Height() - SausageRect.Height()) ) * 00253 (double) (Root->GetCachedListExtent() - MiscInfo->WindowHeight) 00254 ); 00255 } 00256 else 00257 { 00258 // The bar represents the fraction of visible area to extent, so we work out the 00259 // fractional position of the top of the bar, and that gives the position to scroll 00260 // the top of the displayed area to. 00261 ScrollWindowTo = (INT32) ( 00262 ( ((double) (ScrollRect.hi.y - (MousePos.y + AnchorOffset))) / 00263 (double) ScrollRect.Height() ) * 00264 (double) Root->GetCachedListExtent() 00265 ); 00266 } 00267 00268 Root->SetScrollOffset(ScrollWindowTo, MiscInfo); 00269 return(TRUE); 00270 } 00271 00272 00273 // The drag must therefore be to implement simple AutoRepeat on a button or page-scroll. 00274 // We only bother scrolling if: 00275 // 1) Event is 'initialise' (so it scrolls immediately the button goes down) 00276 // 2) Event is 'deinitialise' (so we must ensure all buttons are popped up) 00277 // 3) Or if it is time for another autorepeat 00278 if (Event != DRAGEVENT_INITIALISE && 00279 Event != DRAGEVENT_DEINITIALISE && 00280 !Timer.Elapsed(AUTOREPEATTIME)) 00281 { 00282 // No need to update just now. Return, claiming this event 00283 return(TRUE); 00284 } 00285 00286 const INT32 ClickScroll = 12000; // Millipoint distance to scroll for a button click 00287 INT32 ScrollBy = 0; // Set this to the amount by which to scroll 00288 00289 Timer.Sample(); // Update the autorepeat timer 00290 00291 switch (DragInfo->GetDragType()) 00292 { 00293 case SGDRAG_SCROLLUP: 00294 if (Event == DRAGEVENT_DEINITIALISE) 00295 { 00296 // Drag completed: Unindent the scroll button 00297 Root->IndentedButton = IBUTTON_NONE; 00298 ParentGallery->ForceRedrawOfArea(&UpButton); 00299 ParentGallery->PaintListNow(); 00300 } 00301 else if (UpButton.ContainsCoord(MousePos)) 00302 { 00303 ScrollBy = -ClickScroll; 00304 00305 // Indent the scroll button 00306 Root->IndentedButton = IBUTTON_UP; 00307 ParentGallery->ForceRedrawOfArea(&UpButton); 00308 ParentGallery->PaintListNow(); 00309 } 00310 break; 00311 00312 00313 case SGDRAG_SCROLLDOWN: 00314 if (Event == DRAGEVENT_DEINITIALISE) 00315 { 00316 // Drag completed: Unindent the scroll button 00317 Root->IndentedButton = IBUTTON_NONE; 00318 ParentGallery->ForceRedrawOfArea(&DownButton); 00319 ParentGallery->PaintListNow(); 00320 } 00321 else if (DownButton.ContainsCoord(MousePos)) 00322 { 00323 ScrollBy = ClickScroll; 00324 00325 // Indent the scroll button 00326 Root->IndentedButton = IBUTTON_DOWN; 00327 ParentGallery->ForceRedrawOfArea(&DownButton); 00328 ParentGallery->PaintListNow(); 00329 } 00330 break; 00331 00332 00333 case SGDRAG_PAGEUP: 00334 if (PageUp.IsValid() && PageUp.ContainsCoord(MousePos)) 00335 { 00336 ScrollBy = MiscInfo->WindowHeight - ClickScroll; 00337 if (ScrollBy < 0) 00338 ScrollBy = ClickScroll; 00339 00340 ScrollBy = -ScrollBy; 00341 } 00342 break; 00343 00344 00345 case SGDRAG_PAGEDOWN: 00346 if (PageDown.IsValid() && PageDown.ContainsCoord(MousePos)) 00347 { 00348 ScrollBy = MiscInfo->WindowHeight - ClickScroll; 00349 if (ScrollBy < 0) 00350 ScrollBy = ClickScroll; 00351 } 00352 break; 00353 00354 default: 00355 break; 00356 } 00357 00358 if (Event != DRAGEVENT_DEINITIALISE && ScrollBy != 0) 00359 { 00360 if (DragInfo->IsAdjustDrag()) // If adjust-drag, reverse scroll direction 00361 ScrollBy = -ScrollBy; 00362 00363 Root->SetScrollOffset(Root->GetScrollOffset() + ScrollBy, MiscInfo); 00364 } 00365 00366 // We always claim all events during this drag (it is not a drag to a particular place 00367 // to move an object - really we're using the drag system to "capture" the mouse) 00368 return(TRUE); 00369 }
|
|
Reimplemented from KernelDragTarget. |
|
|