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.

192 lines
6.1 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1996 - 1999.
  5. //
  6. // File: toolbar.cxx
  7. //
  8. // Contents:
  9. //
  10. // History: 15 Aug 1996 DLee Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include "pch.cxx"
  14. #pragma hdrstop
  15. // cImages = Number of images in toolbar.bmp. Note that this is not
  16. // the same as the number of elements on the toolbar.
  17. // cpImageWidth = Width of a single button image in toolbar.bmp
  18. // cpImageHeight = Height of a single button image in toolbar.bmp
  19. // cpButtonWidth = Width of a button on the toolbar (zero = default)
  20. // cpButtonHeight = Height of a button on the toolbar (zero = default)
  21. const int cImages = 12;
  22. const int cpImageWidth = 19;
  23. const int cpImageHeight = 16;
  24. const int cpButtonWidth = 19;
  25. const int cpButtonHeight = 16;
  26. TBBUTTON aButtons[] = // Array defining the toolbar buttons
  27. {
  28. // {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0},
  29. {7, IDM_SEARCH, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0},
  30. {8, IDM_SEARCHCLASSDEF, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0},
  31. {9, IDM_SEARCHFUNCDEF, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0},
  32. {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0},
  33. {2, IDM_BROWSE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0},
  34. {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0},
  35. {11, IDM_DISPLAY_PROPS, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0},
  36. {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0},
  37. {0, IDM_NEWSEARCH, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0},
  38. {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0},
  39. {6, IDM_PREVIOUS_HIT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0},
  40. {5, IDM_NEXT_HIT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0},
  41. {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0},
  42. {4, IDM_FONT, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0},
  43. {0, 0, TBSTATE_ENABLED, TBSTYLE_SEP, 0, 0, 0},
  44. {1, IDM_OPEN, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0},
  45. {10, IDM_TILE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0},
  46. {3, IDM_CASCADE, TBSTATE_ENABLED, TBSTYLE_BUTTON, 0, 0, 0},
  47. };
  48. static WNDPROC _lpOrgTBProc = 0;
  49. LRESULT WINAPI TBSubclassProc(
  50. HWND hwnd,
  51. UINT msg,
  52. WPARAM wParam,
  53. LPARAM lParam )
  54. {
  55. LRESULT lRet = 0;
  56. // ordinarily, flat toolbars ride on a background window with a cool
  57. // bitmap. this one doesn't -- so draw an appropriate background.
  58. if ( WM_ERASEBKGND == msg )
  59. {
  60. RECT rect;
  61. GetClientRect( hwnd, &rect );
  62. FillRect( (HDC) wParam, & rect, App.BtnFaceBrush() );
  63. }
  64. else
  65. {
  66. lRet = CallWindowProc( _lpOrgTBProc,
  67. hwnd,
  68. msg,
  69. wParam,
  70. lParam );
  71. }
  72. return lRet;
  73. } //TBSubclassProc
  74. HWND CreateTBar(
  75. HWND hwnd,
  76. HINSTANCE hInst)
  77. {
  78. HWND bar = CreateToolbarEx( hwnd,
  79. WS_CHILD | WS_VISIBLE |
  80. TBSTYLE_TOOLTIPS | TBSTYLE_FLAT,
  81. IDM_TOOLBAR_WINDOW,
  82. cImages,
  83. hInst,
  84. ToolbarBmpNormal,
  85. aButtons,
  86. sizeof aButtons / sizeof TBBUTTON,
  87. cpButtonWidth,
  88. cpButtonHeight,
  89. cpImageWidth,
  90. cpImageHeight,
  91. sizeof TBBUTTON );
  92. if ( 0 == bar )
  93. return 0;
  94. _lpOrgTBProc = (WNDPROC) GetWindowLongPtr( bar, GWLP_WNDPROC );
  95. SetWindowLongPtr( bar, GWLP_WNDPROC, (LONG_PTR) TBSubclassProc );
  96. SendMessage( bar, TB_BUTTONSTRUCTSIZE, sizeof TBBUTTON, 0 );
  97. // pixels with color 192,192,192 are changed to buttonface color
  98. HIMAGELIST h = ImageList_LoadBitmap( hInst,
  99. MAKEINTRESOURCE( ToolbarBmpHilite ),
  100. cpImageWidth,
  101. 6,
  102. RGB(192,192,192) );
  103. SendMessage( bar, TB_SETBITMAPSIZE, 0, MAKELONG( cpImageWidth,
  104. cpImageHeight ) );
  105. SendMessage( bar, TB_SETHOTIMAGELIST, 0, (LPARAM) h );
  106. return bar;
  107. } //CreateTBar
  108. LRESULT ToolBarNotify(
  109. HWND hwnd,
  110. UINT uMessage,
  111. WPARAM wparam,
  112. LPARAM lparam,
  113. HINSTANCE hInst )
  114. {
  115. WCHAR awcBuffer[64];
  116. TOOLTIPTEXT * pToolTipText = (LPTOOLTIPTEXT)lparam;
  117. if ( TTN_NEEDTEXT == pToolTipText->hdr.code )
  118. {
  119. int id = (int)pToolTipText->hdr.idFrom;
  120. if ( ( IDM_NEWSEARCH == id ) &&
  121. ( IsSpecificClass( GetFocus(), BROWSE_CLASS ) ) )
  122. id = IDS_CLOSEBROWSE;
  123. LoadString( hInst,
  124. id,
  125. awcBuffer,
  126. sizeof awcBuffer / sizeof WCHAR );
  127. pToolTipText->lpszText = awcBuffer;
  128. }
  129. return 0;
  130. } //ToolBarNotify
  131. void UpdateButton(UINT iID, UINT iFlags)
  132. {
  133. int iCurrentFlags = (int) SendMessage( App.ToolBarWindow(),
  134. TB_GETSTATE,
  135. iID, 0L );
  136. if (iCurrentFlags & TBSTATE_PRESSED)
  137. iFlags |= TBSTATE_PRESSED;
  138. SendMessage( App.ToolBarWindow(),
  139. TB_SETSTATE,
  140. iID,
  141. MAKELPARAM( iFlags, 0 ) );
  142. } //UpdateButton
  143. void UpdateButtons( UINT *aId, UINT cId, BOOL fEnabled )
  144. {
  145. for ( UINT i = 0; i < cId; i++ )
  146. UpdateButton( aId[ i ],
  147. fEnabled ? TBSTATE_ENABLED : TBSTATE_INDETERMINATE );
  148. } //UpdateButtons