Example #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);
 }
Example #2
0
 static {
   if (OS.COMCTL32_MAJOR >= 6) {
     WNDCLASS lpWndClass = new WNDCLASS();
     OS.GetClassInfo(0, LinkClass, lpWndClass);
     LinkProc = lpWndClass.lpfnWndProc;
     /*
      * Feature in Windows.  The SysLink window class
      * does not include CS_DBLCLKS.  This means that these
      * controls will not get double click messages such as
      * WM_LBUTTONDBLCLK.  The fix is to register a new
      * window class with CS_DBLCLKS.
      *
      * NOTE:  Screen readers look for the exact class name
      * of the control in order to provide the correct kind
      * of assistance.  Therefore, it is critical that the
      * new window class have the same name.  It is possible
      * to register a local window class with the same name
      * as a global class.  Since bits that affect the class
      * are being changed, it is possible that other native
      * code, other than SWT, could create a control with
      * this class name, and fail unexpectedly.
      */
     int /*long*/ hInstance = OS.GetModuleHandle(null);
     int /*long*/ hHeap = OS.GetProcessHeap();
     lpWndClass.hInstance = hInstance;
     lpWndClass.style &= ~OS.CS_GLOBALCLASS;
     lpWndClass.style |= OS.CS_DBLCLKS;
     int byteCount = LinkClass.length() * TCHAR.sizeof;
     int /*long*/ lpszClassName = OS.HeapAlloc(hHeap, OS.HEAP_ZERO_MEMORY, byteCount);
     OS.MoveMemory(lpszClassName, LinkClass, byteCount);
     lpWndClass.lpszClassName = lpszClassName;
     OS.RegisterClass(lpWndClass);
     OS.HeapFree(hHeap, 0, lpszClassName);
   } else {
     LinkProc = 0;
   }
 }