コード例 #1
0
  /*
   * EnumFormatEtc([in] dwDirection, [out] ppenumFormatetc)
   * Ownership of ppenumFormatetc transfers from callee to caller so reference count on ppenumFormatetc
   * must be incremented before returning.  Caller is responsible for releasing ppenumFormatetc.
   */
  private int EnumFormatEtc(int dwDirection, long /*int*/ ppenumFormatetc) {
    // only allow getting of data - SetData is not currently supported
    if (dwDirection == COM.DATADIR_SET) return COM.E_NOTIMPL;

    // what types have been registered?
    TransferData[] allowedDataTypes = new TransferData[0];
    for (int i = 0; i < transferAgents.length; i++) {
      Transfer transferAgent = transferAgents[i];
      if (transferAgent != null) {
        TransferData[] formats = transferAgent.getSupportedTypes();
        TransferData[] newAllowedDataTypes =
            new TransferData[allowedDataTypes.length + formats.length];
        System.arraycopy(allowedDataTypes, 0, newAllowedDataTypes, 0, allowedDataTypes.length);
        System.arraycopy(formats, 0, newAllowedDataTypes, allowedDataTypes.length, formats.length);
        allowedDataTypes = newAllowedDataTypes;
      }
    }

    OleEnumFORMATETC enumFORMATETC = new OleEnumFORMATETC();
    enumFORMATETC.AddRef();

    FORMATETC[] formats = new FORMATETC[allowedDataTypes.length];
    for (int i = 0; i < formats.length; i++) {
      formats[i] = allowedDataTypes[i].formatetc;
    }
    enumFORMATETC.setFormats(formats);

    OS.MoveMemory(ppenumFormatetc, new long /*int*/[] {enumFORMATETC.getAddress()}, OS.PTR_SIZEOF);
    return COM.S_OK;
  }
コード例 #2
0
 void createItem(TabItem item, int index) {
   long /*int*/ list = OS.gtk_container_get_children(handle);
   int itemCount = 0;
   if (list != 0) {
     itemCount = OS.g_list_length(list);
     OS.g_list_free(list);
   }
   if (!(0 <= index && index <= itemCount)) error(SWT.ERROR_INVALID_RANGE);
   if (itemCount == items.length) {
     TabItem[] newItems = new TabItem[items.length + 4];
     System.arraycopy(items, 0, newItems, 0, items.length);
     items = newItems;
   }
   long /*int*/ boxHandle = gtk_box_new(OS.GTK_ORIENTATION_HORIZONTAL, false, 0);
   if (boxHandle == 0) error(SWT.ERROR_NO_HANDLES);
   long /*int*/ labelHandle = OS.gtk_label_new_with_mnemonic(null);
   if (labelHandle == 0) error(SWT.ERROR_NO_HANDLES);
   long /*int*/ imageHandle = OS.gtk_image_new();
   if (imageHandle == 0) error(SWT.ERROR_NO_HANDLES);
   OS.gtk_container_add(boxHandle, imageHandle);
   OS.gtk_container_add(boxHandle, labelHandle);
   long /*int*/ pageHandle = OS.g_object_new(display.gtk_fixed_get_type(), 0);
   if (pageHandle == 0) error(SWT.ERROR_NO_HANDLES);
   if (OS.GTK3) {
     OS.gtk_widget_override_background_color(pageHandle, OS.GTK_STATE_FLAG_NORMAL, new GdkRGBA());
     long /*int*/ region = OS.gdk_region_new();
     OS.gtk_widget_input_shape_combine_region(pageHandle, region);
     OS.gdk_region_destroy(region);
   }
   OS.g_signal_handlers_block_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
   OS.gtk_notebook_insert_page(handle, pageHandle, boxHandle, index);
   OS.g_signal_handlers_unblock_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
   OS.gtk_widget_show(boxHandle);
   OS.gtk_widget_show(labelHandle);
   OS.gtk_widget_show(pageHandle);
   item.state |= HANDLE;
   item.handle = boxHandle;
   item.labelHandle = labelHandle;
   item.imageHandle = imageHandle;
   item.pageHandle = pageHandle;
   System.arraycopy(items, index, items, index + 1, itemCount++ - index);
   items[index] = item;
   if ((state & FOREGROUND) != 0) {
     item.setForegroundColor(getForegroundColor());
   }
   if ((state & FONT) != 0) {
     item.setFontDescription(getFontDescription());
   }
   if (itemCount == 1) {
     OS.g_signal_handlers_block_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
     OS.gtk_notebook_set_current_page(handle, 0);
     OS.g_signal_handlers_unblock_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
     Event event = new Event();
     event.item = items[0];
     sendSelectionEvent(SWT.Selection, event, false);
     // the widget could be destroyed at this point
   }
 }
