Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

364 lines
23 KiB

  1. /**************************************************************************
  2. *
  3. * THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY
  4. * KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  5. * IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A PARTICULAR
  6. * PURPOSE.
  7. *
  8. * Copyright (c) 1992 - 1995 Microsoft Corporation. All Rights Reserved.
  9. *
  10. **************************************************************************/
  11. /****************************************************************************
  12. *
  13. * toolbar.h: Toolbar include file
  14. *
  15. * Vidcap32 Source code
  16. *
  17. ***************************************************************************/
  18. /*****************************************************************************
  19. * *
  20. * Program Description: Implements a generic toolbar. *
  21. * *
  22. * Here's how to use it: *
  23. * *
  24. * Include the source files "toolbar.h" and "toolbar.c" in your *
  25. * application. *
  26. * *
  27. * Include a line in your application's RC file that gives a file *
  28. * name with a resource id eg. IDBMP_BUTTONS. This is a .BMP file that *
  29. * contains all of the pictures of the buttons you want on your toolbar. *
  30. * Also, make a define for your label with a unique value. If your app has *
  31. * more than one toolbar, and all toolbars don't share a bitmap file, then *
  32. * you will need several defines. *
  33. * *
  34. * e.g. IDBMP_BUTTONS BITMAP "buttons.bmp" *
  35. * IDBMP_ARROWS BITMAP "arrows.bmp" *
  36. * *
  37. * This file must have the different buttons across horizontally *
  38. * and the different states for these buttons vertically. Change the *
  39. * defines in this header file to match the button names and state names of *
  40. * your buttons. You must include the states listed here, and actually *
  41. * you probably won't need to change them at all. The numbers for a button *
  42. * or state are indexes into the bitmap, so the pictures must match. *
  43. * *
  44. * STATE DESCRIPTIONS: *
  45. * GRAYED: The button cannot be pressed & is inactive *
  46. * UP: The button is up *
  47. * DOWN: The button is down *
  48. * FOCUSUP: The button is up and is the one with focus *
  49. * FOCUSDOWN: The button is down and is the one with focus*
  50. * FULLDOWN: A checkbox button has this additional state *
  51. * where it is all the way down when pressed *
  52. * and when it is let go, it will go into *
  53. * either the UP or DOWN state (maybe focused) *
  54. * *
  55. * When you draw the pictures, make sure to get the right state in the right *
  56. * vertical position in the bitmap to match the #define's. *
  57. * *
  58. * A button can also have a type associated with it: *
  59. * *
  60. * PUSH: When pressed it goes down, when let go it bounces *
  61. * up. Therefore, when you aren't currently holding *
  62. * the mouse button or space bar on it, it will *
  63. * ALWAYS be in the up position. It can be in any *
  64. * state except FULLDOWN, which is invalid. *
  65. * *
  66. * CHECKBOX: This button can be up or down. When pushed, it *
  67. * toggles into the opposite state. However, it *
  68. * is always in the FULLDOWN state when being held *
  69. * down with the mouse button or space bar, and when *
  70. * let go, it will go into the opposite state of what *
  71. * it was in before you pressed it. E.G. The button *
  72. * is up. You press it, and it goes way down. You let *
  73. * go, and it comes up a bit, but it's still down. You*
  74. * press it again, and it goes further down before *
  75. * popping all the way up. *
  76. * *
  77. * RADIO: This is a group of buttons that can be up or down, *
  78. * and also have the intermediate step of being *
  79. * FULLDOWN when being held down. But, when you *
  80. * push one of the radio buttons down, all other radio *
  81. * buttons in its group will pop up. Any group can *
  82. * have only 1 down at a time, and 1 must be down. *
  83. * *
  84. * CUSTOM: If your application is wierd, you can have a custom *
  85. * type button that does anything you want it to. *
  86. * *
  87. * First, your app must call: toolbarInit(hInst, hPrev); *
  88. * with the two instance parameters to register a toolbar window class. *
  89. * Then your app is free to call CreateWindow with a class of *
  90. * szToolBarClass to create one or more toolbar windows anywhere it wants *
  91. * and of any size it wants, presumably as the child window of another of the*
  92. * app's windows. The file that creates the window must declare an *
  93. * extern char szToolBarClass[]; All messages about activity to a toolbar *
  94. * button will go to the parent window of the toolbar. *
  95. * *
  96. * Next, call: toolbarSetBitmap(HWND hwnd, HANDLE hInst, int ibmp, *
  97. * POINT ptSize); *
  98. * Pass it the resource ID (eg. IDBMP_BUTTONS) to tell the toolbar where to *
  99. * find the pictures for the buttons. Also pass a point with the width and *
  100. * height of each button (eg. 24 X 22) so it knows how to find individual *
  101. * buttons in the bitmap file. *
  102. * *
  103. * Next, call: toolbarAddTool(HWND hwnd, TOOLBUTTON tb); *
  104. * as many times as you want to add a button to the toolbar specified by *
  105. * hwnd. You fill in the "tb" struct with the following information: *
  106. * *
  107. * tb.rc = the rect in the toolbar window to place the button *
  108. * based at 0,0 and measured in pixels. *
  109. * tb.iButton = the ID of the button you wish the add (which is *
  110. * the horizontal offset into the bitmap of buttons). *
  111. * Only one of each button allowed. Use one of the *
  112. * defines (BTN_??????). *
  113. * tb.iState = the initial state of the button (GRAYED, UP, DOWN). *
  114. * If you wish, you can specify a FOCUS'ed state to give *
  115. * any button you wish the focus. By default, it's the *
  116. * one furthest left and tabbing order goes to the right.*
  117. * This is the vertical offset into the bitmap. *
  118. * Use one of the defines (BTNST_?????). *
  119. * tb.iType = The type of button (BTNTYPE_???). Either pushbutton, *
  120. * checkbox, or radio button. (or custom). If it is a *
  121. * radio button, you can have many groups of radio btn's *
  122. * on the same toolbar. Type BTNTYPE_RADIO is one group.*
  123. * Use BTNTYPE_RADIO+1 for another group, BTNTYPE_RADIO+2*
  124. * for a third group, etc. You have thousands. *
  125. * tb.iString = The resource ID of a string to be associated with *
  126. * this button (if you'd like). *
  127. * *
  128. * *
  129. * At any time in the app, you can call toolbarAddTool to add more buttons *
  130. * or toolbarRemoveTool to take some away. To take one away, identify it *
  131. * with it's button ID (horizontal offset in the bitmap). *
  132. * *
  133. * You can also call toolbarRetrieveTool to get the TOOLBUTTON struct back *
  134. * from a button that is on the toolbar. This is the way to change a *
  135. * button's position. Change the tb.rc and then Remove and Add the button *
  136. * again so that the tabbing order will be re-calculated based on the new *
  137. * rect of the tool. *
  138. * *
  139. * Now, all buttons will automatically behave properly. They'll go up and *
  140. * down as you press on them, or use the keyboard, groups of radio buttons *
  141. * will pop up as you press a different one down, etc. etc. etc. *
  142. * You don't have to do a thing! *
  143. * *
  144. * The parent of the toolbar window will get a WM_COMMAND message with *
  145. * a wParam of IDC_TOOLBAR whenever anything happens to a button. *
  146. * The LOWORD of the lParam is the hwnd of the toolbar window that has the *
  147. * button on it. The (HIWORD & 0xFF) is the button ID of the button. *
  148. * Remember to change IDC_TOOLBAR to something unique. *
  149. * *
  150. * The app can then call toolbarIndexFromButton(hwnd, buttonID) *
  151. * to get the index of the button (used for subsequent calls). *
  152. * *
  153. * Then call: toolbarStateFromButton(hwnd, buttonID) *
  154. * *
  155. * to get either BTNST_UP or BTNST_DOWN. This is the *
  156. * NEW state of the button since the activity on the *
  157. * button. It can also be BTNST_GRAYED, but you won't get *
  158. * any activity messages while it's grayed, unless it is a *
  159. * cutsom button. *
  160. * *
  161. * Call toolbarFullStateFromButton(hwnd, buttonID) *
  162. * *
  163. * to get more detail about the state. It can also return *
  164. * BTNST_FULLDOWN as well as the above states. In the case *
  165. * of BTNST_FULLDOWN, you'll have to call *
  166. * toolbarPrevStateFromButton(hwnd, btn ID) to get the state*
  167. * before it went full down. *
  168. * *
  169. * toolbarPrevStateFromButton(hwnd, buttonID) *
  170. * *
  171. * is only valid when the state is BTNST_FULLDOWN. *
  172. * *
  173. * toolbarActivityFromIndex(hwnd, buttonID) *
  174. * *
  175. * tells you what just happened to the button. *
  176. * BTNACT_KEYDOWN, BTNACT_MOUSEUP, etc. are possibilities. *
  177. * BTNACT_MOUSEMOUSEOFF means that they pressed it down and *
  178. * moved the mouse off of the button ( so it was re- drawn *
  179. * in its previous state before being pressed). *
  180. * BTNACT_MOUSEMOUSEON means that the above happened and *
  181. * then the mouse moved back on top of the button again, so *
  182. * the button was re-drawn as if it was pushed again. *
  183. * *
  184. * For any of the above activities....... *
  185. * *
  186. * HIWORD & BTN_SHIFT is set if this activity involves the right mouse *
  187. * button, or else it is clear. *
  188. * HIWORD & BTN_DBLCLICK is set means that this mouse button down activity *
  189. * is really a double click (if you care). *
  190. * *
  191. * If you are a custom button, you can also receive this message... *
  192. * *
  193. * HIWORD & BTN_REPEAT is set means that the button or key is being held *
  194. * down, and you are being sent many down messages *
  195. * in a row. The first such message is sent with *
  196. * this flag clear, all others have this flag set. *
  197. * If you are a custom button, you will have to *
  198. * ignore messages that are repeats if you don't *
  199. * want to get many down messages in a row. *
  200. * *
  201. * *
  202. * toolbarStringFromIndex(hwnd, index) *
  203. * *
  204. * will return you the string resource ID you gave when *
  205. * you registered this button. *
  206. * *
  207. * *
  208. * IMPORTANT !!!!!!!!!!!!!!!!!!! *
  209. * ============================= *
  210. * *
  211. * When you get the state of a button, it's already been changed by the *
  212. * activity so it's the NEW STATE!!!!!!!!! *
  213. * *
  214. * EXCEPT!!! for a custom button! For a custom button, NOTHING WILL *
  215. * happen, you have to do it all yourself!!!! So the state is going to be *
  216. * the state BEFORE the activity and you have to call *
  217. * toolbarModifyState(hwnd, buttonID, newState) to change the state *
  218. * yourself!!!! *
  219. * *
  220. * You also have toolbarGetNumButtons(hwnd) to tell you how many are on the *
  221. * the toolbar. *
  222. * And... you have other routines you can use if you really want. *
  223. * *
  224. * ENJOY!! *
  225. * *
  226. * P.S. Don't forget to pass on WM_SYSCOLORCHANGE msgs to each toolbar. *
  227. * *
  228. *****************************************************************************/
  229. #define TOOLGROW 8 // power of 2
  230. #define IDC_TOOLBAR 189 // wParam sent to Parent
  231. /* We keep an array of these around (one for each button on the toolbar) */
  232. typedef struct {
  233. RECT rc; // draw it at this postion in the toolbar
  234. int iButton; // it's this button
  235. int iState; // in this state
  236. int iPrevState; // for non-push buttons - last state
  237. int iType; // type of button
  238. int iActivity; // what just happened to button
  239. int iString; // string resource associated with button
  240. } TOOLBUTTON, FAR *LPTOOLBUTTON;
  241. BOOL FAR PASCAL toolbarInit(HANDLE hInst, HANDLE hPrev);
  242. BOOL FAR PASCAL toolbarSetBitmap(HWND hwnd, HANDLE hInst, int ibmp,
  243. POINT ptSize);
  244. BOOL FAR PASCAL toolbarAddTool(HWND hwnd, TOOLBUTTON tb);
  245. BOOL FAR PASCAL toolbarRetrieveTool(HWND hwnd, int iButton, LPTOOLBUTTON tb);
  246. BOOL FAR PASCAL toolbarRemoveTool(HWND hwnd, int iButton);
  247. int FAR PASCAL toolbarGetNumButtons(HWND hwnd);
  248. int FAR PASCAL toolbarButtonFromIndex(HWND hwnd, int iBtnPos);
  249. int FAR PASCAL toolbarIndexFromButton(HWND hwnd, int iButton);
  250. int FAR PASCAL toolbarPrevStateFromButton(HWND hwnd, int iButton);
  251. int FAR PASCAL toolbarActivityFromButton(HWND hwnd, int iButton);
  252. int FAR PASCAL toolbarIndexFromPoint(HWND hwnd, POINT pt);
  253. BOOL FAR PASCAL toolbarRectFromIndex(HWND hwnd, int iBtnPos, LPRECT lprc);
  254. int FAR PASCAL toolbarStringFromIndex(HWND hwnd, int iBtnPos);
  255. int FAR PASCAL toolbarStateFromButton(HWND hwnd, int iButton);
  256. int FAR PASCAL toolbarFullStateFromButton(HWND hwnd, int iButton);
  257. int FAR PASCAL toolbarTypeFromIndex(HWND hwnd, int iBtnPos);
  258. BOOL FAR PASCAL toolbarModifyState(HWND hwnd, int iButton, int iState);
  259. BOOL FAR PASCAL toolbarModifyString(HWND hwnd, int iButton, int iString);
  260. BOOL FAR PASCAL toolbarModifyPrevState(HWND hwnd, int iButton, int iPrevState);
  261. BOOL FAR PASCAL toolbarModifyActivity(HWND hwnd, int iButton, int iActivity);
  262. BOOL FAR PASCAL toolbarExclusiveRadio(HWND hwnd, int iType, int iButton);
  263. BOOL FAR PASCAL toolbarMoveFocus(HWND hwnd, BOOL fBackward);
  264. BOOL FAR PASCAL toolbarSetFocus(HWND hwnd, int iButton);
  265. HBITMAP FAR PASCAL LoadUIBitmap(
  266. HANDLE hInstance, // EXE file to load resource from
  267. LPCSTR szName, // name of bitmap resource
  268. COLORREF rgbText, // color to use for "Button Text"
  269. COLORREF rgbFace, // color to use for "Button Face"
  270. COLORREF rgbShadow, // color to use for "Button Shadow"
  271. COLORREF rgbHighlight, // color to use for "Button Hilight"
  272. COLORREF rgbWindow, // color to use for "Window Color"
  273. COLORREF rgbFrame); // color to use for "Window Frame"
  274. /* In a bitmap file, each button is the same size, and contains
  275. * the picture of a button. Each column contains the picture of a distinct
  276. * button (e.g. BTN_REWIND, BTN_REVERSE, etc.) and each row contains
  277. * a specific button state (BTNST_UP, BTNST_DOWN,
  278. * BTNBAR_GRAYED, etc. just as an example).
  279. *
  280. */
  281. #define TB_FIRST -1
  282. #define TB_LAST -2
  283. #define BTNST_GRAYED 0 //
  284. #define BTNST_UP 1 //
  285. #define BTNST_DOWN 2 //
  286. #define BTNST_FOCUSUP 3 //
  287. #define BTNST_FOCUSDOWN 4 //
  288. #define BTNST_FULLDOWN 5 //
  289. #define BTN_REPEAT 0x100 // add this to button index
  290. #define BTN_SHIFT 0x200
  291. #define BTN_DBLCLICK 0x400
  292. /* Types of buttons */
  293. #define BTNTYPE_PUSH 0
  294. #define BTNTYPE_CHECKBOX 1
  295. #define BTNTYPE_CUSTOM 2
  296. #define BTNTYPE_RADIO 3 // MUST BE LAST to reserve room for more
  297. // radio groups. (3 == one group,
  298. // 4 == another group, etc.)
  299. /* tells parent recent activity on button */
  300. #define BTNACT_MOUSEDOWN 0 // clicked mouse button down on tool
  301. #define BTNACT_MOUSEUP 1 // let go of mouse button while on tool
  302. #define BTNACT_MOUSEMOVEOFF 2 // moved mouse off tool while btn down
  303. #define BTNACT_MOUSEMOVEON 3 // moved back on tool (btn still down)
  304. #define BTNACT_MOUSEDBLCLK 4 // dbl clicked on tool
  305. #define BTNACT_KEYDOWN 5 // key down on tool
  306. #define BTNACT_KEYUP 6 // key up from tool
  307. /* constants */
  308. #define MSEC_BUTTONREPEAT 200 // milliseconds for auto-repeat
  309. /* timers */
  310. #define TIMER_BUTTONREPEAT 1 // timer for button auto-repeat
  311. // Window words for Toolbar
  312. #ifdef _WIN32
  313. #define GWLP_ARRAYBUTT 0 /* Pointer to array of buttons */
  314. #define GWL_NUMBUTTONS (GWLP_ARRAYBUTT + sizeof(HANDLE)) /* Number of buttons in array */
  315. #define GWL_PRESSED (GWL_NUMBUTTONS + sizeof(int)) /* Is a button currently pressed*/
  316. #define GWL_KEYPRESSED (GWL_PRESSED + sizeof(BOOL)) /* Is a key currently pressed? */
  317. #define GWL_WHICH (GWL_KEYPRESSED + sizeof(BOOL)) /* Which button has the focus? */
  318. #define GWL_SHIFTED (GWL_WHICH + sizeof(int)) /* Is it rt-click or shift-left?*/
  319. #define GWLP_BMPHANDLE (GWL_SHIFTED + sizeof(BOOL)) /* handle to bmp of the buttons */
  320. #define GWL_BMPINT (GWLP_BMPHANDLE + sizeof(HANDLE)) /* resource int of button bmp */
  321. #define GWL_BUTTONSIZE (GWL_BMPINT + sizeof(int)) /* a point (x=hi y=lo) */
  322. #define GWLP_HINST (GWL_BUTTONSIZE + sizeof(long)) /* hinst of the app */
  323. #define TOOLBAR_EXTRABYTES (GWLP_HINST + sizeof(HANDLE))
  324. #else
  325. #define GWW_ARRAYBUTT 0 /* Pointer to array of buttons */
  326. #define GWW_NUMBUTTONS 2 /* Number of buttons in array */
  327. #define GWW_PRESSED 4 /* Is a button currently pressed*/
  328. #define GWW_KEYPRESSED 6 /* Is a key currently pressed? */
  329. #define GWW_WHICH 8 /* Which button has the focus? */
  330. #define GWW_SHIFTED 10 /* Is it rt-click or shift-left?*/
  331. #define GWW_BMPHANDLE 12 /* handle to bmp of the buttons */
  332. #define GWW_BMPINT 14 /* resource int of button bmp */
  333. #define GWL_BUTTONSIZE 16 /* a point (x=hi y=lo) */
  334. #define GWW_HINST 20 /* hinst of the app */
  335. #define TOOLBAR_EXTRABYTES 22
  336. #endif
  337.