<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: User Control in Archicad C++ API</title>
    <link>https://community.graphisoft.com/t5/Archicad-C-API/User-Control/m-p/195001#M5329</link>
    <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
You can see one UC262 item in the Document -&amp;gt; Pen Sets -&amp;gt; Pens&amp;amp;Colors dialog at the bottom. It has cells, ideal to show pens.&lt;BR /&gt;
&lt;BR /&gt;
I wrote you an example code to try it:&lt;BR /&gt;
&lt;BR /&gt;
The dialog resource:&lt;BR /&gt;

&lt;PRE&gt;'GDLG'  32590  Modal                0    0  327  278  "Pen User Control" {
/* [  1] */ Button				  250    9   61   20	LargePlain  "Close"
/* [  2] */ UserControl			    0   65  327  214	262  0  0  0  0  0 /* Pen */
/* [  3] */ LeftText			   16    9   30   20	LargePlain  vCenter  StaticEdge  ""
/* [  4] */ RightText			   50   11   74   16	LargePlain  vCenter  "Pen Weight:"
/* [  5] */ RealEdit			  129    7   66   24	LargePlain  "0.0"  "100.0"
/* [  6] */ LeftText			  201    2   20   14	SmallPlain  vBottom  "mm"
/* [  7] */ UserControl			  201   17   12   12	257  0x0005  0x0600  0 /*Change mm/Pt*/
/* [  8] */ RightText			   13   41  110   16	LargePlain  vCenter  "Description:"
/* [  9] */ TextEdit			  129   37  182   24	LargePlain  255
}


'DLGH'  32590  DLG_32590_Pen_User_Control {
1	""							Button_0
2	""							UC262_0
3	""							LeftText_0
4	""							RightText_0
5	""							RealEdit_0
6	""							LeftText_1
7	""							UC257_0
8	""							RightText_1
9	""							TextEdit_0
}&lt;/PRE&gt;

The header file:&lt;BR /&gt;

&lt;PRE&gt;// *********************************************************************************************************************
// API Development Kit 18; Mac/Win
//
// Namespaces:        Contact person:
//     -None-						LT
//
// [SG compatible] - Yes
// *********************************************************************************************************************

#ifndef USERCONTROLSDIALOG_HPP
#define USERCONTROLSDIALOG_HPP

#pragma once


// --- Includes --------------------------------------------------------------------------------------------------------

#include	"DG.h"
#include	"UC.h"
#include	"DGModule.hpp"
#include	"UCModule.hpp"
#include	"Array.hpp"


#define USER_CONTROLS_DIALOG_RESID			32590


// --- PenSettingsEditPensPage -----------------------------------------------------------------------------------------

class PenSettingsEditPensPage: public DG::ModalDialog
{
friend class PenSettingsEditPensObserver;

public:
	enum PenWeightUnit {
		NotDefined			= 0,
		PenWeight_MM		= 1,
		PenWeight_Pt		= 2
	};

private:
	enum {
		OkButtonId				= 1,
		PenControlId			= 2,
		PenNumberStaticId		= 3,
		PenWidthStaticId		= 4,
		PenWidthEditId			= 5,
		UnitStaticId			= 6,
		UnitControlId			= 7,
		DescriptionStaticId		= 8,
		PenNameEditId			= 9
	};

	DG::Button			okButton;
	UC::UC262			penControl;
	DG::LeftText		penNumberStatic;
	DG::RightText		penWidthStatic;
	DG::RealEdit		penWidthEdit;
	DG::LeftText		unitStatic;
	UC::UC257			unitControl;
	DG::RightText		descriptionStatic;
	DG::TextEdit		penNameEdit;

	API_Attribute		penAttr;
	PenWeightUnit		penWeightUnit;

	PenWeightUnit		GetPenWeightUnit ();

	void		InitializeUnitMenu (void);
	void		HandleUnitControlChange (Int32 selectedUnit);
	void		UpdatePenControl (void);

public:
	PenSettingsEditPensPage (GSResModule dialResModule, short resId);
   ~PenSettingsEditPensPage ();
};


