[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.platform.swt] Re: Text Field with buttons in it

TextField is drawn next to buttons, so if SWT.Border style is set, buttons wil be out of text field frame.

Now on carbon, gtk and win32 control created like this: composite with borderless text field and buttons (i added red background to text field to illustrate this: http://picasaweb.google.com/lh/photo/a5egjEQDuYLjH96WGSA7bQ?feat=directlink). Then with paint listener a frame is drawn around composite, so buttons and text inside it, like this:

composite.addPaintListener(new PaintListener() {

			public void paintControl(PaintEvent e) {

				int [] context = new int [1];
				context[0] = e.gc.handle;
				OS.CGContextSaveGState (context[0]);
				int [] outMetric = new int [1];
				OS.GetThemeMetric (OS.kThemeMetricFocusRectOutset, outMetric);
				CGRect rect = new CGRect ();
				OS.HIViewGetBounds (handle, rect);
				rect.x += outMetric [0] + 1;
				rect.y += outMetric [0];
				rect.width -= outMetric [0] * 2 + 2;
				rect.height -= outMetric [0] * 2;
				int state = 0;
				if (OS.IsControlEnabled (text.handle)) {
					state = OS.IsControlActive (text.handle) ? OS.kThemeStateActive : OS.kThemeStateInactive;
				} else {
					state = OS.IsControlActive (text.handle) ? OS.kThemeStateUnavailable : OS.kThemeStateUnavailableInactive;
				}
				HIThemeFrameDrawInfo info = new HIThemeFrameDrawInfo ();
				info.state = state;
				info.isFocused = text.isFocusControl();
				info.kind = OS.kHIThemeFrameTextFieldSquare;
				OS.HIThemeDrawFrame (rect, info, context [0], OS.kHIThemeOrientationNormal);
				OS.CGContextRestoreGState (context[0]);
				
			}
		});

The problem was that in cocoa there i could not find a method to draw simple frame. And i thought, maybe this design was a bit odd and there is a better way to do text field with buttons.