mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 12:28:22 +01:00
Added new wruler.{c,h} files from nwanua
This commit is contained in:
822
WINGs/wruler.c
822
WINGs/wruler.c
@@ -1,145 +1,62 @@
|
||||
|
||||
/* WMRuler: nifty ruler widget for WINGs (OK, for WMText ;-) */
|
||||
/* Copyleft (>) 1999, 2000 Nwanua Elumeze <nwanua@colorado.edu> */
|
||||
|
||||
|
||||
#include <WINGsP.h>
|
||||
#include <WUtil.h>
|
||||
#include <WMaker.h>
|
||||
|
||||
#include "wruler.h"
|
||||
|
||||
#define DEFAULT_X_OFFSET 22
|
||||
#define MIN_DOC_WIDTH 200
|
||||
#define DEFAULT_RULER_WIDTH 240
|
||||
#define DEFAULT_RULER_HEIGHT 40
|
||||
|
||||
|
||||
/* a pixel is defined here as 1/8 of an "inch" */
|
||||
/* an "inch" is not the British unit inch... just so you know :-P */
|
||||
#define MIN_DOC_WIDTH 10
|
||||
|
||||
typedef struct W_Ruler {
|
||||
W_Class widgetClass;
|
||||
W_View *view;
|
||||
|
||||
W_View *pview;
|
||||
W_View *view;
|
||||
W_View *pview; /* the parent's view (for drawing the line) */
|
||||
|
||||
void *clientData;
|
||||
WMAction *action, *moveaction;
|
||||
|
||||
struct {
|
||||
int left, body, first, right, dleft;
|
||||
} margins;
|
||||
int which_marker;
|
||||
|
||||
int end;
|
||||
int pressed;
|
||||
int offset;
|
||||
|
||||
struct {
|
||||
unsigned int showtabs:1;
|
||||
unsigned int buttonPressed:1;
|
||||
} flags;
|
||||
WMAction *moveAction; /* what to when while moving */
|
||||
WMAction *releaseAction; /* what to do when released */
|
||||
void *clientData;
|
||||
|
||||
} Ruler;
|
||||
|
||||
|
||||
static void
|
||||
resizeRuler(W_ViewDelegate *self, WMView *view)
|
||||
{
|
||||
Ruler *rPtr = (Ruler *)view->self;
|
||||
|
||||
CHECK_CLASS(rPtr, WC_Ruler);
|
||||
|
||||
W_ResizeView(rPtr->view, view->size.width,
|
||||
DEFAULT_RULER_HEIGHT); /* more like DEFACTO_RULER_HEIGHT ;-) */
|
||||
|
||||
rPtr->end = view->size.width;
|
||||
rPtr->margins.right = view->size.width;
|
||||
}
|
||||
|
||||
|
||||
W_ViewDelegate _RulerViewDelegate =
|
||||
{
|
||||
NULL,
|
||||
NULL,
|
||||
resizeRuler,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
static void
|
||||
paintRuler(Ruler *rPtr)
|
||||
{
|
||||
GC gc;
|
||||
XPoint points[6];
|
||||
GC fg, bg;
|
||||
WMFont *font;
|
||||
int i, j, xpos;
|
||||
char c[3];
|
||||
int actual_x;
|
||||
|
||||
CHECK_CLASS(rPtr, WC_Ruler);
|
||||
WMRulerMargins margins;
|
||||
int offset;
|
||||
int motion; /* the position of the _moving_ marker(s) */
|
||||
int end; /* the last tick on the baseline (restrict markers to it) */
|
||||
|
||||
if(!rPtr->view->flags.mapped)
|
||||
return;
|
||||
Pixmap drawBuffer;
|
||||
|
||||
gc = WMColorGC(WMBlackColor(rPtr->view->screen));
|
||||
font = WMSystemFontOfSize(rPtr->view->screen, 8);
|
||||
|
||||
|
||||
WMDrawString(rPtr->view->screen, rPtr->view->window, gc,
|
||||
font, rPtr->margins.dleft+2, 25, "0 inches", 10);
|
||||
|
||||
/* marker ticks */
|
||||
j=0;
|
||||
for(i=80; i<rPtr->view->size.width; i+=80) {
|
||||
if(j<10)
|
||||
snprintf(c,3,"%d",++j);
|
||||
else
|
||||
snprintf(c,3,"%2d",++j);
|
||||
WMDrawString(rPtr->view->screen, rPtr->view->window, gc,
|
||||
font, rPtr->margins.dleft+2+i, 25, c, 2);
|
||||
}
|
||||
|
||||
if(rPtr->flags.showtabs){
|
||||
points[0].y = 9;
|
||||
points[1].y = 15;
|
||||
points[2].y = 20;
|
||||
}
|
||||
|
||||
for(i=0; i<rPtr->view->size.width; i+=40) {
|
||||
XDrawLine(rPtr->view->screen->display, rPtr->view->window,
|
||||
gc, rPtr->margins.dleft+i, 21, rPtr->margins.dleft+i, 31);
|
||||
struct {
|
||||
unsigned int buttonPressed:1;
|
||||
/* 0, 1, 2, 3, 4, 5, 6 */
|
||||
unsigned int whichMarker:3; /* none, left, right, first, body, tabstop, both */
|
||||
unsigned int RESERVED:28;
|
||||
} flags;
|
||||
} Ruler;
|
||||
|
||||
if(rPtr->flags.showtabs){
|
||||
points[0].x = rPtr->margins.dleft+i+40;
|
||||
points[1].x = points[0].x+6;
|
||||
points[2].x = points[0].x;
|
||||
XFillPolygon (rPtr->view->screen->display, rPtr->view->window,
|
||||
WMColorGC(WMDarkGrayColor(rPtr->view->screen)),
|
||||
points, 3, Convex, CoordModeOrigin);
|
||||
|
||||
XDrawLine(rPtr->view->screen->display, rPtr->view->window,
|
||||
WMColorGC(WMDarkGrayColor(rPtr->view->screen)),
|
||||
rPtr->margins.dleft+i, 18, rPtr->margins.dleft+i, 21);
|
||||
}
|
||||
}
|
||||
|
||||
for(i=0; i<rPtr->view->size.width; i+=20)
|
||||
XDrawLine(rPtr->view->screen->display, rPtr->view->window,
|
||||
gc, rPtr->margins.dleft+i, 21, rPtr->margins.dleft+i, 27);
|
||||
|
||||
for(i=0; i<rPtr->view->size.width-20; i+=10)
|
||||
XDrawLine(rPtr->view->screen->display, rPtr->view->window,
|
||||
gc, rPtr->margins.dleft+i, 21, rPtr->margins.dleft+i, 24);
|
||||
|
||||
/* guide the end marker in future drawings till next resize */
|
||||
rPtr->end = i+12;
|
||||
|
||||
/* base line */
|
||||
XDrawLine(rPtr->view->screen->display, rPtr->view->window,
|
||||
gc, rPtr->margins.dleft, 21, rPtr->margins.left+i-10, 21);
|
||||
/* Marker for left margin
|
||||
|
||||
|\
|
||||
| \
|
||||
|__\
|
||||
|
|
||||
| */
|
||||
static void
|
||||
drawLeftMarker(Ruler *rPtr)
|
||||
{
|
||||
XPoint points[4];
|
||||
int xpos = (rPtr->flags.whichMarker==1?
|
||||
rPtr->motion:rPtr->margins.left);
|
||||
|
||||
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer,
|
||||
rPtr->fg, xpos, 8, xpos, 22);
|
||||
points[0].x = xpos;
|
||||
points[0].y = 1;
|
||||
points[1].x = points[0].x+6;
|
||||
points[1].y = 8;
|
||||
points[2].x = points[0].x+6;
|
||||
points[2].y = 9;
|
||||
points[3].x = points[0].x;
|
||||
points[3].y = 9;
|
||||
XFillPolygon (rPtr->view->screen->display, rPtr->drawBuffer,
|
||||
rPtr->fg, points, 4, Convex, CoordModeOrigin);
|
||||
}
|
||||
|
||||
/* Marker for right margin
|
||||
|
||||
@@ -149,331 +66,321 @@ paintRuler(Ruler *rPtr)
|
||||
|
|
||||
| */
|
||||
|
||||
xpos = rPtr->margins.right;
|
||||
XDrawLine(rPtr->view->screen->display, rPtr->view->window,
|
||||
WMColorGC(WMDarkGrayColor(rPtr->view->screen)), xpos, 10, xpos, 20);
|
||||
static void
|
||||
drawRightMarker(Ruler *rPtr)
|
||||
{
|
||||
XPoint points[4];
|
||||
int xpos = (rPtr->flags.whichMarker==2?
|
||||
rPtr->motion:rPtr->margins.right);
|
||||
|
||||
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer,
|
||||
rPtr->fg, xpos, 8, xpos, 22);
|
||||
points[0].x = xpos+1;
|
||||
points[0].y = 2;
|
||||
points[0].y = 0;
|
||||
points[1].x = points[0].x-6;
|
||||
points[1].y = 9;
|
||||
points[1].y = 7;
|
||||
points[2].x = points[0].x-6;
|
||||
points[2].y = 11;
|
||||
points[2].y = 9;
|
||||
points[3].x = points[0].x;
|
||||
points[3].y = 11;
|
||||
XFillPolygon (rPtr->view->screen->display, rPtr->view->window,
|
||||
gc, points, 4, Convex, CoordModeOrigin);
|
||||
|
||||
points[3].y = 9;
|
||||
XFillPolygon (rPtr->view->screen->display, rPtr->drawBuffer,
|
||||
rPtr->fg, points, 4, Convex, CoordModeOrigin);
|
||||
}
|
||||
|
||||
/* Marker for left margin
|
||||
|
||||
|\
|
||||
| \
|
||||
|__\
|
||||
|
|
||||
| */
|
||||
|
||||
xpos = rPtr->margins.left;
|
||||
XDrawLine(rPtr->view->screen->display, rPtr->view->window,
|
||||
WMColorGC(WMDarkGrayColor(rPtr->view->screen)), xpos, 10, xpos, 20);
|
||||
|
||||
points[0].x = xpos;
|
||||
points[0].y = 3;
|
||||
points[1].x = points[0].x+6;
|
||||
points[1].y = 10;
|
||||
points[2].x = points[0].x+6;
|
||||
points[2].y = 11;
|
||||
points[3].x = points[0].x;
|
||||
points[3].y = 11;
|
||||
XFillPolygon (rPtr->view->screen->display, rPtr->view->window,
|
||||
gc, points, 4, Convex, CoordModeOrigin);
|
||||
|
||||
/*
|
||||
points[3].x =
|
||||
|
||||
/* Marker for first line only
|
||||
_____
|
||||
|___|
|
||||
|
|
||||
|
||||
*/
|
||||
|
||||
xpos = rPtr->margins.first + rPtr->margins.dleft;
|
||||
XFillRectangle(rPtr->view->screen->display, rPtr->view->window,
|
||||
gc, xpos-5, 7, 11, 5);
|
||||
|
||||
XDrawLine(rPtr->view->screen->display, rPtr->view->window,
|
||||
gc, xpos, 10, xpos, 20);
|
||||
|
||||
| */
|
||||
static void
|
||||
drawFirstMarker(Ruler *rPtr)
|
||||
{
|
||||
int xpos = ((rPtr->flags.whichMarker==3 || rPtr->flags.whichMarker==6)?
|
||||
rPtr->motion:rPtr->margins.first);
|
||||
XFillRectangle(rPtr->view->screen->display, rPtr->drawBuffer,
|
||||
rPtr->fg, xpos-5, 10, 11, 5);
|
||||
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer,
|
||||
rPtr->fg, xpos, 12, xpos, 22);
|
||||
}
|
||||
|
||||
/* Marker for rest of body
|
||||
_____
|
||||
\ /
|
||||
\./ */
|
||||
|
||||
|
||||
xpos = rPtr->margins.body + rPtr->margins.dleft;
|
||||
static void
|
||||
drawBodyMarker(Ruler *rPtr)
|
||||
{
|
||||
XPoint points[4];
|
||||
int xpos = ((rPtr->flags.whichMarker==4 || rPtr->flags.whichMarker==6)?
|
||||
rPtr->motion:rPtr->margins.body);
|
||||
points[0].x = xpos-5;
|
||||
points[0].y = 14;
|
||||
points[0].y = 16;
|
||||
points[1].x = points[0].x+11;
|
||||
points[1].y = 14;
|
||||
points[1].y = 16;
|
||||
points[2].x = points[0].x+5;
|
||||
points[2].y = 20;
|
||||
XFillPolygon (rPtr->view->screen->display, rPtr->view->window,
|
||||
gc, points, 3, Convex, CoordModeOrigin);
|
||||
points[2].y = 22;
|
||||
XFillPolygon (rPtr->view->screen->display, rPtr->drawBuffer,
|
||||
rPtr->fg, points, 3, Convex, CoordModeOrigin);
|
||||
}
|
||||
|
||||
static void
|
||||
createDrawBuffer(Ruler *rPtr)
|
||||
{
|
||||
if(rPtr->drawBuffer)
|
||||
XFreePixmap(rPtr->view->screen->display, rPtr->drawBuffer);
|
||||
rPtr->drawBuffer = XCreatePixmap(rPtr->view->screen->display,
|
||||
rPtr->view->window, rPtr->view->size.width, 40,
|
||||
rPtr->view->screen->depth);
|
||||
XFillRectangle(rPtr->view->screen->display, rPtr->drawBuffer,
|
||||
rPtr->bg, 0, 0, rPtr->view->size.width, 40);
|
||||
}
|
||||
|
||||
static void
|
||||
drawRulerOnPixmap(Ruler *rPtr)
|
||||
{
|
||||
int i, j, w, m;
|
||||
char c[3];
|
||||
int marks[9] = {11, 3, 5, 3, 7, 3, 5, 3};
|
||||
|
||||
if(!rPtr->drawBuffer)
|
||||
createDrawBuffer(rPtr);
|
||||
|
||||
XFillRectangle(rPtr->view->screen->display, rPtr->drawBuffer,
|
||||
rPtr->bg, 0, 0, rPtr->view->size.width, 40);
|
||||
|
||||
|
||||
if(!rPtr->flags.buttonPressed)
|
||||
return;
|
||||
WMDrawString(rPtr->view->screen, rPtr->drawBuffer,
|
||||
rPtr->fg, rPtr->font, rPtr->margins.left+2, 26, "0 inches", 10);
|
||||
|
||||
/* actual_x is used as a shortcut is all... */
|
||||
switch(rPtr->which_marker){
|
||||
case WRulerLeft: actual_x = rPtr->margins.left; break;
|
||||
case WRulerBody:
|
||||
actual_x = rPtr->margins.body + rPtr->margins.dleft;
|
||||
break;
|
||||
case WRulerFirst:
|
||||
actual_x = rPtr->margins.first + rPtr->margins.dleft;
|
||||
break;
|
||||
case WRulerRight: actual_x = rPtr->margins.right; break;
|
||||
default: return;
|
||||
/* marker ticks */
|
||||
i=j=m=0;
|
||||
w = rPtr->view->size.width - rPtr->margins.left;
|
||||
while(m < w) {
|
||||
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer,
|
||||
rPtr->fg, rPtr->margins.left+m, 23,
|
||||
rPtr->margins.left+m, marks[i%8]+23);
|
||||
if(i!=0 && i%8==0) {
|
||||
if(j<10)
|
||||
snprintf(c,3,"%d",++j);
|
||||
else
|
||||
snprintf(c,3,"%2d",++j);
|
||||
WMDrawString(rPtr->view->screen, rPtr->drawBuffer,
|
||||
rPtr->fg, rPtr->font, rPtr->margins.left+2+m, 26, c, 2);
|
||||
}
|
||||
m = (++i)*10;
|
||||
}
|
||||
|
||||
rPtr->end = rPtr->margins.left+m-10;
|
||||
if(rPtr->margins.right > rPtr->end)
|
||||
rPtr->margins.right = rPtr->end;
|
||||
/* base line */
|
||||
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer,
|
||||
rPtr->fg, rPtr->margins.left, 22, rPtr->margins.left+m-10, 22);
|
||||
|
||||
drawLeftMarker(rPtr);
|
||||
drawRightMarker(rPtr);
|
||||
drawFirstMarker(rPtr);
|
||||
drawBodyMarker(rPtr);
|
||||
}
|
||||
|
||||
static void
|
||||
paintRuler(Ruler *rPtr)
|
||||
{
|
||||
WMScreen *screen = rPtr->view->screen;
|
||||
if(1||!rPtr->drawBuffer) { //first exposure
|
||||
drawRulerOnPixmap(rPtr);
|
||||
}
|
||||
|
||||
|
||||
gc = WMColorGC(WMDarkGrayColor(rPtr->view->screen)),
|
||||
|
||||
XSetLineAttributes(rPtr->view->screen->display, gc, 1,
|
||||
LineOnOffDash, CapNotLast, JoinMiter);
|
||||
|
||||
XDrawLine(rPtr->pview->screen->display, rPtr->pview->window,
|
||||
gc, actual_x+1, 45, actual_x+1, rPtr->pview->size.height-5);
|
||||
|
||||
XSetLineAttributes(rPtr->view->screen->display, gc, 1,
|
||||
LineSolid, CapNotLast, JoinMiter);
|
||||
|
||||
|
||||
XCopyArea(rPtr->view->screen->display, rPtr->drawBuffer,
|
||||
rPtr->view->window, rPtr->bg, 0, 0, rPtr->view->size.width, 40,
|
||||
0, 0);
|
||||
}
|
||||
|
||||
static Bool
|
||||
verifyMarkerMove(Ruler *rPtr, int x)
|
||||
{
|
||||
if(rPtr->flags.whichMarker<1 || rPtr->flags.whichMarker>6)
|
||||
return False;
|
||||
|
||||
switch(rPtr->flags.whichMarker) {
|
||||
case 1:
|
||||
if( x > rPtr->margins.right - 10
|
||||
|| rPtr->margins.body + x > rPtr->margins.right-MIN_DOC_WIDTH
|
||||
|| rPtr->margins.first + x > rPtr->margins.right-MIN_DOC_WIDTH
|
||||
|| x < rPtr->offset)
|
||||
return False;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
if( x < rPtr->margins.first+MIN_DOC_WIDTH
|
||||
|| x < rPtr->margins.body+MIN_DOC_WIDTH
|
||||
|| x < rPtr->margins.left+MIN_DOC_WIDTH
|
||||
|| x > rPtr->end) //rPtr->view->size.width)
|
||||
return False;
|
||||
break;
|
||||
|
||||
case 3:
|
||||
if( x >= rPtr->margins.right-MIN_DOC_WIDTH
|
||||
|| x < rPtr->margins.left)
|
||||
return False;
|
||||
break;
|
||||
|
||||
case 4:
|
||||
if( x >= rPtr->margins.right-MIN_DOC_WIDTH
|
||||
|| x < rPtr->margins.left)
|
||||
return False;
|
||||
break;
|
||||
|
||||
case 6:
|
||||
if( x >= rPtr->margins.right-MIN_DOC_WIDTH
|
||||
|| x < rPtr->margins.left)
|
||||
return False;
|
||||
break;
|
||||
|
||||
default: return False;
|
||||
}
|
||||
|
||||
rPtr->motion = x;
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
whichMarker(Ruler *rPtr, int x, int y)
|
||||
{
|
||||
CHECK_CLASS(rPtr, WC_Ruler);
|
||||
if(x<rPtr->offset || y>22)
|
||||
return 0;
|
||||
|
||||
if(y>22)
|
||||
return;
|
||||
|
||||
if(x<0)
|
||||
return;
|
||||
|
||||
if( rPtr->margins.dleft-x >= -6 && y <= 9 &&
|
||||
rPtr->margins.dleft-x <=0 && y>=4)
|
||||
return WRulerLeft;
|
||||
|
||||
if( rPtr->margins.right-x >= -1 && y <= 11 &&
|
||||
rPtr->margins.right-x <=5 && y>=4)
|
||||
return WRulerRight;
|
||||
|
||||
x -= rPtr->margins.dleft;
|
||||
if(x<0)
|
||||
return;
|
||||
|
||||
if( rPtr->margins.first-x <= 4 && y<=12 &&
|
||||
rPtr->margins.first-x >= -5 && y>=5)
|
||||
return WRulerFirst;
|
||||
|
||||
|
||||
|
||||
if( rPtr->margins.body-x <= 4 && y<=19 &&
|
||||
rPtr->margins.body-x >= -5 && y>=15)
|
||||
return WRulerBody;
|
||||
if( rPtr->margins.left-x >= -6 && y <= 9
|
||||
&& (rPtr->margins.left-x <=0) && y>=4) {
|
||||
rPtr->motion = rPtr->margins.left;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if(rPtr->margins.right-x >= -1 && y <= 11
|
||||
&& rPtr->margins.right-x <=5 && y>=4) {
|
||||
rPtr->motion = rPtr->margins.right;
|
||||
return 2;
|
||||
}
|
||||
|
||||
#if 0
|
||||
/* both first and body? */
|
||||
if( rPtr->margins.first-x <= 4 && rPtr->margins.first-x >= -5
|
||||
&& rPtr->margins.body-x <= 4 && rPtr->margins.body-x >= -5
|
||||
&& y>=13 && y<=14)
|
||||
return WRulerBoth;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static Bool
|
||||
verifyMarkerMove(Ruler *rPtr, int x)
|
||||
{
|
||||
if(!rPtr)
|
||||
return;
|
||||
|
||||
switch(rPtr->which_marker){
|
||||
case WRulerLeft:
|
||||
if(x < rPtr->margins.right-MIN_DOC_WIDTH &&
|
||||
rPtr->margins.body + x <= rPtr->margins.right-MIN_DOC_WIDTH &&
|
||||
rPtr->margins.first + x <= rPtr->margins.right-MIN_DOC_WIDTH)
|
||||
rPtr->margins.left = x;
|
||||
else return False;
|
||||
break;
|
||||
|
||||
|
||||
case WRulerBody:
|
||||
if(x < rPtr->margins.right-MIN_DOC_WIDTH && x >= rPtr->margins.left)
|
||||
rPtr->margins.body = x - rPtr->margins.dleft;
|
||||
else return False;
|
||||
break;
|
||||
|
||||
case WRulerFirst:
|
||||
if(x < rPtr->margins.right-MIN_DOC_WIDTH && x >= rPtr->margins.left)
|
||||
rPtr->margins.first = x - rPtr->margins.dleft;
|
||||
else return False;
|
||||
break;
|
||||
|
||||
case WRulerRight:
|
||||
if( x >= rPtr->margins.first+MIN_DOC_WIDTH &&
|
||||
x >= rPtr->margins.body+MIN_DOC_WIDTH &&
|
||||
x >= rPtr->margins.left+MIN_DOC_WIDTH &&
|
||||
x <= rPtr->end)
|
||||
rPtr->margins.right = x;
|
||||
else return False;
|
||||
break;
|
||||
|
||||
case WRulerBoth:
|
||||
if( x < rPtr->margins.right-MIN_DOC_WIDTH && x >= rPtr->margins.left) {
|
||||
rPtr->margins.first = x - rPtr->margins.dleft;
|
||||
rPtr->margins.body = x - rPtr->margins.dleft;
|
||||
} else return False;
|
||||
break;
|
||||
|
||||
default : return False;
|
||||
}
|
||||
|
||||
return True;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
moveMarker(Ruler *rPtr, int x)
|
||||
{
|
||||
|
||||
CHECK_CLASS(rPtr, WC_Ruler);
|
||||
|
||||
if(x < rPtr->offset || x > rPtr->end)
|
||||
return;
|
||||
|
||||
/* restrictive ticks */
|
||||
/*
|
||||
if(x%10-2 != 0)
|
||||
return;
|
||||
*/
|
||||
if(!verifyMarkerMove(rPtr, x))
|
||||
return;
|
||||
|
||||
/* clear around the motion area */
|
||||
#if 0
|
||||
XClearWindow(rPtr->view->screen->display, rPtr->view->window);
|
||||
#else
|
||||
|
||||
XClearArea(rPtr->view->screen->display, rPtr->view->window,
|
||||
x-10, 3, 20, rPtr->view->size.height-4, False);
|
||||
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
{ //while(1) {
|
||||
if (QLength(rPtr->view->screen->display) > 0 ) {
|
||||
XEvent * event;
|
||||
while(QLength(rPtr->view->screen->display) > 0 ) {
|
||||
XNextEvent(rPtr->view->screen->display, event);
|
||||
if(event->type == MotionNotify ||
|
||||
event->type == ButtonRelease)
|
||||
break;
|
||||
}
|
||||
}
|
||||
&& y>=15 && y<=17) {
|
||||
rPtr->motion = rPtr->margins.first;
|
||||
return 6;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if(rPtr->margins.first-x <= 4 && y<=15
|
||||
&& rPtr->margins.first-x >= -5 && y>=10) {
|
||||
rPtr->motion = rPtr->margins.first;
|
||||
return 3;
|
||||
}
|
||||
|
||||
if( rPtr->margins.body-x <= 4 && y<=21 &&
|
||||
rPtr->margins.body-x >= -5 && y>=17) {
|
||||
rPtr->motion = rPtr->margins.body;
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
||||
rPtr->pressed = x;
|
||||
/* do tabs (5)*/
|
||||
|
||||
if(rPtr->moveaction)
|
||||
(rPtr->moveaction)(rPtr, rPtr->clientData);
|
||||
|
||||
paintRuler(rPtr);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
handleEvents(XEvent *event, void *data)
|
||||
{
|
||||
Ruler *rPtr = (Ruler*)data;
|
||||
|
||||
CHECK_CLASS(rPtr, WC_Ruler);
|
||||
|
||||
Display *dpy = event->xany.display;
|
||||
|
||||
switch (event->type) {
|
||||
|
||||
case Expose:
|
||||
if(event->xexpose.count)
|
||||
break;
|
||||
if(rPtr->view->flags.realized)
|
||||
paintRuler(rPtr);
|
||||
case Expose:
|
||||
paintRuler(rPtr);
|
||||
break;
|
||||
|
||||
case MotionNotify:
|
||||
if(rPtr->flags.buttonPressed
|
||||
&& (event->xmotion.state & Button1Mask)) {
|
||||
if(verifyMarkerMove(rPtr, event->xmotion.x)){
|
||||
GC gc = WMColorGC(WMDarkGrayColor(rPtr->view->screen));
|
||||
paintRuler(rPtr);
|
||||
if(rPtr->moveAction)
|
||||
(rPtr->moveAction)(rPtr, rPtr->clientData);
|
||||
XSetLineAttributes(rPtr->view->screen->display, gc, 1,
|
||||
LineSolid, CapNotLast, JoinMiter);
|
||||
XDrawLine(rPtr->pview->screen->display,
|
||||
rPtr->pview->window,
|
||||
gc, rPtr->motion+1, 40,
|
||||
rPtr->motion+1, rPtr->pview->size.height-5);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case ButtonPress:
|
||||
if(event->xbutton.button != Button1)
|
||||
return;
|
||||
|
||||
rPtr->flags.buttonPressed = True;
|
||||
rPtr->which_marker =
|
||||
rPtr->flags.whichMarker =
|
||||
whichMarker(rPtr, event->xmotion.x,
|
||||
event->xmotion.y);
|
||||
|
||||
#if 0
|
||||
/* clear around the clicked area */
|
||||
if(rPtr->which_marker>=0 && rPtr->which_marker <= 4) {
|
||||
|
||||
XClearArea(rPtr->view->screen->display, rPtr->view->window,
|
||||
WMGetRulerMargin(rPtr, rPtr->which_marker)-10, 2, 20, 21, True);
|
||||
|
||||
paintRuler(rPtr);
|
||||
}
|
||||
#endif
|
||||
paintRuler(rPtr);
|
||||
break;
|
||||
|
||||
case ButtonRelease:
|
||||
if(event->xbutton.button != Button1)
|
||||
return;
|
||||
|
||||
rPtr->flags.buttonPressed = False;
|
||||
rPtr->pressed = event->xmotion.x;
|
||||
if(rPtr->which_marker == 0) {
|
||||
rPtr->margins.dleft = rPtr->margins.left;
|
||||
|
||||
/* clear entire (moved) ruler */
|
||||
XClearArea(rPtr->view->screen->display,
|
||||
rPtr->view->window, 0, 0, rPtr->view->size.width,
|
||||
rPtr->view->size.height, True);
|
||||
switch(rPtr->flags.whichMarker) {
|
||||
case 1: {
|
||||
int change = rPtr->margins.left-rPtr->motion;
|
||||
rPtr->margins.first -=change;
|
||||
rPtr->margins.body -= change;
|
||||
rPtr->margins.left = rPtr->motion;
|
||||
paintRuler(rPtr); break;
|
||||
}
|
||||
case 2: rPtr->margins.right = rPtr->motion; break;
|
||||
case 3: rPtr->margins.first = rPtr->motion; break;
|
||||
case 4: rPtr->margins.body = rPtr->motion; break;
|
||||
case 6: rPtr->margins.first = rPtr->margins.body
|
||||
= rPtr->motion; break;
|
||||
}
|
||||
|
||||
if(rPtr->action)
|
||||
(rPtr->action)(rPtr, rPtr->clientData);
|
||||
|
||||
paintRuler(rPtr);
|
||||
if(rPtr->releaseAction)
|
||||
(rPtr->releaseAction)(rPtr, rPtr->clientData);
|
||||
break;
|
||||
|
||||
case MotionNotify:
|
||||
if(rPtr->flags.buttonPressed &&
|
||||
(event->xmotion.state & Button1Mask)) {
|
||||
moveMarker(rPtr, event->xmotion.x);
|
||||
}
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
rulerDidResize(W_ViewDelegate *self, WMView *view)
|
||||
{
|
||||
Ruler *rPtr = (Ruler *)view->self;
|
||||
|
||||
createDrawBuffer(rPtr);
|
||||
paintRuler(rPtr);
|
||||
|
||||
}
|
||||
|
||||
|
||||
W_ViewDelegate _RulerViewDelegate =
|
||||
{
|
||||
NULL,
|
||||
NULL,
|
||||
rulerDidResize,
|
||||
NULL,
|
||||
NULL
|
||||
};
|
||||
|
||||
|
||||
WMRuler *
|
||||
WMCreateRuler(WMWidget *parent)
|
||||
{
|
||||
Ruler *rPtr = wmalloc(sizeof(Ruler));
|
||||
unsigned int w = WMWidgetWidth(parent);
|
||||
|
||||
memset(rPtr, 0, sizeof(Ruler));
|
||||
|
||||
@@ -486,7 +393,9 @@ WMCreateRuler(WMWidget *parent)
|
||||
}
|
||||
rPtr->view->self = rPtr;
|
||||
|
||||
W_ResizeView(rPtr->view, DEFAULT_RULER_WIDTH, DEFAULT_RULER_HEIGHT);
|
||||
rPtr->drawBuffer = (Pixmap) NULL;
|
||||
|
||||
W_ResizeView(rPtr->view, w, 40);
|
||||
|
||||
WMCreateEventHandler(rPtr->view, ExposureMask|StructureNotifyMask
|
||||
|EnterWindowMask|LeaveWindowMask|FocusChangeMask
|
||||
@@ -495,21 +404,22 @@ WMCreateRuler(WMWidget *parent)
|
||||
|
||||
rPtr->view->delegate = &_RulerViewDelegate;
|
||||
|
||||
rPtr->which_marker = WRulerLeft; /* none */
|
||||
rPtr->pressed = 0;
|
||||
rPtr->bg = WMColorGC(WMGrayColor(rPtr->view->screen));
|
||||
rPtr->fg = WMColorGC(WMBlackColor(rPtr->view->screen));
|
||||
rPtr->font = WMSystemFontOfSize(rPtr->view->screen, 8);
|
||||
|
||||
rPtr->offset = 22;
|
||||
rPtr->margins.left = 22;
|
||||
rPtr->margins.body = 22;
|
||||
rPtr->margins.first = 42;
|
||||
rPtr->margins.right = (w<502?w:502);
|
||||
|
||||
rPtr->offset = DEFAULT_X_OFFSET;
|
||||
rPtr->margins.left = DEFAULT_X_OFFSET;
|
||||
rPtr->margins.dleft = DEFAULT_X_OFFSET;
|
||||
rPtr->margins.body = 0; /* relative */
|
||||
rPtr->margins.first = 0; /* relative */
|
||||
rPtr->margins.right = 300+DEFAULT_X_OFFSET;
|
||||
rPtr->end = 320+DEFAULT_X_OFFSET;
|
||||
|
||||
rPtr->flags.showtabs = False;
|
||||
rPtr->flags.whichMarker = 0; /* none */
|
||||
rPtr->flags.buttonPressed = False;
|
||||
|
||||
rPtr->moveAction = NULL;
|
||||
rPtr->releaseAction = NULL;
|
||||
|
||||
rPtr->pview = W_VIEW(parent);
|
||||
|
||||
return rPtr;
|
||||
@@ -517,96 +427,43 @@ WMCreateRuler(WMWidget *parent)
|
||||
|
||||
|
||||
void
|
||||
WMShowRulerTabs(WMRuler *rPtr, Bool show)
|
||||
{
|
||||
if(!rPtr)
|
||||
return;
|
||||
CHECK_CLASS(rPtr, WC_Ruler);
|
||||
rPtr->flags.showtabs = show;
|
||||
}
|
||||
|
||||
void
|
||||
WMSetRulerMargin(WMRuler *rPtr, int which, int pixels)
|
||||
WMSetRulerMargins(WMRuler *rPtr, WMRulerMargins margins)
|
||||
{
|
||||
if(!rPtr)
|
||||
return;
|
||||
|
||||
|
||||
if(pixels<rPtr->offset)
|
||||
pixels = rPtr->offset;
|
||||
|
||||
rPtr->which_marker = which;
|
||||
if(!verifyMarkerMove(rPtr, pixels))
|
||||
return;
|
||||
|
||||
rPtr->pressed = pixels;
|
||||
if(which == WRulerLeft)
|
||||
rPtr->margins.dleft = rPtr->margins.left;
|
||||
|
||||
if(!rPtr->view->flags.realized)
|
||||
return;
|
||||
|
||||
XClearArea(rPtr->view->screen->display,
|
||||
rPtr->view->window, 0, 0, rPtr->view->size.width,
|
||||
rPtr->view->size.height, True);
|
||||
|
||||
rPtr->margins.left = margins.left + rPtr->offset;
|
||||
rPtr->margins.right = margins.right + rPtr->offset;
|
||||
rPtr->margins.first = margins.first + rPtr->offset;
|
||||
rPtr->margins.body = margins.body + rPtr->offset;
|
||||
rPtr->margins.tabs = margins.tabs; //for loop
|
||||
paintRuler(rPtr);
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
WMGetRulerMargin(WMRuler *rPtr, int which)
|
||||
WMRulerMargins
|
||||
WMGetRulerMargins(WMRuler *rPtr)
|
||||
{
|
||||
WMRulerMargins margins;
|
||||
if(!rPtr)
|
||||
return;
|
||||
return margins;
|
||||
|
||||
CHECK_CLASS(rPtr, WC_Ruler);
|
||||
margins.left = rPtr->margins.left - rPtr->offset;
|
||||
margins.right = rPtr->margins.right - rPtr->offset;
|
||||
margins.first = rPtr->margins.first - rPtr->offset;
|
||||
margins.body = rPtr->margins.body - rPtr->offset;
|
||||
//for
|
||||
margins.tabs = rPtr->margins.tabs;
|
||||
|
||||
switch(which) {
|
||||
case WRulerLeft: return rPtr->margins.left; break;
|
||||
case WRulerBody: return rPtr->margins.body; break;
|
||||
case WRulerFirst: return rPtr->margins.first; break;
|
||||
case WRulerRight: return rPtr->margins.right; break;
|
||||
case WRulerBoth: return rPtr->margins.body; break;
|
||||
case WRulerDocLeft: return rPtr->margins.dleft; break;
|
||||
default: return rPtr->margins.dleft;
|
||||
}
|
||||
return rPtr->margins;
|
||||
}
|
||||
|
||||
/* _which_ one was released */
|
||||
int
|
||||
WMGetReleasedRulerMargin(WMRuler *rPtr)
|
||||
{
|
||||
if(!rPtr)
|
||||
return WRulerLeft;
|
||||
CHECK_CLASS(rPtr, WC_Ruler);
|
||||
if(rPtr->which_marker != -1)
|
||||
return rPtr->which_marker;
|
||||
else
|
||||
return WRulerLeft;
|
||||
}
|
||||
|
||||
/* _which_ one is being grabbed */
|
||||
int
|
||||
WMGetGrabbedRulerMargin(WMRuler *rPtr)
|
||||
{
|
||||
if(!rPtr)
|
||||
return WRulerLeft;
|
||||
CHECK_CLASS(rPtr, WC_Ruler);
|
||||
if(rPtr->which_marker != -1)
|
||||
return rPtr->which_marker;
|
||||
else
|
||||
return WRulerLeft;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
void
|
||||
WMSetRulerOffset(WMRuler *rPtr, int pixels)
|
||||
{
|
||||
if(!rPtr || pixels<0)
|
||||
if(!rPtr || pixels<0 || pixels+MIN_DOC_WIDTH>=rPtr->view->size.width)
|
||||
return;
|
||||
CHECK_CLASS(rPtr, WC_Ruler);
|
||||
rPtr->offset = pixels;
|
||||
//rulerDidResize(rPtr, rPtr->view);
|
||||
}
|
||||
|
||||
int
|
||||
@@ -614,30 +471,43 @@ WMGetRulerOffset(WMRuler *rPtr)
|
||||
{
|
||||
if(!rPtr)
|
||||
return;
|
||||
CHECK_CLASS(rPtr, WC_Ruler);
|
||||
return rPtr->offset;
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
WMSetRulerAction(WMRuler *rPtr, WMAction *action, void *clientData)
|
||||
WMSetRulerReleaseAction(WMRuler *rPtr, WMAction *action, void *clientData)
|
||||
{
|
||||
if(!rPtr)
|
||||
return;
|
||||
|
||||
CHECK_CLASS(rPtr, WC_Ruler);
|
||||
rPtr->action = action;
|
||||
rPtr->releaseAction = action;
|
||||
rPtr->clientData = clientData;
|
||||
}
|
||||
|
||||
void
|
||||
WMSetRulerMoveAction(WMRuler *rPtr, WMAction *moveaction, void *clientData)
|
||||
WMSetRulerMoveAction(WMRuler *rPtr, WMAction *action, void *clientData)
|
||||
{
|
||||
if(!rPtr)
|
||||
return;
|
||||
|
||||
CHECK_CLASS(rPtr, WC_Ruler);
|
||||
rPtr->moveaction = moveaction;
|
||||
rPtr->moveAction = action;
|
||||
rPtr->clientData = clientData;
|
||||
}
|
||||
|
||||
/* _which_ one was released */
|
||||
int
|
||||
WMGetReleasedRulerMargin(WMRuler *rPtr)
|
||||
{
|
||||
if(!rPtr)
|
||||
return 0;
|
||||
return rPtr->flags.whichMarker;
|
||||
}
|
||||
|
||||
/* _which_ one is being grabbed */
|
||||
int
|
||||
WMGetGrabbedRulerMargin(WMRuler *rPtr)
|
||||
{
|
||||
if(!rPtr)
|
||||
return 0;
|
||||
return rPtr->flags.whichMarker;
|
||||
}
|
||||
|
||||
47
WINGs/wruler.h
Normal file
47
WINGs/wruler.h
Normal file
@@ -0,0 +1,47 @@
|
||||
|
||||
#include <WINGs.h>
|
||||
#include <WINGsP.h>
|
||||
#include <WUtil.h>
|
||||
|
||||
//items in this file go into WINGs.h
|
||||
#define WC_Ruler 16
|
||||
typedef struct W_Ruler WMRuler;
|
||||
|
||||
/* All indentation and tab markers are _relative_ to the left margin marker */
|
||||
|
||||
/* a tabstop is a linked list of tabstops,
|
||||
* each containing the position of the tabstop */
|
||||
|
||||
typedef struct _tabstops {
|
||||
struct _tabstops *next;
|
||||
int value;
|
||||
} WMTabStops;
|
||||
|
||||
typedef struct W_RulerMargins {
|
||||
int left; /* left margin marker */
|
||||
int right; /* right margin marker */
|
||||
int first; /* indentation marker for first line only */
|
||||
int body; /* body indentation marker */
|
||||
WMTabStops *tabs;
|
||||
} WMRulerMargins;
|
||||
|
||||
|
||||
|
||||
|
||||
WMRuler *WMCreateRuler (WMWidget *parent);
|
||||
void WMShowRulerTabs(WMRuler *rPtr, Bool Show);
|
||||
void WMSetRulerMoveAction(WMRuler *rPtr,
|
||||
WMAction *action, void *clientData);
|
||||
void WMSetRulerReleaseAction(WMRuler *rPtr,
|
||||
WMAction *action, void *clientData);
|
||||
|
||||
int WMGetRulerOffset(WMRuler *rPtr);
|
||||
void WMSetRulerOffset(WMRuler *rPtr, int pixels);
|
||||
|
||||
WMRulerMargins WMGetRulerMargins(WMRuler *rPtr);
|
||||
void WMSetRulerMargins(WMRuler *rPtr, WMRulerMargins margins);
|
||||
|
||||
int WMGetReleasedRulerMargin(WMRuler *rPtr);
|
||||
int WMGetGrabbedRulerMargin(WMRuler *rPtr);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user