// --- PenSettingsEditPensObserver -------------------------------------------------------------------------------------

class PenSettingsEditPensObserver:	public DG::PanelObserver,
									public DG::UserControlObserver,
									public DG::ButtonItemObserver,
									public DG::CompoundItemObserver
{
private:
	PenSettingsEditPensPage* dialog;

protected:

	virtual void	PanelOpened (const DG::PanelOpenEvent&amp;amp; ev);

	virtual void	ButtonClicked (const DG::ButtonClickEvent&amp;amp; ev);
	virtual void	UserControlChanged (const DG::UserControlChangeEvent&amp;amp; ev);

public:
	explicit	PenSettingsEditPensObserver (PenSettingsEditPensPage* penSettingsEditPensPage);
			   ~PenSettingsEditPensObserver ();
};

#endif
&lt;/PRE&gt;

The source:&lt;BR /&gt;

&lt;PRE&gt;// *********************************************************************************************************************
// API Development Kit 18; Mac/Win
//
// Namespaces:			Contact person:
//		-None-						LT
//
// [SG compatible] - Yes
// *********************************************************************************************************************

#include	"APIEnvir.h"
#include	"ACAPinc.h"					// also includes APIdefs.h
#include	"GSUtilsDefs.h"

#include	"UserControlsDialog.hpp"


//--------------------------- Attribute_Get helper function -----------------------

GSErrCode Attribute_Get (API_Attribute* attr, const API_AttrTypeID&amp;amp; typeID, const short index)
{
	GSErrCode err = NoError;
	BNZeroMemory (attr, sizeof (API_Attribute));
	attr-&amp;gt;header.typeID = typeID;
	attr-&amp;gt;header.index = index;
	// search by type and index
	err = ACAPI_Attribute_Get (attr);
	if (err != NoError)
		ACAPI_WriteReport ("ACAPI_Attribute_Get failed", true);
	return err;
}


// --- PenSettingsEditPensPage -----------------------------------------------------------------------------------------

PenSettingsEditPensPage::PenSettingsEditPensPage (GSResModule dialResModule, short resId):
	DG::ModalDialog		(dialResModule, resId, dialResModule),

	okButton			(GetReference (), OkButtonId),
	penControl			(GetReference (), PenControlId),
	penNumberStatic		(GetReference (), PenNumberStaticId),
	penWidthStatic		(GetReference (), PenWidthStaticId),
	penWidthEdit		(GetReference (), PenWidthEditId),
	unitStatic			(GetReference (), UnitStaticId),
	unitControl			(GetReference (), UnitControlId),
	descriptionStatic	(GetReference (), DescriptionStaticId),
	penNameEdit			(GetReference (), PenNameEditId),

	penWeightUnit (PenSettingsEditPensPage::NotDefined)
{
	// unit control
	InitializeUnitMenu ();

	penWidthEdit.Disable ();
	penNameEdit.Disable ();
	okButton.SetAsDefault ();

	// Length type units
	penWeightUnit = GetPenWeightUnit ();
}


PenSettingsEditPensPage::~PenSettingsEditPensPage ()
{
}


// ... Private functions of the page ...................................................................................

PenSettingsEditPensPage::PenWeightUnit PenSettingsEditPensPage::GetPenWeightUnit ()
{
	if (penWeightUnit == PenSettingsEditPensPage::NotDefined) {
		DGUnitData	dgUnit;
		DG::GetUnit (&amp;amp;dgUnit);
		if (dgUnit.lengthType == DG_UNIT_FOOT_DECINCH || dgUnit.lengthType == DG_UNIT_FOOT_INCH ||
			dgUnit.lengthType == DG_UNIT_DECINCH      || dgUnit.lengthType == DG_UNIT_DECFOOT   ||
			dgUnit.lengthType == DG_UNIT_INCH)
		{
			penWeightUnit = PenSettingsEditPensPage::PenWeight_Pt;
		} else {
			penWeightUnit = PenSettingsEditPensPage::PenWeight_MM;
		}
	}

	return penWeightUnit;
}


