Пример #1
0
/**************************************************************************
 OM_SET
**************************************************************************/
static ULONG Numericbutton__OM_SET(struct IClass *cl, Object * obj, struct opSet *msg)
{
    struct Numericbutton_DATA *data = INST_DATA(cl, obj);
    const struct TagItem *tags;
    struct TagItem *tag;

    for (tags = msg->ops_AttrList; (tag = NextTagItem(&tags));)
    {
        switch (tag->ti_Tag)
        {
        case MUIA_Numeric_Max:
            if (tag->ti_Data != XGET(obj, MUIA_Numeric_Max))
                data->needs_to_recalculate_sizes = TRUE;
            break;
        case MUIA_Numeric_Min:
            if (tag->ti_Data != XGET(obj, MUIA_Numeric_Min))
                data->needs_to_recalculate_sizes = TRUE;
            break;
        case MUIA_Numeric_Format:
            if (tag->ti_Data != XGET(obj, MUIA_Numeric_Format))
                data->needs_to_recalculate_sizes = TRUE;
            break;
        }
    }

    return DoSuperMethodA(cl, obj, (Msg)msg);
}
Пример #2
0
static IPTR AddFunc(struct Hook *hook, Object *caller, void *data)
{
    STRPTR s1 = (STRPTR) XGET(str1, MUIA_String_Contents);
    STRPTR s2 = (STRPTR) XGET(str2, MUIA_String_Contents);
    STRPTR s3 = (STRPTR) XGET(str3, MUIA_String_Contents);
    STRPTR *item = (STRPTR*) malloc(sizeof(STRPTR) * 4);
    item[0] = strdup(s1);
    item[1] = strdup(s2);
    item[2] = strdup(s3);
    item[3] = NULL;
    DoMethod(list, MUIM_List_InsertSingle, item, MUIV_List_Insert_Top);
    
    return TRUE;
}
Пример #3
0
/* we need to return the selected config in pitem.lParam
 * WARNING: this is just a minimal implementation to get win32gui.cpp/LoadSaveDlgProc working!
 */
