mirror of
https://github.com/gryf/wmaker.git
synced 2025-12-19 12:28:22 +01:00
Revert "WINGs: Remove wruler and wtext"
This reverts commit f4890b17e6.
It turns out that I needed some functions from wtext.c to develop
a WINGs front-end to my comic book collection MySQL database.
Conflicts:
WINGs/Makefile.am
WINGs/WINGs/WINGs.h
This commit is contained in:
@@ -50,11 +50,13 @@ libWINGs_la_SOURCES = \
|
|||||||
wpanel.c \
|
wpanel.c \
|
||||||
wpixmap.c \
|
wpixmap.c \
|
||||||
wpopupbutton.c \
|
wpopupbutton.c \
|
||||||
|
wruler.c \
|
||||||
wscroller.c \
|
wscroller.c \
|
||||||
wscrollview.c \
|
wscrollview.c \
|
||||||
wslider.c \
|
wslider.c \
|
||||||
wsplitview.c \
|
wsplitview.c \
|
||||||
wtabview.c \
|
wtabview.c \
|
||||||
|
wtext.c \
|
||||||
wtextfield.c \
|
wtextfield.c \
|
||||||
wview.c \
|
wview.c \
|
||||||
wwindow.c
|
wwindow.c
|
||||||
|
|||||||
@@ -287,24 +287,26 @@ enum {
|
|||||||
typedef int W_Class;
|
typedef int W_Class;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
WC_Window,
|
WC_Window = 0,
|
||||||
WC_Frame,
|
WC_Frame = 1,
|
||||||
WC_Label,
|
WC_Label = 2,
|
||||||
WC_Button,
|
WC_Button = 3,
|
||||||
WC_TextField,
|
WC_TextField = 4,
|
||||||
WC_Scroller,
|
WC_Scroller = 5,
|
||||||
WC_ScrollView,
|
WC_ScrollView = 6,
|
||||||
WC_List,
|
WC_List = 7,
|
||||||
WC_Browser,
|
WC_Browser = 8,
|
||||||
WC_PopUpButton,
|
WC_PopUpButton = 9,
|
||||||
WC_ColorWell,
|
WC_ColorWell = 10,
|
||||||
WC_Slider,
|
WC_Slider = 11,
|
||||||
WC_SplitView,
|
WC_Matrix = 12, /* not ready */
|
||||||
WC_TabView,
|
WC_SplitView = 13,
|
||||||
WC_ProgressIndicator,
|
WC_TabView = 14,
|
||||||
WC_MenuView,
|
WC_ProgressIndicator = 15,
|
||||||
WC_Text,
|
WC_MenuView = 16,
|
||||||
WC_Box
|
WC_Ruler = 17,
|
||||||
|
WC_Text = 18,
|
||||||
|
WC_Box = 19
|
||||||
};
|
};
|
||||||
|
|
||||||
/* All widgets must start with the following structure
|
/* All widgets must start with the following structure
|
||||||
@@ -348,6 +350,7 @@ typedef struct W_Slider WMSlider;
|
|||||||
typedef struct W_Matrix WMMatrix; /* not ready */
|
typedef struct W_Matrix WMMatrix; /* not ready */
|
||||||
typedef struct W_SplitView WMSplitView;
|
typedef struct W_SplitView WMSplitView;
|
||||||
typedef struct W_TabView WMTabView;
|
typedef struct W_TabView WMTabView;
|
||||||
|
typedef struct W_Ruler WMRuler;
|
||||||
typedef struct W_Text WMText;
|
typedef struct W_Text WMText;
|
||||||
typedef struct W_Box WMBox;
|
typedef struct W_Box WMBox;
|
||||||
|
|
||||||
@@ -433,6 +436,18 @@ typedef enum WMFontStyle {
|
|||||||
} WMFontStyle;
|
} WMFontStyle;
|
||||||
|
|
||||||
|
|
||||||
|
/* WMRuler: */
|
||||||
|
typedef struct {
|
||||||
|
WMArray *tabs; /* a growable array of tabstops */
|
||||||
|
unsigned short left; /* left margin marker */
|
||||||
|
unsigned short right; /* right margin marker */
|
||||||
|
unsigned short first; /* indentation marker for first line only */
|
||||||
|
unsigned short body; /* body indentation marker */
|
||||||
|
unsigned short retainCount;
|
||||||
|
} WMRulerMargins;
|
||||||
|
/* All indentation and tab markers are _relative_ to the left margin marker */
|
||||||
|
|
||||||
|
|
||||||
typedef void WMEventProc(XEvent *event, void *clientData);
|
typedef void WMEventProc(XEvent *event, void *clientData);
|
||||||
|
|
||||||
typedef void WMEventHook(XEvent *event);
|
typedef void WMEventHook(XEvent *event);
|
||||||
@@ -1509,8 +1524,168 @@ void WMSetSplitViewResizeSubviewsProc(WMSplitView *sPtr,
|
|||||||
|
|
||||||
int WMGetSplitViewDividerThickness(WMSplitView *sPtr);
|
int WMGetSplitViewDividerThickness(WMSplitView *sPtr);
|
||||||
|
|
||||||
/* ---[ WINGs/wtabview.c ]------------------------------------------------ */
|
/* ...................................................................... */
|
||||||
|
|
||||||
|
WMRuler* WMCreateRuler (WMWidget *parent);
|
||||||
|
|
||||||
|
WMRulerMargins* WMGetRulerMargins(WMRuler *rPtr);
|
||||||
|
|
||||||
|
void WMSetRulerMargins(WMRuler *rPtr, WMRulerMargins margins);
|
||||||
|
|
||||||
|
Bool WMIsMarginEqualToMargin(WMRulerMargins *aMargin, WMRulerMargins *anotherMargin);
|
||||||
|
|
||||||
|
int WMGetGrabbedRulerMargin(WMRuler *rPtr);
|
||||||
|
|
||||||
|
int WMGetReleasedRulerMargin(WMRuler *rPtr);
|
||||||
|
|
||||||
|
int WMGetRulerOffset(WMRuler *rPtr);
|
||||||
|
|
||||||
|
void WMSetRulerOffset(WMRuler *rPtr, int pixels);
|
||||||
|
|
||||||
|
void WMSetRulerMoveAction(WMRuler *rPtr, WMAction *action, void *clientData);
|
||||||
|
|
||||||
|
void WMSetRulerReleaseAction(WMRuler *rPtr, WMAction *action, void *clientData);
|
||||||
|
|
||||||
|
/* ....................................................................... */
|
||||||
|
|
||||||
|
|
||||||
|
#define WMCreateText(parent) WMCreateTextForDocumentType \
|
||||||
|
((parent), (NULL), (NULL))
|
||||||
|
|
||||||
|
WMText* WMCreateTextForDocumentType(WMWidget *parent, WMAction *parser,
|
||||||
|
WMAction *writer);
|
||||||
|
|
||||||
|
void WMSetTextDelegate(WMText *tPtr, WMTextDelegate *delegate);
|
||||||
|
|
||||||
|
void WMFreezeText(WMText *tPtr);
|
||||||
|
|
||||||
|
#define WMRefreshText(tPtr) WMThawText((tPtr))
|
||||||
|
|
||||||
|
void WMThawText(WMText *tPtr);
|
||||||
|
|
||||||
|
int WMScrollText(WMText *tPtr, int amount);
|
||||||
|
|
||||||
|
int WMPageText(WMText *tPtr, Bool direction);
|
||||||
|
|
||||||
|
void WMSetTextHasHorizontalScroller(WMText *tPtr, Bool shouldhave);
|
||||||
|
|
||||||
|
void WMSetTextHasVerticalScroller(WMText *tPtr, Bool shouldhave);
|
||||||
|
|
||||||
|
void WMSetTextHasRuler(WMText *tPtr, Bool shouldhave);
|
||||||
|
|
||||||
|
void WMShowTextRuler(WMText *tPtr, Bool show);
|
||||||
|
|
||||||
|
int WMGetTextRulerShown(WMText *tPtr);
|
||||||
|
|
||||||
|
void WMSetTextEditable(WMText *tPtr, Bool editable);
|
||||||
|
|
||||||
|
int WMGetTextEditable(WMText *tPtr);
|
||||||
|
|
||||||
|
void WMSetTextUsesMonoFont(WMText *tPtr, Bool mono);
|
||||||
|
|
||||||
|
int WMGetTextUsesMonoFont(WMText *tPtr);
|
||||||
|
|
||||||
|
void WMSetTextIndentNewLines(WMText *tPtr, Bool indent);
|
||||||
|
|
||||||
|
void WMSetTextIgnoresNewline(WMText *tPtr, Bool ignore);
|
||||||
|
|
||||||
|
int WMGetTextIgnoresNewline(WMText *tPtr);
|
||||||
|
|
||||||
|
void WMSetTextDefaultFont(WMText *tPtr, WMFont *font);
|
||||||
|
|
||||||
|
WMFont* WMGetTextDefaultFont(WMText *tPtr);
|
||||||
|
|
||||||
|
void WMSetTextDefaultColor(WMText *tPtr, WMColor *color);
|
||||||
|
|
||||||
|
WMColor* WMGetTextDefaultColor(WMText *tPtr);
|
||||||
|
|
||||||
|
void WMSetTextRelief(WMText *tPtr, WMReliefType relief);
|
||||||
|
|
||||||
|
void WMSetTextForegroundColor(WMText *tPtr, WMColor *color);
|
||||||
|
|
||||||
|
void WMSetTextBackgroundColor(WMText *tPtr, WMColor *color);
|
||||||
|
|
||||||
|
void WMSetTextBackgroundPixmap(WMText *tPtr, WMPixmap *pixmap);
|
||||||
|
|
||||||
|
void WMPrependTextStream(WMText *tPtr, char *text);
|
||||||
|
|
||||||
|
void WMAppendTextStream(WMText *tPtr, char *text);
|
||||||
|
|
||||||
|
#define WMClearText(tPtr) WMAppendTextStream \
|
||||||
|
((tPtr), (NULL))
|
||||||
|
|
||||||
|
/* free the text */
|
||||||
|
char* WMGetTextStream(WMText *tPtr);
|
||||||
|
|
||||||
|
/* free the text */
|
||||||
|
char* WMGetTextSelectedStream(WMText *tPtr);
|
||||||
|
|
||||||
|
/* destroy the array */
|
||||||
|
WMArray* WMGetTextObjects(WMText *tPtr);
|
||||||
|
|
||||||
|
/* destroy the array */
|
||||||
|
WMArray* WMGetTextSelectedObjects(WMText *tPtr);
|
||||||
|
|
||||||
|
void WMSetTextSelectionColor(WMText *tPtr, WMColor *color);
|
||||||
|
|
||||||
|
WMColor* WMGetTextSelectionColor(WMText *tPtr);
|
||||||
|
|
||||||
|
void WMSetTextSelectionFont(WMText *tPtr, WMFont *font);
|
||||||
|
|
||||||
|
WMFont* WMGetTextSelectionFont(WMText *tPtr);
|
||||||
|
|
||||||
|
void WMSetTextSelectionUnderlined(WMText *tPtr, int underlined);
|
||||||
|
|
||||||
|
int WMGetTextSelectionUnderlined(WMText *tPtr);
|
||||||
|
|
||||||
|
void WMSetTextAlignment(WMText *tPtr, WMAlignment alignment);
|
||||||
|
|
||||||
|
Bool WMFindInTextStream(WMText *tPtr, char *needle, Bool direction,
|
||||||
|
Bool caseSensitive);
|
||||||
|
|
||||||
|
Bool WMReplaceTextSelection(WMText *tPtr, char *replacement);
|
||||||
|
|
||||||
|
|
||||||
|
/* parser related stuff... use only if implementing a new parser */
|
||||||
|
|
||||||
|
void* WMCreateTextBlockWithObject(WMText *tPtr, WMWidget *w, char *description,
|
||||||
|
WMColor *color, unsigned short first,
|
||||||
|
unsigned short extraInfo);
|
||||||
|
|
||||||
|
void* WMCreateTextBlockWithPixmap(WMText *tPtr, WMPixmap *p, char *description,
|
||||||
|
WMColor *color, unsigned short first,
|
||||||
|
unsigned short extraInfo);
|
||||||
|
|
||||||
|
void* WMCreateTextBlockWithText(WMText *tPtr, char *text, WMFont *font,
|
||||||
|
WMColor *color, unsigned short first,
|
||||||
|
unsigned short length);
|
||||||
|
|
||||||
|
void WMSetTextBlockProperties(WMText *tPtr, void *vtb, unsigned int first,
|
||||||
|
unsigned int kanji, unsigned int underlined,
|
||||||
|
int script, WMRulerMargins *margins);
|
||||||
|
|
||||||
|
/* do NOT free the margins */
|
||||||
|
void WMGetTextBlockProperties(WMText *tPtr, void *vtb, unsigned int *first,
|
||||||
|
unsigned int *kanji, unsigned int *underlined,
|
||||||
|
int *script, WMRulerMargins *margins);
|
||||||
|
|
||||||
|
int WMGetTextInsertType(WMText *tPtr);
|
||||||
|
|
||||||
|
/*int WMGetTextBlocks(WMText *tPtr);
|
||||||
|
|
||||||
|
void WMSetCurrentTextBlock(WMText *tPtr, int current);
|
||||||
|
|
||||||
|
int WMGetCurrentTextBlock(WMText *tPtr);*/
|
||||||
|
|
||||||
|
void WMPrependTextBlock(WMText *tPtr, void *vtb);
|
||||||
|
|
||||||
|
void WMAppendTextBlock(WMText *tPtr, void *vtb);
|
||||||
|
|
||||||
|
void* WMRemoveTextBlock(WMText *tPtr);
|
||||||
|
|
||||||
|
void WMDestroyTextBlock(WMText *tPtr, void *vtb);
|
||||||
|
|
||||||
|
/* ---[ WINGs/wtabview.c ]------------------------------------------------ */
|
||||||
|
|
||||||
WMTabView* WMCreateTabView(WMWidget *parent);
|
WMTabView* WMCreateTabView(WMWidget *parent);
|
||||||
|
|
||||||
|
|||||||
532
WINGs/wruler.c
Normal file
532
WINGs/wruler.c
Normal file
@@ -0,0 +1,532 @@
|
|||||||
|
/*
|
||||||
|
* WINGs WMRuler: nifty ruler widget for WINGs :-)
|
||||||
|
*
|
||||||
|
* Copyright (c) 1999-2000 Nwanua Elumeze
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program; if not, write to the Free Software
|
||||||
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "WINGsP.h"
|
||||||
|
#include "wconfig.h"
|
||||||
|
|
||||||
|
#define MIN_DOC_WIDTH 10
|
||||||
|
|
||||||
|
typedef struct W_Ruler {
|
||||||
|
W_Class widgetClass;
|
||||||
|
W_View *view;
|
||||||
|
W_View *pview; /* the parent's view (for drawing the line) */
|
||||||
|
|
||||||
|
WMAction *moveAction; /* what to when while moving */
|
||||||
|
WMAction *releaseAction; /* what to do when released */
|
||||||
|
void *clientData;
|
||||||
|
|
||||||
|
WMColor *fg;
|
||||||
|
GC fgGC, bgGC;
|
||||||
|
WMFont *font;
|
||||||
|
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) */
|
||||||
|
|
||||||
|
Pixmap drawBuffer;
|
||||||
|
|
||||||
|
struct {
|
||||||
|
unsigned int whichMarker:3;
|
||||||
|
/* 0, 1, 2, 3, 4, 5, 6 */
|
||||||
|
/* none, left, right, first, body, tabstop, first & body */
|
||||||
|
|
||||||
|
unsigned int buttonPressed:1;
|
||||||
|
unsigned int redraw:1;
|
||||||
|
unsigned int RESERVED:27;
|
||||||
|
} flags;
|
||||||
|
} Ruler;
|
||||||
|
|
||||||
|
/* 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->fgGC, 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->fgGC,
|
||||||
|
points, 4, Convex, CoordModeOrigin);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Marker for right margin
|
||||||
|
|
||||||
|
/|
|
||||||
|
/ |
|
||||||
|
/__|
|
||||||
|
|
|
||||||
|
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
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->fgGC, xpos, 8, xpos, 22);
|
||||||
|
points[0].x = xpos + 1;
|
||||||
|
points[0].y = 0;
|
||||||
|
points[1].x = points[0].x - 6;
|
||||||
|
points[1].y = 7;
|
||||||
|
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->fgGC,
|
||||||
|
points, 4, Convex, CoordModeOrigin);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Marker for first line only
|
||||||
|
_____
|
||||||
|
|___|
|
||||||
|
|
|
||||||
|
|
||||||
|
*/
|
||||||
|
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->fgGC, xpos - 5, 10, 11, 5);
|
||||||
|
XDrawLine(rPtr->view->screen->display, rPtr->drawBuffer, rPtr->fgGC, xpos, 12, xpos, 22);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Marker for rest of body
|
||||||
|
_____
|
||||||
|
\ /
|
||||||
|
\./
|
||||||
|
*/
|
||||||
|
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 = 16;
|
||||||
|
points[1].x = points[0].x + 11;
|
||||||
|
points[1].y = 16;
|
||||||
|
points[2].x = points[0].x + 5;
|
||||||
|
points[2].y = 22;
|
||||||
|
XFillPolygon(rPtr->view->screen->display, rPtr->drawBuffer, rPtr->fgGC,
|
||||||
|
points, 3, Convex, CoordModeOrigin);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void createDrawBuffer(Ruler * rPtr)
|
||||||
|
{
|
||||||
|
if (!rPtr->view->flags.realized)
|
||||||
|
return;
|
||||||
|
|
||||||
|
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->bgGC, 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 || !rPtr->view->flags.realized)
|
||||||
|
return;
|
||||||
|
|
||||||
|
XFillRectangle(rPtr->view->screen->display, rPtr->drawBuffer,
|
||||||
|
rPtr->bgGC, 0, 0, rPtr->view->size.width, 40);
|
||||||
|
|
||||||
|
WMDrawString(rPtr->view->screen, rPtr->drawBuffer, rPtr->fg,
|
||||||
|
rPtr->font, rPtr->margins.left + 2, 26, _("0 inches"), 10);
|
||||||
|
|
||||||
|
/* 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->fgGC, 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->fgGC,
|
||||||
|
rPtr->margins.left, 22, rPtr->margins.left + m - 10, 22);
|
||||||
|
|
||||||
|
drawLeftMarker(rPtr);
|
||||||
|
drawRightMarker(rPtr);
|
||||||
|
drawFirstMarker(rPtr);
|
||||||
|
drawBodyMarker(rPtr);
|
||||||
|
|
||||||
|
rPtr->flags.redraw = False;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void paintRuler(Ruler * rPtr)
|
||||||
|
{
|
||||||
|
if (!rPtr->drawBuffer || !rPtr->view->flags.realized)
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (rPtr->flags.redraw)
|
||||||
|
drawRulerOnPixmap(rPtr);
|
||||||
|
XCopyArea(rPtr->view->screen->display, rPtr->drawBuffer,
|
||||||
|
rPtr->view->window, rPtr->bgGC, 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 || x < rPtr->offset ||
|
||||||
|
rPtr->margins.body + x > rPtr->margins.right - MIN_DOC_WIDTH ||
|
||||||
|
rPtr->margins.first + x > rPtr->margins.right - MIN_DOC_WIDTH)
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
if (x < rPtr->offset || y > 22)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
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 >= 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;
|
||||||
|
}
|
||||||
|
/* do tabs (5) */
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static void rulerDidResize(W_ViewDelegate * self, WMView * view)
|
||||||
|
{
|
||||||
|
Ruler *rPtr = (Ruler *) view->self;
|
||||||
|
|
||||||
|
createDrawBuffer(rPtr);
|
||||||
|
rPtr->flags.redraw = True;
|
||||||
|
paintRuler(rPtr);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
static void handleEvents(XEvent * event, void *data)
|
||||||
|
{
|
||||||
|
Ruler *rPtr = (Ruler *) data;
|
||||||
|
|
||||||
|
switch (event->type) {
|
||||||
|
case Expose:
|
||||||
|
rulerDidResize(rPtr->view->delegate, rPtr->view);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case MotionNotify:
|
||||||
|
if (rPtr->flags.buttonPressed && (event->xmotion.state & Button1Mask)) {
|
||||||
|
if (verifyMarkerMove(rPtr, event->xmotion.x)) {
|
||||||
|
GC gc = WMColorGC(WMDarkGrayColor(rPtr->view->screen));
|
||||||
|
|
||||||
|
if (rPtr->moveAction)
|
||||||
|
(rPtr->moveAction) (rPtr, rPtr->clientData);
|
||||||
|
rPtr->flags.redraw = True;
|
||||||
|
paintRuler(rPtr);
|
||||||
|
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->flags.whichMarker = whichMarker(rPtr, event->xmotion.x, event->xmotion.y);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case ButtonRelease:
|
||||||
|
if (event->xbutton.button != Button1)
|
||||||
|
return;
|
||||||
|
rPtr->flags.buttonPressed = False;
|
||||||
|
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;
|
||||||
|
rPtr->flags.redraw = True;
|
||||||
|
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->releaseAction)
|
||||||
|
(rPtr->releaseAction) (rPtr, rPtr->clientData);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
W_ViewDelegate _RulerViewDelegate = {
|
||||||
|
NULL,
|
||||||
|
NULL,
|
||||||
|
rulerDidResize,
|
||||||
|
NULL,
|
||||||
|
NULL
|
||||||
|
};
|
||||||
|
|
||||||
|
WMRuler *WMCreateRuler(WMWidget * parent)
|
||||||
|
{
|
||||||
|
Ruler *rPtr = wmalloc(sizeof(Ruler));
|
||||||
|
unsigned int w = WMWidgetWidth(parent);
|
||||||
|
|
||||||
|
rPtr->widgetClass = WC_Ruler;
|
||||||
|
|
||||||
|
rPtr->view = W_CreateView(W_VIEW(parent));
|
||||||
|
|
||||||
|
if (!rPtr->view) {
|
||||||
|
wfree(rPtr);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
rPtr->view->self = rPtr;
|
||||||
|
|
||||||
|
rPtr->drawBuffer = (Pixmap) NULL;
|
||||||
|
|
||||||
|
W_ResizeView(rPtr->view, w, 40);
|
||||||
|
|
||||||
|
WMCreateEventHandler(rPtr->view, ExposureMask | StructureNotifyMask
|
||||||
|
| EnterWindowMask | LeaveWindowMask | FocusChangeMask
|
||||||
|
| ButtonReleaseMask | ButtonPressMask | KeyReleaseMask
|
||||||
|
| KeyPressMask | Button1MotionMask, handleEvents, rPtr);
|
||||||
|
|
||||||
|
rPtr->view->delegate = &_RulerViewDelegate;
|
||||||
|
|
||||||
|
rPtr->fg = WMBlackColor(rPtr->view->screen);
|
||||||
|
rPtr->fgGC = WMColorGC(rPtr->fg);
|
||||||
|
rPtr->bgGC = WMColorGC(WMGrayColor(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->margins.tabs = NULL;
|
||||||
|
|
||||||
|
rPtr->flags.whichMarker = 0; /* none */
|
||||||
|
rPtr->flags.buttonPressed = False;
|
||||||
|
rPtr->flags.redraw = True;
|
||||||
|
|
||||||
|
rPtr->moveAction = NULL;
|
||||||
|
rPtr->releaseAction = NULL;
|
||||||
|
|
||||||
|
rPtr->pview = W_VIEW(parent);
|
||||||
|
|
||||||
|
return rPtr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WMSetRulerMargins(WMRuler * rPtr, WMRulerMargins margins)
|
||||||
|
{
|
||||||
|
if (!rPtr)
|
||||||
|
return;
|
||||||
|
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 */
|
||||||
|
rPtr->flags.redraw = True;
|
||||||
|
paintRuler(rPtr);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
WMRulerMargins *WMGetRulerMargins(WMRuler * rPtr)
|
||||||
|
{
|
||||||
|
WMRulerMargins *margins = wmalloc(sizeof(WMRulerMargins));
|
||||||
|
|
||||||
|
if (!rPtr) {
|
||||||
|
margins->first = margins->body = margins->left = 0;
|
||||||
|
margins->right = 100;
|
||||||
|
return margins;
|
||||||
|
}
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
return margins;
|
||||||
|
}
|
||||||
|
|
||||||
|
Bool WMIsMarginEqualToMargin(WMRulerMargins * aMargin, WMRulerMargins * anotherMargin)
|
||||||
|
{
|
||||||
|
if (aMargin == anotherMargin)
|
||||||
|
return True;
|
||||||
|
else if (!aMargin || !anotherMargin)
|
||||||
|
return False;
|
||||||
|
if (aMargin->left != anotherMargin->left)
|
||||||
|
return False;
|
||||||
|
if (aMargin->first != anotherMargin->first)
|
||||||
|
return False;
|
||||||
|
if (aMargin->body != anotherMargin->body)
|
||||||
|
return False;
|
||||||
|
if (aMargin->right != anotherMargin->right)
|
||||||
|
return False;
|
||||||
|
|
||||||
|
return True;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WMSetRulerOffset(WMRuler * rPtr, int pixels)
|
||||||
|
{
|
||||||
|
if (!rPtr || pixels < 0 || pixels + MIN_DOC_WIDTH >= rPtr->view->size.width)
|
||||||
|
return;
|
||||||
|
rPtr->offset = pixels;
|
||||||
|
/*rulerDidResize(rPtr, rPtr->view); */
|
||||||
|
}
|
||||||
|
|
||||||
|
int WMGetRulerOffset(WMRuler * rPtr)
|
||||||
|
{
|
||||||
|
if (!rPtr)
|
||||||
|
return 0; /* what value should return if no ruler? -1 or 0? */
|
||||||
|
return rPtr->offset;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WMSetRulerReleaseAction(WMRuler * rPtr, WMAction * action, void *clientData)
|
||||||
|
{
|
||||||
|
if (!rPtr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
rPtr->releaseAction = action;
|
||||||
|
rPtr->clientData = clientData;
|
||||||
|
}
|
||||||
|
|
||||||
|
void WMSetRulerMoveAction(WMRuler * rPtr, WMAction * action, void *clientData)
|
||||||
|
{
|
||||||
|
if (!rPtr)
|
||||||
|
return;
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
3958
WINGs/wtext.c
Normal file
3958
WINGs/wtext.c
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user