Пример #1
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
   }
 }
Пример #2
0
 void showWidget(int index) {
   OS.gtk_widget_show(handle);
   OS.gtk_widget_show(clientHandle);
   OS.gtk_container_add(parent.handle, handle);
   OS.gtk_box_set_child_packing(parent.handle, handle, false, false, 0, OS.GTK_PACK_START);
   if (boxHandle != 0) OS.gtk_widget_show(boxHandle);
   if (labelHandle != 0) OS.gtk_widget_show(labelHandle);
 }
Пример #3
0
 void createHandle(int index) {
   state |= HANDLE;
   handle = OS.gtk_expander_new(null);
   if (handle == 0) error(SWT.ERROR_NO_HANDLES);
   clientHandle = OS.g_object_new(display.gtk_fixed_get_type(), 0);
   if (clientHandle == 0) error(SWT.ERROR_NO_HANDLES);
   OS.gtk_container_add(handle, clientHandle);
   boxHandle = OS.gtk_hbox_new(false, 4);
   if (boxHandle == 0) error(SWT.ERROR_NO_HANDLES);
   labelHandle = OS.gtk_label_new(null);
   if (labelHandle == 0) error(SWT.ERROR_NO_HANDLES);
   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);
   OS.gtk_expander_set_label_widget(handle, boxHandle);
   OS.GTK_WIDGET_SET_FLAGS(handle, OS.GTK_CAN_FOCUS);
 }
Пример #4
0
 void createHandle(int index) {
   state |= HANDLE;
   fixedHandle = OS.g_object_new(display.gtk_fixed_get_type(), 0);
   if (fixedHandle == 0) error(SWT.ERROR_NO_HANDLES);
   gtk_widget_set_has_window(fixedHandle, true);
   handle = OS.gtk_notebook_new();
   if (handle == 0) error(SWT.ERROR_NO_HANDLES);
   OS.gtk_container_add(fixedHandle, handle);
   OS.gtk_notebook_set_scrollable(handle, true);
   OS.gtk_notebook_set_show_tabs(handle, true);
   if ((style & SWT.BOTTOM) != 0) {
     OS.gtk_notebook_set_tab_pos(handle, OS.GTK_POS_BOTTOM);
   }
 }
Пример #5
0
 void createHandle(int index) {
   state |= HANDLE;
   fixedHandle = OS.g_object_new(display.gtk_fixed_get_type(), 0);
   if (fixedHandle == 0) error(SWT.ERROR_NO_HANDLES);
   OS.gtk_fixed_set_has_window(fixedHandle, true);
   handle = OS.gtk_progress_bar_new();
   if (handle == 0) error(SWT.ERROR_NO_HANDLES);
   OS.gtk_container_add(fixedHandle, handle);
   int orientation =
       (style & SWT.VERTICAL) != 0 ? OS.GTK_PROGRESS_BOTTOM_TO_TOP : OS.GTK_PROGRESS_LEFT_TO_RIGHT;
   OS.gtk_progress_bar_set_orientation(handle, orientation);
   if ((style & SWT.INDETERMINATE) != 0) {
     timerId = OS.gtk_timeout_add(DELAY, display.windowTimerProc, handle);
   }
 }
Пример #6
0
  @Override
  void createHandle(int index) {
    state |= HANDLE | THEME_BACKGROUND;
    fixedHandle = OS.g_object_new(display.gtk_fixed_get_type(), 0);
    if (fixedHandle == 0) error(SWT.ERROR_NO_HANDLES);
    OS.gtk_widget_set_has_window(fixedHandle, true);
    handle = OS.gtk_toolbar_new();
    if (handle == 0) error(SWT.ERROR_NO_HANDLES);
    OS.gtk_container_add(fixedHandle, handle);
    if ((style & SWT.FLAT) != 0) {
      byte[] swt_toolbar_flat = Converter.wcsToMbcs(null, "swt-toolbar-flat", true);
      OS.gtk_widget_set_name(handle, swt_toolbar_flat);
    }

    /*
     * Bug in GTK. For some reason, the toolbar style context does not read
     * the CSS style sheet until the window containing the toolbar is shown.
     * The fix is to call gtk_style_context_invalidate() which it seems to
     * force the style sheet to be read.
     */
    if (OS.GTK3) {
      long /*int*/ context = OS.gtk_widget_get_style_context(handle);
      String css = "GtkToolbar {padding-top: 4px; padding-bottom: 4px; }";
      gtk_css_provider_load_from_css(context, css);
      OS.gtk_style_context_invalidate(context);
    }

    /*
     * Bug in GTK.  GTK will segment fault if gtk_widget_reparent() is called
     * on a tool bar or on a widget hierarchy containing a tool bar when the icon
     * size is not GTK_ICON_SIZE_LARGE_TOOLBAR.  The fix is to set the icon
     * size to GTK_ICON_SIZE_LARGE_TOOLBAR.
     *
     * Note that the segmentation fault does not happen on GTK 3, but the
     * tool bar preferred size is too big with GTK_ICON_SIZE_LARGE_TOOLBAR
     * when the tool bar item has no image or text.
     */
    OS.gtk_toolbar_set_icon_size(
        handle, OS.GTK3 ? OS.GTK_ICON_SIZE_SMALL_TOOLBAR : OS.GTK_ICON_SIZE_LARGE_TOOLBAR);

    // In GTK 3 font description is inherited from parent widget which is not how SWT has always
    // worked,
    // reset to default font to get the usual behavior
    if (OS.GTK3) {
      setFontDescription(defaultFont().handle);
    }
  }