BOOL TreeView_GetItem(HWND elem, int item, APTR pitem_void) {

  LPTVITEM pitem=(LPTVITEM) pitem_void; /* gcc does no automatic cast here, as MS C++ does */

  LONG i;
  struct MUI_NListtree_TreeNode *act_node;

  DebOut("elem: %lx, item: %d\n", elem, item);
  
  i=get_index(elem, item);
  if(i<0) {
    elem=get_elem(item);
    i=get_index(elem, item);
  }
  if(i<0) {
    DebOut("ERROR: nIDDlgItem %d found nowhere!?\n", item);
    return NULL;
  }

  act_node=(struct MUI_NListtree_TreeNode *) XGET(elem[i].obj, MUIA_NListtree_Active);

  DebOut("act_node: %lx\n", act_node);
  DebOut("act_node->tn_User: %lx\n", act_node->tn_User);

  /* is this correct !? */
  if(act_node == MUIV_NListtree_Active_Off) {
    pitem->lParam=(LPARAM) NULL;
    return FALSE;
  }

  pitem->lParam=(LPARAM) act_node->tn_User;
  DebOut("pitem->lParam: %lx\n", pitem->lParam);

  return TRUE;
}
Пример #4
0
int main (int argc, char **argv)
{
    Object *app;
    Object *mainWin;

    if (!openmuimaster()) return 20;

    app = ApplicationObject,
    SubWindow, mainWin = WindowObject,
               MUIA_Window_Title, "Input modes",
               WindowContents, VGroup,
               Child, SliderObject,
               MUIA_Numeric_Value, 50,
               End,
               End,
               End,
               End;

    if (!app)
    {
        fprintf(stderr, "can't create application object.\n");
        goto error;
    }

    DoMethod(mainWin, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
             (IPTR)app, 2, MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);

    set(mainWin, MUIA_Window_Open, TRUE);
    if (!XGET(mainWin, MUIA_Window_Open))
    {
        MUI_DisposeObject(app);
        fprintf(stderr, "%s : can't open main window.\n", argv[0]);
        goto error;
    }

    {
        ULONG sigs = 0;

        while (DoMethod(app, MUIM_Application_NewInput, (IPTR)&sigs)
                != MUIV_Application_ReturnID_Quit)
        {
            if (sigs)
            {
                sigs = Wait(sigs | SIGBREAKF_CTRL_C);
                if (sigs & SIGBREAKF_CTRL_C) break;
            }
        }
    }

    set(mainWin, MUIA_Window_Open, FALSE);
    MUI_DisposeObject(app);

error:
    closemuimaster();

    return 0;
}
Пример #5
0
HOOKPROTONHNO(template_func, void, int *param)
{

    int selection = XGET ( nwTemplates, MUIA_Cycle_Active );

    int templates[ 9 ][ 2 ] = {
        { 32, 32 }, { 48, 48 }, { 64, 64 }, { 160, 120 },
        { 320, 240 }, { 640, 480 }, { 800, 600 },
        { 1024, 768 }, { 1280, 1024 }
    };

    set ( nwStringWidth, MUIA_String_Integer, ( IPTR )templates[ selection ][ 0 ] );
    set ( nwStringHeight, MUIA_String_Integer, ( IPTR )templates[ selection ][ 1 ] );

}
Пример #6
0
AROS_UFH2(void, tree_double, AROS_UFHA(struct Hook *, hook, A0), AROS_UFHA(APTR, obj, A2)) {

  AROS_USERFUNC_INIT

  struct MUI_NListtree_TreeNode *node;
  struct Data *data = (struct Data *) hook->h_Data;

  DebOut("entered (obj %lx)\n", obj);

  node=(struct MUI_NListtree_TreeNode *) XGET((Object *) obj, MUIA_NListtree_Active);

  if(node!=(struct MUI_NListtree_TreeNode *) MUIA_NListtree_Active) {
    tree_send_notify(NM_DBLCLK, (Object *) obj, data, (struct ConfigStruct *) node->tn_User);
  }

  AROS_USERFUNC_EXIT
}
Пример #7
0
static void tree_send_notify(ULONG type, Object *obj, struct Data *data, struct ConfigStruct *config) {

  int i;
  ULONG state;
  LPNMHDR nm=NULL;
  LPNMTREEVIEW tv;
  struct MUI_NListtree_TreeNode *node;

  DebOut("[%lx] entered\n", obj);

  i=get_elem_from_obj(data, (Object *) obj);

  if(!data->func) {
    DebOut("[%lx] function is zero: %lx\n", obj, data->func);
    goto TREE_SEND_NOTIFY_EXIT;
  }

  node=(struct MUI_NListtree_TreeNode *) XGET((Object *) obj, MUIA_NListtree_Active);
  if(!node || node==(struct MUI_NListtree_TreeNode *) MUIA_NListtree_Active) {
    DebOut("no node / MUIA_Listtree_Active_Off! Do nothing!\n");
    goto TREE_SEND_NOTIFY_EXIT;
  }

  DebOut("node: %lx\n", node);
 
  /* LPNMHDR is sent in itemNew.lParam */
  /* WARNING: all other fields are not correctly set */
  /* NMTREEVIEW contains NMHDR */
  nm=(LPNMHDR) AllocVec(sizeof(NMTREEVIEW), MEMF_CLEAR);
  nm->idFrom=NULL; /* not used by WinUAE! */
  nm->code=type;
  nm->hwndFrom=IDC_CONFIGTREE; 

  /* LPNMTREEVIEW is sent in itemNew.lParam */
  tv=(LPNMTREEVIEW) nm;
  tv->itemNew.lParam=(LPARAM) node->tn_User;

  /* still a lot of unfilled attributes! */
  TODO();

  DebOut("[%lx] call function: %lx(IDC %d, WM_NOTIFY, %lx)\n", obj, data->func, data->src[i].idc, nm);
  data->func(data->src, WM_NOTIFY, NULL, (IPTR) nm);

TREE_SEND_NOTIFY_EXIT:
  if(nm) FreeVec(nm);
}
Пример #8
0
IPTR ScreenModeProperties__OM_GET(Class *CLASS, Object *self, struct opGet *message)
{
    struct ScreenModeProperties_DATA *data = INST_DATA(CLASS, self);    
    
    switch (message->opg_AttrID)
    {
        case MUIA_ScreenModeProperties_DisplayID:
	    *message->opg_Storage = data->DisplayID;
            break;
        
	case MUIA_ScreenModeProperties_Width:
	    if (XGET(data->def_width, MUIA_Selected) == TRUE)
	        *message->opg_Storage = -1;
	    else
	        *message->opg_Storage = XGET(data->width, MUIA_Numeric_Value);
            break;
        
	case MUIA_ScreenModeProperties_Height:
	    if (XGET(data->def_height, MUIA_Selected) == TRUE)
	        *message->opg_Storage = -1;
	    else
	        *message->opg_Storage = XGET(data->height, MUIA_Numeric_Value);
            break;
        
	case MUIA_ScreenModeProperties_Depth:
	    *message->opg_Storage = XGET(data->depth, MUIA_Numeric_Value);
            break;
	
        case MUIA_ScreenModeProperties_Autoscroll:
	    *message->opg_Storage = XGET(data->autoscroll, MUIA_Selected);
            break;
	
	default:
            return DoSuperMethodA(CLASS, self, (Msg)message);
    }
    
    return TRUE;
}
Пример #9
0
IPTR ScreenModeProperties__OM_SET(Class *CLASS, Object *self, struct opSet *message)
{
    struct ScreenModeProperties_DATA *data = INST_DATA(CLASS, self);    
    const struct TagItem *tags;
    struct TagItem *tag;
    struct TagItem noforward_tags[] =
    {
        {MUIA_Group_Forward , FALSE                       },
        {TAG_MORE           , (IPTR)message->ops_AttrList }
    };
    struct opSet noforward_message = *message;
    noforward_message.ops_AttrList = noforward_tags;
    
    ULONG id        = INVALID_ID;
    IPTR  no_notify = TAG_IGNORE;
    
    for (tags = message->ops_AttrList; (tag = NextTagItem(&tags)); )
    {
        switch (tag->ti_Tag)
        {
	    case MUIA_NoNotify:
	        no_notify = MUIA_NoNotify;
		break;
		
	    case MUIA_ScreenModeProperties_DisplayID:
	    {
	        struct TagItem width_tags[] =
		{
		    { no_notify,            TRUE },
		    { MUIA_Numeric_Min,        0 },
		    { MUIA_Numeric_Max,        0 },
		    { MUIA_Numeric_Default,    0 },
		    { TAG_DONE,                0 }
		};
	        struct TagItem height_tags[] =
		{
		    { no_notify,            TRUE },
		    { MUIA_Numeric_Min,        0 },
		    { MUIA_Numeric_Max,        0 },
		    { MUIA_Numeric_Default,    0 },
		    { TAG_DONE,                0 }
		};
	        struct TagItem depth_tags[] =
		{
		    { no_notify,            TRUE },
		    { MUIA_Numeric_Min,        0 },
		    { MUIA_Numeric_Max,        0 },
		    { MUIA_Numeric_Default,    0 },
		    { TAG_DONE,                0 }
		};
	        
                struct DimensionInfo dim;
		
		BOOL autoscroll;
                
		if (GetDisplayInfoData(NULL, (UBYTE *)&dim, sizeof(dim), DTAG_DIMS, tag->ti_Data))
                {
                    width_tags[1].ti_Data  = dim.MinRasterWidth;
                    height_tags[1].ti_Data = dim.MinRasterHeight;
                    depth_tags[1].ti_Data  = 1;
	    
                    width_tags[2].ti_Data  = dim.MaxRasterWidth;
                    height_tags[2].ti_Data = dim.MaxRasterHeight;
	            depth_tags[2].ti_Data  = dim.MaxDepth;
	    
                    width_tags[3].ti_Data  = dim.Nominal.MaxX - dim.Nominal.MinX + 1;
                    height_tags[3].ti_Data = dim.Nominal.MaxY - dim.Nominal.MinY + 1;
	            depth_tags[3].ti_Data  = dim.MaxDepth;
                    
		    id = tag->ti_Data;		    
		}
		
		/* Enable autoscroll only if the maximum sizes are bigger than 
		   the resolution.  */
		   
		autoscroll = width_tags[2].ti_Data  > width_tags[3].ti_Data  &&
		             height_tags[2].ti_Data > height_tags[3].ti_Data;
    
  	        data->DisplayID = id;
 	        nfset(self, MUIA_Disabled, id == INVALID_ID);
		
		SetAttrsA(data->width,  width_tags);
		SetAttrsA(data->height, height_tags);
		SetAttrsA(data->depth,  depth_tags);
		
		SetAttrs(data->autoscroll, no_notify, TRUE, 
		                           MUIA_Disabled, !autoscroll,
					   MUIA_Selected, autoscroll,
					   TAG_DONE);
                
		break;
	    }
	    
	    case MUIA_ScreenModeProperties_Width:
	        if (id != INVALID_ID)
		{
		    WORD width = tag->ti_Data;
		    if (width != -1)
		        SetAttrs(data->width, no_notify, TRUE, MUIA_Numeric_Value, width, TAG_DONE);
		    else
		        DoMethod(data->width, MUIM_Numeric_SetDefault);
		    
		    nnset(data->def_width, MUIA_Selected, width == -1);
		}
		break;
		
	    case MUIA_ScreenModeProperties_Height:
	        if (id != INVALID_ID)
		{
		    WORD height = tag->ti_Data;
		    if (height != -1)
		        SetAttrs(data->height, no_notify, TRUE, MUIA_Numeric_Value, height, TAG_DONE);
		    else
		        DoMethod(data->height, MUIM_Numeric_SetDefault);
		    
		    nnset(data->def_height, MUIA_Selected, height == -1);
		}
		break;
	    
	    case MUIA_ScreenModeProperties_Depth:
	        if (id != INVALID_ID)
		{
		    WORD depth = tag->ti_Data;
		    if (depth != -1)
		        SetAttrs(data->depth, no_notify, TRUE, MUIA_Numeric_Value, depth, TAG_DONE);
		    else
		        DoMethod(data->depth, MUIM_Numeric_SetDefault);
		}
		break;
	    
	    case MUIA_ScreenModeProperties_Autoscroll:
	        if (id != INVALID_ID && !XGET(data->autoscroll, MUIA_Disabled))
		    SetAttrs(data->autoscroll, no_notify, TRUE, MUIA_Selected, tag->ti_Data != 0);
		break;
	}
    }		    

    return DoSuperMethodA(CLASS, self, (Msg)&noforward_message);	
}
Пример #10
0
int main (int argc, char **argv)
{
    Object *app;
    Object *mainWin;
    Object *pages;
    Object *stepb[2];
    Object *b[3];
    int i;

    if (!openmuimaster()) return 20;

    app = ApplicationObject,
	SubWindow, mainWin = WindowObject,
	    MUIA_Window_Title, "Pages",
	    WindowContents, VGroup,
                Child, VGroup,
   		    GroupFrame,
		    Child, HGroup,
			Child, stepb[0] = RectangleObject,
				MUIA_Rectangle_BarTitle, "prev",
	                        MUIA_CycleChain, TRUE,
				MUIA_InnerLeft, 20,
				MUIA_FixHeight, 20,
				MUIA_InputMode, MUIV_InputMode_RelVerify,
				MUIA_Background, MUII_ButtonBack,
				ButtonFrame,
			End,
			Child, stepb[1] = RectangleObject,
				MUIA_Rectangle_BarTitle, "next",
	                        MUIA_CycleChain, TRUE,
				MUIA_InnerLeft, 20,
				MUIA_InputMode, MUIV_InputMode_RelVerify,
				MUIA_Background, MUII_ButtonBack,
				ButtonFrame,
			End,
		    End,

	            Child, MUI_MakeObject(MUIO_HBar, 4),
		    Child, HGroup,
			Child, b[0] = RectangleObject,
				MUIA_Rectangle_BarTitle, "1",
	                        MUIA_CycleChain, TRUE,
				MUIA_InputMode, MUIV_InputMode_RelVerify,
				MUIA_FixHeight, 20,
				MUIA_Background, MUII_ButtonBack,
				ButtonFrame,
			End,
			Child, b[1] = RectangleObject,
				MUIA_Rectangle_BarTitle, "2",
	                        MUIA_CycleChain, TRUE,
				MUIA_InputMode, MUIV_InputMode_RelVerify,
				MUIA_FixHeight, 20,
				MUIA_Background, MUII_ButtonBack,
				ButtonFrame,
			End,
			Child, b[2] = RectangleObject,
				MUIA_Rectangle_BarTitle, "3",
	                        MUIA_CycleChain, TRUE,
				MUIA_InputMode, MUIV_InputMode_RelVerify,
				MUIA_FixHeight, 20,
				MUIA_Background, MUII_ButtonBack,
				ButtonFrame,
			End,
		    End,
                End,
	        Child, pages = HGroup,
	            MUIA_Group_PageMode, TRUE,
	            InputListFrame,
	            MUIA_Background, MUII_PageBack,
	            Child, RectangleObject,
	                    MUIA_FixWidth, 50,
	                    MUIA_Background, MUII_SHADOW,
                            MUIA_Rectangle_BarTitle, "Rect1",
	            End,
                    Child, RectangleObject,
	                    MUIA_FixWidth, 30,
                            MUIA_FixHeight, 30,
	                    MUIA_Background, MUII_SHINE,
                            MUIA_Rectangle_BarTitle, "Rect2",
                    End,
                    Child, RectangleObject,
                            MUIA_FixHeight, 50,
	                    MUIA_Background, MUII_FILL,
                            MUIA_Rectangle_BarTitle, "Rect3",
                    End,
                End,
            End,
        End,
    End;

    if (!app)
    {
	fprintf(stderr, "can't create application object.\n");
	goto error;
    }

    DoMethod(mainWin, MUIM_Notify, MUIA_Window_CloseRequest, TRUE,
	     (IPTR)app, 2,
	     MUIM_Application_ReturnID, MUIV_Application_ReturnID_Quit);

    DoMethod(stepb[0], MUIM_Notify, MUIA_Timer, MUIV_EveryTime,
	     (IPTR)pages, 3, MUIM_Set,
	     MUIA_Group_ActivePage, MUIV_Group_ActivePage_Prev);

    DoMethod(stepb[1], MUIM_Notify, MUIA_Timer, MUIV_EveryTime,
	     (IPTR)pages, 3, MUIM_Set,
	     MUIA_Group_ActivePage, MUIV_Group_ActivePage_Next);

    for (i = 0; i < 3; i++)
    {
	DoMethod(b[i], MUIM_Notify, MUIA_Pressed, FALSE,
		 (IPTR)pages, 3, MUIM_Set, MUIA_Group_ActivePage, i);
    }
    /*
     * Open window and ALWAYS check.
     */
    set(mainWin, MUIA_Window_Open, TRUE);
    if (!XGET(mainWin, MUIA_Window_Open))
    {
	MUI_DisposeObject(app);
	fprintf(stderr, "can't open main window.\n");
	goto error;
    }

    {
	ULONG sigs = 0;

	while (DoMethod(app, MUIM_Application_NewInput, (IPTR)&sigs)
	       != MUIV_Application_ReturnID_Quit)
	{
	    if (sigs)
	    {
	        sigs = Wait(sigs | SIGBREAKF_CTRL_C);
	        if (sigs & SIGBREAKF_CTRL_C) break;
	    }
	}
    }
    
    set(mainWin, MUIA_Window_Open, FALSE);
    MUI_DisposeObject(app);

error:

    closemuimaster();

    return 0;
}
Пример #11
0
/*
 * Open a requester with a fixed font.
 *
 * Only reqtools.library seems to have the ability to use custom fonts.
 * This crashes, if I don't open requtools.library manually. Is this no auto-open library !?
 *
 * Is there really so much code necessary, just to open a fixed width requester !?
 *
 * This is no WinAPI call.
 */