コード例 #3
0
 /**
  * Returns an array of <code>TabItem</code>s which are the items in the receiver.
  *
  * <p>Note: This is not the actual structure used by the receiver to maintain its list of items,
  * so modifying the array will not affect the receiver.
  *
  * @return the items in the receiver
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 public TabItem[] getItems() {
   checkWidget();
   int count = getItemCount();
   TabItem[] result = new TabItem[count];
   System.arraycopy(items, 0, result, 0, count);
   return result;
 }
コード例 #4
0
 Rectangle[] getRectangles(int linkIndex) {
   int lineCount = layout.getLineCount();
   Rectangle[] rects = new Rectangle[lineCount];
   int[] lineOffsets = layout.getLineOffsets();
   Point point = offsets[linkIndex];
   int lineStart = 1;
   while (point.x > lineOffsets[lineStart]) lineStart++;
   int lineEnd = 1;
   while (point.y > lineOffsets[lineEnd]) lineEnd++;
   int index = 0;
   if (lineStart == lineEnd) {
     rects[index++] = layout.getBounds(point.x, point.y);
   } else {
     rects[index++] = layout.getBounds(point.x, lineOffsets[lineStart] - 1);
     rects[index++] = layout.getBounds(lineOffsets[lineEnd - 1], point.y);
     if (lineEnd - lineStart > 1) {
       for (int i = lineStart; i < lineEnd - 1; i++) {
         rects[index++] = layout.getLineBounds(i);
       }
     }
   }
   if (rects.length != index) {
     Rectangle[] tmp = new Rectangle[index];
     System.arraycopy(rects, 0, tmp, 0, index);
     rects = tmp;
   }
   return rects;
 }
コード例 #5
0
 void destroyItem(TabItem item) {
   int index = 0;
   int itemCount = getItemCount();
   while (index < itemCount) {
     if (items[index] == item) break;
     index++;
   }
   if (index == itemCount) error(SWT.ERROR_ITEM_NOT_REMOVED);
   int oldIndex = OS.gtk_notebook_get_current_page(handle);
   OS.g_signal_handlers_block_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
   OS.gtk_notebook_remove_page(handle, index);
   OS.g_signal_handlers_unblock_matched(handle, OS.G_SIGNAL_MATCH_DATA, 0, 0, 0, 0, SWITCH_PAGE);
   System.arraycopy(items, index + 1, items, index, --itemCount - index);
   items[itemCount] = null;
   if (index == oldIndex) {
     int newIndex = OS.gtk_notebook_get_current_page(handle);
     if (newIndex != -1) {
       Control control = items[newIndex].getControl();
       if (control != null && !control.isDisposed()) {
         control.setBounds(getClientArea());
         control.setVisible(true);
       }
       Event event = new Event();
       event.item = items[newIndex];
       sendSelectionEvent(SWT.Selection, event, true);
       // the widget could be destroyed at this point
     }
   }
 }
コード例 #6
0
 /**
  * Unload the given image's data into the given byte stream using the given compression strategy.
  * Answer the number of bytes written. Method modified to use the passed data if it is not null.
  */
 int unloadData(ImageData image, byte[] data, OutputStream out, int comp) {
   int totalSize = 0;
   try {
     if (comp == 0) return unloadDataNoCompression(image, data, out);
     int bpl = (image.width * image.depth + 7) / 8;
     int bmpBpl = (bpl + 3) / 4 * 4; // BMP pads scanlines to multiples of 4 bytes
     int imageBpl = image.bytesPerLine;
     // Compression can actually take twice as much space, in worst case
     byte[] buf = new byte[bmpBpl * 2];
     int srcOffset = imageBpl * (image.height - 1); // Start at last line
     if (data == null) data = image.data;
     totalSize = 0;
     byte[] buf2 = new byte[32768];
     int buf2Offset = 0;
     for (int y = image.height - 1; y >= 0; y--) {
       int lineSize = compress(comp, data, srcOffset, bpl, buf, y == 0);
       if (buf2Offset + lineSize > buf2.length) {
         out.write(buf2, 0, buf2Offset);
         buf2Offset = 0;
       }
       System.arraycopy(buf, 0, buf2, buf2Offset, lineSize);
       buf2Offset += lineSize;
       totalSize += lineSize;
       srcOffset -= imageBpl;
     }
     if (buf2Offset > 0) out.write(buf2, 0, buf2Offset);
   } catch (IOException e) {
     SWT.error(SWT.ERROR_IO, e);
   }
   return totalSize;
 }
コード例 #7
0
ファイル: IME.java プロジェクト: rbatterman/eclipseWorkspace
 /**
  * Returns the styles for the ranges.
  *
  * <p>The ranges array contains start and end pairs. Each pair refers to the corresponding style
  * in the styles array. For example, the pair that starts at ranges[n] and ends at ranges[n+1]
  * uses the style at styles[n/2].
  *
  * @return the ranges for the styles
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  *
  * @see IME#getRanges
  */
 public TextStyle[] getStyles() {
   checkWidget();
   if (styles == null) return new TextStyle[0];
   TextStyle[] result = new TextStyle[styles.length];
   System.arraycopy(styles, 0, result, 0, styles.length);
   return result;
 }
