From affcc3babd6a12cde0f4dbdb54bcc79e30c8b65d Mon Sep 17 00:00:00 2001 From: kojima Date: Tue, 20 Feb 2001 23:38:36 +0000 Subject: [PATCH] various fixes, scrollview scrollers, text painting --- WINGs/ChangeLog | 1 + WINGs/Extras/wtableview.c | 19 ++--- WINGs/Extras/wtableview.h | 3 + WINGs/Tests/wtest.c | 5 +- WINGs/WINGs/WINGs.h | 55 ++++++++---- WINGs/WINGs/WINGsP.h | 5 ++ WINGs/dragdestination.c | 6 ++ WINGs/wbox.c | 39 --------- WINGs/wmisc.c | 10 ++- WINGs/wpanel.c | 175 ++++++++++++++++++++++++++++++++++---- WINGs/wscrollview.c | 8 ++ WINGs/wview.c | 33 +++++++ 12 files changed, 272 insertions(+), 87 deletions(-) diff --git a/WINGs/ChangeLog b/WINGs/ChangeLog index 6b8f693c..47fba34c 100644 --- a/WINGs/ChangeLog +++ b/WINGs/ChangeLog @@ -2,6 +2,7 @@ Changes since wmaker 0.64.0: ............................ - made programmatic scroller changes send notifications +- replaced WMSetBoxExpandsToParent with WMSetViewExpands... changes since wmaker 0.63.1: ............................ diff --git a/WINGs/Extras/wtableview.c b/WINGs/Extras/wtableview.c index 594b925e..947a51f5 100644 --- a/WINGs/Extras/wtableview.c +++ b/WINGs/Extras/wtableview.c @@ -92,14 +92,14 @@ void WMSetTableColumnDelegate(WMTableColumn *column, void WMSetTableColumnConstraints(WMTableColumn *column, unsigned minWidth, unsigned maxWidth) { - wassertr(minWidth <= maxWidth); + wassertr(maxWidth == 0 || minWidth <= maxWidth); column->minWidth = minWidth; column->maxWidth = maxWidth; if (column->width < column->minWidth) WMSetTableColumnWidth(column, column->minWidth); - else if (column->width > column->maxWidth || column->maxWidth == 0) + else if (column->width > column->maxWidth && column->maxWidth != 0) WMSetTableColumnWidth(column, column->maxWidth); } @@ -238,17 +238,14 @@ static void splitterHandler(XEvent *event, void *data) switch (ev.type) { case MotionNotify: ox = cx; + if (column->width + ev.xmotion.x < column->minWidth) cx = pos.x + column->minWidth; + else if (column->maxWidth > 0 + && column->width + ev.xmotion.x > column->maxWidth) + cx = pos.x + column->maxWidth; else cx = offsX + ev.xmotion.x; - - if (column->maxWidth > 0) { - if (column->width + ev.xmotion.x > column->maxWidth) - cx = pos.x + column->maxWidth; - else - cx = offsX + ev.xmotion.x; - } XDrawLine(dpy, w, gc, ox+20, 0, ox+20, h); XDrawLine(dpy, w, gc, cx+20, 0, cx+20, h); @@ -256,13 +253,13 @@ static void splitterHandler(XEvent *event, void *data) case ButtonRelease: column->width = cx - pos.x; - rearrangeHeader(table); done = 1; break; } } - XDrawLine(dpy, w, gc, cx+20, 0, cx+20, h); + XDrawLine(dpy, w, gc, cx+20, 0, cx+20, h); + rearrangeHeader(table); } diff --git a/WINGs/Extras/wtableview.h b/WINGs/Extras/wtableview.h index 49d46d29..0c0a1033 100644 --- a/WINGs/Extras/wtableview.h +++ b/WINGs/Extras/wtableview.h @@ -45,6 +45,9 @@ typedef struct W_TableViewDelegate { WMTableColumn *WMCreateTableColumn(char *title); void WMSetTableColumnWidth(WMTableColumn *column, unsigned width); + +void WMSetTableColumnConstraints(WMTableColumn *column, + unsigned minWidth, unsigned maxWidth); void WMSetTableColumnDelegate(WMTableColumn *column, WMTableColumnDelegate *delegate); diff --git a/WINGs/Tests/wtest.c b/WINGs/Tests/wtest.c index b3df3e40..d5624f3a 100644 --- a/WINGs/Tests/wtest.c +++ b/WINGs/Tests/wtest.c @@ -1279,9 +1279,11 @@ main(int argc, char **argv) */ + + testDragAndDrop(scr); +#if 0 testScrollView(scr); testTabView(scr); -#if 0 testBox(scr); testText(scr); testList(scr); @@ -1292,7 +1294,6 @@ main(int argc, char **argv) testTextField(scr); - testDragAndDrop(scr); testDragAndDrop(scr); testFontPanel(scr); diff --git a/WINGs/WINGs/WINGs.h b/WINGs/WINGs/WINGs.h index 88a05ea5..f640b08c 100644 --- a/WINGs/WINGs/WINGs.h +++ b/WINGs/WINGs/WINGs.h @@ -393,12 +393,31 @@ typedef struct WMAlertPanel { WMFrame *line; /* separator */ short result; /* button that was pushed */ short done; - - KeyCode retKey; - KeyCode escKey; } WMAlertPanel; +typedef struct WMGenericPanel { + WMWindow *win; + WMBox *vbox; + + WMLabel *iLbl; + WMLabel *tLbl; + + WMFrame *line; + + WMFrame *content; + + WMBox *buttonBox; + WMButton *defBtn; + WMButton *altBtn; + + short result; + short done; +} WMGenericPanel; + + + + typedef struct WMInputPanel { WMWindow *win; /* window */ WMButton *defBtn; /* default button */ @@ -408,14 +427,9 @@ typedef struct WMInputPanel { WMTextField *text; /* text field */ short result; /* button that was pushed */ short done; - - KeyCode retKey; - KeyCode escKey; } WMInputPanel; - - /* WMRuler: */ typedef struct { WMArray *tabs; /* a growable array of tabstops */ @@ -720,17 +734,17 @@ WMFont *WMBoldSystemFontOfSize(WMScreen *scrPtr, int size); XFontSet WMGetFontFontSet(WMFont *font); -WMFont * WMNormalizeFont(WMScreen *scr, WMFont *font); +WMFont *WMNormalizeFont(WMScreen *scr, WMFont *font); -WMFont * WMStrengthenFont(WMScreen *scr, WMFont *font); +WMFont *WMStrengthenFont(WMScreen *scr, WMFont *font); -WMFont * WMUnstrengthenFont(WMScreen *scr, WMFont *font); +WMFont *WMUnstrengthenFont(WMScreen *scr, WMFont *font); -WMFont * WMEmphasizeFont(WMScreen *scr, WMFont *font); +WMFont *WMEmphasizeFont(WMScreen *scr, WMFont *font); -WMFont * WMUnemphasizeFont(WMScreen *scr, WMFont *font); +WMFont *WMUnemphasizeFont(WMScreen *scr, WMFont *font); -WMFont * WMGetFontOfSize(WMScreen *scr, WMFont *font, int size); +WMFont *WMGetFontOfSize(WMScreen *scr, WMFont *font, int size); /* ....................................................................... */ @@ -864,6 +878,9 @@ void WMRedisplayWidget(WMWidget *w); void WMSetViewNotifySizeChanges(WMView *view, Bool flag); +void WMSetViewExpandsToParent(WMView *view, int topOffs, int leftOffs, + int rightOffs, int bottomOffs); + WMSize WMGetViewSize(WMView *view); WMPoint WMGetViewPosition(WMView *view); @@ -1709,9 +1726,6 @@ void WMRemoveBoxSubview(WMBox *bPtr, WMView *view); void WMSetBoxHorizontal(WMBox *box, Bool flag); -void WMSetBoxExpandsToParent(WMBox *box, int topOffs, int bottomOffs, - int leftOffs, int rightOffs); - /* ....................................................................... */ int WMRunAlertPanel(WMScreen *app, WMWindow *owner, char *title, char *msg, @@ -1730,10 +1744,17 @@ WMInputPanel *WMCreateInputPanel(WMScreen *app, WMWindow *owner, char *title, char *msg, char *defaultText, char *okButton, char *cancelButton); + +WMGenericPanel *WMCreateGenericPanel(WMScreen *scrPtr, WMWindow *owner, + char *title, char *defaultButton, + char *alternateButton); + void WMDestroyAlertPanel(WMAlertPanel *panel); void WMDestroyInputPanel(WMInputPanel *panel); +void WMDestroyGenericPanel(WMGenericPanel *panel); + /* ....................................................................... */ /* only 1 instance per WMScreen */ diff --git a/WINGs/WINGs/WINGsP.h b/WINGs/WINGs/WINGsP.h index 4a1a67cb..24caa833 100644 --- a/WINGs/WINGs/WINGsP.h +++ b/WINGs/WINGs/WINGsP.h @@ -318,6 +318,11 @@ typedef struct W_View { Window window; WMSize size; + + short topOffs; + short leftOffs; + short bottomOffs; + short rightOffs; WMPoint pos; diff --git a/WINGs/dragdestination.c b/WINGs/dragdestination.c index 3497ed08..2c0441df 100644 --- a/WINGs/dragdestination.c +++ b/WINGs/dragdestination.c @@ -96,30 +96,36 @@ WMUnregisterViewDraggedTypes(WMView *view) static unsigned defDraggingEntered(WMView *self, WMDraggingInfo *info) { + printf("%x drag entered\n", W_VIEW_DRAWABLE(self)); return WDOperationNone; } static unsigned defDraggingUpdated(WMView *self, WMDraggingInfo *info) { + printf("%x drag updat\n", W_VIEW_DRAWABLE(self)); return WDOperationNone; } static void defDraggingExited(WMView *self, WMDraggingInfo *info) { + printf("%x drag exit\n", W_VIEW_DRAWABLE(self)); } static Bool defPrepareForDragOperation(WMView *self, WMDraggingInfo *info) { + printf("%x drag prep\n", W_VIEW_DRAWABLE(self)); return False; } static Bool defPerformDragOperation(WMView *self, WMDraggingInfo *info) { + printf("%x drag perf\n", W_VIEW_DRAWABLE(self)); return False; } static void defConcludeDragOperation(WMView *self, WMDraggingInfo *info) { + printf("%x drag concl\n", W_VIEW_DRAWABLE(self)); } diff --git a/WINGs/wbox.c b/WINGs/wbox.c index ea568acc..9873eaea 100644 --- a/WINGs/wbox.c +++ b/WINGs/wbox.c @@ -23,11 +23,6 @@ typedef struct W_Box { short borderWidth; - int topOffs; - int bottomOffs; - int leftOffs; - int rightOffs; - unsigned horizontal:1; } Box; @@ -54,18 +49,6 @@ static W_ViewDelegate delegate = { -static void resizedParent(void *self, WMNotification *notif) -{ - WMView *view = (WMView*)WMGetNotificationObject(notif); - WMSize size = WMGetViewSize(view); - WMBox *box = (WMBox*)self; - - WMMoveWidget(box, box->leftOffs, box->topOffs); - WMResizeWidget(box, size.width - (box->leftOffs + box->rightOffs), - size.height - (box->topOffs + box->bottomOffs)); -} - - WMBox* WMCreateBox(WMWidget *parent) { @@ -249,28 +232,6 @@ WMSetBoxHorizontal(WMBox *box, Bool flag) } -void -WMSetBoxExpandsToParent(WMBox *box, int topOffs, int bottomOffs, - int leftOffs, int rightOffs) -{ - WMSize size = W_VIEW(box)->parent->size; - - box->topOffs = topOffs; - box->bottomOffs = bottomOffs; - box->leftOffs = leftOffs; - box->rightOffs = rightOffs; - - WMAddNotificationObserver(resizedParent, box, - WMViewSizeDidChangeNotification, - W_VIEW(box)->parent); - WMSetViewNotifySizeChanges(W_VIEW(box)->parent, True); - - WMMoveWidget(box, leftOffs, topOffs); - WMResizeWidget(box, size.width - (leftOffs + rightOffs), - size.height - (topOffs + bottomOffs)); -} - - static void destroyBox(Box *bPtr) { diff --git a/WINGs/wmisc.c b/WINGs/wmisc.c index 43476622..68605f3b 100644 --- a/WINGs/wmisc.c +++ b/WINGs/wmisc.c @@ -94,16 +94,23 @@ fitText(char *text, WMFont *font, int width, int wrap) { int i, j; int w; - + if (text[0]==0) return 0; + i = 0; if (wrap) { + if (text[0]=='\n') + return 1; + do { i++; w = WMWidthOfString(font, text, i); } while (w < width && text[i]!='\n' && text[i]!=0); + if (text[i]=='\n') + return i; + /* keep words complete */ if (!isspace(text[i])) { j = i; @@ -116,7 +123,6 @@ fitText(char *text, WMFont *font, int width, int wrap) while (text[i]!='\n' && text[i]!=0) i++; } - return i; } diff --git a/WINGs/wpanel.c b/WINGs/wpanel.c index 40c6c20b..582426d7 100644 --- a/WINGs/wpanel.c +++ b/WINGs/wpanel.c @@ -26,11 +26,13 @@ static void handleKeyPress(XEvent *event, void *clientData) { WMAlertPanel *panel = (WMAlertPanel*)clientData; - - if (event->xkey.keycode == panel->retKey && panel->defBtn) { + KeySym ksym; + + XLookupString(&event->xkey, NULL, 0, &ksym, NULL); + + if (ksym == XK_Return && panel->defBtn) { WMPerformButtonClick(panel->defBtn); - } - if (event->xkey.keycode == panel->escKey) { + } else if (ksym == XK_Escape) { if (panel->altBtn || panel->othBtn) { WMPerformButtonClick(panel->othBtn ? panel->othBtn : panel->altBtn); } else { @@ -106,10 +108,6 @@ WMCreateAlertPanel(WMScreen *scrPtr, WMWindow *owner, panel = wmalloc(sizeof(WMAlertPanel)); memset(panel, 0, sizeof(WMAlertPanel)); - - panel->retKey = XKeysymToKeycode(scrPtr->display, XK_Return); - panel->escKey = XKeysymToKeycode(scrPtr->display, XK_Escape); - if (owner) { panel->win = WMCreatePanelWithStyleForWindow(owner, "alertPanel", WMTitledWindowMask); @@ -125,7 +123,7 @@ WMCreateAlertPanel(WMScreen *scrPtr, WMWindow *owner, WMSetWindowTitle(panel->win, ""); panel->vbox = WMCreateBox(panel->win); - WMSetBoxExpandsToParent(panel->vbox, 0, 0, 0, 0); + WMSetViewExpandsToParent(WMWidgetView(panel->vbox), 0, 0, 0, 0); WMSetBoxHorizontal(panel->vbox, False); WMMapWidget(panel->vbox); @@ -277,11 +275,13 @@ static void handleKeyPress2(XEvent *event, void *clientData) { WMInputPanel *panel = (WMInputPanel*)clientData; - - if (event->xkey.keycode == panel->retKey && panel->defBtn) { + KeySym ksym; + + XLookupString(&event->xkey, NULL, 0, &ksym, NULL); + + if (ksym == XK_Return && panel->defBtn) { WMPerformButtonClick(panel->defBtn); - } - if (event->xkey.keycode == panel->escKey) { + } else if (ksym == XK_Escape) { if (panel->altBtn) { WMPerformButtonClick(panel->altBtn); } else { @@ -386,9 +386,6 @@ WMCreateInputPanel(WMScreen *scrPtr, WMWindow *owner, char *title, char *msg, panel = wmalloc(sizeof(WMInputPanel)); memset(panel, 0, sizeof(WMInputPanel)); - panel->retKey = XKeysymToKeycode(scrPtr->display, XK_Return); - panel->escKey = XKeysymToKeycode(scrPtr->display, XK_Escape); - if (owner) panel->win = WMCreatePanelWithStyleForWindow(owner, "inputPanel", WMTitledWindowMask); @@ -485,3 +482,149 @@ WMCreateInputPanel(WMScreen *scrPtr, WMWindow *owner, char *title, char *msg, + + + +void +WMDestroyGenericPanel(WMGenericPanel *panel) +{ + WMUnmapWidget(panel->win); + WMDestroyWidget(panel->win); + wfree(panel); +} + + +WMGenericPanel* +WMCreateGenericPanel(WMScreen *scrPtr, WMWindow *owner, + char *title, char *defaultButton, + char *alternateButton) +{ + WMGenericPanel *panel; + int dw=0, aw=0, w; + WMBox *hbox; + + + panel = wmalloc(sizeof(WMGenericPanel)); + memset(panel, 0, sizeof(WMGenericPanel)); + + if (owner) { + panel->win = WMCreatePanelWithStyleForWindow(owner, "genericPanel", + WMTitledWindowMask); + } else { + panel->win = WMCreateWindowWithStyle(scrPtr, "genericPanel", + WMTitledWindowMask); + } + + WMSetWindowInitialPosition(panel->win, + (scrPtr->rootView->size.width - WMWidgetWidth(panel->win))/2, + (scrPtr->rootView->size.height - WMWidgetHeight(panel->win))/2); + + WMSetWindowTitle(panel->win, ""); + + panel->vbox = WMCreateBox(panel->win); + WMSetViewExpandsToParent(WMWidgetView(panel->vbox), 0, 0, 0, 0); + WMSetBoxHorizontal(panel->vbox, False); + WMMapWidget(panel->vbox); + + hbox = WMCreateBox(panel->vbox); + WMSetBoxBorderWidth(hbox, 5); + WMSetBoxHorizontal(hbox, True); + WMMapWidget(hbox); + WMAddBoxSubview(panel->vbox, WMWidgetView(hbox), False, True, 74, 0, 5); + + panel->iLbl = WMCreateLabel(hbox); + WMSetLabelImagePosition(panel->iLbl, WIPImageOnly); + WMMapWidget(panel->iLbl); + WMAddBoxSubview(hbox, WMWidgetView(panel->iLbl), False, True, 64, 0, 10); + + if (scrPtr->applicationIcon) { + WMSetLabelImage(panel->iLbl, scrPtr->applicationIcon); + } + + if (title) { + WMFont *largeFont; + + largeFont = WMBoldSystemFontOfSize(scrPtr, 24); + + panel->tLbl = WMCreateLabel(hbox); + WMMapWidget(panel->tLbl); + WMAddBoxSubview(hbox, WMWidgetView(panel->tLbl), True, True, + 64, 0, 0); + WMSetLabelText(panel->tLbl, title); + WMSetLabelTextAlignment(panel->tLbl, WALeft); + WMSetLabelFont(panel->tLbl, largeFont); + + WMReleaseFont(largeFont); + } + + /* create divider line */ + + panel->line = WMCreateFrame(panel->vbox); + WMMapWidget(panel->line); + WMAddBoxSubview(panel->vbox, WMWidgetView(panel->line), False, True, + 2, 2, 5); + WMSetFrameRelief(panel->line, WRGroove); + + + panel->content = WMCreateFrame(panel->vbox); + WMMapWidget(panel->content); + WMAddBoxSubview(panel->vbox, WMWidgetView(panel->content), True, True, + 50, 0, 5); + WMSetFrameRelief(panel->content, WRFlat); + + hbox = WMCreateBox(panel->vbox); + WMSetBoxBorderWidth(hbox, 10); + WMSetBoxHorizontal(hbox, True); + WMMapWidget(hbox); + WMAddBoxSubview(panel->vbox, WMWidgetView(hbox), False, True, 44, 0, 0); + + /* create buttons */ + if (defaultButton) + dw = WMWidthOfString(scrPtr->normalFont, defaultButton, + strlen(defaultButton)); + + if (alternateButton) + aw = WMWidthOfString(scrPtr->normalFont, alternateButton, + strlen(alternateButton)); + + + dw = dw + (scrPtr->buttonArrow ? scrPtr->buttonArrow->width : 0); + + aw += 30; + dw += 30; + + w = WMAX(dw, aw); + if ((w+10)*2 < 400) { + aw = w; + dw = w; + } else { + int t; + + t = 400 - 40 - aw - dw; + aw += t/2; + dw += t/2; + } + + if (defaultButton) { + panel->defBtn = WMCreateCommandButton(hbox); + WMSetButtonAction(panel->defBtn, alertPanelOnClick, panel); + WMAddBoxSubviewAtEnd(hbox, WMWidgetView(panel->defBtn), + False, True, dw, 0, 0); + WMSetButtonText(panel->defBtn, defaultButton); + WMSetButtonImage(panel->defBtn, scrPtr->buttonArrow); + WMSetButtonAltImage(panel->defBtn, scrPtr->pushedButtonArrow); + WMSetButtonImagePosition(panel->defBtn, WIPRight); + } + + WMMapSubwidgets(hbox); + +// WMCreateEventHandler(W_VIEW(panel->win), KeyPressMask, +// handleKeyPress3, panel); + + WMRealizeWidget(panel->win); + WMMapSubwidgets(panel->win); + + return panel; +} + + diff --git a/WINGs/wscrollview.c b/WINGs/wscrollview.c index d69abd9e..460620b5 100644 --- a/WINGs/wscrollview.c +++ b/WINGs/wscrollview.c @@ -450,6 +450,10 @@ WMSetScrollViewHasHorizontalScroller(WMScrollView *sPtr, Bool flag) /* make it a horiz. scroller */ WMResizeWidget(sPtr->hScroller, 2, 1); + if (W_VIEW_REALIZED(sPtr->view)) { + WMRealizeWidget(sPtr->hScroller); + } + reorganizeInterior(sPtr); WMMapWidget(sPtr->hScroller); @@ -481,6 +485,10 @@ WMSetScrollViewHasVerticalScroller(WMScrollView *sPtr, Bool flag) /* make it a vert. scroller */ WMResizeWidget(sPtr->vScroller, 1, 2); + if (W_VIEW_REALIZED(sPtr->view)) { + WMRealizeWidget(sPtr->vScroller); + } + reorganizeInterior(sPtr); WMMapWidget(sPtr->vScroller); diff --git a/WINGs/wview.c b/WINGs/wview.c index 6d42a894..22d3d8a7 100644 --- a/WINGs/wview.c +++ b/WINGs/wview.c @@ -731,4 +731,37 @@ WMGetViewScreenPosition(WMView *view) return wmkpoint(x, y); } + + + +static void resizedParent(void *self, WMNotification *notif) +{ + WMSize size = WMGetViewSize((WMView*)WMGetNotificationObject(notif)); + WMView *view = (WMView*)self; + + W_MoveView(view, view->leftOffs, view->topOffs); + W_ResizeView(view, size.width - (view->leftOffs + view->rightOffs), + size.height - (view->topOffs + view->bottomOffs)); +} + +void +WMSetViewExpandsToParent(WMView *view, int leftOffs, int topOffs, + int rightOffs, int bottomOffs) +{ + WMSize size = view->parent->size; + + view->topOffs = topOffs; + view->bottomOffs = bottomOffs; + view->leftOffs = leftOffs; + view->rightOffs = rightOffs; + + WMAddNotificationObserver(resizedParent, view, + WMViewSizeDidChangeNotification, + view->parent); + WMSetViewNotifySizeChanges(view->parent, True); + + W_MoveView(view, leftOffs, topOffs); + W_ResizeView(view, size.width - (leftOffs + rightOffs), + size.height - (topOffs + bottomOffs)); +}