DialogBox.st
changeset 310 4bbc8deffc8c
parent 307 d3fe810390cb
child 312 008267b920d9
equal deleted inserted replaced
309:b5c9d68e95e1 310:4bbc8deffc8c
    12 
    12 
    13 ModalBox subclass:#DialogBox
    13 ModalBox subclass:#DialogBox
    14 	instanceVariableNames:'buttonPanel okButton okAction abortButton abortAction
    14 	instanceVariableNames:'buttonPanel okButton okAction abortButton abortAction
    15 		acceptReturnAsOK yPosition leftIndent rightIndent bindings
    15 		acceptReturnAsOK yPosition leftIndent rightIndent bindings
    16 		addedComponents inputFieldGroup acceptOnLeave acceptValue
    16 		addedComponents inputFieldGroup acceptOnLeave acceptValue
    17 		tabableElements hideOnAccept acceptCheck'
    17 		tabableElements hideOnAccept acceptCheck needResize'
    18 	classVariableNames:''
    18 	classVariableNames:''
    19 	poolDictionaries:''
    19 	poolDictionaries:''
    20 	category:'Views-DialogBoxes'
    20 	category:'Views-DialogBoxes'
    21 !
    21 !
    22 
    22 
  1334 
  1334 
  1335     list notNil ifTrue:[
  1335     list notNil ifTrue:[
  1336         listView := ScrollableView for:SelectionInListView.
  1336         listView := ScrollableView for:SelectionInListView.
  1337         listView list:list.
  1337         listView list:list.
  1338         listView doubleClickAction:[:line | box hide. ^ listValues at:line].
  1338         listView doubleClickAction:[:line | box hide. ^ listValues at:line].
  1339 "/        list height:(list font height * maxLines).
  1339         box addComponent:listView withHeight:(listView heightForLines:maxLines).
  1340         box addComponent:listView.
       
  1341     ].
  1340     ].
  1342 
  1341 
  1343     buttonLabels notNil ifTrue:[
  1342     buttonLabels notNil ifTrue:[
  1344         panel := HorizontalPanelView new.
  1343         panel := HorizontalPanelView new.
  1345         panel horizontalLayout:#fit.
  1344         panel horizontalLayout:#fit.
  1352         ].
  1351         ].
  1353         box addComponent:panel.
  1352         box addComponent:panel.
  1354     ].
  1353     ].
  1355     box addAbortButton.
  1354     box addAbortButton.
  1356     list notNil ifTrue:[box addOkButton].
  1355     list notNil ifTrue:[box addOkButton].
       
  1356 
       
  1357     listView notNil ifTrue:[box stickAtBottomWithVariableHeight:listView].
       
  1358     panel notNil ifTrue:[box stickAtBottomWithFixHeight:panel].
       
  1359 
  1357     box showAtPointer.
  1360     box showAtPointer.
  1358     box accepted ifTrue:[
  1361     box accepted ifTrue:[
  1359         (answer := listView selection) notNil ifTrue:[
  1362         (answer := listView selection) notNil ifTrue:[
  1360             ^ listValues at:answer
  1363             ^ listValues at:answer
  1361         ]
  1364         ]
  1370                 choose:'choose any' 
  1373                 choose:'choose any' 
  1371                 fromList:#('one' 'two' 'three' 'four') 
  1374                 fromList:#('one' 'two' 'three' 'four') 
  1372                 values:#(1 2 3 4) 
  1375                 values:#(1 2 3 4) 
  1373                 buttons:#('five' 'six' 'seven')
  1376                 buttons:#('five' 'six' 'seven')
  1374                 values:#(5 6 7)
  1377                 values:#(5 6 7)
  1375                 lines:4
  1378                 lines:10 
  1376                 cancel:nil
  1379                 cancel:nil
  1377          )
  1380          )
  1378 
  1381 
  1379 
  1382 
  1380      no buttons:
  1383      no buttons:
  1433          )
  1436          )
  1434 
  1437 
  1435 
  1438 
  1436     "
  1439     "
  1437 
  1440 
  1438     "Modified: 27.1.1996 / 14:17:27 / cg"
  1441     "Modified: 27.1.1996 / 17:20:16 / cg"
  1439 !
  1442 !
  1440 
  1443 
  1441 choose:aString fromList:list values:listValues lines:maxLines cancel:cancelBlock
  1444 choose:aString fromList:list values:listValues lines:maxLines cancel:cancelBlock
  1442     "launch a Dialog showing the message and list.
  1445     "launch a Dialog showing the message and list.
  1443      The user can select an item and click ok; in this case, the corresponding value
  1446      The user can select an item and click ok; in this case, the corresponding value
  1739 
  1742 
  1740     |h|
  1743     |h|
  1741 
  1744 
  1742     buttonPanel addSubView:aButton after:someOtherButtonOrNil.
  1745     buttonPanel addSubView:aButton after:someOtherButtonOrNil.
  1743     buttonPanel subViews size > 1 ifTrue:[
  1746     buttonPanel subViews size > 1 ifTrue:[
  1744 	buttonPanel horizontalLayout:#fitSpace.
  1747         buttonPanel horizontalLayout:#fitSpace.
  1745     ].
  1748     ].
  1746     (h := (aButton heightIncludingBorder + (ViewSpacing * 2))) > buttonPanel topInset ifTrue:[
  1749     (h := (aButton heightIncludingBorder + (ViewSpacing * 2))) > buttonPanel topInset ifTrue:[
  1747 	 buttonPanel topInset:h negated
  1750          buttonPanel topInset:h negated
  1748     ].
  1751     ].
       
  1752     needResize := true.
  1749     ^ aButton
  1753     ^ aButton
       
  1754 
       
  1755     "Modified: 27.1.1996 / 18:20:18 / cg"
  1750 !
  1756 !
  1751 
  1757 
  1752 addCheckBox:label on:aModel
  1758 addCheckBox:label on:aModel
  1753     "create a checkBox with label on aModel and add it.
  1759     "create a checkBox with label on aModel and add it.
  1754      Returns the box."
  1760      Returns the box."
  1872 
  1878 
  1873     self basicAddComponent:aComponent.
  1879     self basicAddComponent:aComponent.
  1874     fullSize := ext + (leftIndent + rightIndent @ 0).
  1880     fullSize := ext + (leftIndent + rightIndent @ 0).
  1875     aComponent extent:fullSize.
  1881     aComponent extent:fullSize.
  1876     aComponent origin:0.0@yPosition; 
  1882     aComponent origin:0.0@yPosition; 
  1877 	       leftInset:leftIndent; 
  1883                leftInset:leftIndent; 
  1878 	       rightInset:rightIndent.
  1884                rightInset:rightIndent.
  1879     yPosition := yPosition + aComponent height + ViewSpacing.
  1885     yPosition := yPosition + aComponent height + ViewSpacing.
  1880     width := fullSize x max:width.
  1886     width := fullSize x max:width.
       
  1887     needResize := true.
  1881     ^ aComponent
  1888     ^ aComponent
       
  1889 
       
  1890     "Modified: 27.1.1996 / 18:20:36 / cg"
  1882 !
  1891 !
  1883 
  1892 
  1884 addComponent:aComponent withHeight:height 
  1893 addComponent:aComponent withHeight:height 
  1885     "add a component with some given height and full width.
  1894     "add a component with some given height and full width.
  1886      Returns the component."
  1895      Returns the component."
  1887 
  1896 
  1888     self basicAddComponent:aComponent.
  1897     self basicAddComponent:aComponent.
  1889     aComponent height:height.
  1898     aComponent height:height.
  1890     aComponent origin:0.0@yPosition; 
  1899     aComponent origin:0.0@yPosition; 
  1891 	       width:1.0; 
  1900                width:1.0; 
  1892 	       leftInset:leftIndent;
  1901                leftInset:leftIndent;
  1893 	       rightInset:rightIndent.
  1902                rightInset:rightIndent.
  1894     yPosition := yPosition + "aComponent" height + ViewSpacing.
  1903     yPosition := yPosition + "aComponent" height + ViewSpacing.
       
  1904     needResize := true.
  1895     ^ aComponent
  1905     ^ aComponent
       
  1906 
       
  1907     "Modified: 27.1.1996 / 18:20:39 / cg"
  1896 !
  1908 !
  1897 
  1909 
  1898 addFilenameInputFieldOn:aModel in:aDirectory tabable:tabable
  1910 addFilenameInputFieldOn:aModel in:aDirectory tabable:tabable
  1899     "create a fileName input field on aModel and add it.
  1911     "create a fileName input field on aModel and add it.
  1900      Returns the field. This is much like a normal input field,
  1912      Returns the field. This is much like a normal input field,
  2191 
  2203 
  2192 addVerticalSpace:nPixel
  2204 addVerticalSpace:nPixel
  2193     "add some pixels of space to the next component"
  2205     "add some pixels of space to the next component"
  2194 
  2206 
  2195     yPosition := yPosition + nPixel.
  2207     yPosition := yPosition + nPixel.
       
  2208     needResize := true.
       
  2209 
       
  2210     "Modified: 27.1.1996 / 18:21:27 / cg"
  2196 !
  2211 !
  2197 
  2212 
  2198 leftIndent:aNumber 
  2213 leftIndent:aNumber 
  2199     "set the left indent (current x position - thats where the next component
  2214     "set the left indent (current x position - thats where the next component
  2200      will be located)."
  2215      will be located)."
  2201 
  2216 
  2202     leftIndent := aNumber.
  2217     leftIndent := aNumber.
       
  2218     needResize := true.
       
  2219 
       
  2220     "Modified: 27.1.1996 / 18:21:31 / cg"
  2203 !
  2221 !
  2204 
  2222 
  2205 makeTabable:aComponentOrSubcomponent
  2223 makeTabable:aComponentOrSubcomponent
  2206     "add a component (usually a subcomponent, of which the dialog
  2224     "add a component (usually a subcomponent, of which the dialog
  2207      does not know) to the list of tabable ones (i.e. those, that can be
  2225      does not know) to the list of tabable ones (i.e. those, that can be
  2226 
  2244 
  2227 rightIndent:aNumber 
  2245 rightIndent:aNumber 
  2228     "set the right indent"
  2246     "set the right indent"
  2229 
  2247 
  2230     rightIndent := aNumber.
  2248     rightIndent := aNumber.
       
  2249     needResize := true.
       
  2250 
       
  2251     "Modified: 27.1.1996 / 18:21:36 / cg"
  2231 !
  2252 !
  2232 
  2253 
  2233 yPosition 
  2254 yPosition 
  2234     "return the current y position (thats where the next component
  2255     "return the current y position (thats where the next component
  2235      will be located)."
  2256      will be located)."
  2240 yPosition:aNumber 
  2261 yPosition:aNumber 
  2241     "set the current y position (thats where the next component
  2262     "set the current y position (thats where the next component
  2242      will be located)."
  2263      will be located)."
  2243 
  2264 
  2244     yPosition := aNumber.
  2265     yPosition := aNumber.
       
  2266     needResize := true.
       
  2267 
       
  2268     "Modified: 27.1.1996 / 18:21:40 / cg"
  2245 ! !
  2269 ! !
  2246 
  2270 
  2247 !DialogBox methodsFor:'initialization'!
  2271 !DialogBox methodsFor:'initialization'!
  2248 
  2272 
  2249 focusSequence
  2273 focusSequence
  2282     acceptOnLeave := true.
  2306     acceptOnLeave := true.
  2283     hideOnAccept := true.
  2307     hideOnAccept := true.
  2284 
  2308 
  2285     buttonPanel := HorizontalPanelView in:self.
  2309     buttonPanel := HorizontalPanelView in:self.
  2286     buttonPanel 
  2310     buttonPanel 
  2287 	origin:(0.0 @ 1.0) corner:(1.0 @ 1.0);
  2311         origin:(0.0 @ 1.0) corner:(1.0 @ 1.0);
  2288 	bottomInset:mm; 
  2312         bottomInset:mm; 
  2289 	topInset:(font height + mm * 2) negated;
  2313         topInset:(font height + mm * 2) negated;
  2290 	borderWidth:0;
  2314         borderWidth:0;
  2291 	horizontalLayout:#spread.
  2315         horizontalLayout:#spread.
  2292 
  2316 
  2293     yPosition := ViewSpacing.
  2317     yPosition := ViewSpacing.
  2294     leftIndent := rightIndent := ViewSpacing.
  2318     leftIndent := rightIndent := ViewSpacing.
       
  2319     needResize := true.
  2295 
  2320 
  2296     "
  2321     "
  2297      |b|
  2322      |b|
  2298      b := DialogBox new.
  2323      b := DialogBox new.
  2299      b addAbortButton; 
  2324      b addAbortButton; 
  2319      b addTextLabel:'hello world';
  2344      b addTextLabel:'hello world';
  2320        addVerticalSpace:50; 
  2345        addVerticalSpace:50; 
  2321        addOkButton; 
  2346        addOkButton; 
  2322        showAtPointer
  2347        showAtPointer
  2323     "
  2348     "
       
  2349 
       
  2350     "Modified: 27.1.1996 / 17:21:22 / cg"
  2324 !
  2351 !
  2325 
  2352 
  2326 reAdjustGeometry
  2353 reAdjustGeometry
  2327     "sent late in snapin processing - gives me a chance
  2354     "sent late in snapin processing - gives me a chance
  2328      to resize for changed font dimensions."
  2355      to resize for changed font dimensions."
  2362 
  2389 
  2363     inputFieldGroup notNil ifTrue:[
  2390     inputFieldGroup notNil ifTrue:[
  2364 	inputFieldGroup activateFirst
  2391 	inputFieldGroup activateFirst
  2365     ].
  2392     ].
  2366     super realize
  2393     super realize
       
  2394 !
       
  2395 
       
  2396 resize
       
  2397     needResize ifTrue:[
       
  2398         needResize := false.
       
  2399         super resize
       
  2400     ]
       
  2401 
       
  2402     "Created: 27.1.1996 / 17:22:33 / cg"
       
  2403     "Modified: 27.1.1996 / 18:25:40 / cg"
  2367 ! !
  2404 ! !
  2368 
  2405 
  2369 !DialogBox methodsFor:'queries'!
  2406 !DialogBox methodsFor:'queries'!
  2370 
  2407 
  2371 accepted
  2408 accepted
  2393      whichever is larger, by the sum of the components heights."
  2430      whichever is larger, by the sum of the components heights."
  2394 
  2431 
  2395     |w h p|
  2432     |w h p|
  2396 
  2433 
  2397     addedComponents notNil ifTrue:[
  2434     addedComponents notNil ifTrue:[
  2398 	w := addedComponents 
  2435         w := addedComponents 
  2399 		inject:0 
  2436                 inject:0 
  2400 		into:[:max :element |
  2437                 into:[:max :element |
  2401 			|eExt|
  2438                         |eExt|
  2402 
  2439 
  2403 			eExt := (element preferredExtent x) + (element borderWidth * 2). "/ max:element extent x.
  2440                         eExt := (element preferredExtent x) + (element borderWidth * 2). "/ max:element extent x.
  2404 			max max:(eExt + element leftInset + element rightInset)].
  2441                         max max:(eExt + element leftInset + element rightInset)].
  2405     ] ifFalse:[
  2442     ] ifFalse:[
  2406 	w := super preferredExtent x.
  2443         w := super preferredExtent x.
  2407     ].
  2444     ].
  2408     w := w max:width.
  2445     w := w max:width.
  2409     h := yPosition
  2446     h := yPosition + ViewSpacing.
  2410 	 + ViewSpacing.
       
  2411 
  2447 
  2412     buttonPanel subViews size ~~ 0 ifTrue:[
  2448     buttonPanel subViews size ~~ 0 ifTrue:[
  2413 	p := buttonPanel preferredExtent.
  2449         p := buttonPanel preferredExtent.
  2414 	w := w max:p x.
  2450         w := w max:p x.
  2415 	h := h
  2451         h := h
  2416 	     + p y
  2452              + p y
  2417 	     + ViewSpacing.
  2453              + ViewSpacing.
  2418     ].
  2454     ].
  2419 
  2455 
  2420 "/    okButton isNil ifTrue:[
  2456 "/    okButton isNil ifTrue:[
  2421 "/        ^ super preferredExtent
  2457 "/        ^ super preferredExtent
  2422 "/    ].
  2458 "/    ].
  2425 "/    h := ViewSpacing
  2461 "/    h := ViewSpacing
  2426 "/         + p y
  2462 "/         + p y
  2427 "/         + ViewSpacing.
  2463 "/         + ViewSpacing.
  2428 "/
  2464 "/
  2429     ^ w @ h
  2465     ^ w @ h
       
  2466 
       
  2467     "Modified: 27.1.1996 / 18:19:50 / cg"
       
  2468 ! !
       
  2469 
       
  2470 !DialogBox methodsFor:'special geometry settings'!
       
  2471 
       
  2472 stickAtBottomWithFixHeight:aComponent
       
  2473     "arrange for a component to be positioned at a constant offset
       
  2474      from the bottom of the box and its height to remain the same.
       
  2475      This will keep the component at a constant distance from the bottom
       
  2476      (without this setup, it would stay at a constant offset from the top)"
       
  2477 
       
  2478     self resize.
       
  2479 
       
  2480     aComponent
       
  2481         topInset:(self height - aComponent top) negated;
       
  2482         bottomInset:(self height - aComponent bottom); 
       
  2483         origin:0.0 @ 1.0; corner:1.0 @ 1.0.
       
  2484 
       
  2485     "
       
  2486      compare the resizing behavior of:
       
  2487 
       
  2488         |box|
       
  2489 
       
  2490         box := Dialog new.
       
  2491         box addTextLabel:'hello'.
       
  2492         box addTextLabel:'hello2'.
       
  2493         box addOkButton.
       
  2494         box show
       
  2495 
       
  2496      with:
       
  2497 
       
  2498         |box l2|
       
  2499 
       
  2500         box := Dialog new.
       
  2501         box addTextLabel:'hello'.
       
  2502         l2 := box addTextLabel:'hello2'.
       
  2503         box addOkButton.
       
  2504         box stickAtBottomWithFixHeight:l2.
       
  2505         box show
       
  2506    "
       
  2507 
       
  2508     "Created: 27.1.1996 / 17:17:41 / cg"
       
  2509     "Modified: 27.1.1996 / 18:29:03 / cg"
       
  2510 !
       
  2511 
       
  2512 stickAtBottomWithVariableHeight:aComponent
       
  2513     "arrange for a component to be positioned at a constant offset
       
  2514      from the bottom of the box and its height to be adjusted.
       
  2515      This will resize the component for a constant distance from the top,
       
  2516      and the bottom.
       
  2517      (without this setup, its height would remain constant)"
       
  2518 
       
  2519     self resize.
       
  2520 
       
  2521     aComponent
       
  2522         bottomInset:(self height - aComponent bottom); 
       
  2523         corner:1.0@1.0.
       
  2524 
       
  2525     "
       
  2526      compare the resizing behavior of:
       
  2527 
       
  2528         |box|
       
  2529 
       
  2530         box := Dialog new.
       
  2531         box addTextLabel:'hello'.
       
  2532         (box addComponent:(SelectionInListView new)) level:-1.
       
  2533         box addOkButton.
       
  2534         box show
       
  2535 
       
  2536      with:
       
  2537 
       
  2538         |box list|
       
  2539 
       
  2540         box := Dialog new.
       
  2541         box addTextLabel:'hello'.
       
  2542         list := (box addComponent:(SelectionInListView new)) level:-1.
       
  2543         box addOkButton.
       
  2544         box stickAtBottomWithVariableHeight:list.
       
  2545         box show
       
  2546    "
       
  2547 
       
  2548     "Modified: 27.1.1996 / 18:27:36 / cg"
  2430 ! !
  2549 ! !
  2431 
  2550 
  2432 !DialogBox methodsFor:'user actions'!
  2551 !DialogBox methodsFor:'user actions'!
  2433 
  2552 
  2434 abortPressed
  2553 abortPressed
  2507 ! !
  2626 ! !
  2508 
  2627 
  2509 !DialogBox class methodsFor:'documentation'!
  2628 !DialogBox class methodsFor:'documentation'!
  2510 
  2629 
  2511 version
  2630 version
  2512     ^ '$Header: /cvs/stx/stx/libwidg/DialogBox.st,v 1.36 1996-01-27 14:16:15 cg Exp $'
  2631     ^ '$Header: /cvs/stx/stx/libwidg/DialogBox.st,v 1.37 1996-01-27 17:30:14 cg Exp $'
  2513 ! !
  2632 ! !