コード例 #8
0
 /**
  * We have just read the Comment extension identifier from the input stream. Read in the rest of
  * the comment and return it. GIF comment blocks are variable size.
  */
 byte[] readCommentExtension() {
   try {
     byte[] comment = new byte[0];
     byte[] block = new byte[255];
     int size = inputStream.read();
     while ((size > 0) && (inputStream.read(block, 0, size) != -1)) {
       byte[] oldComment = comment;
       comment = new byte[oldComment.length + size];
       System.arraycopy(oldComment, 0, comment, 0, oldComment.length);
       System.arraycopy(block, 0, comment, oldComment.length, size);
       size = inputStream.read();
     }
     return comment;
   } catch (Exception e) {
     SWT.error(SWT.ERROR_IO, e);
     return null;
   }
 }
コード例 #9
0
ファイル: Device.java プロジェクト: andreyvit/yoursway-swt
 void new_Object(Object object) {
   synchronized (trackingLock) {
     for (int i = 0; i < objects.length; i++) {
       if (objects[i] == null) {
         objects[i] = object;
         errors[i] = new Error();
         return;
       }
     }
     Object[] newObjects = new Object[objects.length + 128];
     System.arraycopy(objects, 0, newObjects, 0, objects.length);
     newObjects[objects.length] = object;
     objects = newObjects;
     Error[] newErrors = new Error[errors.length + 128];
     System.arraycopy(errors, 0, newErrors, 0, errors.length);
     newErrors[errors.length] = new Error();
     errors = newErrors;
   }
 }
コード例 #10
0
 static char[] mbcsToWcs(String codePage, byte[] buffer) {
   char[] chars = new char[buffer.length];
   int charCount =
       OS.MultiByteToWideChar(
           OS.CP_ACP, OS.MB_PRECOMPOSED, buffer, buffer.length, chars, chars.length);
   if (charCount == chars.length) return chars;
   char[] result = new char[charCount];
   System.arraycopy(chars, 0, result, 0, charCount);
   return result;
 }
コード例 #11
0
 /**
  * We have just read the Application extension identifier from the input stream. Read in the rest
  * of the extension, look for and store 'number of repeats', and return the data.
  */
 byte[] readApplicationExtension() {
   try {
     // Read block data.
     int blockSize = inputStream.read();
     byte[] blockData = new byte[blockSize];
     inputStream.read(blockData);
     // Read application data.
     byte[] data = new byte[0];
     byte[] block = new byte[255];
     int size = inputStream.read();
     while ((size > 0) && (inputStream.read(block, 0, size) != -1)) {
       byte[] oldData = data;
       data = new byte[oldData.length + size];
       System.arraycopy(oldData, 0, data, 0, oldData.length);
       System.arraycopy(block, 0, data, oldData.length, size);
       size = inputStream.read();
     }
     // Look for the NETSCAPE 'repeat count' field for an animated GIF.
     boolean netscape =
         blockSize > 7
             && blockData[0] == 'N'
             && blockData[1] == 'E'
             && blockData[2] == 'T'
             && blockData[3] == 'S'
             && blockData[4] == 'C'
             && blockData[5] == 'A'
             && blockData[6] == 'P'
             && blockData[7] == 'E';
     boolean authentic =
         blockSize > 10 && blockData[8] == '2' && blockData[9] == '.' && blockData[10] == '0';
     if (netscape && authentic && data[0] == 01) { // $NON-NLS-1$ //$NON-NLS-2$
       repeatCount = (data[1] & 0xFF) | ((data[2] & 0xFF) << 8);
       loader.repeatCount = repeatCount;
     }
     return data;
   } catch (Exception e) {
     SWT.error(SWT.ERROR_IO, e);
     return null;
   }
 }
コード例 #12
0
ファイル: Path.java プロジェクト: andreyvit/yoursway-swt
 /**
  * Returns a device independent representation of the receiver.
  *
  * @return the PathData for the receiver
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_GRAPHIC_DISPOSED - if the receiver has been disposed
  *     </ul>
  *
  * @see PathData
  */
 public PathData getPathData() {
   if (isDisposed()) SWT.error(SWT.ERROR_GRAPHIC_DISPOSED);
   int count = handle.elementCount();
   int pointCount = 0, typeCount = 0;
   byte[] types = new byte[count];
   float[] pointArray = new float[count * 6];
   int points = OS.malloc(3 * NSPoint.sizeof);
   if (points == 0) SWT.error(SWT.ERROR_NO_HANDLES);
   NSPoint pt = new NSPoint();
   for (int i = 0; i < count; i++) {
     int element = handle.elementAtIndex_associatedPoints_(i, points);
     switch (element) {
       case OS.NSMoveToBezierPathElement:
         types[typeCount++] = SWT.PATH_MOVE_TO;
         OS.memmove(pt, points, NSPoint.sizeof);
         pointArray[pointCount++] = (int) pt.x;
         pointArray[pointCount++] = (int) pt.y;
         break;
       case OS.NSLineToBezierPathElement:
         types[typeCount++] = SWT.PATH_LINE_TO;
         OS.memmove(pt, points, NSPoint.sizeof);
         pointArray[pointCount++] = (int) pt.x;
         pointArray[pointCount++] = (int) pt.y;
         break;
       case OS.NSCurveToBezierPathElement:
         types[typeCount++] = SWT.PATH_CUBIC_TO;
         OS.memmove(pt, points, NSPoint.sizeof);
         pointArray[pointCount++] = (int) pt.x;
         pointArray[pointCount++] = (int) pt.y;
         OS.memmove(pt, points + NSPoint.sizeof, NSPoint.sizeof);
         pointArray[pointCount++] = (int) pt.x;
         pointArray[pointCount++] = (int) pt.y;
         OS.memmove(pt, points + NSPoint.sizeof + NSPoint.sizeof, NSPoint.sizeof);
         pointArray[pointCount++] = (int) pt.x;
         pointArray[pointCount++] = (int) pt.y;
         break;
       case OS.NSClosePathBezierPathElement:
         types[typeCount++] = SWT.PATH_CLOSE;
         break;
     }
   }
   OS.free(points);
   if (pointCount != pointArray.length) {
     float[] temp = new float[pointCount];
     System.arraycopy(pointArray, 0, temp, 0, pointCount);
     pointArray = temp;
   }
   PathData data = new PathData();
   data.types = types;
   data.points = pointArray;
   return data;
 }
