Hello,
I have just started to work on a Palm OS development.
I have a application that works well on a OS4 but when I run it on OS5 I
have some trouble with "WinDrawBitmap"  when it is in the initialation for
one of the forms.  The code for this form is here and the problem occurs
when the function "ReportFormInit" is called.

I would be thankful if someone can give me some information what can be
wrong here.



//ReportForm.c
#include <PalmOS.h>
#include "resource.h"
#include "ReportForm.h"
#include "MtthDB.h"
#include "MarelUtil.h"
#include "MtthSerial.h"


static Boolean  gbPieces = false;

/***********************************************************************
 * FUNCTION:    GetObjectPtr
 * DESCRIPTION: This routine returns a pointer to an object in the current
 *              form.
 * PARAMETERS:  formId - id of the form to display
 * RETURNED:    void *
 * REVISION HISTORY:
 ***********************************************************************/
static void * GetObjectPtr(UInt16 objectID)
{
 FormPtr ptForm;

 ptForm = FrmGetActiveForm();
 return FrmGetObjectPtr(ptForm, FrmGetObjectIndex(ptForm, objectID));
}

/***********************************************************************
 * FUNCTION:    LoadReportSettings
 * DESCRIPTION:
 * PARAMETERS:
 * RETURNED:
 * REVISION HISTORY:
 ***********************************************************************/
 static Boolean LoadReportSettings()
 {
   ReportDataT   tReportData;

 if( MtthDBGetReportRecord(&tReportData) )
 {

  MutiFieldSetString(ReportKgFieldID, tReportData.unit, 0);
  if( gbPieces )
  {
   for(int i = 0; i < 7; i++)
   {
    MutiFieldSetString(ReportSum1FieldID + i, tReportData.piSum[i], 0);
    MutiFieldSetString(ReportNum1FieldID + i, tReportData.piNum[i], 0);
    MutiFieldSetString(ReportAvg1FieldID + i, tReportData.piAvg[i], 0);
   }
  }
  else
  {
   for(int i = 0; i < 7; i++)
   {
    MutiFieldSetString(ReportSum1FieldID + i, tReportData.baSum[i], 0);
    MutiFieldSetString(ReportNum1FieldID + i, tReportData.baNum[i], 0);
    MutiFieldSetString(ReportAvg1FieldID + i, tReportData.baAvg[i], 0);
   }
  }
 }
  return true;
 }

/***********************************************************************
 * FUNCTION:    Toggle
 * DESCRIPTION:
 * PARAMETERS:
 * RETURNED:
 * REVISION HISTORY:
 ***********************************************************************/
 static void Toggle()
 {
 RectangleType  tPiecesGadgetBounds, tBachesGadetBounds;
 FormType  *ptForm;
 UInt16   iGadgetIndex;

 ptForm = FrmGetActiveForm();
 //pieces gadget bounds
 iGadgetIndex = FrmGetObjectIndex(ptForm, ReportPiecesGadgetID);
 FrmGetObjectBounds(ptForm, iGadgetIndex, &tPiecesGadgetBounds);
 //baches gadget bounds
 iGadgetIndex = FrmGetObjectIndex(ptForm, ReportBachesGadgetID);
 FrmGetObjectBounds(ptForm, iGadgetIndex, &tBachesGadetBounds);

 WinInvertRectangle(&tPiecesGadgetBounds, 0);
 WinInvertRectangle(&tBachesGadetBounds, 0);
 gbPieces = !gbPieces;
 }

  /***********************************************************************
 * FUNCTION:    SetToggleButton
 * DESCRIPTION:
 * PARAMETERS:
 * RETURNED:
 * REVISION HISTORY:
 ***********************************************************************/
