25 #include <Xm/ToggleB.h>
31 #include <Xm/ScrolledW.h>
54 #define SCALER_MIN_VALUE 0
55 #define SCALER_MAX_VALUE 1000
66 aw_assert(scaleRel>=0.0 && scaleRel<=1.0);
103 switch (widget_type) {
110 char *new_text = XmTextGetString((widget));
122 if (XmToggleButtonGetState(widget) == False)
break;
131 int incr =
reinterpret_cast<XmListCallbackStruct*
>(call_data)->item_position;
132 while (entry && --incr>0) entry = entry->
next;
135 entry = ts.sellist->default_select;
136 if (!entry)
GBK_terminate(
"no default specified for selection list");
146 XmScaleCallbackStruct *xms = (XmScaleCallbackStruct*)call_data;
151 GBK_terminatef(
"Unknown widget type %i in AW_variable_update_callback", widget_type);
190 XtVaGetValues(w, XmNheight, &height, XmNwidth, &width,
NULp);
191 if (default_width >0) width = default_width;
211 #define MIN_RIGHT_OFFSET 10
212 #define MIN_BOTTOM_OFFSET 10
223 args.
add(XmNrightAttachment, XmATTACH_FORM);
224 args.
add(XmNrightOffset, right_offset);
227 args.
add(XmNrightAttachment, XmATTACH_OPPOSITE_FORM);
232 args.
add(XmNleftAttachment, XmATTACH_NONE);
236 args.
add(XmNleftAttachment, XmATTACH_FORM);
247 args.
add(XmNbottomAttachment, XmATTACH_FORM);
248 args.
add(XmNbottomOffset, bottom_offset);
251 args.
add(XmNbottomAttachment, XmATTACH_OPPOSITE_FORM);
255 args.
add(XmNtopAttachment, XmATTACH_NONE);
259 args.
add(XmNtopAttachment, XmATTACH_FORM);
267 const char *pixmapsDir =
"motifHack/pixmaps";
277 #define MAX_LINE_LENGTH 200
285 FILE *in = fopen(path,
"rt");
287 const char *subdir = strrchr(pixmapname,
'/');
288 char *name = strdup(subdir ? subdir+1 : pixmapname);
290 char *
dot = strrchr(name,
'.');
292 else err =
"'.' expected";
294 int namelen = strlen(name);
298 while (!done && !err) {
302 else if (strchr(buffer, 0)[-1] !=
'\n') {
305 else if (strncmp(buffer,
"#define", 7) != 0) {
309 char *name_pos = strstr(buffer+7, name);
311 char *behind = name_pos+namelen;
312 if (strncmp(behind,
"_width ", 7) == 0) *width = atoi(behind+7);
313 else if (strncmp(behind,
"_height ", 8) == 0) *height = atoi(behind+8);
318 if (done && ((*width == 0) || (*height == 0))) {
319 if (strstr(buffer,
"XPM")) {
324 char *temp = strtok(buffer+1,
" ");
326 temp = strtok(
NULp,
" ");
327 *height = atoi(temp);
331 err =
"can't detect size";
339 err =
"no such file";
346 #if defined(DUMP_BUTTON_CREATION)
347 printf(
"Bitmap '%s' has size %i/%i\n", pixmapname, *width, *height);
348 #endif // DUMP_BUTTON_CREATION
353 #undef MAX_LINE_LENGTH
360 for (
int p = 0; str[p]; ++p) {
361 if (str[p] ==
'\n') {
362 if (linewidth>textwidth) textwidth = linewidth;
372 if (linewidth>textwidth) textwidth = linewidth;
375 *height = textheight;
378 void AW_window::calculate_label_size(
int *width,
int *height,
bool in_pixel) {
391 *width = calculate_string_width(*width);
392 *height = calculate_string_height(*height, 0);
406 size_t text_width = strcspn(text,
"\n");
408 if (text[text_width]) {
412 if (text_width>width) width = text_width;
426 size_t width, height;
437 int len = width+(xtraSpace*2);
466 #if defined(DUMP_BUTTON_CREATION)
467 printf(
"------------------------------ Button '%s'\n", buttonlabel);
469 #endif // DUMP_BUTTON_CREATION
480 #if defined(DEVEL_RALF) && 1
486 #define SPACE_BEHIND_LABEL 10
488 #define BUTTON_TEXT_X_PADDING 4
489 #define BUTTON_TEXT_Y_PADDING 10
491 #define BUTTON_GRAPHIC_PADDING 12
492 #define FLAT_GRAPHIC_PADDING 4 // for buttons w/o callback
496 #if defined(ASSERTION_USED)
498 #endif // ASSERTION_USED
500 int width_of_button = -1, height_of_button = -1;
502 int width_of_label, height_of_label;
503 calculate_label_size(&width_of_label, &height_of_label,
true);
506 bool let_motif_choose_size =
false;
515 if (!is_graphical_button) {
520 int textwidth, textheight;
532 if (is_graphical_button) {
539 width_of_button = width+gpadding;
540 height_of_button = height+gpadding;
545 let_motif_choose_size =
true;
549 int textwidth, textheight;
557 if (!let_motif_choose_size) {
558 if (height_of_button<height_of_label) height_of_button = height_of_label;
559 aw_assert(width_of_button && height_of_button);
564 int x_button = x_label + width_of_label_and_spacer;
565 int y_button = y_label;
570 if (!let_motif_choose_size) {
574 int width_of_label_and_button = width_of_label_and_spacer+width_of_button_and_highlight;
577 int shiftback = width_of_label_and_button;
581 x_label -= shiftback;
582 x_button -= shiftback;
591 y_label += (height_of_button-height_of_label)/2;
602 label_widget = XtVaCreateManagedWidget(
"label",
605 XmNwidth, (
int)(width_of_label + 2),
607 XmNrecomputeSize,
false,
608 XmNalignment, XmALIGNMENT_BEGINNING,
610 XmNx, (
int)(x_label),
611 XmNy, (
int)(y_label),
621 Widget fatherwidget = parent_widget;
625 printf(
"Attaching highlighted buttons does not work - "
626 "highlight ignored for button '%s'!\n", buttonlabel);
632 int x_shadow = x_button - shadow_offset;
633 int y_shadow = y_button - shadow_offset;
635 fatherwidget = XtVaCreateManagedWidget(
"draw_area",
638 XmNx, (
int)(x_shadow),
639 XmNy, (
int)(y_shadow),
640 XmNshadowType, XmSHADOW_IN,
650 args.
add(XmNx, x_button);
651 args.
add(XmNy, y_button);
653 args.
add(XmNfontList, (XtArgVal)
p_global->fontlist);
656 if (!let_motif_choose_size) {
657 args.
add(XmNwidth, width_of_button);
658 args.
add(XmNheight, height_of_button);
661 Label buttonLabel(buttonlabel,
this);
664 args.
add(XmNalignment, XmALIGNMENT_CENTER);
666 button = XtVaCreateManagedWidget(
"button", xmPushButtonWidgetClass, fatherwidget,
RES_LABEL_CONVERT(buttonLabel),
NULp);
669 button = XtVaCreateManagedWidget(
"label", xmLabelWidgetClass, parent_widget,
RES_LABEL_CONVERT(buttonLabel),
NULp);
670 args.
add(XmNalignment, (org_correct_for_at_center == 1) ? XmALIGNMENT_CENTER : XmALIGNMENT_BEGINNING);
699 int recenterSize = 0;
701 if (!height || !width) {
704 XtVaGetValues(ButOrHigh, XmNheight, &height, XmNwidth, &width,
NULp);
706 if (let_motif_choose_size) {
708 toRecenter = ButOrHigh;
709 recenterSize = width;
718 case 1: shiftback = recenterSize/2;
break;
719 case 2: shiftback = recenterSize;
break;
722 XtVaSetValues(toRecenter, XmNx, x_button-shiftback,
NULp);
741 if (
get_root()->changer_of_variable != widget) {
760 const char *text = tdata->
bitmapOrText[(var[0] ==
'0' || var[0] ==
'n') ? 0 : 1];
772 void AW_window::create_toggle(
const char *var_name,
aw_toggle_data *tdata) {
818 void AW_window::create_toggle(
const char *var_name,
const char *
no,
const char *
yes,
int buttonWidth) {
830 create_toggle(var_name, tdata);
840 create_toggle(var_name, tdata);
844 void AW_window::create_toggle(
const char *var_name) {
845 create_toggle(var_name,
"#no.xpm",
"#yes.xpm");
851 create_toggle(var_name,
"#yes.xpm",
"#no.xpm");
863 int xoff_for_label = 0;
870 int width_of_input_label, height_of_input_label;
871 calculate_label_size(&width_of_input_label, &height_of_input_label,
true);
872 #if defined(DUMP_BUTTON_CREATION)
873 printf(
"width_of_input_label=%i height_of_input_label=%i label='%s'\n", width_of_input_label, height_of_input_label, _at->
label_for_inputfield);
874 #endif // DUMP_BUTTON_CREATION
876 int width_of_input = this->calculate_string_width(columns+1) + 9;
884 label_widget = XtVaCreateManagedWidget(
"label",
887 XmNwidth, (
int)(width_of_input_label + 2),
888 XmNhighlightThickness, 0,
890 XmNrecomputeSize,
false,
891 XmNalignment, XmALIGNMENT_BEGINNING,
897 xoff_for_label = width_of_input_label + 10;
901 int width_of_last_widget = xoff_for_label + width_of_input + 2;
910 textField = XtVaCreateManagedWidget(
"textField",
911 xmTextFieldWidgetClass,
913 XmNwidth, (
int)width_of_input,
936 XtAddCallback(textField, XmNactivateCallback,
940 XtAddCallback(textField, XmNactivateCallback,
948 XtAddCallback(textField, XmNlosingFocusCallback,
949 (XtCallbackProc) AW_variable_update_callback,
952 XtAddCallback(textField, XmNvalueChangedCallback,
960 XtVaGetValues(textField, XmNheight, &height,
NULp);
961 int height_of_last_widget = height;
964 XtVaSetValues(textField, XmNx, ((
int)(_at->
x_for_next_button + xoff_for_label) - (
int)(width_of_last_widget/2) + 1),
NULp);
966 XtVaSetValues(label_widget, XmNx, ((
int)(_at->
x_for_next_button) - (
int)(width_of_last_widget/2) + 1),
NULp);
968 width_of_last_widget = width_of_last_widget / 2;
971 XtVaSetValues(textField, XmNx, (
int)(_at->
x_for_next_button + xoff_for_label - width_of_last_widget + 3),
NULp);
975 width_of_last_widget = 0;
977 width_of_last_widget -= 2;
985 XtVaSetValues(widget, XmNvalue, var_value,
NULp);
989 Widget scrolledWindowText;
995 short width_of_last_widget = 0;
996 short height_of_last_widget = 0;
997 int width_of_text = 0;
998 int height_of_text = 0;
999 int xoff_for_label = 0;
1004 int width_of_text_label, height_of_text_label;
1005 calculate_label_size(&width_of_text_label, &height_of_text_label,
true);
1009 width_of_text = this->calculate_string_width(columns) + 18;
1010 height_of_text = this->calculate_string_height(rows, rows*4) + 9;
1015 label_widget = XtVaCreateManagedWidget(
"label",
1019 XmNy, (
int)(_at->
y_for_next_button) + this->get_root()->y_correction_for_input_labels + 5 - 6,
1020 XmNwidth, (
int)(width_of_text_label + 2),
1022 XmNrecomputeSize,
false,
1023 XmNalignment, XmALIGNMENT_BEGINNING,
1027 xoff_for_label = width_of_text_label + 10;
1033 args.
add(XmNscrollingPolicy, XmAPPLICATION_DEFINED);
1034 args.
add(XmNvisualPolicy, XmVARIABLE);
1035 args.
add(XmNscrollBarDisplayPolicy, XmSTATIC);
1036 args.
add(XmNfontList, (XtArgVal)
p_global->fontlist);
1039 scrolledWindowText = XtVaCreateManagedWidget(
"scrolledWindowList1", xmScrolledWindowWidgetClass,
INFO_FORM,
NULp);
1049 scrolledWindowText = XtVaCreateManagedWidget(
"scrolledWindowText", xmScrolledWindowWidgetClass,
INFO_WIDGET,
NULp);
1057 scrolledText = XtVaCreateManagedWidget(
"scrolledText1",
1060 XmNeditMode, XmMULTI_LINE_EDIT,
1062 XmNscrollLeftSide,
false,
1063 XmNwidth, (
int)width_of_text,
1064 XmNheight, (
int)height_of_text,
1071 XtVaGetValues(scrolledWindowText, XmNheight, &height_of_last_widget,
1072 XmNwidth, &width_of_last_widget,
NULp);
1074 width_of_last_widget += (
short)xoff_for_label;
1082 XtVaSetValues(scrolledWindowText, XmNx, (
int)(_at->
x_for_next_button + xoff_for_label - (width_of_last_widget/2)),
NULp);
1086 width_of_last_widget = width_of_last_widget / 2;
1090 XtVaSetValues(scrolledWindowText, XmNx, (
int)(_at->
x_for_next_button + xoff_for_label - width_of_last_widget),
NULp);
1094 width_of_last_widget = 0;
1106 XtAddCallback(scrolledText, XmNlosingFocusCallback, (XtCallbackProc) AW_variable_update_callback, (XtPointer) vui);
1111 root->make_sensitive(scrolledText, _at->
widget_mask);
1119 XtVaSetValues(widget, XmNvalue, var_value,
NULp);
1123 XmScaleCallbackStruct *cbs = (XmScaleCallbackStruct*)call_data;
1126 bool do_update =
true;
1127 if (cbs->reason == XmCR_DRAG) {
1130 const double MAX_DRAGGED_CALLBACK_TIME = 1.0;
1131 if (mean_callback_time>MAX_DRAGGED_CALLBACK_TIME) {
1152 Widget scale = XtVaCreateManagedWidget(
"scale",
1157 XmNorientation, XmHORIZONTAL,
1158 XmNscaleWidth, scaler_length,
1159 XmNshowValue, False,
1162 XmNvalue, scalerValue,
1165 short width_of_last_widget = 0;
1166 short height_of_last_widget = 0;
1168 XtVaGetValues(scale,
1169 XmNheight, &height_of_last_widget,
1170 XmNwidth, &width_of_last_widget,
1177 XtAddCallback(scale, XmNvalueChangedCallback,
scalerChanged_cb, (XtPointer)vui);
1189 XtVaSetValues(widget, XmNvalue, scalerVal,
NULp);
1197 int oldPos, visible, items;
1198 XtVaGetValues(scrolledList,
1199 XmNtopItemPosition, &oldPos,
1200 XmNvisibleItemCount, &visible,
1201 XmNitemCount, &items,
1204 int amount = visible/5;
1205 if (amount<1) amount = 1;
1206 if (upwards) amount = -amount;
1208 int newPos =
force_in_range(1, oldPos + amount, items-visible+2);
1209 if (newPos != oldPos) XmListSetPos(scrolledList, newPos);
1216 Widget scrolledWindowList;
1223 int width_of_last_widget = 0;
1224 int height_of_last_widget = 0;
1232 if (var_name) vs =
root->
awar(var_name);
1234 width_of_list = this->calculate_string_width(columns) + 9;
1235 height_of_list = this->calculate_string_height(rows, 4*rows) + 9;
1239 args.
add(XmNvisualPolicy, XmVARIABLE);
1240 args.
add(XmNscrollBarDisplayPolicy, XmSTATIC);
1241 args.
add(XmNshadowThickness, 0);
1242 args.
add(XmNfontList, (XtArgVal)
p_global->fontlist);
1249 scrolledWindowList = XtVaCreateManagedWidget(
"scrolledWindowList1", xmScrolledWindowWidgetClass,
INFO_FORM,
NULp);
1258 scrolledWindowList = XtVaCreateManagedWidget(
"scrolledWindowList1", xmScrolledWindowWidgetClass,
INFO_WIDGET,
NULp);
1260 args.
add(XmNscrollingPolicy, XmAPPLICATION_DEFINED);
1268 int select_type = XmMULTIPLE_SELECT;
1269 if (vs) select_type = XmBROWSE_SELECT;
1272 scrolledList = XtVaCreateManagedWidget(
"scrolledList1",
1275 XmNwidth, (
int)width_of_list,
1276 XmNheight, (
int) height_of_list,
1277 XmNscrollBarDisplayPolicy, XmSTATIC,
1278 XmNselectionPolicy, select_type,
1279 XmNlistSizePolicy, XmCONSTANT,
1284 static bool actionsAdded =
false;
1285 if (!actionsAdded) {
1286 struct _XtActionsRec actions[2] = {
1291 XtAppAddActions(
p_global->context, actions, 2);
1294 XtTranslations translations = XtParseTranslationTable(
1295 "<Btn4Down>:scroll_sellist_up()\n"
1296 "<Btn5Down>:scroll_sellist_dn()\n"
1298 XtAugmentTranslations(scrolledList, translations);
1303 XtVaGetValues(scrolledList, XmNheight, &height,
NULp);
1304 height_of_last_widget = height + 20;
1305 width_of_last_widget = width_of_list + 20;
1314 XtVaSetValues(scrolledWindowList, XmNx, (
int)(_at->
x_for_next_button - (width_of_last_widget/2)),
NULp);
1315 width_of_last_widget = width_of_last_widget / 2;
1320 width_of_last_widget = 0;
1348 XtAddCallback(scrolledList, XmNbrowseSelectionCallback,
1353 XtAddCallback(scrolledList, XmNdefaultActionCallback,
1363 return p_global->last_selection_list;
void TuneBackground(Widget w, int modStrength)
#define AW_JUSTIFY_LABEL(widget, corr)
void define_remote_command(class AW_cb *cbs)
GB_ERROR GB_incur_error()
static void dot(double **i, double **j, double **k)
AW_awar * label_is_awar(const char *label)
GB_ERROR GB_add_callback(GBDATA *gbd, GB_CB_TYPE type, const DatabaseCallback &dbcb)
void update_label(Widget widget, const char *var_value)
void change_from_widget(XtPointer call_data)
short length_of_label_for_inputfield
void _set_activate_callback(void *widget)
AW_VARIABLE_TYPE variable_type
GB_ERROR GB_IO_error(const char *action, const char *filename)
GB_ERROR write_to(class AW_awar *awar) const
int y_correction_for_input_labels
const char * GBS_global_string(const char *templat,...)
void GBK_terminatef(const char *templat,...)
char * window_defaults_name
window title
void update_text_field(Widget widget, const char *var_value)
char buffer[MESSAGE_BUFFERSIZE]
void update_toggle(Widget widget, const char *var_value, AW_CL cd)
void create_input_field_with_scaler(const char *awar_name, int textcolumns=4, int scaler_length=250, AW_ScalerType scalerType=AW_SCALER_LINEAR)
void update_input_field(Widget widget, const char *var_value)
bool AW_IS_IMAGEREF(const char *label)
static AW_root * SINGLETON
Widget get_last_widget() const
#define RES_LABEL_CONVERT(label)
void create_inverse_toggle(const char *awar_name)
void increment_at_commands(int width, int height)
void GBK_terminate(const char *error) __ATTR__NORETURN
CONSTEXPR_INLINE const T & force_in_range(const T &lower_bound, const T &value, const T &upper_bound)
double mean_callback_time() const
void track_awar_change(AW_awar *changed_awar)
static char const * macro_name
void assign_to_widget(Widget w)
static void error(const char *msg)
char * read_as_string() const
const AW_scalar & get_value() const
AW_selection_list_entry * next
void TuneOrSetBackground(Widget w, const char *color, int modStrength)
int label_widget(void *wgt, AW_label str, char *mnemonic=NULp, int width=0, int alignment=0)
char * read_string() const
AW_awar * awar(const char *awar)
void create_autosize_button(const char *macro_name, AW_label label, const char *mnemonic=NULp, unsigned xtraSpace=1)
#define RES_CONVERT(res_name, res_value)
GB_ERROR write_as_string(const char *aw_string)
void create_input_field(const char *awar_name, int columns=0)
unsigned long int background_color
void update_scaler(Widget widget, AW_awar *awar, AW_ScalerType scalerType)
#define IF_ASSERTION_USED(x)
#define __ATTR__USERESULT
void make_sensitive(Widget w, AW_active mask)
void GB_remove_callback(GBDATA *gbd, GB_CB_TYPE type, const DatabaseCallback &dbcb)
AW_selection_list * create_selection_list(const char *awar_name, int columns, int rows)
GB_CSTR GB_concat_path_in_ARBLIB(const char *relative_path_left, const char *anypath_right)
void aw_message(const char *msg)
void set_scalerType(AW_ScalerType scalerType_)
TrackedAwarChange(AW_awar *awar_)
void dump_at_position(const char *debug_label) const
void create_text_toggle(const char *var_name, const char *noText, const char *yesText, int buttonWidth=0)
char * label_for_inputfield
void AW_label_in_awar_list(AW_window *aww, Widget widget, const char *str)
void AW_server_callback(Widget, XtPointer aw_cb_struct, XtPointer)
#define SPACE_BEHIND_BUTTON
Widget changer_of_variable
static void useraction_init()
GB_transaction ta(gb_var)
static void useraction_done(AW_window *aw)
GB_ERROR write_float(float aw_float)
void add(String name, XtArgVal value)
int correct_for_at_center
GB_ERROR write_int(long aw_int)
struct _WidgetRec * Widget
void create_text_field(const char *awar_name, int columns=20, int rows=4)
void aw_message_if(GB_ERROR error)
char * GBS_global_string_copy(const char *templat,...)
void tie_widget(AW_CL cd1, Widget widget, AW_widget_type type, AW_window *aww)
void create_button(const char *macro_name, AW_label label, const char *mnemonic=NULp, const char *color=NULp)
void set_sellist(AW_selection_list *asl)