1 11 package org.eclipse.swt.widgets; 12 13 14 import org.eclipse.swt.internal.win32.*; 15 import org.eclipse.swt.*; 16 import org.eclipse.swt.graphics.*; 17 18 41 42 public class CoolBar extends Composite { 43 CoolItem [] items; 44 CoolItem [] originalItems; 45 boolean locked; 46 boolean ignoreResize; 47 static final int ReBarProc; 48 static final TCHAR ReBarClass = new TCHAR (0, OS.REBARCLASSNAME, true); 49 static { 50 INITCOMMONCONTROLSEX icex = new INITCOMMONCONTROLSEX (); 51 icex.dwSize = INITCOMMONCONTROLSEX.sizeof; 52 icex.dwICC = OS.ICC_COOL_CLASSES; 53 OS.InitCommonControlsEx (icex); 54 WNDCLASS lpWndClass = new WNDCLASS (); 55 OS.GetClassInfo (0, ReBarClass, lpWndClass); 56 ReBarProc = lpWndClass.lpfnWndProc; 57 } 58 static final int SEPARATOR_WIDTH = 2; 59 static final int MAX_WIDTH = 0x7FFF; 60 static final int DEFAULT_COOLBAR_WIDTH = 0; 61 static final int DEFAULT_COOLBAR_HEIGHT = 0; 62 63 91 public CoolBar (Composite parent, int style) { 92 super (parent, checkStyle (style)); 93 104 if ((style & SWT.VERTICAL) != 0) { 105 this.style |= SWT.VERTICAL; 106 int bits = OS.GetWindowLong (handle, OS.GWL_STYLE); 107 OS.SetWindowLong (handle, OS.GWL_STYLE, bits | OS.CCS_VERT); 108 } else { 109 this.style |= SWT.HORIZONTAL; 110 } 111 } 112 113 int callWindowProc (int hwnd, int msg, int wParam, int lParam) { 114 if (handle == 0) return 0; 115 return OS.CallWindowProc (ReBarProc, hwnd, msg, wParam, lParam); 116 } 117 118 static int checkStyle (int style) { 119 style |= SWT.NO_FOCUS; 120 127 return style & ~(SWT.H_SCROLL | SWT.V_SCROLL); 128 } 129 130 protected void checkSubclass () { 131 if (!isValidSubclass ()) error (SWT.ERROR_INVALID_SUBCLASS); 132 } 133 134 public Point computeSize (int wHint, int hHint, boolean changed) { 135 checkWidget (); 136 int width = 0, height = 0; 137 int border = getBorderWidth (); 138 int newWidth = wHint == SWT.DEFAULT ? 0x3FFF : wHint + (border * 2); 139 int newHeight = hHint == SWT.DEFAULT ? 0x3FFF : hHint + (border * 2); 140 int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0); 141 if (count != 0) { 142 ignoreResize = true; 143 boolean redraw = false; 144 if (OS.IsWindowVisible (handle)) { 145 if (OS.COMCTL32_MAJOR >= 6) { 146 redraw = true; 147 OS.UpdateWindow (handle); 148 OS.DefWindowProc (handle, OS.WM_SETREDRAW, 0, 0); 149 } else { 150 redraw = drawCount == 0; 151 if (redraw) { 152 OS.UpdateWindow (handle); 153 OS.SendMessage (handle, OS.WM_SETREDRAW, 0, 0); 154 } 155 } 156 } 157 RECT oldRect = new RECT (); 158 OS.GetWindowRect (handle, oldRect); 159 int oldWidth = oldRect.right - oldRect.left; 160 int oldHeight = oldRect.bottom - oldRect.top; 161 int flags = OS.SWP_NOACTIVATE | OS.SWP_NOMOVE | OS.SWP_NOREDRAW | OS.SWP_NOZORDER; 162 SetWindowPos (handle, 0, 0, 0, newWidth, newHeight, flags); 163 RECT rect = new RECT (); 164 OS.SendMessage (handle, OS.RB_GETRECT, count - 1, rect); 165 height = Math.max (height, rect.bottom); 166 SetWindowPos (handle, 0, 0, 0, oldWidth, oldHeight, flags); 167 REBARBANDINFO rbBand = new REBARBANDINFO (); 168 rbBand.cbSize = REBARBANDINFO.sizeof; 169 rbBand.fMask = OS.RBBIM_IDEALSIZE | OS.RBBIM_STYLE; 170 int rowWidth = 0; 171 for (int i = 0; i < count; i++) { 172 OS.SendMessage(handle, OS.RB_GETBANDINFO, i, rbBand); 173 if ((rbBand.fStyle & OS.RBBS_BREAK) != 0) { 174 width = Math.max(width, rowWidth); 175 rowWidth = 0; 176 } 177 rowWidth += rbBand.cxIdeal + getMargin (i); 178 } 179 width = Math.max(width, rowWidth); 180 if (redraw) { 181 if (OS.COMCTL32_MAJOR >= 6) { 182 OS.DefWindowProc (handle, OS.WM_SETREDRAW, 1, 0); 183 } else { 184 OS.SendMessage (handle, OS.WM_SETREDRAW, 1, 0); 185 } 186 } 187 ignoreResize = false; 188 } 189 if (width == 0) width = DEFAULT_COOLBAR_WIDTH; 190 if (height == 0) height = DEFAULT_COOLBAR_HEIGHT; 191 if ((style & SWT.VERTICAL) != 0) { 192 int tmp = width; 193 width = height; 194 height = tmp; 195 } 196 if (wHint != SWT.DEFAULT) width = wHint; 197 if (hHint != SWT.DEFAULT) height = hHint; 198 height += border * 2; 199 width += border * 2; 200 return new Point (width, height); 201 } 202 203 void createHandle () { 204 super.createHandle (); 205 state &= ~(CANVAS | THEME_BACKGROUND); 206 207 219 int hFont = OS.GetStockObject (OS.SYSTEM_FONT); 220 OS.SendMessage (handle, OS.WM_SETFONT, hFont, 0); 221 } 222 223 void createItem (CoolItem item, int index) { 224 int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0); 225 if (!(0 <= index && index <= count)) error (SWT.ERROR_INVALID_RANGE); 226 int id = 0; 227 while (id < items.length && items [id] != null) id++; 228 if (id == items.length) { 229 CoolItem [] newItems = new CoolItem [items.length + 4]; 230 System.arraycopy (items, 0, newItems, 0, items.length); 231 items = newItems; 232 } 233 int hHeap = OS.GetProcessHeap (); 234 int lpText = OS.HeapAlloc (hHeap, OS.HEAP_ZERO_MEMORY, TCHAR.sizeof); 235 REBARBANDINFO rbBand = new REBARBANDINFO (); 236 rbBand.cbSize = REBARBANDINFO.sizeof; 237 rbBand.fMask = OS.RBBIM_TEXT | OS.RBBIM_STYLE | OS.RBBIM_ID; 238 rbBand.fStyle = OS.RBBS_VARIABLEHEIGHT | OS.RBBS_GRIPPERALWAYS; 239 if ((item.style & SWT.DROP_DOWN) != 0) { 240 rbBand.fStyle |= OS.RBBS_USECHEVRON; 241 } 242 rbBand.lpText = lpText; 243 rbBand.wID = id; 244 245 252 int lastIndex = getLastIndexOfRow (index - 1); 253 boolean fixLast = index == lastIndex + 1; 254 if (fixLast) { 255 rbBand.fMask |= OS.RBBIM_SIZE; 256 rbBand.cx = MAX_WIDTH; 257 } 258 259 267 if (index == 0 && count > 0) { 268 getItem (0).setWrap (false); 269 } 270 271 272 if (OS.SendMessage (handle, OS.RB_INSERTBAND, index, rbBand) == 0) { 273 error (SWT.ERROR_ITEM_NOT_ADDED); 274 } 275 276 277 if (fixLast) { 278 resizeToPreferredWidth (lastIndex); 279 } 280 281 OS.HeapFree (hHeap, 0, lpText); 282 items [item.id = id] = item; 283 int length = originalItems.length; 284 CoolItem [] newOriginals = new CoolItem [length + 1]; 285 System.arraycopy (originalItems, 0, newOriginals, 0, index); 286 System.arraycopy (originalItems, index, newOriginals, index + 1, length - index); 287 newOriginals [index] = item; 288 originalItems = newOriginals; 289 } 290 291 void createWidget () { 292 super.createWidget (); 293 items = new CoolItem [4]; 294 originalItems = new CoolItem [0]; 295 } 296 297 void destroyItem (CoolItem item) { 298 int index = OS.SendMessage (handle, OS.RB_IDTOINDEX, item.id, 0); 299 int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0); 300 if (count != 0) { 301 int lastIndex = getLastIndexOfRow (index); 302 if (index == lastIndex) { 303 312 resizeToMaximumWidth (lastIndex - 1); 313 } 314 } 315 316 321 Control control = item.control; 322 boolean wasVisible = control != null && !control.isDisposed() && control.getVisible (); 323 324 331 CoolItem nextItem = null; 332 if (item.getWrap ()) { 333 if (index + 1 < count) { 334 nextItem = getItem (index + 1); 335 ignoreResize = !nextItem.getWrap (); 336 } 337 } 338 if (OS.SendMessage (handle, OS.RB_DELETEBAND, index, 0) == 0) { 339 error (SWT.ERROR_ITEM_NOT_REMOVED); 340 } 341 items [item.id] = null; 342 item.id = -1; 343 if (ignoreResize) { 344 nextItem.setWrap (true); 345 ignoreResize = false; 346 } 347 348 349 if (wasVisible) control.setVisible (true); 350 351 index = 0; 352 while (index < originalItems.length) { 353 if (originalItems [index] == item) break; 354 index++; 355 } 356 int length = originalItems.length - 1; 357 CoolItem [] newOriginals = new CoolItem [length]; 358 System.arraycopy (originalItems, 0, newOriginals, 0, index); 359 System.arraycopy (originalItems, index + 1, newOriginals, index, length - index); 360 originalItems = newOriginals; 361 } 362 363 void drawThemeBackground (int hDC, int hwnd, RECT rect) { 364 if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed ()) { 365 if (background == -1 && (style & SWT.FLAT) != 0) { 366 Control control = findBackgroundControl (); 367 if (control != null && control.backgroundImage != null) { 368 fillBackground (hDC, control.getBackgroundPixel (), rect); 369 return; 370 } 371 } 372 } 373 RECT rect2 = new RECT (); 374 OS.GetClientRect (handle, rect2); 375 OS.MapWindowPoints (handle, hwnd, rect2, 2); 376 POINT lpPoint = new POINT (); 377 OS.SetWindowOrgEx (hDC, -rect2.left, -rect2.top, lpPoint); 378 OS.SendMessage (handle, OS.WM_PRINT, hDC, OS.PRF_CLIENT | OS.PRF_ERASEBKGND); 379 OS.SetWindowOrgEx (hDC, lpPoint.x, lpPoint.y, null); 380 } 381 382 Control findThemeControl () { 383 if ((style & SWT.FLAT) != 0) return this; 384 return background == -1 && backgroundImage == null ? this : super.findThemeControl (); 385 } 386 387 int getMargin (int index) { 388 int margin = 0; 389 if (OS.COMCTL32_MAJOR >= 6) { 390 MARGINS margins = new MARGINS (); 391 OS.SendMessage (handle, OS.RB_GETBANDMARGINS, 0, margins); 392 margin += margins.cxLeftWidth + margins.cxRightWidth; 393 } 394 RECT rect = new RECT (); 395 OS.SendMessage (handle, OS.RB_GETBANDBORDERS, index, rect); 396 if ((style & SWT.FLAT) != 0) { 397 402 if ((style & SWT.VERTICAL) != 0) { 403 margin += rect.top + 4; 404 } else { 405 margin += rect.left + 4; 406 } 407 } else { 408 if ((style & SWT.VERTICAL) != 0) { 409 margin += rect.top + rect.bottom; 410 } else { 411 margin += rect.left + rect.right; 412 } 413 } 414 if ((style & SWT.FLAT) == 0) { 415 if (!isLastItemOfRow (index)) { 416 margin += CoolBar.SEPARATOR_WIDTH; 417 } 418 } 419 return margin; 420 } 421 422 438 public CoolItem getItem (int index) { 439 checkWidget (); 440 int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0); 441 if (!(0 <= index && index < count)) error (SWT.ERROR_INVALID_RANGE); 442 REBARBANDINFO rbBand = new REBARBANDINFO (); 443 rbBand.cbSize = REBARBANDINFO.sizeof; 444 rbBand.fMask = OS.RBBIM_ID; 445 OS.SendMessage (handle, OS.RB_GETBANDINFO, index, rbBand); 446 return items [rbBand.wID]; 447 } 448 449 459 public int getItemCount () { 460 checkWidget (); 461 return OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0); 462 } 463 464 485 public int [] getItemOrder () { 486 checkWidget (); 487 int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0); 488 int [] indices = new int [count]; 489 REBARBANDINFO rbBand = new REBARBANDINFO (); 490 rbBand.cbSize = REBARBANDINFO.sizeof; 491 rbBand.fMask = OS.RBBIM_ID; 492 for (int i=0; i<count; i++) { 493 OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand); 494 CoolItem item = items [rbBand.wID]; 495 int index = 0; 496 while (index<originalItems.length) { 497 if (originalItems [index] == item) break; 498 index++; 499 } 500 if (index == originalItems.length) error (SWT.ERROR_CANNOT_GET_ITEM); 501 indices [i] = index; 502 } 503 return indices; 504 } 505 506 522 public CoolItem [] getItems () { 523 checkWidget (); 524 int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0); 525 CoolItem [] result = new CoolItem [count]; 526 REBARBANDINFO rbBand = new REBARBANDINFO (); 527 rbBand.cbSize = REBARBANDINFO.sizeof; 528 rbBand.fMask = OS.RBBIM_ID; 529 for (int i=0; i<count; i++) { 530 OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand); 531 result [i] = items [rbBand.wID]; 532 } 533 return result; 534 } 535 536 548 public Point [] getItemSizes () { 549 checkWidget (); 550 int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0); 551 Point [] sizes = new Point [count]; 552 REBARBANDINFO rbBand = new REBARBANDINFO (); 553 rbBand.cbSize = REBARBANDINFO.sizeof; 554 rbBand.fMask = OS.RBBIM_CHILDSIZE; 555 int separator = (style & SWT.FLAT) == 0 ? SEPARATOR_WIDTH : 0; 556 MARGINS margins = new MARGINS (); 557 for (int i=0; i<count; i++) { 558 RECT rect = new RECT (); 559 OS.SendMessage (handle, OS.RB_GETRECT, i, rect); 560 OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand); 561 if (OS.COMCTL32_MAJOR >= 6) { 562 OS.SendMessage (handle, OS.RB_GETBANDMARGINS, 0, margins); 563 rect.left -= margins.cxLeftWidth; 564 rect.right += margins.cxRightWidth; 565 } 566 if (!isLastItemOfRow(i)) rect.right += separator; 567 if ((style & SWT.VERTICAL) != 0) { 568 sizes [i] = new Point (rbBand.cyChild, rect.right - rect.left); 569 } else { 570 sizes [i] = new Point (rect.right - rect.left, rbBand.cyChild); 571 } 572 } 573 return sizes; 574 } 575 576 int getLastIndexOfRow (int index) { 577 int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0); 578 if (count == 0) return -1; 579 REBARBANDINFO rbBand = new REBARBANDINFO (); 580 rbBand.cbSize = REBARBANDINFO.sizeof; 581 rbBand.fMask = OS.RBBIM_STYLE; 582 for (int i=index + 1; i<count; i++) { 583 OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand); 584 if ((rbBand.fStyle & OS.RBBS_BREAK) != 0) { 585 return i - 1; 586 } 587 } 588 return count - 1; 589 } 590 591 boolean isLastItemOfRow (int index) { 592 int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0); 593 if (index + 1 == count) return true; 594 REBARBANDINFO rbBand = new REBARBANDINFO (); 595 rbBand.cbSize = REBARBANDINFO.sizeof; 596 rbBand.fMask = OS.RBBIM_STYLE; 597 OS.SendMessage (handle, OS.RB_GETBANDINFO, index + 1, rbBand); 598 return (rbBand.fStyle & OS.RBBS_BREAK) != 0; 599 } 600 601 614 public boolean getLocked () { 615 checkWidget (); 616 return locked; 617 } 618 619 632 public int [] getWrapIndices () { 633 checkWidget (); 634 CoolItem [] items = getItems (); 635 int [] indices = new int [items.length]; 636 int count = 0; 637 for (int i=0; i<items.length; i++) { 638 if (items [i].getWrap ()) indices [count++] = i; 639 } 640 int [] result = new int [count]; 641 System.arraycopy (indices, 0, result, 0, count); 642 return result; 643 } 644 645 663 public int indexOf (CoolItem item) { 664 checkWidget (); 665 if (item == null) error (SWT.ERROR_NULL_ARGUMENT); 666 if (item.isDisposed()) error (SWT.ERROR_INVALID_ARGUMENT); 667 return OS.SendMessage (handle, OS.RB_IDTOINDEX, item.id, 0); 668 } 669 670 void resizeToPreferredWidth (int index) { 671 676 int count = OS.SendMessage(handle, OS.RB_GETBANDCOUNT, 0, 0); 677 if (0 <= index && index < count) { 678 REBARBANDINFO rbBand = new REBARBANDINFO(); 679 rbBand.cbSize = REBARBANDINFO.sizeof; 680 rbBand.fMask = OS.RBBIM_IDEALSIZE; 681 OS.SendMessage (handle, OS.RB_GETBANDINFO, index, rbBand); 682 RECT rect = new RECT (); 683 OS.SendMessage (handle, OS.RB_GETBANDBORDERS, index, rect); 684 rbBand.cx = rbBand.cxIdeal + rect.left; 685 if ((style & SWT.FLAT) == 0) rbBand.cx += rect.right; 686 rbBand.fMask = OS.RBBIM_SIZE; 687 OS.SendMessage (handle, OS.RB_SETBANDINFO, index, rbBand); 688 } 689 } 690 691 void resizeToMaximumWidth (int index) { 692 REBARBANDINFO rbBand = new REBARBANDINFO(); 693 rbBand.cbSize = REBARBANDINFO.sizeof; 694 rbBand.fMask = OS.RBBIM_SIZE; 695 rbBand.cx = MAX_WIDTH; 696 OS.SendMessage (handle, OS.RB_SETBANDINFO, index, rbBand); 697 } 698 699 void releaseChildren (boolean destroy) { 700 if (items != null) { 701 for (int i=0; i<items.length; i++) { 702 CoolItem item = items [i]; 703 if (item != null && !item.isDisposed ()) { 704 item.release (false); 705 } 706 } 707 items = null; 708 } 709 super.releaseChildren (destroy); 710 } 711 712 void removeControl (Control control) { 713 super.removeControl (control); 714 for (int i=0; i<items.length; i++) { 715 CoolItem item = items [i]; 716 if (item != null && item.control == control) { 717 item.setControl (null); 718 } 719 } 720 } 721 722 void setBackgroundPixel (int pixel) { 723 if (pixel == -1) pixel = defaultBackground (); 724 OS.SendMessage (handle, OS.RB_SETBKCOLOR, 0, pixel); 725 setItemColors (OS.SendMessage (handle, OS.RB_GETTEXTCOLOR, 0, 0), pixel); 726 732 if (!OS.IsWindowVisible (handle)) return; 733 if (OS.IsWinCE) { 734 OS.InvalidateRect (handle, null, true); 735 } else { 736 int flags = OS.RDW_ERASE | OS.RDW_FRAME | OS.RDW_INVALIDATE | OS.RDW_ALLCHILDREN; 737 OS.RedrawWindow (handle, null, 0, flags); 738 } 739 } 740 741 void setForegroundPixel (int pixel) { 742 if (pixel == -1) pixel = defaultForeground (); 743 OS.SendMessage (handle, OS.RB_SETTEXTCOLOR, 0, pixel); 744 setItemColors (pixel, OS.SendMessage (handle, OS.RB_GETBKCOLOR, 0, 0)); 745 } 746 747 void setItemColors (int foreColor, int backColor) { 748 int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0); 749 REBARBANDINFO rbBand = new REBARBANDINFO (); 750 rbBand.cbSize = REBARBANDINFO.sizeof; 751 rbBand.fMask = OS.RBBIM_COLORS; 752 rbBand.clrFore = foreColor; 753 rbBand.clrBack = backColor; 754 for (int i=0; i<count; i++) { 755 OS.SendMessage (handle, OS.RB_SETBANDINFO, i, rbBand); 756 } 757 } 758 759 792 public void setItemLayout (int [] itemOrder, int [] wrapIndices, Point [] sizes) { 793 checkWidget (); 794 setRedraw (false); 795 setItemOrder (itemOrder); 796 setWrapIndices (wrapIndices); 797 setItemSizes (sizes); 798 setRedraw (true); 799 } 800 801 818 void setItemOrder (int [] itemOrder) { 819 if (itemOrder == null) error (SWT.ERROR_NULL_ARGUMENT); 820 int itemCount = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0); 821 if (itemOrder.length != itemCount) error (SWT.ERROR_INVALID_ARGUMENT); 822 823 824 boolean [] set = new boolean [itemCount]; 825 for (int i=0; i<itemOrder.length; i++) { 826 int index = itemOrder [i]; 827 if (index < 0 || index >= itemCount) error (SWT.ERROR_INVALID_RANGE); 828 if (set [index]) error (SWT.ERROR_INVALID_ARGUMENT); 829 set [index] = true; 830 } 831 832 REBARBANDINFO rbBand = new REBARBANDINFO (); 833 rbBand.cbSize = REBARBANDINFO.sizeof; 834 for (int i=0; i<itemOrder.length; i++) { 835 int id = originalItems [itemOrder [i]].id; 836 int index = OS.SendMessage (handle, OS.RB_IDTOINDEX, id, 0); 837 if (index != i) { 838 int lastItemSrcRow = getLastIndexOfRow (index); 839 int lastItemDstRow = getLastIndexOfRow (i); 840 if (index == lastItemSrcRow) { 841 resizeToPreferredWidth (index); 842 } 843 if (i == lastItemDstRow) { 844 resizeToPreferredWidth (i); 845 } 846 847 848 OS.SendMessage (handle, OS.RB_MOVEBAND, index, i); 849 850 if (index == lastItemSrcRow && index - 1 >= 0) { 851 resizeToMaximumWidth (index - 1); 852 } 853 if (i == lastItemDstRow) { 854 resizeToMaximumWidth (i); 855 } 856 } 857 } 858 } 859 860 877 void setItemSizes (Point [] sizes) { 878 if (sizes == null) error (SWT.ERROR_NULL_ARGUMENT); 879 int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0); 880 if (sizes.length != count) error (SWT.ERROR_INVALID_ARGUMENT); 881 REBARBANDINFO rbBand = new REBARBANDINFO (); 882 rbBand.cbSize = REBARBANDINFO.sizeof; 883 rbBand.fMask = OS.RBBIM_ID; 884 for (int i=0; i<count; i++) { 885 OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand); 886 items [rbBand.wID].setSize (sizes [i].x, sizes [i].y); 887 } 888 } 889 890 903 public void setLocked (boolean locked) { 904 checkWidget (); 905 this.locked = locked; 906 int count = OS.SendMessage (handle, OS.RB_GETBANDCOUNT, 0, 0); 907 REBARBANDINFO rbBand = new REBARBANDINFO (); 908 rbBand.cbSize = REBARBANDINFO.sizeof; 909 rbBand.fMask = OS.RBBIM_STYLE; 910 for (int i=0; i<count; i++) { 911 OS.SendMessage (handle, OS.RB_GETBANDINFO, i, rbBand); 912 if (locked) { 913 rbBand.fStyle |= OS.RBBS_NOGRIPPER; 914 } else { 915 rbBand.fStyle &= ~OS.RBBS_NOGRIPPER; 916 } 917 OS.SendMessage (handle, OS.RB_SETBANDINFO, i, rbBand); 918 } 919 } 920 921 936 public void setWrapIndices (int [] indices) { 937 checkWidget (); 938 if (indices == null) indices = new int [0]; 939 int count = getItemCount (); 940 for (int i=0; i<indices.length; i++) { 941 if (indices [i] < 0 || indices [i] >= count) { 942 error (SWT.ERROR_INVALID_RANGE); 943 } 944 } 945 setRedraw (false); 946 CoolItem [] items = getItems (); 947 for (int i=0; i<items.length; i++) { 948 CoolItem item = items [i]; 949 if (item.getWrap ()) { 950 resizeToPreferredWidth (i - 1); 951 item.setWrap (false); 952 } 953 } 954 resizeToMaximumWidth (count - 1); 955 for (int i=0; i<indices.length; i++) { 956 int index = indices [i]; 957 if (0 <= index && index < items.length) { 958 CoolItem item = items [index]; 959 item.setWrap (true); 960 resizeToMaximumWidth (index - 1); 961 } 962 } 963 setRedraw (true); 964 } 965 966 int widgetStyle () { 967 int bits = super.widgetStyle () | OS.CCS_NODIVIDER | OS.CCS_NORESIZE; 968 bits |= OS.RBS_VARHEIGHT | OS.RBS_DBLCLKTOGGLE; 969 if ((style & SWT.FLAT) == 0) bits |= OS.RBS_BANDBORDERS; 970 return bits; 971 } 972 973 TCHAR windowClass () { 974 return ReBarClass; 975 } 976 977 int windowProc () { 978 return ReBarProc; 979 } 980 981 LRESULT WM_COMMAND (int wParam, int lParam) { 982 1000 LRESULT result = super.WM_COMMAND (wParam, lParam); 1001 if (result != null) return result; 1002 return LRESULT.ZERO; 1003} 1004 1005LRESULT WM_ERASEBKGND (int wParam, int lParam) { 1006 LRESULT result = super.WM_ERASEBKGND (wParam, lParam); 1007 1020 if (OS.COMCTL32_MAJOR < 6 || !OS.IsAppThemed ()) { 1021 drawBackground (wParam); 1022 return null; 1023 } 1024 return result; 1025} 1026 1027LRESULT WM_NOTIFY (int wParam, int lParam) { 1028 1046 LRESULT result = super.WM_NOTIFY (wParam, lParam); 1047 if (result != null) return result; 1048 return LRESULT.ZERO; 1049} 1050 1051LRESULT WM_SETREDRAW (int wParam, int lParam) { 1052 LRESULT result = super.WM_SETREDRAW (wParam, lParam); 1053 if (result != null) return result; 1054 1073 if (OS.COMCTL32_MAJOR >= 6) return LRESULT.ZERO; 1074 Rectangle rect = getBounds (); 1075 int code = callWindowProc (handle, OS.WM_SETREDRAW, wParam, lParam); 1076 OS.DefWindowProc (handle, OS.WM_SETREDRAW, wParam, lParam); 1077 if (!rect.equals (getBounds ())) { 1078 parent.redraw (rect.x, rect.y, rect.width, rect.height, true); 1079 } 1080 return new LRESULT (code); 1081} 1082 1083LRESULT WM_SIZE (int wParam, int lParam) { 1084 if (ignoreResize) { 1085 int code = callWindowProc (handle, OS.WM_SIZE, wParam, lParam); 1086 if (code == 0) return LRESULT.ZERO; 1087 return new LRESULT (code); 1088 } 1089 return super.WM_SIZE (wParam, lParam); 1096} 1097 1098LRESULT wmNotifyChild (NMHDR hdr, int wParam, int lParam) { 1099 switch (hdr.code) { 1100 case OS.RBN_BEGINDRAG: { 1101 int pos = OS.GetMessagePos (); 1102 POINT pt = new POINT (); 1103 pt.x = (short) (pos & 0xFFFF); 1104 pt.y = (short) (pos >> 16); 1105 OS.ScreenToClient (handle, pt); 1106 int button = display.lastButton != 0 ? display.lastButton : 1; 1107 if (!sendDragEvent (button, pt.x, pt.y)) return LRESULT.ONE; 1108 break; 1109 } 1110 case OS.RBN_CHILDSIZE: { 1111 1120 NMREBARCHILDSIZE lprbcs = new NMREBARCHILDSIZE (); 1121 OS.MoveMemory (lprbcs, lParam, NMREBARCHILDSIZE.sizeof); 1122 if (lprbcs.uBand != -1) { 1123 CoolItem item = items [lprbcs.wID]; 1124 Control control = item.control; 1125 if (control != null) { 1126 int width = lprbcs.rcChild_right - lprbcs.rcChild_left; 1127 int height = lprbcs.rcChild_bottom - lprbcs.rcChild_top; 1128 control.setBounds (lprbcs.rcChild_left, lprbcs.rcChild_top, width, height); 1129 } 1130 } 1131 break; 1132 } 1133 case OS.RBN_HEIGHTCHANGE: { 1134 if (!ignoreResize) { 1135 Point size = getSize (); 1136 int border = getBorderWidth (); 1137 int barHeight = OS.SendMessage (handle, OS.RB_GETBARHEIGHT, 0, 0); 1138 if ((style & SWT.VERTICAL) != 0) { 1139 setSize (barHeight + 2 * border, size.y); 1140 } else { 1141 setSize (size.x, barHeight + 2 * border); 1142 } 1143 } 1144 break; 1145 } 1146 case OS.RBN_CHEVRONPUSHED: { 1147 NMREBARCHEVRON lpnm = new NMREBARCHEVRON (); 1148 OS.MoveMemory (lpnm, lParam, NMREBARCHEVRON.sizeof); 1149 CoolItem item = items [lpnm.wID]; 1150 if (item != null) { 1151 Event event = new Event(); 1152 event.detail = SWT.ARROW; 1153 if ((style & SWT.VERTICAL) != 0) { 1154 event.x = lpnm.right; 1155 event.y = lpnm.top; 1156 } else { 1157 event.x = lpnm.left; 1158 event.y = lpnm.bottom; 1159 } 1160 item.postEvent (SWT.Selection, event); 1161 } 1162 break; 1163 } 1164 case OS.NM_CUSTOMDRAW: { 1165 1171 if (OS.COMCTL32_MAJOR < 6) break; 1172 if (findBackgroundControl () != null || (style & SWT.FLAT) != 0) { 1173 NMCUSTOMDRAW nmcd = new NMCUSTOMDRAW (); 1174 OS.MoveMemory (nmcd, lParam, NMCUSTOMDRAW.sizeof); 1175 switch (nmcd.dwDrawStage) { 1176 case OS.CDDS_PREERASE: 1177 return new LRESULT (OS.CDRF_SKIPDEFAULT | OS.CDRF_NOTIFYPOSTERASE); 1178 case OS.CDDS_POSTERASE: 1179 drawBackground (nmcd.hdc); 1180 break; 1181 } 1182 } 1183 break; 1184 } 1185 } 1186 return super.wmNotifyChild (hdr, wParam, lParam); 1187} 1188} 1189 | Popular Tags |