void RichEdit::SetObjectPos(int pos) { Rect r = GetObjectRect(cursor); Rect rr = r.Offseted(GetTextRect().left, -sb); objectrect = GetObjectRect(pos); objectpos = cursor; PlaceCaret(); Refresh(rr); ReadFormat(); }
// Show icon image void filetypeed_show_icon(filetype_ed_data *data) { struct Rectangle bounds; struct TagItem tags[2]; ImageRemap remap; // Clear icon area SetGadgetValue(data->objlist,GAD_FILETYPEED_ICON_AREA,0); // Valid icon? if (!data->icon_image) return; // Get icon area if (!(GetObjectRect(data->objlist,GAD_FILETYPEED_ICON_AREA,&bounds))) return; // Move bounds inwards bounds.MinX+=2; bounds.MinY+=1; bounds.MaxX-=2; bounds.MaxY-=1; #ifdef USE_DRAWICONSTATE { struct Rectangle rect; int x=0,y=0; if (GetIconRectangle( data->window->RPort, data->icon_image, NULL, &rect, ICONDRAWA_Borderless, TRUE, TAG_DONE)) { x = (bounds.MaxX-bounds.MinX - (rect.MaxX-rect.MinX)) >> 1; y = (bounds.MaxY-bounds.MinY - (rect.MaxY-rect.MinY)) >> 1; } DrawIconState( data->window->RPort, data->icon_image, NULL, x+bounds.MinX, y+bounds.MinY, /*data->image_num ? IDS_SELECTED :*/ IDS_NORMAL, ICONDRAWA_Frameless, TRUE, ICONDRAWA_Borderless, TRUE, ICONDRAWA_EraseBackground, TRUE, TAG_DONE); }
// Show font example void font_show_font(font_data *data,BOOL refresh) { struct Rectangle rect; struct Region *region; struct RastPort rp; // Get display rectangle GetObjectRect(data->list,GAD_FONT_DISPLAY,&rect); // Move rectangle in rect.MinX+=3; rect.MinY+=3; rect.MaxX-=3; rect.MaxY-=3; // Copy rastport rp=*data->window->RPort; // Refresh? if (refresh) { LockLayerInfo(&data->window->WScreen->LayerInfo); BeginRefresh(data->window); } // Clear background SetAPen(&rp,DRAWINFO(data->window)->dri_Pens[SHINEPEN]); RectFill(&rp,rect.MinX-1,rect.MinY-1,rect.MaxX+1,rect.MaxY+1); // Refreshing? if (refresh) EndRefresh(data->window,FALSE); // Create region if ((region=NewRegion())) { // Set rectangle OrRectRegion(region,&rect); // Install region InstallClipRegion(data->window->WLayer,region); } // Refreshing? if (refresh) BeginRefresh(data->window); // Got a font? if (data->font) { ULONG flags; short y; struct TextExtent extent; char *ptr,*end; // Set pen and font SetAPen(&rp,DRAWINFO(data->window)->dri_Pens[TEXTPEN]); SetDrMd(&rp,JAM1); SetFont(&rp,data->font); // Get style flags flags=0; if (GetGadgetValue(data->list,GAD_FONT_BOLD)) flags|=FSF_BOLD; if (GetGadgetValue(data->list,GAD_FONT_ITALIC)) flags|=FSF_ITALIC; if (GetGadgetValue(data->list,GAD_FONT_ULINE)) flags|=FSF_UNDERLINED; // Set styles SetSoftStyle(&rp,flags,FSF_BOLD|FSF_ITALIC|FSF_UNDERLINED); // Valid font to draw? if (data->font_text[0]) { // Get end of the string end=data->font_text+strlen(data->font_text); // Initial coordinates y=rect.MinY; // Initialise position if (!(ptr=strchr(data->font_text,'A'))) ptr=data->font_text; Move(&rp,rect.MinX,y+rp.TxBaseline); // Draw until we reach the bottom while (y<rect.MaxY) { // New line if (rp.cp_x>rect.MaxX) { // Bump position y+=rp.TxHeight+1; Move(&rp,rect.MinX,y+rp.TxBaseline); } // Otherwise else { short len,maxlen; // Get text that will fit len= TextFit( &rp, ptr, (maxlen=strlen(ptr)), &extent, 0,1, rect.MaxX-rp.cp_x+1, rp.TxHeight); // Check against length, add extra character if ok if (len<maxlen) ++len; // Draw text Text(&rp,ptr,len); // Bump text position ptr+=len; // End of the string? if (ptr>=end) ptr=data->font_text; } } } } // Finished refreshing? if (refresh) EndRefresh(data->window,TRUE); // Remove region if (region) { InstallClipRegion(data->window->WLayer,0); DisposeRegion(region); } // Unlock layers if we refreshed if (refresh) UnlockLayerInfo(&data->window->WScreen->LayerInfo); }
Att_List *build_text_display(struct Window *window,ObjectList *objlist,char *text) { Att_List *list; struct TextExtent extent; short want_len,max_len,textlen=0,width; char *textpos=0; struct Rectangle rect; char old; // Allocate a new list list=Att_NewList(0); // Get list object size GetObjectRect(objlist,GAD_TEXT_DISPLAY,&rect); width=RECTWIDTH(&rect)-28; // Go through text FOREVER { // No current line? if (!textpos) textpos=text; // Move on from current line else { // Were we on a newline? if (textlen==0) ++textpos; // No else { // Bump pointer textpos+=textlen; // If this leaves us on a newline or space, skip over it if (*textpos=='\n' || *textpos=='\t') ++textpos; } } // End of text? if (!*textpos) break; // If we're on a space, skip over it if (*textpos==' ') ++textpos; // Calculate desired length of the line for (want_len=0;textpos[want_len] && textpos[want_len]!='\n';++want_len); // Blank line? if (want_len==0) { textlen=0; } // Not blank else { // Get maximum length that will actually fit max_len=TextFit( window->RPort, textpos, want_len, &extent, 0,1, width,window->RPort->TxHeight); // Go from here to end of current word want_len=max_len; while ( textpos[want_len] && textpos[want_len]!='\n' && textpos[want_len]!=' ') ++want_len; // Loop until successful do { // Get text size TextExtent(window->RPort,textpos,want_len,&extent); // Will it fit? if (extent.te_Width<=width) { // Save size textlen=want_len; break; } // Come backwards to word break for (--want_len;want_len>0 && textpos[want_len]!=' ';--want_len); // Didn't find one? if (want_len<1) { // Get maximum length want_len=max_len; } } while(1); } // Null out break temporarily old=textpos[textlen]; textpos[textlen]=0; // Add node Att_NewNode(list,textpos,0,0); // Restore character textpos[textlen]=old; } // Add list to display SetGadgetChoices(objlist,GAD_TEXT_DISPLAY,list); return list; }
void RichEdit::LeftDown(Point p, dword flags) { useraction = true; NextUndo(); SetFocus(); selclick = false; tabmove = GetHotPos(p); if(tabmove.table && tabmove.column >= -2) { SaveTableFormat(tabmove.table); SetCapture(); Move(text.GetCellPos(tabmove.table, 0, max(tabmove.column, 0)).pos); return; } int c = GetHotSpot(p); if(c >= 0 && objectpos >= 0) { int pos = objectpos; RectTracker tracker(*this); RichObject obj = text.GetRichPos(pos).object; tracker.MinSize(Size(16, 16)) .MaxSize(GetZoom() * pagesz) .Animation() .Dashed() .KeepRatio(obj.IsKeepRatio()); int tx, ty; switch(c) { case 1: tracker.SetCursorImage(Image::SizeVert()); tx = ALIGN_CENTER; ty = ALIGN_BOTTOM; break; case 2: tracker.SetCursorImage(Image::SizeHorz()); tx = ALIGN_RIGHT; ty = ALIGN_CENTER; break; default: tracker.SetCursorImage(Image::SizeBottomRight()); tx = ALIGN_RIGHT; ty = ALIGN_RIGHT; break; } double zoom = GetZoom().AsDouble(); Size sz = obj.GetSize(); sz.cx = int(zoom * sz.cx + 0.5); sz.cy = int(zoom * sz.cy + 0.5); sz = tracker.Track(Rect(objectrect.Offseted(GetTextRect().left, -sb).TopLeft(), sz), tx, ty).Size(); sz.cx = int(sz.cx / zoom + 0.5); sz.cy = int(sz.cy / zoom + 0.5); obj.SetSize(sz); ReplaceObject(obj); } else { c = GetMousePos(p); if(c >= 0) { if(InSelection(c)) { selclick = true; return; } Move(c, flags & K_SHIFT); mpos = c; SetCapture(); if(cursorp.object && GetObjectRect(cursor).Offseted(GetTextRect().left, -sb).Contains(p)) SetObjectPos(cursor); } } }