void	PenSettingsEditPensPage::InitializeUnitMenu (void)
{
	short nCells = 2;
	GSSize dataSize = UC257DataSize (nCells);
	GSHandle cntlData = BMAllocateHandle (dataSize, ALLOCATE_CLEAR, 0);
	if (DBERROR (cntlData == NULL))
		return;

	BMhLock (cntlData);
	UC257HeadData*	header = reinterpret_cast&amp;lt;UC257HeadData*&amp;gt; (*cntlData);

	header-&amp;gt;minWidth = 50;
	header-&amp;gt;nColumns = 1;
	header-&amp;gt;nCells = nCells;

	UC257CellData* cell = &amp;amp;header-&amp;gt;cell[0];

	GS::UniString text = "mm";
	GS::snuprintf (cell[0].text, sizeof (cell[0].text), text.ToUStr ());
	cell[0].value = 1;
	cell[0].flags = CF257_VALID | CF257_SHOWTEXT;

	text = "Pt";
	GS::snuprintf (cell[1].text, sizeof (cell[1].text), text.ToUStr ());
	cell[1].value = 2;
	cell[1].flags = CF257_VALID | CF257_SHOWTEXT;

	unitControl.SetCallBack (NULL);

	unitControl.SetControlType (UC::UC257::Text);
	unitControl.SetButtonType (UC::UC257::SmallButton);
	unitControl.SetPaletteType (UC::UC257::PlainPalette);
	unitControl.SetFontType (UC::UC257::SmallFont);
	unitControl.SetData (*cntlData, 0, dataSize);
	BMhUnlock (cntlData);
	BMKillHandle (&amp;amp;cntlData);
}


void	PenSettingsEditPensPage::HandleUnitControlChange (Int32 selectedUnit)
{
	double penWidth = penAttr.pen.width;;
	if (selectedUnit == PenSettingsEditPensPage::PenWeight_Pt)
		penWidth *= MM_TO_POINT;
	penWidthEdit.SetValue (penWidth);

	GS::UniString str = (selectedUnit == PenSettingsEditPensPage::PenWeight_MM) ? "mm" : "Pt";
	unitStatic.SetText (str);
}


void	PenSettingsEditPensPage::UpdatePenControl (void)
{
	short penCount = 0;
	ACAPI_Attribute_GetNum (API_PenID, &amp;amp;penCount);

	penControl.Setup (penCount, 13, 20);
	for (short cellIndex = 1; cellIndex &amp;lt;= penCount; cellIndex++) {
		API_Attribute attr;
		Attribute_Get (&amp;amp;attr, API_PenID, cellIndex);
		Gfx::Color color;
		color.Set ((unsigned char) (attr.pen.rgb.f_red * 255.0),
				 (unsigned char) (attr.pen.rgb.f_green * 255.0),
				 (unsigned char) (attr.pen.rgb.f_blue * 255.0));
		penControl.SetCellData (cellIndex, cellIndex, false, CCF262_USEDPEN, color.GetRed (), color.GetGreen (),
								color.GetBlue (), GS::UniString (), GS::UniString ());
	}
	penControl.Redraw ();
}


// --- PenSettingsEditPensObserver -------------------------------------------------------------------------------------

PenSettingsEditPensObserver::PenSettingsEditPensObserver (PenSettingsEditPensPage* penSettingsEditPensPage):
	dialog (penSettingsEditPensPage)
{
	dialog-&amp;gt;Attach (*this);
	AttachToAllItems (*dialog);
}


PenSettingsEditPensObserver::~PenSettingsEditPensObserver ()
{
	dialog-&amp;gt;Detach (*this);
	DetachFromAllItems (*dialog);
	dialog = NULL;
}

void	PenSettingsEditPensObserver::PanelOpened (const DG::PanelOpenEvent&amp;amp; /*ev*/)
{
	short penId = 1;
	dialog-&amp;gt;penControl.SetValue (penId);
	Attribute_Get (&amp;amp;dialog-&amp;gt;penAttr, API_PenID, penId);

	GS::UniString str = GS::UniString::Printf ("%u", penId);
	dialog-&amp;gt;penNumberStatic.SetText (str);

	dialog-&amp;gt;unitControl.SetValue (dialog-&amp;gt;penWeightUnit);
	dialog-&amp;gt;HandleUnitControlChange (dialog-&amp;gt;penWeightUnit);

	str = dialog-&amp;gt;penAttr.pen.description;
	dialog-&amp;gt;penNameEdit.SetText (str);

	dialog-&amp;gt;UpdatePenControl ();
}


