datebrowser.gadget

This forum is for general developer support questions.
Post Reply
User avatar
javierdlr
Beta Tester
Beta Tester
Posts: 389
Joined: Sun Jun 19, 2011 11:13 pm
Location: Donostia (GUIPUZCOA) - Spain
Contact:

datebrowser.gadget

Post by javierdlr »

Hi, playing a bit with datebrowser_gd I don't get what 'DATEBROWSER_ShowTitle, FALSE,' should do.
If setting it to FALSE, means that Mon,Tue,Wed,.. strings should be hidden, here It doesn't work :-(

Autodocs says:
DATEBROWSER_ShowTitle (BOOL)
Enables display of the week-day title bar.
Defaults to FALSE.

See example sourcfe code (execute datebrowser.c to compile).
1)The right side has a little gap/space between the datebrowser and the window border, someway to avoid such gap/space?
2)Any way to make "date-buttons" less wide?

TIA

Code: Select all

;/* Example
gcc -N -Wall -o DateBrowser dateBrowser.c -lauto -gstabs
quit

*  DateBrowser.c -- DateBrowser class Example.
*
*  This code opens a window and then creates a datebrowser object.
*  There have been no tags applied, but setting the date and day
*  are possible. See the datebrowser.doc for more details.
*/
#include <gadgets/datebrowser.h>
#include <classes/window.h>
#include <gadgets/layout.h>

#include <proto/intuition.h>
#include <proto/graphics.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include <proto/datebrowser.h>
#include <proto/diskfont.h>
#include <proto/locale.h>

struct Library *DateBrowserBase;
struct DateBrowserIFace *IDateBrowser;

#define OBJ(x) Objects[x]
#define GAD(x) (struct Gadget *)Objects[x]

enum
{
    GID_MAIN = 0,
    GID_DATEBROWSER,
    GID_LAST
};

enum
{
    WID_MAIN=0,
    WID_LAST
};

enum
{
    OID_MAIN = 0,
    OID_LAST
};


void fmtfunct(struct Hook *hook, struct Locale *locale, ULONG ch)
{
 char *buffer = (char *)hook->h_Data;
 *buffer++ = ch;
 hook->h_Data = (APTR)buffer;
}