Пример #7
0
 void createHandle(int index) {
   state |= HANDLE;
   int bits = SWT.SEPARATOR | SWT.RADIO | SWT.CHECK | SWT.PUSH | SWT.DROP_DOWN;
   if ((style & SWT.SEPARATOR) == 0) {
     labelHandle = OS.gtk_label_new_with_mnemonic(null);
     if (labelHandle == 0) error(SWT.ERROR_NO_HANDLES);
     imageHandle = OS.gtk_image_new_from_pixbuf(0);
     if (imageHandle == 0) error(SWT.ERROR_NO_HANDLES);
   }
   switch (style & bits) {
     case SWT.SEPARATOR:
       handle = OS.gtk_separator_tool_item_new();
       if (handle == 0) error(SWT.ERROR_NO_HANDLES);
       OS.gtk_separator_tool_item_set_draw(handle, true);
       break;
     case SWT.DROP_DOWN:
       if (OS.GTK_VERSION >= OS.VERSION(2, 6, 0)) {
         handle = OS.gtk_menu_tool_button_new(0, null);
         if (handle == 0) error(SWT.ERROR_NO_HANDLES);
         /*
          * Feature in GTK. The arrow button of DropDown tool-item is
          * disabled when it does not contain menu. The fix is to
          * find the arrow button handle and enable it.
          */
         long /*int*/ child = OS.gtk_bin_get_child(handle);
         long /*int*/ list = OS.gtk_container_get_children(child);
         arrowHandle = OS.g_list_nth_data(list, 1);
         OS.gtk_widget_set_sensitive(arrowHandle, true);
         OS.gtk_widget_set_size_request(OS.gtk_bin_get_child(arrowHandle), 8, 6);
       } else {
         /*
          * GTK does not support GtkMenuToolButton until 2.6.
          * So, we try to emulate it on the un-supported version.
          */
         handle = OS.gtk_tool_button_new(0, null);
         if (handle == 0) error(SWT.ERROR_NO_HANDLES);
         arrowBoxHandle = OS.gtk_hbox_new(false, 0);
         if (arrowBoxHandle == 0) error(SWT.ERROR_NO_HANDLES);
         arrowHandle = OS.gtk_arrow_new(OS.GTK_ARROW_DOWN, OS.GTK_SHADOW_NONE);
         if (arrowHandle == 0) error(SWT.ERROR_NO_HANDLES);
         OS.gtk_widget_set_size_request(arrowHandle, 8, 6);
         OS.gtk_container_add(arrowBoxHandle, labelHandle);
         OS.gtk_container_add(arrowBoxHandle, arrowHandle);
         /*
          * As we are try to emulate GtkMenuToolButton and in order
          * to display both the label and image, it is required
          * the set the toolitem as important. This will entitle
          * to display the label all the times.
          */
         OS.gtk_tool_item_set_is_important(handle, true);
       }
       break;
     case SWT.RADIO:
       /*
        * Because GTK enforces radio behavior in a button group
        * a radio group is not created for each set of contiguous
        * buttons, each radio button will not draw unpressed.
        * The fix is to use toggle buttons instead.
        */
     case SWT.CHECK:
       handle = OS.gtk_toggle_tool_button_new();
       if (handle == 0) error(SWT.ERROR_NO_HANDLES);
       break;
     case SWT.PUSH:
     default:
       handle = OS.gtk_tool_button_new(0, null);
       if (handle == 0) error(SWT.ERROR_NO_HANDLES);
       break;
   }
   if (labelHandle != 0) {
     OS.gtk_tool_button_set_label_widget(handle, labelHandle);
   }
   if (imageHandle != 0) {
     OS.gtk_tool_button_set_icon_widget(handle, imageHandle);
   }
   if ((parent.state & FOREGROUND) != 0) {
     setForegroundColor(parent.getForegroundColor());
   }
   if ((parent.state & FONT) != 0) {
     setFontDescription(parent.getFontDescription());
   }
   /*
    * Feature in GTK. GtkToolButton class uses this property to
    * determine whether to show or hide its label when the toolbar
    * style is GTK_TOOLBAR_BOTH_HORIZ (or SWT.RIGHT).
    */
   if ((parent.style & SWT.RIGHT) != 0) OS.gtk_tool_item_set_is_important(handle, true);
   if ((style & SWT.SEPARATOR) == 0) OS.gtk_tool_button_set_use_underline(handle, true);
 }