void	PenSettingsEditPensObserver::UserControlChanged (const DG::UserControlChangeEvent&amp;amp; ev)
{
	if (ev.GetSource () == &amp;amp;dialog-&amp;gt;penControl) {
		short penId = dialog-&amp;gt;penControl.GetValue ();
		Attribute_Get (&amp;amp;dialog-&amp;gt;penAttr, API_PenID, penId);

		GS::UniString str = GS::UniString::Printf ("%u", penId);
		dialog-&amp;gt;penNumberStatic.SetText (str);

		dialog-&amp;gt;HandleUnitControlChange (dialog-&amp;gt;unitControl.GetValue ());

		str = dialog-&amp;gt;penAttr.pen.description;
		dialog-&amp;gt;penNameEdit.SetText (str);
	} else if (ev.GetSource () == &amp;amp;dialog-&amp;gt;unitControl) {
		dialog-&amp;gt;HandleUnitControlChange (dialog-&amp;gt;unitControl.GetValue ());
	}
}


void	PenSettingsEditPensObserver::ButtonClicked (const DG::ButtonClickEvent&amp;amp; ev)
{
	if (ev.GetSource () == &amp;amp;dialog-&amp;gt;okButton) {
		dialog-&amp;gt;PostCloseRequest (DG::ModalDialog::Accept);
	}
}&lt;/PRE&gt;

To try:&lt;BR /&gt;

&lt;PRE&gt;	PenSettingsEditPensPage		dialog (ACAPI_GetOwnResModule (), USER_CONTROLS_DIALOG_RESID);
	if (DBERROR (dialog.GetId () == 0)) {
		return;
	}

	PenSettingsEditPensObserver	observer (&amp;amp;dialog);
	dialog.Invoke ();&lt;/PRE&gt;</description>
    <pubDate>Fri, 08 Aug 2014 15:39:59 GMT</pubDate>
    <dc:creator>Tibor Lorantfy</dc:creator>
    <dc:date>2014-08-08T15:39:59Z</dc:date>
    <item>
      <title>User Control</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/User-Control/m-p/195000#M5328</link>
      <description>&lt;DIV class="actalk-migrated-content"&gt;As a newbie to the API, I am still wading through the documentation. Was wondering if anyone has any info on User Control Number 262. I think something to do with color.&lt;BR /&gt;&lt;BR /&gt;I can't find anything in the documentation although it may be buried deep. The header file does not give much info either, other than a couple options - not described. I can't get this control to execute so I can't verify. Although I really have no idea as to what options to use or the tool size requirements.&lt;BR /&gt;&lt;BR /&gt;Archicad 18&lt;/DIV&gt;</description>
      <pubDate>Tue, 01 Aug 2023 12:26:34 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/User-Control/m-p/195000#M5328</guid>
      <dc:creator>poco2013</dc:creator>
      <dc:date>2023-08-01T12:26:34Z</dc:date>
    </item>
    <item>
      <title>Re: User Control</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/User-Control/m-p/195001#M5329</link>
      <description>Hi,&lt;BR /&gt;
&lt;BR /&gt;
You can see one UC262 item in the Document -&amp;gt; Pen Sets -&amp;gt; Pens&amp;amp;Colors dialog at the bottom. It has cells, ideal to show pens.&lt;BR /&gt;
&lt;BR /&gt;
I wrote you an example code to try it:&lt;BR /&gt;
&lt;BR /&gt;
The dialog resource:&lt;BR /&gt;

