From 52308a0abcb3a9b795d2edadd7491f7ea7c6335d Mon Sep 17 00:00:00 2001 From: kojima Date: Sat, 11 Nov 2000 18:08:10 +0000 Subject: [PATCH] fixed bugs of resized widgets --- WINGs/ChangeLog | 2 +- WINGs/Tests/wtest.c | 50 +++++++++++++++++++++++++++++++++++++------- WINGs/WINGsP.h | 3 +++ WINGs/wbox.c | 17 ++++++++------- WINGs/wpopupbutton.c | 1 + WINGs/wscrollview.c | 4 +++- WINGs/wtabview.c | 43 +++++++++++++++++++++++++++++++++++++ WINGs/wview.c | 13 +++++++++++- 8 files changed, 116 insertions(+), 17 deletions(-) diff --git a/WINGs/ChangeLog b/WINGs/ChangeLog index bbdd3ec4..19d9a9e8 100644 --- a/WINGs/ChangeLog +++ b/WINGs/ChangeLog @@ -58,7 +58,7 @@ changes since wmaker 0.62.1: the program name prepended to it. Similar to wwarning(), except that it doesn't add "warning:" in the output message. - added WMBox widget - +- added W_SetViewCursor() changes since wmaker 0.62.0: ............................ diff --git a/WINGs/Tests/wtest.c b/WINGs/Tests/wtest.c index f4381aa3..4262c2f1 100644 --- a/WINGs/Tests/wtest.c +++ b/WINGs/Tests/wtest.c @@ -115,12 +115,21 @@ testFrame(WMScreen *scr) } +static void resizedWindow(void *self, WMNotification *notif) +{ + WMView *view = (WMView*)WMGetNotificationObject(notif); + WMSize size = WMGetViewSize(view); + + WMResizeWidget((WMWidget*)self, size.width, size.height); +} + void testBox(WMScreen *scr) { WMWindow *win; - WMBox *box; + WMBox *box, *hbox; WMButton *btn; + WMPopUpButton *pop; int i; windowCount++; @@ -128,12 +137,19 @@ testBox(WMScreen *scr) win = WMCreateWindow(scr, "testBox"); WMSetWindowTitle(win, "Box"); WMSetWindowCloseAction(win, closeAction, NULL); - WMResizeWidget(win, 400, 300); + + WMSetViewNotifySizeChanges(WMWidgetView(win), True); box = WMCreateBox(win); - WMMoveWidget(box, 50, 50); - WMResizeWidget(box, 300, 200); -// WMSetBoxHorizontal(box, True); + WMSetBoxBorderWidth(box, 5); + + WMAddNotificationObserver(resizedWindow, box, + WMViewSizeDidChangeNotification, + WMWidgetView(win)); + WMResizeWidget(win, 400, 300); + + +/* WMSetBoxHorizontal(box, True); */ for (i = 0; i < 4; i++) { btn = WMCreateCommandButton(box); WMSetButtonText(btn, "bla"); @@ -141,6 +157,25 @@ testBox(WMScreen *scr) WMAddBoxSubview(box, WMWidgetView(btn), i&1, True, 20, 0, 5); } + pop = WMCreatePopUpButton(box); + WMAddPopUpButtonItem(pop, "ewqeq"); + WMAddPopUpButtonItem(pop, "ewqeqrewrw"); + WMAddBoxSubview(box, WMWidgetView(pop), False, True, 20, 0, 5); + WMMapWidget(pop); + + hbox = WMCreateBox(box); + WMSetBoxHorizontal(hbox, True); + WMAddBoxSubview(box, WMWidgetView(hbox), False, True, 24, 0, 0); + WMMapWidget(hbox); + + for (i = 0; i < 4; i++) { + btn = WMCreateCommandButton(hbox); + WMSetButtonText(btn, "bla"); + WMMapWidget(btn); + WMAddBoxSubview(hbox, WMWidgetView(btn), 1, True, 60, 0, i<3?5:0); + } + + WMRealizeWidget(win); WMMapSubwidgets(win); WMMapWidget(win); @@ -1239,7 +1274,9 @@ main(int argc, char **argv) */ testBox(scr); -#if 0 + +#if 0 + testTabView(scr); testList(scr); testProgressIndicator(scr); @@ -1259,7 +1296,6 @@ main(int argc, char **argv) testFrame(scr); - testTabView(scr); diff --git a/WINGs/WINGsP.h b/WINGs/WINGsP.h index 099f3b75..3608b3e6 100644 --- a/WINGs/WINGsP.h +++ b/WINGs/WINGsP.h @@ -337,6 +337,7 @@ typedef struct W_View { WMColor *backColor; + Cursor cursor; Atom *droppableTypes; struct W_DragSourceProcs *dragSourceProcs; @@ -461,6 +462,8 @@ void W_ResizeView(W_View *view, unsigned int width, unsigned int height); void W_SetViewBackgroundColor(W_View *view, WMColor *color); +void W_SetViewCursor(W_View *view, Cursor cursor); + void W_DrawRelief(W_Screen *scr, Drawable d, int x, int y, unsigned int width, unsigned int height, WMReliefType relief); diff --git a/WINGs/wbox.c b/WINGs/wbox.c index f3e4262a..e6bde7ea 100644 --- a/WINGs/wbox.c +++ b/WINGs/wbox.c @@ -82,12 +82,12 @@ rearrange(WMBox *box) { int i; int x, y; - int w, h; + int w = 1, h = 1; int total; int expands = 0; x = box->borderWidth; - y = box->borderWidth; + y = box->borderWidth; if (box->horizontal) { h = WMWidgetHeight(box) - 2 * box->borderWidth; total = WMWidgetWidth(box) - 2 * box->borderWidth; @@ -95,16 +95,19 @@ rearrange(WMBox *box) w = WMWidgetWidth(box) - 2 * box->borderWidth; total = WMWidgetHeight(box) - 2 * box->borderWidth; } - - + + if (w <= 0 || h <= 0 || total <= 0) { + return; + } + for (i = 0; i < box->subviewCount; i++) { total -= box->subviews[i].minSize; - total -= box->subviews[i].space; + total -= box->subviews[i].space; if (box->subviews[i].expand) { expands++; } } - + for (i = 0; i < box->subviewCount; i++) { if (box->horizontal) { w = box->subviews[i].minSize; @@ -115,8 +118,8 @@ rearrange(WMBox *box) if (box->subviews[i].expand) h += total/expands; } - W_ResizeView(box->subviews[i].view, w, h); W_MoveView(box->subviews[i].view, x, y); + W_ResizeView(box->subviews[i].view, w, h); if (box->horizontal) { x += w + box->subviews[i].space; } else { diff --git a/WINGs/wpopupbutton.c b/WINGs/wpopupbutton.c index 8785134c..f78f5bf5 100644 --- a/WINGs/wpopupbutton.c +++ b/WINGs/wpopupbutton.c @@ -224,6 +224,7 @@ WMSetPopUpButtonSelectedItem(WMPopUpButton *bPtr, int index) paintPopUpButton(bPtr); } + int WMGetPopUpButtonSelectedItem(WMPopUpButton *bPtr) { diff --git a/WINGs/wscrollview.c b/WINGs/wscrollview.c index 4dae0f70..24560ed2 100644 --- a/WINGs/wscrollview.c +++ b/WINGs/wscrollview.c @@ -73,6 +73,8 @@ WMCreateScrollView(WMWidget *parent) sPtr->view->delegate = &_ScrollViewViewDelegate; + W_SetViewBackgroundColor(sPtr->viewport, + WMBlackColor(WMWidgetScreen(parent))); sPtr->viewport->flags.mapWhenRealized = 1; WMCreateEventHandler(sPtr->view, StructureNotifyMask|ExposureMask, @@ -163,7 +165,7 @@ reorganizeInterior(WMScrollView *sPtr) W_ResizeView(sPtr->viewport, cw, ch); W_MoveView(sPtr->viewport, cx, cy); - + if (sPtr->flags.hasHScroller) { WMResizeWidget(sPtr->hScroller, hw, 20); WMMoveWidget(sPtr->hScroller, hx, hy); diff --git a/WINGs/wtabview.c b/WINGs/wtabview.c index d690421f..1204f23d 100644 --- a/WINGs/wtabview.c +++ b/WINGs/wtabview.c @@ -37,6 +37,9 @@ typedef struct W_TabView { + + + #define DEFAULT_WIDTH 40 #define DEFAULT_HEIGHT 40 @@ -61,6 +64,19 @@ static WMView *W_TabViewItemView(WMTabViewItem *item); static void recalcTabWidth(TabView *tPtr); +static void didResize(struct W_ViewDelegate*, WMView*); + +static W_ViewDelegate delegate = { + NULL, + NULL, + didResize, + NULL, + NULL +}; + + + + static void handleEvents(XEvent *event, void *data) { @@ -131,6 +147,7 @@ WMCreateTabView(WMWidget *parent) return NULL; } tPtr->view->self = tPtr; + tPtr->view->delegate = &delegate; tPtr->lightGray = WMCreateRGBColor(scr, 0xd9d9, 0xd9d9, 0xd9d9, False); tPtr->tabColor = WMCreateRGBColor(scr, 0x8420, 0x8420, 0x8420, False); @@ -640,6 +657,32 @@ paintTabView(TabView *tPtr) } +static void +rearrange(TabView *tPtr) +{ + int i; + int width, height; + + recalcTabWidth(tPtr); + + width = tPtr->view->size.width - 3; + height = tPtr->view->size.height - tPtr->tabHeight - 3; + + for (i = 0; i < tPtr->itemCount; i++) { + W_ResizeView(W_TabViewItemView(tPtr->items[i]), width, height); + } + if (W_VIEW_MAPPED(tPtr->view) && W_VIEW_REALIZED(tPtr->view)) + paintTabView(tPtr); +} + + +static void +didResize(struct W_ViewDelegate *deleg, WMView *view) +{ + rearrange(view->self); +} + + static void destroyTabView(TabView *tPtr) { diff --git a/WINGs/wview.c b/WINGs/wview.c index 0ec6141e..9e29eeb9 100644 --- a/WINGs/wview.c +++ b/WINGs/wview.c @@ -561,6 +561,18 @@ W_SetViewBackgroundColor(W_View *view, WMColor *color) } +void +W_SetViewCursor(W_View *view, Cursor cursor) +{ + view->cursor = cursor; + if (W_VIEW_REALIZED(view)) { + XDefineCursor(W_VIEW_DISPLAY(view), W_VIEW_DRAWABLE(view), cursor); + } else { + view->attribFlags |= CWCursor; + view->attribs.cursor = cursor; + } +} + W_View* W_FocusedViewOfToplevel(W_View *view) @@ -714,4 +726,3 @@ WMGetViewScreenPosition(WMView *view) } -