コード例 #13
0
 /**
  * We have just read the PlainText extension identifier from the input stream. Read in the plain
  * text info and text, and return the text. GIF plain text blocks are variable size.
  */
 byte[] readPlainTextExtension() {
   try {
     // Read size of block = 0x0C.
     inputStream.read();
     // Read the text information (x, y, width, height, colors).
     byte[] info = new byte[12];
     inputStream.read(info);
     // Read the text.
     byte[] text = new byte[0];
     byte[] block = new byte[255];
     int size = inputStream.read();
     while ((size > 0) && (inputStream.read(block, 0, size) != -1)) {
       byte[] oldText = text;
       text = new byte[oldText.length + size];
       System.arraycopy(oldText, 0, text, 0, oldText.length);
       System.arraycopy(block, 0, text, oldText.length, size);
       size = inputStream.read();
     }
     return text;
   } catch (Exception e) {
     SWT.error(SWT.ERROR_IO, e);
     return null;
   }
 }
コード例 #14
0
 @Override
 Widget[] computeTabList() {
   ToolItem[] items = _getItems();
   if (tabItemList == null) {
     int i = 0;
     while (i < items.length && items[i].control == null) i++;
     if (i == items.length) return super.computeTabList();
   }
   Widget result[] = {};
   if (!isTabGroup() || !isEnabled() || !isVisible()) return result;
   ToolItem[] list = tabList != null ? _getTabItemList() : items;
   for (int i = 0; i < list.length; i++) {
     ToolItem child = list[i];
     Widget[] childList = child.computeTabList();
     if (childList.length != 0) {
       Widget[] newResult = new Widget[result.length + childList.length];
       System.arraycopy(result, 0, newResult, 0, result.length);
       System.arraycopy(childList, 0, newResult, result.length, childList.length);
       result = newResult;
     }
   }
   if (result.length == 0) result = new Widget[] {this};
   return result;
 }
コード例 #15
0
 /*public*/ void setTabItemList(ToolItem[] tabList) {
   checkWidget();
   if (tabList != null) {
     for (int i = 0; i < tabList.length; i++) {
       ToolItem item = tabList[i];
       if (item == null) error(SWT.ERROR_INVALID_ARGUMENT);
       if (item.isDisposed()) error(SWT.ERROR_INVALID_ARGUMENT);
       if (item.parent != this) error(SWT.ERROR_INVALID_PARENT);
     }
     ToolItem[] newList = new ToolItem[tabList.length];
     System.arraycopy(tabList, 0, newList, 0, tabList.length);
     tabList = newList;
   }
   this.tabItemList = tabList;
 }
コード例 #16
0
 /**
  * Returns an array of listeners who will be notified when a drag and drop operation is in
  * progress, by sending it one of the messages defined in the <code>DragSourceListener</code>
  * interface.
  *
  * @return the listeners who will be notified when a drag and drop operation is in progress
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  *
  * @see DragSourceListener
  * @see #addDragListener
  * @see #removeDragListener
  * @see DragSourceEvent
  * @since 3.4
  */
 public DragSourceListener[] getDragListeners() {
   Listener[] listeners = getListeners(DND.DragStart);
   int length = listeners.length;
   DragSourceListener[] dragListeners = new DragSourceListener[length];
   int count = 0;
   for (int i = 0; i < length; i++) {
     Listener listener = listeners[i];
     if (listener instanceof DNDListener) {
       dragListeners[count] = (DragSourceListener) ((DNDListener) listener).getEventListener();
       count++;
     }
   }
   if (count == length) return dragListeners;
   DragSourceListener[] result = new DragSourceListener[count];
   System.arraycopy(dragListeners, 0, result, 0, count);
   return result;
 }