&lt;PRE&gt;'GDLG'  32590  Modal                0    0  327  278  "Pen User Control" {
/* [  1] */ Button				  250    9   61   20	LargePlain  "Close"
/* [  2] */ UserControl			    0   65  327  214	262  0  0  0  0  0 /* Pen */
/* [  3] */ LeftText			   16    9   30   20	LargePlain  vCenter  StaticEdge  ""
/* [  4] */ RightText			   50   11   74   16	LargePlain  vCenter  "Pen Weight:"
/* [  5] */ RealEdit			  129    7   66   24	LargePlain  "0.0"  "100.0"
/* [  6] */ LeftText			  201    2   20   14	SmallPlain  vBottom  "mm"
/* [  7] */ UserControl			  201   17   12   12	257  0x0005  0x0600  0 /*Change mm/Pt*/
/* [  8] */ RightText			   13   41  110   16	LargePlain  vCenter  "Description:"
/* [  9] */ TextEdit			  129   37  182   24	LargePlain  255
}


'DLGH'  32590  DLG_32590_Pen_User_Control {
1	""							Button_0
2	""							UC262_0
3	""							LeftText_0
4	""							RightText_0
5	""							RealEdit_0
6	""							LeftText_1
7	""							UC257_0
8	""							RightText_1
9	""							TextEdit_0
}&lt;/PRE&gt;

The header file:&lt;BR /&gt;

&lt;PRE&gt;// *********************************************************************************************************************
// API Development Kit 18; Mac/Win
//
// Namespaces:        Contact person:
//     -None-						LT
//
// [SG compatible] - Yes
// *********************************************************************************************************************

#ifndef USERCONTROLSDIALOG_HPP
#define USERCONTROLSDIALOG_HPP

#pragma once


// --- Includes --------------------------------------------------------------------------------------------------------

#include	"DG.h"
#include	"UC.h"
#include	"DGModule.hpp"
#include	"UCModule.hpp"
#include	"Array.hpp"


#define USER_CONTROLS_DIALOG_RESID			32590


// --- PenSettingsEditPensPage -----------------------------------------------------------------------------------------

class PenSettingsEditPensPage: public DG::ModalDialog
{
friend class PenSettingsEditPensObserver;

public:
	enum PenWeightUnit {
		NotDefined			= 0,
		PenWeight_MM		= 1,
		PenWeight_Pt		= 2
	};

private:
	enum {
		OkButtonId				= 1,
		PenControlId			= 2,
		PenNumberStaticId		= 3,
		PenWidthStaticId		= 4,
		PenWidthEditId			= 5,
		UnitStaticId			= 6,
		UnitControlId			= 7,
		DescriptionStaticId		= 8,
		PenNameEditId			= 9
	};

	DG::Button			okButton;
	UC::UC262			penControl;
	DG::LeftText		penNumberStatic;
	DG::RightText		penWidthStatic;
	DG::RealEdit		penWidthEdit;
	DG::LeftText		unitStatic;
	UC::UC257			unitControl;
	DG::RightText		descriptionStatic;
	DG::TextEdit		penNameEdit;

	API_Attribute		penAttr;
	PenWeightUnit		penWeightUnit;

	PenWeightUnit		GetPenWeightUnit ();

	void		InitializeUnitMenu (void);
	void		HandleUnitControlChange (Int32 selectedUnit);
	void		UpdatePenControl (void);

public:
	PenSettingsEditPensPage (GSResModule dialResModule, short resId);
   ~PenSettingsEditPensPage ();
};


// --- PenSettingsEditPensObserver -------------------------------------------------------------------------------------

class PenSettingsEditPensObserver:	public DG::PanelObserver,
									public DG::UserControlObserver,
									public DG::ButtonItemObserver,
									public DG::CompoundItemObserver
{
private:
	PenSettingsEditPensPage* dialog;

protected:

	virtual void	PanelOpened (const DG::PanelOpenEvent&amp;amp; ev);

	virtual void	ButtonClicked (const DG::ButtonClickEvent&amp;amp; ev);
	virtual void	UserControlChanged (const DG::UserControlChangeEvent&amp;amp; ev);

public:
	explicit	PenSettingsEditPensObserver (PenSettingsEditPensPage* penSettingsEditPensPage);
			   ~PenSettingsEditPensObserver ();
};

