mirror of
https://github.com/gryf/wmaker.git
synced 2026-01-24 08:05:45 +01:00
Modified ruler stuff
This commit is contained in:
@@ -401,6 +401,23 @@ typedef struct WMInputPanel {
|
|||||||
} WMInputPanel;
|
} WMInputPanel;
|
||||||
|
|
||||||
|
|
||||||
|
/* WMRuler stuff */
|
||||||
|
/* 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 {
|
||||||
|
int value;
|
||||||
|
struct WMTabStops *next;
|
||||||
|
} WMTabStops;
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
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;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -1389,27 +1406,25 @@ int WMGetSplitViewDividerThickness(WMSplitView *sPtr);
|
|||||||
|
|
||||||
/* ...................................................................... */
|
/* ...................................................................... */
|
||||||
|
|
||||||
|
WMRuler *WMCreateRuler (WMWidget *parent);
|
||||||
WMRuler *WMCreateRuler(WMWidget *parent);
|
|
||||||
|
|
||||||
void WMShowRulerTabs(WMRuler *rPtr, Bool Show);
|
void WMShowRulerTabs(WMRuler *rPtr, Bool Show);
|
||||||
|
|
||||||
int WMGetRulerMargin(WMRuler *rPtr, int which);
|
WMRulerMargins WMGetRulerMargins(WMRuler *rPtr);
|
||||||
|
|
||||||
int WMGetReleasedRulerMargin(WMRuler *rPtr);
|
void WMSetRulerMargins(WMRuler *rPtr, WMRulerMargins margins);
|
||||||
|
|
||||||
int WMGetGrabbedRulerMargin(WMRuler *rPtr);
|
int WMGetGrabbedRulerMargin(WMRuler *rPtr);
|
||||||
|
|
||||||
|
int WMGetReleasedRulerMargin(WMRuler *rPtr);
|
||||||
|
|
||||||
int WMGetRulerOffset(WMRuler *rPtr);
|
int WMGetRulerOffset(WMRuler *rPtr);
|
||||||
|
|
||||||
void WMSetRulerOffset(WMRuler *rPtr, int pixels);
|
void WMSetRulerOffset(WMRuler *rPtr, int pixels);
|
||||||
|
|
||||||
void WMSetRulerMargin(WMRuler *rPtr, int which, int pixels);
|
|
||||||
|
|
||||||
void WMSetRulerAction(WMRuler *rPtr, WMAction *action, void *clientData);
|
|
||||||
|
|
||||||
void WMSetRulerMoveAction(WMRuler *rPtr, WMAction *action, void *clientData);
|
void WMSetRulerMoveAction(WMRuler *rPtr, WMAction *action, void *clientData);
|
||||||
|
|
||||||
|
void WMSetRulerReleaseAction(WMRuler *rPtr, WMAction *action, void *clientData);
|
||||||
|
|
||||||
/* ....................................................................... */
|
/* ....................................................................... */
|
||||||
|
|
||||||
|
|||||||
598
WINGs/wruler.c
598
WINGs/wruler.c
@@ -1,51 +1,51 @@
|
|||||||
#include "wruler.h"
|
#include "WINGsP.h"
|
||||||
|
|
||||||
#define MIN_DOC_WIDTH 10
|
#define MIN_DOC_WIDTH 10
|
||||||
|
|
||||||
typedef struct W_Ruler {
|
typedef struct W_Ruler {
|
||||||
W_Class widgetClass;
|
W_Class widgetClass;
|
||||||
W_View *view;
|
W_View *view;
|
||||||
W_View *pview; /* the parent's view (for drawing the line) */
|
W_View *pview; /* the parent's view (for drawing the line) */
|
||||||
|
|
||||||
WMAction *moveAction; /* what to when while moving */
|
WMAction *moveAction; /* what to when while moving */
|
||||||
WMAction *releaseAction; /* what to do when released */
|
WMAction *releaseAction; /* what to do when released */
|
||||||
void *clientData;
|
void *clientData;
|
||||||
|
|
||||||
GC fg, bg;
|
GC fg, bg;
|
||||||
WMFont *font;
|
WMFont *font;
|
||||||
WMRulerMargins margins;
|
WMRulerMargins margins;
|
||||||
int offset;
|
int offset;
|
||||||
int motion; /* the position of the _moving_ marker(s) */
|
int motion; /* the position of the _moving_ marker(s) */
|
||||||
int end; /* the last tick on the baseline (restrict markers to it) */
|
int end; /* the last tick on the baseline (restrict markers to it) */
|
||||||
|
|
||||||
Pixmap drawBuffer;
|
Pixmap drawBuffer;
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
unsigned int buttonPressed:1;
|
unsigned int buttonPressed:1;
|
||||||
/* 0, 1, 2, 3, 4, 5, 6 */
|
/* 0, 1, 2, 3, 4, 5, 6 */
|
||||||
unsigned int whichMarker:3; /* none, left, right, first, body, tabstop, both */
|
unsigned int whichMarker:3; /* none, left, right, first, body, tabstop, both */
|
||||||
unsigned int RESERVED:28;
|
unsigned int RESERVED:28;
|
||||||
} flags;
|
} flags;
|
||||||
} Ruler;
|
} Ruler;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Marker for left margin
|
/* Marker for left margin
|
||||||
|
|
||||||
|\
|
|\
|
||||||
| \
|
| \
|
||||||
|__\
|
|__\
|
||||||
|
|
|
|
||||||
| */
|
| */
|
||||||
static void
|
static void
|
||||||
drawLeftMarker(Ruler *rPtr)
|
drawLeftMarker(Ruler *rPtr)
|
||||||
{
|
{
|
||||||
XPoint points[4];
|
XPoint points[4];
|
||||||
int xpos = (rPtr->flags.whichMarker==1?
|
int xpos = (rPtr->flags.whichMarker==1?
|
||||||
rPtr->motion:rPtr->margins.left);
|
rPtr->motion:rPtr->margins.left);
|
||||||
|
|
||||||
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer,
|
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer,
|
||||||
rPtr->fg, xpos, 8, xpos, 22);
|
rPtr->fg, xpos, 8, xpos, 22);
|
||||||
points[0].x = xpos;
|
points[0].x = xpos;
|
||||||
points[0].y = 1;
|
points[0].y = 1;
|
||||||
points[1].x = points[0].x+6;
|
points[1].x = points[0].x+6;
|
||||||
@@ -54,27 +54,27 @@ drawLeftMarker(Ruler *rPtr)
|
|||||||
points[2].y = 9;
|
points[2].y = 9;
|
||||||
points[3].x = points[0].x;
|
points[3].x = points[0].x;
|
||||||
points[3].y = 9;
|
points[3].y = 9;
|
||||||
XFillPolygon (rPtr->view->screen->display, rPtr->drawBuffer,
|
XFillPolygon (rPtr->view->screen->display, rPtr->drawBuffer,
|
||||||
rPtr->fg, points, 4, Convex, CoordModeOrigin);
|
rPtr->fg, points, 4, Convex, CoordModeOrigin);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Marker for right margin
|
/* Marker for right margin
|
||||||
|
|
||||||
/|
|
/|
|
||||||
/ |
|
/ |
|
||||||
/__|
|
/__|
|
||||||
|
|
|
|
||||||
| */
|
| */
|
||||||
|
|
||||||
static void
|
static void
|
||||||
drawRightMarker(Ruler *rPtr)
|
drawRightMarker(Ruler *rPtr)
|
||||||
{
|
{
|
||||||
XPoint points[4];
|
XPoint points[4];
|
||||||
int xpos = (rPtr->flags.whichMarker==2?
|
int xpos = (rPtr->flags.whichMarker==2?
|
||||||
rPtr->motion:rPtr->margins.right);
|
rPtr->motion:rPtr->margins.right);
|
||||||
|
|
||||||
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer,
|
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer,
|
||||||
rPtr->fg, xpos, 8, xpos, 22);
|
rPtr->fg, xpos, 8, xpos, 22);
|
||||||
points[0].x = xpos+1;
|
points[0].x = xpos+1;
|
||||||
points[0].y = 0;
|
points[0].y = 0;
|
||||||
points[1].x = points[0].x-6;
|
points[1].x = points[0].x-6;
|
||||||
@@ -83,276 +83,276 @@ drawRightMarker(Ruler *rPtr)
|
|||||||
points[2].y = 9;
|
points[2].y = 9;
|
||||||
points[3].x = points[0].x;
|
points[3].x = points[0].x;
|
||||||
points[3].y = 9;
|
points[3].y = 9;
|
||||||
XFillPolygon (rPtr->view->screen->display, rPtr->drawBuffer,
|
XFillPolygon (rPtr->view->screen->display, rPtr->drawBuffer,
|
||||||
rPtr->fg, points, 4, Convex, CoordModeOrigin);
|
rPtr->fg, points, 4, Convex, CoordModeOrigin);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Marker for first line only
|
/* Marker for first line only
|
||||||
_____
|
_____
|
||||||
|___|
|
|___|
|
||||||
| */
|
| */
|
||||||
static void
|
static void
|
||||||
drawFirstMarker(Ruler *rPtr)
|
drawFirstMarker(Ruler *rPtr)
|
||||||
{
|
{
|
||||||
int xpos = ((rPtr->flags.whichMarker==3 || rPtr->flags.whichMarker==6)?
|
int xpos = ((rPtr->flags.whichMarker==3 || rPtr->flags.whichMarker==6)?
|
||||||
rPtr->motion:rPtr->margins.first);
|
rPtr->motion:rPtr->margins.first);
|
||||||
XFillRectangle(rPtr->view->screen->display, rPtr->drawBuffer,
|
XFillRectangle(rPtr->view->screen->display, rPtr->drawBuffer,
|
||||||
rPtr->fg, xpos-5, 10, 11, 5);
|
rPtr->fg, xpos-5, 10, 11, 5);
|
||||||
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer,
|
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer,
|
||||||
rPtr->fg, xpos, 12, xpos, 22);
|
rPtr->fg, xpos, 12, xpos, 22);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Marker for rest of body
|
/* Marker for rest of body
|
||||||
_____
|
_____
|
||||||
\ /
|
\ /
|
||||||
\./ */
|
\./ */
|
||||||
static void
|
static void
|
||||||
drawBodyMarker(Ruler *rPtr)
|
drawBodyMarker(Ruler *rPtr)
|
||||||
{
|
{
|
||||||
XPoint points[4];
|
XPoint points[4];
|
||||||
int xpos = ((rPtr->flags.whichMarker==4 || rPtr->flags.whichMarker==6)?
|
int xpos = ((rPtr->flags.whichMarker==4 || rPtr->flags.whichMarker==6)?
|
||||||
rPtr->motion:rPtr->margins.body);
|
rPtr->motion:rPtr->margins.body);
|
||||||
points[0].x = xpos-5;
|
points[0].x = xpos-5;
|
||||||
points[0].y = 16;
|
points[0].y = 16;
|
||||||
points[1].x = points[0].x+11;
|
points[1].x = points[0].x+11;
|
||||||
points[1].y = 16;
|
points[1].y = 16;
|
||||||
points[2].x = points[0].x+5;
|
points[2].x = points[0].x+5;
|
||||||
points[2].y = 22;
|
points[2].y = 22;
|
||||||
XFillPolygon (rPtr->view->screen->display, rPtr->drawBuffer,
|
XFillPolygon (rPtr->view->screen->display, rPtr->drawBuffer,
|
||||||
rPtr->fg, points, 3, Convex, CoordModeOrigin);
|
rPtr->fg, points, 3, Convex, CoordModeOrigin);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
createDrawBuffer(Ruler *rPtr)
|
createDrawBuffer(Ruler *rPtr)
|
||||||
{
|
{
|
||||||
if(rPtr->drawBuffer)
|
if(rPtr->drawBuffer)
|
||||||
XFreePixmap(rPtr->view->screen->display, rPtr->drawBuffer);
|
XFreePixmap(rPtr->view->screen->display, rPtr->drawBuffer);
|
||||||
rPtr->drawBuffer = XCreatePixmap(rPtr->view->screen->display,
|
rPtr->drawBuffer = XCreatePixmap(rPtr->view->screen->display,
|
||||||
rPtr->view->window, rPtr->view->size.width, 40,
|
rPtr->view->window, rPtr->view->size.width, 40,
|
||||||
rPtr->view->screen->depth);
|
rPtr->view->screen->depth);
|
||||||
XFillRectangle(rPtr->view->screen->display, rPtr->drawBuffer,
|
XFillRectangle(rPtr->view->screen->display, rPtr->drawBuffer,
|
||||||
rPtr->bg, 0, 0, rPtr->view->size.width, 40);
|
rPtr->bg, 0, 0, rPtr->view->size.width, 40);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
drawRulerOnPixmap(Ruler *rPtr)
|
drawRulerOnPixmap(Ruler *rPtr)
|
||||||
{
|
{
|
||||||
int i, j, w, m;
|
int i, j, w, m;
|
||||||
char c[3];
|
char c[3];
|
||||||
int marks[9] = {11, 3, 5, 3, 7, 3, 5, 3};
|
int marks[9] = {11, 3, 5, 3, 7, 3, 5, 3};
|
||||||
|
|
||||||
if(!rPtr->drawBuffer)
|
if(!rPtr->drawBuffer)
|
||||||
createDrawBuffer(rPtr);
|
createDrawBuffer(rPtr);
|
||||||
|
|
||||||
XFillRectangle(rPtr->view->screen->display, rPtr->drawBuffer,
|
XFillRectangle(rPtr->view->screen->display, rPtr->drawBuffer,
|
||||||
rPtr->bg, 0, 0, rPtr->view->size.width, 40);
|
rPtr->bg, 0, 0, rPtr->view->size.width, 40);
|
||||||
|
|
||||||
|
|
||||||
WMDrawString(rPtr->view->screen, rPtr->drawBuffer,
|
WMDrawString(rPtr->view->screen, rPtr->drawBuffer,
|
||||||
rPtr->fg, rPtr->font, rPtr->margins.left+2, 26, "0 inches", 10);
|
rPtr->fg, rPtr->font, rPtr->margins.left+2, 26, "0 inches", 10);
|
||||||
|
|
||||||
/* marker ticks */
|
/* marker ticks */
|
||||||
i=j=m=0;
|
i=j=m=0;
|
||||||
w = rPtr->view->size.width - rPtr->margins.left;
|
w = rPtr->view->size.width - rPtr->margins.left;
|
||||||
while(m < w) {
|
while(m < w) {
|
||||||
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer,
|
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer,
|
||||||
rPtr->fg, rPtr->margins.left+m, 23,
|
rPtr->fg, rPtr->margins.left+m, 23,
|
||||||
rPtr->margins.left+m, marks[i%8]+23);
|
rPtr->margins.left+m, marks[i%8]+23);
|
||||||
if(i!=0 && i%8==0) {
|
if(i!=0 && i%8==0) {
|
||||||
if(j<10)
|
if(j<10)
|
||||||
snprintf(c,3,"%d",++j);
|
snprintf(c,3,"%d",++j);
|
||||||
else
|
else
|
||||||
snprintf(c,3,"%2d",++j);
|
snprintf(c,3,"%2d",++j);
|
||||||
WMDrawString(rPtr->view->screen, rPtr->drawBuffer,
|
WMDrawString(rPtr->view->screen, rPtr->drawBuffer,
|
||||||
rPtr->fg, rPtr->font, rPtr->margins.left+2+m, 26, c, 2);
|
rPtr->fg, rPtr->font, rPtr->margins.left+2+m, 26, c, 2);
|
||||||
}
|
}
|
||||||
m = (++i)*10;
|
m = (++i)*10;
|
||||||
}
|
}
|
||||||
|
|
||||||
rPtr->end = rPtr->margins.left+m-10;
|
rPtr->end = rPtr->margins.left+m-10;
|
||||||
if(rPtr->margins.right > rPtr->end)
|
if(rPtr->margins.right > rPtr->end)
|
||||||
rPtr->margins.right = rPtr->end;
|
rPtr->margins.right = rPtr->end;
|
||||||
/* base line */
|
/* base line */
|
||||||
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer,
|
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer,
|
||||||
rPtr->fg, rPtr->margins.left, 22, rPtr->margins.left+m-10, 22);
|
rPtr->fg, rPtr->margins.left, 22, rPtr->margins.left+m-10, 22);
|
||||||
|
|
||||||
drawLeftMarker(rPtr);
|
drawLeftMarker(rPtr);
|
||||||
drawRightMarker(rPtr);
|
drawRightMarker(rPtr);
|
||||||
drawFirstMarker(rPtr);
|
drawFirstMarker(rPtr);
|
||||||
drawBodyMarker(rPtr);
|
drawBodyMarker(rPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
paintRuler(Ruler *rPtr)
|
paintRuler(Ruler *rPtr)
|
||||||
{
|
{
|
||||||
WMScreen *screen = rPtr->view->screen;
|
WMScreen *screen = rPtr->view->screen;
|
||||||
if(1||!rPtr->drawBuffer) { //first exposure
|
if(1||!rPtr->drawBuffer) { //first exposure
|
||||||
drawRulerOnPixmap(rPtr);
|
drawRulerOnPixmap(rPtr);
|
||||||
}
|
}
|
||||||
|
|
||||||
XCopyArea(rPtr->view->screen->display, rPtr->drawBuffer,
|
XCopyArea(rPtr->view->screen->display, rPtr->drawBuffer,
|
||||||
rPtr->view->window, rPtr->bg, 0, 0, rPtr->view->size.width, 40,
|
rPtr->view->window, rPtr->bg, 0, 0, rPtr->view->size.width, 40,
|
||||||
0, 0);
|
0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Bool
|
static Bool
|
||||||
verifyMarkerMove(Ruler *rPtr, int x)
|
verifyMarkerMove(Ruler *rPtr, int x)
|
||||||
{
|
{
|
||||||
if(rPtr->flags.whichMarker<1 || rPtr->flags.whichMarker>6)
|
if(rPtr->flags.whichMarker<1 || rPtr->flags.whichMarker>6)
|
||||||
return False;
|
return False;
|
||||||
|
|
||||||
switch(rPtr->flags.whichMarker) {
|
switch(rPtr->flags.whichMarker) {
|
||||||
case 1:
|
case 1:
|
||||||
if( x > rPtr->margins.right - 10
|
if( x > rPtr->margins.right - 10
|
||||||
|| rPtr->margins.body + 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.first + x > rPtr->margins.right-MIN_DOC_WIDTH
|
||||||
|| x < rPtr->offset)
|
|| x < rPtr->offset)
|
||||||
return False;
|
return False;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
if( x < rPtr->margins.first+MIN_DOC_WIDTH
|
if( x < rPtr->margins.first+MIN_DOC_WIDTH
|
||||||
|| x < rPtr->margins.body+MIN_DOC_WIDTH
|
|| x < rPtr->margins.body+MIN_DOC_WIDTH
|
||||||
|| x < rPtr->margins.left+MIN_DOC_WIDTH
|
|| x < rPtr->margins.left+MIN_DOC_WIDTH
|
||||||
|| x > rPtr->end) //rPtr->view->size.width)
|
|| x > rPtr->end) //rPtr->view->size.width)
|
||||||
return False;
|
return False;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
if( x >= rPtr->margins.right-MIN_DOC_WIDTH
|
if( x >= rPtr->margins.right-MIN_DOC_WIDTH
|
||||||
|| x < rPtr->margins.left)
|
|| x < rPtr->margins.left)
|
||||||
return False;
|
return False;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
if( x >= rPtr->margins.right-MIN_DOC_WIDTH
|
if( x >= rPtr->margins.right-MIN_DOC_WIDTH
|
||||||
|| x < rPtr->margins.left)
|
|| x < rPtr->margins.left)
|
||||||
return False;
|
return False;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 6:
|
case 6:
|
||||||
if( x >= rPtr->margins.right-MIN_DOC_WIDTH
|
if( x >= rPtr->margins.right-MIN_DOC_WIDTH
|
||||||
|| x < rPtr->margins.left)
|
|| x < rPtr->margins.left)
|
||||||
return False;
|
return False;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default: return False;
|
default: return False;
|
||||||
}
|
}
|
||||||
|
|
||||||
rPtr->motion = x;
|
rPtr->motion = x;
|
||||||
return True;
|
return True;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
whichMarker(Ruler *rPtr, int x, int y)
|
whichMarker(Ruler *rPtr, int x, int y)
|
||||||
{
|
{
|
||||||
if(x<rPtr->offset || y>22)
|
if(x<rPtr->offset || y>22)
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
if( rPtr->margins.left-x >= -6 && y <= 9
|
if( rPtr->margins.left-x >= -6 && y <= 9
|
||||||
&& (rPtr->margins.left-x <=0) && y>=4) {
|
&& (rPtr->margins.left-x <=0) && y>=4) {
|
||||||
rPtr->motion = rPtr->margins.left;
|
rPtr->motion = rPtr->margins.left;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(rPtr->margins.right-x >= -1 && y <= 11
|
if(rPtr->margins.right-x >= -1 && y <= 11
|
||||||
&& rPtr->margins.right-x <=5 && y>=4) {
|
&& rPtr->margins.right-x <=5 && y>=4) {
|
||||||
rPtr->motion = rPtr->margins.right;
|
rPtr->motion = rPtr->margins.right;
|
||||||
return 2;
|
return 2;
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
#if 0
|
||||||
/* both first and body? */
|
/* both first and body? */
|
||||||
if( rPtr->margins.first-x <= 4 && rPtr->margins.first-x >= -5
|
if( rPtr->margins.first-x <= 4 && rPtr->margins.first-x >= -5
|
||||||
&& rPtr->margins.body-x <= 4 && rPtr->margins.body-x >= -5
|
&& rPtr->margins.body-x <= 4 && rPtr->margins.body-x >= -5
|
||||||
&& y>=15 && y<=17) {
|
&& y>=15 && y<=17) {
|
||||||
rPtr->motion = rPtr->margins.first;
|
rPtr->motion = rPtr->margins.first;
|
||||||
return 6;
|
return 6;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if(rPtr->margins.first-x <= 4 && y<=15
|
if(rPtr->margins.first-x <= 4 && y<=15
|
||||||
&& rPtr->margins.first-x >= -5 && y>=10) {
|
&& rPtr->margins.first-x >= -5 && y>=10) {
|
||||||
rPtr->motion = rPtr->margins.first;
|
rPtr->motion = rPtr->margins.first;
|
||||||
return 3;
|
return 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
if( rPtr->margins.body-x <= 4 && y<=21 &&
|
if( rPtr->margins.body-x <= 4 && y<=21 &&
|
||||||
rPtr->margins.body-x >= -5 && y>=17) {
|
rPtr->margins.body-x >= -5 && y>=17) {
|
||||||
rPtr->motion = rPtr->margins.body;
|
rPtr->motion = rPtr->margins.body;
|
||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* do tabs (5)*/
|
/* do tabs (5)*/
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
handleEvents(XEvent *event, void *data)
|
handleEvents(XEvent *event, void *data)
|
||||||
{
|
{
|
||||||
Ruler *rPtr = (Ruler*)data;
|
Ruler *rPtr = (Ruler*)data;
|
||||||
Display *dpy = event->xany.display;
|
Display *dpy = event->xany.display;
|
||||||
|
|
||||||
switch (event->type) {
|
switch (event->type) {
|
||||||
case Expose:
|
case Expose:
|
||||||
paintRuler(rPtr);
|
paintRuler(rPtr);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MotionNotify:
|
case MotionNotify:
|
||||||
if(rPtr->flags.buttonPressed
|
if(rPtr->flags.buttonPressed
|
||||||
&& (event->xmotion.state & Button1Mask)) {
|
&& (event->xmotion.state & Button1Mask)) {
|
||||||
if(verifyMarkerMove(rPtr, event->xmotion.x)){
|
if(verifyMarkerMove(rPtr, event->xmotion.x)){
|
||||||
GC gc = WMColorGC(WMDarkGrayColor(rPtr->view->screen));
|
GC gc = WMColorGC(WMDarkGrayColor(rPtr->view->screen));
|
||||||
paintRuler(rPtr);
|
paintRuler(rPtr);
|
||||||
if(rPtr->moveAction)
|
if(rPtr->moveAction)
|
||||||
(rPtr->moveAction)(rPtr, rPtr->clientData);
|
(rPtr->moveAction)(rPtr, rPtr->clientData);
|
||||||
XSetLineAttributes(rPtr->view->screen->display, gc, 1,
|
XSetLineAttributes(rPtr->view->screen->display, gc, 1,
|
||||||
LineSolid, CapNotLast, JoinMiter);
|
LineSolid, CapNotLast, JoinMiter);
|
||||||
XDrawLine(rPtr->pview->screen->display,
|
XDrawLine(rPtr->pview->screen->display,
|
||||||
rPtr->pview->window,
|
rPtr->pview->window,
|
||||||
gc, rPtr->motion+1, 40,
|
gc, rPtr->motion+1, 40,
|
||||||
rPtr->motion+1, rPtr->pview->size.height-5);
|
rPtr->motion+1, rPtr->pview->size.height-5);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ButtonPress:
|
case ButtonPress:
|
||||||
if(event->xbutton.button != Button1)
|
if(event->xbutton.button != Button1)
|
||||||
return;
|
return;
|
||||||
rPtr->flags.buttonPressed = True;
|
rPtr->flags.buttonPressed = True;
|
||||||
rPtr->flags.whichMarker =
|
rPtr->flags.whichMarker =
|
||||||
whichMarker(rPtr, event->xmotion.x,
|
whichMarker(rPtr, event->xmotion.x,
|
||||||
event->xmotion.y);
|
event->xmotion.y);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ButtonRelease:
|
case ButtonRelease:
|
||||||
if(event->xbutton.button != Button1)
|
if(event->xbutton.button != Button1)
|
||||||
return;
|
return;
|
||||||
rPtr->flags.buttonPressed = False;
|
rPtr->flags.buttonPressed = False;
|
||||||
switch(rPtr->flags.whichMarker) {
|
switch(rPtr->flags.whichMarker) {
|
||||||
case 1: {
|
case 1: {
|
||||||
int change = rPtr->margins.left-rPtr->motion;
|
int change = rPtr->margins.left-rPtr->motion;
|
||||||
rPtr->margins.first -=change;
|
rPtr->margins.first -=change;
|
||||||
rPtr->margins.body -= change;
|
rPtr->margins.body -= change;
|
||||||
rPtr->margins.left = rPtr->motion;
|
rPtr->margins.left = rPtr->motion;
|
||||||
paintRuler(rPtr); break;
|
paintRuler(rPtr); break;
|
||||||
}
|
}
|
||||||
case 2: rPtr->margins.right = rPtr->motion; break;
|
case 2: rPtr->margins.right = rPtr->motion; break;
|
||||||
case 3: rPtr->margins.first = rPtr->motion; break;
|
case 3: rPtr->margins.first = rPtr->motion; break;
|
||||||
case 4: rPtr->margins.body = rPtr->motion; break;
|
case 4: rPtr->margins.body = rPtr->motion; break;
|
||||||
case 6: rPtr->margins.first = rPtr->margins.body
|
case 6: rPtr->margins.first = rPtr->margins.body
|
||||||
= rPtr->motion; break;
|
= rPtr->motion; break;
|
||||||
}
|
}
|
||||||
if(rPtr->releaseAction)
|
if(rPtr->releaseAction)
|
||||||
(rPtr->releaseAction)(rPtr, rPtr->clientData);
|
(rPtr->releaseAction)(rPtr, rPtr->clientData);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -360,8 +360,8 @@ rulerDidResize(W_ViewDelegate *self, WMView *view)
|
|||||||
{
|
{
|
||||||
Ruler *rPtr = (Ruler *)view->self;
|
Ruler *rPtr = (Ruler *)view->self;
|
||||||
|
|
||||||
createDrawBuffer(rPtr);
|
createDrawBuffer(rPtr);
|
||||||
paintRuler(rPtr);
|
paintRuler(rPtr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -379,48 +379,48 @@ W_ViewDelegate _RulerViewDelegate =
|
|||||||
WMRuler *
|
WMRuler *
|
||||||
WMCreateRuler(WMWidget *parent)
|
WMCreateRuler(WMWidget *parent)
|
||||||
{
|
{
|
||||||
Ruler *rPtr = wmalloc(sizeof(Ruler));
|
Ruler *rPtr = wmalloc(sizeof(Ruler));
|
||||||
unsigned int w = WMWidgetWidth(parent);
|
unsigned int w = WMWidgetWidth(parent);
|
||||||
|
|
||||||
memset(rPtr, 0, sizeof(Ruler));
|
memset(rPtr, 0, sizeof(Ruler));
|
||||||
|
|
||||||
rPtr->widgetClass = WC_Ruler;
|
rPtr->widgetClass = WC_Ruler;
|
||||||
|
|
||||||
rPtr->view = W_CreateView(W_VIEW(parent));
|
rPtr->view = W_CreateView(W_VIEW(parent));
|
||||||
if (!rPtr->view) {
|
if (!rPtr->view) {
|
||||||
free(rPtr);
|
free(rPtr);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
rPtr->view->self = rPtr;
|
rPtr->view->self = rPtr;
|
||||||
|
|
||||||
rPtr->drawBuffer = (Pixmap) NULL;
|
rPtr->drawBuffer = (Pixmap) NULL;
|
||||||
|
|
||||||
W_ResizeView(rPtr->view, w, 40);
|
W_ResizeView(rPtr->view, w, 40);
|
||||||
|
|
||||||
WMCreateEventHandler(rPtr->view, ExposureMask|StructureNotifyMask
|
WMCreateEventHandler(rPtr->view, ExposureMask|StructureNotifyMask
|
||||||
|EnterWindowMask|LeaveWindowMask|FocusChangeMask
|
|EnterWindowMask|LeaveWindowMask|FocusChangeMask
|
||||||
|ButtonReleaseMask|ButtonPressMask|KeyReleaseMask
|
|ButtonReleaseMask|ButtonPressMask|KeyReleaseMask
|
||||||
|KeyPressMask|Button1MotionMask, handleEvents, rPtr);
|
|KeyPressMask|Button1MotionMask, handleEvents, rPtr);
|
||||||
|
|
||||||
rPtr->view->delegate = &_RulerViewDelegate;
|
rPtr->view->delegate = &_RulerViewDelegate;
|
||||||
|
|
||||||
rPtr->bg = WMColorGC(WMGrayColor(rPtr->view->screen));
|
rPtr->bg = WMColorGC(WMGrayColor(rPtr->view->screen));
|
||||||
rPtr->fg = WMColorGC(WMBlackColor(rPtr->view->screen));
|
rPtr->fg = WMColorGC(WMBlackColor(rPtr->view->screen));
|
||||||
rPtr->font = WMSystemFontOfSize(rPtr->view->screen, 8);
|
rPtr->font = WMSystemFontOfSize(rPtr->view->screen, 8);
|
||||||
|
|
||||||
rPtr->offset = 22;
|
rPtr->offset = 22;
|
||||||
rPtr->margins.left = 22;
|
rPtr->margins.left = 22;
|
||||||
rPtr->margins.body = 22;
|
rPtr->margins.body = 22;
|
||||||
rPtr->margins.first = 42;
|
rPtr->margins.first = 42;
|
||||||
rPtr->margins.right = (w<502?w:502);
|
rPtr->margins.right = (w<502?w:502);
|
||||||
|
|
||||||
rPtr->flags.whichMarker = 0; /* none */
|
rPtr->flags.whichMarker = 0; /* none */
|
||||||
rPtr->flags.buttonPressed = False;
|
rPtr->flags.buttonPressed = False;
|
||||||
|
|
||||||
rPtr->moveAction = NULL;
|
rPtr->moveAction = NULL;
|
||||||
rPtr->releaseAction = NULL;
|
rPtr->releaseAction = NULL;
|
||||||
|
|
||||||
rPtr->pview = W_VIEW(parent);
|
rPtr->pview = W_VIEW(parent);
|
||||||
|
|
||||||
return rPtr;
|
return rPtr;
|
||||||
}
|
}
|
||||||
@@ -429,56 +429,56 @@ WMCreateRuler(WMWidget *parent)
|
|||||||
void
|
void
|
||||||
WMSetRulerMargins(WMRuler *rPtr, WMRulerMargins margins)
|
WMSetRulerMargins(WMRuler *rPtr, WMRulerMargins margins)
|
||||||
{
|
{
|
||||||
if(!rPtr)
|
if(!rPtr)
|
||||||
return;
|
return;
|
||||||
rPtr->margins.left = margins.left + rPtr->offset;
|
rPtr->margins.left = margins.left + rPtr->offset;
|
||||||
rPtr->margins.right = margins.right + rPtr->offset;
|
rPtr->margins.right = margins.right + rPtr->offset;
|
||||||
rPtr->margins.first = margins.first + rPtr->offset;
|
rPtr->margins.first = margins.first + rPtr->offset;
|
||||||
rPtr->margins.body = margins.body + rPtr->offset;
|
rPtr->margins.body = margins.body + rPtr->offset;
|
||||||
rPtr->margins.tabs = margins.tabs; //for loop
|
rPtr->margins.tabs = margins.tabs; //for loop
|
||||||
paintRuler(rPtr);
|
paintRuler(rPtr);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
WMRulerMargins
|
WMRulerMargins
|
||||||
WMGetRulerMargins(WMRuler *rPtr)
|
WMGetRulerMargins(WMRuler *rPtr)
|
||||||
{
|
{
|
||||||
WMRulerMargins margins;
|
WMRulerMargins margins;
|
||||||
if(!rPtr)
|
if(!rPtr)
|
||||||
return margins;
|
return margins;
|
||||||
|
|
||||||
margins.left = rPtr->margins.left - rPtr->offset;
|
margins.left = rPtr->margins.left - rPtr->offset;
|
||||||
margins.right = rPtr->margins.right - rPtr->offset;
|
margins.right = rPtr->margins.right - rPtr->offset;
|
||||||
margins.first = rPtr->margins.first - rPtr->offset;
|
margins.first = rPtr->margins.first - rPtr->offset;
|
||||||
margins.body = rPtr->margins.body - rPtr->offset;
|
margins.body = rPtr->margins.body - rPtr->offset;
|
||||||
//for
|
//for
|
||||||
margins.tabs = rPtr->margins.tabs;
|
margins.tabs = rPtr->margins.tabs;
|
||||||
|
|
||||||
return rPtr->margins;
|
return rPtr->margins;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
WMSetRulerOffset(WMRuler *rPtr, int pixels)
|
WMSetRulerOffset(WMRuler *rPtr, int pixels)
|
||||||
{
|
{
|
||||||
if(!rPtr || pixels<0 || pixels+MIN_DOC_WIDTH>=rPtr->view->size.width)
|
if(!rPtr || pixels<0 || pixels+MIN_DOC_WIDTH>=rPtr->view->size.width)
|
||||||
return;
|
return;
|
||||||
rPtr->offset = pixels;
|
rPtr->offset = pixels;
|
||||||
//rulerDidResize(rPtr, rPtr->view);
|
//rulerDidResize(rPtr, rPtr->view);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
WMGetRulerOffset(WMRuler *rPtr)
|
WMGetRulerOffset(WMRuler *rPtr)
|
||||||
{
|
{
|
||||||
if(!rPtr)
|
if(!rPtr)
|
||||||
return;
|
return;
|
||||||
return rPtr->offset;
|
return rPtr->offset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
WMSetRulerReleaseAction(WMRuler *rPtr, WMAction *action, void *clientData)
|
WMSetRulerReleaseAction(WMRuler *rPtr, WMAction *action, void *clientData)
|
||||||
{
|
{
|
||||||
if(!rPtr)
|
if(!rPtr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
rPtr->releaseAction = action;
|
rPtr->releaseAction = action;
|
||||||
rPtr->clientData = clientData;
|
rPtr->clientData = clientData;
|
||||||
@@ -487,8 +487,8 @@ WMSetRulerReleaseAction(WMRuler *rPtr, WMAction *action, void *clientData)
|
|||||||
void
|
void
|
||||||
WMSetRulerMoveAction(WMRuler *rPtr, WMAction *action, void *clientData)
|
WMSetRulerMoveAction(WMRuler *rPtr, WMAction *action, void *clientData)
|
||||||
{
|
{
|
||||||
if(!rPtr)
|
if(!rPtr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
rPtr->moveAction = action;
|
rPtr->moveAction = action;
|
||||||
rPtr->clientData = clientData;
|
rPtr->clientData = clientData;
|
||||||
@@ -498,16 +498,16 @@ WMSetRulerMoveAction(WMRuler *rPtr, WMAction *action, void *clientData)
|
|||||||
int
|
int
|
||||||
WMGetReleasedRulerMargin(WMRuler *rPtr)
|
WMGetReleasedRulerMargin(WMRuler *rPtr)
|
||||||
{
|
{
|
||||||
if(!rPtr)
|
if(!rPtr)
|
||||||
return 0;
|
return 0;
|
||||||
return rPtr->flags.whichMarker;
|
return rPtr->flags.whichMarker;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* _which_ one is being grabbed */
|
/* _which_ one is being grabbed */
|
||||||
int
|
int
|
||||||
WMGetGrabbedRulerMargin(WMRuler *rPtr)
|
WMGetGrabbedRulerMargin(WMRuler *rPtr)
|
||||||
{
|
{
|
||||||
if(!rPtr)
|
if(!rPtr)
|
||||||
return 0;
|
return 0;
|
||||||
return rPtr->flags.whichMarker;
|
return rPtr->flags.whichMarker;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,47 +0,0 @@
|
|||||||
|
|
||||||
#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