Re: 16x16 icons and getImageBlock - I'm still struggling to get the right icon...
- From: Udo Schneider <Udo.Schneider@xxxxxxxxxxxxxx>
- Date: Sun, 29 Jul 2007 09:43:57 +0200
Hi Tim,
the attached package adds a few methods which might be convient for you. In your case Icon>>copyExtentSmall, Icon>>copyExtentLarge and Icon>>copyExtent: might be interesting. As the name suggests these methods do return an icon with a specified extent. You can either provide your own extent or choose the system small/large default ones. So with this package in place your code would change to:
YourClass>>planningIcon
| iconName |
iconName := self wasAdded ifTrue: ['plus.ico'] ifFalse: [ 'minus.ico' ].
^(Icon fromId: MyAppBase defaultPath, iconName) copyExtentSmall.
However I would add caching for those copied icons. If you do not then everytime this method is called a new copy of the icon is created. And AFAIK the underlying WinImageList uses the Icon as keys into the image list. Thus it would create a new ImageList entry everytime.
I would do something like:
YourClass>>planningIcon
| iconName |
iconName := self wasAdded ifTrue: ['plus.ico'] ifFalse: ['minus.ico'].
^cachedIcons at: iconName
ifAbsentPut: [(Icon fromId: MyAppBase defaultPath , iconName) copyExtentSmall]
CU,
Udo
| package |
package := Package name: 'US Runtime Patches'.
package paxVersion: 1;
basicComment: 'US Runtime Patches
Patches several glitches (mainly UI) in Dolphin Applications
Version 0.04, April 2007
For version 6 of Dolphin Smalltalk
(c) 2007, Udo Schneider <Udo.Schneider@xxxxxxxxxxxxxx>
Notifyware
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
* The author /should/ (no must) be notified of the Software''s use
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
'.
package basicPackageVersion: '0.007'.
package methodNames
add: #Canvas -> #fillRectangle:startColor:endColor:verticalGradient:;
add: #CheckBox -> #onColorRequired:;
add: #Icon -> #copyExtent:;
add: #Icon -> #copyExtentLarge;
add: #Icon -> #copyExtentSmall;
add: #Icon -> #createHandleWithExtent:;
add: #Icon -> #loadFromInstance:extent:;
add: #ImageView -> #paintImageOn:;
add: #ShellView -> #updateIcons;
add: #Splitter -> #onPaintRequired:;
yourself.
package binaryGlobalNames: (Set new
yourself).
package globalAliases: (Set new
yourself).
package setPrerequisites: (IdentitySet new
add: 'S:\Dolphin Smalltalk X6\Object Arts\Dolphin\Base\Dolphin';
add: 'S:\Dolphin Smalltalk X6\Object Arts\Dolphin\MVP\Presenters\Image\Dolphin Image Presenter';
add: 'S:\Dolphin Smalltalk X6\Object Arts\Dolphin\MVP\Base\Dolphin MVP Base';
yourself).
package!
"Class Definitions"!
"Global Aliases"!
"Loose Methods"!
!Canvas methodsFor!
fillRectangle: aRectangle startColor: startColor endColor: endColor verticalGradient: aBoolean
"Added startPosition for first Vertex. Original code didn't do that and therefor always assumed 0@0 as origin"
| vertices gRect |
#USChanged .
vertices := StructureArray length: 2 elementClass: TRIVERTEX.
(vertices at: 1)
color: startColor;
position: aRectangle origin.
(vertices at: 2)
color: endColor;
position: aRectangle corner.
gRect := GRADIENT_RECT new.
gRect
upperLeft: 0;
lowerRight: 1.
^Msimg32Library default
gradientFill: self asParameter
pVertex: vertices
dwNumVertex: 2
pMesh: gRect
dwNumMesh: 1
dwMode: (aBoolean ifTrue: [GRADIENT_FILL_RECT_V] ifFalse: [GRADIENT_FILL_RECT_H])! !
!Canvas categoriesFor: #fillRectangle:startColor:endColor:verticalGradient:!*-not in class package!drawing!public! !
!CheckBox methodsFor!
onColorRequired: aColorEvent
"Private - Workaround XP bug whereby themed checkboxes are drawn against a
solid black background when using a null brush."
| canvas back brush | #USAdded.
back := self basicActualBackcolor.
canvas := aColorEvent canvas.
self forecolor ifNotNil: [:fore | canvas forecolor: fore].
back isDefault ifTrue: [^nil].
brush := back brush.
back isNone
ifTrue:
[self isThemed
ifTrue:
[ThemeLibrary default
drawThemeParentBackground: self asParameter
hdc: canvas asParameter
prc: nil].
canvas backgroundMode: TRANSPARENT]
ifFalse: [canvas backcolor: back].
canvas brush: brush.
^brush asParameter! !
!CheckBox categoriesFor: #onColorRequired:!*-not in class package!private! !
!Icon methodsFor!
copyExtent: aPoint
"Returns a copy of the icon with an preferred extent"
#USAdded.
^self class fromOwnedHandle: (self createHandleWithExtent: aPoint)!
copyExtentLarge
"Returns a copy of the icon with an large Icon extent"
#USAdded.
^self class fromOwnedHandle: (self createHandleWithExtent: SystemMetrics current largeIconExtent)!
copyExtentSmall
"Returns a copy of the icon with an small Icon extent"
#USAdded.
^self class fromOwnedHandle: (self createHandleWithExtent: SystemMetrics current smallIconExtent)!
createHandleWithExtent: extent
"Returns a new handle of the icon with an preferred extent"
| spec |
#USAdded.
instanceHandle notNil
ifTrue: [(self loadFromInstance: instanceHandle extent: extent) ifNotNil: [:hImage | ^hImage]].
spec := self fileSpec.
spec isInteger ifFalse: [(self loadFromFile: spec extent: extent) ifNotNil: [:hImage | ^hImage]].
^(self loadFromInstance: SessionManager current defaultResourceLibrary extent: extent)
ifNil: [self class question handle]!
loadFromInstance: hModule extent: aPoint
^UserLibrary default
loadImage: hModule asParameter
lpszName: identifier asParameter
uType: self imageType
cxDesired: aPoint x
cyDesired: aPoint y
fuLoad: LR_DEFAULTCOLOR! !
!Icon categoriesFor: #copyExtent:!*-not in class package!public! !
!Icon categoriesFor: #copyExtentLarge!*-not in class package!public! !
!Icon categoriesFor: #copyExtentSmall!*-not in class package!public! !
!Icon categoriesFor: #createHandleWithExtent:!*-not in class package!public! !
!Icon categoriesFor: #loadFromInstance:extent:!*-not in class package!public! !
!ImageView methodsFor!
paintImageOn: aCanvas
"Added halftone blitting to prevent artefacts when image is scaled"
#USChanged.
^(image isNil or: [image handle isNull])
ifFalse:
[| rect |
rect := self calcRectangle.
aCanvas stretchBlitMode: HALFTONE.
image
drawOn: aCanvas
at: rect topLeft
extent: rect extent.
rect]! !
!ImageView categoriesFor: #paintImageOn:!*-not in class package!event handling!private! !
!ShellView methodsFor!
updateIcons
"Private - Update the large and small icons of the receiver"
"Patched to force the system to use small and large extent Icons"
| actualLargeIcon actualSmallIcon |
#USChanged.
actualLargeIcon := (largeIcon notNil ifTrue: [largeIcon] ifFalse: [self icon]) copyExtentLarge.
self propertyAt: #largeIcon put: actualLargeIcon.
self
sendMessage: WM_SETICON
wParam: 1
lParam: actualLargeIcon asParameter.
smallIcon notNil
ifTrue:
[actualSmallIcon := smallIcon copyExtentSmall.
self propertyAt: #smallIcon put: actualSmallIcon.
self
sendMessage: WM_SETICON
wParam: 0
lParam: actualSmallIcon asParameter]! !
!ShellView categoriesFor: #updateIcons!*-not in class package!accessing!public! !
!Splitter methodsFor!
onPaintRequired: aPaintEvent
"Fixed from self rectangle to self clientRectangle"
#USChanged.
aPaintEvent canvas
fillRectangle: self clientRectangle
startColor: self forecolor
endColor: self actualBackcolor
verticalGradient: self isVertical! !
!Splitter categoriesFor: #onPaintRequired:!*-not in class package!event handling!private! !
"End of package definition"!
"Source Globals"!
"Classes"!
"Binary Globals"!
- Follow-Ups:
- References:
- Prev by Date: Re: 16x16 icons and getImageBlock - I'm still struggling to get the
- Next by Date: Re: 16x16 icons and getImageBlock - I'm still struggling to get theright icon...
- Previous by thread: Re: 16x16 icons and getImageBlock - I'm still struggling to get the
- Next by thread: Re: 16x16 icons and getImageBlock - I'm still struggling to get theright icon...
- Index(es):
Relevant Pages
|