diff --git a/WINGs/ChangeLog b/WINGs/ChangeLog index 56f6d057..efafa139 100644 --- a/WINGs/ChangeLog +++ b/WINGs/ChangeLog @@ -1,3 +1,8 @@ +changes since wmaker 0.63.1: +............................ +- added WMRunModalLoop() and WMBreakModalLoop() +- added WMSetBoxExpandsToParent() + changes since wmaker 0.62.1: ............................ - added WRuler widget @@ -58,6 +63,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 WMAddTabViewItemWithView() - added W_SetViewCursor() - made Extra widgets library - added table widget in Extras library diff --git a/WINGs/Extras/wtableview.c b/WINGs/Extras/wtableview.c index 4af9c38d..76623591 100644 --- a/WINGs/Extras/wtableview.c +++ b/WINGs/Extras/wtableview.c @@ -772,6 +772,10 @@ void WMSelectTableViewRow(WMTableView *table, int row) { if (table->clickedRow >= 0) setRowSelected(table, table->clickedRow, False); + + if (row <= table->rows) + return; + setRowSelected(table, row, True); table->clickedRow = row; @@ -788,6 +792,8 @@ void WMReloadTableView(WMTableView *table) repaintTable(table, 0, 0, W_VIEW_WIDTH(table->tableView), rect.size.height); + + table->clickedRow = -1; } diff --git a/WINGs/WINGs.h b/WINGs/WINGs.h index 37d50d7a..b4ec373b 100644 --- a/WINGs/WINGs.h +++ b/WINGs/WINGs.h @@ -363,6 +363,7 @@ typedef struct WMListItem { /* struct for message panel */ typedef struct WMAlertPanel { WMWindow *win; /* window */ + WMBox *vbox; WMButton *defBtn; /* default button */ WMButton *altBtn; /* alternative button */ WMButton *othBtn; /* other button */ @@ -580,6 +581,9 @@ WMScreen *WMCreateSimpleApplicationScreen(Display *display); void WMScreenMainLoop(WMScreen *scr); +void WMBreakModalLoop(WMScreen *scr); + +void WMRunModalLoop(WMScreen *scr, WMView *view); RContext *WMScreenRContext(WMScreen *scr); @@ -1672,6 +1676,8 @@ void WMAddBoxSubviewAtEnd(WMBox *bPtr, WMView *view, Bool expand, Bool fill, void WMSetBoxHorizontal(WMBox *box, Bool flag); +void WMSetBoxExpandsToParent(WMBox *box); + /* ....................................................................... */ int WMRunAlertPanel(WMScreen *app, WMWindow *owner, char *title, char *msg, diff --git a/WINGs/WINGsP.h b/WINGs/WINGsP.h index 3608b3e6..577e11b4 100644 --- a/WINGs/WINGsP.h +++ b/WINGs/WINGsP.h @@ -284,7 +284,7 @@ typedef struct W_Screen { Window lastClickWindow; /* window of the last mousedown */ struct W_View *modalView; - unsigned modal:1; + unsigned modalLoop:1; unsigned ignoreNextDoubleClick:1; } W_Screen; diff --git a/WINGs/dragdestination.c b/WINGs/dragdestination.c index 8ef872a0..3497ed08 100644 --- a/WINGs/dragdestination.c +++ b/WINGs/dragdestination.c @@ -128,8 +128,9 @@ void WMSetViewDragDestinationProcs(WMView *view, WMDragDestinationProcs *procs) { if (view->dragDestinationProcs == NULL) { - wfree(view->dragDestinationProcs); view->dragDestinationProcs = wmalloc(sizeof(WMDragDestinationProcs)); + } else { + free(view->dragDestinationProcs); } *view->dragDestinationProcs = *procs; diff --git a/WINGs/wbox.c b/WINGs/wbox.c index 32318e5c..ba691ec2 100644 --- a/WINGs/wbox.c +++ b/WINGs/wbox.c @@ -47,6 +47,16 @@ static W_ViewDelegate delegate = { + +static void resizedParent(void *self, WMNotification *notif) +{ + WMView *view = (WMView*)WMGetNotificationObject(notif); + WMSize size = WMGetViewSize(view); + + WMResizeWidget((WMWidget*)self, size.width, size.height); +} + + WMBox* WMCreateBox(WMWidget *parent) { @@ -213,6 +223,16 @@ WMSetBoxHorizontal(WMBox *box, Bool flag) } +void +WMSetBoxExpandsToParent(WMBox *box) +{ + WMAddNotificationObserver(resizedParent, box, + WMViewSizeDidChangeNotification, + W_VIEW(box)->parent); + WMSetViewNotifySizeChanges(W_VIEW(box)->parent, True); +} + + static void destroyBox(Box *bPtr) { diff --git a/WINGs/widgets.c b/WINGs/widgets.c index 66242a87..abb2ed32 100644 --- a/WINGs/widgets.c +++ b/WINGs/widgets.c @@ -1038,6 +1038,29 @@ WMScreenMainLoop(WMScreen *scr) } +void +WMBreakModalLoop(WMScreen *scr) +{ + scr->modalLoop = 0; +} + + +void +WMRunModalLoop(WMScreen *scr, WMView *view) +{ + WMScreen *scr = view->screen; + + scr->modalView = view; + + scr->modalLoop = 1; + while (scr->modalLoop) { + XEvent event; + + WMNextEvent(scr->display, &event); + WMHandleEvent(&event); + } +} + Display* WMScreenDisplay(WMScreen *scr) diff --git a/WINGs/wpanel.c b/WINGs/wpanel.c index 1e030905..edf80728 100644 --- a/WINGs/wpanel.c +++ b/WINGs/wpanel.c @@ -11,7 +11,7 @@ alertPanelOnClick(WMWidget *self, void *clientData) { WMAlertPanel *panel = clientData; - panel->done = 1; + WMBreakModalLoop(WMWidgetScreen(panel->othBtn)); if (self == panel->defBtn) { panel->result = WAPRDefault; } else if (self == panel->othBtn) { @@ -35,7 +35,7 @@ handleKeyPress(XEvent *event, void *clientData) WMPerformButtonClick(panel->othBtn ? panel->othBtn : panel->altBtn); } else { panel->result = WAPRDefault; - panel->done=1; + WMBreakModalLoop(WMWidgetScreen(panel->othBtn)); } } } @@ -72,19 +72,10 @@ WMRunAlertPanel(WMScreen *scrPtr, WMWindow *owner, WMSetWindowInitialPosition(panel->win, px, py); } - - scrPtr->modalView = W_VIEW(panel->win); WMMapWidget(panel->win); - scrPtr->modal = 1; - while (!panel->done || WMScreenPending(scrPtr)) { - XEvent event; - - WMNextEvent(scrPtr->display, &event); - WMHandleEvent(&event); - } - scrPtr->modal = 0; - + WMRunModalLoop(scrPtr, W_VIEW(panel->win)); + tmp = panel->result; WMDestroyAlertPanel(panel); @@ -109,6 +100,7 @@ WMCreateAlertPanel(WMScreen *scrPtr, WMWindow *owner, { WMAlertPanel *panel; int x, dw=0, aw=0, ow=0, w; + WMBox *hbox; panel = wmalloc(sizeof(WMAlertPanel)); @@ -131,15 +123,24 @@ WMCreateAlertPanel(WMScreen *scrPtr, WMWindow *owner, (scrPtr->rootView->size.height - WMWidgetHeight(panel->win))/2); WMSetWindowTitle(panel->win, ""); + + panel->vbox = WMCreateBox(panel->win); + WMSetBoxExpandsToParent(panel->vbox); + WMSetBoxHorizontal(panel->vbox, False); + WMMapWidget(panel->vbox); + + hbox = WMCreateBox(panel->vbox); + WSetBoxHorizontal(hbox, True); + WMMapWidget(hbox); + WMAddBoxSubview(panel->vbox, WMWidgetView(hbox), False, True, 80, 0, 0, 5); + + panel->iLbl = WMCreateLabel(hbox); + WMSetLabelImagePosition(panel->iLbl, WIPImageOnly); + WMMapWidget(panel->iLbl); + WMAddBoxSubview(hbox, WMWidgetView(panel->iLbl), False, True, 64, 0, 0, 10); if (scrPtr->applicationIcon) { - panel->iLbl = WMCreateLabel(panel->win); - WMResizeWidget(panel->iLbl, scrPtr->applicationIcon->width, - scrPtr->applicationIcon->height); - WMMoveWidget(panel->iLbl, 8 + (64 - scrPtr->applicationIcon->width)/2, - (75 - scrPtr->applicationIcon->height)/2); WMSetLabelImage(panel->iLbl, scrPtr->applicationIcon); - WMSetLabelImagePosition(panel->iLbl, WIPImageOnly); } if (title) { @@ -147,33 +148,40 @@ WMCreateAlertPanel(WMScreen *scrPtr, WMWindow *owner, largeFont = WMBoldSystemFontOfSize(scrPtr, 24); - panel->tLbl = WMCreateLabel(panel->win); - WMMoveWidget(panel->tLbl, 80, (80 - WMFontHeight(largeFont))/2); - WMResizeWidget(panel->tLbl, 400 - 70, WMFontHeight(largeFont)+4); + panel->tLbl = WMCreateLabel(hbox); + WMMapWidget(panel->tLbl); + WMAddBoxSubview(hbox, WMWidgetView(panel->tLbl), True, True, + 64, 0, 0, 0); WMSetLabelText(panel->tLbl, title); WMSetLabelTextAlignment(panel->tLbl, WALeft); WMSetLabelFont(panel->tLbl, largeFont); - + WMReleaseFont(largeFont); } + /* create divider line */ + + panel->line = WMCreateFrame(panel->win); + WMMapWidget(panel->line); + WMAddBoxSubview(panel->vbox, WMWidgetView(panel->line), False, True, + 2, 2, 5); + WMSetFrameRelief(panel->line, WRGroove); + if (msg) { panel->mLbl = WMCreateLabel(panel->win); - WMMoveWidget(panel->mLbl, 10, 83); - WMResizeWidget(panel->mLbl, 380, WMFontHeight(scrPtr->normalFont)*4); + WMMapWidget(panel->mLbl); + WMAddBoxSubview(panel->vbox, WMWidgetView(panel->mLbl), True, True, + WMFontHeight(scrPtr->normalFont)*4, 0, 0, 5); WMSetLabelText(panel->mLbl, msg); WMSetLabelTextAlignment(panel->mLbl, WACenter); } + hbox = WMCreateBox(panel->vbox); + WMSetBoxHorizontal(hbox, True); + WMMapWidget(hbox); + WMAddBoxSubview(panel->vbox, hbox, False, True, 24, 0, 0, 0); - /* create divider line */ - - panel->line = WMCreateFrame(panel->win); - WMMoveWidget(panel->line, 0, 80); - WMResizeWidget(panel->line, 400, 2); - WMSetFrameRelief(panel->line, WRGroove); - /* create buttons */ if (otherButton) ow = WMWidthOfString(scrPtr->normalFont, otherButton, @@ -211,11 +219,11 @@ WMCreateAlertPanel(WMScreen *scrPtr, WMWindow *owner, if (defaultButton) { x -= dw + 10; - + panel->defBtn = WMCreateCommandButton(panel->win); WMSetButtonAction(panel->defBtn, alertPanelOnClick, panel); - WMMoveWidget(panel->defBtn, x, 144); - WMResizeWidget(panel->defBtn, dw, 24); + WMAddBoxSubviewAtEnd(hbox, WMWidgetView(panel->defBtn), + False, True, dw, 0, 5); WMSetButtonText(panel->defBtn, defaultButton); WMSetButtonImage(panel->defBtn, scrPtr->buttonArrow); WMSetButtonAltImage(panel->defBtn, scrPtr->pushedButtonArrow); @@ -225,8 +233,8 @@ WMCreateAlertPanel(WMScreen *scrPtr, WMWindow *owner, x -= aw + 10; panel->altBtn = WMCreateCommandButton(panel->win); - WMMoveWidget(panel->altBtn, x, 144); - WMResizeWidget(panel->altBtn, aw, 24); + WMAddBoxSubviewAtEnd(hbox, WMWidgetView(panel->altBtn), + False, True, aw, 0, 5); WMSetButtonAction(panel->altBtn, alertPanelOnClick, panel); WMSetButtonText(panel->altBtn, alternateButton); } @@ -235,12 +243,12 @@ WMCreateAlertPanel(WMScreen *scrPtr, WMWindow *owner, panel->othBtn = WMCreateCommandButton(panel->win); WMSetButtonAction(panel->othBtn, alertPanelOnClick, panel); - WMMoveWidget(panel->othBtn, x, 144); - WMResizeWidget(panel->othBtn, ow, 24); + WMAddBoxSubviewAtEnd(hbox, WMWidgetView(panel->othBtn), + False, True, ow, 0, 5); WMSetButtonText(panel->othBtn, otherButton); } - - panel->done = 0; + + WMMapSubwidgets(hbox); WMCreateEventHandler(W_VIEW(panel->win), KeyPressMask, handleKeyPress, panel); @@ -260,7 +268,7 @@ inputBoxOnClick(WMWidget *self, void *clientData) { WMInputPanel *panel = clientData; - panel->done = 1; + WMBreakModalLoop(WMWidgetScreen(self)); if (self == panel->defBtn) { panel->result = WAPRDefault; } else if (self == panel->altBtn) { @@ -283,7 +291,7 @@ handleKeyPress2(XEvent *event, void *clientData) WMPerformButtonClick(panel->altBtn); } else { /* printf("got esc\n");*/ - panel->done = 1; + WMBreakModalLoop(WMWidgetScreen(panel->altBtn)); panel->result = WAPRDefault; } } @@ -324,13 +332,7 @@ WMRunInputPanel(WMScreen *scrPtr, WMWindow *owner, char *title, WMMapWidget(panel->win); - while (!panel->done || WMScreenPending(scrPtr)) { - XEvent event; - - WMNextEvent(scrPtr->display, &event); - WMHandleEvent(&event); - } - + WMRunModalLoop(scrPtr, W_VIEW(panel->win)); if (panel->result == WAPRDefault) tmp = WMGetTextFieldText(panel->text); @@ -368,7 +370,7 @@ endedEditingObserver(void *observerData, WMNotification *notification) if (panel->altBtn) WMPerformButtonClick(panel->altBtn); else { - panel->done = 1; + WMBreakModalLoop(WMWidgetScreen(panel->defBtn)); panel->result = WAPRDefault; } break; @@ -475,8 +477,6 @@ WMCreateInputPanel(WMScreen *scrPtr, WMWindow *owner, char *title, char *msg, WMSetButtonText(panel->altBtn, cancelButton); } - panel->done = 0; - WMCreateEventHandler(W_VIEW(panel->win), KeyPressMask, handleKeyPress2, panel);