mirror of
https://github.com/gryf/wmaker.git
synced 2026-03-10 19:45:48 +01:00
- Added xdnd v3 support in WINGs (Sylvain Reynal <sreynal@nerim.net>)
- CVS should compile again
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "WINGsP.h"
|
||||
|
||||
#define XDND_COLOR_DATA_TYPE "application/X-color"
|
||||
|
||||
char *WMColorWellDidChangeNotification = "WMColorWellDidChangeNotification";
|
||||
|
||||
@@ -11,7 +12,7 @@ char *WMColorWellDidChangeNotification = "WMColorWellDidChangeNotification";
|
||||
typedef struct W_ColorWell {
|
||||
W_Class widgetClass;
|
||||
WMView *view;
|
||||
|
||||
|
||||
WMView *colorView;
|
||||
|
||||
WMColor *color;
|
||||
@@ -22,9 +23,11 @@ typedef struct W_ColorWell {
|
||||
WMPoint ipoint;
|
||||
|
||||
struct {
|
||||
unsigned int active:1;
|
||||
unsigned int bordered:1;
|
||||
unsigned int active:1;
|
||||
unsigned int bordered:1;
|
||||
} flags;
|
||||
|
||||
WMArray *xdndTypes;
|
||||
} ColorWell;
|
||||
|
||||
static char *_ColorWellActivatedNotification = "_ColorWellActivatedNotification";
|
||||
@@ -53,33 +56,36 @@ W_ViewDelegate _ColorWellViewDelegate = {
|
||||
};
|
||||
|
||||
|
||||
static unsigned draggingSourceOperation(WMView *self, Bool local);
|
||||
|
||||
static WMArray* dropDataTypes(WMView *self);
|
||||
static WMDragOperationType wantedDropOperation(WMView *self);
|
||||
static Bool acceptDropOperation(WMView *self, WMDragOperationType operation);
|
||||
static WMData* fetchDragData(WMView *self, char *type);
|
||||
|
||||
static WMDragSourceProcs _DragSourceProcs = {
|
||||
draggingSourceOperation,
|
||||
dropDataTypes,
|
||||
wantedDropOperation,
|
||||
NULL,
|
||||
acceptDropOperation,
|
||||
NULL,
|
||||
NULL,
|
||||
fetchDragData
|
||||
};
|
||||
|
||||
|
||||
static unsigned draggingEntered(WMView *self, WMDraggingInfo *info);
|
||||
static unsigned draggingUpdated(WMView *self, WMDraggingInfo *info);
|
||||
static void draggingExited(WMView *self, WMDraggingInfo *info);
|
||||
static char *prepareForDragOperation(WMView *self, WMDraggingInfo *info);
|
||||
static Bool performDragOperation(WMView *self, WMDraggingInfo *info,
|
||||
WMData *data);
|
||||
static void concludeDragOperation(WMView *self, WMDraggingInfo *info);
|
||||
static WMArray* requiredDataTypes(WMView *self,
|
||||
WMDragOperationType requestedOperation, WMArray *sourceDataTypes);
|
||||
static WMDragOperationType allowedOperation(WMView *self,
|
||||
WMDragOperationType requestedOperation, WMArray *sourceDataTypes);
|
||||
static void performDragOperation(WMView *self, WMArray *dropDatas,
|
||||
WMArray *operationsList, WMPoint* dropLocation);
|
||||
|
||||
static WMDragDestinationProcs _DragDestinationProcs = {
|
||||
draggingEntered,
|
||||
draggingUpdated,
|
||||
draggingExited,
|
||||
prepareForDragOperation,
|
||||
performDragOperation,
|
||||
concludeDragOperation
|
||||
NULL,
|
||||
requiredDataTypes,
|
||||
allowedOperation,
|
||||
NULL,
|
||||
performDragOperation ,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
@@ -100,10 +106,10 @@ colorChangedObserver(void *data, WMNotification *notification)
|
||||
WMColor *color;
|
||||
|
||||
if (!cPtr->flags.active)
|
||||
return;
|
||||
return;
|
||||
|
||||
color = WMGetColorPanelColor(panel);
|
||||
|
||||
|
||||
WMSetColorWellColor(cPtr, color);
|
||||
WMPostNotificationName(WMColorWellDidChangeNotification, cPtr, NULL);
|
||||
}
|
||||
@@ -126,21 +132,30 @@ updateColorCallback(void *self, void *data)
|
||||
static void
|
||||
activatedObserver(void *data, WMNotification *notification)
|
||||
{
|
||||
/*
|
||||
WMColorWell *cPtr = (WMColorWell*)data;
|
||||
/*
|
||||
WMColorWell *cPtr = (WMColorWell*)data;
|
||||
|
||||
if (!cPtr->flags.active || WMGetNotificationObject(notification) == cPtr)
|
||||
return;
|
||||
if (!cPtr->flags.active || WMGetNotificationObject(notification) == cPtr)
|
||||
return;
|
||||
|
||||
W_SetViewBackgroundColor(cPtr->view, WMWidgetScreen(cPtr)->gray);
|
||||
paintColorWell(cPtr);
|
||||
W_SetViewBackgroundColor(cPtr->view, WMWidgetScreen(cPtr)->gray);
|
||||
paintColorWell(cPtr);
|
||||
|
||||
cPtr->flags.active = 0;
|
||||
*/
|
||||
cPtr->flags.active = 0;
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
|
||||
static WMArray*
|
||||
getXdndTypeArray()
|
||||
{
|
||||
WMArray *types = WMCreateArray(1);
|
||||
WMAddToArray(types, XDND_COLOR_DATA_TYPE);
|
||||
return types;
|
||||
}
|
||||
|
||||
|
||||
WMColorWell*
|
||||
WMCreateColorWell(WMWidget *parent)
|
||||
{
|
||||
@@ -150,11 +165,11 @@ WMCreateColorWell(WMWidget *parent)
|
||||
memset(cPtr, 0, sizeof(ColorWell));
|
||||
|
||||
cPtr->widgetClass = WC_ColorWell;
|
||||
|
||||
|
||||
cPtr->view = W_CreateView(W_VIEW(parent));
|
||||
if (!cPtr->view) {
|
||||
wfree(cPtr);
|
||||
return NULL;
|
||||
wfree(cPtr);
|
||||
return NULL;
|
||||
}
|
||||
cPtr->view->self = cPtr;
|
||||
|
||||
@@ -162,22 +177,21 @@ WMCreateColorWell(WMWidget *parent)
|
||||
|
||||
cPtr->colorView = W_CreateView(cPtr->view);
|
||||
if (!cPtr->colorView) {
|
||||
W_DestroyView(cPtr->view);
|
||||
wfree(cPtr);
|
||||
return NULL;
|
||||
W_DestroyView(cPtr->view);
|
||||
wfree(cPtr);
|
||||
return NULL;
|
||||
}
|
||||
cPtr->colorView->self = cPtr;
|
||||
|
||||
WMCreateEventHandler(cPtr->view, ExposureMask|StructureNotifyMask
|
||||
|ClientMessageMask, handleEvents, cPtr);
|
||||
|ClientMessageMask, handleEvents, cPtr);
|
||||
|
||||
WMCreateEventHandler(cPtr->colorView, ExposureMask, handleEvents, cPtr);
|
||||
|
||||
WMCreateEventHandler(cPtr->colorView, ButtonPressMask|ButtonMotionMask
|
||||
|EnterWindowMask, handleDragEvents, cPtr);
|
||||
WMCreateDragHandler(cPtr->colorView, handleDragEvents, cPtr);
|
||||
|
||||
WMCreateEventHandler(cPtr->view, ButtonPressMask, handleActionEvents,
|
||||
cPtr);
|
||||
WMCreateEventHandler(cPtr->view, ButtonPressMask, handleActionEvents,
|
||||
cPtr);
|
||||
|
||||
cPtr->colorView->flags.mapWhenRealized = 1;
|
||||
|
||||
@@ -185,22 +199,19 @@ WMCreateColorWell(WMWidget *parent)
|
||||
|
||||
W_ResizeView(cPtr->view, DEFAULT_WIDTH, DEFAULT_HEIGHT);
|
||||
|
||||
WMAddNotificationObserver(activatedObserver, cPtr,
|
||||
_ColorWellActivatedNotification, NULL);
|
||||
WMAddNotificationObserver(activatedObserver, cPtr,
|
||||
_ColorWellActivatedNotification, NULL);
|
||||
|
||||
cPtr->color = WMBlackColor(WMWidgetScreen(cPtr));
|
||||
|
||||
WMAddNotificationObserver(colorChangedObserver, cPtr,
|
||||
WMColorPanelColorChangedNotification, NULL);
|
||||
WMColorPanelColorChangedNotification, NULL);
|
||||
|
||||
WMSetViewDragSourceProcs(cPtr->colorView, &_DragSourceProcs);
|
||||
WMSetViewDragDestinationProcs(cPtr->colorView, &_DragDestinationProcs);
|
||||
|
||||
{
|
||||
char *types[2] = {"application/X-color", NULL};
|
||||
|
||||
WMRegisterViewForDraggedTypes(cPtr->colorView, types);
|
||||
}
|
||||
cPtr->xdndTypes = getXdndTypeArray();
|
||||
WMRegisterViewForDraggedTypes(cPtr->colorView, cPtr->xdndTypes);
|
||||
|
||||
return cPtr;
|
||||
}
|
||||
@@ -210,12 +221,12 @@ void
|
||||
WMSetColorWellColor(WMColorWell *cPtr, WMColor *color)
|
||||
{
|
||||
if (cPtr->color)
|
||||
WMReleaseColor(cPtr->color);
|
||||
|
||||
WMReleaseColor(cPtr->color);
|
||||
|
||||
cPtr->color = WMRetainColor(color);
|
||||
|
||||
|
||||
if (cPtr->colorView->flags.realized && cPtr->colorView->flags.mapped)
|
||||
paintColorWell(cPtr);
|
||||
paintColorWell(cPtr);
|
||||
}
|
||||
|
||||
|
||||
@@ -231,36 +242,36 @@ WSetColorWellBordered(WMColorWell *cPtr, Bool flag)
|
||||
{
|
||||
flag = ((flag==0) ? 0 : 1);
|
||||
if (cPtr->flags.bordered != flag) {
|
||||
cPtr->flags.bordered = flag;
|
||||
W_ResizeView(cPtr->view, cPtr->view->size.width, cPtr->view->size.height);
|
||||
cPtr->flags.bordered = flag;
|
||||
W_ResizeView(cPtr->view, cPtr->view->size.width, cPtr->view->size.height);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
willResizeColorWell(W_ViewDelegate *self, WMView *view,
|
||||
unsigned int *width, unsigned int *height)
|
||||
unsigned int *width, unsigned int *height)
|
||||
{
|
||||
WMColorWell *cPtr = (WMColorWell*)view->self;
|
||||
int bw;
|
||||
|
||||
|
||||
if (cPtr->flags.bordered) {
|
||||
|
||||
if (*width < MIN_WIDTH)
|
||||
*width = MIN_WIDTH;
|
||||
if (*height < MIN_HEIGHT)
|
||||
*height = MIN_HEIGHT;
|
||||
if (*width < MIN_WIDTH)
|
||||
*width = MIN_WIDTH;
|
||||
if (*height < MIN_HEIGHT)
|
||||
*height = MIN_HEIGHT;
|
||||
|
||||
bw = (int)((float)WMIN(*width, *height)*0.24);
|
||||
bw = (int)((float)WMIN(*width, *height)*0.24);
|
||||
|
||||
W_ResizeView(cPtr->colorView, *width-2*bw, *height-2*bw);
|
||||
W_ResizeView(cPtr->colorView, *width-2*bw, *height-2*bw);
|
||||
|
||||
if (cPtr->colorView->pos.x!=bw || cPtr->colorView->pos.y!=bw)
|
||||
W_MoveView(cPtr->colorView, bw, bw);
|
||||
} else {
|
||||
W_ResizeView(cPtr->colorView, *width, *height);
|
||||
if (cPtr->colorView->pos.x!=bw || cPtr->colorView->pos.y!=bw)
|
||||
W_MoveView(cPtr->colorView, bw, bw);
|
||||
} else {
|
||||
W_ResizeView(cPtr->colorView, *width, *height);
|
||||
|
||||
W_MoveView(cPtr->colorView, 0, 0);
|
||||
W_MoveView(cPtr->colorView, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -271,16 +282,16 @@ paintColorWell(ColorWell *cPtr)
|
||||
W_Screen *scr = cPtr->view->screen;
|
||||
|
||||
W_DrawRelief(scr, cPtr->view->window, 0, 0, cPtr->view->size.width,
|
||||
cPtr->view->size.height, WRRaised);
|
||||
|
||||
W_DrawRelief(scr, cPtr->colorView->window, 0, 0,
|
||||
cPtr->colorView->size.width, cPtr->colorView->size.height,
|
||||
WRSunken);
|
||||
cPtr->view->size.height, WRRaised);
|
||||
|
||||
W_DrawRelief(scr, cPtr->colorView->window, 0, 0,
|
||||
cPtr->colorView->size.width, cPtr->colorView->size.height,
|
||||
WRSunken);
|
||||
|
||||
if (cPtr->color)
|
||||
WMPaintColorSwatch(cPtr->color, cPtr->colorView->window,
|
||||
2, 2, cPtr->colorView->size.width-4,
|
||||
cPtr->colorView->size.height-4);
|
||||
WMPaintColorSwatch(cPtr->color, cPtr->colorView->window,
|
||||
2, 2, cPtr->colorView->size.width-4,
|
||||
cPtr->colorView->size.height-4);
|
||||
}
|
||||
|
||||
|
||||
@@ -293,38 +304,51 @@ handleEvents(XEvent *event, void *data)
|
||||
CHECK_CLASS(data, WC_ColorWell);
|
||||
|
||||
|
||||
switch (event->type) {
|
||||
case Expose:
|
||||
if (event->xexpose.count!=0)
|
||||
break;
|
||||
paintColorWell(cPtr);
|
||||
break;
|
||||
|
||||
case DestroyNotify:
|
||||
destroyColorWell(cPtr);
|
||||
break;
|
||||
|
||||
switch (event->type) {
|
||||
case Expose:
|
||||
if (event->xexpose.count!=0)
|
||||
break;
|
||||
paintColorWell(cPtr);
|
||||
break;
|
||||
|
||||
case DestroyNotify:
|
||||
destroyColorWell(cPtr);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static unsigned
|
||||
draggingSourceOperation(WMView *self, Bool local)
|
||||
static WMArray*
|
||||
dropDataTypes(WMView *self)
|
||||
{
|
||||
return ((ColorWell*)self->self)->xdndTypes;
|
||||
}
|
||||
|
||||
|
||||
static WMDragOperationType
|
||||
wantedDropOperation(WMView *self)
|
||||
{
|
||||
return WDOperationCopy;
|
||||
}
|
||||
|
||||
|
||||
static WMData*
|
||||
static Bool
|
||||
acceptDropOperation(WMView *self, WMDragOperationType operation)
|
||||
{
|
||||
return (operation == WDOperationCopy);
|
||||
}
|
||||
|
||||
|
||||
static WMData*
|
||||
fetchDragData(WMView *self, char *type)
|
||||
{
|
||||
char *color = WMGetColorRGBDescription(((WMColorWell*)self->self)->color);
|
||||
WMData *data;
|
||||
|
||||
|
||||
data = WMCreateDataWithBytes(color, strlen(color)+1);
|
||||
|
||||
wfree(color);
|
||||
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@@ -334,13 +358,13 @@ makeDragPixmap(WMColorWell *cPtr)
|
||||
{
|
||||
WMScreen *scr = cPtr->view->screen;
|
||||
Pixmap pix;
|
||||
|
||||
|
||||
pix = XCreatePixmap(scr->display, W_DRAWABLE(scr), 16, 16, scr->depth);
|
||||
|
||||
|
||||
XFillRectangle(scr->display, pix, WMColorGC(cPtr->color), 0, 0, 15, 15);
|
||||
|
||||
|
||||
XDrawRectangle(scr->display, pix, WMColorGC(scr->black), 0, 0, 15, 15);
|
||||
|
||||
|
||||
return WMCreatePixmapFromXPixmaps(scr, pix, None, 16, 16, scr->depth);
|
||||
}
|
||||
|
||||
@@ -350,36 +374,12 @@ handleDragEvents(XEvent *event, void *data)
|
||||
{
|
||||
WMColorWell *cPtr = (ColorWell*)data;
|
||||
|
||||
switch (event->type) {
|
||||
case ButtonPress:
|
||||
if (event->xbutton.button == Button1) {
|
||||
cPtr->ipoint.x = event->xbutton.x;
|
||||
cPtr->ipoint.y = event->xbutton.y;
|
||||
}
|
||||
break;
|
||||
|
||||
case MotionNotify:
|
||||
if (event->xmotion.state & Button1Mask) {
|
||||
if (abs(cPtr->ipoint.x - event->xmotion.x) > 4
|
||||
|| abs(cPtr->ipoint.y - event->xmotion.y) > 4) {
|
||||
WMSize offs;
|
||||
WMPixmap *pixmap;
|
||||
char *types[2] = {"application/X-color", NULL};
|
||||
|
||||
offs.width = 2;
|
||||
offs.height = 2;
|
||||
pixmap = makeDragPixmap(cPtr);
|
||||
|
||||
WMDragImageFromView(cPtr->colorView, pixmap, types,
|
||||
wmkpoint(event->xmotion.x_root,
|
||||
event->xmotion.y_root),
|
||||
offs, event, True);
|
||||
|
||||
WMReleasePixmap(pixmap);
|
||||
}
|
||||
}
|
||||
break;
|
||||
if (event->type == ButtonPress && event->xbutton.button == Button1) {
|
||||
/* initialise drag icon */
|
||||
WMSetViewDragImage(cPtr->colorView, makeDragPixmap(cPtr));
|
||||
}
|
||||
|
||||
WMDragImageFromView(cPtr->colorView, event);
|
||||
}
|
||||
|
||||
|
||||
@@ -389,24 +389,24 @@ handleActionEvents(XEvent *event, void *data)
|
||||
WMColorWell *cPtr = (ColorWell*)data;
|
||||
WMScreen *scr = WMWidgetScreen(cPtr);
|
||||
WMColorPanel *cpanel;
|
||||
|
||||
|
||||
if (cPtr->flags.active)
|
||||
W_SetViewBackgroundColor(cPtr->view, scr->gray);
|
||||
W_SetViewBackgroundColor(cPtr->view, scr->gray);
|
||||
else
|
||||
W_SetViewBackgroundColor(cPtr->view, scr->white);
|
||||
W_SetViewBackgroundColor(cPtr->view, scr->white);
|
||||
paintColorWell(cPtr);
|
||||
|
||||
cPtr->flags.active ^= 1;
|
||||
|
||||
if (cPtr->flags.active) {
|
||||
WMPostNotificationName(_ColorWellActivatedNotification, cPtr, NULL);
|
||||
WMPostNotificationName(_ColorWellActivatedNotification, cPtr, NULL);
|
||||
}
|
||||
cpanel = WMGetColorPanel(scr);
|
||||
|
||||
WMSetColorPanelAction(cpanel, updateColorCallback, cPtr);
|
||||
|
||||
if (cPtr->color)
|
||||
WMSetColorPanelColor(cpanel, cPtr->color);
|
||||
WMSetColorPanelColor(cpanel, cPtr->color);
|
||||
WMShowColorPanel(cpanel);
|
||||
}
|
||||
|
||||
@@ -417,58 +417,69 @@ destroyColorWell(ColorWell *cPtr)
|
||||
WMRemoveNotificationObserver(cPtr);
|
||||
|
||||
if (cPtr->color)
|
||||
WMReleaseColor(cPtr->color);
|
||||
WMReleaseColor(cPtr->color);
|
||||
|
||||
WMFreeArray(cPtr->xdndTypes);
|
||||
|
||||
wfree(cPtr);
|
||||
}
|
||||
|
||||
|
||||
|
||||
static unsigned
|
||||
draggingEntered(WMView *self, WMDraggingInfo *info)
|
||||
{
|
||||
return WDOperationCopy;
|
||||
}
|
||||
|
||||
|
||||
static unsigned
|
||||
draggingUpdated(WMView *self, WMDraggingInfo *info)
|
||||
{
|
||||
return WDOperationCopy;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
draggingExited(WMView *self, WMDraggingInfo *info)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
|
||||
static char*
|
||||
prepareForDragOperation(WMView *self, WMDraggingInfo *info)
|
||||
{
|
||||
return "application/X-color";
|
||||
}
|
||||
|
||||
|
||||
static Bool
|
||||
performDragOperation(WMView *self, WMDraggingInfo *info, WMData *data)
|
||||
dropIsOk(WMDragOperationType request, WMArray *sourceDataTypes)
|
||||
{
|
||||
char *colorName = (char*)WMDataBytes(data);
|
||||
WMColor *color;
|
||||
|
||||
color = WMCreateNamedColor(W_VIEW_SCREEN(self), colorName, True);
|
||||
|
||||
WMSetColorWellColor(self->self, color);
|
||||
|
||||
WMReleaseColor(color);
|
||||
|
||||
return True;
|
||||
WMArrayIterator iter;
|
||||
char *type;
|
||||
|
||||
if (request == WDOperationCopy) {
|
||||
WM_ITERATE_ARRAY(sourceDataTypes, type, iter) {
|
||||
if (type != NULL && strcmp(type, XDND_COLOR_DATA_TYPE)==0) {
|
||||
return True;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return False;
|
||||
}
|
||||
|
||||
|
||||
static WMArray*
|
||||
requiredDataTypes(WMView *self, WMDragOperationType request, WMArray *sourceDataTypes)
|
||||
{
|
||||
if (dropIsOk(request, sourceDataTypes))
|
||||
return ((ColorWell*)self->self)->xdndTypes;
|
||||
else
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
static WMDragOperationType
|
||||
allowedOperation(WMView *self, WMDragOperationType request, WMArray *sourceDataTypes)
|
||||
{
|
||||
if (dropIsOk(request, sourceDataTypes))
|
||||
return WDOperationCopy;
|
||||
else
|
||||
return WDOperationNone;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
concludeDragOperation(WMView *self, WMDraggingInfo *info)
|
||||
performDragOperation(WMView *self, WMArray *dropData, WMArray *operations,
|
||||
WMPoint* dropLocation)
|
||||
{
|
||||
char *colorName;
|
||||
WMColor *color;
|
||||
WMData* data;
|
||||
|
||||
/* only one operation requested (WDOperationCopy) implies only one data */
|
||||
data = (WMData*)WMGetFromArray(dropData, 0);
|
||||
|
||||
if (data != NULL) {
|
||||
colorName = (char*)WMDataBytes(data);
|
||||
color = WMCreateNamedColor(W_VIEW_SCREEN(self), colorName, True);
|
||||
WMSetColorWellColor(self->self, color);
|
||||
WMReleaseColor(color);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user