#endif
&lt;/PRE&gt;

The source:&lt;BR /&gt;

&lt;PRE&gt;// *********************************************************************************************************************
// API Development Kit 18; Mac/Win
//
// Namespaces:			Contact person:
//		-None-						LT
//
// [SG compatible] - Yes
// *********************************************************************************************************************

#include	"APIEnvir.h"
#include	"ACAPinc.h"					// also includes APIdefs.h
#include	"GSUtilsDefs.h"

#include	"UserControlsDialog.hpp"


//--------------------------- Attribute_Get helper function -----------------------

GSErrCode Attribute_Get (API_Attribute* attr, const API_AttrTypeID&amp;amp; typeID, const short index)
{
	GSErrCode err = NoError;
	BNZeroMemory (attr, sizeof (API_Attribute));
	attr-&amp;gt;header.typeID = typeID;
	attr-&amp;gt;header.index = index;
	// search by type and index
	err = ACAPI_Attribute_Get (attr);
	if (err != NoError)
		ACAPI_WriteReport ("ACAPI_Attribute_Get failed", true);
	return err;
}


// --- PenSettingsEditPensPage -----------------------------------------------------------------------------------------

PenSettingsEditPensPage::PenSettingsEditPensPage (GSResModule dialResModule, short resId):
	DG::ModalDialog		(dialResModule, resId, dialResModule),

	okButton			(GetReference (), OkButtonId),
	penControl			(GetReference (), PenControlId),
	penNumberStatic		(GetReference (), PenNumberStaticId),
	penWidthStatic		(GetReference (), PenWidthStaticId),
	penWidthEdit		(GetReference (), PenWidthEditId),
	unitStatic			(GetReference (), UnitStaticId),
	unitControl			(GetReference (), UnitControlId),
	descriptionStatic	(GetReference (), DescriptionStaticId),
	penNameEdit			(GetReference (), PenNameEditId),

	penWeightUnit (PenSettingsEditPensPage::NotDefined)
{
	// unit control
	InitializeUnitMenu ();

	penWidthEdit.Disable ();
	penNameEdit.Disable ();
	okButton.SetAsDefault ();

	// Length type units
	penWeightUnit = GetPenWeightUnit ();
}


PenSettingsEditPensPage::~PenSettingsEditPensPage ()
{
}


// ... Private functions of the page ...................................................................................

PenSettingsEditPensPage::PenWeightUnit PenSettingsEditPensPage::GetPenWeightUnit ()
{
	if (penWeightUnit == PenSettingsEditPensPage::NotDefined) {
		DGUnitData	dgUnit;
		DG::GetUnit (&amp;amp;dgUnit);
		if (dgUnit.lengthType == DG_UNIT_FOOT_DECINCH || dgUnit.lengthType == DG_UNIT_FOOT_INCH ||
			dgUnit.lengthType == DG_UNIT_DECINCH      || dgUnit.lengthType == DG_UNIT_DECFOOT   ||
			dgUnit.lengthType == DG_UNIT_INCH)
		{
			penWeightUnit = PenSettingsEditPensPage::PenWeight_Pt;
		} else {
			penWeightUnit = PenSettingsEditPensPage::PenWeight_MM;
		}
	}

	return penWeightUnit;
}


