ui/gtk/container.h

Wed, 30 Oct 2024 12:23:52 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Wed, 30 Oct 2024 12:23:52 +0100
branch
newapi
changeset 374
eae5d6623fd3
parent 354
baf9bcc98d87
permissions
-rw-r--r--

add textarea (WINUI)

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2017 Olaf Wintermann. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   1. Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 *
 *   2. Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef CONTAINER_H
#define	CONTAINER_H

#include "../ui/toolkit.h"
#include "../ui/container.h"
#include <string.h>

#include <cx/allocator.h>

#ifdef	__cplusplus
extern "C" {
#endif

#define ui_reset_layout(layout) memset(&(layout), 0, sizeof(UiLayout))
#define ui_lb2bool(b) ((b) == UI_LAYOUT_TRUE ? TRUE : FALSE)
#define ui_bool2lb(b) ((b) ? UI_LAYOUT_TRUE : UI_LAYOUT_FALSE)
    
typedef void (*ui_container_add_f)(UiContainer*, GtkWidget*, UiBool);

typedef struct UiDocumentView UiDocumentView;

typedef struct UiLayout UiLayout;
typedef enum UiLayoutBool UiLayoutBool;

enum UiLayoutBool {
    UI_LAYOUT_UNDEFINED = 0,
    UI_LAYOUT_TRUE,
    UI_LAYOUT_FALSE,
};

struct UiLayout {
    UiLayoutBool fill;
    UiBool       newline;
    char         *label;
    UiBool       hexpand;
    UiBool       vexpand;
    int          width;
    int          colspan;
    int          rowspan;
};

struct UiContainer {
    GtkWidget *widget;
    UIMENU menu;
    GtkWidget *current;
    
    void (*add)(UiContainer*, GtkWidget*, UiBool);
    UiLayout layout;
    
    int close;
};

typedef struct UiBoxContainer {
    UiContainer container;
    UiSubContainerType type;
    UiBool has_fill;
} UiBoxContainer;

typedef struct UiGridContainer {
    UiContainer container;
    int x;
    int y;
#ifdef UI_GTK2
    int width;
    int height;
#endif
} UiGridContainer;

/*
typedef struct UiPanedContainer {
    UiContainer container;
    GtkWidget *current_pane;
    int orientation;
    int max;
    int cur;
} UiPanedContainer;
*/

typedef struct UiTabViewContainer {
    UiContainer container;
} UiTabViewContainer;

typedef void (*ui_select_tab_func)(UIWIDGET widget, int tab);
typedef void (*ui_add_tab_func)(UIWIDGET widget, int index, const char *name, UIWIDGET child);

typedef struct UiGtkTabView {
    UiObject *obj;
    GtkWidget *widget;
    ui_select_tab_func select_tab;
    ui_select_tab_func remove_tab;
    ui_add_tab_func add_tab;
    UiSubContainerType subcontainer;
    int margin;
    int spacing;
    int columnspacing;
    int rowspacing;
} UiGtkTabView;

typedef struct UiHeaderbarContainer {
    UiContainer container;
    GtkWidget *centerbox;
    int part;
    UiHeaderbarAlternative alternative; /* only used by fallback headerbar */
} UiHeaderbarContainer;

GtkWidget* ui_gtk_vbox_new(int spacing);
GtkWidget* ui_gtk_hbox_new(int spacing);

GtkWidget* ui_subcontainer_create(
        UiSubContainerType type,
        UiObject *newobj,
        int spacing,
        int columnspacing,
        int rowspacing,
        int margin);

UiContainer* ui_frame_container(UiObject *obj, GtkWidget *frame);
void ui_frame_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill);

GtkWidget* ui_box_set_margin(GtkWidget *box, int margin);
UIWIDGET ui_box_create(UiObject *obj, UiContainerArgs args, UiSubContainerType type);

UiContainer* ui_box_container(UiObject *obj, GtkWidget *box, UiSubContainerType type);
void ui_box_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill);

GtkWidget* ui_create_grid_widget(int colspacing, int rowspacing);
UiContainer* ui_grid_container(UiObject *obj, GtkWidget *grid);
void ui_grid_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill);

UiContainer* ui_frame_container(UiObject *obj, GtkWidget *frame);
void ui_frame_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill);

UiContainer* ui_expander_container(UiObject *obj, GtkWidget *expander);
void ui_expander_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill);

UiContainer* ui_scrolledwindow_container(UiObject *obj, GtkWidget *scrolledwindow);
void ui_scrolledwindow_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill);

UiContainer* ui_tabview_container(UiObject *obj, GtkWidget *tabview);
void ui_tabview_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill);

void ui_paned_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill);

void ui_split_container_add1(UiContainer *ct, GtkWidget *widget, UiBool fill);
void ui_split_container_add2(UiContainer *ct, GtkWidget *widget, UiBool fill);

UiGtkTabView* ui_widget_get_tabview_data(UIWIDGET tabview);

void ui_gtk_notebook_select_tab(GtkWidget *widget, int tab);

#if GTK_CHECK_VERSION(3, 10, 0)
UiContainer* ui_headerbar_container(UiObject *obj, GtkWidget *headerbar);
void ui_headerbar_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill);
#endif

UiContainer* ui_headerbar_fallback_container(UiObject *obj, GtkWidget *headerbar);
void ui_headerbar_fallback_container_add(UiContainer *ct, GtkWidget *widget, UiBool fill);

#ifdef	__cplusplus
}
#endif

#endif	/* CONTAINER_H */

mercurial