summaryrefslogtreecommitdiff
path: root/app/wlib/gtklib/util.c
diff options
context:
space:
mode:
authorJörg Frings-Fürst <debian@jff-webhosting.net>2018-03-19 19:56:15 +0100
committerJörg Frings-Fürst <debian@jff-webhosting.net>2018-03-19 19:56:15 +0100
commit1542c122b3672fe83e027411ad2445772e2d0ed3 (patch)
treee535bc621bd7ffa9d5ce89e0d495df5d1c4ab6fd /app/wlib/gtklib/util.c
parent773810e6583142d7d15263e6481c42aebed6d7f1 (diff)
parentd1a8285f818eb7e5c3d6a05709ea21a808490b8c (diff)
Update upstream source from tag 'upstream/5.1.0'
Update to upstream version '5.1.0' with Debian dir 93ca74b8b4602fce4c9c7740e0cfdde25f086673
Diffstat (limited to 'app/wlib/gtklib/util.c')
-rw-r--r--app/wlib/gtklib/util.c235
1 files changed, 124 insertions, 111 deletions
diff --git a/app/wlib/gtklib/util.c b/app/wlib/gtklib/util.c
index 61b5b95..e6587a0 100644
--- a/app/wlib/gtklib/util.c
+++ b/app/wlib/gtklib/util.c
@@ -23,6 +23,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
+#include <string.h>
#define GTK_DISABLE_SINGLE_INCLUDES
#define GDK_DISABLE_DEPRECATED
@@ -74,7 +75,7 @@ static wBool_t reverseIcon =
#endif
-
+
/*
*****************************************************************************
*
@@ -91,7 +92,7 @@ static wBool_t reverseIcon =
*/
GdkPixbuf* wlibPixbufFromXBM(
- wIcon_p ip )
+ wIcon_p ip)
{
GdkPixbuf * pixbuf;
@@ -99,39 +100,41 @@ GdkPixbuf* wlibPixbufFromXBM(
char line2[40];
char ** pixmapData;
- int row,col,wb;
+ int row, col, wb;
long rgb;
const char * bits;
- wb = (ip->w+7)/8;
- pixmapData = (char**)malloc((3+ip->h) * sizeof *pixmapData);
+ wb = (ip->w + 7) / 8;
+ pixmapData = (char**) malloc((3 + ip->h) * sizeof *pixmapData);
pixmapData[0] = line0;
rgb = wDrawGetRGB(ip->color);
sprintf(line0, " %d %d 2 1", ip->w, ip->h);
- sprintf(line2, "# c #%2.2lx%2.2lx%2.2lx", (rgb>>16)&0xFF, (rgb>>8)&0xFF,
- rgb&0xFF);
+ sprintf(line2, "# c #%2.2lx%2.2lx%2.2lx", (rgb >> 16)&0xFF, (rgb >> 8)&0xFF,
+ rgb & 0xFF);
pixmapData[1] = ". c None s None";
pixmapData[2] = line2;
bits = ip->bits;
- for (row = 0; row<ip->h; row++) {
- pixmapData[row+3] = (char*)malloc((ip->w+1) * sizeof **pixmapData);
+ for (row = 0; row < ip->h; row++) {
+ pixmapData[row + 3] = (char*) malloc((ip->w + 1) * sizeof **pixmapData);
- for (col = 0; col<ip->w; col++) {
- if (bits[ row*wb+(col>>3) ] & (1<<(col&07))) {
- pixmapData[row+3][col] = '#';
- } else {
- pixmapData[row+3][col] = '.';
+ for (col = 0; col < ip->w; col++) {
+ if (bits[ row * wb + (col >> 3) ] & (1 << (col & 07))) {
+ pixmapData[row + 3][col] = '#';
+ }
+ else {
+ pixmapData[row + 3][col] = '.';
}
}
- pixmapData[row+3][ip->w] = 0;
+ pixmapData[row + 3][ip->w] = 0;
}
- pixbuf = gdk_pixbuf_new_from_xpm_data((const char **)pixmapData);
+ pixbuf = gdk_pixbuf_new_from_xpm_data((const char **) pixmapData);
- for (row = 0; row<ip->h; row++) {
- free(pixmapData[row+3]);
+ for (row = 0; row < ip->h; row++) {
+ free(pixmapData[row + 3]);
}
+ free(pixmapData);
return pixbuf;
}
@@ -145,7 +148,7 @@ GdkPixbuf* wlibPixbufFromXBM(
int wlibAddLabel(wControl_p b, const char * labelStr)
{
- GtkRequisition requisition;
+ GtkRequisition requisition, reqwidget;
if (labelStr == NULL) {
return 0;
@@ -153,12 +156,15 @@ int wlibAddLabel(wControl_p b, const char * labelStr)
b->label = gtk_label_new(wlibConvertInput(labelStr));
gtk_widget_size_request(b->label, &requisition);
+ if (b->widget)
+ gtk_widget_size_request(b->widget, &reqwidget);
+ else
+ reqwidget.height = requisition.height;
gtk_container_add(GTK_CONTAINER(b->parent->widget), b->label);
gtk_fixed_move(GTK_FIXED(b->parent->widget), b->label,
- b->realX-requisition.width-8, b->realY+LABEL_OFFSET);
-
+ b->realX - requisition.width - 8, b->realY + (reqwidget.height/2 - requisition.height/2));
gtk_widget_show(b->label);
- return requisition.width+8;
+ return requisition.width + 8;
}
/**
@@ -175,15 +181,15 @@ int wlibAddLabel(wControl_p b, const char * labelStr)
*/
void * wlibAlloc(
- wWin_p parent,
- wType_e type,
- wPos_t origX,
- wPos_t origY,
- const char * labelStr,
- int size,
- void * data)
+ wWin_p parent,
+ wType_e type,
+ wPos_t origX,
+ wPos_t origY,
+ const char * labelStr,
+ int size,
+ void * data)
{
- wControl_p w = (wControl_p)malloc(size);
+ wControl_p w = (wControl_p) malloc(size);
char * cp;
memset(w, 0, size);
@@ -197,7 +203,7 @@ void * wlibAlloc(
w->origY = origY;
if (labelStr) {
- cp = (char*)malloc(strlen(labelStr)+1);
+ cp = (char*) malloc(strlen(labelStr) + 1);
w->labelStr = cp;
for (; *labelStr; labelStr++)
@@ -220,19 +226,21 @@ void * wlibAlloc(
*/
void wlibComputePos(
- wControl_p b)
+ wControl_p b)
{
wWin_p w = b->parent;
if (b->origX >= 0) {
b->realX = b->origX;
- } else {
+ }
+ else {
b->realX = w->lastX + (-b->origX) - 1;
}
if (b->origY >= 0) {
- b->realY = b->origY + BORDERSIZE + ((w->option&F_MENUBAR)?MENUH:0);
- } else {
+ b->realY = b->origY + BORDERSIZE + ((w->option & F_MENUBAR) ? w->menu_height : 0);
+ }
+ else {
b->realY = w->lastY + (-b->origY) - 1;
}
}
@@ -244,7 +252,7 @@ void wlibComputePos(
*/
void wlibControlGetSize(
- wControl_p b)
+ wControl_p b)
{
GtkRequisition requisition;
gtk_widget_size_request(b->widget, &requisition);
@@ -258,14 +266,15 @@ void wlibControlGetSize(
*/
void wlibAddButton(
- wControl_p b)
+ wControl_p b)
{
wWin_p win = b->parent;
wBool_t resize = FALSE;
if (win->first == NULL) {
win->first = b;
- } else {
+ }
+ else {
win->last->next = b;
}
@@ -275,7 +284,7 @@ void wlibAddButton(
win->lastX = b->realX + b->w;
win->lastY = b->realY + b->h;
- if (win->option&F_AUTOSIZE) {
+ if (win->option & F_AUTOSIZE) {
if (win->lastX > win->realX) {
win->realX = win->lastX;
@@ -312,20 +321,20 @@ void wlibAddButton(
*/
wControl_p wlibGetControlFromPos(
- wWin_p win,
- wPos_t x,
- wPos_t y)
+ wWin_p win,
+ wPos_t x,
+ wPos_t y)
{
wControl_p b;
wPos_t xx, yy;
- for (b=win->first; b != NULL; b = b->next) {
+ for (b = win->first; b != NULL; b = b->next) {
if (b->widget && gtk_widget_get_visible(b->widget)) {
xx = b->realX;
yy = b->realY;
- if (xx <= x && x < xx+b->w &&
- yy <= y && y < yy+b->h) {
+ if (xx <= x && x < xx + b->w &&
+ yy <= y && y < yy + b->h) {
return b;
}
}
@@ -334,7 +343,7 @@ wControl_p wlibGetControlFromPos(
return NULL;
}
-
+
/*
*****************************************************************************
*
@@ -352,13 +361,12 @@ void wBeep(void)
gdk_display_beep(gdk_display_get_default());
}
-
/**
* Flushs all commands to the Window.
*/
void wFlush(
- void)
+ void)
{
while (gtk_events_pending()) {
gtk_main_iteration();
@@ -427,36 +435,36 @@ char * wlibConvertInput(const char * inString)
/* Already UTF-8 encoded? */
if (g_utf8_validate(inString, -1, NULL))
- /* Yes, do not double-convert */
- {
- return (char*)inString;
+ /* Yes, do not double-convert */ {
+ return (char*) inString;
}
- for (cp=inString, extCharCnt=0; *cp; cp++) {
+ for (cp = inString, extCharCnt = 0; *cp; cp++) {
if (((*cp)&0x80) != '\0') {
extCharCnt++;
}
}
- inCharCnt = cp-inString;
+ inCharCnt = cp - inString;
if (extCharCnt == '\0') {
- return (char*)inString;
+ return (char*) inString;
}
- DYNARR_SET(char, conversionBuffer_da, inCharCnt+extCharCnt+1);
+ DYNARR_SET(char, conversionBuffer_da, inCharCnt + extCharCnt + 1);
- for (cp=inString, cq=(char*)conversionBuffer_da.ptr; *cp; cp++) {
+ for (cp = inString, cq = (char*) conversionBuffer_da.ptr; *cp; cp++) {
if (((*cp)&0x80) != 0) {
- *cq++ = 0xC0+(((*cp)&0xC0)>>6);
- *cq++ = 0x80+((*cp)&0x3F);
- } else {
+ *cq++ = 0xC0 + (((*cp)&0xC0) >> 6);
+ *cq++ = 0x80 + ((*cp)&0x3F);
+ }
+ else {
*cq++ = *cp;
}
}
*cq = 0;
- return (char*)conversionBuffer_da.ptr;
+ return (char*) conversionBuffer_da.ptr;
}
/**
@@ -472,31 +480,32 @@ char * wlibConvertOutput(const char * inString)
char * cq;
int extCharCnt, inCharCnt;
- for (cp=inString, extCharCnt=0; *cp; cp++) {
+ for (cp = inString, extCharCnt = 0; *cp; cp++) {
if (((*cp)&0xC0) == 0x80) {
extCharCnt++;
}
}
- inCharCnt = cp-inString;
+ inCharCnt = cp - inString;
if (extCharCnt == '\0') {
- return (char*)inString;
+ return (char*) inString;
}
- DYNARR_SET(char, conversionBuffer_da, inCharCnt+1);
+ DYNARR_SET(char, conversionBuffer_da, inCharCnt + 1);
- for (cp=inString, cq=(char*)conversionBuffer_da.ptr; *cp; cp++) {
+ for (cp = inString, cq = (char*) conversionBuffer_da.ptr; *cp; cp++) {
if (((*cp)&0x80) != 0) {
- *cq++ = 0xC0+(((*cp)&0xC0)>>6);
- *cq++ = 0x80+((*cp)&0x3F);
- } else {
+ *cq++ = 0xC0 + (((*cp)&0xC0) >> 6);
+ *cq++ = 0x80 + ((*cp)&0x3F);
+ }
+ else {
*cq++ = *cp;
}
}
*cq = '\0';
- return (char*)conversionBuffer_da.ptr;
+ return (char*) conversionBuffer_da.ptr;
}
/*-----------------------------------------------------------------*/
@@ -506,30 +515,32 @@ static dynArr_t accelData_da;
#define accelData(N) DYNARR_N( accelData_t, accelData_da, N )
static guint accelKeyMap[] = {
- 0, /* wAccelKey_None, */
- GDK_KEY_Delete, /* wAccelKey_Del, */
- GDK_KEY_Insert, /* wAccelKey_Ins, */
- GDK_KEY_Home, /* wAccelKey_Home, */
- GDK_KEY_End, /* wAccelKey_End, */
- GDK_KEY_Page_Up, /* wAccelKey_Pgup, */
- GDK_KEY_Page_Down, /* wAccelKey_Pgdn, */
- GDK_KEY_Up, /* wAccelKey_Up, */
- GDK_KEY_Down, /* wAccelKey_Down, */
- GDK_KEY_Right, /* wAccelKey_Right, */
- GDK_KEY_Left, /* wAccelKey_Left, */
- GDK_KEY_BackSpace, /* wAccelKey_Back, */
- GDK_KEY_F1, /* wAccelKey_F1, */
- GDK_KEY_F2, /* wAccelKey_F2, */
- GDK_KEY_F3, /* wAccelKey_F3, */
- GDK_KEY_F4, /* wAccelKey_F4, */
- GDK_KEY_F5, /* wAccelKey_F5, */
- GDK_KEY_F6, /* wAccelKey_F6, */
- GDK_KEY_F7, /* wAccelKey_F7, */
- GDK_KEY_F8, /* wAccelKey_F8, */
- GDK_KEY_F9, /* wAccelKey_F9, */
- GDK_KEY_F10, /* wAccelKey_F10, */
- GDK_KEY_F11, /* wAccelKey_F11, */
- GDK_KEY_F12 /* wAccelKey_F12, */
+ 0, /* wAccelKey_None, */
+ GDK_KEY_Delete, /* wAccelKey_Del, */
+ GDK_KEY_Insert, /* wAccelKey_Ins, */
+ GDK_KEY_Home, /* wAccelKey_Home, */
+ GDK_KEY_End, /* wAccelKey_End, */
+ GDK_KEY_Page_Up, /* wAccelKey_Pgup, */
+ GDK_KEY_Page_Down, /* wAccelKey_Pgdn, */
+ GDK_KEY_Up, /* wAccelKey_Up, */
+ GDK_KEY_Down, /* wAccelKey_Down, */
+ GDK_KEY_Right, /* wAccelKey_Right, */
+ GDK_KEY_Left, /* wAccelKey_Left, */
+ GDK_KEY_BackSpace, /* wAccelKey_Back, */
+ GDK_KEY_F1, /* wAccelKey_F1, */
+ GDK_KEY_F2, /* wAccelKey_F2, */
+ GDK_KEY_F3, /* wAccelKey_F3, */
+ GDK_KEY_F4, /* wAccelKey_F4, */
+ GDK_KEY_F5, /* wAccelKey_F5, */
+ GDK_KEY_F6, /* wAccelKey_F6, */
+ GDK_KEY_F7, /* wAccelKey_F7, */
+ GDK_KEY_F8, /* wAccelKey_F8, */
+ GDK_KEY_F9, /* wAccelKey_F9, */
+ GDK_KEY_F10, /* wAccelKey_F10, */
+ GDK_KEY_F11, /* wAccelKey_F11, */
+ GDK_KEY_F12, /* wAccelKey_F12, */
+ GDK_KEY_KP_Add, /* wAccelKey_Numpad_Add */
+ GDK_KEY_KP_Subtract /* wAccelKey_Numpad_Subtract */
};
/**
@@ -542,20 +553,20 @@ static guint accelKeyMap[] = {
*/
void wAttachAccelKey(
- wAccelKey_e key,
- int modifier,
- wAccelKeyCallBack_p action,
- void * data)
+ wAccelKey_e key,
+ int modifier,
+ wAccelKeyCallBack_p action,
+ void * data)
{
accelData_t * ad;
- if (key < 1 || key > wAccelKey_F12) {
- fprintf(stderr, "wAttachAccelKey(%d) out of range\n", (int)key);
- return;
- }
+// if (key < 1 || key > wAccelKey_F12) {
+// fprintf(stderr, "wAttachAccelKey(%d) out of range\n", (int) key);
+// return;
+// }
DYNARR_APPEND(accelData_t, accelData_da, 10);
- ad = &accelData(accelData_da.cnt-1);
+ ad = &accelData(accelData_da.cnt - 1);
ad->key = key;
ad->modifier = modifier;
ad->action = action;
@@ -570,7 +581,7 @@ void wAttachAccelKey(
*/
struct accelData_t * wlibFindAccelKey(
- GdkEventKey * event)
+ GdkEventKey * event)
{
accelData_t * ad;
int modifier = 0;
@@ -587,9 +598,9 @@ struct accelData_t * wlibFindAccelKey(
modifier |= WKEY_ALT;
}
- for (ad=&accelData(0); ad<&accelData(accelData_da.cnt); ad++)
+ for (ad = &accelData(0); ad<&accelData(accelData_da.cnt); ad++)
if (event->keyval == accelKeyMap[ad->key] &&
- modifier == ad->modifier) {
+ modifier == ad->modifier) {
return ad;
}
@@ -604,7 +615,7 @@ struct accelData_t * wlibFindAccelKey(
*/
wBool_t wlibHandleAccelKey(
- GdkEventKey *event)
+ GdkEventKey *event)
{
accelData_t * ad = wlibFindAccelKey(event);
@@ -615,7 +626,7 @@ wBool_t wlibHandleAccelKey(
return FALSE;
}
-
+
/**
* Add control to circular list of synonymous controls. Synonymous controls are kept in sync by
* calling wControlLinkedActive for one member of the list
@@ -652,8 +663,9 @@ void wControlLinkedActive(wControl_p b, int active)
wControl_p savePtr = b;
if (savePtr->type == B_MENUITEM) {
- wMenuPushEnable((wMenuPush_p)savePtr, active);
- } else {
+ wMenuPushEnable((wMenuPush_p) savePtr, active);
+ }
+ else {
wControlActive(savePtr, active);
}
@@ -662,8 +674,9 @@ void wControlLinkedActive(wControl_p b, int active)
while (savePtr && savePtr != b) {
if (savePtr->type == B_MENUITEM) {
- wMenuPushEnable((wMenuPush_p)savePtr, active);
- } else {
+ wMenuPushEnable((wMenuPush_p) savePtr, active);
+ }
+ else {
wControlActive(savePtr, active);
}