Ejemplo n.º 1
0
 public Point computeSize(int wHint, int hHint, boolean changed) {
   checkWidget();
   if (wHint != SWT.DEFAULT && wHint < 0) wHint = 0;
   if (hHint != SWT.DEFAULT && hHint < 0) hHint = 0;
   int width, height;
   if (OS.COMCTL32_MAJOR >= 6) {
     int /*long*/ hDC = OS.GetDC(handle);
     int /*long*/ newFont = OS.SendMessage(handle, OS.WM_GETFONT, 0, 0);
     int /*long*/ oldFont = OS.SelectObject(hDC, newFont);
     if (text.length() > 0) {
       TCHAR buffer = new TCHAR(getCodePage(), parse(text), false);
       RECT rect = new RECT();
       int flags = OS.DT_CALCRECT | OS.DT_NOPREFIX;
       if (wHint != SWT.DEFAULT) {
         flags |= OS.DT_WORDBREAK;
         rect.right = wHint;
       }
       OS.DrawText(hDC, buffer, buffer.length(), rect, flags);
       width = rect.right - rect.left;
       height = rect.bottom;
     } else {
       TEXTMETRIC lptm = OS.IsUnicode ? (TEXTMETRIC) new TEXTMETRICW() : new TEXTMETRICA();
       OS.GetTextMetrics(hDC, lptm);
       width = 0;
       height = lptm.tmHeight;
     }
     if (newFont != 0) OS.SelectObject(hDC, oldFont);
     OS.ReleaseDC(handle, hDC);
   } else {
     int layoutWidth = layout.getWidth();
     // TEMPORARY CODE
     if (wHint == 0) {
       layout.setWidth(1);
       Rectangle rect = layout.getBounds();
       width = 0;
       height = rect.height;
     } else {
       layout.setWidth(wHint);
       Rectangle rect = layout.getBounds();
       width = rect.width;
       height = rect.height;
     }
     layout.setWidth(layoutWidth);
   }
   if (wHint != SWT.DEFAULT) width = wHint;
   if (hHint != SWT.DEFAULT) height = hHint;
   int border = getBorderWidth();
   width += border * 2;
   height += border * 2;
   return new Point(width, height);
 }
Ejemplo n.º 2
0
  @Override
  void draw(Theme theme, GC gc, Rectangle bounds) {
    if (OS.COMCTL32_MAJOR >= 6 && OS.IsAppThemed()) {
      // TODO - drawScale not done
      int style = this.style;
      int minimum = this.minimum;
      int maximum = this.maximum;
      int selection = this.selection;
      int pageIncrement = this.pageIncrement;
      long /*int*/ hTheme = OS.OpenThemeData(0, getClassId());
      RECT rect = new RECT();
      rect.left = bounds.x;
      rect.right = rect.left + bounds.width;
      rect.top = bounds.y;
      rect.bottom = rect.top + bounds.height;
      SIZE size = new SIZE();
      if ((style & SWT.VERTICAL) != 0) {
        OS.GetThemePartSize(hTheme, gc.handle, OS.TKP_TRACKVERT, 0, null, OS.TS_TRUE, size);
        int trackWidth = size.cx - 1;
        OS.GetThemePartSize(hTheme, gc.handle, OS.TKP_THUMBVERT, 0, null, OS.TS_TRUE, size);
        int thumbWidth = size.cx, thumbHeight = size.cy;
        OS.GetThemePartSize(hTheme, gc.handle, OS.TKP_TICS, 0, rect, OS.TS_TRUE, size);
        int ticWidth = size.cx;
        int marginX = (thumbWidth - trackWidth) / 2;
        int marginY = marginX;
        marginX += TICS_MARGIN;
        rect.left += marginX;
        rect.top += marginY;
        rect.right = rect.left + trackWidth;
        rect.bottom -= marginY;
        int trackHeight = rect.bottom - rect.top;
        OS.DrawThemeBackground(hTheme, gc.handle, OS.TKP_TRACKVERT, 0, rect, null);
        rect.top +=
            ((trackHeight - thumbHeight) * (selection - minimum)) / Math.max(1, maximum - minimum);
        rect.left -= (thumbWidth - trackWidth) / 2;
        rect.right = rect.left + thumbWidth;
        rect.bottom = rect.top + thumbHeight;
        OS.DrawThemeBackground(hTheme, gc.handle, OS.TKP_THUMBVERT, 0, rect, null);
        rect.top = bounds.y + marginY + thumbHeight / 2;
        rect.bottom = rect.top + 1;
        for (int sel = minimum; sel <= maximum; sel += pageIncrement) {
          rect.left = bounds.x + TICS_MARGIN / 2;
          rect.right = rect.left + ticWidth;
          if (sel != minimum && sel != maximum) rect.left++;
          rect.top = bounds.y + marginY + thumbHeight / 2;
          rect.top +=
              ((trackHeight - thumbHeight) * (sel - minimum)) / Math.max(1, maximum - minimum);
          rect.bottom = rect.top + 1;
          // TODO - why tics are ot drawn
          OS.DrawThemeBackground(hTheme, gc.handle, OS.TKP_TICSVERT, 1, rect, null);
          gc.drawLine(rect.left, rect.top, rect.right, rect.top);
          rect.left = bounds.x + TICS_MARGIN + thumbWidth + 1;
          rect.right = rect.left + ticWidth;
          if (sel != minimum && sel != maximum) rect.right--;
          // TODO - why tics are ot drawn
          OS.DrawThemeBackground(hTheme, gc.handle, OS.TKP_TICSVERT, 1, rect, null);
          gc.drawLine(rect.left, rect.top, rect.right, rect.top);
        }
      } else {

      }
      OS.CloseThemeData(hTheme);
    }
  }