cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
Showing results for 
Search instead for 
Did you mean: 

Streamline your workflows and master BIM coordination! Program starts April 28!

Archicad C++ API
About Archicad add-on development using the C++ API.
SOLVED!

Default draw of an OwnerDraw ListBox TabField

Oleg
Expert

Inside ListBoxTabFieldUpdate event handler, I need in some ListBox items to draw tabfield just like it has no owner draw flag. TabField can contans icon and trext, has different justification, font, color. It may be disabled etc.
To implement generic function is not trivial task.

May be there is any function(s) or simple method to draw ListBox's tab field as default ?


1 ACCEPTED SOLUTION

Accepted Solutions
Solution

Sorry, but the answer is no. The owner drawn status is set to the whole column of the listbox. So all tab fields in that column will be owner drawn for each list row and the listbox will not draw any content for those tabfields. So you should do the necessary drawing regardless if it is a simple text only.

You can to use the DG::Utils::DrawText function in that case.

 

There is an other ownerdrawn capability of a listbox that behaves a bit different way. You can set ownerdrawn status for any arbitrary listbox item (for whole listbox rows) with the void SetItemOwnerDrawFlag (short listItem, bool isOwnerDrawn) function. In this case the listbox draws the content of the entire row first, and then sends the drawing context to the listbox observer with the ListBoxItemUpdateEvent notification. This context contain the area of all tabfields.

View solution in original post

3 REPLIES 3
Miklos Vegh
Graphisoft
Graphisoft

Hi, you can get the drawing context of the listbox tabfield easily then draw anything on that surface. Please check this sample code:

void	SampleDialog::ListBoxTabFieldUpdate (const DG::ListBoxTabItemUpdateEvent& ev)
{
	if (ev.GetSource () == &sampleListBox) {
		NewDisplay::ListBoxUpdateEventContext context (ev); // This context represents the drawing surface
		if (ev.GetTabFieldIndex () == OwnerDrawColumn) {
			const short tabFieldWidth = sampleListBox.GetTabFieldEndPosition (OwnerDrawColumn) - userList.GetTabFieldBeginPosition (OwnerDrawColumn);
			const short tabFieldHeight = sampleListBox.GetItemHeight ();

			// Fill the whole tab field with a blue color
			DG::Rect rc (0, 0, tabFieldWidth, tabFieldHeight);
			Gfx::Color blue (0x00, 0x00, 0xFF);
			bool drawFrame = true;
			DG::Utils::FillRect (context, rc, blue, drawFrame);

			// Draw a text
			GS::UniString text = "Owner Draw Column";
			DG::Rect textRect (0, 0, tabFieldWidth, tabFieldHeight);
			DG::Utils::DrawText (context, textRect, text, DG_IS_LARGE | DG_IS_PLAIN, DG_IS_LEFT, true);

			// Draw an icon
			DG::Rect iconRect (0, 0, tabFieldWidth, tabFieldHeight);
			DG::Icon icon (resModule, iconId); // Replace with your icon ID
			double resolutionFactor = sampleListBox.GetResolutionFactor ();
			DG::Utils::DrawIcon (context, iconRect, icon, resolutionFactor);

			// Draw a NativeImage
			NewDisplay::NativeImage image (...);
			context.DrawImage (image, 1, 1, 0, 0, 0, false, 1.0, NewDisplay::HighQuality);

		} else if (ev.GetTabFieldIndex () == AnotherOwnerDrawColumn) {
			// ...
		}
	}
}

 

Thank you for reply.  My english is not clear, sorry.

Imagine you has owner draw tabfield. In some list box rows ( items), the tabfield draws by functions you show above.
In other listbox rows, the tabfiled should be like it is not owner draw (defaut). 
May be there is a function like DrawListBoxTabFieldAsDrfault, or flag like 'unprocessed', or call base class method like BaseClass::ListBoxTabFiledUpdate or other trick, to call it for some listbox items ?

Simple example:

Oleg_1-1744639311807.png


Lets rows 1 and 2 is custom draw. But last total row actually is not, and I need to draw it too.
It is not big issue in this case. But sometimes, in general, it may be is no so trivial.

Solution

Sorry, but the answer is no. The owner drawn status is set to the whole column of the listbox. So all tab fields in that column will be owner drawn for each list row and the listbox will not draw any content for those tabfields. So you should do the necessary drawing regardless if it is a simple text only.

You can to use the DG::Utils::DrawText function in that case.

 

There is an other ownerdrawn capability of a listbox that behaves a bit different way. You can set ownerdrawn status for any arbitrary listbox item (for whole listbox rows) with the void SetItemOwnerDrawFlag (short listItem, bool isOwnerDrawn) function. In this case the listbox draws the content of the entire row first, and then sends the drawing context to the listbox observer with the ListBoxItemUpdateEvent notification. This context contain the area of all tabfields.

Didn't find the answer?

Check other topics in this Forum

Back to Forum

Read the latest accepted solutions!

Accepted Solutions

Start a new conversation!