コード例 #17
0
 private String[] splitString(String text) {
   String[] lines = new String[1];
   int start = 0, pos;
   do {
     pos = text.indexOf('\n', start);
     if (pos == -1) {
       lines[lines.length - 1] = text.substring(start);
     } else {
       boolean crlf = (pos > 0) && (text.charAt(pos - 1) == '\r');
       lines[lines.length - 1] = text.substring(start, pos - (crlf ? 1 : 0));
       start = pos + 1;
       String[] newLines = new String[lines.length + 1];
       System.arraycopy(lines, 0, newLines, 0, lines.length);
       lines = newLines;
     }
   } while (pos != -1);
   return lines;
 }
コード例 #18
0
 static byte[] wcsToMbcs(String codePage, String string, boolean terminate) {
   int byteCount;
   char[] chars = new char[string.length()];
   string.getChars(0, chars.length, chars, 0);
   byte[] bytes = new byte[byteCount = chars.length * 2 + (terminate ? 1 : 0)];
   byteCount =
       OS.WideCharToMultiByte(OS.CP_ACP, 0, chars, chars.length, bytes, byteCount, null, null);
   if (terminate) {
     byteCount++;
   } else {
     if (bytes.length != byteCount) {
       byte[] result = new byte[byteCount];
       System.arraycopy(bytes, 0, result, 0, byteCount);
       bytes = result;
     }
   }
   return bytes;
 }
コード例 #19
0
 /**
  * Prepare the given image's data for unloading into a byte stream using no compression strategy.
  * Answer the number of bytes written. Method modified to use the passed data if it is not null.
  */
 int unloadDataNoCompression(ImageData image, byte[] data, OutputStream out) {
   int bmpBpl = 0;
   try {
     int bpl = (image.width * image.depth + 7) / 8;
     bmpBpl = (bpl + 3) / 4 * 4; // BMP pads scanlines to multiples of 4 bytes
     int linesPerBuf = 32678 / bmpBpl;
     byte[] buf = new byte[linesPerBuf * bmpBpl];
     if (data == null) data = image.data;
     int imageBpl = image.bytesPerLine;
     int dataIndex = imageBpl * (image.height - 1); // Start at last line
     if (image.depth == 16) {
       for (int y = 0; y < image.height; y += linesPerBuf) {
         int count = image.height - y;
         if (linesPerBuf < count) count = linesPerBuf;
         int bufOffset = 0;
         for (int i = 0; i < count; i++) {
           for (int wIndex = 0; wIndex < bpl; wIndex += 2) {
             buf[bufOffset + wIndex + 1] = data[dataIndex + wIndex + 1];
             buf[bufOffset + wIndex] = data[dataIndex + wIndex];
           }
           bufOffset += bmpBpl;
           dataIndex -= imageBpl;
         }
         out.write(buf, 0, bufOffset);
       }
     } else {
       for (int y = 0; y < image.height; y += linesPerBuf) {
         int tmp = image.height - y;
         int count = tmp < linesPerBuf ? tmp : linesPerBuf;
         int bufOffset = 0;
         for (int i = 0; i < count; i++) {
           System.arraycopy(data, dataIndex, buf, bufOffset, bpl);
           bufOffset += bmpBpl;
           dataIndex -= imageBpl;
         }
         out.write(buf, 0, bufOffset);
       }
     }
   } catch (IOException e) {
     SWT.error(SWT.ERROR_IO, e);
   }
   return bmpBpl * image.height;
 }
コード例 #20
0
ファイル: Dialog.java プロジェクト: abego/java2script
 static void addDialog(Dialog dialog) {
   if (activeDialogs == null) {
     activeDialogs = new Dialog[3];
   }
   int length = activeDialogs.length;
   for (int i = 0; i < length; i++) {
     if (activeDialogs[i] == dialog) {
       return;
     }
   }
   for (int i = 0; i < length; i++) {
     if (activeDialogs[i] == null) {
       activeDialogs[i] = dialog;
       return;
     }
   }
   Dialog[] newActiveDialogs = new Dialog[length + 3];
   System.arraycopy(activeDialogs, 0, newActiveDialogs, 0, length);
   activeDialogs[length] = dialog;
 }
コード例 #21
0
 ToolItem[] _getItems() {
   long /*int*/ list = OS.gtk_container_get_children(handle);
   if (list == 0) return new ToolItem[0];
   int count = OS.g_list_length(list);
   ToolItem[] items = new ToolItem[count];
   long /*int*/ originalList = list;
   int index = 0;
   for (int i = 0; i < count; i++) {
     long /*int*/ data = OS.g_list_data(list);
     Widget widget = display.getWidget(data);
     if (widget != null) items[index++] = (ToolItem) widget;
     list = OS.g_list_next(list);
   }
   OS.g_list_free(originalList);
   if (index != items.length) {
     ToolItem[] newItems = new ToolItem[index];
     System.arraycopy(items, 0, newItems, 0, index);
     items = newItems;
   }
   return items;
 }
