1
0
mirror of https://github.com/gryf/wmaker.git synced 2025-12-20 12:58:08 +01:00
Files
wmaker/WINGs/Extras/test.c
Carlos R. Mafra 06f59b9928 wmaker: Fix compiler warnings about pointer <--> integer conversion
There may be issues with running applications in 64-bit mode when
they were written with tacit assumptions about 32-bit platforms.
For example,

    * Assuming that a pointer can be cast back and forth to an integer

The reason is that the size of the integer and pointer may be different.
See the description of "[PATCH] Warn when casting a pointer (constant)
to an integer of different size." in the gcc mailing list

http://gcc.gnu.org/ml/gcc-patches/2005-12/msg01881.html

where it was also suggested the use of casts to uintptr_t. This is
what this patch does.

As a result the following warnings are fixed, leaving us with an
almost warning-free compilation in 64-bit platforms:

defaults.c:1446: warning: cast to pointer from integer of different size
defaults.c:1457: warning: cast to pointer from integer of different size
defaults.c:1471: warning: cast to pointer from integer of different size
defaults.c:1486: warning: cast to pointer from integer of different size
icon.c:67: warning: cast from pointer to integer of different size
menu.c:112: warning: cast from pointer to integer of different size
switchmenu.c:452: warning: cast from pointer to integer of different size
window.c:140: warning: cast from pointer to integer of different size
window.c:2217: warning: cast to pointer from integer of different size
workspace.c:135: warning: cast to pointer from integer of different size
workspace.c:214: warning: cast to pointer from integer of different size
workspace.c:634: warning: cast to pointer from integer of different size
workspace.c:1330: warning: cast to pointer from integer of different size
workspace.c:1514: warning: cast to pointer from integer of different size
wfilepanel.c:135: warning: cast from pointer to integer of different size
wfilepanel.c:171: warning: cast from pointer to integer of different size
wfontpanel.c:499: warning: cast to pointer from integer of different size
wfontpanel.c:500: warning: cast to pointer from integer of different size
wfontpanel.c:505: warning: cast to pointer from integer of different size
wfontpanel.c:506: warning: cast to pointer from integer of different size
wfontpanel.c:776: warning: cast from pointer to integer of different size
wfontpanel.c:777: warning: cast from pointer to integer of different size
wfontpanel.c:877: warning: cast from pointer to integer of different size
wfontpanel.c:878: warning: cast from pointer to integer of different size
wpanel.c:363: warning: cast from pointer to integer of different size
fontl.c:42: warning: cast from pointer to integer of different size
fontl.c:42: warning: cast from pointer to integer of different size
fontl.c:42: warning: cast from pointer to integer of different size
fontl.c:90: warning: cast to pointer from integer of different size
puzzle.c:138: warning: cast from pointer to integer of different size
puzzle.c:225: warning: cast to pointer from integer of different size
wtableview.c:1031: warning: cast to pointer from integer of different size
wtableview.c:1067: warning: cast to pointer from integer of different size
wtableview.c:1069: warning: cast to pointer from integer of different size
wtableview.c:1074: warning: cast to pointer from integer of different size
wtabledelegates.c:234: warning: cast from pointer to integer of different size
wtabledelegates.c:250: warning: cast from pointer to integer of different size
wtabledelegates.c:265: warning: cast from pointer to integer of different size
wtabledelegates.c:287: warning: cast to pointer from integer of different size
wtabledelegates.c:351: warning: cast from pointer to integer of different size
wtabledelegates.c:372: warning: cast from pointer to integer of different size
wtabledelegates.c:393: warning: cast from pointer to integer of different size
wtabledelegates.c:410: warning: cast to pointer from integer of different size
test.c:44: warning: cast from pointer to integer of different size
test.c:47: warning: cast to pointer from integer of different size
test.c:55: warning: cast from pointer to integer of different size
test.c:58: warning: cast from pointer to integer of different size
2008-11-06 09:07:50 +01:00

142 lines
3.0 KiB
C

#include <WINGs/WINGs.h>
#include <stdio.h>
#include <stdint.h>
#include "wtableview.h"
#include "wtabledelegates.h"
static char *col1[20] = {0};
static int col2[20];
static char *options[] = {
"Option1",
"Option2",
"Option3",
"Option4",
"Option5"
};
int
numberOfRows(WMTableViewDelegate *self, WMTableView *table)
{
return 20;
}
void*
valueForCell(WMTableViewDelegate *self, WMTableColumn *column, int row)
{
/*WMTableView *table = (WMTableView*)WMGetTableColumnTableView(column);*/
int i;
if (col1[0] == 0) {
for (i = 0; i < 20; i++) {
char buf[128];
sprintf(buf, "Test row %i", i);
col1[i] = wstrdup(buf);
col2[i] = 0;
}
}
if ((int)(uintptr_t)WMGetTableColumnId(column) == 1)
return col1[row];
else
return (void*)(uintptr_t)col2[row];
}
void
setValueForCell(WMTableViewDelegate *self, WMTableColumn *column, int row,
void *data)
{
if ((int)(uintptr_t)WMGetTableColumnId(column) == 1)
col1[row] = data;
else
col2[row] = (int)(uintptr_t)data;
}
static WMTableViewDelegate delegate = {
NULL,
numberOfRows,
valueForCell,
setValueForCell
};
void
clickedTable(WMWidget *w, void *self)
{
int row = WMGetTableViewClickedRow((WMTableView*)self);
WMEditTableViewRow(self, row);
}
int
main(int argc, char **argv)
{
WMScreen *scr;
WMWindow *win;
WMTableView *table;
WMTableColumn *col;
WMTableColumnDelegate *colDeleg;
WMInitializeApplication("test", &argc, argv);
scr = WMOpenScreen(NULL);
XSynchronize(WMScreenDisplay(scr), 1);
win = WMCreateWindow(scr, "eweq");
WMResizeWidget(win, 400, 200);
WMMapWidget(win);
table = WMCreateTableView(win);
WMSetTableViewHasHorizontalScroller(table, 0);
WMSetViewExpandsToParent(WMWidgetView(table), 10, 10, 10, 10);
WMSetTableViewBackgroundColor(table, WMWhiteColor(scr));
/*WMSetTableViewGridColor(table, WMGrayColor(scr));*/
WMSetTableViewHeaderHeight(table, 20);
WMSetTableViewDelegate(table, &delegate);
WMSetTableViewAction(table, clickedTable, table);
colDeleg = WTCreateStringEditorDelegate(table);
col = WMCreateTableColumn("Group");
WMSetTableColumnWidth(col, 180);
WMAddTableViewColumn(table, col);
WMSetTableColumnDelegate(col, colDeleg);
WMSetTableColumnId(col, (void*)1);
colDeleg = WTCreateEnumSelectorDelegate(table);
WTSetEnumSelectorOptions(colDeleg, options, 5);
col = WMCreateTableColumn("Package");
WMSetTableColumnWidth(col, 140);
WMAddTableViewColumn(table, col);
WMSetTableColumnDelegate(col, colDeleg);
WMSetTableColumnId(col, (void*)2);
colDeleg = WTCreateBooleanSwitchDelegate(table);
col = WMCreateTableColumn("Bool");
WMSetTableColumnWidth(col, 50);
WMAddTableViewColumn(table, col);
WMSetTableColumnDelegate(col, colDeleg);
WMSetTableColumnId(col, (void*)2);
WMMapWidget(table);
WMRealizeWidget(win);
WMScreenMainLoop(scr);
return 0;
}