void	PenSettingsEditPensPage::InitializeUnitMenu (void)
{
	short nCells = 2;
	GSSize dataSize = UC257DataSize (nCells);
	GSHandle cntlData = BMAllocateHandle (dataSize, ALLOCATE_CLEAR, 0);
	if (DBERROR (cntlData == NULL))
		return;

	BMhLock (cntlData);
	UC257HeadData*	header = reinterpret_cast&amp;lt;UC257HeadData*&amp;gt; (*cntlData);

	header-&amp;gt;minWidth = 50;
	header-&amp;gt;nColumns = 1;
	header-&amp;gt;nCells = nCells;

	UC257CellData* cell = &amp;amp;header-&amp;gt;cell[0];

	GS::UniString text = "mm";
	GS::snuprintf (cell[0].text, sizeof (cell[0].text), text.ToUStr ());
	cell[0].value = 1;
	cell[0].flags = CF257_VALID | CF257_SHOWTEXT;

	text = "Pt";
	GS::snuprintf (cell[1].text, sizeof (cell[1].text), text.ToUStr ());
	cell[1].value = 2;
	cell[1].flags = CF257_VALID | CF257_SHOWTEXT;

	unitControl.SetCallBack (NULL);

	unitControl.SetControlType (UC::UC257::Text);
	unitControl.SetButtonType (UC::UC257::SmallButton);
	unitControl.SetPaletteType (UC::UC257::PlainPalette);
	unitControl.SetFontType (UC::UC257::SmallFont);
	unitControl.SetData (*cntlData, 0, dataSize);
	BMhUnlock (cntlData);
	BMKillHandle (&amp;amp;cntlData);
}


void	PenSettingsEditPensPage::HandleUnitControlChange (Int32 selectedUnit)
{
	double penWidth = penAttr.pen.width;;
	if (selectedUnit == PenSettingsEditPensPage::PenWeight_Pt)
		penWidth *= MM_TO_POINT;
	penWidthEdit.SetValue (penWidth);

	GS::UniString str = (selectedUnit == PenSettingsEditPensPage::PenWeight_MM) ? "mm" : "Pt";
	unitStatic.SetText (str);
}


void	PenSettingsEditPensPage::UpdatePenControl (void)
{
	short penCount = 0;
	ACAPI_Attribute_GetNum (API_PenID, &amp;amp;penCount);

	penControl.Setup (penCount, 13, 20);
	for (short cellIndex = 1; cellIndex &amp;lt;= penCount; cellIndex++) {
		API_Attribute attr;
		Attribute_Get (&amp;amp;attr, API_PenID, cellIndex);
		Gfx::Color color;
		color.Set ((unsigned char) (attr.pen.rgb.f_red * 255.0),
				 (unsigned char) (attr.pen.rgb.f_green * 255.0),
				 (unsigned char) (attr.pen.rgb.f_blue * 255.0));
		penControl.SetCellData (cellIndex, cellIndex, false, CCF262_USEDPEN, color.GetRed (), color.GetGreen (),
								color.GetBlue (), GS::UniString (), GS::UniString ());
	}
	penControl.Redraw ();
}


// --- PenSettingsEditPensObserver -------------------------------------------------------------------------------------

PenSettingsEditPensObserver::PenSettingsEditPensObserver (PenSettingsEditPensPage* penSettingsEditPensPage):
	dialog (penSettingsEditPensPage)
{
	dialog-&amp;gt;Attach (*this);
	AttachToAllItems (*dialog);
}


PenSettingsEditPensObserver::~PenSettingsEditPensObserver ()
{
	dialog-&amp;gt;Detach (*this);
	DetachFromAllItems (*dialog);
	dialog = NULL;
}

void	PenSettingsEditPensObserver::PanelOpened (const DG::PanelOpenEvent&amp;amp; /*ev*/)
{
	short penId = 1;
	dialog-&amp;gt;penControl.SetValue (penId);
	Attribute_Get (&amp;amp;dialog-&amp;gt;penAttr, API_PenID, penId);

	GS::UniString str = GS::UniString::Printf ("%u", penId);
	dialog-&amp;gt;penNumberStatic.SetText (str);

	dialog-&amp;gt;unitControl.SetValue (dialog-&amp;gt;penWeightUnit);
	dialog-&amp;gt;HandleUnitControlChange (dialog-&amp;gt;penWeightUnit);

	str = dialog-&amp;gt;penAttr.pen.description;
	dialog-&amp;gt;penNameEdit.SetText (str);

	dialog-&amp;gt;UpdatePenControl ();
}