コード例 #22
0
 /**
  * Returns a (possibly empty) array of <code>MenuItem</code>s which are the items in the receiver.
  *
  * <p>Note: This is not the actual structure used by the receiver to maintain its list of items,
  * so modifying the array will not affect the receiver.
  *
  * @return the items in the receiver
  * @exception SWTException
  *     <ul>
  *       <li>ERROR_WIDGET_DISPOSED - if the receiver has been disposed
  *       <li>ERROR_THREAD_INVALID_ACCESS - if not called from the thread that created the receiver
  *     </ul>
  */
 public MenuItem[] getItems() {
   checkWidget();
   int[] handles = OS.QWidget_actions(handle);
   int count = handles.length;
   if (count == 0) return new MenuItem[0];
   MenuItem[] children = new MenuItem[count];
   int items = 0;
   for (int i = 0; i < count; ++i) {
     int handle = handles[i];
     if (handle != 0) {
       Widget widget = Display.getWidget(handle);
       if (widget != null && widget != this) {
         if (widget instanceof MenuItem) {
           children[items++] = (MenuItem) widget;
         }
       }
     }
   }
   if (items == count) return children;
   MenuItem[] newChildren = new MenuItem[items];
   System.arraycopy(children, 0, newChildren, 0, items);
   return newChildren;
 }
コード例 #23
0
  private void openAddressBook() {
    FileDialog fileDialog = new FileDialog(shell, SWT.OPEN);

    fileDialog.setFilterExtensions(new String[] {"*.adr;", "*.*"});
    fileDialog.setFilterNames(
        new String[] {
          resAddressBook.getString("Book_filter_name") + " (*.adr)",
          resAddressBook.getString("All_filter_name") + " (*.*)"
        });
    String name = fileDialog.open();

    if (name == null) return;
    File file = new File(name);
    if (!file.exists()) {
      displayError(
          resAddressBook.getString("File")
              + file.getName()
              + " "
              + resAddressBook.getString("Does_not_exist"));
      return;
    }

    Cursor waitCursor = shell.getDisplay().getSystemCursor(SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);

    FileReader fileReader = null;
    BufferedReader bufferedReader = null;
    String[] data = new String[0];
    try {
      fileReader = new FileReader(file.getAbsolutePath());
      bufferedReader = new BufferedReader(fileReader);
      String nextLine = bufferedReader.readLine();
      while (nextLine != null) {
        String[] newData = new String[data.length + 1];
        System.arraycopy(data, 0, newData, 0, data.length);
        newData[data.length] = nextLine;
        data = newData;
        nextLine = bufferedReader.readLine();
      }
    } catch (FileNotFoundException e) {
      displayError(resAddressBook.getString("File_not_found") + "\n" + file.getName());
      return;
    } catch (IOException e) {
      displayError(resAddressBook.getString("IO_error_read") + "\n" + file.getName());
      return;
    } finally {

      shell.setCursor(null);

      if (fileReader != null) {
        try {
          fileReader.close();
        } catch (IOException e) {
          displayError(resAddressBook.getString("IO_error_close") + "\n" + file.getName());
          return;
        }
      }
    }

    String[][] tableInfo = new String[data.length][table.getColumnCount()];
    int writeIndex = 0;
    for (int i = 0; i < data.length; i++) {
      String[] line = decodeLine(data[i]);
      if (line != null) tableInfo[writeIndex++] = line;
    }
    if (writeIndex != data.length) {
      String[][] result = new String[writeIndex][table.getColumnCount()];
      System.arraycopy(tableInfo, 0, result, 0, writeIndex);
      tableInfo = result;
    }
    Arrays.sort(tableInfo, new RowComparator(0));

    for (int i = 0; i < tableInfo.length; i++) {
      TableItem item = new TableItem(table, SWT.NONE);
      item.setText(tableInfo[i]);
    }
    shell.setText(resAddressBook.getString("Title_bar") + fileDialog.getFileName());
    isModified = false;
    this.file = file;
  }