static void SetToggleButton()
{
 RectangleType  tPiecesGadgetBounds, tBachesGadetBounds;
 FormType  *ptForm;
 UInt16   iGadgetIndex;

 ptForm = FrmGetActiveForm();
 //pieces gadget bounds
 iGadgetIndex = FrmGetObjectIndex(ptForm, ReportPiecesGadgetID);
 FrmGetObjectBounds(ptForm, iGadgetIndex, &tPiecesGadgetBounds);
 //baches gadget bounds
 iGadgetIndex = FrmGetObjectIndex(ptForm, ReportBachesGadgetID);
 FrmGetObjectBounds(ptForm, iGadgetIndex, &tBachesGadetBounds);

 if( gbPieces )
 {
  WinInvertRectangle(&tPiecesGadgetBounds, 0);
 }
 else
 {
  WinInvertRectangle(&tBachesGadetBounds, 0);
 }
}
/***********************************************************************
 * FUNCTION:    OnPenDownEvent
 * DESCRIPTION:
 * PARAMETERS:
 * RETURNED:
 * REVISION HISTORY:
 ***********************************************************************/
static void OnPenDownEvent(EventPtr ptEvent)
{
 UInt16   iTicsPerSecond;
 UInt16   iGadgetIndex;
 Coord   tNewPointX, tNewPointY;
 RectangleType  tPiecesGadgetBounds, tBachesGadetBounds;
 Boolean   bPenIsDown = true;
 FormType  *ptForm;
 //static Boolean bAction = false;
 Boolean   bPiecesPrevious;

 iTicsPerSecond = SysTicksPerSecond();
 ptForm = FrmGetActiveForm();

 //pieces gadget bounds
 iGadgetIndex = FrmGetObjectIndex(ptForm, ReportPiecesGadgetID);
 FrmGetObjectBounds(ptForm, iGadgetIndex, &tPiecesGadgetBounds);
 //baches gadget bounds
 iGadgetIndex = FrmGetObjectIndex(ptForm, ReportBachesGadgetID);
 FrmGetObjectBounds(ptForm, iGadgetIndex, &tBachesGadetBounds);

 //pieces button
 if(RctPtInRectangle(ptEvent->screenX, ptEvent->screenY,
&tPiecesGadgetBounds))
 {
  bPiecesPrevious = gbPieces;
  if( !gbPieces )
  {
   Toggle();
  }

  while(bPenIsDown)
  {
   EvtGetPen(&tNewPointX, &tNewPointY, &bPenIsDown);
   if(!RctPtInRectangle(tNewPointX, tNewPointY, &tPiecesGadgetBounds))
   {
    if( bPiecesPrevious != gbPieces )
    {
     Toggle();
    }
    return;
   }
    SysTaskDelay(iTicsPerSecond / 10);
  }
  if(RctPtInRectangle(ptEvent->screenX, ptEvent->screenY,
&tPiecesGadgetBounds))
  {
   if( bPiecesPrevious != gbPieces ) LoadReportSettings();
  }
 }
 //baches button
 if(RctPtInRectangle(ptEvent->screenX, ptEvent->screenY,
&tBachesGadetBounds))
 {
  bPiecesPrevious = gbPieces;
  if( gbPieces )
  {
   Toggle();
  }
  while(bPenIsDown)
  {
   EvtGetPen(&tNewPointX, &tNewPointY, &bPenIsDown);
   if(!RctPtInRectangle(tNewPointX, tNewPointY, &tBachesGadetBounds))
   {
    if( bPiecesPrevious != gbPieces )
    {
     Toggle();
    }
    return;
   }
    SysTaskDelay(iTicsPerSecond / 10);
  }
  if(RctPtInRectangle(ptEvent->screenX, ptEvent->screenY,
&tBachesGadetBounds))
  {
   if( bPiecesPrevious != gbPieces ) LoadReportSettings();
  }
 }
}

   /***********************************************************************
 * FUNCTION:    DrawTable
 * DESCRIPTION:
 * PARAMETERS:
 * RETURNED:
 * REVISION HISTORY:
 ***********************************************************************/
 static void DrawTable()
 {
 UInt16 iT = 2;
 UInt16 iL = 0;
 UInt16 iR = 159;
 UInt16 iB = 128;
 UInt16 iO = 0;

  //Rect.
  WinDrawLine(iL,iT,iR,iT); // top
  WinDrawLine(iL,iT,iL,iB); // lef
  WinDrawLine(iR,iT,iR,iB); // right
  WinDrawLine(iR,iB,iL,iB); // bottom

  //vert. line
  iO = 16;
  WinDrawLine(iL+iO,iT,iL+iO,iB);
  iO = 65;
  WinDrawLine(iL+iO,iT,iL+iO,iB);
  iO = 113;
  WinDrawLine(iL+iO,iT,iL+iO,iB);
   //hor. line
  iO = 15;
  WinDrawLine(iL,iT+iO,iR,iT+iO);
  iO = 30;
  WinDrawLine(iL,iT+iO,iR,iT+iO);
  iO = 46;
  WinDrawLine(iL,iT+iO,iR,iT+iO);
  iO = 62;
  WinDrawLine(iL,iT+iO,iR,iT+iO);
  iO = 78;
  WinDrawLine(iL,iT+iO,iR,iT+iO);
  iO = 94;
  WinDrawLine(iL,iT+iO,iR,iT+iO);
  iO = 110;
  WinDrawLine(iL,iT+iO,iR,iT+iO);
 }
 /***********************************************************************
 * FUNCTION:    ExchangeToLocal
 * DESCRIPTION: send report to local memo pad
 * PARAMETERS:
 * RETURNED:
 * REVISION HISTORY:
 ***********************************************************************/
