We value your input! Please participate in Archicad 28 Home Screen and Tooltips/Quick Tutorials survey
2014-08-01 05:48 AM - last edited on 2023-08-01 02:26 PM by Doreena Deng
2014-08-08 05:39 PM
'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 }The header file:
// ********************************************************************************************************************* // 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& ev); virtual void ButtonClicked (const DG::ButtonClickEvent& ev); virtual void UserControlChanged (const DG::UserControlChangeEvent& ev); public: explicit PenSettingsEditPensObserver (PenSettingsEditPensPage* penSettingsEditPensPage); ~PenSettingsEditPensObserver (); }; #endifThe source:
// ********************************************************************************************************************* // 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& typeID, const short index) { GSErrCode err = NoError; BNZeroMemory (attr, sizeof (API_Attribute)); attr->header.typeID = typeID; attr->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 (&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<UC257HeadData*> (*cntlData); header->minWidth = 50; header->nColumns = 1; header->nCells = nCells; UC257CellData* cell = &header->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 (&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, &penCount); penControl.Setup (penCount, 13, 20); for (short cellIndex = 1; cellIndex <= penCount; cellIndex++) { API_Attribute attr; Attribute_Get (&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->Attach (*this); AttachToAllItems (*dialog); } PenSettingsEditPensObserver::~PenSettingsEditPensObserver () { dialog->Detach (*this); DetachFromAllItems (*dialog); dialog = NULL; } void PenSettingsEditPensObserver::PanelOpened (const DG::PanelOpenEvent& /*ev*/) { short penId = 1; dialog->penControl.SetValue (penId); Attribute_Get (&dialog->penAttr, API_PenID, penId); GS::UniString str = GS::UniString::Printf ("%u", penId); dialog->penNumberStatic.SetText (str); dialog->unitControl.SetValue (dialog->penWeightUnit); dialog->HandleUnitControlChange (dialog->penWeightUnit); str = dialog->penAttr.pen.description; dialog->penNameEdit.SetText (str); dialog->UpdatePenControl (); } void PenSettingsEditPensObserver::UserControlChanged (const DG::UserControlChangeEvent& ev) { if (ev.GetSource () == &dialog->penControl) { short penId = dialog->penControl.GetValue (); Attribute_Get (&dialog->penAttr, API_PenID, penId); GS::UniString str = GS::UniString::Printf ("%u", penId); dialog->penNumberStatic.SetText (str); dialog->HandleUnitControlChange (dialog->unitControl.GetValue ()); str = dialog->penAttr.pen.description; dialog->penNameEdit.SetText (str); } else if (ev.GetSource () == &dialog->unitControl) { dialog->HandleUnitControlChange (dialog->unitControl.GetValue ()); } } void PenSettingsEditPensObserver::ButtonClicked (const DG::ButtonClickEvent& ev) { if (ev.GetSource () == &dialog->okButton) { dialog->PostCloseRequest (DG::ModalDialog::Accept); } }To try:
PenSettingsEditPensPage dialog (ACAPI_GetOwnResModule (), USER_CONTROLS_DIALOG_RESID); if (DBERROR (dialog.GetId () == 0)) { return; } PenSettingsEditPensObserver observer (&dialog); dialog.Invoke ();
2014-08-09 02:52 AM
2014-08-11 10:29 AM
poco2013 wrote:Sorry, that was one of my private header files.
I get an "can't find the header DrawDialogItems.hpp error
2014-08-11 01:01 PM