int MessageBox_fixed(HWND hWnd, TCHAR *lpText, TCHAR *lpCaption, UINT uType/*, UINT size*/) {
  rtReqInfo *req;
  ULONG ret;
  BOOL i_opened_it=false;
  struct TextFont *font;
  struct Window *window;
  struct TextAttr myta = {
      "fixed.font",
      8,
      0,
      NULL
  };

  struct TagItem tags[]={
    {RT_TextAttr, (IPTR) &myta},
    {RT_Window, NULL},
    {RTEZ_ReqTitle , (IPTR) lpCaption},
    {RT_ReqPos, REQPOS_CENTERSCR},
    {RT_WaitPointer, TRUE},
    {RT_LockWindow, TRUE},
    {TAG_DONE}
  };

  DebOut("Caption: %s\n", lpCaption);
  DebOut("Text: %s\n", lpText);

  font=OpenDiskFont(&myta);
  if(!font) {
    DebOut("unable to open fixed.font\n");
    tags[0].ti_Tag=TAG_IGNORE;
  }

  window=(struct Window *)XGET(win, MUIA_Window_Window);
  if(window) {
    DebOut("window: %lx\n", window);
    tags[1].ti_Data=(IPTR) window;
  }
  else {
    DebOut("ERROR: no window !?\n");
    tags[1].ti_Tag=TAG_IGNORE;
  }

  /* do I really have to open it !? */
  if(!ReqToolsBase) {
    i_opened_it=TRUE;
    ReqToolsBase = (struct ReqToolsBase *)OpenLibrary("reqtools.library", 0);
  }

  if(!ReqToolsBase) {
    fprintf(stderr, "ERROR: Unable to open reqtools.library!\n");
    DebOut("ERROR: Unable to open reqtools.library!\n");
    return FALSE;
  }

  ret=rtEZRequestA(lpText, "Ok", NULL, NULL, tags);

  if(i_opened_it) {
    CloseLibrary((struct Library *)ReqToolsBase);
    ReqToolsBase=NULL;
  }

  if(font) {
    CloseFont(font);
  }
  return TRUE;
}
Пример #12
0
IPTR SMEditor__MUIM_PrefsEditor_ExportFH
(
    Class *CLASS, Object *self,
    struct MUIP_PrefsEditor_ExportFH *message
)
{
    SETUP_INST_DATA;
    
    struct PrefHeader header = { 0 }; 
    struct IFFHandle *handle;
    BOOL              success = TRUE;
    LONG              error   = 0;
        
    if ((handle = AllocIFF()))
    {
        handle->iff_Stream = (IPTR) message->fh;
        
        InitIFFasDOS(handle);
        
        if (!(error = OpenIFF(handle, IFFF_WRITE))) /* NULL = successful! */
        {
            struct ScreenModePrefs smp;
	    
	    memset(&smp, 0, sizeof(smp));
            
	    BYTE i;
            
            PushChunk(handle, ID_PREF, ID_FORM, IFFSIZE_UNKNOWN); /* FIXME: IFFSIZE_UNKNOWN? */
            
            header.ph_Version = PHV_CURRENT;
            header.ph_Type    = 0;
            
            PushChunk(handle, ID_PREF, ID_PRHD, IFFSIZE_UNKNOWN); /* FIXME: IFFSIZE_UNKNOWN? */
            
            WriteChunkBytes(handle, &header, sizeof(struct PrefHeader));
            
            PopChunk(handle);
            
            for (i = 0; i < 1; i++)
            {
                error = PushChunk(handle, ID_PREF, ID_SCRM, sizeof(struct ScreenModePrefs));
                
                if (error != 0) // TODO: We need some error checking here!
                {
                    printf("error: PushChunk() = %ld ", error);
                }
                
	        smp.smp_DisplayID = XGET(data->properties, MUIA_ScreenModeProperties_DisplayID);
                smp.smp_Width     = XGET(data->properties, MUIA_ScreenModeProperties_Width);
                smp.smp_Height    = XGET(data->properties, MUIA_ScreenModeProperties_Height);
                smp.smp_Depth     = XGET(data->properties, MUIA_ScreenModeProperties_Depth);
                
		if (XGET(data->properties, MUIA_ScreenModeProperties_Autoscroll))
		    smp.smp_Control = AUTOSCROLL;
		else
		    smp.smp_Control = 0;
                
		SMPByteSwap(&smp);
			
                error = WriteChunkBytes(handle, &smp, sizeof(struct ScreenModePrefs));
                error = PopChunk(handle);
                                
                if (error != 0) // TODO: We need some error checking here!
                {
                    printf("error: PopChunk() = %ld ", error);
                }
            }

            // Terminate the FORM
            PopChunk(handle);
        }
        else
        {
            //ShowError(_(MSG_CANT_OPEN_STREAM));
            success = FALSE;
        }
        
        CloseIFF(handle);
	FreeIFF(handle);
    }
    else // AllocIFF()
    {
        // Do something more here - if IFF allocation has failed, something isn't right
        //ShowError(_(MSG_CANT_ALLOCATE_IFFPTR));
        success = FALSE;
    }

    return success;
}
Пример #13
0
///ImageBackFill__MUIM_IconWindow_BackFill_ProcessBackground()
IPTR ImageBackFill__MUIM_IconWindow_BackFill_ProcessBackground
(
  Class *CLASS, Object *self, struct MUIP_IconWindow_BackFill_ProcessBackground *message
)
{

  LONG        Depth = 0;
  Object      *_IconWindows_PrefsObj    = NULL,
              *_IconWindows_WindowObj   = NULL;
  Object      *_IconWindows_IconListObj = NULL;

  BOOL        options_changed = FALSE;

  IPTR        prefs_processing        = 0;
  
  IPTR        BackGround_Attrib       = 0,
              BackGround_Base         = 0,
              BackGround_RenderMode   = 0,
              BackGround_TileMode     = 0,
              BackGround_XOffset      = 0,
              BackGround_YOffset      = 0;
  
  struct BackFillInfo   *this_BFI =(struct BackFillInfo   *) message->BackFill_Data;

  UBYTE                  *this_bgtype;
  char                  *this_ImageName;

  D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground()\n"));
  
  GET(_app(self), MUIA_Wanderer_Prefs, &_IconWindows_PrefsObj);

  D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: PrefsObj @ %x\n", _IconWindows_PrefsObj));
  
  GET(self, MUIA_IconWindow_Window, &_IconWindows_WindowObj);
  GET(self, MUIA_IconWindow_IconList, &_IconWindows_IconListObj);

  D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: MUIA_IconWindow_Window = %x\n", _IconWindows_WindowObj));

  if ((_IconWindows_PrefsObj == NULL) || (_IconWindows_WindowObj == NULL) || (_IconWindows_IconListObj == NULL)) return FALSE;

  GET(_IconWindows_PrefsObj, MUIA_WandererPrefs_Processing, &prefs_processing);

#if defined(DEBUG)
  if (prefs_processing)
  {
    D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Wanderer Prefs (re)loading detected\n"));
  }
#endif
  
  GET(_IconWindows_WindowObj, MUIA_IconWindow_BackgroundAttrib, &BackGround_Attrib);
  
  D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Background Attrib = '%s'\n", BackGround_Attrib));

  if (BackGround_Attrib == (IPTR) NULL) return FALSE;
  
  if ((BackGround_Base = DoMethod(_IconWindows_PrefsObj, MUIM_WandererPrefs_ViewSettings_GetAttribute,
                  BackGround_Attrib, MUIA_Background)) == -1)
    return FALSE;

  if ((BackGround_RenderMode = DoMethod(_IconWindows_PrefsObj, MUIM_WandererPrefs_ViewSettings_GetAttribute,
                  BackGround_Attrib, MUIA_IconWindowExt_ImageBackFill_BGRenderMode)) == -1)
    BackGround_RenderMode = IconWindowExt_ImageBackFill_RenderMode_Tiled;

  this_bgtype    = (UBYTE *)BackGround_Base;
  this_ImageName = (char *)(BackGround_Base + 2);
  
  D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: BackFillInfo @ %x\n", this_BFI));
  D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Background '%s', mode %d\n", BackGround_Base, BackGround_RenderMode));

  if ((this_bgtype[0] - 48) != 5)
  {
    D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Background is NOT an image - letting our windoclass handle it ..\n"));
    
    goto pb_cleanup_buffer;
  }
  
  GET(self, MUIA_Window_Screen, &this_BFI->bfi_Screen);
  GET(_IconWindows_IconListObj, MUIA_IconList_BufferRastport, &this_BFI->bfi_RastPort);

  D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Wanderers Screen @ %x, Using RastPort @ %x\n", this_BFI->bfi_Screen, this_BFI->bfi_RastPort));
  
  if (this_BFI->bfi_Source)
  {
    D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: BackFillInfo has existing source record @ %x\n", this_BFI->bfi_Source));
    if ((strcmp(this_BFI->bfi_Source->bfsir_SourceImage, this_ImageName) == 0) && (this_BFI->bfi_Source->bfsir_BackGroundRenderMode == BackGround_RenderMode))
    {
      D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: existing BackFillInfo Using the same background / mode\n"));
      goto check_imagebuffer;
    }
    else
    {
      if (this_BFI->bfi_Buffer)
      {
        ImageBackFill_CloseSourceBuffer(this_BFI->bfi_Source, this_BFI->bfi_Buffer);
        this_BFI->bfi_Buffer = NULL;
      }
      ImageBackFill_CloseSourceRecord(this_BFI->bfi_Source);
      this_BFI->bfi_Source = NULL;
    }
  }

  if (!(this_BFI->bfi_Source)) this_BFI->bfi_Source = ImageBackFill_FindSourceRecord(this_ImageName, BackGround_RenderMode);

  if (!(this_BFI->bfi_Source))
  {
    D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Creating NEW ImageSource Record\n"));
    if (!(this_BFI->bfi_Source = AllocMem(sizeof(struct BackFillSourceImageRecord), MEMF_CLEAR|MEMF_PUBLIC)))
    {
      D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Couldnt allocate enough mem for source record!\n"));      
      return FALSE;
    }

    if (!(this_BFI->bfi_Source->bfsir_SourceImage = AllocVec(strlen(this_ImageName) +1, MEMF_CLEAR|MEMF_PUBLIC)))
    {
      D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Couldnt allocate enough mem for source image name store\n"));     
      FreeMem(this_BFI->bfi_Source, sizeof(struct BackFillSourceImageRecord));
      return FALSE;
    }
    strcpy(this_BFI->bfi_Source->bfsir_SourceImage, this_ImageName);
    
    if ((this_BFI->bfi_Source->bfsir_DTPictureObject = NewDTObject(this_BFI->bfi_Source->bfsir_SourceImage,
                          DTA_SourceType,         DTST_FILE,
                          DTA_GroupID,            GID_PICTURE,
                          PDTA_DestMode,          PMODE_V43,
                          PDTA_Remap,             TRUE,
                          PDTA_Screen,            this_BFI->bfi_Screen,
                          PDTA_FreeSourceBitMap,  TRUE,
                          OBP_Precision,          PRECISION_IMAGE,
                          TAG_DONE)))
    {
      D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Opened Datatype Object @ %x for image '%s'\n", this_BFI->bfi_Source->bfsir_DTPictureObject, this_BFI->bfi_Source->bfsir_SourceImage));
      if (DoMethod(this_BFI->bfi_Source->bfsir_DTPictureObject, DTM_PROCLAYOUT, NULL, 1))
      {
        D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Caused Datatype Object LAYOUT\n"));

        GetDTAttrs(this_BFI->bfi_Source->bfsir_DTPictureObject, PDTA_BitMapHeader, &this_BFI->bfi_Source->bfsir_DTBitMapHeader, TAG_DONE);
        GetDTAttrs(this_BFI->bfi_Source->bfsir_DTPictureObject, PDTA_DestBitMap, &this_BFI->bfi_Source->bfsir_DTBitMap, TAG_DONE);

        if (!this_BFI->bfi_Source->bfsir_DTBitMap)
          GetDTAttrs(this_BFI->bfi_Source->bfsir_DTPictureObject, PDTA_BitMap, &this_BFI->bfi_Source->bfsir_DTBitMap, TAG_DONE);
      
        if (this_BFI->bfi_Source->bfsir_DTBitMap)
        {
          D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Datatype Object BitMap @ %x\n", this_BFI->bfi_Source->bfsir_DTBitMap));

          if ((this_BFI->bfi_Source->bfsir_DTRastPort = CreateRastPort()))
          {
            this_BFI->bfi_Source->bfsir_DTRastPort->BitMap = this_BFI->bfi_Source->bfsir_DTBitMap;
            this_BFI->bfi_Source->bfsir_BackGroundRenderMode = BackGround_RenderMode;
            this_BFI->bfi_Source->bfsir_OpenerCount = 0x01;

            NewList(&this_BFI->bfi_Source->bfsir_Buffers);

            AddTail(&image_backfill_images, &this_BFI->bfi_Source->bfsir_Node);
            goto check_imagebuffer;
          }
        }
        /* Failed to obtain datatype object's BM */
      }
      /* Failed to Layout datatype object */
    }
    /* Failed to open datatype object */
#if defined(DEBUG)
    if (!this_BFI->bfi_Source->bfsir_DTRastPort)
    {
      D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Failed to create ImageSource RastPort\n"));
    }
#endif
    
    if (this_BFI->bfi_Source->bfsir_DTBitMap)
    {
      FreeBitMap(this_BFI->bfi_Source->bfsir_DTBitMap);
      this_BFI->bfi_Source->bfsir_DTBitMap = NULL;
    }
#if defined(DEBUG)
    else
    {
      D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Failed to create ImageSource BitMap\n"));
    }
#endif

    if (this_BFI->bfi_Source->bfsir_DTPictureObject)
    {
      DisposeDTObject(this_BFI->bfi_Source->bfsir_DTPictureObject);
      this_BFI->bfi_Source->bfsir_DTPictureObject = NULL;
    }
#if defined(DEBUG)
    else
    {
      D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Failed to create ImageSource Datatype Object\n"));
    }
#endif
    D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Failed to create ImageSource Record\n"));
    if (this_BFI->bfi_Source->bfsir_SourceImage) FreeVec(this_BFI->bfi_Source->bfsir_SourceImage);
    FreeMem(this_BFI->bfi_Source, sizeof(struct BackFillSourceImageRecord));
    this_BFI->bfi_Source = NULL;
    return FALSE;
  }
  else
  {
    D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Using existing ImageSource Record\n"));
    this_BFI->bfi_Source->bfsir_OpenerCount += 1;
  }

check_imagebuffer:

  Depth = GetBitMapAttr(this_BFI->bfi_Source->bfsir_DTBitMap, BMA_DEPTH);
  this_BFI->bfi_CopyWidth = this_BFI->bfi_Source->bfsir_DTBitMapHeader->bmh_Width;
  this_BFI->bfi_CopyHeight = this_BFI->bfi_Source->bfsir_DTBitMapHeader->bmh_Height;

  switch (BackGround_RenderMode)
  {
    case IconWindowExt_ImageBackFill_RenderMode_Scale:
    {
      D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: SCALED mode\n"));

      this_BFI->bfi_Options.bfo_TileMode = IconWindowExt_ImageBackFill_TileMode_Fixed;
      
      SET(_IconWindows_IconListObj, MUIA_IconListview_FixedBackground, TRUE);
      SET(_IconWindows_IconListObj, MUIA_IconListview_ScaledBackground, TRUE);

      if ((BOOL)XGET(self, MUIA_IconWindow_IsRoot))
      {
        struct BackFillSourceImageBuffer *this_Buffer;
        D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: SCALED - Root Window = TRUE!\n"));
        this_BFI->bfi_CopyWidth = GetBitMapAttr(this_BFI->bfi_Screen->RastPort.BitMap, BMA_WIDTH);
        this_BFI->bfi_CopyHeight = GetBitMapAttr(this_BFI->bfi_Screen->RastPort.BitMap, BMA_HEIGHT);

        D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: SCALED - Base Dimensions (%d x %d)\n", this_BFI->bfi_CopyWidth, this_BFI->bfi_CopyHeight));

        if (!((BOOL)XGET(self, MUIA_IconWindow_IsBackdrop)))
        {
          D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: SCALED - Adjusting for window border Dimensions ..\n"));
          D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: SCALED -      WBorTop %d, WBorLeft %d, WBorRight %d, WBorBottom %d\n", this_BFI->bfi_Screen->WBorTop, this_BFI->bfi_Screen->WBorLeft, this_BFI->bfi_Screen->WBorRight, this_BFI->bfi_Screen->WBorBottom));
          this_BFI->bfi_CopyWidth -= (this_BFI->bfi_Screen->WBorLeft + this_BFI->bfi_Screen->WBorRight);
          this_BFI->bfi_CopyHeight -= (this_BFI->bfi_Screen->WBorTop + this_BFI->bfi_Screen->WBorBottom);;
        }

        this_BFI->bfi_CopyHeight -= (this_BFI->bfi_Screen->BarHeight + 1);

        this_Buffer = NULL;

        if (this_BFI->bfi_Buffer)
        {
          if ((this_BFI->bfi_Buffer->bfsib_BitMapWidth == this_BFI->bfi_CopyWidth) && (this_BFI->bfi_Buffer->bfsib_BitMapHeight == this_BFI->bfi_CopyHeight))
          {
            goto pb_backfillsetup_complete;
          }
          else
          {
            ImageBackFill_CloseSourceBuffer(this_BFI->bfi_Source, this_BFI->bfi_Buffer);
            this_BFI->bfi_Buffer = NULL;
          }
        }
        
        if (!(this_Buffer = ImageBackFill_FindBufferRecord(this_BFI->bfi_Source, this_BFI->bfi_CopyWidth, this_BFI->bfi_CopyHeight)))
        {
          this_Buffer = AllocMem(sizeof(struct BackFillSourceImageBuffer), MEMF_CLEAR|MEMF_PUBLIC);
          this_Buffer->bfsib_BitMapWidth = this_BFI->bfi_CopyWidth;
          this_Buffer->bfsib_BitMapHeight = this_BFI->bfi_CopyHeight;

          if (!(this_Buffer->bfsib_BitMapRastPort = CreateRastPort()))
          {
            D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: SCALED - Failed to create RastPort for BackFill BitMap\n"));
            break;
          }

          if ((this_Buffer->bfsib_BitMap = AllocBitMap(this_BFI->bfi_CopyWidth, this_BFI->bfi_CopyHeight, Depth, Depth == 8 ? BMF_MINPLANES : 0L, this_BFI->bfi_Screen->RastPort.BitMap)))
          {
            struct Rectangle CopyBounds;

            D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: SCALED - Scale Dimensions (%d x %d)\n", this_BFI->bfi_CopyWidth, this_BFI->bfi_CopyHeight));

            
            this_Buffer->bfsib_BitMapRastPort->BitMap = this_Buffer->bfsib_BitMap;
            this_BFI->bfi_Buffer = this_Buffer;
            
            CopyBounds.MinX = 0;
            CopyBounds.MinY = 0;
            CopyBounds.MaxX = this_BFI->bfi_CopyWidth - 1;
            CopyBounds.MaxY = this_BFI->bfi_CopyHeight - 1;

            
            ImageBackFill_CopyScaledBitMap(this_BFI->bfi_Source->bfsir_DTRastPort,
                    0, 0, 
                    this_BFI->bfi_Source->bfsir_DTBitMapHeader->bmh_Width,
                    this_BFI->bfi_Source->bfsir_DTBitMapHeader->bmh_Height,
                    this_Buffer->bfsib_BitMapRastPort,
                    &CopyBounds, &CopyBounds, blit_MODE_Blit);

            this_Buffer->bfsib_OpenerCount = 0x01;

            AddTail(&this_BFI->bfi_Source->bfsir_Buffers, &this_Buffer->bfsib_Node);
            
            goto pb_backfillsetup_complete;
          }
          break;
        }
        else
        {
          this_BFI->bfi_Buffer = this_Buffer;
          this_Buffer->bfsib_OpenerCount += 1;
          goto pb_backfillsetup_complete;
        }
      }
      // We arent the "ROOT" (desktop) window so only tile ...
      D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: SCALED - Drawer window scaling unsupported ...\n"));
    }
    default:
    {
      struct BackFillSourceImageBuffer *this_Buffer;
      D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: TILED mode\n"));
      if ((BackGround_TileMode = DoMethod(_IconWindows_PrefsObj, MUIM_WandererPrefs_ViewSettings_GetAttribute,
                                BackGround_Attrib, MUIA_IconWindowExt_ImageBackFill_BGTileMode)) == -1)
        BackGround_TileMode = IconWindowExt_ImageBackFill_TileMode_Float;

      if ((BackGround_XOffset = DoMethod(_IconWindows_PrefsObj, MUIM_WandererPrefs_ViewSettings_GetAttribute,
                                BackGround_Attrib, MUIA_IconWindowExt_ImageBackFill_BGXOffset)) == -1)
        BackGround_XOffset = 0;

      if ((BackGround_YOffset = DoMethod(_IconWindows_PrefsObj, MUIM_WandererPrefs_ViewSettings_GetAttribute,
                                BackGround_Attrib, MUIA_IconWindowExt_ImageBackFill_BGYOffset)) == -1)
        this_BFI->bfi_Options.bfo_OffsetY = 0;

      if (this_BFI->bfi_Options.bfo_TileMode != BackGround_TileMode)
      {
        this_BFI->bfi_Options.bfo_TileMode = BackGround_TileMode;
        options_changed = TRUE;
      }

      if (this_BFI->bfi_Options.bfo_OffsetX != BackGround_XOffset)
      {
        this_BFI->bfi_Options.bfo_OffsetX = BackGround_XOffset;
        options_changed = TRUE;
      }
      
      if (this_BFI->bfi_Options.bfo_OffsetY != BackGround_YOffset)
      {
        this_BFI->bfi_Options.bfo_OffsetY = BackGround_YOffset;
        options_changed = TRUE;
      }

      if (this_BFI->bfi_Options.bfo_TileMode == IconWindowExt_ImageBackFill_TileMode_Float)
        SET(_IconWindows_IconListObj, MUIA_IconListview_FixedBackground, FALSE);
      else
        SET(_IconWindows_IconListObj, MUIA_IconListview_FixedBackground, TRUE);

      SET(_IconWindows_IconListObj, MUIA_IconListview_ScaledBackground, FALSE);

      this_Buffer = NULL;

      if (this_BFI->bfi_Buffer)
      {
        if ((this_BFI->bfi_Buffer->bfsib_BitMapWidth == this_BFI->bfi_CopyWidth) && (this_BFI->bfi_Buffer->bfsib_BitMapHeight == this_BFI->bfi_CopyHeight))
        {
          goto pb_backfillsetup_complete;
        }
        else
        {
          ImageBackFill_CloseSourceBuffer(this_BFI->bfi_Source, this_BFI->bfi_Buffer);
          this_BFI->bfi_Buffer = NULL;
        }
      }

      D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Dimensions Width %d, Height %d\n", this_BFI->bfi_CopyWidth, this_BFI->bfi_CopyHeight));
      
      if (!(this_Buffer = ImageBackFill_FindBufferRecord(this_BFI->bfi_Source, this_BFI->bfi_CopyWidth, this_BFI->bfi_CopyHeight)))
      {
        this_Buffer = AllocMem(sizeof(struct BackFillSourceImageBuffer), MEMF_CLEAR|MEMF_PUBLIC);
        this_Buffer->bfsib_BitMapWidth = this_BFI->bfi_CopyWidth;
        this_Buffer->bfsib_BitMapHeight = this_BFI->bfi_CopyHeight;

        if ((this_Buffer->bfsib_BitMap = AllocBitMap(this_BFI->bfi_CopyWidth, this_BFI->bfi_CopyHeight, Depth, Depth == 8 ? BMF_MINPLANES : 0L, this_BFI->bfi_Screen->RastPort.BitMap)))
        {
          struct Rectangle CopyBounds;

          if (!(this_Buffer->bfsib_BitMapRastPort = CreateRastPort()))
          {
            D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: TILED - Failed to create RastPort for BackFill BitMap\n"));
            break;
          }

          this_Buffer->bfsib_BitMapRastPort->BitMap = this_Buffer->bfsib_BitMap;
          this_BFI->bfi_Buffer = this_Buffer;
          
          CopyBounds.MinX = 0;
          CopyBounds.MinY = 0;
          CopyBounds.MaxX = this_BFI->bfi_CopyWidth - 1;
          CopyBounds.MaxY = this_BFI->bfi_CopyHeight - 1;

          ImageBackFill_CopyTiledBitMap(this_BFI->bfi_Source->bfsir_DTRastPort,
                  0, 0, 
                  this_BFI->bfi_Source->bfsir_DTBitMapHeader->bmh_Width,
                  this_BFI->bfi_Source->bfsir_DTBitMapHeader->bmh_Height,
                  this_BFI->bfi_Buffer->bfsib_BitMapRastPort,
                  &CopyBounds, &CopyBounds, blit_MODE_Blit);

          this_Buffer->bfsib_OpenerCount = 0x01;
          
          AddTail(&this_BFI->bfi_Source->bfsir_Buffers, &this_BFI->bfi_Buffer->bfsib_Node);

          goto pb_backfillsetup_complete;
        }
        break;
      }
      else
      {
        this_BFI->bfi_Buffer = this_Buffer;
        this_Buffer->bfsib_OpenerCount += 1;
        goto pb_backfillsetup_complete;
      }
    }
  }

  D(bug("[IconWindow.ImageBackFill] MUIM_IconWindow_BackFill_ProcessBackground: Failed to create image datatype object\n"));  
  return FALSE;
  
pb_cleanup_buffer:
  if (this_BFI->bfi_Buffer)
  {
    ImageBackFill_CloseSourceBuffer(this_BFI->bfi_Source, this_BFI->bfi_Buffer);
    this_BFI->bfi_Buffer = NULL;
  }

pb_cleanup_source:
  if (this_BFI->bfi_Source)
  { 
    ImageBackFill_CloseSourceRecord(this_BFI->bfi_Source);
    this_BFI->bfi_Source = NULL;
  }
  
  return FALSE;
  
pb_backfillsetup_complete:
  if ((prefs_processing) && (options_changed))
    SET(self, MUIA_IconWindow_Changed, TRUE);

  return TRUE;
}