/* Copyright 2005 M.Andersson. All rights reserved. */ /* Build with: gcc -o tabs tabs.c -lraauto -lauto */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include enum { GID_MAIN=0, GID_CLICKTAB, GID_PAGE_TAB1, GID_LISTBROWSER_TAB1, GID_STRING_TEXT_TAB1, GID_PAGE_TAB2, GID_LISTBROWSER_TAB2, GID_BUTTON_TAB2, GID_PAGE_TAB3, GID_CHOOSER_TAB3, GID_LAST }; char *tabsLabels[] = { "Tab 1", "Tab 2", "Tab 3", NULL }; struct ColumnInfo ciListBrowser[] = { {15,"Name ",0 }, {80,"Message",0 }, {0xffff,NULL,0xffff} }; STRPTR chooserLabels[] = {"None","TAB1","TAB2",NULL}; void freeList(struct List *list) { struct Node *node, *nextnode; node = list->lh_Head; while (nextnode = node->ln_Succ) { IListBrowser->FreeListBrowserNode(node); node = nextnode; } IExec->NewList(list); } void freeListChooser(struct List *list) { struct Node *node, *nextnode; node = list->lh_Head; while (nextnode = node->ln_Succ) { IChooser->FreeChooserNode(node); node = nextnode; } IExec->NewList(list); } void freeListClickTab(struct List *list) { struct Node *node, *nextnode; node = list->lh_Head; while (nextnode = node->ln_Succ) { IClickTab->FreeClickTabNode(node); node = nextnode; } IExec->NewList(list); } // Tabs GUI int main(void) { struct Screen *scr; struct MsgPort *AppPort = NULL; struct Window *window = NULL; struct Gadget *gadgets[GID_LAST]; Object *windowObject = NULL; Object *pageObject = NULL; ULONG wait, signal; ULONG result; UWORD code; int i, done = FALSE; struct List clickTabLabelList; struct List listBrowser1LabelList; struct List listBrowser2LabelList; struct Node *node; IExec->NewList(&clickTabLabelList); IExec->NewList(&listBrowser1LabelList); IExec->NewList(&listBrowser2LabelList); for(i = 0; i < 3; i++) { if (node = IClickTab->AllocClickTabNode(TNA_Text, tabsLabels[i], TNA_Number, i, TAG_DONE)) { IExec->AddTail(&clickTabLabelList, node); } } if ((AppPort = (struct MsgPort *)IExec->CreateMsgPort()) == NULL) return 0; if ((scr = IIntuition->LockPubScreen (NULL)) == NULL) { IExec->DeletePort(AppPort); return 0; } windowObject = (Object *)WindowObject, WA_Title, "Simple Tabs", WA_Activate, TRUE, WA_DepthGadget, FALSE, WA_DragBar, TRUE, WA_CloseGadget, TRUE, WA_SizeGadget, TRUE, WINDOW_IconifyGadget, TRUE, WINDOW_IconTitle, "Tabs", WINDOW_AppPort, AppPort, WINDOW_Position, WPOS_TOPLEFT, WINDOW_ParentGroup, gadgets[GID_MAIN] = (struct Gadget *)VGroupObject, LAYOUT_VertAlignment, LALIGN_CENTER, LAYOUT_HorizAlignment, LALIGN_CENTER, LAYOUT_BevelStyle, BVS_FIELD, LAYOUT_AddChild, gadgets[GID_CLICKTAB] = (struct Gadget *)ClickTabObject, GA_ID, GID_CLICKTAB, GA_RelVerify, TRUE, GA_TabCycle,FALSE, CLICKTAB_Current, 0, CLICKTAB_Labels, (ULONG)&clickTabLabelList, CLICKTAB_PageGroup, pageObject = PageObject, PAGE_Add, gadgets[GID_PAGE_TAB1] = (struct Gadget *)VGroupObject, LAYOUT_AddChild, gadgets[GID_LISTBROWSER_TAB1] = (struct Gadget *)ListBrowserObject, GA_ID, GID_LISTBROWSER_TAB1, GA_RelVerify, FALSE, GA_Text, "ListBrowser 1", GA_TabCycle, FALSE, GA_Disabled,FALSE, GA_ReadOnly, TRUE, LISTBROWSER_Labels, (ULONG)&listBrowser1LabelList, LISTBROWSER_ColumnInfo, (ULONG)&ciListBrowser, LISTBROWSER_ColumnTitles, TRUE, LISTBROWSER_MultiSelect, FALSE, LISTBROWSER_Separators, TRUE, LISTBROWSER_ShowSelected, FALSE, LISTBROWSER_Editable,FALSE, LISTBROWSER_HorizontalProp, TRUE, LISTBROWSER_AutoFit, FALSE, LISTBROWSER_HorizSeparators, FALSE, LISTBROWSER_WrapText, TRUE, ListBrowserEnd, CHILD_MinWidth,200, CHILD_MinHeight,75, LAYOUT_AddChild, gadgets[GID_STRING_TEXT_TAB1] = (struct Gadget *)StringObject, GA_ID, GID_STRING_TEXT_TAB1, GA_TabCycle, TRUE, GA_RelVerify, TRUE, GA_Disabled, FALSE, STRINGA_TextVal, "", EndObject, EndGroup, PAGE_Add, gadgets[GID_PAGE_TAB2] = (struct Gadget *)VGroupObject, LAYOUT_AddChild, gadgets[GID_LISTBROWSER_TAB2] = (struct Gadget *)ListBrowserObject, GA_ID, GID_LISTBROWSER_TAB2, GA_RelVerify, FALSE, GA_Text, "ListBrowser 2", GA_TabCycle, FALSE, GA_Disabled,FALSE, GA_ReadOnly, TRUE, LISTBROWSER_Labels, (ULONG)&listBrowser2LabelList, LISTBROWSER_ColumnInfo, (ULONG)&ciListBrowser, LISTBROWSER_ColumnTitles, TRUE, LISTBROWSER_MultiSelect, FALSE, LISTBROWSER_Separators, TRUE, LISTBROWSER_ShowSelected, FALSE, LISTBROWSER_Editable,FALSE, LISTBROWSER_HorizontalProp, TRUE, LISTBROWSER_AutoFit, FALSE, LISTBROWSER_HorizSeparators, FALSE, LISTBROWSER_WrapText, TRUE, ListBrowserEnd, CHILD_MinWidth,200, CHILD_MinHeight,75, LAYOUT_AddChild, gadgets[GID_BUTTON_TAB2] = (struct Gadget *)ButtonObject, GA_ID, GID_BUTTON_TAB2, GA_TabCycle, TRUE, GA_RelVerify, TRUE, GA_Disabled, FALSE, GA_Text, "_REPLY", EndObject, EndGroup, PAGE_Add, gadgets[GID_PAGE_TAB2] = (struct Gadget *)VGroupObject, LAYOUT_AddImage, BitMapObject, BITMAP_Screen,scr, BITMAP_SourceFile,"SYS:Prefs/Presets/Default/640x480.preset/Backdrops/blue9_640x480.jpg", BITMAP_Masking,TRUE, End, LAYOUT_AddChild, gadgets[GID_CHOOSER_TAB3] = (struct Gadget *)ChooserObject, GA_ID, GID_CHOOSER_TAB3, GA_TabCycle, TRUE, GA_RelVerify, TRUE, GA_Disabled, FALSE, CHOOSER_LabelArray, &chooserLabels, EndObject, EndGroup, End, End, EndGroup, EndWindow; if (windowObject == NULL) { IExec->DeletePort(AppPort); freeListClickTab(&clickTabLabelList); freeList(&listBrowser1LabelList); freeList(&listBrowser2LabelList); IIntuition->UnlockPubScreen(NULL,scr); return 0; } if ((window = (struct Window *) RA_OpenWindow(windowObject)) == NULL) { IIntuition->DisposeObject(windowObject); IExec->DeletePort(AppPort); freeListClickTab(&clickTabLabelList); freeList(&listBrowser1LabelList); freeList(&listBrowser2LabelList); IIntuition->UnlockPubScreen(NULL,scr); return 0; } IIntuition->GetAttr(WINDOW_SigMask, windowObject, &signal); while (!done) { wait = IExec->Wait( signal | SIGBREAKF_CTRL_C); if ( wait & SIGBREAKF_CTRL_C ) done = TRUE; else { while ( (result = RA_HandleInput(windowObject, &code) ) != WMHI_LASTMSG ) { switch (result & WMHI_CLASSMASK) { case WMHI_CLOSEWINDOW: done = TRUE; break; case WMHI_ICONIFY: RA_Iconify(windowObject); window = NULL; break; case WMHI_UNICONIFY: window = (struct Window *) RA_OpenWindow(windowObject); if (window) IIntuition->GetAttr(WINDOW_SigMask, windowObject, &signal); else done = TRUE; // error re-opening window! break; case WMHI_GADGETUP: switch (result & WMHI_GADGETMASK) { case GID_STRING_TEXT_TAB1: { ULONG pszBuffer; IIntuition->GetAttr((ULONG)STRINGA_TextVal, (gadgets[GID_STRING_TEXT_TAB1]), &pszBuffer); ILayout->SetPageGadgetAttrs(gadgets[GID_LISTBROWSER_TAB1], pageObject, window,NULL,(LONG)LISTBROWSER_Labels,~0,TAG_END); ILayout->SetPageGadgetAttrs(gadgets[GID_LISTBROWSER_TAB2], pageObject, window,NULL,(LONG)LISTBROWSER_Labels,~0,TAG_END); if (node = IListBrowser->AllocListBrowserNode(2, LBNA_Flags, LBFLG_CUSTOMPENS, LBNA_Column, 0, LBNCA_CopyText, TRUE, LBNCA_Text, "TAB1", LBNCA_MaxChars, 1024, LBNCA_Editable, FALSE, LBNCA_VertJustify,LRJ_TOP, LBNA_Column, 1, LBNCA_CopyText, TRUE, LBNCA_Text, (char *)pszBuffer, LBNCA_MaxChars, 1024, LBNCA_Editable, FALSE, LBNCA_WordWrap, TRUE, TAG_DONE)) { IExec->AddTail(&listBrowser1LabelList, node); } if (node = IListBrowser->AllocListBrowserNode(2, LBNA_Flags, LBFLG_CUSTOMPENS, LBNA_Column, 0, LBNCA_CopyText, TRUE, LBNCA_Text, "From TAB1", LBNCA_MaxChars, 9, LBNCA_Editable, FALSE, LBNCA_VertJustify,LRJ_TOP, LBNA_Column, 1, LBNCA_CopyText, TRUE, LBNCA_Text, (char *)pszBuffer, LBNCA_MaxChars, 1024, LBNCA_Editable, FALSE, LBNCA_WordWrap, TRUE, TAG_DONE)) { IExec->AddTail(&listBrowser2LabelList, node); } ILayout->SetPageGadgetAttrs(gadgets[GID_LISTBROWSER_TAB1], pageObject, window,NULL,(LONG)LISTBROWSER_Labels,&listBrowser1LabelList,TAG_END); ILayout->SetPageGadgetAttrs(gadgets[GID_STRING_TEXT_TAB1], pageObject, window,NULL,(LONG)STRINGA_TextVal,"",TAG_END); ILayout->RefreshPageGadget(gadgets[GID_LISTBROWSER_TAB1], pageObject, window, NULL); ILayout->RefreshPageGadget(gadgets[GID_STRING_TEXT_TAB1], pageObject, window, NULL); ILayout->SetPageGadgetAttrs(gadgets[GID_LISTBROWSER_TAB2], pageObject, window,NULL,(LONG)LISTBROWSER_Labels,&listBrowser2LabelList,TAG_END); ILayout->SetPageGadgetAttrs(gadgets[GID_LISTBROWSER_TAB2], pageObject, window,NULL,(LONG)LISTBROWSER_Position,LBP_BOTTOM,TAG_END); ILayout->RefreshPageGadget(gadgets[GID_LISTBROWSER_TAB2], pageObject, window, NULL); ILayout->ActivateLayoutGadget(gadgets[GID_MAIN],window,NULL,(ULONG)gadgets[GID_STRING_TEXT_TAB1]); break; } case GID_BUTTON_TAB2: { ILayout->SetPageGadgetAttrs(gadgets[GID_LISTBROWSER_TAB1], pageObject, window,NULL,(LONG)LISTBROWSER_Labels,~0,TAG_END); ILayout->SetPageGadgetAttrs(gadgets[GID_LISTBROWSER_TAB2], pageObject, window,NULL,(LONG)LISTBROWSER_Labels,~0,TAG_END); if (node = IListBrowser->AllocListBrowserNode(5, LBNA_Flags, LBFLG_CUSTOMPENS, LBNA_Column, 0, LBNCA_CopyText, TRUE, LBNCA_Text, "From TAB2", LBNCA_MaxChars, 9, LBNCA_Editable, FALSE, LBNCA_VertJustify,LRJ_TOP, LBNA_Column, 1, LBNCA_CopyText, TRUE, LBNCA_Text, "Reply!", LBNCA_MaxChars, 6, LBNCA_Editable, FALSE, LBNCA_WordWrap, TRUE, TAG_DONE)) { IExec->AddTail(&listBrowser1LabelList, node); } if (node = IListBrowser->AllocListBrowserNode(5, LBNA_Flags, LBFLG_CUSTOMPENS, LBNA_Column, 0, LBNCA_CopyText, TRUE, LBNCA_Text, "TAB2", LBNCA_MaxChars, 9, LBNCA_Editable, FALSE, LBNCA_VertJustify,LRJ_TOP, LBNA_Column, 1, LBNCA_CopyText, TRUE, LBNCA_Text, "I replied!", LBNCA_MaxChars, 10, LBNCA_Editable, FALSE, LBNCA_WordWrap, TRUE, TAG_DONE)) { IExec->AddTail(&listBrowser2LabelList, node); } ILayout->SetPageGadgetAttrs(gadgets[GID_LISTBROWSER_TAB1], pageObject, window,NULL,(LONG)LISTBROWSER_Labels,&listBrowser1LabelList,TAG_END); ILayout->RefreshPageGadget(gadgets[GID_LISTBROWSER_TAB1], pageObject, window, NULL); ILayout->SetPageGadgetAttrs(gadgets[GID_LISTBROWSER_TAB2], pageObject, window,NULL,(LONG)LISTBROWSER_Labels,&listBrowser2LabelList,TAG_END); ILayout->SetPageGadgetAttrs(gadgets[GID_LISTBROWSER_TAB2], pageObject, window,NULL,(LONG)LISTBROWSER_Position,LBP_BOTTOM,TAG_END); ILayout->RefreshPageGadget(gadgets[GID_LISTBROWSER_TAB2], pageObject, window, NULL); break; } case GID_CHOOSER_TAB3: { ULONG chooserRow; IIntuition->GetAttr((ULONG)CHOOSER_Selected, (gadgets[GID_CHOOSER_TAB3]), &chooserRow); if(chooserRow > 0) { IIntuition->SetAttrs(gadgets[GID_CLICKTAB],(ULONG)CLICKTAB_Current,chooserRow - 1,TAG_END); ILayout->RethinkLayout(gadgets[GID_CLICKTAB],window,NULL,TRUE); } ILayout->SetPageGadgetAttrs(gadgets[GID_CHOOSER_TAB3],pageObject,window,NULL,(LONG)CHOOSER_Selected,0,TAG_END); break; } default:; } break; default:; } } } } IIntuition->DisposeObject(windowObject); IExec->DeletePort(AppPort); freeListClickTab(&clickTabLabelList); freeList(&listBrowser1LabelList); freeList(&listBrowser2LabelList); IIntuition->UnlockPubScreen(NULL,scr); return 0; }