mirror of
https://github.com/gryf/wmaker.git
synced 2026-02-21 09:15:46 +01:00
Change to the linux kernel coding style
for arq in `git ls-files *.c`; do
echo $arq;
indent -linux -l115 $arq;
done
The different line break at 115 columns is because
I use a widescreen monitor :-)
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
/*
|
||||
*
|
||||
* Include the WINGs private data header.
|
||||
@@ -25,29 +24,23 @@
|
||||
* Define the widget "class"
|
||||
*/
|
||||
typedef struct W_MyWidget {
|
||||
/* these two fields must be present in all your widgets in this
|
||||
* exact position */
|
||||
W_Class widgetClass;
|
||||
WMView *view;
|
||||
/* these two fields must be present in all your widgets in this
|
||||
* exact position */
|
||||
W_Class widgetClass;
|
||||
WMView *view;
|
||||
|
||||
/* put your stuff here */
|
||||
char *text;
|
||||
/* put your stuff here */
|
||||
char *text;
|
||||
|
||||
} _MyWidget;
|
||||
|
||||
|
||||
|
||||
|
||||
/* some forward declarations */
|
||||
|
||||
static void destroyMyWidget(_MyWidget *mPtr);
|
||||
static void paintMyWidget(_MyWidget *mPtr);
|
||||
|
||||
|
||||
static void handleEvents(XEvent *event, void *data);
|
||||
static void handleActionEvents(XEvent *event, void *data);
|
||||
|
||||
static void destroyMyWidget(_MyWidget * mPtr);
|
||||
static void paintMyWidget(_MyWidget * mPtr);
|
||||
|
||||
static void handleEvents(XEvent * event, void *data);
|
||||
static void handleActionEvents(XEvent * event, void *data);
|
||||
|
||||
/*
|
||||
* Delegates
|
||||
@@ -55,173 +48,150 @@ static void handleActionEvents(XEvent *event, void *data);
|
||||
* You won't need to use this most of the time.
|
||||
*/
|
||||
static W_ViewDelegate _MyWidgetDelegate = {
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
/* our widget class ID */
|
||||
static W_Class myWidgetClass = 0;
|
||||
|
||||
|
||||
/*
|
||||
* Initializer for our widget. Must be called before creating any
|
||||
* instances of the widget.
|
||||
*/
|
||||
W_Class
|
||||
InitMyWidget(WMScreen *scr)
|
||||
W_Class InitMyWidget(WMScreen * scr)
|
||||
{
|
||||
/* register our widget with WINGs and get our widget class ID */
|
||||
if (!myWidgetClass) {
|
||||
myWidgetClass = W_RegisterUserWidget();
|
||||
}
|
||||
/* register our widget with WINGs and get our widget class ID */
|
||||
if (!myWidgetClass) {
|
||||
myWidgetClass = W_RegisterUserWidget();
|
||||
}
|
||||
|
||||
return myWidgetClass;
|
||||
return myWidgetClass;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Our widget fabrication plant.
|
||||
*/
|
||||
MyWidget*
|
||||
CreateMyWidget(WMWidget *parent)
|
||||
MyWidget *CreateMyWidget(WMWidget * parent)
|
||||
{
|
||||
MyWidget *mPtr;
|
||||
MyWidget *mPtr;
|
||||
|
||||
/* allocate some storage for our new widget instance */
|
||||
mPtr = wmalloc(sizeof(MyWidget));
|
||||
/* initialize it */
|
||||
memset(mPtr, 0, sizeof(MyWidget));
|
||||
/* allocate some storage for our new widget instance */
|
||||
mPtr = wmalloc(sizeof(MyWidget));
|
||||
/* initialize it */
|
||||
memset(mPtr, 0, sizeof(MyWidget));
|
||||
|
||||
/* set the class ID */
|
||||
mPtr->widgetClass = myWidgetClass;
|
||||
/* set the class ID */
|
||||
mPtr->widgetClass = myWidgetClass;
|
||||
|
||||
/*
|
||||
* Create the view for our widget.
|
||||
* Note: the Window for the view is only created after the view is
|
||||
* realized with W_RealizeView()
|
||||
*
|
||||
* Consider the returned view as read-only.
|
||||
*/
|
||||
mPtr->view = W_CreateView(W_VIEW(parent));
|
||||
if (!mPtr->view) {
|
||||
wfree(mPtr);
|
||||
return NULL;
|
||||
}
|
||||
/* always do this */
|
||||
mPtr->view->self = mPtr;
|
||||
/*
|
||||
* Create the view for our widget.
|
||||
* Note: the Window for the view is only created after the view is
|
||||
* realized with W_RealizeView()
|
||||
*
|
||||
* Consider the returned view as read-only.
|
||||
*/
|
||||
mPtr->view = W_CreateView(W_VIEW(parent));
|
||||
if (!mPtr->view) {
|
||||
wfree(mPtr);
|
||||
return NULL;
|
||||
}
|
||||
/* always do this */
|
||||
mPtr->view->self = mPtr;
|
||||
|
||||
/* setup the delegates for the view */
|
||||
mPtr->view->delegate = &_MyWidgetDelegate;
|
||||
/* setup the delegates for the view */
|
||||
mPtr->view->delegate = &_MyWidgetDelegate;
|
||||
|
||||
/*
|
||||
* Intercept some events for our widget, so that we can handle them.
|
||||
*/
|
||||
WMCreateEventHandler(mPtr->view, ExposureMask /* this allows us to know when we should paint */
|
||||
|StructureNotifyMask, /* this allows us to know things like when we are destroyed */
|
||||
handleEvents, mPtr);
|
||||
/*
|
||||
* Intercept some events for our widget, so that we can handle them.
|
||||
*/
|
||||
WMCreateEventHandler(mPtr->view, ExposureMask /* this allows us to know when we should paint */
|
||||
| StructureNotifyMask, /* this allows us to know things like when we are destroyed */
|
||||
handleEvents, mPtr);
|
||||
|
||||
/*
|
||||
* Intercept some other events. This could be merged with the above
|
||||
* call, but we separate for more organization.
|
||||
*/
|
||||
WMCreateEventHandler(mPtr->view, ButtonPressMask,handleActionEvents, mPtr);
|
||||
/*
|
||||
* Intercept some other events. This could be merged with the above
|
||||
* call, but we separate for more organization.
|
||||
*/
|
||||
WMCreateEventHandler(mPtr->view, ButtonPressMask, handleActionEvents, mPtr);
|
||||
|
||||
return mPtr;
|
||||
return mPtr;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Paint our widget contents.
|
||||
*/
|
||||
static void
|
||||
paintMyWidget(_MyWidget *mPtr)
|
||||
static void paintMyWidget(_MyWidget * mPtr)
|
||||
{
|
||||
W_Screen *scr = mPtr->view->screen;
|
||||
WMColor *color;
|
||||
W_Screen *scr = mPtr->view->screen;
|
||||
WMColor *color;
|
||||
|
||||
if (mPtr->text) {
|
||||
|
||||
if (mPtr->text) {
|
||||
color = WMWhiteColor(scr);
|
||||
|
||||
color = WMWhiteColor(scr);
|
||||
W_PaintText(mPtr->view, mPtr->view->window, scr->normalFont, 0, 0,
|
||||
mPtr->view->size.width, WACenter, color, False, mPtr->text, strlen(mPtr->text));
|
||||
|
||||
W_PaintText(mPtr->view, mPtr->view->window, scr->normalFont, 0, 0,
|
||||
mPtr->view->size.width, WACenter, color,
|
||||
False, mPtr->text, strlen(mPtr->text));
|
||||
|
||||
WMReleaseColor(color);
|
||||
}
|
||||
WMReleaseColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
handleEvents(XEvent *event, void *data)
|
||||
static void handleEvents(XEvent * event, void *data)
|
||||
{
|
||||
_MyWidget *mPtr = (_MyWidget*)data;
|
||||
_MyWidget *mPtr = (_MyWidget *) data;
|
||||
|
||||
switch (event->type) {
|
||||
case Expose:
|
||||
if (event->xexpose.count != 0)
|
||||
break;
|
||||
paintMyWidget(mPtr);
|
||||
break;
|
||||
|
||||
switch (event->type) {
|
||||
case Expose:
|
||||
if (event->xexpose.count!=0)
|
||||
break;
|
||||
paintMyWidget(mPtr);
|
||||
break;
|
||||
case DestroyNotify:
|
||||
destroyMyWidget(mPtr);
|
||||
break;
|
||||
|
||||
case DestroyNotify:
|
||||
destroyMyWidget(mPtr);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
handleActionEvents(XEvent *event, void *data)
|
||||
static void handleActionEvents(XEvent * event, void *data)
|
||||
{
|
||||
_MyWidget *mPtr = (_MyWidget*)data;
|
||||
_MyWidget *mPtr = (_MyWidget *) data;
|
||||
|
||||
switch (event->type) {
|
||||
case ButtonPress:
|
||||
XBell(mPtr->view->screen->display, 100);
|
||||
XBell(mPtr->view->screen->display, 100);
|
||||
break;
|
||||
}
|
||||
switch (event->type) {
|
||||
case ButtonPress:
|
||||
XBell(mPtr->view->screen->display, 100);
|
||||
XBell(mPtr->view->screen->display, 100);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
SetMyWidgetText(MyWidget *mPtr, char *text)
|
||||
void SetMyWidgetText(MyWidget * mPtr, char *text)
|
||||
{
|
||||
CHECK_CLASS(mPtr, myWidgetClass);
|
||||
CHECK_CLASS(mPtr, myWidgetClass);
|
||||
|
||||
if (mPtr->text)
|
||||
wfree(mPtr->text);
|
||||
if (mPtr->text)
|
||||
wfree(mPtr->text);
|
||||
|
||||
mPtr->text = wstrdup(text);
|
||||
mPtr->text = wstrdup(text);
|
||||
|
||||
if (W_VIEW_MAPPED(mPtr->view)) {
|
||||
paintMyWidget(mPtr);
|
||||
}
|
||||
if (W_VIEW_MAPPED(mPtr->view)) {
|
||||
paintMyWidget(mPtr);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static void
|
||||
destroyMyWidget(_MyWidget *mPtr)
|
||||
static void destroyMyWidget(_MyWidget * mPtr)
|
||||
{
|
||||
/*
|
||||
* Free all data we allocated for our widget.
|
||||
*/
|
||||
/*
|
||||
* Free all data we allocated for our widget.
|
||||
*/
|
||||
|
||||
if (mPtr->text)
|
||||
wfree(mPtr->text);
|
||||
if (mPtr->text)
|
||||
wfree(mPtr->text);
|
||||
|
||||
wfree(mPtr);
|
||||
wfree(mPtr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user