home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <owl\applicat.h>
- #include <owl\button.h>
- #include <owl\checkbox.h>
- #include <owl\framewin.h>
- #include <owl\groupbox.h>
- #include <owl\radiobut.h>
- #include <owl\window.h>
- #include <owl\window.rh>
-
- #include "widgets.h"
-
- class TMyGroup : public TGroupBox
- {
- public:
- TMyGroup(TWindow *parent,
- int id,
- const char far *text,
- int X, int Y, int W, int H,
- TModule *module = 0 )
- : TGroupBox(parent, id, text, X, Y, W, H, module), cur(-1)
- { }
-
- LPCSTR GetCurCheck();
-
- virtual void SelectionChanged(int controlId)
- { TGroupBox::SelectionChanged(cur = controlId); }
-
- private:
- int cur;
- };
-
- LPCSTR TMyGroup::GetCurCheck()
- {
- TWindow *w = Parent->ChildWithId(cur);
- return w ? w->Title : NULL;
- }
-
- class TWidgetWindow : public TWindow
- {
- public:
- TWidgetWindow(TWindow *parent = 0);
-
- protected:
- virtual void SetupWindow();
-
- void EnableGroupA(BOOL enable);
- void EnableGroupB(BOOL enable);
- void EnableGroupC(BOOL enable);
-
- BOOL BuildStr( LPSTR str,
- LPCSTR name,
- TCheckBox *check,
- TMyGroup *group );
-
- void CmDone();
- void CmCancel();
- void CmTypeA();
- void CmTypeB();
- void CmTypeC();
-
- private:
- TCheckBox *TypeA, *TypeB, *TypeC;
- TMyGroup *GroupA, *GroupB, *GroupC;
- TRadioButton *Etched, *Polished,
- *WoodGrain, *Varnished, *Engraved,
- *Mediocre, *Deluxe;
-
- DECLARE_RESPONSE_TABLE(TWidgetWindow);
- };
- DEFINE_RESPONSE_TABLE1(TWidgetWindow, TWindow)
- EV_BN_CLICKED(IDOK, CmDone),
- EV_BN_CLICKED(IDCANCEL, CmCancel),
- EV_BN_CLICKED(IDC_TYPEA, CmTypeA),
- EV_BN_CLICKED(IDC_TYPEB, CmTypeB),
- EV_BN_CLICKED(IDC_TYPEC, CmTypeC),
- END_RESPONSE_TABLE;
-
- TWidgetWindow::TWidgetWindow(TWindow *parent)
- {
- Init(parent, 0, 0);
-
- new TButton(this, IDOK, "Done", 175, 350, 100, 30);
- new TButton(this, IDCANCEL, "Cancel", 400, 350, 100, 30);
-
- TypeA = new TCheckBox(this, IDC_TYPEA, "Type A",
- 70, 40, 100, 20);
- GroupA = new TMyGroup(this, IDG_TYPEA, NULL,
- 192, 15, 280, 75);
- Etched = new TRadioButton(this, IDR_ETCHED, "Etched",
- 203, 42, 100, 20, GroupA);
- Polished = new TRadioButton(this, IDR_POLISHED, "Polished",
- 332, 42, 100, 20, GroupA);
-
- TypeB = new TCheckBox(this, IDC_TYPEB, "Type B",
- 70, 153, 100, 20);
- GroupB = new TMyGroup(this, IDG_TYPEB, NULL,
- 192, 123, 280, 75);
- WoodGrain = new TRadioButton(this, IDR_WOODGRAIN, "Wood-Grain",
- 203, 138, 100, 20, GroupB);
- Varnished = new TRadioButton(this, IDR_VARNISHED, "Varnished",
- 332, 138, 100, 20, GroupB);
- Engraved = new TRadioButton(this, IDR_ENGRAVED, "Engraved",
- 203, 172, 100, 20, GroupB);
-
- TypeC = new TCheckBox(this, IDC_TYPEC, "Type C",
- 70, 272, 100, 20);
- GroupC = new TMyGroup(this, IDG_TYPEC, NULL,
- 192, 247, 280, 75);
- Mediocre = new TRadioButton(this, IDR_MEDIOCRE, "Mediocre",
- 203, 273, 100, 20, GroupC);
- Deluxe = new TRadioButton(this, IDR_DELUXE, "Deluxe",
- 332, 273, 100, 20, GroupC);
- }
-
- void TWidgetWindow::SetupWindow()
- {
- TWindow::SetupWindow(); // Initialize the visual element
-
- EnableGroupA(FALSE);
- EnableGroupB(FALSE);
- EnableGroupC(FALSE);
- }
-
- void TWidgetWindow::EnableGroupA(BOOL enable)
- {
- if (Etched)
- Etched->EnableWindow(enable);
- if (Polished)
- Polished->EnableWindow(enable);
- }
-
- void TWidgetWindow::EnableGroupB(BOOL enable)
- {
- if (WoodGrain)
- WoodGrain->EnableWindow(enable);
- if (Varnished)
- Varnished->EnableWindow(enable);
- if (Engraved)
- Engraved->EnableWindow(enable);
- }
-
- void TWidgetWindow::EnableGroupC(BOOL enable)
- {
- if (Mediocre)
- Mediocre->EnableWindow(enable);
- if (Deluxe)
- Deluxe->EnableWindow(enable);
- }
-
- BOOL TWidgetWindow::BuildStr( LPSTR str,
- LPCSTR name,
- TCheckBox *check,
- TMyGroup *group )
- {
- BOOL rslt = FALSE;
- if (str && check && check->GetCheck())
- {
- rslt = TRUE;
- LPCSTR groupname;
-
- str += lstrlen(str); // point to end of str
- sprintf(str, "\n %s: ", name);
- if (group && (NULL != (groupname = group->GetCurCheck())))
- strcat(str, groupname);
- }
- return rslt;
- }
-
-
- void TWidgetWindow::CmDone()
- {
- char str[256] = "";
- int sels = 0;
-
- strcpy(str, "You have selected the following:");
- sels += BuildStr(str, "Widget A", TypeA, GroupA);
- sels += BuildStr(str, "Widget B", TypeB, GroupB);
- sels += BuildStr(str, "Widget C", TypeC, GroupC);
- if (!sels)
- strcat(str, "\n << No selections >>");
- MessageBox(str, "Widget Selection", MB_OK);
- SendMessage(WM_CLOSE);
- }
-
- void TWidgetWindow::CmCancel()
- {
- SendMessage(WM_CLOSE);
- }
-
- void TWidgetWindow::CmTypeA()
- {
- if (TypeA)
- EnableGroupA(TypeA->GetCheck());
- if (GroupA && !GroupA->GetCurCheck() && Etched)
- Etched->Check();
- }
-
- void TWidgetWindow::CmTypeB()
- {
- if (TypeB)
- EnableGroupB(TypeB->GetCheck());
- if (GroupB && !GroupB->GetCurCheck() && WoodGrain)
- WoodGrain->Check();
- }
-
- void TWidgetWindow::CmTypeC()
- {
- if (TypeC)
- EnableGroupC(TypeC->GetCheck());
- if (GroupC && !GroupC->GetCurCheck() && Mediocre)
- Mediocre->Check();
- }
-
-
- class TWidgetApp : public TApplication
- {
- public:
- TWidgetApp() : TApplication()
- { nCmdShow = SW_SHOWMAXIMIZED; }
-
- void InitMainWindow()
- {
- SetMainWindow(new TFrameWindow( 0,
- "World-Wide Widget Weilders",
- new TWidgetWindow ));
- }
- };
-
- int OwlMain(int, char *[])
- {
- return TWidgetApp().Run();
- }
-