home *** CD-ROM | disk | FTP | other *** search
/ The CDPD Public Domain Collection for CDTV 3 / CDPDIII.bin / pd / programming / utils / mui-demo / mui-demo.c < prev    next >
C/C++ Source or Header  |  1993-04-26  |  32KB  |  701 lines

  1. /*
  2. **          C Source Code For The MUI Demo Program
  3. **          --------------------------------------
  4. **
  5. **               written 1993 by Stefan Stuntz
  6. **
  7. ** Even if it doesn't look so, all of the code below is pure C,
  8. ** just a little bit enhanced with some MUI specific macros.
  9. **
  10. ** Note: You won't be able to recompile this program unless
  11. **       you have the MUI include files, which are *not* part
  12. **       of the demo release!
  13. */
  14.  
  15. #include "demos.h"
  16.  
  17.  
  18. /*
  19. ** Convetional GadTools NewMenu structures. Since I was
  20. ** too lazy to construct my own, object oriented menu
  21. ** system for now, this is the only part of MUI that needs
  22. ** "gadtools.library". Well, GadTools menus aren't that bad,
  23. ** at least not as bad as the other GadTools crap :-)
  24. ** Nevertheless, object oriented menus will come soon.
  25. */
  26.  
  27. #define ID_ABOUT     1
  28. #define ID_FRAMES    2
  29. #define ID_IMAGES    3
  30. #define ID_BROADCAST 4
  31. #define ID_GROUPS    5
  32. #define ID_BACKFILL  6
  33. #define ID_LISTVIEWS 7
  34. #define ID_CYCLE     8
  35. #define ID_STRING    9
  36. #define ID_DATATYPE  10
  37. #define ID_NEWVOL    11
  38. #define ID_NEWBRI    12
  39.  
  40. static const struct NewMenu Menu[] =
  41. {
  42.     { NM_TITLE, "Project"  , 0 ,0,0,(APTR)0            },
  43.     { NM_ITEM , "About..." ,"?",0,0,(APTR)ID_ABOUT     },
  44.     { NM_ITEM , NM_BARLABEL, 0 ,0,0,(APTR)0            },
  45.     { NM_ITEM , "Frames"   ,"F",0,0,(APTR)ID_FRAMES    },
  46.     { NM_ITEM , "Images"   ,"I",0,0,(APTR)ID_IMAGES    },
  47.     { NM_ITEM , "Broadcast","B",0,0,(APTR)ID_BROADCAST },
  48.     { NM_ITEM , "Groups"   ,"G",0,0,(APTR)ID_GROUPS    },
  49.     { NM_ITEM , "Backfill" ,"A",0,0,(APTR)ID_BACKFILL  },
  50.     { NM_ITEM , "Listviews","L",0,0,(APTR)ID_LISTVIEWS },
  51.     { NM_ITEM , "Strings"  ,"S",0,0,(APTR)ID_STRING    },
  52.     { NM_ITEM , "Datatypes","D",0,0,(APTR)ID_DATATYPE  },
  53.     { NM_ITEM , "Cycle"    ,"C",0,0,(APTR)ID_CYCLE     },
  54.     { NM_ITEM , NM_BARLABEL, 0 ,0,0,(APTR)0            },
  55.     { NM_ITEM , "Quit"     ,"Q",0,0,(APTR)MUIV_Application_ReturnID_Quit },
  56.     { NM_END  , NULL       , 0 ,0,0,(APTR)0            },
  57. };
  58.  
  59.  
  60. /*
  61. ** Here are all the little info texts
  62. ** that appear at the top of each demo window.
  63. */
  64.  
  65. static const char IN_Master[]    = "\tWelcome to the MUI demonstration program. This little toy will show you, how easy it is to create graphical user interfaces with MUI and how powerful the results are.\n\tMUI is based on BOOPSI, Amiga's basic object oriented programming system. For details about programming, see the 'ReadMe' file and the documented source code of this demo. Only one thing so far: it's really easy!\n\tNow go on, click around and watch this demo. Or use your keyboard (TAB, Return, Cursor-Keys) if you like that better. Hint: play around with the MUI preferences program and customize every pixel to fit your personal taste.";
  66. static const char IN_Broadcast[] = "\tMUI objects communicate with each other with the aid of a broadcasting system. This system is frequently used in every MUI application. Binding an up and a down arrow to a prop gadget e.g. makes up a scrollbar, binding a scrollbar to a list makes up a listview. You can also bind windows to buttons, thus the window will be opened when the button is pressed.\n\tRemember: The main loop of this demo program simply consists of a Wait(). Once set up, MUI handles all user actions concerning the GUI automatically.";
  67. static const char IN_Frames[]    = "\tEvery MUI object can have a surrounding frame. Several types are available, each of them either normal or inverted. The border thickness is adjustable via MUI's preferences program.";
  68. static const char IN_Images[]    = "\tMUI offers a vector image class, that allows images to be zoomed to any dimension. Every MUI image is transformed to match the current screens colors before displaying.\n\tThere are several standard images for often used GUI components (e.g. Arrows). These standard images can be defined via the preferences program.";
  69. static const char IN_Groups[]    = "\tGroups are very important for MUI. Their combinations determine how the GUI will look. A group may contain any number of child objects, which are positioned either horizontal or vertical.\n\tWhen a group is layouted, the available space is distributed between all of its childs, depending on their minimum and maximum dimensions and on their weight.\n\tOf course, the childs of a group may be other groups. There are no restrictions.";
  70. static const char IN_Backfill[]  = "\tEvery object can have his own background, if it wants to. MUI offers several standard backgrounds (e.g. one of the DrawInfo pens or one of the rasters below). Additionally, a program can specify custom backfill hooks as shown at the bottom of this little window.";
  71. static const char IN_Listviews[] = "\tMUI's list class is very flexible. A list can be made up of any number of columns containing formatted text or even images. Several subclasses of list class (e.g. a directory class and a volume class) are available. All MUI lists have the capability of multi selection, just by setting a single flag.\n\tThe small info texts at the top of each demo window are made with floattext class. This one just needs a character string as input and formats the text according to its width.";
  72. static const char IN_Cycle[]     = "\tCycle gadgets, radios buttons and simple lists can be used to let the user pick exactly one selection from a list of choices. In this example, all three possibilities are shown. Of course they are connected via broadcasting, so every object will immediately be notified and updated when necessary.";
  73. static const char IN_String[]    = "\tOf course, MUI offers a standard string gadget class for text input. The gadget in this example is attached to the list, you can control the list cursor from within the gadget.";
  74. static const char IN_Datatype[]  = "";
  75.  
  76.  
  77. /*
  78. ** This are the entries for the cycle gadgets and radio buttons.
  79. */
  80.  
  81. static const char *CYA_Computer[] = { "Amiga 500","Amiga 600","Amiga 1000 :)","Amiga 1200","Amiga 2000","Amiga 3000","Amiga 4000", "Amiga 4000T", "Atari ST :(", NULL };
  82. static const char *CYA_Printer[]  = { "HP Deskjet","NEC P6","Okimate 20",NULL };
  83. static const char *CYA_Display[]  = { "A1081","NEC 3D","A2024","Eizo T660i",NULL };
  84. static const char *LVT_Brian[48]; /* this secret text is hidden at the end of this file :) */
  85.  
  86.  
  87. /*
  88. ** Some Macros to make my life easier and the actual source
  89. ** code more readable.
  90. */
  91.  
  92. #define List(ftxt)             ListviewObject, MUIA_Weight, 50, MUIA_Listview_Input, FALSE, MUIA_Listview_List, FloattextObject, RaisedFrame, MUIA_Floattext_Text, ftxt, MUIA_Floattext_TabSize, 4, MUIA_List_CursorType, MUIV_List_CursorType_Bar, End, End
  93. #define DemoWindow(name,info)  WindowObject, MUIA_Window_Name, name, WindowContents, VChilds, MUIA_InnerWindow, TRUE, Child, List(info)
  94. #define ImageLine(name,nr)     HChilds, Child, TextObject, TextEntry, name, MUIA_FixWidthTxt, "RadioButton:", MUIA_Text_Format, MUIV_Text_Format_Right, End, Child, VChilds, Child, VSpace(0), Child, ImageObject, MUIA_Image_Type, nr, End, Child, VSpace(0), End, End
  95. #define ScaledImage(nr,s,x,y)  ImageObject, MUIA_Image_Type, nr, MUIA_FixWidth, x, MUIA_FixHeight, y, MUIA_Image_Scalable, TRUE, MUIA_Image_State, s, End
  96. #define Cycle(p,name,max,e)    HChilds, Child, VChilds, GroupSpacing(0), Child, VSpace(0), Child, TextObject, TextEntry, name, MUIA_FixWidthTxt, max, MUIA_Text_Format, MUIV_Text_Format_Right, End, Child, VSpace(0), End, Child, p = CycleObject, MUIA_Cycle_Entries, e, End, End
  97. #define HProp                  PropObject, MUIA_Prop_Horiz, TRUE, MUIA_FixHeight, 8, MUIA_Prop_Entries, 8, MUIA_Prop_Visible, 1, End
  98. #define VProp                  PropObject, MUIA_Prop_Horiz, FALSE, MUIA_FixWidth , 8, MUIA_Prop_Entries, 8, MUIA_Prop_Visible, 1, End
  99.  
  100.  
  101. /*
  102. ** For every object we want to refer later (e.g. for broadcasting purposes)
  103. ** we need a pointer. These pointer do not need to be static, but this
  104. ** saves stack space.
  105. */
  106.  
  107. static APTR AP_Demo;
  108. static APTR WI_Master,WI_Frames,WI_Images,WI_Broadcast,WI_Listviews,WI_Groups,WI_Backfill,WI_Cycle,WI_String,WI_Datatype;
  109. static APTR BT_Broadcast,BT_Frames,BT_Images,BT_Groups,BT_Backfill,BT_Listviews,BT_Cycle,BT_String,BT_Datatype;
  110. static APTR PR_PropA,PR_PropH,PR_PropV,PR_PropL,PR_PropR,PR_PropT,PR_PropB;
  111. static APTR LV_Volumes,LV_Directory,LV_Computer,LV_Brian;
  112. static APTR CY_Computer,CY_Printer,CY_Display;
  113. static APTR MT_Computer,MT_Printer,MT_Display;
  114. static APTR ST_Brian,ST_Datatype;
  115. static APTR DT_Datatype;
  116.  
  117.  
  118. /*
  119. ** Here we have the custom background hook for the backfill demo.
  120. ** This is the only part where the programmer actually draws,
  121. ** all other rendering is done by MUI.
  122. */
  123.  
  124. SAVEDS ASM LONG CustomBackgroundFunc(REG(a0) struct Hook *hook,REG(a2) struct RastPort *rp,REG(a1) struct MUIP_BackgroundPacket *p)
  125. {
  126.     USHORT pattern[]={0x1111,0x1111<<1,0x1111<<2,0x1111<<3};
  127.     SetDrMd(rp,JAM2);
  128.     SetAPen(rp,p->DrawInfo->dri_Pens[SHADOWPEN]);
  129.     SetBPen(rp,p->DrawInfo->dri_Pens[FILLPEN]);
  130.     SetAfPt(rp,pattern,2);
  131.     RectFill(rp,p->left,p->top,p->left+p->width-1,p->top+p->height-1);
  132.     SetAfPt(rp,NULL,-1);
  133.     return(0);
  134. }
  135. static const struct Hook CustomBackgroundHook = { { NULL,NULL },CustomBackgroundFunc,NULL,NULL };
  136.  
  137.  
  138. /*
  139. ** This is where all begins...
  140. */
  141.  
  142. int main(int argc,char *argv[])
  143. {
  144.  
  145. /*
  146. ** The init() functions is define in demos.h and does nothing
  147. ** but open "muimaster.library".
  148. */
  149.  
  150.     init();
  151.  
  152.  
  153. /*
  154. ** Every MUI application needs an application object,
  155. ** which will hold general informations and serve as
  156. ** anchor for user input, ARexx functions,
  157. ** commodities interface, etc.
  158. */
  159.  
  160.     AP_Demo = ApplicationObject,
  161.         MUIA_Application_Title      , "MUI-Demo",
  162.         MUIA_Application_Version    , "$VER: MUI-Demo 3.318 (26.04.93)",
  163.         MUIA_Application_Copyright  , "Copyright ©1993, Stefan Stuntz",
  164.         MUIA_Application_Author     , "Stefan Stuntz",
  165.         MUIA_Application_Description, "Demonstrate the features of MUI.",
  166.         MUIA_Application_Base       , "MUIDEMO",
  167.         MUIA_Application_Menu       , Menu,
  168.         End;
  169.  
  170.  
  171. /*
  172. ** Now we will create all the nice demo windows. This is
  173. ** what makes up the GUI. Note that we do not need any
  174. ** error control for the sub objects since every error
  175. ** will automatically be forwarded to the parent object
  176. ** and cause this one to fail too.
  177. **
  178. ** Creating the window does not mean to display it instantly.
  179. ** This is done later by a call to the applications AddWindow method.
  180. */
  181.  
  182.     WI_String =
  183.         DemoWindow("String",IN_String),
  184.             Child, LV_Brian = ListviewObject,
  185.                 MUIA_Listview_Input, TRUE,
  186.                 MUIA_Listview_List, ListObject, RaisedFrame, MUIA_List_CursorType, MUIV_List_CursorType_Bar, End,
  187.                 End,
  188.             Child, ST_Brian = StringObject, StringFrame, End,
  189.             End,
  190.         End;
  191.  
  192.     WI_Datatype =
  193.         DemoWindow("Datatype",IN_Datatype),
  194.             Child, ST_Datatype = StringObject, StringFrame, End,
  195.             Child, DT_Datatype = DatatypeObject, RecessedFrame, End,
  196.             End,
  197.         End;
  198.  
  199.     WI_Cycle =
  200.         DemoWindow("Cycle Gadgets & RadioButtons",IN_Cycle),
  201.             Child, HChilds,
  202.                 Child, MT_Computer = Mutex("Computer:",CYA_Computer),
  203.                 Child, VChilds,
  204.                     Child, MT_Printer = Mutex("Printer:",CYA_Printer),
  205.                     Child, VSpace(0),
  206.                     Child, MT_Display = Mutex("Display:",CYA_Display),
  207.                     End,
  208.                 Child, VChilds,
  209.                     Child, VChilds, GroupFrame("Cycle Gadgets"),
  210.                         Child, Cycle(CY_Computer,"Computer:","Computer:",CYA_Computer),
  211.                         Child, Cycle(CY_Printer ,"Printer:" ,"Computer:",CYA_Printer ),
  212.                         Child, Cycle(CY_Display ,"Display:" ,"Computer:",CYA_Display ),
  213.                         End,
  214.                     Child, LV_Computer =    ListviewObject,
  215.                         MUIA_Listview_Input, TRUE,
  216.                         MUIA_Listview_List, ListObject, RaisedFrame, MUIA_List_CursorType, MUIV_List_CursorType_Bar, End,
  217.                         End,
  218.                     End,
  219.                 End,
  220.             End,
  221.         End;
  222.  
  223.     WI_Listviews =
  224.         DemoWindow("Listviews",IN_Listviews),
  225.             Child, HChilds, GroupFrame("Dir & Volume List"),
  226.                 Child, LV_Directory = ListviewObject,
  227.                     MUIA_Listview_Input, TRUE,
  228.                     MUIA_Listview_MultiSelect, TRUE,
  229.                     MUIA_Listview_List, DirlistObject, RaisedFrame, MUIA_Dirlist_DirName, "ram:", MUIA_List_CursorType, MUIV_List_CursorType_Bar, End,
  230.                     End,
  231.                 Child, LV_Volumes = ListviewObject,
  232.                     MUIA_Weight, 20,
  233.                     MUIA_Listview_Input, TRUE,
  234.                     MUIA_Listview_List, VolumelistObject, RaisedFrame, MUIA_Dirlist_DirName, "ram:", MUIA_List_CursorType, MUIV_List_CursorType_Bar, End,
  235.                     End,
  236.                 End,
  237.             End,
  238.         End;
  239.  
  240.     WI_Broadcast =
  241.         DemoWindow("Broadcasting",IN_Broadcast),
  242.             Child, HChilds, GroupFrame("Connections"),
  243.                 Child, PR_PropL = VProp,
  244.                 Child, PR_PropR = VProp,
  245.                 Child, VChilds,
  246.                     Child, VSpace(0),
  247.                     Child, PR_PropA = HProp,
  248.                     Child, HChilds,
  249.                         Child, PR_PropH = HProp,
  250.                         Child, PR_PropV = HProp,
  251.                         End,
  252.                     Child, VSpace(0),
  253.                     End,
  254.                 Child, PR_PropT = VProp,
  255.                 Child, PR_PropB = VProp,
  256.                 End,
  257.             End,
  258.         End;
  259.  
  260.     WI_Backfill =
  261.         DemoWindow("Backfill",IN_Backfill),
  262.             Child, VChilds, GroupFrame("Standard Backgrounds"),
  263.                 Child, HChilds,
  264.                     Child, RectangleObject, RecessedFrame, MUIA_Background, BACKGROUNDPEN              , End,
  265.                  Child, RectangleObject, RecessedFrame, MUIA_Background, FILLPEN                    , End,
  266.                  Child, RectangleObject, RecessedFrame, MUIA_Background, TEXTPEN                    , End,
  267.                     End,
  268.                 Child, HChilds,
  269.                  Child, RectangleObject, RecessedFrame, MUIA_Background, MUIV_Background_ShadowBack , End,
  270.                  Child, RectangleObject, RecessedFrame, MUIA_Background, MUIV_Background_ShadowFill , End,
  271.                  Child, RectangleObject, RecessedFrame, MUIA_Background, MUIV_Background_ShadowShine, End,
  272.                     End,
  273.                 Child, HChilds,
  274.                  Child, RectangleObject, RecessedFrame, MUIA_Background, MUIV_Background_FillBack   , End,
  275.                  Child, RectangleObject, RecessedFrame, MUIA_Background, MUIV_Background_ShineBack  , End,
  276.                  Child, RectangleObject, RecessedFrame, MUIA_Background, MUIV_Background_FillShine  , End,
  277.                     End,
  278.                 End,
  279.             Child, VChilds, GroupFrame("Custom Background"),
  280.                 Child, VChilds, RecessedFrame, MUIA_Background, &CustomBackgroundHook,
  281.                     Child, TextObject, TextEntry, "Custom"    , MUIA_Text_SetMin, TRUE, MUIA_Text_Format, MUIV_Text_Format_Left  , MUIA_Text_FrontPen, SHINEPEN, End,
  282.                     Child, TextObject, TextEntry, "Background", MUIA_Text_SetMin, TRUE, MUIA_Text_Format, MUIV_Text_Format_Center, MUIA_Text_FrontPen, SHINEPEN, End,
  283.                     Child, TextObject, TextEntry, "Hook"      , MUIA_Text_SetMin, TRUE, MUIA_Text_Format, MUIV_Text_Format_Right , MUIA_Text_FrontPen, SHINEPEN, End,
  284.                     End,
  285.                 End,
  286.             End,
  287.         End;
  288.  
  289.     WI_Groups =
  290.         DemoWindow("Groups",IN_Groups),
  291.             Child, HChilds, GroupFrame("Two Basic Group Types"),
  292.                 Child, HChilds, GroupFrame("Horizontal"),
  293.                     Child, RectangleObject, RecessedFrame, End,
  294.                     Child, RectangleObject, RecessedFrame, End,
  295.                     Child, RectangleObject, RecessedFrame, End,
  296.                     End,
  297.                 Child, VChilds, GroupFrame("Vertical"),
  298.                     Child, RectangleObject, RecessedFrame, End,
  299.                     Child, RectangleObject, RecessedFrame, End,
  300.                     Child, RectangleObject, RecessedFrame, End,
  301.                     End,
  302.                 End,
  303.             Child, HChilds, GroupFrame("Different Weights"),
  304.                 Child, TextObject, RecessedFrame, TextEntry, "25 kg" , MUIA_Text_SetMin, TRUE, MUIA_Text_Format, MUIV_Text_Format_Center, MUIA_Weight,  25, End,
  305.                 Child, TextObject, RecessedFrame, TextEntry, "50 kg" , MUIA_Text_SetMin, TRUE, MUIA_Text_Format, MUIV_Text_Format_Center, MUIA_Weight,  50, End,
  306.                 Child, TextObject, RecessedFrame, TextEntry, "75 kg" , MUIA_Text_SetMin, TRUE, MUIA_Text_Format, MUIV_Text_Format_Center, MUIA_Weight,  75, End,
  307.                 Child, TextObject, RecessedFrame, TextEntry, "100 kg", MUIA_Text_SetMin, TRUE, MUIA_Text_Format, MUIV_Text_Format_Center, MUIA_Weight, 100, End,
  308.                 End,
  309.             Child, HChilds, GroupFrame("Fixed & Variable Sizes"),
  310.                 Child, TextObject, RecessedFrame, TextEntry, "fixed" , MUIA_Text_SetMin, TRUE, MUIA_Text_SetMax, TRUE , MUIA_Text_Format, MUIV_Text_Format_Center, End,
  311.                 Child, TextObject, RecessedFrame, TextEntry, "free"  , MUIA_Text_SetMin, TRUE, MUIA_Text_SetMax, FALSE, MUIA_Text_Format, MUIV_Text_Format_Center, End,
  312.                 Child, TextObject, RecessedFrame, TextEntry, "fixed" , MUIA_Text_SetMin, TRUE, MUIA_Text_SetMax, TRUE , MUIA_Text_Format, MUIV_Text_Format_Center, End,
  313.                 Child, TextObject, RecessedFrame, TextEntry, "free"  , MUIA_Text_SetMin, TRUE, MUIA_Text_SetMax, FALSE, MUIA_Text_Format, MUIV_Text_Format_Center, End,
  314.                 Child, TextObject, RecessedFrame, TextEntry, "fixed" , MUIA_Text_SetMin, TRUE, MUIA_Text_SetMax, TRUE , MUIA_Text_Format, MUIV_Text_Format_Center, End,
  315.                 End,
  316.             End,
  317.         End;
  318.  
  319.     WI_Frames =
  320.         DemoWindow("Frames",IN_Frames),
  321.             Child, HChilds,
  322.                 Child, VChilds,
  323.                     Child, CenterText("Normal"),
  324.                     Child, VSpace(2),
  325.                     Child, HChilds, BoringFrame   , Child, CenterText("Boring Frame"), End,
  326.                     Child, HChilds, RaisedFrame   , Child, CenterText("Raised Frame"), End,
  327.                     Child, HChilds, StringFrame   , Child, CenterText("String Frame"), End,
  328.                     Child, HChilds, DoubleFrame   , Child, CenterText("Double Frame"), End,
  329.                     Child, HChilds, OvalFrame     , Child, CenterText("Oval Frame"  ), End,
  330.                     End,
  331.                 Child, VChilds,
  332.                     Child, CenterText("Reverse"),
  333.                     Child, VSpace(2),
  334.                     Child, HChilds, InvBoringFrame, Child, CenterText("InvBoring Frame"), End,
  335.                     Child, HChilds, RecessedFrame , Child, CenterText("Recessed Frame"), End,
  336.                     Child, HChilds, NeXTFrame     , Child, CenterText("NeXT Frame"), End,
  337.                     Child, HChilds, InvDoubleFrame, Child, CenterText("InvDouble Frame"), End,
  338.                     Child, HChilds, InvOvalFrame  , Child, CenterText("InvOval Frame"), End,
  339.                     End,
  340.                 End,
  341.             End,
  342.         End;
  343.  
  344.     WI_Images =
  345.         DemoWindow("Images",IN_Images),
  346.             Child, HChilds,
  347.                 Child, VChilds, GroupFrame("Standard Images"),
  348.                     Child, ImageLine("ArrowUp:"    ,MUIV_Image_Type_ArrowUp    ),
  349.                     Child, ImageLine("ArrowDown:"  ,MUIV_Image_Type_ArrowDown  ),
  350.                     Child, ImageLine("ArrowLeft:"  ,MUIV_Image_Type_ArrowLeft  ),
  351.                     Child, ImageLine("ArrowRight:" ,MUIV_Image_Type_ArrowRight ),
  352.                     Child, ImageLine("RadioButton:",MUIV_Image_Type_RadioButton),
  353.                     Child, ImageLine("PopUp:"      ,MUIV_Image_Type_PopUp      ),
  354.                     Child, ImageLine("HardDisk:"   ,MUIV_Image_Type_HardDisk   ),
  355.                     Child, ImageLine("Disk:"       ,MUIV_Image_Type_Disk       ),
  356.                     Child, ImageLine("Chip:"       ,MUIV_Image_Type_Chip       ),
  357.                     Child, ImageLine("Volume:"     ,MUIV_Image_Type_Volume     ),
  358.                     Child, ImageLine("Drawer:"     ,MUIV_Image_Type_Drawer     ),
  359.                     End,
  360.                 Child, VChilds, GroupFrame("Scale Engine"),
  361.                     Child, VSpace(0),
  362.                     Child, HChilds,
  363.                         Child, ScaledImage(MUIV_Image_Type_RadioButton,1,17, 9),
  364.                         Child, ScaledImage(MUIV_Image_Type_RadioButton,1,20,12),
  365.                         Child, ScaledImage(MUIV_Image_Type_RadioButton,1,23,15),
  366.                         Child, ScaledImage(MUIV_Image_Type_RadioButton,1,26,18),
  367.                         Child, ScaledImage(MUIV_Image_Type_RadioButton,1,29,21),
  368.                         End,
  369.                     Child, VSpace(0),
  370.                     Child, HChilds,
  371.                         Child, ScaledImage(MUIV_Image_Type_CheckMark,1,13, 7),
  372.                         Child, ScaledImage(MUIV_Image_Type_CheckMark,1,16,10),
  373.                         Child, ScaledImage(MUIV_Image_Type_CheckMark,1,19,13),
  374.                         Child, ScaledImage(MUIV_Image_Type_CheckMark,1,22,16),
  375.                         Child, ScaledImage(MUIV_Image_Type_CheckMark,1,25,19),
  376.                         Child, ScaledImage(MUIV_Image_Type_CheckMark,1,28,22),
  377.                         End,
  378.                     Child, VSpace(0),
  379.                     Child, HChilds,
  380.                         Child, ScaledImage(MUIV_Image_Type_PopUp,0,12,10),
  381.                         Child, ScaledImage(MUIV_Image_Type_PopUp,0,15,13),
  382.                         Child, ScaledImage(MUIV_Image_Type_PopUp,0,18,16),
  383.                         Child, ScaledImage(MUIV_Image_Type_PopUp,0,21,19),
  384.                         Child, ScaledImage(MUIV_Image_Type_PopUp,0,24,22),
  385.                         Child, ScaledImage(MUIV_Image_Type_PopUp,0,27,25),
  386.                         End,
  387.                     Child, VSpace(0),
  388.                     End,
  389.                 End,
  390.             End,
  391.         End;
  392.  
  393.     WI_Master = WindowObject,
  394.         MUIA_Window_Name, "MUI-Demo",
  395.         WindowContents, VChilds, MUIA_InnerWindow,TRUE,
  396.             Child, VChilds, NeXTFrame, MUIA_Background, MUIV_Background_ShadowFill,
  397.                 Child, TextObject, TextEntry, "MUI - MagicUserInterface"     , MUIA_Text_SetMin, TRUE, MUIA_Text_Format, MUIV_Text_Format_Center, MUIA_Text_FrontPen, SHINEPEN, End,
  398.                 Child, TextObject, TextEntry, "written 1993 by Stefan Stuntz", MUIA_Text_SetMin, TRUE, MUIA_Text_Format, MUIV_Text_Format_Center, MUIA_Text_FrontPen, SHINEPEN, End,
  399.                 End,
  400.             Child, List(IN_Master),
  401.             Child, VChilds, GroupFrame("Available Demos"),
  402.                 Child, HIChilds,
  403.                     Child, BT_Groups    = SimpleButton("Groups"),
  404.                     Child, BT_Frames    = SimpleButton("Frames"),
  405.                     Child, BT_Backfill  = SimpleButton("Backfill"),
  406.                     End,
  407.                 Child, HIChilds,
  408.                     Child, BT_Broadcast = SimpleButton("Broadcast"),
  409.                     Child, BT_Listviews = SimpleButton("Listviews"),
  410.                     Child, BT_Cycle     = SimpleButton("Cycle"),
  411.                     End,
  412.                 Child, HIChilds,
  413.                     Child, BT_Images    = SimpleButton("Images"),
  414.                     Child, BT_String    = SimpleButton("String"),
  415.                     Child, BT_Datatype  = SimpleButton("Datatype"),
  416.                     End,
  417.                 End,
  418.             End,
  419.         End;
  420.  
  421.  
  422. /*
  423. ** See if all the windows are created. The fail function
  424. ** is defined in demos.h, it deletes every created object
  425. ** and closes "muimaster.library".
  426. */
  427.  
  428.     if (!WI_Master   ) fail("Failed to create master window.");
  429.     if (!WI_Frames   ) fail("Failed to create frames window.");
  430.     if (!WI_Images   ) fail("Failed to create images window.");
  431.     if (!WI_Broadcast) fail("Failed to create broadcasts window.");
  432.     if (!WI_Listviews) fail("Failed to create listviews window.");
  433.     if (!WI_Groups   ) fail("Failed to create groups window.");
  434.     if (!WI_Backfill ) fail("Failed to create backfill window.");
  435.     if (!WI_Cycle    ) fail("Failed to create cycle window.");
  436.     if (!WI_String   ) fail("Failed to create String window.");
  437.     if (!AP_Demo     ) fail("Failed to create application.");
  438.  
  439.  
  440. /*
  441. ** Here comes the broadcast magic. Broadcasting means:
  442. ** When an attribute of an object changes, then please change
  443. ** another attribute of another object (accordingly) or send
  444. ** a method to another object.
  445. */
  446.  
  447. /*
  448. ** Lets bind the sub windows to the corresponding button
  449. ** of the master window.
  450. */
  451.  
  452.     DoMethod(BT_Frames   ,MUIM_Broadcast_Add,MUIA_Released,AP_Demo,2,MUIM_Application_AddWindow,WI_Frames);
  453.     DoMethod(BT_Images   ,MUIM_Broadcast_Add,MUIA_Released,AP_Demo,2,MUIM_Application_AddWindow,WI_Images);
  454.     DoMethod(BT_Broadcast,MUIM_Broadcast_Add,MUIA_Released,AP_Demo,2,MUIM_Application_AddWindow,WI_Broadcast);
  455.     DoMethod(BT_Listviews,MUIM_Broadcast_Add,MUIA_Released,AP_Demo,2,MUIM_Application_AddWindow,WI_Listviews);
  456.     DoMethod(BT_Groups   ,MUIM_Broadcast_Add,MUIA_Released,AP_Demo,2,MUIM_Application_AddWindow,WI_Groups);
  457.     DoMethod(BT_Backfill ,MUIM_Broadcast_Add,MUIA_Released,AP_Demo,2,MUIM_Application_AddWindow,WI_Backfill);
  458.     DoMethod(BT_Cycle    ,MUIM_Broadcast_Add,MUIA_Released,AP_Demo,2,MUIM_Application_AddWindow,WI_Cycle);
  459.     DoMethod(BT_String   ,MUIM_Broadcast_Add,MUIA_Released,AP_Demo,2,MUIM_Application_AddWindow,WI_String);
  460.     if (WI_Datatype)
  461.         DoMethod(BT_Datatype,MUIM_Broadcast_Add,MUIA_Released,AP_Demo,2,MUIM_Application_AddWindow,WI_Datatype);
  462.     else
  463.         set(BT_Datatype,MUIA_Disabled,TRUE);
  464.  
  465.  
  466. /*
  467. ** Automagically remove a window when the user hits the close gadget.
  468. */
  469.  
  470.     DoMethod(WI_Images   ,MUIM_Broadcast_Add,MUIA_Window_CloseRequest,AP_Demo,2,MUIM_Application_RemoveWindow,WI_Images   );
  471.     DoMethod(WI_Frames   ,MUIM_Broadcast_Add,MUIA_Window_CloseRequest,AP_Demo,2,MUIM_Application_RemoveWindow,WI_Frames   );
  472.     DoMethod(WI_Broadcast,MUIM_Broadcast_Add,MUIA_Window_CloseRequest,AP_Demo,2,MUIM_Application_RemoveWindow,WI_Broadcast);
  473.     DoMethod(WI_Listviews,MUIM_Broadcast_Add,MUIA_Window_CloseRequest,AP_Demo,2,MUIM_Application_RemoveWindow,WI_Listviews);
  474.     DoMethod(WI_Groups   ,MUIM_Broadcast_Add,MUIA_Window_CloseRequest,AP_Demo,2,MUIM_Application_RemoveWindow,WI_Groups   );
  475.     DoMethod(WI_Backfill ,MUIM_Broadcast_Add,MUIA_Window_CloseRequest,AP_Demo,2,MUIM_Application_RemoveWindow,WI_Backfill );
  476.     DoMethod(WI_Cycle    ,MUIM_Broadcast_Add,MUIA_Window_CloseRequest,AP_Demo,2,MUIM_Application_RemoveWindow,WI_Cycle    );
  477.     DoMethod(WI_String   ,MUIM_Broadcast_Add,MUIA_Window_CloseRequest,AP_Demo,2,MUIM_Application_RemoveWindow,WI_String   );
  478.     if (WI_Datatype)
  479.         DoMethod(WI_Datatype ,MUIM_Broadcast_Add,MUIA_Window_CloseRequest,AP_Demo,2,MUIM_Application_RemoveWindow,WI_Datatype );
  480.  
  481.  
  482. /*
  483. ** Closing the master window forces a complete shutdown of the application.
  484. */
  485.  
  486.     DoMethod(WI_Master,MUIM_Broadcast_Add,MUIA_Window_CloseRequest,AP_Demo,2,MUIM_Application_ReturnID,MUIV_Application_ReturnID_Quit);
  487.  
  488.  
  489. /*
  490. ** This connects the prop gadgets in the broadcast demo window.
  491. */
  492.  
  493.     DoMethod(PR_PropA,MUIM_Broadcast_Add,MUIA_Prop_First,PR_PropH,2+MUIP_Broadcast_Add_AppendTriggered,MUIM_SET,MUIA_Prop_First,0);
  494.     DoMethod(PR_PropA,MUIM_Broadcast_Add,MUIA_Prop_First,PR_PropV,2+MUIP_Broadcast_Add_AppendTriggered,MUIM_SET,MUIA_Prop_First,0);
  495.     DoMethod(PR_PropH,MUIM_Broadcast_Add,MUIA_Prop_First,PR_PropL,2+MUIP_Broadcast_Add_AppendTriggered,MUIM_SET,MUIA_Prop_First,0);
  496.     DoMethod(PR_PropH,MUIM_Broadcast_Add,MUIA_Prop_First,PR_PropR,2+MUIP_Broadcast_Add_AppendTriggered,MUIM_SET,MUIA_Prop_First,0);
  497.     DoMethod(PR_PropV,MUIM_Broadcast_Add,MUIA_Prop_First,PR_PropT,2+MUIP_Broadcast_Add_AppendTriggered,MUIM_SET,MUIA_Prop_First,0);
  498.     DoMethod(PR_PropV,MUIM_Broadcast_Add,MUIA_Prop_First,PR_PropB,2+MUIP_Broadcast_Add_AppendTriggered,MUIM_SET,MUIA_Prop_First,0);
  499.  
  500.  
  501. /*
  502. ** And here we connect cycle gadgets, radio buttons and the list in the
  503. ** cycle & radio window.
  504. */
  505.  
  506.     DoMethod(CY_Computer,MUIM_Broadcast_Add,MUIA_Cycle_Active,MT_Computer,2+MUIP_Broadcast_Add_AppendTriggered,MUIM_SET,MUIA_Mutex_Active,0);
  507.     DoMethod(CY_Printer ,MUIM_Broadcast_Add,MUIA_Cycle_Active,MT_Printer ,2+MUIP_Broadcast_Add_AppendTriggered,MUIM_SET,MUIA_Mutex_Active,0);
  508.     DoMethod(CY_Display ,MUIM_Broadcast_Add,MUIA_Cycle_Active,MT_Display ,2+MUIP_Broadcast_Add_AppendTriggered,MUIM_SET,MUIA_Mutex_Active,0);
  509.     DoMethod(MT_Computer,MUIM_Broadcast_Add,MUIA_Mutex_Active,CY_Computer,2+MUIP_Broadcast_Add_AppendTriggered,MUIM_SET,MUIA_Cycle_Active,0);
  510.     DoMethod(MT_Printer ,MUIM_Broadcast_Add,MUIA_Mutex_Active,CY_Printer ,2+MUIP_Broadcast_Add_AppendTriggered,MUIM_SET,MUIA_Cycle_Active,0);
  511.     DoMethod(MT_Display ,MUIM_Broadcast_Add,MUIA_Mutex_Active,CY_Display ,2+MUIP_Broadcast_Add_AppendTriggered,MUIM_SET,MUIA_Cycle_Active,0);
  512.     DoMethod(MT_Computer,MUIM_Broadcast_Add,MUIA_Mutex_Active,LV_Computer,2+MUIP_Broadcast_Add_AppendTriggered,MUIM_SET,MUIA_List_Active ,0);
  513.     DoMethod(LV_Computer,MUIM_Broadcast_Add,MUIA_List_Active ,MT_Computer,2+MUIP_Broadcast_Add_AppendTriggered,MUIM_SET,MUIA_Mutex_Active,0);
  514.  
  515.  
  516. /*
  517. ** This one makes us receive input ids from several list views.
  518. */
  519.  
  520.     DoMethod(LV_Volumes ,MUIM_Broadcast_Add,MUIA_Listview_DoubleClick,AP_Demo,2,MUIM_Application_ReturnID,ID_NEWVOL);
  521.     DoMethod(LV_Brian   ,MUIM_Broadcast_Add,MUIA_List_Active,AP_Demo,2,MUIM_Application_ReturnID,ID_NEWBRI);
  522.  
  523.  
  524. /*
  525. ** Now lets set the TAB cycle chain for some of our windows.
  526. */
  527.  
  528.     DoMethod(WI_Master   ,MUIM_Window_SetCycleChain,BT_Groups,BT_Frames,BT_Backfill,BT_Broadcast,BT_Listviews,BT_Cycle,BT_Images,BT_String,BT_Datatype,NULL);
  529.     DoMethod(WI_Listviews,MUIM_Window_SetCycleChain,LV_Directory,LV_Volumes,NULL);
  530.     DoMethod(WI_Cycle    ,MUIM_Window_SetCycleChain,MT_Computer,MT_Printer,MT_Display,CY_Computer,CY_Printer,CY_Display,LV_Computer,NULL);
  531.     DoMethod(WI_String   ,MUIM_Window_SetCycleChain,ST_Brian,NULL);
  532.     if (WI_Datatype)
  533.         DoMethod(WI_Datatype ,MUIM_Window_SetCycleChain,ST_Datatype,NULL);
  534.  
  535.  
  536. /*
  537. ** Set some start values for some objects.
  538. */
  539.  
  540.     DoMethod(ST_Datatype,MUIM_Broadcast_Add,MUIA_String_Final,DT_Datatype,2+MUIP_Broadcast_Add_AppendTriggered,MUIM_SET,MUIA_Datatype_Name,0);
  541.  
  542.     DoMethod(LV_Computer,MUIM_List_Insert,CYA_Computer,-1,MUIV_List_Insert_Last);
  543.     DoMethod(LV_Brian   ,MUIM_List_Insert,LVT_Brian,-1,MUIV_List_Insert_Last);
  544.     set(LV_Computer,MUIA_List_Active,0);
  545.     set(LV_Brian   ,MUIA_List_Active,0);
  546.     set(ST_Brian   ,MUIA_String_AttachedList,LV_Brian);
  547.  
  548.  
  549. /*
  550. ** Everything's ready, lets launch the application. We will
  551. ** open the master window now.
  552. */
  553.  
  554.     DoMethod(AP_Demo,MUIM_Application_AddWindow,WI_Master);
  555.  
  556.  
  557. /*
  558. ** This is the main loop. As you can see, it does just nothing.
  559. ** Everything is handled by MUI, no work for the programmer.
  560. **
  561. ** The only thing we do here is to react on a double click
  562. ** in the volume list (which causes an ID_NEWVOL) by setting
  563. ** a new directory name for the directory list. If you want
  564. ** to see a real file requester with MUI, wait for the
  565. ** next release of MFR :-)
  566. **
  567. ** Since MUI currently has no object oriented menu system
  568. ** that could send broadcast messages itself, we have also
  569. ** to check for the menu ids and open the appropriate
  570. ** windows by hand.
  571. */
  572.  
  573.     {
  574.         ULONG signal;
  575.         BOOL running = TRUE;
  576.         char *buf;
  577.  
  578.         while (running)
  579.         {
  580.             switch (DoMethod(AP_Demo,MUIM_Application_Input,&signal))
  581.             {
  582.                 case MUIV_Application_ReturnID_Quit:
  583.                     running = FALSE;
  584.                     break;
  585.  
  586.                 case ID_NEWVOL:
  587.                     DoMethod(LV_Volumes,MUIM_Volumelist_GetVol,-1,&buf);
  588.                     set(LV_Directory,MUIA_Dirlist_DirName,buf);
  589.                     break;
  590.  
  591.                 case ID_NEWBRI:
  592.                     get(LV_Brian,MUIA_List_Active,&buf);
  593.                     set(ST_Brian,MUIA_String_Contents,LVT_Brian[(int)buf]);
  594.                     break;
  595.  
  596.                 case ID_ABOUT:
  597.                     MUI_Request(AP_Demo, MUIR_Text, "\\appversion\n\\appcopyright", MUIR_Responses, "OK", TAG_DONE);
  598.                     break;
  599.  
  600.                 case ID_FRAMES   : DoMethod(AP_Demo,MUIM_Application_AddWindow,WI_Frames   ); break;
  601.                 case ID_IMAGES   : DoMethod(AP_Demo,MUIM_Application_AddWindow,WI_Images   ); break;
  602.                 case ID_BROADCAST: DoMethod(AP_Demo,MUIM_Application_AddWindow,WI_Broadcast); break;
  603.                 case ID_GROUPS   : DoMethod(AP_Demo,MUIM_Application_AddWindow,WI_Groups   ); break;
  604.                 case ID_BACKFILL : DoMethod(AP_Demo,MUIM_Application_AddWindow,WI_Backfill ); break;
  605.                 case ID_LISTVIEWS: DoMethod(AP_Demo,MUIM_Application_AddWindow,WI_Listviews); break;
  606.                 case ID_CYCLE    : DoMethod(AP_Demo,MUIM_Application_AddWindow,WI_Cycle    ); break;
  607.                 case ID_STRING   : DoMethod(AP_Demo,MUIM_Application_AddWindow,WI_String   ); break;
  608.                 case ID_DATATYPE : if (WI_Datatype) DoMethod(AP_Demo,MUIM_Application_AddWindow,WI_Datatype ); break;
  609.             }
  610.             if (signal) Wait(signal);
  611.         }
  612.     }
  613.  
  614.  
  615. /*
  616. ** Shut down the application, remove all windows.
  617. */
  618.  
  619.     DoMethod(AP_Demo,MUIM_Application_RemoveWindow,NULL);
  620.  
  621.  
  622. /*
  623. ** Call the fail function in demos.h, this will dispose all
  624. ** objects and close "muimaster.library".
  625. */
  626.  
  627.     fail(NULL);
  628. }
  629.  
  630.  
  631. /*
  632. ** This is the end...
  633. */
  634.  
  635.  
  636.  
  637.  
  638.  
  639.  
  640.  
  641.  
  642.  
  643.  
  644.  
  645.  
  646. /*
  647. ** expect for a little array definition:
  648. */
  649.  
  650. static const char *LVT_Brian[48] =
  651. {
  652. "Cheer up, Brian. You know what they say.",
  653. "Some things in life are bad,",
  654. "They can really make you mad.",
  655. "Other things just make you swear and curse.",
  656. "When you're chewing on life's grissle,",
  657. "Don't grumble, give a whistle.",
  658. "And this'll help things turn out for the best,",
  659. "And...",
  660. "",
  661. "Always look on the bright side of life",
  662. "Always look on the light side of life",
  663. "",
  664. "If life seems jolly rotten,",
  665. "There's something you've forgotten,",
  666. "And that's to laugh, and smile, and dance, and sing.",
  667. "When you're feeling in the dumps,",
  668. "Don't be silly chumps,",
  669. "Just purse your lips and whistle, that's the thing.",
  670. "And...",
  671. "",
  672. "Always look on the bright side of life, come on!",
  673. "Always look on the right side of life",
  674. "",
  675. "For life is quite absurd,",
  676. "And death's the final word.",
  677. "You must always face the curtain with a bow.",
  678. "Forget about your sin,",
  679. "Give the audience a grin.",
  680. "Enjoy it, it's your last chance anyhow,",
  681. "So...",
  682. "",
  683. "Always look on the bright side of death",
  684. "Just before you draw your terminal breath.",
  685. "",
  686. "Life's a piece of shit,",
  687. "When you look at it.",
  688. "Life's a laugh, and death's a joke, it's true.",
  689. "You'll see it's all a show,",
  690. "Keep 'em laughing as you go,",
  691. "Just remember that the last laugh is on you.",
  692. "And...",
  693. "",
  694. "Always look on the bright side of life !",
  695. "",
  696. "...",
  697. "",
  698. "[Thanx to sprooney@unix1.tcd.ie and to Mr. M. Python]",
  699. NULL,
  700. };
  701.