コード例 #24
0
 String parse(String string) {
   int length = string.length();
   offsets = new Point[length / 4];
   ids = new String[length / 4];
   mnemonics = new int[length / 4 + 1];
   StringBuffer result = new StringBuffer();
   char[] buffer = new char[length];
   string.getChars(0, string.length(), buffer, 0);
   int index = 0, state = 0, linkIndex = 0;
   int start = 0, tagStart = 0, linkStart = 0, endtagStart = 0, refStart = 0;
   while (index < length) {
     char c = Character.toLowerCase(buffer[index]);
     switch (state) {
       case 0:
         if (c == '<') {
           tagStart = index;
           state++;
         }
         break;
       case 1:
         if (c == 'a') state++;
         break;
       case 2:
         switch (c) {
           case 'h':
             state = 7;
             break;
           case '>':
             linkStart = index + 1;
             state++;
             break;
           default:
             if (Character.isWhitespace(c)) break;
             else state = 13;
         }
         break;
       case 3:
         if (c == '<') {
           endtagStart = index;
           state++;
         }
         break;
       case 4:
         state = c == '/' ? state + 1 : 3;
         break;
       case 5:
         state = c == 'a' ? state + 1 : 3;
         break;
       case 6:
         if (c == '>') {
           mnemonics[linkIndex] = parseMnemonics(buffer, start, tagStart, result);
           int offset = result.length();
           parseMnemonics(buffer, linkStart, endtagStart, result);
           offsets[linkIndex] = new Point(offset, result.length() - 1);
           if (ids[linkIndex] == null) {
             ids[linkIndex] = new String(buffer, linkStart, endtagStart - linkStart);
           }
           linkIndex++;
           start = tagStart = linkStart = endtagStart = refStart = index + 1;
           state = 0;
         } else {
           state = 3;
         }
         break;
       case 7:
         state = c == 'r' ? state + 1 : 0;
         break;
       case 8:
         state = c == 'e' ? state + 1 : 0;
         break;
       case 9:
         state = c == 'f' ? state + 1 : 0;
         break;
       case 10:
         state = c == '=' ? state + 1 : 0;
         break;
       case 11:
         if (c == '"') {
           state++;
           refStart = index + 1;
         } else {
           state = 0;
         }
         break;
       case 12:
         if (c == '"') {
           ids[linkIndex] = new String(buffer, refStart, index - refStart);
           state = 2;
         }
         break;
       case 13:
         if (Character.isWhitespace(c)) {
           state = 0;
         } else if (c == '=') {
           state++;
         }
         break;
       case 14:
         state = c == '"' ? state + 1 : 0;
         break;
       case 15:
         if (c == '"') state = 2;
         break;
       default:
         state = 0;
         break;
     }
     index++;
   }
   if (start < length) {
     int tmp = parseMnemonics(buffer, start, tagStart, result);
     int mnemonic = parseMnemonics(buffer, Math.max(tagStart, linkStart), length, result);
     if (mnemonic == -1) mnemonic = tmp;
     mnemonics[linkIndex] = mnemonic;
   } else {
     mnemonics[linkIndex] = -1;
   }
   if (offsets.length != linkIndex) {
     Point[] newOffsets = new Point[linkIndex];
     System.arraycopy(offsets, 0, newOffsets, 0, linkIndex);
     offsets = newOffsets;
     String[] newIDs = new String[linkIndex];
     System.arraycopy(ids, 0, newIDs, 0, linkIndex);
     ids = newIDs;
     int[] newMnemonics = new int[linkIndex + 1];
     System.arraycopy(mnemonics, 0, newMnemonics, 0, linkIndex + 1);
     mnemonics = newMnemonics;
   }
   return result.toString();
 }
コード例 #25
0
  /**
   * Load the GIF image(s) stored in the input stream. Return an array of ImageData representing the
   * image(s).
   */
  @Override
  ImageData[] loadFromByteStream() {
    byte[] signature = new byte[3];
    byte[] versionBytes = new byte[3];
    byte[] block = new byte[7];
    try {
      inputStream.read(signature);
      if (!(signature[0] == 'G' && signature[1] == 'I' && signature[2] == 'F'))
        SWT.error(SWT.ERROR_INVALID_IMAGE);

      inputStream.read(versionBytes);

      inputStream.read(block);
    } catch (IOException e) {
      SWT.error(SWT.ERROR_IO, e);
    }
    screenWidth = (block[0] & 0xFF) | ((block[1] & 0xFF) << 8);
    loader.logicalScreenWidth = screenWidth;
    screenHeight = (block[2] & 0xFF) | ((block[3] & 0xFF) << 8);
    loader.logicalScreenHeight = screenHeight;
    byte bitField = block[4];
    backgroundPixel = block[5] & 0xFF;
    // aspect = block[6] & 0xFF;
    bitsPerPixel = ((bitField >> 4) & 0x07) + 1;
    defaultDepth = (bitField & 0x7) + 1;
    PaletteData palette = null;
    if ((bitField & 0x80) != 0) {
      // Global palette.
      // sorted = (bitField & 0x8) != 0;
      palette = readPalette(1 << defaultDepth);
    } else {
      // No global palette.
      // sorted = false;
      backgroundPixel = -1;
      defaultDepth = bitsPerPixel;
    }
    loader.backgroundPixel = backgroundPixel;

    ImageData[] images = new ImageData[0];
    int id = readID();
    while (id != GIF_TRAILER_ID && id != -1) {
      if (id == GIF_IMAGE_BLOCK_ID) {
        ImageData image = readImageBlock(palette);
        if (loader.hasListeners()) {
          loader.notifyListeners(new ImageLoaderEvent(loader, image, 3, true));
        }
        ImageData[] oldImages = images;
        images = new ImageData[oldImages.length + 1];
        System.arraycopy(oldImages, 0, images, 0, oldImages.length);
        images[images.length - 1] = image;
      } else if (id == GIF_EXTENSION_BLOCK_ID) {
        /* Read the extension block. Currently, only the
         * interesting parts of certain extensions are kept,
         * and the rest is discarded. In future, if we want
         * to keep extensions, they should be grouped with
         * the image data before which they appear.
         */
        readExtension();
      } else {
        /* The GIF is not to spec, but try to salvage it
         * if we read at least one image. */
        if (images.length > 0) break;
        SWT.error(SWT.ERROR_INVALID_IMAGE);
      }
      id = readID(); // block terminator (0)
      if (id == 0) id = readID(); // next block ID (unless we just read it)
    }
    return images;
  }
