/opencascade-6.5.1/ros/src/WNT/W95_Allocator.cxx

https://github.com/jehc/MondocosmOS · C++ · 1202 lines · 751 code · 359 blank · 92 comment · 87 complexity · 59603e21516dab8e2e87da362dab617b MD5 · raw file

  1. ////////////////////////////////////////////////////////////////////////////////
  2. // W95_Allocator //
  3. // Provides memory management and drawing operations for Windows 95. //
  4. // World transformations and styled lines are managed by EHDC stuff. //
  5. // //
  6. // History: FEB-98 - creation (EUG) //
  7. // MAR-98 - modification (DCB) //
  8. // //
  9. // Notes: bitmap rotation code was created by MPO //
  10. ////////////////////////////////////////////////////////////////////////////////
  11. #include "W95_Allocator.hxx"
  12. #include <math.h>
  13. #include <limits>
  14. #define SGN( x ) ( ( x ) > 0 ? 1 : ( ( x ) < 0 ? -1 : 0 ) )
  15. #define ALLOCATOR ( ( PW95_Allocator )myAllocator )
  16. #define MIN4( a, b, c, d ) min( min( ( a ), ( b ) ), min( ( c ), ( d ) ) )
  17. #define MAX4( a, b, c, d ) max( max( \
  18. ( ( a ) == INT_MAX ? INT_MIN : ( a ) ), \
  19. ( ( b ) == INT_MAX ? INT_MIN : ( b ) ) \
  20. ), \
  21. max( \
  22. ( ( c ) == INT_MAX ? INT_MIN : ( c ) ), \
  23. ( ( d ) == INT_MAX ? INT_MIN : ( d ) ) \
  24. ) \
  25. )
  26. static void WINAPI _InitXform ( PXFORM, double, int, int );
  27. static VOID CALLBACK _LineDDAProc ( int, int, LPARAM );
  28. W95_Allocator :: W95_Allocator ( int anID, PW32_Allocator prev ) :
  29. W32_Allocator ( anID, prev ) {
  30. myLinePenWidth = 0;
  31. myLineBrush.lbStyle = BS_SOLID;
  32. myLineBrush.lbColor = RGB( 0, 0, 0 );
  33. myLineBrush.lbHatch = 0;
  34. myLineStyleCount = 0;
  35. myLineStyles = NULL;
  36. myPolyBrush.lbStyle = BS_NULL;
  37. myTextColor = RGB( 0, 0, 0 );
  38. myMarkerBrush = myPolyBrush;
  39. myMarkerWidth = 0;
  40. myFlags |= W32F_WIN95;
  41. } // end constructor
  42. W95_Allocator :: ~W95_Allocator () {
  43. if ( myLineStyles != NULL ) HeapFree (
  44. GetProcessHeap (), 0, ( LPVOID )myLineStyles
  45. );
  46. } // end destructor
  47. void W95_Allocator :: Play ( HDC hdc, PSIZE szClient ) {
  48. if ( !( myFlags & W32F_EMPTY ) ) {
  49. myHDC.SetDC ( hdc, szClient );
  50. myHDC.ResetURect ();
  51. myHDC.SelectEPen (
  52. myLinePenWidth, &myLineBrush,
  53. myLineStyleCount, myLineStyles
  54. );
  55. myHDC.SelectEBrush ( &myPolyBrush, NULL );
  56. myHDC.SetTextAttrib (
  57. myTextColor, myTextFont, myTextSlant,
  58. myTextHScale, myTextVScale
  59. );
  60. myHDC.SetPolyFillMode ( myFillMode );
  61. Xform ();
  62. for ( PW32_Block aBlock = myStart; aBlock != NULL; aBlock = aBlock -> next )
  63. for ( int i = 0; i < aBlock -> free; i += aBlock -> data[ i ] )
  64. if ( aBlock -> data[ i + 1 ] != __W32_DATA ) {
  65. W32_Note* pNote = ( W32_Note* )&( aBlock -> data[ i + 1 ] );
  66. pNote -> Play ();
  67. } // end if
  68. } // end if
  69. } // end W95_Allocator :: Play
  70. void W95_Allocator :: URect ( LPRECT lpRect ) {
  71. myHDC.GetURect ( lpRect );
  72. } // end W95_Allocator :: URect
  73. void W95_Allocator :: Xform ( void ) {
  74. if ( myAngle != 0.0 || myPivot.x != 0 || myPivot.y != 0 ||
  75. myMove.x != 0 || myMove.y != 0 ||
  76. myScaleX != 1.0 || myScaleY != 1.0
  77. ) {
  78. XFORM xf;
  79. double sinVal, cosVal;
  80. sinVal = sin ( myAngle );
  81. cosVal = cos ( myAngle );
  82. xf.eM11 = 1.0F; xf.eM12 = 0.0F;
  83. xf.eM21 = 0.0F; xf.eM22 = 1.0F;
  84. xf.eDx = ( FLOAT )-myPivot.x; xf.eDy = ( FLOAT )-myPivot.y;
  85. myHDC.SetWorldTransform ( &xf );
  86. xf.eM11 = FLOAT ( cosVal * myScaleX ); xf.eM12 = FLOAT ( sinVal * myScaleX );
  87. xf.eM21 = FLOAT ( -sinVal * myScaleY ); xf.eM22 = FLOAT ( cosVal * myScaleY );
  88. xf.eDx = 0.0F; xf.eDy = 0.0F;
  89. myHDC.ModifyWorldTransform ( &xf, MWT_RIGHTMULTIPLY );
  90. xf.eM11 = 1.0F; xf.eM12 = 0.0F;
  91. xf.eM21 = 0.0F; xf.eM22 = 1.0F;
  92. xf.eDx = FLOAT ( myPivot.x + myMove.x ); xf.eDy = FLOAT ( myPivot.y + myMove.y );
  93. myHDC.ModifyWorldTransform ( &xf, MWT_RIGHTMULTIPLY );
  94. myFlags |= W32F_XFORM;
  95. } else {
  96. myHDC.ModifyWorldTransform ( NULL, MWT_IDENTITY );
  97. myFlags &= ~W32F_XFORM;
  98. } // end else
  99. } // end W95_Allocator :: Xform
  100. void W95_Allocator :: Point ( int x, int y ) {
  101. new ( this ) W32_PointNote ( x, y );
  102. } // end W95_Allocator :: Point
  103. void W95_Allocator :: MarkerPoint ( int x, int y ) {
  104. new ( this ) W32_MarkerPointNote ( x, y );
  105. } // end W95_Allocator :: MarkerPoint
  106. void W95_Allocator :: Line ( int x, int y, int x1, int y1 ) {
  107. new ( this ) W32_LineNote ( x, y, x1, y1 );
  108. } // end W95_Allocator :: Line
  109. void W95_Allocator :: PolyEllipse ( int xc, int yc, int xr, int yr ) {
  110. new ( this ) W32_PolyEllipseNote ( xc, yc, xr, yr );
  111. } // end W95_Allocator :: PolyEllipse
  112. void W95_Allocator :: Ellipse ( int xc, int yc, int xr, int yr ) {
  113. new ( this ) W32_EllipseNote ( xc, yc, xr, yr );
  114. } // end W95_Allocator :: Ellipse
  115. void W95_Allocator :: Arc (
  116. int xc, int yc, int xr, int yr,
  117. double sa, double oa
  118. ) {
  119. new ( this ) W32_ArcNote ( xc, yc, xr, yr, sa, oa );
  120. } // end W95_Allocator :: Arc
  121. void W95_Allocator :: PolyChord (
  122. int xc, int yc, int xr, int yr,
  123. double sa, double oa
  124. ) {
  125. new ( this ) W32_PolyChordNote ( xc, yc, xr, yr, sa, oa );
  126. } // end W95_Allocator :: PolyChord
  127. void W95_Allocator :: Chord (
  128. int xc, int yc, int xr, int yr,
  129. double sa, double oa
  130. ) {
  131. new ( this ) W32_PolyChordNote ( xc, yc, xr, yr, sa, oa );
  132. } // end W95_Allocator :: Chord
  133. void W95_Allocator :: PolySector (
  134. int xc, int yc, int xr, int yr,
  135. double sa, double oa
  136. ) {
  137. new ( this ) W32_PolySectorNote ( xc, yc, xr, yr, sa, oa );
  138. } // end W95_Allocator :: PolySector
  139. void W95_Allocator :: Sector (
  140. int xc, int yc, int xr, int yr,
  141. double sa, double oa
  142. ) {
  143. new ( this ) W32_SectorNote ( xc, yc, xr, yr, sa, oa );
  144. } // end W95_Allocator :: Sector
  145. void W95_Allocator :: PolyMarker ( int aMaxPoints ) {
  146. new ( this ) W32_PolyMarkerNote ( aMaxPoints );
  147. } // end W95_Allocator :: PolyMarker
  148. void W95_Allocator :: PolyMarker1 (
  149. int aMaxPoints, GetPointFunc fn,
  150. int aStartPoint, void* fParam
  151. ) {
  152. new ( this ) W32_PolyMarker1Note (
  153. aMaxPoints, fn, aStartPoint, fParam
  154. );
  155. } // end W95_Allocator :: PolyMarker1
  156. void W95_Allocator :: PolyMarker2 (
  157. int aMaxPoints, GetPointFunc fn,
  158. int aStartPoint, void* fParam
  159. ) {
  160. new ( this ) W32_PolyMarker2Note (
  161. aMaxPoints, fn, aStartPoint, fParam
  162. );
  163. } // end W95_Allocator :: PolyMarker1
  164. W32_Note* W95_Allocator :: Polygon ( int aMaxPoints ) {
  165. return new ( this ) W32_PolygonNote ( aMaxPoints );
  166. } // end W95_Allocator :: Polygon
  167. W32_Note* W95_Allocator :: Polyline ( int aMaxPoints ) {
  168. return new ( this ) W32_PolylineNote ( aMaxPoints );
  169. } // end W95_Allocator :: Polyline
  170. void W95_Allocator :: Image (
  171. int x, int y, PW32_Bitmap pBmp, double aScale
  172. ) {
  173. new ( this ) W32_ImageNote ( x, y, pBmp, aScale );
  174. } // end W95_Allocator :: Image
  175. void W95_Allocator :: Text (
  176. int x, int y, double angle, void* text,
  177. BOOL fWide, BOOL fOutlined
  178. ) {
  179. new ( this ) W32_TextNote ( x, y, angle, text, fWide, fOutlined );
  180. } // end W95_Allocator :: Text
  181. void W95_Allocator :: Polytext (
  182. int x, int y, double angle, double margin,
  183. void* text, BOOL fWide, BOOL fOutlined
  184. ) {
  185. new ( this ) W32_PolyTextNote ( x, y, angle, margin, text, fWide, fOutlined );
  186. } // end W95_Allocator :: Polytext
  187. void W95_Allocator :: BeginMarker (
  188. int x, int y, int w, int h, double angle
  189. ) {
  190. new ( this ) W32_BeginMarkerNote ( x, y, w, h, angle );
  191. } // end W95_Allocator :: BeginMarker
  192. void W95_Allocator :: EndMarker ( void ) {
  193. new ( this ) W32_EndMarkerNote ();
  194. } // end W95_Allocator :: EndMarker
  195. void W95_Allocator :: LineAttrib (
  196. DWORD width, PLOGBRUSH plb,
  197. DWORD nStyles, PDWORD pdwStyle
  198. ) {
  199. new ( this ) W32_LineAttribNote ( width, plb, nStyles, pdwStyle );
  200. } // end W95_Allocator :: LineAttrib
  201. void W95_Allocator :: PolyAttrib (
  202. PLOGBRUSH plb, BOOL fDrawEdge, int aFillMode
  203. ) {
  204. new ( this ) W32_PolyAttribNote ( plb, fDrawEdge, aFillMode );
  205. } // end W95_Allocator :: PolyAttrib
  206. void W95_Allocator :: TextAttrib (
  207. HFONT hFont, COLORREF color, double slant,
  208. double hScale, double vScale,
  209. BOOL fUnderlined, BOOL fFree, BOOL fIndex
  210. ) {
  211. if ( myFlags & W32F_START )
  212. new ( this ) W32_TextAttribNote (
  213. hFont, color, slant, hScale, vScale,
  214. fUnderlined, fFree, fIndex
  215. );
  216. else {
  217. if ( myFlags & W32F_DFONT && !fIndex ) {
  218. DeleteFont( myTextFont );
  219. myFlags &= ~W32F_DFONT;
  220. } // end if
  221. myTextColor = color;
  222. myTextFont = hFont;
  223. myTextSlant = slant;
  224. myTextHScale = vScale;
  225. myTextVScale = hScale;
  226. myFlags |= ( fUnderlined ? W32F_TULIN : 0 );
  227. } // end else
  228. } // end W95_Allocator :: TextAttrib
  229. void W95_Allocator :: MarkerAttrib (
  230. COLORREF color, DWORD dwWidth, BOOL fFill
  231. ) {
  232. new ( this ) W32_MarkerAttribNote ( color, dwWidth, fFill );
  233. } // end W95_Allocator :: MarkerAttrib
  234. void W95_Allocator :: FunCall (
  235. W32_FCall fCall, int sz, PW32_FCALLPARAM param
  236. ) {
  237. new ( this ) W32_FCallNote ( fCall, sz, param );
  238. } // end W95_Allocator :: FunCall
  239. int W95_Allocator :: TextSize ( HDC hdc, char* str, PSIZE psz )
  240. {
  241. ABC abcf;
  242. GetTextExtentPoint32A ( hdc, str, lstrlenA ( str ), psz );
  243. GetCharABCWidthsA ( hdc, str[ 0 ], str[ 0 ], &abcf );
  244. psz->cx = LONG ( psz->cx * myTextHScale );
  245. psz->cy = LONG ( psz->cy * myTextVScale );
  246. abcf.abcA = UINT ( abcf.abcA * myTextHScale );
  247. return abcf.abcA;
  248. } // end W95_Allocator :: TextSize
  249. int W95_Allocator :: TextSize ( HDC hdc, wchar_t* str, PSIZE psz )
  250. {
  251. ABC abcf;
  252. GetTextExtentPoint32W ( hdc, str, lstrlenW ( str ), psz );
  253. GetCharABCWidthsW ( hdc, str[ 0 ], str[ 0 ], &abcf );
  254. psz->cx = LONG ( psz->cx * myTextHScale );
  255. psz->cy = LONG ( psz->cy * myTextVScale );
  256. abcf.abcA = UINT ( abcf.abcA * myTextHScale );
  257. return abcf.abcA;
  258. } // end W95_Allocator :: TextSize
  259. ////////////////////////////////////////////////////////////////////////////////
  260. // W 3 2 _ P o i n t N o t e //
  261. ////////////////////////////////////////////////////////////////////////////////
  262. W32_PointNote :: W32_PointNote ( int x, int y ) {
  263. myX = x;
  264. myY = y;
  265. } // end constructor
  266. void W32_PointNote :: Play ( BOOL fDummy ) {
  267. ALLOCATOR -> myHDC.SetPixel ( myX, myY, ALLOCATOR -> myPointColor );
  268. } // end W32_PointNote :: Play
  269. ////////////////////////////////////////////////////////////////////////////////
  270. // W 3 2 _ M a r k e r P o i n t N o t e //
  271. ////////////////////////////////////////////////////////////////////////////////
  272. W32_MarkerPointNote :: W32_MarkerPointNote ( int x, int y ) :
  273. W32_PointNote ( x, y ) {
  274. } // end constructor
  275. void W32_MarkerPointNote :: Play ( BOOL fDummy ) {
  276. ALLOCATOR -> myHDC.SetPixel ( myX, myY, ALLOCATOR -> myMarkerPointColor );
  277. } // end W32_MarkerPointNote :: Play
  278. ////////////////////////////////////////////////////////////////////////////////
  279. // W 3 2 _ L i n e N o t e //
  280. ////////////////////////////////////////////////////////////////////////////////
  281. W32_LineNote :: W32_LineNote ( int x, int y, int x1, int y1 ) :
  282. W32_PointNote ( x, y ) {
  283. myX2 = x1;
  284. myY2 = y1;
  285. } // end constructor
  286. void W32_LineNote :: Play ( BOOL fDummy ) {
  287. EHDC* pe = &ALLOCATOR -> myHDC;
  288. pe -> MoveToEx ( myX, myY, NULL );
  289. pe -> LineTo ( myX2, myY2 );
  290. } // end W32_LineNote :: Play
  291. ////////////////////////////////////////////////////////////////////////////////
  292. // W 3 2 _ P o l y E l l i p s e N o t e //
  293. ////////////////////////////////////////////////////////////////////////////////
  294. W32_PolyEllipseNote :: W32_PolyEllipseNote ( int xc, int yc, int xr, int yr ) :
  295. W32_PointNote ( xc, yc ) {
  296. myXr = xr;
  297. myYr = yr;
  298. } // end constructor
  299. void W32_PolyEllipseNote :: Play ( BOOL fDummy ) {
  300. ALLOCATOR -> myHDC.Polyarc ( myX, myY, myXr, myYr );
  301. } // end W32_PolyEllipseNote :: Play
  302. ////////////////////////////////////////////////////////////////////////////////
  303. // W 3 2 _ E l l i p s e N o t e //
  304. ////////////////////////////////////////////////////////////////////////////////
  305. W32_EllipseNote :: W32_EllipseNote ( int xc, int yc, int xr, int yr ) :
  306. W32_PolyEllipseNote ( xc, yc, xr, yr ) {
  307. } // end constructor
  308. void W32_EllipseNote :: Play ( BOOL fDummy ) {
  309. ALLOCATOR -> myHDC.Arc ( myX, myY, myXr, myYr );
  310. } // end W32_PolyEllipseNote :: Play
  311. ////////////////////////////////////////////////////////////////////////////////
  312. // W 3 2 _ A r c N o t e //
  313. ////////////////////////////////////////////////////////////////////////////////
  314. W32_ArcNote :: W32_ArcNote (
  315. int xc, int yc, int xr, int yr, double sa, double oa
  316. ) : W32_PolyEllipseNote ( xc, yc, xr, yr ) {
  317. mySa = sa;
  318. myOa = oa;
  319. } // end constructor
  320. void W32_ArcNote :: Play ( BOOL fDummy ) {
  321. ALLOCATOR -> myHDC.Arc ( myX, myY, myXr, myYr, mySa, myOa );
  322. } // end W32_ArcNote :: Play
  323. ////////////////////////////////////////////////////////////////////////////////
  324. // W 3 2 _ P o l y C h o r d N o t e //
  325. ////////////////////////////////////////////////////////////////////////////////
  326. W32_PolyChordNote :: W32_PolyChordNote (
  327. int xc, int yc, int xr, int yr, double sa, double oa
  328. ) : W32_ArcNote ( xc, yc, xr, yr, sa, oa ) {
  329. } // end constructor
  330. void W32_PolyChordNote :: Play ( BOOL fDummy ) {
  331. ALLOCATOR -> myHDC.Polyarc ( myX, myY, myXr, myYr, mySa, myOa );
  332. } // end W32_PolyChordNote :: Play
  333. ////////////////////////////////////////////////////////////////////////////////
  334. // W 3 2 _ C h o r d N o t e //
  335. ////////////////////////////////////////////////////////////////////////////////
  336. W32_ChordNote :: W32_ChordNote (
  337. int xc, int yc, int xr, int yr, double sa, double oa
  338. ) : W32_PolyChordNote ( xc, yc, xr, yr, sa, oa ) {
  339. } // end constructor
  340. void W32_ChordNote :: Play ( BOOL fDummy ) {
  341. ALLOCATOR -> myHDC.Arc ( myX, myY, myXr, myYr, mySa, myOa );
  342. } // end W32_ChordNote :: Play
  343. ////////////////////////////////////////////////////////////////////////////////
  344. // W 3 2 _ P o l y S e c t o r N o t e //
  345. ////////////////////////////////////////////////////////////////////////////////
  346. W32_PolySectorNote :: W32_PolySectorNote (
  347. int xc, int yc, int xr, int yr, double sa, double oa
  348. ) : W32_ArcNote ( xc, yc, xr, yr, sa, oa ) {
  349. } // end constructor
  350. void W32_PolySectorNote :: Play ( BOOL fDummy ) {
  351. ALLOCATOR -> myHDC.Polyarc ( myX, myY, myXr, myYr, mySa, myOa, FALSE );
  352. } // end W32_PolySectorNote :: Play
  353. ////////////////////////////////////////////////////////////////////////////////
  354. // W 3 2 _ S e c t o r N o t e //
  355. ////////////////////////////////////////////////////////////////////////////////
  356. W32_SectorNote :: W32_SectorNote (
  357. int xc, int yc, int xr, int yr, double sa, double oa
  358. ) : W32_PolySectorNote ( xc, yc, xr, yr, sa, oa ) {
  359. } // end constructor
  360. void W32_SectorNote :: Play ( BOOL fDummy ) {
  361. ALLOCATOR -> myHDC.Arc ( myX, myY, myXr, myYr, mySa, myOa, ARCF_PIE );
  362. } // end W32_SectorNote :: Play
  363. ////////////////////////////////////////////////////////////////////////////////
  364. // W 3 2 _ P o l y M a r k e r N o t e //
  365. ////////////////////////////////////////////////////////////////////////////////
  366. W32_PolyMarkerNote :: W32_PolyMarkerNote ( int aMaxPoints ) {
  367. myMaxPoints = aMaxPoints;
  368. mySetPoints = 0;
  369. myPoints = ( LPPOINT )myAllocator -> NewData (
  370. myMaxPoints * sizeof ( POINT )
  371. );
  372. } // end constructor
  373. void W32_PolyMarkerNote :: Replace ( int idx, int x, int y ) {
  374. if ( idx >= myMaxPoints ) return;
  375. myPoints[ idx ].x = x;
  376. myPoints[ idx ].y = y;
  377. } // end CPolyMarkerNote :: Replace
  378. ////////////////////////////////////////////////////////////////////////////////
  379. // W 3 2 _ P o l y M a r k e r 1 N o t e //
  380. ////////////////////////////////////////////////////////////////////////////////
  381. W32_PolyMarker1Note :: W32_PolyMarker1Note (
  382. int aMaxPoints, GetPointFunc fn, int aStartPoint,
  383. void* fParam
  384. ) : W32_PolyMarkerNote ( aMaxPoints ) {
  385. ( *fn ) ( aStartPoint, myMaxPoints, aStartPoint, myPoints, &mySetPoints, fParam );
  386. } // end constructor
  387. void W32_PolyMarker1Note :: Play ( BOOL fDummy ) {
  388. if ( ALLOCATOR -> myFlags & W32F_MFILL )
  389. ALLOCATOR -> myHDC.Polygon (
  390. myPoints, mySetPoints,
  391. POLYF_NOCLOSEDGE
  392. );
  393. else
  394. ALLOCATOR -> myHDC.Polyline ( myPoints, mySetPoints );
  395. } // end W32_PolyMarker1Note :: Play
  396. ////////////////////////////////////////////////////////////////////////////////
  397. // W 3 2 _ P o l y M a r k e r 2 N o t e //
  398. ////////////////////////////////////////////////////////////////////////////////
  399. W32_PolyMarker2Note :: W32_PolyMarker2Note (
  400. int aMaxPoints, GetPointFunc fn, int aStartPoint,
  401. void* fParam
  402. ) : W32_PolyMarker1Note (
  403. aMaxPoints, fn, aStartPoint, fParam
  404. ) {
  405. } // end constructor
  406. void W32_PolyMarker2Note :: Play ( BOOL fDummy ) {
  407. if ( ALLOCATOR -> myFlags & W32F_MFILL )
  408. ALLOCATOR -> myHDC.Polygon ( myPoints, mySetPoints - 1 );
  409. else
  410. ALLOCATOR -> myHDC.Polyline ( myPoints, mySetPoints - 1, TRUE );
  411. } // end W32_PolyMarker2Note :: Play
  412. ////////////////////////////////////////////////////////////////////////////////
  413. // W 3 2 _ P o l y g o n N o t e //
  414. ////////////////////////////////////////////////////////////////////////////////
  415. W32_PolygonNote :: W32_PolygonNote ( int aMaxPoints ) :
  416. W32_PolyMarkerNote ( aMaxPoints ) {
  417. } // end constructor
  418. void W32_PolygonNote :: Play ( BOOL fDummy ) {
  419. ALLOCATOR -> myHDC.Polygon (
  420. myPoints, mySetPoints,
  421. ALLOCATOR -> myFlags & W32F_POUTL ? 0 : POLYF_NOEDGE
  422. );
  423. } // end W32_PolygonNote :: Play
  424. void W32_PolygonNote :: Add ( int aX,int aY ) {
  425. if ( mySetPoints == myMaxPoints ) return;
  426. ( myPoints + mySetPoints ) -> x = aX;
  427. ( myPoints + mySetPoints ) -> y = aY;
  428. ++mySetPoints;
  429. } // end W32_CPolygonNote :: Add
  430. ////////////////////////////////////////////////////////////////////////////////
  431. // W 3 2 _ P o l y l i n e N o t e //
  432. ////////////////////////////////////////////////////////////////////////////////
  433. W32_PolylineNote :: W32_PolylineNote ( int aMaxPoints ) :
  434. W32_PolygonNote ( aMaxPoints ) {
  435. } // end constructor
  436. void W32_PolylineNote :: Play ( BOOL fDummy ) {
  437. DWORD nPts;
  438. BOOL fClose;
  439. int idx = mySetPoints - 1;
  440. if ( myPoints -> x == myPoints[ idx ].x &&
  441. myPoints -> y == myPoints[ idx ].y
  442. ) {
  443. nPts = idx;
  444. fClose = TRUE;
  445. } else {
  446. nPts = mySetPoints;
  447. fClose = FALSE;
  448. } // end else
  449. ALLOCATOR -> myHDC.Polyline ( myPoints, nPts, fClose );
  450. } // end W32_PolylineNote :: Play
  451. ////////////////////////////////////////////////////////////////////////////////
  452. // W 3 2 _ I m a g e N o t e //
  453. ////////////////////////////////////////////////////////////////////////////////
  454. W32_ImageNote :: W32_ImageNote (
  455. int x, int y, PW32_Bitmap pBmp, double aScale
  456. ) : W32_PointNote ( x, y ) {
  457. myBitmap = pBmp;
  458. ++pBmp -> nUsed;
  459. myScale = aScale;
  460. } // end constructor
  461. W32_ImageNote :: ~W32_ImageNote () {
  462. if ( myBitmap -> hBmp != NULL && --myBitmap -> nUsed == 0 ) {
  463. DeleteObject ( myBitmap -> hBmp );
  464. HeapFree ( GetProcessHeap (), 0, ( PVOID )myBitmap );
  465. } // end if
  466. } // end W32_ImageNote :: ~W32_ImageNote
  467. void W32_ImageNote :: Play ( BOOL fDummy ) {
  468. int xx, yy, w, h;
  469. HDC hdc, hdcMem;
  470. BITMAP bmp;
  471. HBITMAP hbo;
  472. SIZE sz;
  473. POINT up[ 4 ];
  474. BOOL fScale = FALSE;
  475. ALLOCATOR -> myHDC.Extent ( &sz );
  476. GetObject ( myBitmap -> hBmp, sizeof ( BITMAP ), &bmp );
  477. xx = myX;
  478. yy = myY;
  479. w = bmp.bmWidth;
  480. h = bmp.bmHeight;
  481. if ( myScale != 1.0 ) {
  482. w = int ( w * myScale + 0.5 );
  483. h = int ( h * myScale + 0.5 );
  484. fScale = TRUE;
  485. }
  486. if ( ALLOCATOR -> myScaleX != 1.0 ) {
  487. xx = int ( xx * ALLOCATOR -> myScaleX + 0.5 );
  488. w = int ( w * ALLOCATOR -> myScaleX + 0.5 );
  489. fScale = TRUE;
  490. } // end if
  491. if ( ALLOCATOR -> myScaleY != 1.0 ) {
  492. yy = int ( yy * ALLOCATOR -> myScaleY + 0.5 );
  493. h = int ( h * ALLOCATOR -> myScaleY + 0.5 );
  494. fScale = TRUE;
  495. } // end if
  496. xx = xx - ( w >> 1 ) + ALLOCATOR -> myPivot.x + ALLOCATOR -> myMove.x ;
  497. yy = sz.cy - ( yy + ( h >> 1 ) ) - ALLOCATOR -> myPivot.y - ALLOCATOR -> myMove.y;
  498. hdc = ALLOCATOR -> myHDC.Hdc ();
  499. hdcMem = CreateCompatibleDC ( hdc );
  500. hbo = SelectBitmap( hdcMem, myBitmap -> hBmp );
  501. if ( ALLOCATOR -> myAngle == 0.0 ) {
  502. StretchBlt (
  503. hdc, xx, yy, w, h,
  504. hdcMem, 0, 0, bmp.bmWidth, bmp.bmHeight,
  505. SRCCOPY
  506. );
  507. up[ 0 ].x = xx; up[ 0 ].y = yy;
  508. up[ 1 ].x = xx + w; up[ 1 ].y = up[ 0 ].y;
  509. up[ 2 ].x = up[ 1 ].x; up[ 2 ].y = yy + h;
  510. up[ 3 ].x = up[ 0 ].x; up[ 3 ].y = up[ 2 ].y;
  511. ALLOCATOR -> myHDC.Register ( up, 4 );
  512. } else {
  513. int i, j;
  514. int x1 = xx;
  515. int y1 = sz.cy - yy - h;
  516. int x2 = x1 + w;
  517. int y2 = y1;
  518. int x3 = x2;
  519. int y3 = y1 + h;
  520. int x4 = x1;
  521. int y4 = y3;
  522. int xmin = MIN4( x1, x2, x3, x4 );
  523. int ymin = MIN4( y1, y2, y3, y4 );
  524. double DeltaX = cos ( -ALLOCATOR -> myAngle );
  525. double DeltaY = sin ( -ALLOCATOR -> myAngle );
  526. int X1 = int ( x1 * DeltaX + y1 * DeltaY );
  527. int Y1 = int ( -x1 * DeltaY + y1 * DeltaX );
  528. int X2 = int ( x2 * DeltaX + y2 * DeltaY );
  529. int Y2 = int ( -x2 * DeltaY + y2 * DeltaX );
  530. int X3 = int ( x3 * DeltaX + y3 * DeltaY );
  531. int Y3 = int ( -x3 * DeltaY + y3 * DeltaX );
  532. int X4 = int ( x4 * DeltaX + y4 * DeltaY );
  533. int Y4 = int ( -x4 * DeltaY + y4 * DeltaX );
  534. int YHeight = max( abs ( Y1 - Y3 ), abs ( Y2 - Y4 ) ) + 1;
  535. int Ymin = MIN4( Y1, Y2, Y3, Y4 );
  536. PINT line1, line2, line3, line4;
  537. PPOINT lines;
  538. HBITMAP hbo2, hBmp;
  539. if ( fScale ) {
  540. HDC hdcMem2 = CreateCompatibleDC ( hdc );
  541. hBmp = CreateCompatibleBitmap ( hdc, w, h );
  542. hbo2 = SelectBitmap( hdcMem2, hBmp );
  543. StretchBlt (
  544. hdcMem2, 0, 0, w, h,
  545. hdcMem, 0, 0, bmp.bmWidth, bmp.bmHeight,
  546. SRCCOPY
  547. );
  548. SelectBitmap( hdcMem2, hbo2 );
  549. DeleteDC ( hdcMem2 );
  550. hbo2 = SelectBitmap( hdcMem, hBmp );
  551. } // end if
  552. lines = ( PPOINT )VirtualAlloc (
  553. NULL, ( ( j = ( sizeof ( int ) * YHeight ) ) << 2 ) +
  554. ( i = YHeight * sizeof ( POINT ) ),
  555. MEM_RESERVE | MEM_COMMIT, PAGE_READWRITE
  556. );
  557. line1 = PINT ( ( ( PBYTE )lines ) + i );
  558. line2 = PINT ( ( ( PBYTE )line1 ) + j );
  559. line3 = PINT ( ( ( PBYTE )line2 ) + j );
  560. line4 = PINT ( ( ( PBYTE )line3 ) + j );
  561. for ( i = 0; i < YHeight; ++i )
  562. line1[ i ] = line2[ i ] = line3[ i ] = line4[ i ] = INT_MAX;
  563. LineDDA ( X1, Y1 - Ymin, X2, Y2 - Ymin, &_LineDDAProc, ( LPARAM )line1 );
  564. LineDDA ( X2, Y2 - Ymin, X3, Y3 - Ymin, &_LineDDAProc, ( LPARAM )line2 );
  565. LineDDA ( X3, Y3 - Ymin, X4, Y4 - Ymin, &_LineDDAProc, ( LPARAM )line3 );
  566. LineDDA ( X4, Y4 - Ymin, X1, Y1 - Ymin, &_LineDDAProc, ( LPARAM )line4 );
  567. for ( i = 0; i < YHeight; ++i ) {
  568. lines[ i ].x = MIN4( line1[ i ], line2[ i ], line3[ i ], line4[ i ] );
  569. if ( lines[ i ].x < 0 ) lines[ i ].x = 0;
  570. lines[ i ].y = MAX4( line1[ i ], line2[ i ], line3[ i ], line4[ i ] );
  571. } // end for
  572. for ( j = ( -Ymin < 0 ? 0 : -Ymin ); j < YHeight; ++j ) {
  573. int Yt = sz.cy - ( j + Ymin );
  574. int Yy = j + Ymin;
  575. double XB = lines[ j ].x * DeltaX - Yy * DeltaY - xmin;
  576. double YB = h - ( lines[ j ].x * DeltaY + Yy * DeltaX - ymin );
  577. up[ 0 ].x = lines[ j ].x; up[ 0 ].y = Yt;
  578. up[ 1 ].x = lines[ j ].y; up[ 1 ].y = Yt;
  579. ALLOCATOR -> myHDC.Register ( up, 2 );
  580. for ( i = lines[ j ].x; i <= lines[ j ].y; ++i ) {
  581. SetPixel (
  582. hdc, i, Yt, GetPixel ( hdcMem, ( int )XB, ( int )YB )
  583. );
  584. XB += DeltaX; YB -= DeltaY;
  585. } // end for ( i )
  586. } // end for ( j )
  587. VirtualFree ( ( LPVOID )lines, 0, MEM_DECOMMIT | MEM_RELEASE );
  588. if ( fScale ) {
  589. SelectBitmap( hdcMem, hbo2 );
  590. DeleteBitmap( hBmp );
  591. } // end if
  592. ALLOCATOR -> Xform ();
  593. } // end else
  594. SelectBitmap( hdcMem, hbo );
  595. DeleteDC ( hdcMem );
  596. } // end W32_ImageNote :: Play
  597. ////////////////////////////////////////////////////////////////////////////////
  598. // W 3 2 _ T e x t N o t e //
  599. ////////////////////////////////////////////////////////////////////////////////
  600. W32_TextNote :: W32_TextNote (
  601. int x, int y, double angle, void* text,
  602. BOOL fWide, BOOL fOutlined
  603. ) : W32_PointNote ( x, y ), myAngle ( angle ) {
  604. DWORD dwLen = fWide ? ( ( lstrlenW ( ( LPCWSTR )text ) + 1 ) << 1 )
  605. : ( ( lstrlenA ( ( LPCSTR )text ) + 1 ) << 0 );
  606. myText = ALLOCATOR -> NewData ( dwLen );
  607. CopyMemory ( myText, text, dwLen );
  608. myFlags = ( ( fWide ? W32F_TUNICODE : 0 ) |
  609. ( fOutlined ? W32F_TOUTLINE : 0 )
  610. );
  611. } // end constructor
  612. void W32_TextNote :: Play ( BOOL fDummy ) {
  613. if ( myFlags & W32F_TUNICODE )
  614. ALLOCATOR -> myHDC.ETextOut (
  615. myX, myY, ( wchar_t* )myText, myAngle,
  616. myFlags & W32F_TOUTLINE || ALLOCATOR -> myFlags & W32F_MONO
  617. );
  618. else
  619. ALLOCATOR -> myHDC.ETextOut (
  620. myX, myY, ( char* )myText, myAngle,
  621. myFlags & W32F_TOUTLINE || ALLOCATOR -> myFlags & W32F_MONO
  622. );
  623. } // end W32_TextNote :: Play
  624. ////////////////////////////////////////////////////////////////////////////////
  625. // W 3 2 _ P o l y T e x t N o t e //
  626. ////////////////////////////////////////////////////////////////////////////////
  627. W32_PolyTextNote :: W32_PolyTextNote (
  628. int x, int y, double angle, double margin,
  629. void* text, BOOL fWide, BOOL fOutlined
  630. ) : W32_TextNote ( x, y, angle, text, fWide, fOutlined ),
  631. myMargin ( margin ) {
  632. } // end constructor
  633. void W32_PolyTextNote :: Play ( BOOL fDummy ) {
  634. BOOL fNofill = ( ALLOCATOR -> myFlags & W32F_NOFIL ? TRUE : FALSE );
  635. BOOL fNoframe = ( ALLOCATOR -> myFlags & W32F_POUTL ? FALSE : TRUE );
  636. if ( myFlags & W32F_TUNICODE )
  637. ALLOCATOR -> myHDC.PolyTextOut (
  638. myX, myY, ( wchar_t* )myText, myAngle,
  639. myMargin, myFlags & W32F_TOUTLINE || ALLOCATOR -> myFlags & W32F_MONO, fNofill,
  640. fNoframe
  641. );
  642. else
  643. ALLOCATOR -> myHDC.PolyTextOut (
  644. myX, myY, ( char* )myText, myAngle,
  645. myMargin, myFlags & W32F_TOUTLINE || ALLOCATOR -> myFlags & W32F_MONO, fNofill,
  646. fNoframe
  647. );
  648. } // end W32_PolyTextNote :: Play
  649. ////////////////////////////////////////////////////////////////////////////////
  650. // W 3 2 _ B e g i n M a r k e r N o t e //
  651. ////////////////////////////////////////////////////////////////////////////////
  652. W32_BeginMarkerNote :: W32_BeginMarkerNote (
  653. int x, int y, int w, int h, double angle
  654. ) : W32_PointNote ( x, y ),
  655. myAngle ( angle ), myWidth ( w ), myHeight ( h ) {
  656. } // end constructor
  657. void W32_BeginMarkerNote :: Play ( BOOL fDummy ) {
  658. XFORM xfm;
  659. LOGBRUSH lb = { BS_SOLID, ALLOCATOR -> myMarkerPointColor, 0 };
  660. POINT p = { myX, myY };
  661. if ( ALLOCATOR -> myFlags & W32F_XFORM ) ALLOCATOR -> myHDC.Transform ( &p, 1 );
  662. _InitXform ( &xfm, myAngle, p.x, p.y );
  663. ALLOCATOR -> myHDC.SetWorldTransform ( &xfm );
  664. ALLOCATOR -> myHDC.SelectEPen (
  665. ALLOCATOR -> myMarkerWidth, &lb
  666. );
  667. ALLOCATOR -> myHDC.SelectEBrush (
  668. &ALLOCATOR -> myMarkerBrush,
  669. &ALLOCATOR -> myMarkerBrushOrig
  670. );
  671. } // end W32_BeginMarkerNote :: Play
  672. ////////////////////////////////////////////////////////////////////////////////
  673. // W 3 2 _ E n d M a r k e r N o t e //
  674. ////////////////////////////////////////////////////////////////////////////////
  675. W32_EndMarkerNote :: W32_EndMarkerNote () {}
  676. void W32_EndMarkerNote :: Play ( BOOL fDummy ) {
  677. ALLOCATOR -> Xform ();
  678. ALLOCATOR -> myHDC.SelectEPen ( 0xFFFFFFFF, NULL );
  679. ALLOCATOR -> myHDC.SelectEBrush ( &ALLOCATOR -> myMarkerBrushOrig );
  680. } // end W32_EndMarkerNote :: Play
  681. ////////////////////////////////////////////////////////////////////////////////
  682. ////////////////////////////////////////////////////////////////////////////////
  683. ////////////////////////////////////////////////////////////////////////////////
  684. #define SET_ATTRIB \
  685. ( ((ALLOCATOR->myFlags & W32F_MONO) && (ALLOCATOR->myFlags & W32F_MINIT)) ||\
  686. !(ALLOCATOR->myFlags & W32F_MONO)\
  687. )
  688. ////////////////////////////////////////////////////////////////////////////////
  689. // W 3 2 _ L i n e A t t r i b N o t e //
  690. ////////////////////////////////////////////////////////////////////////////////
  691. W32_LineAttribNote :: W32_LineAttribNote (
  692. DWORD width, PLOGBRUSH plb,
  693. DWORD nStyles, PDWORD pdwStyle
  694. ) {
  695. myPenWidth = width;
  696. myLogBrush = *plb;
  697. myStyleCount = nStyles;
  698. if ( myStyleCount != 0 ) {
  699. DWORD dwLen = nStyles * sizeof ( DWORD );
  700. myStyles = ( PDWORD )ALLOCATOR -> NewData ( dwLen );
  701. CopyMemory ( myStyles, pdwStyle, dwLen );
  702. } // end if
  703. Play ( FALSE );
  704. } // end constructor
  705. void W32_LineAttribNote :: Play ( BOOL fRealize ) {
  706. ALLOCATOR -> myPointColor = myLogBrush.lbColor;
  707. ALLOCATOR -> myLineBrush = myLogBrush;
  708. ALLOCATOR -> myLinePenWidth = myPenWidth;
  709. if ( myStyleCount != 0 ) {
  710. DWORD dwLen = myStyleCount * sizeof ( DWORD );
  711. if ( ALLOCATOR -> myLineStyles != NULL )
  712. ALLOCATOR -> myLineStyles = ( PDWORD )HeapReAlloc (
  713. GetProcessHeap (),
  714. HEAP_GENERATE_EXCEPTIONS,
  715. ALLOCATOR -> myLineStyles,
  716. dwLen
  717. );
  718. else
  719. ALLOCATOR -> myLineStyles = ( PDWORD )HeapAlloc (
  720. GetProcessHeap (),
  721. HEAP_GENERATE_EXCEPTIONS,
  722. dwLen
  723. );
  724. CopyMemory ( ALLOCATOR -> myLineStyles, myStyles, dwLen );
  725. ALLOCATOR -> myLineStyleCount = myStyleCount;
  726. } // end if
  727. if ( fRealize ) ALLOCATOR -> myHDC.SelectEPen (
  728. myPenWidth, &myLogBrush,
  729. myStyleCount, myStyles
  730. );
  731. } // end W32_LineAttribNote :: Play
  732. ////////////////////////////////////////////////////////////////////////////////
  733. // W 3 2 _ P o l y A t t r i b N o t e //
  734. ////////////////////////////////////////////////////////////////////////////////
  735. W32_PolyAttribNote :: W32_PolyAttribNote (
  736. PLOGBRUSH plb, BOOL fDrawEdge, int aFillMode
  737. ) {
  738. myBrush = *plb;
  739. myfEdge = fDrawEdge;
  740. myFillMode = aFillMode;
  741. Play ( FALSE );
  742. } // end constructor
  743. void W32_PolyAttribNote :: Play ( BOOL fRealize ) {
  744. ALLOCATOR -> myFillMode = myFillMode;
  745. if ( myfEdge ) ALLOCATOR -> myFlags |= W32F_POUTL;
  746. else ALLOCATOR -> myFlags &= ~W32F_POUTL;
  747. if ( myBrush.lbStyle == BS_NULL ) ALLOCATOR -> myFlags |= W32F_NOFIL;
  748. else ALLOCATOR -> myFlags &= ~W32F_NOFIL;
  749. ALLOCATOR -> myPolyBrush = myBrush;
  750. if ( fRealize ) {
  751. ALLOCATOR -> myHDC.SelectEBrush ( &myBrush );
  752. ALLOCATOR -> myHDC.SetPolyFillMode ( myFillMode );
  753. } // end if
  754. } // end W32_PolyAttribNote :: Play
  755. ////////////////////////////////////////////////////////////////////////////////
  756. // W 3 2 _ T e x t A t t r i b N o t e //
  757. ////////////////////////////////////////////////////////////////////////////////
  758. W32_TextAttribNote :: W32_TextAttribNote (
  759. HFONT hFont, COLORREF color, double slant,
  760. double hScale, double vScale,
  761. BOOL fUnderlined, BOOL fFree, BOOL fIndex
  762. ) {
  763. myColor = color;
  764. myFont = hFont;
  765. mySlant = slant;
  766. myHScale = vScale;
  767. myVScale = hScale;
  768. myFlags = ( fUnderlined ? W32F_TFULINED : 0 ) |
  769. ( fIndex ? W32F_TINDEX : 0 ) |
  770. ( fFree ? W32F_TFREE : 0 );
  771. Play ( FALSE );
  772. } // end constructor
  773. W32_TextAttribNote :: ~W32_TextAttribNote () {
  774. if ( myFlags & W32F_TFREE ) DeleteFont( myFont );
  775. } // end destructor
  776. void W32_TextAttribNote :: Play ( BOOL fRealize ) {
  777. if ( ( ALLOCATOR -> myFlags & W32F_DFONT ) && !( myFlags & W32F_TINDEX ) ) {
  778. DeleteFont( ALLOCATOR -> myTextFont );
  779. ALLOCATOR -> myFlags &= ~W32F_DFONT;
  780. } // end if
  781. ALLOCATOR -> myTextFont = myFont;
  782. ALLOCATOR -> myTextSlant = mySlant;
  783. ALLOCATOR -> myTextHScale = myHScale;
  784. ALLOCATOR -> myTextVScale = myVScale;
  785. if ( myFlags & W32F_TFULINED ) ALLOCATOR -> myFlags |= W32F_TULIN;
  786. else ALLOCATOR -> myFlags &= ~W32F_TULIN;
  787. ALLOCATOR -> myTextColor = myColor;
  788. if ( fRealize && !( myFlags & W32F_TINDEX ) )
  789. ALLOCATOR -> myHDC.SetTextAttrib (
  790. myColor, myFont, mySlant,
  791. myHScale, myVScale
  792. );
  793. } // end W32_TextAttribNote :: Play
  794. ////////////////////////////////////////////////////////////////////////////////
  795. // W 3 2 _ M a r k e r A t t r i b N o t e //
  796. ////////////////////////////////////////////////////////////////////////////////
  797. W32_MarkerAttribNote :: W32_MarkerAttribNote (
  798. COLORREF color, DWORD dwWidth, BOOL fFill
  799. ) {
  800. myLogBrush.lbStyle = fFill;
  801. myLogBrush.lbColor = color;
  802. myLogBrush.lbHatch = dwWidth;
  803. Play ();
  804. } // end constructor
  805. void W32_MarkerAttribNote :: Play ( BOOL fDummy ) {
  806. ALLOCATOR -> myMarkerBrush.lbStyle = BS_SOLID;
  807. ALLOCATOR -> myMarkerBrush.lbColor = ALLOCATOR -> myPolyBrush.lbColor;
  808. ALLOCATOR -> myMarkerBrush.lbHatch = 0;
  809. ALLOCATOR -> myMarkerWidth = myLogBrush.lbHatch;
  810. ALLOCATOR -> myMarkerPointColor = myLogBrush.lbColor;
  811. if ( myLogBrush.lbStyle )
  812. ALLOCATOR -> myFlags |= W32F_MFILL;
  813. else
  814. ALLOCATOR -> myFlags &= ~W32F_MFILL;
  815. } // end W32_MarkerAttribNote :: Play
  816. ////////////////////////////////////////////////////////////////////////////////
  817. // W 3 2 _ F C a l l N o t e //
  818. ////////////////////////////////////////////////////////////////////////////////
  819. W32_FCallNote :: W32_FCallNote (
  820. W32_FCall fCall, int sz, PW32_FCALLPARAM param
  821. ) {
  822. myFunc = fCall;
  823. myParam = ( PW32_FCALLPARAM )ALLOCATOR -> NewData ( sz );
  824. CopyMemory ( myParam, param, sz );
  825. } // end constructor
  826. void W32_FCallNote :: Play ( BOOL fDummy ) {
  827. ( *myFunc ) ( myParam );
  828. } // end W32_FCallNote :: Play
  829. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
  830. // M i s c e l l a n e o u s +//
  831. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//
  832. static void WINAPI _InitXform ( PXFORM pxf, double angle, int x, int y ) {
  833. double cosVal, sinVal;
  834. cosVal = cos ( angle );
  835. sinVal = sin ( angle );
  836. pxf -> eM11 = ( FLOAT ) cosVal; pxf -> eM12 = ( FLOAT )sinVal;
  837. pxf -> eM21 = ( FLOAT )-sinVal; pxf -> eM22 = ( FLOAT )cosVal;
  838. pxf -> eDx = ( FLOAT ) x; pxf -> eDy = ( FLOAT ) y;
  839. } // end _InitXform
  840. static VOID CALLBACK _LineDDAProc ( int x, int y, LPARAM lpData ) {
  841. ( ( PINT )lpData )[ y ] = x;
  842. } // end LineDDAProc
  843. //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++//