static void ExchangeToLocal()
{
 ExgSocketType  tExgSocet;
 Err    err = 0;
 Char   *pcReport;
 Char   *pcFormatLine;
 ReportDataT  *ptReportData;
 ProgramDataT  *ptProgramData;
 UInt16   iReport = 0;
 UInt32    iSize;
 MemHandle   hStringHandle, hReportData, hProgramData, hFormatLine;
 Char    sDate[16], sTime[16], sUnit[8];
 DateTimeType    tDateTime;
 char   *sGateNrAr[] = {"1 : ","2 : ","3 : ","4 : ","5 : ","6 : ","1..6 :
"};

 //get time and day.
 TimSecondsToDateTime(TimGetSeconds(), &tDateTime);
 DateToAscii(tDateTime.month, tDateTime.day, tDateTime.year, dfDMYLong,
sDate);
 StrPrintF(sTime, "%d:%d",tDateTime.hour, tDateTime.minute);

 //allocate mem to free stack.
 hStringHandle = MemHandleNew(1024);
 hFormatLine = MemHandleNew(35);
 hReportData   = MemHandleNew(sizeof(ReportDataT));
 hProgramData  = MemHandleNew(sizeof(ProgramDataT));
 pcReport = (char*) MemHandleLock(hStringHandle);
 pcFormatLine = (char*) MemHandleLock(hFormatLine);
 ptReportData = (ReportDataT*) MemHandleLock(hReportData);
 ptProgramData= (ProgramDataT*)MemHandleLock(hProgramData);
 //get last received report data from cg
 MtthDBGetReportRecord(ptReportData);
 //get last received setup from cg
 MtthDBGetRecord(NUMBER_OF_PROGRAMS, ptProgramData);
 //print header... cg namename is controler ethernet address.
 StrCopy(pcReport, "Marel CG ");
 StrCat(pcReport, sDate);
 StrCat(pcReport, "  ");
 StrCat(pcReport, sTime);
 StrCat(pcReport,"\n");
 //StrNCat(pcReport,ptReportData->name, 16);
 //print report data pieces
 StrCat(pcReport, "-P-\n");
 sUnit[0] = ' ';
 sUnit[1] = '\0';
 StrCat(sUnit, ptReportData->unit);
 for(iReport = 0; iReport < 7; iReport++)
 {
  //StrIToA(sGateNr, iReport + 1);
  StrCat(pcReport, sGateNrAr[iReport]);
  StrCat(pcReport, ptReportData->piSum[iReport]);
  StrCat(pcReport, sUnit);
  StrCat(pcReport, "   ");
  StrCat(pcReport, ptReportData->piNum[iReport]);
  StrCat(pcReport, "   ");
  StrCat(pcReport, ptReportData->piAvg[iReport]);
  StrCat(pcReport, sUnit);
  StrCat(pcReport, "\n");
 }
 //StrCat(pcReport, "\n");
 //print batches data
 StrCat(pcReport, "-B-\n");
 for(iReport = 0; iReport < 7; iReport++)
 {
  //StrIToA(sGateNr, iReport + 1);
  StrCat(pcReport, sGateNrAr[iReport]);
  StrCat(pcReport, ptReportData->baSum[iReport]);
  StrCat(pcReport, sUnit);
  StrCat(pcReport, "   ");
  StrCat(pcReport, ptReportData->baNum[iReport]);
  StrCat(pcReport, "   ");
  StrCat(pcReport, ptReportData->baAvg[iReport]);
  StrCat(pcReport, sUnit);
  StrCat(pcReport, "\n");
 }
 //StrCat(pcReport, "\n");
 //print setup data
 StrCat(pcReport, "-S-\n");
 for(iReport = 0; iReport < 6; iReport++)
 {
  //StrIToA(sGateNr, iReport + 1);
  StrCat(pcReport, sGateNrAr[iReport]);
  StrCat(pcReport, ptProgramData->itemLo[iReport]);
  StrCat(pcReport, sUnit);
  StrCat(pcReport, "   ");
  StrCat(pcReport, ptProgramData->itemHi[iReport]);
  StrCat(pcReport, sUnit);
  StrCat(pcReport, "   ");
  StrCat(pcReport, ptProgramData->itemBa[iReport]);
  StrCat(pcReport, sUnit);
  StrCat(pcReport, "   ");
  StrCat(pcReport, ptProgramData->itemCo[iReport]);
  StrCat(pcReport, "\n");
 }
 StrCat(pcReport, "\0");
 iSize = StrLen(pcReport) + 1;
 MemSet(&tExgSocet, sizeof(tExgSocet), 0);
 tExgSocet.description = "Marel CG report";
 tExgSocet.type = ".txt";
 tExgSocet.name = "Marel CG.txt";
 tExgSocet.localMode = 1;
 err = ExgPut(&tExgSocet);
 if(err == 0)
 {
  ExgSend(&tExgSocet, pcReport, iSize, &err);
  ExgDisconnect(&tExgSocet, err);
 }
 MemHandleUnlock(hStringHandle);
 MemHandleFree(hStringHandle);

 MemHandleUnlock(hFormatLine);
 MemHandleFree(hFormatLine);

 MemHandleUnlock(hReportData);
 MemHandleFree(hReportData);

 MemHandleUnlock(hProgramData);
 MemHandleFree(hProgramData);
}
/***********************************************************************
 * FUNCTION:    MyFormInit
 * DESCRIPTION:
 * PARAMETERS:
 * RETURNED:
 * REVISION HISTORY:
 ***********************************************************************/
static void ReportFormInit(FormPtr ptForm)
{
 MemHandle  hBitmap;
 BitmapType  *ptBitmap;
 UInt16   iGadgetIndex;
 RectangleType  tPiecesGadgetBounds, tBachesGadetBounds;

 //pieces gadget bounds
 iGadgetIndex = FrmGetObjectIndex(ptForm, ReportPiecesGadgetID);
 FrmGetObjectBounds(ptForm, iGadgetIndex, &tPiecesGadgetBounds);
 //baches gadget bounds
 iGadgetIndex = FrmGetObjectIndex(ptForm, ReportBachesGadgetID);
 FrmGetObjectBounds(ptForm, iGadgetIndex, &tBachesGadetBounds);

 if( gbPieces )
 {
  hBitmap = DmGetResource(bitmapRsc, BitmapFamPiecesInv);
  ptBitmap = (BitmapType*)MemHandleLock(hBitmap);
  WinDrawBitmap(ptBitmap, tPiecesGadgetBounds.topLeft.x,
tPiecesGadgetBounds.topLeft.y);
  MemHandleUnlock(hBitmap);

  hBitmap = DmGetResource(bitmapRsc, BitmapFamBatches);
  ptBitmap = (BitmapType*)MemHandleLock(hBitmap);
  WinDrawBitmap(ptBitmap, tBachesGadetBounds.topLeft.x,
tBachesGadetBounds.topLeft.y);
  MemHandleUnlock(hBitmap);
 }
 else
 {
  hBitmap = DmGetResource(bitmapRsc, BitmapFamPieces);
  ptBitmap = (BitmapType*)MemHandleLock(hBitmap);
  WinDrawBitmap(ptBitmap, 27, 140);
  MemHandleUnlock(hBitmap);

  hBitmap = DmGetResource(bitmapRsc, BitmapFamBatchesInv);
  ptBitmap = (BitmapType*)MemHandleLock(hBitmap);
  WinDrawBitmap(ptBitmap, tBachesGadetBounds.topLeft.x,
tBachesGadetBounds.topLeft.y);
  MemHandleUnlock(hBitmap);
 }
 WinDrawRectangleFrame(simpleFrame, &tPiecesGadgetBounds);
 WinDrawRectangleFrame(simpleFrame, &tBachesGadetBounds);
 //DrawTable();

}
/***********************************************************************
 * FUNCTION:    MyFormDeinit
 * DESCRIPTION:
 * PARAMETERS:
 * RETURNED:
 * REVISION HISTORY:
 ***********************************************************************/
static void ReportFormDeinit(FormPtr ptForm)
{
 #pragma unused(ptForm)
}
/***********************************************************************
 * FUNCTION:    MyFormHandleEvent
 * DESCRIPTION:
 * PARAMETERS:
 * RETURNED:
 * REVISION HISTORY:
 ***********************************************************************/
Boolean ReportFormHandleEvent(EventPtr ptEvent)
{
 Boolean handled = false;
 FormPtr ptForm;

 if(ptEvent->eType == frmOpenEvent)
 {
  ptForm = FrmGetActiveForm();
  ReportFormInit(ptForm);
  FrmDrawForm(ptForm);
  LoadReportSettings();
  handled = true;
 }
 else if(ptEvent->eType == frmUpdateEvent)
 {
  ptForm = FrmGetActiveForm();
 }
 else if(ptEvent->eType == frmCloseEvent)
 {
  ptForm = FrmGetActiveForm();
  ReportFormDeinit(ptForm);
 }
 else if(ptEvent->eType == fldEnterEvent)
 {
  handled = true;
 }
 else if(ptEvent->eType == winExitEvent)
 {
  //executed after receive dialog is closed!
  LoadReportSettings();
  handled = true;
 }
 else if(ptEvent->eType == ctlSelectEvent)
 {
  if(ptEvent->data.ctlSelect.controlID == ReportExitButtonID)
  {
   FrmGotoForm(GradingForm);
   handled = true;
  }
  else if(ptEvent->data.ctlSelect.controlID == ReportReceiveButtonID)
  {

   FrmPopupForm(ReportReceiveDialogID);
   /*
   if( MtthSerGetReport() )
   {
    LoadReportSettings();

   }
   */
   handled = true;
  }
  else if(ptEvent->data.ctlSelect.controlID == ReportExchangeButtonID)
  {
   ExchangeToLocal();
   handled = true;
  }
 }
 else if(ptEvent->eType == penDownEvent)
 {
  OnPenDownEvent(ptEvent);
  handled = false;
 }
 return handled;
}




Best Regards
Gunnar Tj�rvi Sig
Iceland







-- 
For information on using the Palm Developer Forums, or to unsubscribe, please see 
http://www.palmos.com/dev/support/forums/

Reply via email to