コード例 #26
0
  private void openAddressBook(String name) {
    if (name == null) return;
    File file = new File(name);
    if (!file.exists()) {
      displayError(
          resMessages.getString("File")
              + file.getName()
              + " "
              + resMessages.getString("Does_not_exist"));
      return;
    }

    Cursor waitCursor = new Cursor(shell.getDisplay(), SWT.CURSOR_WAIT);
    shell.setCursor(waitCursor);

    FileReader fileReader = null;
    BufferedReader bufferedReader = null;
    String[] data = new String[0];
    try {
      fileReader = new FileReader(file.getAbsolutePath());
      bufferedReader = new BufferedReader(fileReader);
      String nextLine = bufferedReader.readLine();
      while (nextLine != null) {
        String[] newData = new String[data.length + 1];
        System.arraycopy(data, 0, newData, 0, data.length);
        newData[data.length] = nextLine;
        data = newData;
        nextLine = bufferedReader.readLine();
      }
    } catch (FileNotFoundException e) {
      displayError(resMessages.getString("File_not_found") + "\n" + file.getName());
      return;
    } catch (IOException e) {
      displayError(resMessages.getString("IO_error_read") + "\n" + file.getName());
      return;
    } finally {

      shell.setCursor(null);
      waitCursor.dispose();

      if (fileReader != null) {
        try {
          fileReader.close();
        } catch (IOException e) {
          displayError(resMessages.getString("IO_error_close") + "\n" + file.getName());
          return;
        }
      }
    }

    String[][] tableInfo = new String[data.length][table.getColumnCount()];
    for (int i = 0; i < data.length; i++) {
      tableInfo[i] = decodeLine(data[i]);
    }

    Arrays.sort(tableInfo, new RowComparator(0));

    for (int i = 0; i < tableInfo.length; i++) {
      TableItem item = new TableItem(table, SWT.NONE);
      item.setText(tableInfo[i]);
    }
    shell.setText(resMessages.getString("Title_bar") + file.getName());
    isModified = false;
    this.file = file;
  }
コード例 #27
0
 /**
  * Answer all program extensions in the operating system. Note that a <code>Display</code> must
  * already exist to guarantee that this method returns an appropriate result.
  *
  * @return an array of extensions
  */
 public static String[] getExtensions() {
   NSAutoreleasePool pool = (NSAutoreleasePool) new NSAutoreleasePool().alloc().init();
   try {
     NSMutableSet supportedDocumentTypes = (NSMutableSet) NSMutableSet.set();
     NSWorkspace workspace = NSWorkspace.sharedWorkspace();
     NSString CFBundleDocumentTypes = NSString.stringWith("CFBundleDocumentTypes");
     NSString CFBundleTypeExtensions = NSString.stringWith("CFBundleTypeExtensions");
     NSArray array =
         new NSArray(
             OS.NSSearchPathForDirectoriesInDomains(
                 OS.NSAllApplicationsDirectory, OS.NSAllDomainsMask, true));
     int count = (int) /*64*/ array.count();
     for (int i = 0; i < count; i++) {
       NSString path = new NSString(array.objectAtIndex(i));
       NSFileManager fileManager = NSFileManager.defaultManager();
       NSDirectoryEnumerator enumerator = fileManager.enumeratorAtPath(path);
       if (enumerator != null) {
         id id;
         while ((id = enumerator.nextObject()) != null) {
           enumerator.skipDescendents();
           NSString filePath = new NSString(id.id);
           NSString fullPath = path.stringByAppendingPathComponent(filePath);
           if (workspace.isFilePackageAtPath(fullPath)) {
             NSBundle bundle = NSBundle.bundleWithPath(fullPath);
             id =
                 bundle != null
                     ? bundle.infoDictionary().objectForKey(CFBundleDocumentTypes)
                     : null;
             if (id != null) {
               NSDictionary documentTypes = new NSDictionary(id.id);
               NSEnumerator documentTypesEnumerator = documentTypes.objectEnumerator();
               while ((id = documentTypesEnumerator.nextObject()) != null) {
                 NSDictionary documentType = new NSDictionary(id.id);
                 id = documentType.objectForKey(CFBundleTypeExtensions);
                 if (id != null) {
                   supportedDocumentTypes.addObjectsFromArray(new NSArray(id.id));
                 }
               }
             }
           }
         }
       }
     }
     int i = 0;
     String[] exts = new String[(int) /*64*/ supportedDocumentTypes.count()];
     NSEnumerator enumerator = supportedDocumentTypes.objectEnumerator();
     id id;
     while ((id = enumerator.nextObject()) != null) {
       String ext = new NSString(id.id).getString();
       if (!ext.equals("*")) exts[i++] = "." + ext;
     }
     if (i != exts.length) {
       String[] temp = new String[i];
       System.arraycopy(exts, 0, temp, 0, i);
       exts = temp;
     }
     return exts;
   } finally {
     pool.release();
   }
 }