void	PenSettingsEditPensObserver::UserControlChanged (const DG::UserControlChangeEvent&amp;amp; ev)
{
	if (ev.GetSource () == &amp;amp;dialog-&amp;gt;penControl) {
		short penId = dialog-&amp;gt;penControl.GetValue ();
		Attribute_Get (&amp;amp;dialog-&amp;gt;penAttr, API_PenID, penId);

		GS::UniString str = GS::UniString::Printf ("%u", penId);
		dialog-&amp;gt;penNumberStatic.SetText (str);

		dialog-&amp;gt;HandleUnitControlChange (dialog-&amp;gt;unitControl.GetValue ());

		str = dialog-&amp;gt;penAttr.pen.description;
		dialog-&amp;gt;penNameEdit.SetText (str);
	} else if (ev.GetSource () == &amp;amp;dialog-&amp;gt;unitControl) {
		dialog-&amp;gt;HandleUnitControlChange (dialog-&amp;gt;unitControl.GetValue ());
	}
}


void	PenSettingsEditPensObserver::ButtonClicked (const DG::ButtonClickEvent&amp;amp; ev)
{
	if (ev.GetSource () == &amp;amp;dialog-&amp;gt;okButton) {
		dialog-&amp;gt;PostCloseRequest (DG::ModalDialog::Accept);
	}
}&lt;/PRE&gt;

To try:&lt;BR /&gt;

&lt;PRE&gt;	PenSettingsEditPensPage		dialog (ACAPI_GetOwnResModule (), USER_CONTROLS_DIALOG_RESID);
	if (DBERROR (dialog.GetId () == 0)) {
		return;
	}

	PenSettingsEditPensObserver	observer (&amp;amp;dialog);
	dialog.Invoke ();&lt;/PRE&gt;</description>
      <pubDate>Fri, 08 Aug 2014 15:39:59 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/User-Control/m-p/195001#M5329</guid>
      <dc:creator>Tibor Lorantfy</dc:creator>
      <dc:date>2014-08-08T15:39:59Z</dc:date>
    </item>
    <item>
      <title>Re: User Control</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/User-Control/m-p/195002#M5330</link>
      <description>Thanks for the response and the code. I now understand the usage of control 262 based on its use in archicad. I was confused because the User Control documentation stops at 261. However, I wasn't able to compile your code. Pardon the rookie question but I get an "can't find the header DrawDialogItems.hpp error. I assume you want to name the program  header, UserControlsDialog.hpp, but where would  DrawDialogItems.hpp be.&lt;BR /&gt;
&lt;BR /&gt;
I'm not at all familiar with the protocol here. -- Sorry, but thanks again for the code!!.</description>
      <pubDate>Sat, 09 Aug 2014 00:52:28 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/User-Control/m-p/195002#M5330</guid>
      <dc:creator>poco2013</dc:creator>
      <dc:date>2014-08-09T00:52:28Z</dc:date>
    </item>
    <item>
      <title>Re: User Control</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/User-Control/m-p/195003#M5331</link>
      <description>&lt;BLOCKQUOTE&gt;poco2013 wrote:&lt;BR /&gt;I get an "can't find the header DrawDialogItems.hpp error&lt;/BLOCKQUOTE&gt;

Sorry, that was one of my private header files.&lt;BR /&gt;
I updated my code, deleted that include and added Attribute_Get helper function.</description>
      <pubDate>Mon, 11 Aug 2014 08:29:54 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/User-Control/m-p/195003#M5331</guid>
      <dc:creator>Tibor Lorantfy</dc:creator>
      <dc:date>2014-08-11T08:29:54Z</dc:date>
    </item>
    <item>
      <title>Re: User Control</title>
      <link>https://community.graphisoft.com/t5/Archicad-C-API/User-Control/m-p/195004#M5332</link>
      <description>Thanks for the revised code and the Attribute_get Function which was also one of the missing identifier errors.&lt;BR /&gt;
&lt;BR /&gt;
Got your code to compile -- Thanks -- Still experimenting</description>
      <pubDate>Mon, 11 Aug 2014 11:01:48 GMT</pubDate>
      <guid>https://community.graphisoft.com/t5/Archicad-C-API/User-Control/m-p/195004#M5332</guid>
      <dc:creator>poco2013</dc:creator>
      <dc:date>2014-08-11T11:01:48Z</dc:date>
    </item>
  </channel>
</rss>

