window.pp 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524
  1. (******************************************************************************
  2. *
  3. * Copyright (c) 1994-2000 Palm, Inc. or its subsidiaries.
  4. * All rights reserved.
  5. *
  6. * File: Window.h
  7. *
  8. * Release: Palm OS SDK 4.0 (63220)
  9. *
  10. * Description:
  11. * This file defines window structures and routines that support color.
  12. *
  13. * History:
  14. * January 20, 1999 Created by Bob Ebert
  15. * Name Date Description
  16. * ---- ---- -----------
  17. * bob 1/20/99 Branch off WindowNew.h
  18. * BS 4/20/99 Re-design of the screen driver
  19. * bob 5/26/99 Cleanup/reorg
  20. * jmp 12/23/99 Fix <> vs. "" problem.
  21. *
  22. *****************************************************************************)
  23. {$MACRO ON}
  24. unit window;
  25. interface
  26. uses palmos, coretraps, rect, errorbase, bitmap;
  27. const
  28. kWinVersion = 3;
  29. // enum for WinScrollRectangle
  30. type
  31. WinDirectionType = Enum;
  32. const
  33. winUp = 0;
  34. winDown = Succ(winUp);
  35. winLeft = Succ(winDown);
  36. winRight = Succ(winLeft);
  37. // enum for WinCreateOffscreenWindow
  38. type
  39. WindowFormatType = Enum;
  40. const
  41. screenFormat = 0;
  42. genericFormat = Succ(screenFormat);
  43. // enum for WinLockScreen
  44. type
  45. WinLockInitType = Enum;
  46. const
  47. winLockCopy = 0;
  48. winLockErase = Succ(winLockCopy);
  49. winLockDontCare = Succ(winLockErase);
  50. // operations for the WinScreenMode function
  51. type
  52. WinScreenModeOperation = Enum;
  53. const
  54. winScreenModeGetDefaults = 0;
  55. winScreenModeGet = Succ(winScreenModeGetDefaults);
  56. winScreenModeSetToDefaults = Succ(winScreenModeGet);
  57. winScreenModeSet = Succ(winScreenModeSetToDefaults);
  58. winScreenModeGetSupportedDepths = Succ(winScreenModeSet);
  59. winScreenModeGetSupportsColor = Succ(winScreenModeGetSupportedDepths);
  60. // Operations for the WinPalette function
  61. const
  62. winPaletteGet = 0;
  63. winPaletteSet = 1;
  64. winPaletteSetToDefault = 2;
  65. winPaletteInit = 3; // for internal use only
  66. // transfer modes for color drawing
  67. type
  68. WinDrawOperation = Enum;
  69. const
  70. winPaint = 0;
  71. winErase = Succ(winPaint);
  72. winMask = Succ(winErase);
  73. winInvert = Succ(winMask);
  74. winOverlay = Succ(winInvert);
  75. winPaintInverse = Succ(winOverlay);
  76. winSwap = Succ(winPaintInverse);
  77. type
  78. PatternType = Enum;
  79. const
  80. blackPattern = 0;
  81. whitePattern = Succ(blackPattern);
  82. grayPattern = Succ(whitePattern);
  83. customPattern = Succ(grayPattern);
  84. const
  85. noPattern = blackPattern;
  86. grayHLinePattern = $AA;
  87. grayHLinePatternOdd = $55;
  88. // grayUnderline means dotted current foreground color
  89. // solidUnderline means solid current foreground color
  90. // colorUnderline redundant, use solidUnderline instead
  91. type
  92. UnderlineModeType = Enum;
  93. const
  94. noUnderline = 0;
  95. grayUnderline = Succ(noUnderline);
  96. solidUnderline = Succ(grayUnderline);
  97. colorUnderline = Succ(solidUnderline);
  98. const
  99. WinMaxSupportedDepth = 8;
  100. WinNumSupportedColors = 4;
  101. type
  102. IndexedColorType = UInt8; // 1-, 2-, 4-, or 8-bit index
  103. CustomPatternType = array [0..7] of UInt8; // 8x8 1-bit deep pattern
  104. CustomPatternPtr = ^CustomPatternType;
  105. // for WinPalette startIndex value, respect indexes in passed table
  106. const
  107. WinUseTableIndexes = -1;
  108. //-----------------------------------------------
  109. // Draw state structures.
  110. //-----------------------------------------------
  111. type
  112. DrawStateType = record
  113. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_WINDOWS} // These fields will not be available in the next OS release!
  114. transferMode: WinDrawOperation;
  115. pattern: PatternType;
  116. underlineMode: UnderlineModeType;
  117. fontId: FontID;
  118. font: FontPtr;
  119. patternData: CustomPatternType;
  120. // These are only valid for indexed color bitmaps
  121. foreColor: IndexedColorType;
  122. backColor: IndexedColorType;
  123. textColor: IndexedColorType;
  124. reserved: UInt8;
  125. // These are only valid for direct color bitmaps
  126. foreColorRGB: RGBColorType;
  127. backColorRGB: RGBColorType;
  128. textColorRGB: RGBColorType;
  129. {$endif}
  130. end;
  131. const
  132. DrawStateStackSize = 5; // enough for a control in a field in a window
  133. //-----------------------------------------------
  134. // The Window Structures.
  135. //-----------------------------------------------
  136. type
  137. FrameBitsType = record
  138. case Integer of
  139. 1: (bits: UInt16);
  140. {
  141. (
  142. UInt16 cornerDiam : 8; // corner diameter, max 38
  143. UInt16 reserved_3 : 3;
  144. UInt16 threeD : 1; // Draw 3D button
  145. UInt16 shadowWidth : 2; // Width of shadow
  146. UInt16 width : 2; // Width frame
  147. ) bits;
  148. }
  149. 2: (word: UInt16); // IMPORTANT: INITIALIZE word to zero before setting bits!
  150. end;
  151. FrameType = UInt16;
  152. // Standard Frame Types
  153. const
  154. noFrame = 0;
  155. simpleFrame = 1;
  156. rectangleFrame = 1;
  157. simple3DFrame = $0012; // 3d, frame = 2
  158. roundFrame = $0401; // corner = 7, frame = 1
  159. boldRoundFrame = $0702; // corner = 7, frame = 2
  160. popupFrame = $0205; // corner = 2, frame = 1, shadow = 1
  161. dialogFrame = $0302; // corner = 3, frame = 2
  162. menuFrame = popupFrame;
  163. winDefaultDepthFlag = $FF;
  164. type
  165. WindowFlagsType = record
  166. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_WINDOWS} // These fields will not be available in the next OS release!
  167. Bits: UInt16;
  168. {
  169. UInt16 format:1; // window format: 0=screen mode; 1=generic mode
  170. UInt16 offscreen:1; // offscreen flag: 0=onscreen ; 1=offscreen
  171. UInt16 modal:1; // modal flag: 0=modeless window; 1=modal window
  172. UInt16 focusable:1; // focusable flag: 0=non-focusable; 1=focusable
  173. UInt16 enabled:1; // enabled flag: 0=disabled; 1=enabled
  174. UInt16 visible:1; // visible flag: 0-invisible; 1=visible
  175. UInt16 dialog:1; // dialog flag: 0=non-dialog; 1=dialog
  176. UInt16 freeBitmap:1; // free bitmap w/window: 0=don't free, 1=free
  177. UInt16 reserved :8;
  178. }
  179. {$endif}
  180. end;
  181. WindowType = record
  182. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_WINDOWS} // These fields will not be available in the next OS release!
  183. displayWidthV20: Coord; // use WinGetDisplayExtent instead
  184. displayHeightV20: Coord; // use WinGetDisplayExtent instead
  185. displayAddrV20: Pointer; // use the drawing functions instead
  186. windowFlags: WindowFlagsType;
  187. windowBounds: RectangleType;
  188. clippingBounds: AbsRectType;
  189. bitmapP: BitmapPtr;
  190. frameType: FrameBitsType;
  191. drawStateP: ^DrawStateType; // was GraphicStatePtr
  192. nextWindow: ^WindowType;
  193. {$endif}
  194. end;
  195. WinPtr = ^WindowType;
  196. WinHandle = ^WindowType;
  197. //-----------------------------------------------
  198. // More graphics shapes
  199. //-----------------------------------------------
  200. WinLineType = record
  201. x1: Coord;
  202. y1: Coord;
  203. x2: Coord;
  204. y2: Coord;
  205. end;
  206. WinLinePtr = ^WinLineType;
  207. // Rectangles, Points defined in Rect.h
  208. //-----------------------------------------------
  209. // Low Memory Globals
  210. //-----------------------------------------------
  211. // This is the structure of a low memory global reserved for the Window Manager
  212. // In GRAPHIC_VERSION_2, it held a single drawing state. In this version, it
  213. // holds stack information for structures that are allocated from the dynamic heap
  214. GraphicStateType = record
  215. {$ifdef ALLOW_ACCESS_TO_INTERNALS_OF_WINDOWS} // These fields will not be available in the next OS release!
  216. drawStateP: ^DrawStateType;
  217. drawStateStackP: ^DrawStateType;
  218. drawStateIndex: Int16;
  219. unused: UInt16; //was screenLockCount
  220. {$endif}
  221. end;
  222. // ----------------------
  223. // Window manager errors
  224. // ----------------------
  225. const
  226. winErrPalette = winErrorClass or 1;
  227. //-----------------------------------------------
  228. // Macros
  229. //-----------------------------------------------
  230. // For now, the window handle is a pointer to a window structure,
  231. // this however may change, so use the following macros.
  232. function WinGetWindowPointer(winHandle: WinHandle): WinPtr;
  233. function WinGetWindowHandle(winPtr: WinPtr): WinHandle;
  234. //-----------------------------------------------
  235. // Routines relating to windows management
  236. //-----------------------------------------------
  237. function WinValidateHandle(winHandle: WinHandle): Boolean; syscall sysTrapWinValidateHandle;
  238. function WinCreateWindow({const} var bounds: RectangleType; frame: FrameType; modal, focusable: Boolean;
  239. var error: UInt16): WinHandle; syscall sysTrapWinCreateWindow;
  240. function WinCreateOffscreenWindow(width, height: Coord; format: WindowFormatType; var error: UInt16): WinHandle; syscall sysTrapWinCreateOffscreenWindow;
  241. function WinCreateBitmapWindow(bitmapP: BitmapPtr; var error: UInt16): WinHandle; syscall sysTrapWinCreateBitmapWindow;
  242. procedure WinDeleteWindow(winHandle: WinHandle; eraseIt: Boolean); syscall sysTrapWinDeleteWindow;
  243. procedure WinInitializeWindow(winHandle: WinHandle); syscall sysTrapWinInitializeWindow;
  244. procedure WinAddWindow(winHandle: WinHandle); syscall sysTrapWinAddWindow;
  245. procedure WinRemoveWindow(winHandle: WinHandle); syscall sysTrapWinRemoveWindow;
  246. procedure WinMoveWindowAddr(oldLocationP, newLocationP: WinPtr); syscall sysTrapWinMoveWindowAddr;
  247. procedure WinSetActiveWindow(winHandle: WinHandle); syscall sysTrapWinSetActiveWindow;
  248. function WinSetDrawWindow(winHandle: WinHandle): WinHandle; syscall sysTrapWinSetDrawWindow;
  249. function WinGetDrawWindow: WinHandle; syscall sysTrapWinGetDrawWindow;
  250. function WinGetActiveWindow: WinHandle; syscall sysTrapWinGetActiveWindow;
  251. function WinGetDisplayWindow: WinHandle; syscall sysTrapWinGetDisplayWindow;
  252. function WinGetFirstWindow: WinHandle; syscall sysTrapWinGetFirstWindow;
  253. procedure WinEnableWindow(winHandle: WinHandle); syscall sysTrapWinEnableWindow;
  254. procedure WinDisableWindow(winHandle: WinHandle); syscall sysTrapWinDisableWindow;
  255. procedure WinGetWindowFrameRect(winHandle: WinHandle; var r: RectangleType); syscall sysTrapWinGetWindowFrameRect;
  256. procedure WinDrawWindowFrame; syscall sysTrapWinDrawWindowFrame;
  257. procedure WinEraseWindow; syscall sysTrapWinEraseWindow;
  258. function WinSaveBits({const} var source: RectangleType; var error: UInt16): WinHandle; syscall sysTrapWinSaveBits;
  259. procedure WinRestoreBits(winHandle: WinHandle; destX, destY: Coord); syscall sysTrapWinRestoreBits;
  260. procedure WinCopyRectangle(srcWin, dstWin: WinHandle; {const} var srcRect: RectangleType;
  261. destX, destY: Coord; mode: WinDrawOperation); syscall sysTrapWinCopyRectangle;
  262. procedure WinScrollRectangle({const} var rP: RectangleType; direction: WinDirectionType;
  263. distance: Coord; var vacatedP: RectangleType); syscall sysTrapWinScrollRectangle;
  264. procedure WinGetDisplayExtent(var extentX, extentY: Coord); syscall sysTrapWinGetDisplayExtent;
  265. procedure WinGetDrawWindowBounds(var rP: RectangleType); syscall sysTrapWinGetDrawWindowBounds;
  266. procedure WinGetBounds(winH: WinHandle; var rP: RectangleType); syscall sysTrapWinGetBounds;
  267. procedure WinSetBounds(winHandle: WinHandle; {const} var rP: RectangleType); syscall sysTrapWinSetBounds;
  268. {$ifdef ALLOW_OLD_API_NAMES}
  269. procedure WinGetWindowBounds(var rP: RectangleType); syscall sysTrapWinGetWindowBounds;
  270. procedure WinSetWindowBounds(winHandle: WinHandle; {const} var rP: RectangleType); syscall WinSetWindowBounds;
  271. {$endif}
  272. procedure WinGetWindowExtent(var extentX, extentY: Coord); syscall sysTrapWinGetWindowExtent;
  273. procedure WinDisplayToWindowPt(var extentX, extentY: Coord); syscall sysTrapWinDisplayToWindowPt;
  274. procedure WinWindowToDisplayPt(var extentX, extentY: Coord); syscall sysTrapWinWindowToDisplayPt;
  275. function WinGetBitmap(winHandle: WinHandle): BitmapPtr; syscall sysTrapWinGetBitmap;
  276. procedure WinGetClip(var rP: RectangleType); syscall sysTrapWinGetClip;
  277. procedure WinSetClip({const} var rP: RectangleType); syscall sysTrapWinSetClip;
  278. procedure WinResetClip; syscall sysTrapWinResetClip;
  279. procedure WinClipRectangle(var rP: RectangleType); syscall sysTrapWinClipRectangle;
  280. function WinModal(winHandle: WinHandle): Boolean; syscall sysTrapWinModal;
  281. //-----------------------------------------------
  282. // Routines to draw shapes or frames shapes
  283. //-----------------------------------------------
  284. // Pixel(s)
  285. function WinGetPixel(x, y: Coord): IndexedColorType; syscall sysTrapWinGetPixel;
  286. procedure WinPaintPixel(x, y: Coord); syscall sysTrapWinPaintPixel; // uses drawing mode
  287. function WinGetPixelRGB (x, y: Coord; var rgbP: RGBColorType): Err; syscall sysTrapWinGetPixelRGB; // Direct color version
  288. procedure WinDrawPixel(x, y: Coord); syscall sysTrapWinDrawPixel;
  289. procedure WinErasePixel(x, y: Coord); syscall sysTrapWinErasePixel;
  290. procedure WinInvertPixel(x, y: Coord); syscall sysTrapWinInvertPixel;
  291. procedure WinPaintPixels(numPoints: UInt16; pts: PointPtr); syscall sysTrapWinPaintPixels;
  292. // Line(s)
  293. procedure WinPaintLines(numLines: UInt16; lines: WinLinePtr); syscall sysTrapWinPaintLines;
  294. procedure WinPaintLine(x1, y1, x2, y2: Coord); syscall sysTrapWinPaintLine;
  295. procedure WinDrawLine(x1, y1, x2, y2: Coord); syscall sysTrapWinDrawLine;
  296. procedure WinDrawGrayLine(x1, y1, x2, y2: Coord); syscall sysTrapWinDrawGrayLine;
  297. procedure WinEraseLine(x1, y1, x2, y2: Coord); syscall sysTrapWinEraseLine;
  298. procedure WinInvertLine(x1, y1, x2, y2: Coord); syscall sysTrapWinInvertLine;
  299. procedure WinFillLine(x1, y1, x2, y2: Coord); syscall sysTrapWinFillLine;
  300. // Rectangle
  301. procedure WinPaintRectangle({const} var rP: RectangleType; cornerDiam: UInt16); syscall sysTrapWinPaintRectangle;
  302. procedure WinDrawRectangle({const} var rP: RectangleType; cornerDiam: UInt16); syscall sysTrapWinDrawRectangle;
  303. procedure WinEraseRectangle({const} var rP: RectangleType; cornerDiam: UInt16); syscall sysTrapWinEraseRectangle;
  304. procedure WinInvertRectangle({const} var rP: RectangleType; cornerDiam: UInt16); syscall sysTrapWinInvertRectangle;
  305. procedure WinFillRectangle({const} var rP: RectangleType; cornerDiam: UInt16); syscall sysTrapWinFillRectangle;
  306. // Rectangle frames
  307. procedure WinPaintRectangleFrame(frame: FrameType; {const} var rP: RectangleType); syscall sysTrapWinPaintRectangleFrame;
  308. procedure WinDrawRectangleFrame(frame: FrameType; {const} var rP: RectangleType); syscall sysTrapWinDrawRectangleFrame;
  309. procedure WinDrawGrayRectangleFrame(frame: FrameType; {const} var rP: RectangleType); syscall sysTrapWinDrawGrayRectangleFrame;
  310. procedure WinEraseRectangleFrame(frame: FrameType; {const} var rP: RectangleType); syscall sysTrapWinEraseRectangleFrame;
  311. procedure WinInvertRectangleFrame(frame: FrameType; {const} var rP: RectangleType); syscall sysTrapWinInvertRectangleFrame;
  312. procedure WinGetFramesRectangle(frame: FrameType; {const} var rP, obscuredRect: RectangleType); syscall sysTrapWinGetFramesRectangle;
  313. // Bitmap
  314. procedure WinDrawBitmap(bitmapP: BitmapPtr; x, y: Coord); syscall sysTrapWinDrawBitmap;
  315. procedure WinPaintBitmap(bitmapP: BitmapPtr; x, y: Coord); syscall sysTrapWinPaintBitmap;
  316. // Characters
  317. procedure WinDrawChar(theChar: WChar; x, y: Coord); syscall sysTrapWinDrawChar;
  318. procedure WinDrawChars(const chars: PChar; len: Int16; x, y: Coord); syscall sysTrapWinDrawChars;
  319. procedure WinPaintChar(theChar: WChar; x, y: Coord); syscall sysTrapWinPaintChar;
  320. procedure WinPaintChars(const chars: PChar; len: Int16; x, y: Coord); syscall sysTrapWinPaintChars;
  321. procedure WinDrawInvertedChars(const chars: PChar; len: Int16; x, y: Coord); syscall sysTrapWinDrawInvertedChars;
  322. procedure WinDrawTruncChars(const chars: PChar; len: Int16; x, y, maxWidth: Coord); syscall sysTrapWinDrawTruncChars;
  323. procedure WinEraseChars(const chars: PChar; len: Int16; x, y: Coord); syscall sysTrapWinEraseChars;
  324. procedure WinInvertChars(const chars: PChar; len: Int16; x, y: Coord); syscall sysTrapWinInvertChars;
  325. function WinSetUnderlineMode(mode: UnderlineModeType): UnderlineModeType; syscall sysTrapWinSetUnderlineMode;
  326. //-----------------------------------------------
  327. // Routines for patterns and colors
  328. //-----------------------------------------------
  329. procedure WinPushDrawState; syscall sysTrapWinPushDrawState; // "save" fore, back, text color, pattern, underline mode, font
  330. procedure WinPopDrawState; syscall sysTrapWinPopDrawState; // "restore" saved drawing variables
  331. function WinSetDrawMode(newMode: WinDrawOperation): WinDrawOperation; syscall sysTrapWinSetDrawMode;
  332. function WinSetForeColor(foreColor: IndexedColorType): IndexedColorType; syscall sysTrapWinSetForeColor;
  333. function WinSetBackColor(backColor: IndexedColorType): IndexedColorType; syscall sysTrapWinSetBackColor;
  334. function WinSetTextColor(textColor: IndexedColorType): IndexedColorType; syscall sysTrapWinSetTextColor;
  335. // Direct color versions
  336. procedure WinSetForeColorRGB(const newRgbP: RGBColorPtr; prevRgbP: RGBColorPtr); syscall sysTrapWinSetForeColorRGB;
  337. procedure WinSetBackColorRGB(const newRgbP: RGBColorPtr; prevRgbP: RGBColorPtr); syscall sysTrapWinSetBackColorRGB;
  338. procedure WinSetTextColorRGB(const newRgbP: RGBColorPtr; prevRgbP: RGBColorPtr); syscall sysTrapWinSetTextColorRGB;
  339. procedure WinGetPattern(patternP: CustomPatternPtr); syscall sysTrapWinGetPattern;
  340. function WinGetPatternType: PatternType; syscall sysTrapWinGetPatternType;
  341. procedure WinSetPattern(const patternP: CustomPatternPtr); syscall sysTrapWinSetPattern;
  342. procedure WinSetPatternType(newPattern: PatternType); syscall sysTrapWinSetPatternType;
  343. function WinPalette(operation: UInt8; startIndex: Int16; paletteEntries: UInt16; tableP: RGBColorPtr): Err; syscall sysTrapWinPalette;
  344. function WinRGBToIndex(const rgbP: RGBColorPtr): IndexedColorType; syscall sysTrapWinRGBToIndex;
  345. procedure WinIndexToRGB(i: IndexedColorType; rgbP: RGBColorPtr); syscall sysTrapWinIndexToRGB;
  346. // "obsolete" color call, supported for backwards compatibility
  347. procedure WinSetColors(const newForeColorP: RGBColorPtr; oldForeColorP: RGBColorPtr;
  348. const newBackColorP: RGBColorPtr; oldBackColorP: RGBColorPtr); syscall sysTrapWinSetColors;
  349. //-----------------------------------------------
  350. // WinScreen functions
  351. //-----------------------------------------------
  352. procedure WinScreenInit; syscall sysTrapWinScreenInit;
  353. function WinScreenMode(operation: WinScreenModeOperation; var widthP, heightP, depthP: UInt32;
  354. var enableColorP: Boolean): Err; syscall sysTrapWinScreenMode;
  355. //-----------------------------------------------
  356. // Screen tracking (double buffering) support
  357. //-----------------------------------------------
  358. function WinScreenLock(initMode: WinLockInitType): UInt8Ptr; syscall sysTrapWinScreenLock;
  359. procedure WinScreenUnlock; syscall sysTrapWinScreenUnlock;
  360. implementation
  361. function WinGetWindowPointer(winHandle: WinHandle): WinPtr;
  362. begin
  363. WinGetWindowPointer := winHandle;
  364. end;
  365. function WinGetWindowHandle(winPtr: WinPtr): WinHandle;
  366. begin
  367. WinGetWindowHandle := winPtr
  368. end;
  369. end.