Code: Select all
/*#################*/
/* TstBorderless.c */ /* 14.7.2013 */
/*#################*/
/*
Showing extra active border space around a borderless ListBrowser.
gcc -o TstBorderless TstBorderless.c -lauto
*/
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include <proto/dos.h>
#include <proto/exec.h>
#include <proto/intuition.h>
#include <proto/layout.h>
#include <proto/listbrowser.h>
#include <proto/utility.h>
#include <proto/window.h>
#include <classes/window.h>
#include <gadgets/listbrowser.h>
#include <intuition/intuition.h>
#include <libraries/keymap.h>
#include <utility/tagitem.h>
#define PgmName "TstBorderless"
#define PgmVersion "$VER: TstBorderless 0.0 (14.7.2013) C\0"
#define NROWS 50
#define NCOLS 50
#define COLWIDTH 50
Object *w,
*pg,
*listGad,
*butGad;
struct Window *wp;
struct List lblist;
struct ColumnInfo *ci;
typedef char string10[10];
string10 cellstr[NROWS][NCOLS];
/*----------------------------------------*/
static void Assert(BOOL b, char msg[])
/*----------------------------------------*/
{
if (!b) {
fprintf(stderr, "%s\n", msg);
assert(0);
}
}
/*###########################################################################*/
/* --------------------- start of Tags Array Support ---------------------- */
/*###########################################################################*/
struct TagsStruct {struct TagItem *Tags;
int numelems;
int cntr;
};
int tagcntr,
tagsnumelems;
/*-------------------------------------------------------------*/
static void InitTags(struct TagsStruct *TagsInfo, int numtags)
/*-------------------------------------------------------------*/
{
TagsInfo->Tags = (struct TagItem *) malloc(numtags * sizeof(struct TagItem));
Assert(TagsInfo->Tags != NULL, "Out of memory");
TagsInfo->numelems = numtags;
TagsInfo->cntr = 0;
TagsInfo->Tags[0].ti_Tag = TAG_DONE;
}
/*-----------------------------------------------------------------------------------------*/
static void RegisterTags(struct TagsStruct *TagsInfo, struct TagItem *TagsArr, int numtags)
/*-----------------------------------------------------------------------------------------*/
{
printf("TagsArr %X\n", TagsArr);
TagsInfo->Tags = TagsArr;
TagsInfo->numelems = numtags;
TagsInfo->cntr = 0;
TagsInfo->Tags[0].ti_Tag = TAG_DONE;
}
/*--------------------------------------------------*/
static void ResetTags(struct TagsStruct *TagsInfo)
/*-------------------------------------------------*/
{
TagsInfo->cntr = 0;
TagsInfo->Tags[0].ti_Tag = TAG_DONE;
}
/*-----------------------------------------------*/
static void TermTags(struct TagsStruct *TagsInfo)
/*-----------------------------------------------*/
{
free(TagsInfo->Tags);
TagsInfo->Tags = NULL;
TagsInfo->numelems = 0;
TagsInfo->cntr = 0;
}
/*-------------------------------------------------------------------------*/
static void AsgTag(struct TagsStruct *TagsInfo, uint tagcode, uint tagval)
/*-------------------------------------------------------------------------*/
{
TagsInfo->Tags[0].ti_Tag = tagcode;
TagsInfo->Tags[0].ti_Data = tagval;
TagsInfo->Tags[1].ti_Tag = TAG_DONE;
TagsInfo->cntr = 1;
}
/*-------------------------------------------------------------------------*/
static void CatTag(struct TagsStruct *TagsInfo, uint tagcode, uint tagval)
/*-------------------------------------------------------------------------*/
{
char msg[80];
if (TagsInfo->cntr >= (TagsInfo->numelems-1)) {
snprintf(msg, 80, "CatTag: Tags overflow, %u\n", TagsInfo->cntr);
Assert(0, msg);
}
TagsInfo->Tags[TagsInfo->cntr].ti_Tag = tagcode;
TagsInfo->Tags[TagsInfo->cntr].ti_Data = tagval;
TagsInfo->cntr++;
TagsInfo->Tags[TagsInfo->cntr].ti_Tag = TAG_DONE;
}
/*---------------------------------------------------------------------------------------------------------*/
static void CatTags2(struct TagsStruct *TagsInfo, uint tagcode1, uint tagval1, uint tagcode2, uint tagval2)
/*---------------------------------------------------------------------------------------------------------*/
{
CatTag(TagsInfo, tagcode1, tagval1);
CatTag(TagsInfo, tagcode2, tagval2);
}
/*-----------------------------------------------------------------------------------------------------*/
static void CatTags3(struct TagsStruct *TagsInfo, uint tagcode1, uint tagval1, uint tagcode2, uint tagval2,
uint tagcode3, uint tagval3)
/*-----------------------------------------------------------------------------------------------------*/
{
CatTags2(TagsInfo, tagcode1, tagval1, tagcode2, tagval2);
CatTag(TagsInfo, tagcode3, tagval3);
}
/*-----------------------------------------------------------------------------------------------------*/
static void CatTags4(struct TagsStruct *TagsInfo, uint tagcode1, uint tagval1, uint tagcode2, uint tagval2,
uint tagcode3, uint tagval3, uint tagcode4, uint tagval4)
/*-----------------------------------------------------------------------------------------------------*/
{
CatTags2(TagsInfo, tagcode1, tagval1, tagcode2, tagval2);
CatTags2(TagsInfo, tagcode3, tagval3, tagcode4, tagval4);
}
/*###########################################################################*/
/* --------------------- end of Tags Array Support -- ---------------------- */
/*###########################################################################*/
/*------------------------------------*/
static Object* MakeRootContainer(void)
/*------------------------------------*/
{
Object *ret;
ret = IIntuition->NewObject(NULL, "layout.gadget",
GA_Width, 100,
GA_Height, 100,
LAYOUT_Orientation, LAYOUT_ORIENT_HORIZ,
LAYOUT_SpaceOuter, FALSE,
LAYOUT_SpaceInner, FALSE,
LAYOUT_DeferLayout, FALSE,
LAYOUT_FillPen, 4,
TAG_DONE);
Assert(ret != NULL, "MakeRootContainer fail");
return ret;
}
/*-------------------------------------------*/
static Object* MakeWindowObject(char *title)
/*-------------------------------------------*/
{
return IIntuition->NewObject(NULL, "window.class",
WA_Title, title,
WA_CloseGadget, 1,
WA_DepthGadget, 1,
WA_SizeGadget, 1,
WA_DragBar, 1,
WA_Activate, 1,
WA_IDCMP, IDCMP_MOUSEMOVE,
WA_InnerWidth, 320,
WA_InnerHeight, 240,
WINDOW_Position, WPOS_CENTERSCREEN,
WINDOW_Layout, pg,
TAG_DONE);
}
/*-----------------------------------*/
static Object* MakeListObject(void)
/*-----------------------------------*/
{
int r, c;
struct Node *n;
Object *ret;
struct TagsStruct TagsInfo;
int numtags = 6*NCOLS+10;
InitTags(&TagsInfo, numtags);
IExec->NewList(&lblist);
/* set up the ColumnInfo */
for (c = 0; c < NCOLS; c++) {
CatTags2(&TagsInfo, LBCIA_Column, c,
LBCIA_Width, COLWIDTH);
CatTag(&TagsInfo, LBCIA_DraggableSeparator, 1);
}
ci = IListBrowser->AllocLBColumnInfoA(NCOLS, TagsInfo.Tags);
Assert(ci != NULL, "AllocLBColumnInfoA FAIL");
/* set up the LISTBROWSER_Labels */
for (r = 0; r < NROWS; r++) {
AsgTag(&TagsInfo, LBNA_Flags, LBFLG_CUSTOMPENS);
for (c = 0; c < NCOLS; c++) {
CatTag(&TagsInfo, LBNA_Column, c);
CatTag(&TagsInfo, LBNCA_FGPen, 1);
CatTag(&TagsInfo, LBNCA_BGPen, 2);
snprintf((char *)&cellstr[r][c], 10, "%-u,%-u", r, c); /* cell contents */
CatTag(&TagsInfo, LBNCA_Text, (uint) &cellstr[r][c]);
}
n = IListBrowser->AllocListBrowserNodeA(NCOLS, TagsInfo.Tags);
Assert(n != NULL, "AllocListBrowserNodeA FAIL in MakeListObject()")
;
IExec->AddTail(&lblist, n);
}
ResetTags(&TagsInfo);
CatTags2(&TagsInfo, GA_ID, 1,
GA_RelVerify, TRUE);
CatTags2(&TagsInfo, GA_Immediate, TRUE,
GA_FollowMouse, TRUE);
CatTags2(&TagsInfo, LISTBROWSER_Labels, (uint) &lblist,
LISTBROWSER_ShowSelected, TRUE);
CatTags2(&TagsInfo, LISTBROWSER_VerticalProp, 0,
LISTBROWSER_HorizontalProp, 0);
CatTag(&TagsInfo, LISTBROWSER_Borderless, TRUE);
CatTag(&TagsInfo, LISTBROWSER_ColumnInfo, (uint) ci);
CatTags2(&TagsInfo, LISTBROWSER_VertSeparators, TRUE,
LISTBROWSER_HorizSeparators, TRUE);
CatTag(&TagsInfo, LISTBROWSER_VirtualWidth, NCOLS*COLWIDTH); /* this works around the AutoVirtualWidth bug w/ fixed widths */
ret = IIntuition->NewObjectA(NULL, "listbrowser.gadget", TagsInfo.Tags);
Assert(ret != NULL, "MakeObject FAIL");
TermTags(&TagsInfo);
return ret;
}
/*---------------------------------------------------*/
static void AddToContainer(Object *cont, Object *gad)
/*---------------------------------------------------*/
{
uint uRes;
uRes = IIntuition->SetAttrs(cont, LAYOUT_AddChild, (uint) gad,
CHILD_MinWidth, 100,
CHILD_MinHeight, 100);
}
/*---------------------------*/
static void OpenTheWndo(void)
/*---------------------------*/
{
pg = MakeRootContainer();
listGad = MakeListObject();
AddToContainer(pg, listGad);
w = MakeWindowObject(PgmVersion);
Assert(w != NULL, "MakeWindowObject FAIL");
wp = (struct Window *)IIntuition->IDoMethod(w, WM_OPEN);
Assert(wp != NULL, "WM_OPEN fail");
/*ILayout->RethinkLayout((struct Gadget *) pg, wp, NULL, TRUE);*/
}
/*------------------------------*/
int main(int argc, char *argv[])
/*------------------------------*/
{
struct wmHandle msg;
int16 code = 0;
int i;
uint32 sigmask = 0;
uint32 siggot;
int gadgleft,
winborderleft;
uint32 result = 0;
BOOL done = FALSE;
w = NULL;
OpenTheWndo();
IIntuition->GetAttr(WINDOW_SigMask, w, &sigmask);
winborderleft = wp->BorderLeft;
IIntuition->GetAttr(GA_Left, listGad, (uint32 *) &gadgleft);
while (!done) {
siggot = IExec->Wait(sigmask | SIGBREAKF_CTRL_C);
done = (siggot & SIGBREAKF_CTRL_C);
while ((result = IIntuition->IDoMethod(w, WM_HANDLEINPUT, &code))) {
switch(result & WMHI_CLASSMASK) {
case WMHI_CLOSEWINDOW:
done = TRUE;
break;
case WMHI_MOUSEMOVE:
printf("gx= %i\n", wp->MouseX-gadgleft);
break;
}
}
}
IIntuition->DisposeObject(w);
IListBrowser->FreeListBrowserList(&lblist);
IListBrowser->FreeLBColumnInfo(ci);
}