int main(void)
{
 struct Window *windows[WID_LAST];
 Object *win[OID_LAST], *Objects[GID_LAST];
// CONST_STRPTR weekname[] = {"Su", "Mo", "Tu", "We", "Th", "Fr", "Sa",};
 struct TextAttr ta = {0};
 struct TextFont *font;
 char buffer[20];
 int32 D_today, M_today, Y_today;
 struct Hook *prhook;
 struct DateStamp ds;

 DiskfontBase = IExec->OpenLibrary("diskfont.library", 52);
// if(!DiskfontBase) return FALSE;
 IDiskfont = (struct DiskfontIFace *)IExec->GetInterface(DiskfontBase, "main", 1, NULL);
// if(!IDiskfont) return FALSE;

 ta.ta_Name = "DejaVu Sans Condensed.font";
 ta.ta_YSize = 12;
 font = IDiskfont->OpenDiskFont(&ta);
//IDOS->Printf("Changed to use: '%s', %ld\n",font->tf_Message.mn_Node.ln_Name,font->tf_YSize);

 IDOS->DateStamp(&ds);

 prhook = (struct Hook *)IExec->AllocSysObjectTags(ASOT_HOOK,
                                     ASOHOOK_Entry, fmtfunct,
                                     ASOHOOK_Data, buffer, TAG_DONE);
 ILocale->FormatDate(NULL,"%d", &ds, prhook);
//IDOS->Printf("Dia: %s  ",buffer);
 IDOS->StrToLong(buffer, &D_today);

 prhook = (struct Hook *)IExec->AllocSysObjectTags(ASOT_HOOK,
                                     ASOHOOK_Entry, fmtfunct,
                                     ASOHOOK_Data, buffer, TAG_DONE);
 ILocale->FormatDate(NULL,"%m", &ds, prhook);
//IDOS->Printf("Mes: %s  ",buffer);
 IDOS->StrToLong(buffer, &M_today);

 prhook = (struct Hook *)IExec->AllocSysObjectTags(ASOT_HOOK,
                                     ASOHOOK_Entry, fmtfunct,
                                     ASOHOOK_Data, buffer, TAG_DONE);
 ILocale->FormatDate(NULL,"%Y", &ds, prhook);
//IDOS->Printf("Año: %s\n",buffer);
 IDOS->StrToLong(buffer, &Y_today);

 prhook = (struct Hook *)IExec->AllocSysObjectTags(ASOT_HOOK,
                                     ASOHOOK_Entry, fmtfunct,
                                     ASOHOOK_Data, buffer, TAG_DONE);
 ILocale->FormatDate(NULL,"%^B %Y", &ds, prhook);
//IDOS->Printf("Fecha: %s\n",buffer);

 /* Create the window object. */
 win[OID_MAIN] = IIntuition->NewObject(NULL, "window.class",
//            WA_ScreenTitle, "DateBrowser",
            WA_Title,       buffer,
            WA_Activate,    TRUE,
            WA_DepthGadget, TRUE,
            WA_DragBar,     TRUE,
            WA_CloseGadget, TRUE,
            //WA_SizeGadget,  TRUE,
            WINDOW_Position,    WPOS_CENTERMOUSE,
            WINDOW_ParentGroup, OBJ(GID_MAIN) = IIntuition->NewObject(NULL, "layout.gadget",
             LAYOUT_SpaceOuter, FALSE,
             //LAYOUT_DeferLayout, TRUE,
             LAYOUT_AddChild, OBJ(GID_DATEBROWSER) = IIntuition->NewObject(NULL, "datebrowser.gadget",
              GA_ReadOnly, TRUE,
              GA_TextAttr, ta,
              //DATEBROWSER_ShowTitle, TRUE,
              //DATEBROWSER_DayTitles, weekname,
              DATEBROWSER_Day,   D_today,
              DATEBROWSER_Month, M_today,
              DATEBROWSER_Year,  Y_today,
             TAG_DONE),
            TAG_DONE),
 TAG_END);

 // Window/Object creation sucessful?
 if(win[OID_MAIN])
 {
  // Open the window.
  if( (windows[WID_MAIN] = (struct Window *)IIntuition->IDoMethod(win[OID_MAIN], WM_OPEN)) )
  {
   ULONG wait, signal, done = FALSE, result;
   UWORD code;

   // Obtain the window wait signal mask.
   IIntuition->GetAttr(WINDOW_SigMask, win[OID_MAIN], &signal);

   // Input Event Loop
   while(!done)
   {
    wait = IExec->Wait( signal | SIGBREAKF_CTRL_C);

    if(wait & SIGBREAKF_CTRL_C) done = TRUE;
    else
    {
     while( (result = IIntuition->IDoMethod(win[OID_MAIN], WM_HANDLEINPUT, &code)) != WMHI_LASTMSG )
     {
      switch(result & WMHI_CLASSMASK)
      {
       case WMHI_CLOSEWINDOW:
        windows[WID_MAIN] = NULL;
        done = TRUE;
       break;
      }
     }
    }

   }
  }
  // Disposing of the window object will also close the window if it is
  // already opened, and it will dispose of the layout object attached to it.
  IIntuition->DisposeObject(win[OID_MAIN]);
 }

 IExec->FreeSysObject(ASOT_HOOK, prhook);
 IGraphics->CloseFont(font);
 return(0);
}
*EDIT: fixed some bugs/typos in DateBrowser source included
Last edited by javierdlr on Tue Jan 14, 2014 1:35 pm, edited 2 times in total.
User avatar
salass00
AmigaOS Core Developer
AmigaOS Core Developer
Posts: 534
Joined: Sat Jun 18, 2011 4:12 pm
Location: Finland
Contact:

Re: datebrowser.gadget

Post by salass00 »

@javierdlr

If it defaults to FALSE as stated in the autodoc then setting it to FALSE obviously won't do anything. How about you set it to TRUE instead and see if that makes any difference?
User avatar
javierdlr
Beta Tester
Beta Tester
Posts: 389
Joined: Sun Jun 19, 2011 11:13 pm
Location: Donostia (GUIPUZCOA) - Spain
Contact:

Re: datebrowser.gadget

Post by javierdlr »

salass00 wrote:@javierdlr

If it defaults to FALSE as stated in the autodoc then setting it to FALSE obviously won't do anything. How about you set it to TRUE instead and see if that makes any difference?
I don't see any change setting it to TRUE.
What should DATEBROWSER_ShowTitle change/show?
Post Reply