ui/motif/container.h

Thu, 14 Nov 2024 17:26:16 +0100

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Thu, 14 Nov 2024 17:26:16 +0100
branch
newapi
changeset 382
de653b07050b
parent 176
bc63cb601f6d
permissions
-rw-r--r--

implement ui groups/states (WINUI)

/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright 2014 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 <cx/list.h>
#include <string.h>

#ifdef	__cplusplus
extern "C" {
#endif

#define ui_reset_layout(layout) memset(&(layout), 0, sizeof(UiLayout))
    
typedef struct MotifTabbedPane    MotifTabbedPane;
typedef struct UiTab              UiTab;
typedef struct UiBoxContainer     UiBoxContainer;
typedef struct UiGridContainer    UiGridContainer;
typedef struct UiTabViewContainer UiTabViewContainer;
typedef struct UiLayout           UiLayout;

typedef Widget (*ui_container_add_f)(UiContainer*, Arg*, int*, UiBool);

typedef enum UiLayoutBool     UiLayoutBool;
typedef enum UiBoxOrientation UiBoxOrientation;


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

enum UiBoxOrientation {
    UI_BOX_VERTICAL = 0,
    UI_BOX_HORIZONTAL
};

struct UiLayout {
    UiLayoutBool fill;
    UiBool       newline;
    char         *label;
    UiBool       hexpand;
    UiBool       vexpand;
    int          gridwidth;
};

struct UiContainer {
    Widget   widget;
    Widget   (*prepare)(UiContainer*, Arg *, int*, UiBool);
    void     (*add)(UiContainer*, Widget);
    UiLayout layout;
    Widget   current;
    Widget   menu;
};

struct UiBoxContainer {
    UiContainer container;
    Widget      prev_widget;
    UiBool      has_fill;
    UiBoxOrientation orientation;
    int         margin;
    int         spacing;
};

struct UiGridContainer {
    UiContainer container;
    CxList      *lines;
    CxList      *current;
    int         columnspacing;
    int         rowspacing;
};

struct UiTabViewContainer {
    UiContainer container;
    UiContext   *context;
    Widget      widget;
    CxList      *tabs;
    Widget      current;
};

struct MotifTabbedPane {
    UiTabbedPane view;
    Widget       tabbar;
    CxList       *tabs;
    UiTab        *current;
    int          index;
    Pixel        bg1;
    Pixel        bg2;
    int          height;
};

struct UiTab {
    MotifTabbedPane *tabbedpane;
    UiObject        *content;
    Widget          tab_button;
};
    

UiContainer* ui_frame_container(UiObject *obj, Widget frame);
Widget ui_frame_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill);
void ui_frame_container_add(UiContainer *ct, Widget widget);

UiContainer* ui_box_container(UiObject *obj, Widget box, int margin, int spacing, UiBoxOrientation orientation);
Widget ui_box_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill);
void ui_box_container_add(UiContainer *ct, Widget widget);

UiContainer* ui_grid_container(UiObject *obj, Widget form, int columnspacing, int rowspacing);
Widget ui_grid_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill);
void ui_grid_container_add(UiContainer *ct, Widget widget);

UiContainer* ui_scrolledwindow_container(UiObject *obj, Widget scrolledwindow);
Widget ui_scrolledwindow_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill);
void ui_scrolledwindow_container_add(UiContainer *ct, Widget widget);

UiContainer* ui_tabview_container(UiObject *obj, Widget rowcolumn);
Widget ui_tabview_container_prepare(UiContainer *ct, Arg *args, int *n, UiBool fill);
void ui_tabview_container_add(UiContainer *ct, Widget widget);

void ui_tab_button_callback(Widget widget, UiTab *tab, XtPointer d);
void ui_change_tab(MotifTabbedPane *pane, UiTab *tab);

void ui_tab_set_document(UiContext *ctx, void *document);
void ui_tab_detach_document(UiContext *ctx);


#ifdef	__cplusplus
}
#endif

#endif	/* CONTAINER_H */

mercurial