static MRESULT APIENTRY Char ( HWND Window, MESG, MPARAM1 mp1, MPARAM2 mp2 ) { /*************************************************************************** * Find the instance data. * ***************************************************************************/ PDATA Data = PDATA ( Sys_GetWindowData ( Window ) ) ; /*************************************************************************** * Get the message data. * ***************************************************************************/ USHORT Flags = (USHORT) SHORT1FROMMP ( mp1 ) ; //UCHAR Repeat = (UCHAR) CHAR3FROMMP ( mp1 ) ; //UCHAR ScanCode = (UCHAR) CHAR4FROMMP ( mp1 ) ; //USHORT Char = (USHORT) SHORT1FROMMP ( mp2 ) ; USHORT VKey = (USHORT) SHORT2FROMMP ( mp2 ) ; /*************************************************************************** * Ignore keys being released, invalid characters, dead keys and * * invalid composite characters. * ***************************************************************************/ if ( ( Flags & KC_KEYUP ) OR ( Flags & KC_INVALIDCHAR ) OR ( Flags & KC_DEADKEY ) OR ( Flags & KC_INVALIDCOMP ) ) { Sys_BeepNote ( ) ; return ( MRFROMSHORT ( FALSE ) ) ; } /*************************************************************************** * Intercept the ESC virtual key to abort margin set mode. * ***************************************************************************/ if ( Flags & KC_VIRTUALKEY ) { switch ( VKey ) { case VK_ESC: { if ( Data->Capture ) { Data->Capture = FALSE ; Sys_ReleaseCapture ( ) ; HPOINTER Ptr = WinQuerySysPointer ( HWND_DESKTOP, SPTR_ARROW, FALSE ) ; WinSetPointer ( HWND_DESKTOP, Ptr ) ; Sys_SetFocus ( Data->HadFocus ) ; WorkSpace PS ( "HRuler::Char", 0, Window, Data->pDevice, int(Data->Metric) ) ; PS.SetTransform ( Data->fxZoom, int(Data->TopLeft), 0 ) ; RECTL Rectangle ; WinQueryWindowRect ( Window, &Rectangle ) ; PS.Transform ( CVTC_DEVICE, CVTC_DEFAULTPAGE, Rectangle ) ; POINTL ButtonSize = { 8, 8 } ; PS.Transform ( CVTC_DEVICE, CVTC_PAGE, 1, &ButtonSize ) ; PS.SetMix ( FM_INVERT ) ; PS.SetLineType ( LINETYPE_ALTERNATE ) ; POINTL Point = { Data->Tick, Rectangle.yBottom } ; PS.Move ( Point ) ; Point.y = Rectangle.yTop ; PS.DrawLine ( Point ) ; Data->Mode = NOTMOVING ; } break ; } } } /*************************************************************************** * Return. * ***************************************************************************/ return ( MRFROMSHORT ( TRUE ) ) ; }
static MRESULT APIENTRY Button1Up ( HWND Window, MESG, MPARAM1 mp1, MPARAM2 ) { /*************************************************************************** * Find the instance data. * ***************************************************************************/ PDATA Data = PDATA ( Sys_GetWindowData ( Window ) ) ; /*************************************************************************** * If the mouse wasn't captured, return. * ***************************************************************************/ if ( NOT Data->Capture ) return ( MRFROMSHORT ( FALSE ) ) ; /*************************************************************************** * Get the presentation space. * ***************************************************************************/ WorkSpace PS ( "HRuler::Button1Up", 0, Window, Data->pDevice, int(Data->Metric) ) ; PS.SetTransform ( Data->fxZoom, int(Data->TopLeft), 0 ) ; /*************************************************************************** * Find out where the mouse touched. * ***************************************************************************/ RECTL Rectangle ; WinQueryWindowRect ( Window, &Rectangle ) ; POINTL Mouse = { SHORT1FROMMP(mp1), SHORT2FROMMP(mp1) } ; PS.Transform ( CVTC_DEVICE, CVTC_DEFAULTPAGE, 1, &Mouse ) ; PS.Transform ( CVTC_DEVICE, CVTC_DEFAULTPAGE, Rectangle ) ; POINTL ButtonSize = { 8, 8 } ; PS.Transform ( CVTC_DEVICE, CVTC_PAGE, 1, &ButtonSize ) ; #ifdef DEBUG Log ( "HRuler::Button1Up: Mouse at %i,%i (%i,%i). Rectangle %i,%i-%i,%i. ButtonSize %i.%i (8x8).", Mouse.x, Mouse.y, SHORT1FROMMP(mp1), SHORT2FROMMP(mp1), Rectangle.xLeft, Rectangle.yBottom, Rectangle.xRight, Rectangle.yTop, ButtonSize.x, ButtonSize.y ) ; #endif /*************************************************************************** * Erase the previous hairline. * ***************************************************************************/ PS.SetMix ( FM_INVERT ) ; PS.SetLineType ( LINETYPE_ALTERNATE ) ; POINTL Point = { Data->Tick, Rectangle.yBottom } ; PS.Move ( Point ) ; Point.y = Rectangle.yTop ; PS.DrawLine ( Point ) ; /*************************************************************************** * Release the mouse. * ***************************************************************************/ Data->Capture = FALSE ; Sys_ReleaseCapture ( ) ; /*************************************************************************** * Restore the normal mouse pointer. * ***************************************************************************/ HPOINTER Ptr = WinQuerySysPointer ( HWND_DESKTOP, SPTR_ARROW, FALSE ) ; WinSetPointer ( HWND_DESKTOP, Ptr ) ; /*************************************************************************** * Restore the keyboard focus. * ***************************************************************************/ Sys_SetFocus ( Data->HadFocus ) ; /*************************************************************************** * Process final location of mouse. * ***************************************************************************/ switch ( Data->Mode ) { case MOVELEFT: { Data->Tick = TICK(Mouse.x) ; if ( ( Data->Tick < 0 ) OR ( Data->Tick >= Data->RightMargin ) ) { Sys_BeepError ( ) ; break ; } Sys_SendMessage ( OWNER(Window), WM_SET_LEFTMARGIN, MPFROMLONG(Data->Tick), 0 ) ; break ; } case MOVERIGHT: { Data->Tick = TICK(Mouse.x) ; if ( ( Data->Tick <= Data->LeftMargin ) OR ( Data->Tick > Data->PageWidth ) ) { Sys_BeepError ( ) ; break ; } Sys_SendMessage ( OWNER(Window), WM_SET_RIGHTMARGIN, MPFROMLONG(Data->Tick), 0 ) ; break ; } case MOVETAB: { Data->Tick = TICK(Mouse.x) ; if ( ( Mouse.y > Rectangle.yTop ) OR ( Mouse.y < Rectangle.yBottom ) OR ( Data->Tick <= Data->LeftMargin ) OR ( Data->Tick >= Data->RightMargin ) ) { Sys_SendMessage ( OWNER(Window), WM_CLEAR_TAB, MPFROMLONG(Data->Tabs[Data->TabIndex]), 0 ) ; break ; } Sys_SendMessage ( OWNER(Window), WM_MOVE_TAB, MPFROMLONG(Data->Tabs[Data->TabIndex]), MPFROMLONG(Data->Tick) ) ; break ; } case SETTAB: { Data->Tick = TICK(Mouse.x) ; if ( ( Mouse.y > Rectangle.yTop ) OR ( Mouse.y < Rectangle.yBottom ) OR ( Data->Tick <= Data->LeftMargin ) OR ( Data->Tick >= Data->RightMargin ) ) { Sys_BeepError ( ) ; break ; } Sys_SendMessage ( OWNER(Window), WM_SET_TAB, MPFROMLONG(Data->Tick), 0 ) ; break ; } } /*************************************************************************** * Reset mode. * ***************************************************************************/ Data->Mode = NOTMOVING ; /*************************************************************************** * We're done. * ***************************************************************************/ return ( MRFROMSHORT ( TRUE ) ) ; }
static MRESULT APIENTRY MouseMove ( HWND Window, MESG msg, MPARAM1 mp1, MPARAM2 mp2 ) { /*************************************************************************** * Find the instance data. * ***************************************************************************/ PDATA Data = PDATA ( Sys_GetWindowData ( Window ) ) ; /*************************************************************************** * If the mouse wasn't captured, return. * ***************************************************************************/ if ( NOT Data->Capture ) return ( Sys_DefWindowProc ( Window, msg, mp1, mp2 ) ) ; /*************************************************************************** * Get the presentation space. * ***************************************************************************/ WorkSpace PS ( "HRuler::MouseMove", 0, Window, Data->pDevice, int(Data->Metric) ) ; PS.SetTransform ( Data->fxZoom, int(Data->TopLeft), 0 ) ; /*************************************************************************** * Find out where the mouse touched. * ***************************************************************************/ RECTL Rectangle ; WinQueryWindowRect ( Window, &Rectangle ) ; POINTL Mouse = { SHORT1FROMMP(mp1), SHORT2FROMMP(mp1) } ; PS.Transform ( CVTC_DEVICE, CVTC_DEFAULTPAGE, 1, &Mouse ) ; PS.Transform ( CVTC_DEVICE, CVTC_DEFAULTPAGE, Rectangle ) ; POINTL ButtonSize = { 8, 8 } ; PS.Transform ( CVTC_DEVICE, CVTC_PAGE, 1, &ButtonSize ) ; #ifdef DEBUG Log ( "HRuler::MouseMove: Mouse at %i,%i (%i,%i). Rectangle %i,%i-%i,%i. ButtonSize %i.%i (8x8).", Mouse.x, Mouse.y, SHORT1FROMMP(mp1), SHORT2FROMMP(mp1), Rectangle.xLeft, Rectangle.yBottom, Rectangle.xRight, Rectangle.yTop, ButtonSize.x, ButtonSize.y ) ; #endif /*************************************************************************** * Erase the previous hairline. * ***************************************************************************/ PS.SetMix ( FM_INVERT ) ; PS.SetLineType ( LINETYPE_ALTERNATE ) ; POINTL Point = { Data->Tick, Rectangle.yBottom } ; PS.Move ( Point ) ; Point.y = Rectangle.yTop ; PS.DrawLine ( Point ) ; /*************************************************************************** * Save the current hairline position. * ***************************************************************************/ Data->Tick = TICK(Mouse.x) ; /*************************************************************************** * Draw a hairline showing the current position. * ***************************************************************************/ Point.x = Data->Tick ; Point.y = Rectangle.yBottom ; PS.Move ( Point ) ; Point.y = Rectangle.yTop ; PS.DrawLine ( Point ) ; /*************************************************************************** * We're done. * ***************************************************************************/ return ( MRFROMSHORT ( TRUE ) ) ; }
static MRESULT APIENTRY Button1Down ( HWND Window, MESG, MPARAM1 mp1, MPARAM2 ) { /*************************************************************************** * Find the instance data. * ***************************************************************************/ PDATA Data = PDATA ( Sys_GetWindowData ( Window ) ) ; /*************************************************************************** * Find out where the mouse touched. * ***************************************************************************/ RECTL Rectangle ; WinQueryWindowRect ( Window, &Rectangle ) ; WorkSpace PS ( "HRuler::Button1Down", 0, Window, Data->pDevice, int(Data->Metric) ) ; PS.SetTransform ( Data->fxZoom, int(Data->TopLeft), 0 ) ; POINTL Mouse = { SHORT1FROMMP(mp1), SHORT2FROMMP(mp1) } ; PS.Transform ( CVTC_DEVICE, CVTC_DEFAULTPAGE, 1, &Mouse ) ; PS.Transform ( CVTC_DEVICE, CVTC_DEFAULTPAGE, Rectangle ) ; POINTL ButtonSize = { 8, 8 } ; PS.Transform ( CVTC_DEVICE, CVTC_PAGE, 1, &ButtonSize ) ; #ifdef DEBUG Log ( "HRuler::Button1Down: Mouse at %i,%i (%i,%i). Rectangle %i,%i-%i,%i. ButtonSize %i.%i (8x8).", Mouse.x, Mouse.y, SHORT1FROMMP(mp1), SHORT2FROMMP(mp1), Rectangle.xLeft, Rectangle.yBottom, Rectangle.xRight, Rectangle.yTop, ButtonSize.x, ButtonSize.y ) ; #endif /*************************************************************************** * If the mouse isn't touching in the button area, return. * ***************************************************************************/ if ( Mouse.y < Rectangle.yTop - ButtonSize.y ) { Sys_BeepNote ( ) ; return ( MRFROMSHORT ( FALSE ) ) ; } /* endif */ /*************************************************************************** * If the mouse is beyond the margins, return. * ***************************************************************************/ if ( ( Mouse.x < Data->LeftMargin ) OR ( Mouse.x > Data->RightMargin+ButtonSize.x ) ) { Sys_BeepNote ( ) ; return ( MRFROMSHORT ( FALSE ) ) ; } /* endif */ /*************************************************************************** * If mouse is touching the left margin button, set mode to MOVELEFT. * ***************************************************************************/ if ( ( Mouse.x >= Data->LeftMargin ) AND ( Mouse.x <= Data->LeftMargin+ButtonSize.x ) ) { Data->Mode = MOVELEFT ; Data->Ptr = Data->MarginPtr ; } /* endif */ /*************************************************************************** * If mouse is touching the right margin button, set mode to MOVERIGHT. * ***************************************************************************/ else if ( ( Mouse.x >= Data->RightMargin-ButtonSize.x ) AND ( Mouse.x <= Data->RightMargin ) ) { Data->Mode = MOVERIGHT ; Data->Ptr = Data->MarginPtr ; } /* endif */ /*************************************************************************** * Else, find which tab-stop, if any, we're touching. * ***************************************************************************/ else { for ( int i=0; i<Data->TabCount; i++ ) { if ( ( Mouse.x >= Data->Tabs[i] ) AND ( Mouse.x <= Data->Tabs[i]+ButtonSize.x ) ) { Data->Mode = MOVETAB ; Data->TabIndex = USHORT ( i ) ; break ; } /* endif */ } /* endfor */ if ( i >= Data->TabCount ) { Data->Mode = SETTAB ; } /* endif */ Data->Ptr = Data->TabstopPtr ; } /* endif */ /*************************************************************************** * Capture the mouse. * ***************************************************************************/ Data->Capture = TRUE ; Sys_SetCapture ( Window ) ; /*************************************************************************** * Set the new mouse pointer. * ***************************************************************************/ WinSetPointer ( HWND_DESKTOP, Data->Ptr ) ; /*************************************************************************** * Get the keyboard focus. * ***************************************************************************/ Data->HadFocus = WinQueryFocus ( HWND_DESKTOP ) ; Sys_SetFocus ( Window ) ; /*************************************************************************** * Save the current hairline position. * ***************************************************************************/ Data->Tick = TICK(Mouse.x) ; /*************************************************************************** * Draw a hairline showing the current position. * ***************************************************************************/ PS.SetMix ( FM_INVERT ) ; PS.SetLineType ( LINETYPE_ALTERNATE ) ; POINTL Point = { Data->Tick, Rectangle.yBottom } ; PS.Move ( Point ) ; Point.y = Rectangle.yTop ; PS.DrawLine ( Point ) ; /*************************************************************************** * We're done. * ***************************************************************************/ return ( MRFROMSHORT ( TRUE ) ) ; }
static MRESULT APIENTRY Paint ( HWND Window, MESG, MPARAM1, MPARAM2 ) { /************************************************************************** * Find the instance data. * **************************************************************************/ PDATA Data = PDATA ( Sys_GetWindowData ( Window ) ) ; /************************************************************************** * Compute the current zoom factor. * **************************************************************************/ double Zoom = (double) FIXEDINT ( Data->fxZoom ) ; Zoom += (double) FIXEDFRAC ( Data->fxZoom ) / 0x10000L ; /************************************************************************** * Get presentation space and prepare it for use. * **************************************************************************/ RECTL ClippingRectangle ; WorkSpace PS ( "HRuler::Paint", 0, Window, Data->pDevice, int(Data->Metric), ClippingRectangle ) ; PS.SetTransform ( Data->fxZoom, int(Data->TopLeft), 0 ) ; PS.Transform ( CVTC_DEVICE, CVTC_DEFAULTPAGE, ClippingRectangle ) ; /************************************************************************** * Clear the window and draw a border. * **************************************************************************/ RECTL WindowRectangle ; WinQueryWindowRect ( Window, &WindowRectangle ) ; WindowRectangle.xRight -- ; WindowRectangle.yTop -- ; PS.Transform ( CVTC_DEVICE, CVTC_DEFAULTPAGE, WindowRectangle ) ; PS.SetColor ( Data->IniData->fRulerColors[0] ? Data->IniData->RulerColors[0] : RGB_WHITE ) ; PS.FillBox ( WindowRectangle ) ; PS.SetColor ( RGB_BLACK ) ; PS.DrawBox ( WindowRectangle ) ; /************************************************************************** * Draw the left margin. * **************************************************************************/ if ( ClippingRectangle.xLeft <= Data->LeftMargin ) { PS.SetColor ( Data->IniData->fRulerColors[1] ? Data->IniData->RulerColors[1] : RGB_BLUE ) ; PS.SetFillType ( PATSYM_HALFTONE ) ; RECTL Box = { ClippingRectangle.xLeft, ClippingRectangle.yBottom, Data->LeftMargin, ClippingRectangle.yTop } ; PS.FillBox ( Box ) ; PS.SetFillType ( PATSYM_DEFAULT ) ; PS.SetColor ( RGB_BLACK ) ; PS.SetLineType ( LINETYPE_ALTERNATE ) ; POINTL Point = { Data->LeftMargin, ClippingRectangle.yTop } ; PS.Move ( Point ) ; Point.y = ClippingRectangle.yTop ; PS.DrawLine ( Point ) ; PS.SetLineType ( LINETYPE_SOLID ) ; } /* endif */ POINTL Point = { Data->LeftMargin, WindowRectangle.yTop } ; PS.Transform ( CVTC_DEFAULTPAGE, CVTC_DEVICE, 1, &Point ) ; Point.y -= 8 ; PS.DrawPointer ( Data->MarginPtr, Point, DP_NORMAL ) ; /************************************************************************** * Draw the right margin. * **************************************************************************/ if ( ClippingRectangle.xRight >= Data->RightMargin ) { PS.SetColor ( Data->IniData->fRulerColors[1] ? Data->IniData->RulerColors[1] : RGB_BLUE ) ; PS.SetFillType ( PATSYM_HALFTONE ) ; RECTL Box = { Data->RightMargin, ClippingRectangle.yBottom, ClippingRectangle.xRight, ClippingRectangle.yTop } ; PS.FillBox ( Box ) ; PS.SetFillType ( PATSYM_DEFAULT ) ; PS.SetColor ( RGB_BLACK ) ; PS.SetLineType ( LINETYPE_ALTERNATE ) ; Point.x = Data->RightMargin ; Point.y = ClippingRectangle.yBottom ; PS.Move ( Point ) ; Point.y = ClippingRectangle.yTop ; PS.DrawLine ( Point ) ; PS.SetLineType ( LINETYPE_SOLID ) ; } /* endif */ Point.x = Data->RightMargin ; Point.y = WindowRectangle.yTop ; PS.Transform ( CVTC_DEFAULTPAGE, CVTC_DEVICE, 1, &Point ) ; Point.x -= 8 ; Point.y -= 8 ; PS.DrawPointer ( Data->MarginPtr, Point, DP_NORMAL ) ; /************************************************************************** * Draw the tab-stops. * **************************************************************************/ for ( int i=0; i<Data->TabCount; i++ ) { Point.x = Data->Tabs[i] ; Point.y = WindowRectangle.yTop ; PS.Transform ( CVTC_DEFAULTPAGE, CVTC_DEVICE, 1, &Point ) ; Point.y -= 8 ; PS.DrawPointer ( Data->TabstopPtr, Point, DP_NORMAL ) ; } /* endfor */ /************************************************************************** * Draw the ruler. * **************************************************************************/ for ( long x=WindowRectangle.xLeft; x<WindowRectangle.xRight; x++ ) { if ( x % ( Data->Metric ? 200 : 250 ) == 0 ) { PS.SetColor ( RGB_BLACK ) ; Point.x = x ; Point.y = 0 ; PS.Move ( Point ) ; if ( x % 1000 == 0 ) { Point.y = LONG ( 200.0 / Zoom ) ; PS.DrawLine ( Point ) ; Point.x += LONG ( 50.0 / Zoom ) ; Point.y = LONG ( 50.0 / Zoom ) ; char Text [10] ; sprintf ( Text, "%i", int(x/1000) ) ; PS.SetColor ( Data->IniData->fRulerColors[1] ? Data->IniData->RulerColors[1] : RGB_BLUE ) ; PS.Move ( Point ) ; PS.DrawText ( Text ) ; } else if ( x % 500 == 0 ) { Point.y = LONG ( 150.0 / Zoom ) ; PS.DrawLine ( Point ) ; } else { Point.y = LONG ( 100.0 / Zoom ) ; PS.DrawLine ( Point ) ; } /* endif */ } /* endif */ } /* endfor */ /************************************************************************** * We're done. * **************************************************************************/ return ( MRFROMSHORT ( 0 ) ) ; }
static MRESULT APIENTRY SetTick ( HWND Window, MESG, MPARAM1 mp1, MPARAM2 ) { /************************************************************************** * Find the instance data. * **************************************************************************/ PDATA Data = PDATA ( Sys_GetWindowData ( Window ) ) ; /************************************************************************** * Get the new tick-mark position from the message. * **************************************************************************/ LONG Tick = LONGFROMMP ( mp1 ) ; /************************************************************************** * If only the tick-mark has changed, move it. * **************************************************************************/ if ( Data->Tick != Tick ) { /*********************************************************************** * Get the presentation space. * ***********************************************************************/ WorkSpace PS ( "HRuler::SetTick", 0, Window, Data->pDevice, int(Data->Metric) ) ; PS.SetTransform ( Data->fxZoom, int(Data->TopLeft), 0 ) ; /*********************************************************************** * Find out some background information. * ***********************************************************************/ RECTL Rectangle ; WinQueryWindowRect ( Window, &Rectangle ) ; PS.Transform ( CVTC_DEVICE, CVTC_DEFAULTPAGE, Rectangle ) ; /*********************************************************************** * Erase the previous hairline. * ***********************************************************************/ if ( Data->Tick ) { PS.SetMix ( FM_INVERT ) ; PS.SetLineType ( LINETYPE_ALTERNATE ) ; POINTL Point = { Data->Tick, Rectangle.yBottom } ; PS.Move ( Point ) ; Point.y = Rectangle.yTop ; PS.DrawLine ( Point ) ; } /* endif */ /*********************************************************************** * Save the current hairline position. * ***********************************************************************/ Data->Tick = Tick ; /*********************************************************************** * Draw a hairline showing the current position. * ***********************************************************************/ if ( Data->Tick ) { PS.SetMix ( FM_INVERT ) ; PS.SetLineType ( LINETYPE_ALTERNATE ) ; POINTL Point = { Data->Tick, Rectangle.yBottom } ; PS.Move ( Point ) ; Point.y = Rectangle.yTop ; PS.DrawLine ( Point ) ; } /* endif */ } /* endif */ /************************************************************************** * We're done. * **************************************************************************/ return ( MRFROMSHORT ( 0 ) ) ; }